view.php 10.6 KB
Newer Older
1
2
<?php
/**
Francois Marier's avatar
Francois Marier committed
3
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
4
5
 * Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
 *                         http://wiki.mahara.org/Contributors
6
 *
Francois Marier's avatar
Francois Marier committed
7
8
9
10
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
11
 *
Francois Marier's avatar
Francois Marier committed
12
13
14
15
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
16
 *
Francois Marier's avatar
Francois Marier committed
17
18
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20
21
 *
 * @package    mahara
 * @subpackage core
22
 * @author     Catalyst IT Ltd
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
24
 * @copyright  (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
25
26
27
28
 *
 */

define('INTERNAL', 1);
29
define('PUBLIC', 1);
30
31
32
33
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'view');
define('SECTION_PAGE', 'view');

34
require(dirname(dirname(__FILE__)) . '/init.php');
35

36
require_once(get_config('libroot') . 'view.php');
37
require_once(get_config('libroot') . 'collection.php');
38
require_once('group.php');
39
safe_require('artefact', 'comment');
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
// access key for roaming teachers
$mnettoken = $SESSION->get('mnetuser') ? param_alphanum('mt', null) : null;

// access key for logged out users
$usertoken = (is_null($mnettoken) && get_config('allowpublicviews')) ? param_alphanum('t', null) : null;

if ($mnettoken) {
    if (!$viewid = get_view_from_token($mnettoken, false)) {
        throw new AccessDeniedException(get_string('accessdenied', 'error'));
    }
}
else if ($usertoken) {
    if (!$viewid = get_view_from_token($usertoken, true)) {
        throw new AccessDeniedException(get_string('accessdenied', 'error'));
Richard Mansfield's avatar
Richard Mansfield committed
55
56
57
58
59
    }
}
else {
    $viewid = param_integer('id');
}
60

61
$new = param_boolean('new');
62
63
64
65
$showmore = param_boolean('showmore');
if (!$showmore) {
    $showmore = 0;
}
66

67
if (!can_view_view($viewid)) {
68
    throw new AccessDeniedException(get_string('accessdenied', 'error'));
69
}
70
71

// Feedback list pagination requires limit/offset params
72
73
74
$limit       = param_integer('limit', 10);
$offset      = param_integer('offset', 0);
$showcomment = param_integer('showcomment', null);
75

Richard Mansfield's avatar
Richard Mansfield committed
76
$view = new View($viewid);
77

78
// Create the "make feedback private form" now if it's been submitted
79
80
if (param_variable('make_public_submit', null)) {
    pieform(ArtefactTypeComment::make_public_form(param_integer('comment')));
81
}
82
else if (param_variable('delete_comment_submit_x', null)) {
Richard Mansfield's avatar
Richard Mansfield committed
83
    pieform(ArtefactTypeComment::delete_comment_form(param_integer('comment')));
84
85
}

86
87
$owner    = $view->get('owner');
$viewtype = $view->get('type');
88

89
90
if ($viewtype == 'profile' || $viewtype == 'dashboard' || $viewtype == 'grouphomepage') {
    redirect($view->get_url());
91
}
92

93
94
define('TITLE', $view->get('title'));

95
$submittedgroup = (int)$view->get('submittedgroup');
96
if ($USER->is_logged_in() && $submittedgroup && group_user_can_assess_submitted_views($submittedgroup, $USER->get('id'))) {
97
    // The user is a tutor of the group that this view has
98
    // been submitted to, and is entitled to release the view
99
    $submittedgroup = get_record('group', 'id', $submittedgroup);
100
    if ($view->get('submittedtime')) {
101
        $text = get_string('viewsubmittedtogroupon', 'view', get_config('wwwroot') . 'group/view.php?id=' . $submittedgroup->id, hsc($submittedgroup->name), format_date(strtotime($view->get('submittedtime'))));
102
103
    }
    else {
104
        $text = get_string('viewsubmittedtogroup', 'view', get_config('wwwroot') . 'group/view.php?id=' . $submittedgroup->id, hsc($submittedgroup->name));
105
    }
106
107
108
109
110
    $releaseform = pieform(array(
        'name'     => 'releaseview',
        'method'   => 'post',
        'plugintype' => 'core',
        'pluginname' => 'view',
111
        'autofocus' => false,
112
113
114
        'elements' => array(
            'submittedview' => array(
                'type'  => 'html',
115
                'value' => $text,
116
117
118
119
120
121
122
            ),
            'submit' => array(
                'type'  => 'submit',
                'value' => get_string('releaseview', 'group'),
            ),
        ),
    ));
123
}
124
125
126
127
128
129
130
else {
    $releaseform = '';
}


function releaseview_submit() {
    global $USER, $SESSION, $view;
131
    $groupid = $view->get('submittedgroup');
132
    $view->release($USER);
133
    $SESSION->add_ok_msg(get_string('viewreleasedsuccess', 'group'));
134
135
136
137
138
    if ($groupid) {
        // The tutor might not have access to the view any more; send
        // them back to the group page.
        redirect(get_config('wwwroot') . 'group/view.php?id='.$groupid);
    }
139
140
    redirect(get_config('wwwroot') . 'view/view.php?id='.$view->get('id'));
}
141
142
143
144
145

$javascript = array('paginator', 'viewmenu', 'jquery', 'artefact/resume/resumeshowhide.js');
$javascript = array_merge($javascript, $view->get_blocktype_javascript());

$extrastylesheets = array('style/views.css');
146
  
147
148
// If the view has comments turned off, tutors can still leave
// comments if the view is submitted to their group.
149
if (!empty($releaseform) || ($commenttype = $view->user_comments_allowed($USER))) {
150
    $defaultprivate = !empty($releaseform);
151
152
    $moderate = isset($commenttype) && $commenttype === 'private';
    $addfeedbackform = pieform(ArtefactTypeComment::add_comment_form($defaultprivate, $moderate));
153
154
    $extrastylesheets[] = 'style/jquery.rating.css';
    $javascript[] = 'jquery.rating';
155
156
157
}
if ($USER->is_logged_in()) {
    $objectionform = pieform(objection_form());
158
159
160
    if ($notrudeform = $view->notrude_form()) {
        $notrudeform = pieform($notrudeform);
    }
161
162
}

163
164
$viewbeingwatched = (int)record_exists('usr_watchlist_view', 'usr', $USER->get('id'), 'view', $viewid);

165
$feedback = ArtefactTypeComment::get_comments($limit, $offset, $showcomment, $view);
166

167
// Set up theme
168
169
170
$viewtheme = $view->get('theme');
if ($viewtheme && $THEME->basename != $viewtheme) {
    $THEME = new Theme($viewtheme);
171
}
172
173
174
175
176
$headers = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">');

if (!$view->is_public()) {
    $headers[] = '<meta name="robots" content="noindex">';  // Tell search engines not to index non-public views
}
177

178
179
180
181
182
183
184
185
186
// include slimbox2 js and css files, if it is enabled...
if (get_config_plugin('blocktype', 'gallery', 'useslimbox2')) {
    $langdir = (get_string('thisdirection', 'langconfig') == 'rtl' ? '-rtl' : '');
    $headers = array_merge($headers, array(
        '<script type="text/javascript" src="' . get_config('wwwroot') . 'lib/slimbox2/js/slimbox2.js"></script>',
        '<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'lib/slimbox2/css/slimbox2' . $langdir . '.css">'
    ));
}

187
$can_edit = $USER->can_edit_view($view) && !$submittedgroup && !$view->is_submitted();
188

189
$smarty = smarty(
190
    $javascript,
191
    $headers,
192
    array(),
193
    array(
194
        'stylesheets' => $extrastylesheets,
195
196
        'sidebars' => false,
    )
197
);
198

199
200
$javascript = <<<EOF
var viewid = {$viewid};
201
var showmore = {$showmore};
202
203
204
205
206
addLoadEvent(function () {
    paginator = {$feedback->pagination_js}
});
EOF;

207
// collection top navigation
208
if ($collection = $view->get('collection')) {
209
210
    $shownav = $collection->get('navigation');
    if ($shownav) {
211
212
        if ($views = $collection->get('views')) {
            if (count($views['views']) > 1) {
213
                $smarty->assign_by_ref('collection', array_chunk($views['views'], 5));
214
215
            }
        }
216
    }
217
218
}

Richard Mansfield's avatar
Richard Mansfield committed
219
$smarty->assign('INLINEJAVASCRIPT', $javascript);
220
$smarty->assign('new', $new);
221
$smarty->assign('viewid', $viewid);
222
$smarty->assign('viewtype', $viewtype);
223
$smarty->assign('feedback', $feedback);
Richard Mansfield's avatar
Richard Mansfield committed
224
225
$smarty->assign('owner', $owner);
$smarty->assign('tags', $view->get('tags'));
226

227
228
$smarty->assign('PAGEAUTHOR', $view->formatted_owner());

229
230
if (get_config('viewmicroheaders')) {
    $smarty->assign('microheaders', true);
231
    $smarty->assign('microheadertitle', $collection ? hsc($collection->get('name')) : $view->display_title(true, false));
232
233

    if ($can_edit) {
234
        if ($new) {
235
236
237
            $microheaderlinks = array(
                array(
                    'name' => get_string('back'),
238
                    'url' => get_config('wwwroot') . 'view/blocks.php?id=' . $viewid . '&new=1',
239
240
241
242
243
244
245
                    'type' => 'reply',
                ),
            );
        }
        else {
            $microheaderlinks = array(
                array(
246
247
                    'name' => get_string('editthisview', 'view'),
                    'image' => $THEME->get_url('images/edit.gif'),
248
                    'url' => get_config('wwwroot') . 'view/blocks.php?id=' . $viewid,
249
250
251
252
                ),
            );
        }
        $smarty->assign('microheaderlinks', $microheaderlinks);
253
    }
254

255
}
256
else if ($can_edit) {
257
    $smarty->assign('visitstring', $view->visit_message());
258
259
    $smarty->assign('editurl', get_config('wwwroot') . 'view/blocks.php?id=' . $viewid . ($new ? '&new=1' : ''));
}
260

261
262
$title = hsc(TITLE);

263
if (!get_config('viewmicroheaders')) {
264
    $title = $collection ? hsc($collection->get('name')) : $view->display_title();
265
266
267
    $smarty->assign('maintitle', $title);
}

268
269
270
271
272
273
274
275
276
277
278
279
280
// Provide a link for roaming teachers to return
if ($mnetviewlist = $SESSION->get('mnetviewaccess')) {
    if (isset($mnetviewlist[$view->get('id')])) {
        $returnurl = $SESSION->get('mnetuserfrom');
        require_once(get_config('docroot') . 'api/xmlrpc/lib.php');
        if ($peer = get_peer_from_instanceid($SESSION->get('authinstance'))) {
            $smarty->assign('mnethost', array(
                'name'      => $peer->name,
                'url'       => $returnurl ? $returnurl : $peer->wwwroot,
            ));
        }
    }
}
281

282
283
$smarty->assign('viewdescription', $view->get('description'));
$smarty->assign('viewcontent', $view->build_columns());
284
$smarty->assign('releaseform', $releaseform);
285
if (isset($addfeedbackform)) {
286
    $smarty->assign('enablecomments', 1);
287
    $smarty->assign('addfeedbackform', $addfeedbackform);
288
}
289
290
if (isset($objectionform)) {
    $smarty->assign('objectionform', $objectionform);
291
    $smarty->assign('notrudeform', $notrudeform);
292
}
293
$smarty->assign('viewbeingwatched', $viewbeingwatched);
294

295
296
297
298
299
300
301
302
if ($owner && $owner == $USER->get('id')) {
    if ($tutorgroupdata = group_get_user_course_groups()) {
        if (!$view->get('submittedgroup') && !$view->get('submittedhost')) {
            $smarty->assign(
                'view_group_submission_form',
                view_group_submission_form($view->get('id'), $tutorgroupdata, 'view')
            );
        }
303
304
305
    }
}

306
307
$smarty->display('view/view.tpl');

308
mahara_log('views', "$viewid"); // Log view visits