view.php 6.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');
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
}
Richard Mansfield's avatar
Richard Mansfield committed
68
$view = new View($viewid);
69

70
71
72
73
74
$group = $view->get('group');

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

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


function releaseview_submit() {
    global $USER, $SESSION, $view;
108
    $view->release($USER);
109
110
111
112
    $SESSION->add_ok_msg(get_string('viewreleasedsuccess', 'group'));
    redirect(get_config('wwwroot') . 'view/view.php?id='.$view->get('id'));
}
  
113
$viewbeingwatched = (int)record_exists('usr_watchlist_view', 'usr', $USER->get('id'), 'view', $viewid);
114

115
// Feedback 
116
$javascript = <<<EOF
117
feedbacklist.view = {$viewid};
118
feedbacklist.statevars.push('view');
119
feedbacklist.updateOnLoad();
120
EOF;
Richard Mansfield's avatar
Richard Mansfield committed
121

122
123
124
125
126
127
128
129
130

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

131
$can_edit = $USER->can_edit_view($view) && !$submittedgroup && !$view->is_submitted();
132

133
$smarty = smarty(
134
    array('mahara', 'tablerenderer', 'feedbacklist', 'artefact/resume/resumeshowhide.js'),
135
    array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">'),
136
    array(),
137
138
    array(
        'stylesheets' => array('style/views.css'),
139
        'sidebars' => false,
140
141
    )
);
142

Richard Mansfield's avatar
Richard Mansfield committed
143
$smarty->assign('INLINEJAVASCRIPT', $javascript);
144
$smarty->assign('new', $new);
145
146
$smarty->assign('viewid', $viewid);
$smarty->assign('viewtitle', $view->get('title'));
147
148

$owner = $view->get('owner');
Richard Mansfield's avatar
Richard Mansfield committed
149
150
$smarty->assign('owner', $owner);
$smarty->assign('tags', $view->get('tags'));
151
152
153
154
155
156
if ($owner) {
    $smarty->assign('ownerlink', 'user/view.php?id=' . $owner);
}
else if ($group) {
    $smarty->assign('ownerlink', 'group/view.php?id=' . $group);
}
157
158
159
160
161
162
163
164
165
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']);
    }
}
166

167
168
169
170
171
172
173
174
175
176
177
178
179
180
// 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,
            ));
        }
    }
}

181
$smarty->assign('ownername', $view->formatted_owner());
182
183
$smarty->assign('viewdescription', $view->get('description'));
$smarty->assign('viewcontent', $view->build_columns());
184
$smarty->assign('releaseform', $releaseform);
185
$smarty->assign('anonfeedback', $anonfeedback);
186
187
if (isset($addfeedbackform)) {
    $smarty->assign('addfeedbackform', $addfeedbackform);
188
}
189
190
if (isset($objectionform)) {
    $smarty->assign('objectionform', $objectionform);
191
}
192
$smarty->assign('viewbeingwatched', $viewbeingwatched);
193

194
195
196
$smarty->display('view/view.tpl');

?>