view.php 11.3 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
$viewid = param_integer('id');
38
39
$new = param_boolean('new');

40
$view = new View($viewid);
Penny Leach's avatar
Penny Leach committed
41
42
if (!can_view_view($viewid)) {
    throw new AccessDeniedException();
43
}
44

45
46
47
48
49
$group = $view->get('group');

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

50
if ($new) {
51
    $heading = hsc($title);
52
53
}
else {
54
55
56
57
58
59
    $heading = '<a href="' . get_config('wwwroot') . 'view/view.php?id=' . $view->get('id') .'">' . hsc($title) . '</a>';
}

if (!$group) { 
    $title .= ' ' . get_string('by', 'view') . ' ' . $view->formatted_owner();
    $heading .= ' ' . get_string('by', 'view') . ' <a href="' . get_config('wwwroot') .'user/view.php?id=' . $view->get('owner'). '">' . $view->formatted_owner() . '</a>';
60
}
61

62

63
$tutorfilefeedbackformrow = '';
64
$submittedgroup = (int)$view->get('submittedto');
65
if ($submittedgroup && can_assess_submitted_views($USER->get('id'), $submittedgroup)) {
66
67
68
    // 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
69
    $tutorfilefeedbackformrow = "TR(null, TH(null, LABEL(null, '" . get_string('attachfile', 'view') . "'))),"
70
        . "TR(null, TD(null, INPUT({'type':'file', 'name':'attachment', 'onchange': 'process_public_checkbox(this)'}))),";
71
}
72
$viewbeingwatched = (int)record_exists('usr_watchlist_view', 'usr', $USER->get('id'), 'view', $viewid);
73

74
75
76
$getstring = quotestrings(array(
    'mahara' => array('message', 'cancel'),
    'view' => array('makepublic', 'placefeedback', 'complaint',
77
        'feedbackonthisartefactwillbeprivate', 'notifysiteadministrator',
Nigel McNie's avatar
Nigel McNie committed
78
        'nopublicfeedback', 'reportobjectionablematerial', 'print',
79
80
        'thisfeedbackispublic', 'thisfeedbackisprivate', 'attachment',
        'makeprivate')
81
));
82

83
84
85
$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')) . ")'";
86

87
// Safari doesn't seem to like these inputs to be called 'public', so call them 'ispublic' instead.
88
if (!empty($feedbackisprivate)) {
89
    $makepublic = "TR(null, INPUT({'type':'hidden','name':'ispublic','value':'false'}), TD({'colspan':2}, " 
90
91
92
93
        . $getstring['feedbackonthisartefactwillbeprivate'] . ")),";
}
else {
    $makepublic = "TR(null, TH(null, LABEL(null, " . $getstring['makepublic'] . " ), " 
94
        . "INPUT({'type':'checkbox', 'class':'checkbox', 'name':'ispublic', 'id': 'ispublic'}))),";
95
96
}

97
$javascript = <<<EOF
Richard Mansfield's avatar
Richard Mansfield committed
98

99
var view = {$viewid};
Richard Mansfield's avatar
Richard Mansfield committed
100
101

function feedbackform() {
102
103
104
105
    if ($('menuform')) {
        removeElement('menuform');
    }
    var form = FORM({'id':'menuform','method':'post'});
Richard Mansfield's avatar
Richard Mansfield committed
106
    submitfeedback = function () {
107
        if (form.attachment && form.attachment.value) {
108
109
110
111
112
113
114
            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();
115
        }
116
117
        else {
            var data = {'view':view, 
118
119
                        'public':form.ispublic.checked,
                        'message':form.message.value};
120
            sendjsonrequest('addfeedback.json.php', data, 'POST', function () { 
121
                removeElement('menuform');
122
                feedbacklist.doupdate();
123
            });
124
125
            return false;
        }
Richard Mansfield's avatar
Richard Mansfield committed
126
127
    }
    appendChildNodes(form, 
128
        TABLE({'border':0, 'cellspacing':0, 'id':'feedback'},
Richard Mansfield's avatar
Richard Mansfield committed
129
130
131
        TBODY(null,
        TR(null, TH(null, LABEL(null, {$getstring['message']}))),
        TR(null, TD(null, TEXTAREA({'rows':5, 'cols':80, 'name':'message'}))),
132
        {$makepublic}
133
        {$tutorfilefeedbackformrow}
Richard Mansfield's avatar
Richard Mansfield committed
134
        TR(null, TD(null,
Richard Mansfield's avatar
Richard Mansfield committed
135
136
                    INPUT({'type':'button', 'class':'button', 
                               'value':{$getstring['placefeedback']},
Richard Mansfield's avatar
Richard Mansfield committed
137
                               'onclick':'submitfeedback();'}),
Richard Mansfield's avatar
Richard Mansfield committed
138
                    INPUT({'type':'button', 'class':'button', 'value':{$getstring['cancel']},
139
                               'onclick':"removeElement('menuform');"}))))));
Richard Mansfield's avatar
Richard Mansfield committed
140
    appendChildNodes('viewmenu', DIV(null, form));
141
    form.message.focus();
Richard Mansfield's avatar
Richard Mansfield committed
142
143
144
145
    return false;
}

function objectionform() {
146
147
148
149
    if ($('menuform')) {
        removeElement('menuform');
    }
    var form = FORM({'id':'menuform','method':'post'});
Richard Mansfield's avatar
Richard Mansfield committed
150
    submitobjection = function () {
151
        var data = {'view':view, 'message':form.message.value};
152
        sendjsonrequest('objectionable.json.php', data, 'POST', function () { removeElement('menuform'); });
Richard Mansfield's avatar
Richard Mansfield committed
153
154
155
        return false;
    }
    appendChildNodes(form, 
156
        TABLE({'border':0, 'cellspacing':0, 'id':'objection'},
Richard Mansfield's avatar
Richard Mansfield committed
157
158
159
160
        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
161
162
                    INPUT({'type':'button', 'class':'button', 
                               'value':{$getstring['notifysiteadministrator']},
Richard Mansfield's avatar
Richard Mansfield committed
163
                               'onclick':'submitobjection();'}),
Richard Mansfield's avatar
Richard Mansfield committed
164
                    INPUT({'type':'button', 'class':'button', 'value':{$getstring['cancel']},
165
                               'onclick':"removeElement('menuform');"}))))));
Richard Mansfield's avatar
Richard Mansfield committed
166
    appendChildNodes('viewmenu', DIV(null, form));
167
    form.message.focus();
Richard Mansfield's avatar
Richard Mansfield committed
168
169
170
    return false;
}

171
function view_menu() {
172
173
174
175
176
177
178
179
    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
180
    appendChildNodes('viewmenu',
181
182
183
        A({'href':'', 'onclick':'window.print();return false;'}, 
            {$getstring['print']})
    );
184
    if (config.loggedin) {
185
186
187
188
189
190
191
192
193
194
195
        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);
196
197
198
199

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

200
     }
201

Richard Mansfield's avatar
Richard Mansfield committed
202
203
}

204
205
addLoadEvent(view_menu);

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

209
feedbacklist.limit = 10;
Nigel McNie's avatar
Nigel McNie committed
210
211
212
213
214
215
216
217
218
219
220
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) {
221
222
            makePrivateLink = A({'href': ''}, {$getstring['makeprivate']});
            connect(makePrivateLink, 'onclick', function (e) {
Nigel McNie's avatar
Nigel McNie committed
223
224
225
226
227
228
                sendjsonrequest(
                    'changefeedback.json.php',
                    r,
                    'POST',
                    function (data) {
                        if (!data.error) {
229
                            replaceChildNodes(makePrivateLink.parentNode, {$getstring['thisfeedbackisprivate']});
Nigel McNie's avatar
Nigel McNie committed
230
231
232
233
234
235
                        }
                    }
                );

                e.stop();
            });
236
            makePrivate = [' - ', makePrivateLink];
Nigel McNie's avatar
Nigel McNie committed
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
        }
        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);
};
254
feedbacklist.view = view;
255
feedbacklist.statevars.push('view');
256
feedbacklist.emptycontent = {$getstring['nopublicfeedback']};
257
258
feedbacklist.updateOnLoad();

Richard Mansfield's avatar
Richard Mansfield committed
259

260
261
262
263
264
265
266
267
268
269
270
271
272
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 = '';
    }
}

273
EOF;
Richard Mansfield's avatar
Richard Mansfield committed
274

275
276
$smarty = smarty(
    array('tablerenderer'),
277
    array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">'),
278
    array(),
279
280
    array(
        'stylesheets' => array('style/views.css'),
281
282
    )
);
283
$smarty->assign('heading', $heading);
Richard Mansfield's avatar
Richard Mansfield committed
284
$smarty->assign('INLINEJAVASCRIPT', $javascript);
285
286
287
288
$smarty->assign('viewid', $viewid);
$smarty->assign('viewtitle', $view->get('title'));
$smarty->assign('viewdescription', $view->get('description'));
$smarty->assign('viewcontent', $view->build_columns());
289
$smarty->assign('streditviewbutton', ($new) ? get_string('backtocreatemyview', 'view') : get_string('editmyview', 'view'));
290

291
if ($USER->get('id') == $view->get('owner')) {
292
    $smarty->assign('can_edit', !$view->get('submittedto'));
293
    $smarty->assign('new', $new);
294
}
295
296
297
$smarty->display('view/view.tpl');

?>