view.php 10.5 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
37
require_once(get_config('libroot') . 'view.php');
require_once('group.php');
38
safe_require('artefact', 'comment');
39

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// 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'));
    }
    if ($mnettoken != get_cookie('mviewaccess:'.$viewid)) {
        set_cookie('mviewaccess:'.$viewid, $mnettoken);
    }
}
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
57
    }
58
59
    if ($usertoken != get_cookie('viewaccess:'.$viewid)) {
        set_cookie('viewaccess:'.$viewid, $usertoken);
Richard Mansfield's avatar
Richard Mansfield committed
60
61
62
63
64
    }
}
else {
    $viewid = param_integer('id');
}
65

66
67
$new = param_boolean('new');

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

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

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

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

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

90
91
if ($viewtype == 'profile') {
    define('TITLE', display_name($owner, null, true));
92
93
}
else {
94
    define('TITLE', $view->get('title'));
95
}
96
$title = hsc(TITLE);
97

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


function releaseview_submit() {
    global $USER, $SESSION, $view;
135
    $groupid = $view->get('submittedgroup');
136
    $view->release($USER);
137
    $SESSION->add_ok_msg(get_string('viewreleasedsuccess', 'group'));
138
139
140
141
142
    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);
    }
143
144
145
    redirect(get_config('wwwroot') . 'view/view.php?id='.$view->get('id'));
}
  
146
147
// If the view has comments turned off, tutors can still leave
// comments if the view is submitted to their group.
148
if (($USER->is_logged_in() || get_config('anonymouscomments')) && ($view->get('allowcomments') || !empty($releaseform))) {
149
150
    $defaultprivate = !empty($releaseform);
    $addfeedbackform = pieform(ArtefactTypeComment::add_comment_form($defaultprivate));
151
152
153
154
155
}
if ($USER->is_logged_in()) {
    $objectionform = pieform(objection_form());
}

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

158
$feedback = ArtefactTypeComment::get_comments($limit, $offset, $showcomment, $view);
159

160
// Set up theme
161
162
163
$viewtheme = $view->get('theme');
if ($viewtheme && $THEME->basename != $viewtheme) {
    $THEME = new Theme($viewtheme);
164
}
165
166
$stylesheets = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">');

167
$can_edit = $USER->can_edit_view($view) && !$submittedgroup && !$view->is_submitted();
168

169
$smarty = smarty(
170
    array('paginator', 'viewmenu', 'artefact/resume/resumeshowhide.js'),
171
    $stylesheets,
172
    array(),
173
174
175
176
    array(
        'stylesheets' => array('style/views.css'),
        'sidebars' => false,
    )
177
);
178

179
180
181
182
183
184
185
$javascript = <<<EOF
var viewid = {$viewid};
addLoadEvent(function () {
    paginator = {$feedback->pagination_js}
});
EOF;

Richard Mansfield's avatar
Richard Mansfield committed
186
$smarty->assign('INLINEJAVASCRIPT', $javascript);
187
$smarty->assign('new', $new);
188
$smarty->assign('viewid', $viewid);
189
$smarty->assign('viewtype', $viewtype);
190
$smarty->assign('feedback', $feedback);
Richard Mansfield's avatar
Richard Mansfield committed
191
192
$smarty->assign('owner', $owner);
$smarty->assign('tags', $view->get('tags'));
193
194
195
196
197
198

if (get_config('viewmicroheaders')) {
    $smarty->assign('microheaders', true);
    $smarty->assign('microheadertitle', $view->display_title(true, false));

    if ($can_edit) {
199
        $smarty->assign('visitstring', $view->visit_message());
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
        if ($viewtype == 'profile') {
            $microheaderlinks = array(
                array(
                    'name' => get_string('editmyprofilepage'),
                    'url' => get_config('wwwroot') . 'view/blocks.php?profile=1',
                    'type' => 'edit',
                ),
                array(
                    'name' => get_string('editmyprofile', 'artefact.internal'),
                    'url' => get_config('wwwroot') . 'artefact/internal/index.php',
                    'type' => 'edit',
                ),
            );
        }
        else if ($new) {
            $microheaderlinks = array(
                array(
                    'name' => get_string('back'),
                    'url' => get_config('wwwroot') . 'view/blocks.php?id=' . $viewid . '&amp;new=1',
                    'type' => 'reply',
                ),
            );
        }
        else {
            $microheaderlinks = array(
                array(
                    'name' => get_string('edittitle', 'view'),
                    'url' => get_config('wwwroot') . 'view/edit.php?id=' . $viewid . '&amp;new=' . $new,
                    'type' => 'edit',
                ),
                array(
                    'name' => get_string('editcontent', 'view'),
                    'url' => get_config('wwwroot') . 'view/blocks.php?id=' . $viewid . '&amp;new=' . $new,
                    'type' => 'edit',
                ),
                array(
                    'name' => get_string('editaccess', 'view'),
                    'url' => get_config('wwwroot') . 'view/access.php?id=' . $viewid . '&amp;new=' . $new,
                    'type' => 'edit',
                ),
            );
        }
        $smarty->assign('microheaderlinks', $microheaderlinks);
243
    }
244
245
246
247
248
249
250
251

    if ($USER->is_logged_in()) {
        $smarty->assign('userdisplayname', display_name($USER, null, true));
        if (!empty($_SERVER['HTTP_REFERER'])) {
            $page = get_config('wwwroot') . 'view/view.php?id=' . $viewid . ($new ? '&new=1' : '');
            if ($_SERVER['HTTP_REFERER'] != $page) {
                $smarty->assign('backurl', $_SERVER['HTTP_REFERER']);
            }
252
        }
253
254
    }
}
255

256
257
258
259
260
261
262
263
if ($viewtype != 'profile' && !get_config('viewmicroheaders')) {
    $title = $view->display_title();
}

if ($viewtype != 'profile' || !get_config('viewmicroheaders')) {
    $smarty->assign('maintitle', $title);
}

264
265
266
267
268
269
270
271
272
273
274
275
276
// 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,
            ));
        }
    }
}
277

278
279
$smarty->assign('viewdescription', $view->get('description'));
$smarty->assign('viewcontent', $view->build_columns());
280
$smarty->assign('releaseform', $releaseform);
281
if (isset($addfeedbackform)) {
282
    $smarty->assign('enablecomments', 1);
283
    $smarty->assign('addfeedbackform', $addfeedbackform);
284
}
285
286
if (isset($objectionform)) {
    $smarty->assign('objectionform', $objectionform);
287
}
288
$smarty->assign('viewbeingwatched', $viewbeingwatched);
289

290
291
292
if ($tutorgroupdata = group_get_user_course_groups()) {
    $options = array();
    if (!$view->get('submittedgroup') && !$view->get('submittedhost')) {
293
        $smarty->assign('view_group_submission_form', view_group_submission_form($view->get('id'), $tutorgroupdata, 'view'));
294
295
296
    }
}

297
298
$smarty->display('view/view.tpl');

299
mahara_log('views', "$viewid"); // Log view visits
300
?>