view.php 7.42 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');
Penny Leach's avatar
Penny Leach committed
35
require(get_config('libroot') . 'view.php');
36
require('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('mviewaccess:'.$viewid)) {
        set_cookie('mviewaccess:'.$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
82
83
84
$group = $view->get('group');

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

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


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

131
132
$feedback = $view->get_feedback($limit, $offset);
build_feedback_html($feedback);
133
134
135
136
137
138
139
140
141

$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());
}

142
// Set up theme
143
144
145
$viewtheme = $view->get('theme');
if ($viewtheme && $THEME->basename != $viewtheme) {
    $THEME = new Theme($viewtheme);
146
}
147
148
$stylesheets = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">');

149
$can_edit = $USER->can_edit_view($view) && !$submittedgroup && !$view->is_submitted();
150

151
$smarty = smarty(
152
    array('paginator', 'feedbacklist', 'artefact/resume/resumeshowhide.js'),
153
    $stylesheets,
154
    array(),
155
156
157
158
    array(
        'stylesheets' => array('style/views.css'),
        'sidebars' => false,
    )
159
);
160

161
162
163
164
165
166
167
$javascript = <<<EOF
var viewid = {$viewid};
addLoadEvent(function () {
    paginator = {$feedback->pagination_js}
});
EOF;

Richard Mansfield's avatar
Richard Mansfield committed
168
$smarty->assign('INLINEJAVASCRIPT', $javascript);
169
$smarty->assign('new', $new);
170
171
$smarty->assign('viewid', $viewid);
$smarty->assign('viewtitle', $view->get('title'));
172
$smarty->assign('feedback', $feedback);
173
174

$owner = $view->get('owner');
Richard Mansfield's avatar
Richard Mansfield committed
175
176
$smarty->assign('owner', $owner);
$smarty->assign('tags', $view->get('tags'));
177
178
179
180
if ($owner) {
    $smarty->assign('ownerlink', 'user/view.php?id=' . $owner);
}
else if ($group) {
181
    $smarty->assign('ownerlink', 'group/view.php?id=' . $group);
182
}
183
184
185
186
187
188
189
190
191
if ($can_edit) {
    $smarty->assign('can_edit', 1);
}
if ($USER->is_logged_in() && !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']);
    }
}
192

193
194
195
196
197
198
199
200
201
202
203
204
205
// 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,
            ));
        }
    }
}
206

207
$smarty->assign('ownername', $view->formatted_owner());
208
209
$smarty->assign('viewdescription', $view->get('description'));
$smarty->assign('viewcontent', $view->build_columns());
210
$smarty->assign('releaseform', $releaseform);
211
$smarty->assign('anonfeedback', $anonfeedback);
212
213
if (isset($addfeedbackform)) {
    $smarty->assign('addfeedbackform', $addfeedbackform);
214
}
215
216
if (isset($objectionform)) {
    $smarty->assign('objectionform', $objectionform);
217
}
218
$smarty->assign('viewbeingwatched', $viewbeingwatched);
219

220
221
222
$smarty->display('view/view.tpl');

?>