view.php 12.4 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
$tutorfilefeedbackformrow = '';
62
$submittedgroup = (int)$view->get('submittedto');
63
if ($submittedgroup && group_user_can_assess_submitted_views($submittedgroup, $USER->get('id'))) {
64
65
66
    // The user is a tutor of the group that this view has
    // been submitted to, and is entitled to upload an additional
    // file when submitting feedback.
Nigel McNie's avatar
Nigel McNie committed
67
    $tutorfilefeedbackformrow = "TR(null, TH(null, LABEL(null, '" . get_string('attachfile', 'view') . "'))),"
68
        . "TR(null, TD(null, INPUT({'type':'file', 'name':'attachment', 'onchange': 'process_public_checkbox(this)'}))),";
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
    $submittedgroup = get_record('group', 'id', $submittedgroup);
    $releaseform = pieform(array(
        'name'     => 'releaseview',
        'method'   => 'post',
        'plugintype' => 'core',
        'pluginname' => 'view',
        'elements' => array(
            'submittedview' => array(
                'type'  => 'html',
                'value' => get_string('viewsubmittedtogroup', 'view', $submittedgroup->id, $submittedgroup->name),
            ),
            'submit' => array(
                'type'  => 'submit',
                'value' => get_string('releaseview', 'group'),
            ),
        ),
    ));
86
}
87
88
89
90
91
92
93
94
95
96
97
98
99
else {
    $releaseform = '';
}


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'));
}

  
100
$viewbeingwatched = (int)record_exists('usr_watchlist_view', 'usr', $USER->get('id'), 'view', $viewid);
101

102
103
104
$getstring = quotestrings(array(
    'mahara' => array('message', 'cancel'),
    'view' => array('makepublic', 'placefeedback', 'complaint',
105
        'feedbackonthisartefactwillbeprivate', 'notifysiteadministrator',
Nigel McNie's avatar
Nigel McNie committed
106
        'nopublicfeedback', 'reportobjectionablematerial', 'print',
107
108
        'thisfeedbackispublic', 'thisfeedbackisprivate', 'attachment',
        'makeprivate')
109
));
110

111
112
113
$getstring['addtowatchlist'] = json_encode(get_string('addtowatchlist', 'view'));
$getstring['removefromwatchlist'] = json_encode(get_string('removefromwatchlist', 'view'));
$getstring['feedbackattachmessage'] = "'(" . get_string('feedbackattachmessage', 'view', get_string('feedbackattachdirname', 'view')) . ")'";
114

115
// Safari doesn't seem to like these inputs to be called 'public', so call them 'ispublic' instead.
116
if (!empty($feedbackisprivate)) {
117
    $makepublic = "TR(null, INPUT({'type':'hidden','name':'ispublic','value':'false'}), TD({'colspan':2}, " 
118
119
120
121
        . $getstring['feedbackonthisartefactwillbeprivate'] . ")),";
}
else {
    $makepublic = "TR(null, TH(null, LABEL(null, " . $getstring['makepublic'] . " ), " 
122
        . "INPUT({'type':'checkbox', 'class':'checkbox', 'name':'ispublic', 'id': 'ispublic'}))),";
123
124
}

125
$javascript = <<<EOF
Richard Mansfield's avatar
Richard Mansfield committed
126

127
var view = {$viewid};
Richard Mansfield's avatar
Richard Mansfield committed
128
129

function feedbackform() {
130
131
132
133
    if ($('menuform')) {
        removeElement('menuform');
    }
    var form = FORM({'id':'menuform','method':'post'});
Richard Mansfield's avatar
Richard Mansfield committed
134
    submitfeedback = function () {
135
        if (form.attachment && form.attachment.value) {
136
137
138
139
140
141
142
            updateNodeAttributes(form, {'enctype':'multipart/form-data',
                                        'encoding':'multipart/form-data',
                                        'action':'feedbackattachment.php', 'target':''});
            appendChildNodes(form, INPUT({'type':'hidden', 'name':'view', 'value':view}));
            appendChildNodes(form, INPUT({'type':'hidden', 'name':'filename', 
                                          'value':basename(form.attachment.value)}));
            form.submit();
143
        }
144
145
        else {
            var data = {'view':view, 
146
147
                        'public':form.ispublic.checked,
                        'message':form.message.value};
148
            sendjsonrequest('addfeedback.json.php', data, 'POST', function () { 
149
                removeElement('menuform');
150
                feedbacklist.doupdate();
151
            });
152
153
            return false;
        }
Richard Mansfield's avatar
Richard Mansfield committed
154
155
    }
    appendChildNodes(form, 
156
        TABLE({'border':0, 'cellspacing':0, 'id':'feedback'},
Richard Mansfield's avatar
Richard Mansfield committed
157
158
159
        TBODY(null,
        TR(null, TH(null, LABEL(null, {$getstring['message']}))),
        TR(null, TD(null, TEXTAREA({'rows':5, 'cols':80, 'name':'message'}))),
160
        {$makepublic}
161
        {$tutorfilefeedbackformrow}
Richard Mansfield's avatar
Richard Mansfield committed
162
        TR(null, TD(null,
Richard Mansfield's avatar
Richard Mansfield committed
163
164
                    INPUT({'type':'button', 'class':'button', 
                               'value':{$getstring['placefeedback']},
Richard Mansfield's avatar
Richard Mansfield committed
165
                               'onclick':'submitfeedback();'}),
Richard Mansfield's avatar
Richard Mansfield committed
166
                    INPUT({'type':'button', 'class':'button', 'value':{$getstring['cancel']},
167
                               'onclick':"removeElement('menuform');"}))))));
Richard Mansfield's avatar
Richard Mansfield committed
168
    appendChildNodes('viewmenu', DIV(null, form));
169
    form.message.focus();
Richard Mansfield's avatar
Richard Mansfield committed
170
171
172
173
    return false;
}

function objectionform() {
174
175
176
177
    if ($('menuform')) {
        removeElement('menuform');
    }
    var form = FORM({'id':'menuform','method':'post'});
Richard Mansfield's avatar
Richard Mansfield committed
178
    submitobjection = function () {
179
        var data = {'view':view, 'message':form.message.value};
180
        sendjsonrequest('objectionable.json.php', data, 'POST', function () { removeElement('menuform'); });
Richard Mansfield's avatar
Richard Mansfield committed
181
182
183
        return false;
    }
    appendChildNodes(form, 
184
        TABLE({'border':0, 'cellspacing':0, 'id':'objection'},
Richard Mansfield's avatar
Richard Mansfield committed
185
186
187
188
        TBODY(null,
        TR(null, TH(null, LABEL(null, {$getstring['complaint']}))),
        TR(null, TD(null, TEXTAREA({'rows':5, 'cols':80, 'name':'message'}))),
        TR(null, TD(null,
Richard Mansfield's avatar
Richard Mansfield committed
189
190
                    INPUT({'type':'button', 'class':'button', 
                               'value':{$getstring['notifysiteadministrator']},
Richard Mansfield's avatar
Richard Mansfield committed
191
                               'onclick':'submitobjection();'}),
Richard Mansfield's avatar
Richard Mansfield committed
192
                    INPUT({'type':'button', 'class':'button', 'value':{$getstring['cancel']},
193
                               'onclick':"removeElement('menuform');"}))))));
Richard Mansfield's avatar
Richard Mansfield committed
194
    appendChildNodes('viewmenu', DIV(null, form));
195
    form.message.focus();
Richard Mansfield's avatar
Richard Mansfield committed
196
197
198
    return false;
}

199
function view_menu() {
200
201
202
203
204
205
206
207
    if (config.loggedin) {
        appendChildNodes('viewmenu',
            A({'href':'', 'onclick':"return feedbackform();"}, 
                {$getstring['placefeedback']}), ' | ',
            A({'href':'', 'onclick':'return objectionform();'},
               {$getstring['reportobjectionablematerial']}), ' | '
        );
    }
Richard Mansfield's avatar
Richard Mansfield committed
208
    appendChildNodes('viewmenu',
209
210
211
        A({'href':'', 'onclick':'window.print();return false;'}, 
            {$getstring['print']})
    );
212
    if (config.loggedin) {
213
214
215
216
217
218
219
220
221
222
223
        var linkTextFlag = {$viewbeingwatched};
        var linkText = [{$getstring['addtowatchlist']}, {$getstring['removefromwatchlist']}];
        link = A({'href': ''}, linkText[linkTextFlag]);
        connect(link, 'onclick', function(e) {
            var data = {'view': view};
            sendjsonrequest('togglewatchlist.json.php', data, 'POST', function() {
                link.innerHTML = linkText[++linkTextFlag % 2];
            });
            e.stop();
        });
        appendChildNodes('viewmenu', ' | ', link);
224
225
226
227

        var helpIcon = contextualHelpIcon(null, null, 'core', 'view', null, 'viewmenu');
        appendChildNodes('viewmenu', ' ', helpIcon);

228
     }
229

Richard Mansfield's avatar
Richard Mansfield committed
230
231
}

232
233
addLoadEvent(view_menu);

234
// The list of existing feedback.
Nigel McNie's avatar
Nigel McNie committed
235
var feedbacklist = new TableRenderer('feedbacktable', 'getfeedback.json.php', []);
236

237
feedbacklist.limit = 10;
Nigel McNie's avatar
Nigel McNie committed
238
239
240
241
242
243
244
245
246
247
248
feedbacklist.rowfunction = function(r, n, d) {
    var td = TD(null);
    td.innerHTML = r.message;
    if (r.attachid && r.ownedbythisuser) {
        appendChildNodes(td, DIV(null, {$getstring['feedbackattachmessage']}));
    }

    var publicPrivate = null;
    if (r.ispublic == 1) {
        var makePrivate = null;
        if (r.ownedbythisuser) {
249
250
            makePrivateLink = A({'href': ''}, {$getstring['makeprivate']});
            connect(makePrivateLink, 'onclick', function (e) {
Nigel McNie's avatar
Nigel McNie committed
251
252
253
254
255
256
                sendjsonrequest(
                    'changefeedback.json.php',
                    r,
                    'POST',
                    function (data) {
                        if (!data.error) {
257
                            replaceChildNodes(makePrivateLink.parentNode, {$getstring['thisfeedbackisprivate']});
Nigel McNie's avatar
Nigel McNie committed
258
259
260
261
262
263
                        }
                    }
                );

                e.stop();
            });
264
            makePrivate = [' - ', makePrivateLink];
Nigel McNie's avatar
Nigel McNie committed
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
        }
        publicPrivate = SPAN(null, {$getstring['thisfeedbackispublic']}, makePrivate);
    }
    else {
        publicPrivate = {$getstring['thisfeedbackisprivate']};
    }

    var attachment = null;
    if (r.attachid) {
        attachment = [' | ', {$getstring['attachment']}, ': ', A({'href':config.wwwroot + 'artefact/file/download.php?file=' + r.attachid}, r.attachtitle), ' (', r.attachsize, ')'];
    }

    var icon = A({'href': config.wwwroot + 'user/view.php?id=' + r.author}, IMG({'src': config.wwwroot + 'thumb.php?type=profileicon&id=' + r.author + '&maxsize=20', 'valign': 'middle'}));
    appendChildNodes(td, DIV({'class': 'details'}, DIV({'class': 'icon'}, icon), A({'href': config.wwwroot + 'user/view.php?id=' + r.author}, r.name), ' | ', r.date, ' | ', publicPrivate, attachment));

    return TR({'class': 'r' + (n % 2)}, td);
};
282
feedbacklist.view = view;
283
feedbacklist.statevars.push('view');
284
feedbacklist.emptycontent = {$getstring['nopublicfeedback']};
285
286
feedbacklist.updateOnLoad();

Richard Mansfield's avatar
Richard Mansfield committed
287

288
289
290
291
292
293
294
295
296
297
298
299
300
function process_public_checkbox(input) {
    var checkbox = $('ispublic');
    if (input.value != '') {
        log('making public checkbox not checked and disabled');
        checkbox.checked = false;
        checkbox.disabled = 'disabled';
    }
    else {
        log('making public checkbox enabled');
        checkbox.disabled = '';
    }
}

301
EOF;
Richard Mansfield's avatar
Richard Mansfield committed
302

303
304
$smarty = smarty(
    array('tablerenderer'),
305
    array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">'),
306
    array(),
307
308
    array(
        'stylesheets' => array('style/views.css'),
309
310
    )
);
311

Richard Mansfield's avatar
Richard Mansfield committed
312
$smarty->assign('INLINEJAVASCRIPT', $javascript);
313
$smarty->assign('new', $new);
314
315
$smarty->assign('viewid', $viewid);
$smarty->assign('viewtitle', $view->get('title'));
316
317
318
319
320
321
322
323
324
325
326
327
328
329

$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'));
330
331
$smarty->assign('viewdescription', $view->get('description'));
$smarty->assign('viewcontent', $view->build_columns());
332
$smarty->assign('releaseform', $releaseform);
333

334
335
336
$smarty->display('view/view.tpl');

?>