view.php 9.53 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');
require_once('group.php');
37

38
39
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'));
    }
    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
55
    }
56
57
    if ($usertoken != get_cookie('viewaccess:'.$viewid)) {
        set_cookie('viewaccess:'.$viewid, $usertoken);
Richard Mansfield's avatar
Richard Mansfield committed
58
59
60
61
62
    }
}
else {
    $viewid = param_integer('id');
}
63
64
$new = param_boolean('new');

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

// Feedback list pagination requires limit/offset params
$limit    = param_integer('limit', 10);
$offset   = param_integer('offset', 0);

Richard Mansfield's avatar
Richard Mansfield committed
73
$view = new View($viewid);
74

75
76
77
78
79
// Create the "make feedback private form" now if it's been submitted
if (param_variable('make_private_submit', null)) {
    pieform(make_private_form(param_integer('feedback')));
}

80
81
$owner    = $view->get('owner');
$viewtype = $view->get('type');
82

83
84
if ($viewtype == 'profile') {
    define('TITLE', display_name($owner, null, true));
85
86
}
else {
87
    define('TITLE', $view->get('title'));
88
}
89
$title = hsc(TITLE);
90

91
$submittedgroup = (int)$view->get('submittedgroup');
92
if ($USER->is_logged_in() && $submittedgroup && group_user_can_assess_submitted_views($submittedgroup, $USER->get('id'))) {
93
    // The user is a tutor of the group that this view has
94
95
    // been submitted to, and is entitled to release the view, and to
    // upload an additional file when submitting feedback.
96
97
98
99
100
101
    $submittedgroup = get_record('group', 'id', $submittedgroup);
    $releaseform = pieform(array(
        'name'     => 'releaseview',
        'method'   => 'post',
        'plugintype' => 'core',
        'pluginname' => 'view',
102
        'autofocus' => false,
103
104
105
        'elements' => array(
            'submittedview' => array(
                'type'  => 'html',
106
                'value' => get_string('viewsubmittedtogroup', 'view', get_config('wwwroot') . 'group/view.php?id=' . $submittedgroup->id, $submittedgroup->name),
107
108
109
110
111
112
113
            ),
            'submit' => array(
                'type'  => 'submit',
                'value' => get_string('releaseview', 'group'),
            ),
        ),
    ));
114
    $allowattachments = true;
115
}
116
117
else {
    $releaseform = '';
118
    $allowattachments = false;
119
120
121
122
123
}


function releaseview_submit() {
    global $USER, $SESSION, $view;
124
    $groupid = $view->get('submittedgroup');
125
    $view->release($USER);
126
    $SESSION->add_ok_msg(get_string('viewreleasedsuccess', 'group'));
127
128
129
130
131
    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);
    }
132
133
134
    redirect(get_config('wwwroot') . 'view/view.php?id='.$view->get('id'));
}
  
135
$viewbeingwatched = (int)record_exists('usr_watchlist_view', 'usr', $USER->get('id'), 'view', $viewid);
136

137
138
$feedback = $view->get_feedback($limit, $offset);
build_feedback_html($feedback);
139
140
141
142
143
144
145
146
147

$anonfeedback = !$USER->is_logged_in() && ($usertoken || $viewid == get_view_from_token(get_cookie('viewaccess:'.$viewid)));
if ($USER->is_logged_in() || $anonfeedback) {
    $addfeedbackform = pieform(add_feedback_form($allowattachments));
}
if ($USER->is_logged_in()) {
    $objectionform = pieform(objection_form());
}

148
// Set up theme
149
150
151
$viewtheme = $view->get('theme');
if ($viewtheme && $THEME->basename != $viewtheme) {
    $THEME = new Theme($viewtheme);
152
}
153
154
$stylesheets = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">');

155
$can_edit = $USER->can_edit_view($view) && !$submittedgroup && !$view->is_submitted();
156

157
$smarty = smarty(
158
    array('paginator', 'feedbacklist', 'artefact/resume/resumeshowhide.js'),
159
    $stylesheets,
160
    array(),
161
162
163
164
    array(
        'stylesheets' => array('style/views.css'),
        'sidebars' => false,
    )
165
);
166

167
168
169
170
171
172
173
$javascript = <<<EOF
var viewid = {$viewid};
addLoadEvent(function () {
    paginator = {$feedback->pagination_js}
});
EOF;

Richard Mansfield's avatar
Richard Mansfield committed
174
$smarty->assign('INLINEJAVASCRIPT', $javascript);
175
$smarty->assign('new', $new);
176
$smarty->assign('viewid', $viewid);
177
$smarty->assign('viewtype', $viewtype);
178
$smarty->assign('feedback', $feedback);
Richard Mansfield's avatar
Richard Mansfield committed
179
180
$smarty->assign('owner', $owner);
$smarty->assign('tags', $view->get('tags'));
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
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

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

    if ($can_edit) {
        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);
230
    }
231
232
233
234
235
236
237
238

    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']);
            }
239
        }
240
241
    }
}
242

243
244
245
246
247
248
249
250
if ($viewtype != 'profile' && !get_config('viewmicroheaders')) {
    $title = $view->display_title();
}

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

251
252
253
254
255
256
257
258
259
260
261
262
263
// 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,
            ));
        }
    }
}
264

265
266
$smarty->assign('viewdescription', $view->get('description'));
$smarty->assign('viewcontent', $view->build_columns());
267
$smarty->assign('releaseform', $releaseform);
268
$smarty->assign('anonfeedback', $anonfeedback);
269
270
if (isset($addfeedbackform)) {
    $smarty->assign('addfeedbackform', $addfeedbackform);
271
}
272
273
if (isset($objectionform)) {
    $smarty->assign('objectionform', $objectionform);
274
}
275
$smarty->assign('viewbeingwatched', $viewbeingwatched);
276

277
278
279
$smarty->display('view/view.tpl');

?>