view.php 6.31 KB
Newer Older
1
2
<?php
/**
Francois Marier's avatar
Francois Marier committed
3
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
4
 * Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
5
 *
Francois Marier's avatar
Francois Marier committed
6
7
8
9
 * 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.
10
 *
Francois Marier's avatar
Francois Marier committed
11
12
13
14
 * 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.
15
 *
Francois Marier's avatar
Francois Marier committed
16
17
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19
20
 *
 * @package    mahara
 * @subpackage core
21
 * @author     Catalyst IT Ltd
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
23
 * @copyright  (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
24
25
26
27
 *
 */

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

33
require(dirname(dirname(__FILE__)) . '/init.php');
Penny Leach's avatar
Penny Leach committed
34
require(get_config('libroot') . 'view.php');
35
require('group.php');
36

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

64
65
if (!can_view_view($viewid, null, $usertoken, $mnettoken)) {
    throw new AccessDeniedException(get_string('accessdenied', 'error'));
66
}
Richard Mansfield's avatar
Richard Mansfield committed
67
$view = new View($viewid);
68

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

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

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


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

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

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

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

$owner = $view->get('owner');
if ($owner) {
    $smarty->assign('ownerlink', 'user/view.php?id=' . $owner);
    if ($USER->get('id') == $owner) {
150
        $smarty->assign('can_edit', !$submittedgroup && !$view->is_submitted());
151
152
153
154
155
156
    }
}
else if ($group) {
    $smarty->assign('ownerlink', 'group/view.php?id=' . $group);
}

157
158
159
160
161
162
163
164
165
166
167
168
169
170
// 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,
            ));
        }
    }
}

171
172
$smarty->assign('ownername', $view->formatted_owner());
$smarty->assign('streditviewbutton', ($new) ? get_string('backtocreatemyview', 'view') : get_string('editmyview', 'view'));
173
174
$smarty->assign('viewdescription', $view->get('description'));
$smarty->assign('viewcontent', $view->build_columns());
175
$smarty->assign('releaseform', $releaseform);
176
$smarty->assign('anonfeedback', $anonfeedback);
177
178
if (isset($addfeedbackform)) {
    $smarty->assign('addfeedbackform', $addfeedbackform);
179
}
180
181
if (isset($objectionform)) {
    $smarty->assign('objectionform', $objectionform);
182
}
183
$smarty->assign('viewbeingwatched', $viewbeingwatched);
184

185
186
187
$smarty->display('view/view.tpl');

?>