view.php 7.32 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
$can_edit = $USER->can_edit_view($view) && !$submittedgroup && !$view->is_submitted();
if ($can_edit) {
123
124
125
126
127
128
129
130
131
132
133
134
135
136
    $goto = get_config('wwwroot') . 'view/view.php?id=' . $viewid . ($new ? '&new=1' : '');
    $viewthemeform = $view->viewtheme_form($goto);
    //$smarty->assign('viewtheme', "$basetheme/$viewtheme");
    //$smarty->assign('viewthemes', View::get_viewthemes());
    /*$javascript .= <<<EOF
addLoadEvent(function () {
    var currentTheme = $('viewtheme-select').selectedIndex;
    connect($('viewtheme-select'), 'onchange', function(e) {
        if (this.selectedIndex != currentTheme && this.options[this.selectedIndex].value) {
            this.form.submit();
        };
    });
});
EOF;*/
137
}
138
139
140
141
142
143
144
145
146

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

147
148
149
150
151
152
153
154
155
156
157
158
159
// Set up theme
list($basetheme, $viewtheme) = $view->get_theme();
if ($THEME->basename != $basetheme) {
    $THEME = new Theme($basetheme);
}
$stylesheets = array(
    // Basic structure CSS
    '<link rel="stylesheet" type="text/css" href="'
        . get_config('wwwroot') . 'theme/views.css">',
    // Extra CSS for the view theme
    '<link rel="stylesheet" type="text/css" href="'
        . get_config('wwwroot') . 'theme/' . $basetheme . '/viewthemes/' . $viewtheme . '/views.css">',
);
160

161
$smarty = smarty(
162
    array('mahara', 'tablerenderer', 'feedbacklist', 'artefact/resume/resumeshowhide.js'),
163
    $stylesheets,
164
    array(),
165
    array('sidebars' => false)
166
);
167

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
173
174
175
176
177
178
179
180

$owner = $view->get('owner');
if ($owner) {
    $smarty->assign('ownerlink', 'user/view.php?id=' . $owner);
}
else if ($group) {
    $smarty->assign('ownerlink', 'group/view.php?id=' . $group);
}

181
182
183
184
185
if ($can_edit) {
    $smarty->assign('can_edit', 1);
    $smarty->assign('viewthemeform', $viewthemeform);
}

186
187
188
189
190
191
192
193
194
195
196
197
198
// 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,
            ));
        }
    }
}
199
200
201
if ($USER->is_logged_in() && !empty($_SERVER['HTTP_REFERER'])) {
    $smarty->assign('backurl', $_SERVER['HTTP_REFERER']);
}
202
$smarty->assign('ownername', $view->formatted_owner());
203
204
$smarty->assign('viewdescription', $view->get('description'));
$smarty->assign('viewcontent', $view->build_columns());
205
$smarty->assign('releaseform', $releaseform);
206
$smarty->assign('anonfeedback', $anonfeedback);
207
208
if (isset($addfeedbackform)) {
    $smarty->assign('addfeedbackform', $addfeedbackform);
209
}
210
211
if (isset($objectionform)) {
    $smarty->assign('objectionform', $objectionform);
212
}
213
$smarty->assign('viewbeingwatched', $viewbeingwatched);
214

215
216
217
$smarty->display('view/view.tpl');

?>