view.php 4.93 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

Richard Mansfield's avatar
Richard Mansfield committed
37
38
39
40
41
42
43
44
45
46
47
48
$viewtoken = get_config('allowpublicviews') ? param_alphanum('t', null) : null;
if ($viewtoken) {
    if (!$viewid = get_view_from_token($viewtoken)) {
        throw new AccessDeniedException();
    }
    if ($viewtoken != get_cookie('viewaccess:'.$viewid)) {
        set_cookie('viewaccess:'.$viewid, $viewtoken);
    }
}
else {
    $viewid = param_integer('id');
}
49
50
$new = param_boolean('new');

Richard Mansfield's avatar
Richard Mansfield committed
51
if (!can_view_view($viewid, null, $viewtoken)) {
Penny Leach's avatar
Penny Leach committed
52
    throw new AccessDeniedException();
53
}
Richard Mansfield's avatar
Richard Mansfield committed
54
$view = new View($viewid);
55

56
57
58
59
60
$group = $view->get('group');

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

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


function releaseview_submit() {
    global $USER, $SESSION, $view;
    $view->release($view->get('submittedto'), $USER);
    $SESSION->add_ok_msg(get_string('viewreleasedsuccess', 'group'));
    redirect(get_config('wwwroot') . 'view/view.php?id='.$view->get('id'));
}
  
99
$viewbeingwatched = (int)record_exists('usr_watchlist_view', 'usr', $USER->get('id'), 'view', $viewid);
100

101
// Feedback 
102
$javascript = <<<EOF
103
feedbacklist.view = {$viewid};
104
feedbacklist.statevars.push('view');
105
feedbacklist.updateOnLoad();
106
EOF;
Richard Mansfield's avatar
Richard Mansfield committed
107

108
$smarty = smarty(
109
    array('mahara', 'tablerenderer', 'feedbacklist', 'artefact/resume/resumeshowhide.js'),
110
    array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">'),
111
    array(),
112
113
    array(
        'stylesheets' => array('style/views.css'),
114
115
    )
);
116

Richard Mansfield's avatar
Richard Mansfield committed
117
$smarty->assign('INLINEJAVASCRIPT', $javascript);
118
$smarty->assign('new', $new);
119
120
$smarty->assign('viewid', $viewid);
$smarty->assign('viewtitle', $view->get('title'));
121
122
123
124
125
126
127
128
129
130
131
132
133
134

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

$smarty->assign('ownername', $view->formatted_owner());
$smarty->assign('streditviewbutton', ($new) ? get_string('backtocreatemyview', 'view') : get_string('editmyview', 'view'));
135
136
$smarty->assign('viewdescription', $view->get('description'));
$smarty->assign('viewcontent', $view->build_columns());
137
$smarty->assign('releaseform', $releaseform);
138
139
140
141
$smarty->assign('anonfeedback', !$USER->is_logged_in() && ($viewtoken || $viewid == get_view_from_token(get_cookie('viewaccess:'.$viewid))));
$smarty->assign('addfeedbackform', pieform(add_feedback_form($allowattachments)));
$smarty->assign('objectionform', pieform(objection_form()));
$smarty->assign('viewbeingwatched', $viewbeingwatched);
142

143
144
145
$smarty->display('view/view.tpl');

?>