view.php 10 KB
Newer Older
1
2
<?php
/**
Francois Marier's avatar
Francois Marier committed
3
4
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
 * Copyright (C) 2006-2007 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
21
22
23
24
25
26
27
 *
 * @package    mahara
 * @subpackage core
 * @author     Richard Mansfield <richard.mansfield@catalyst.net.nz>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
 *
 */

define('INTERNAL', 1);
28
define('PUBLIC', 1);
29
require(dirname(dirname(__FILE__)) . '/init.php');
Penny Leach's avatar
Penny Leach committed
30
require(get_config('libroot') . 'view.php');
31

32
$viewid = param_integer('id');
33
$view = new View($viewid);
Penny Leach's avatar
Penny Leach committed
34
35
if (!can_view_view($viewid)) {
    throw new AccessDeniedException();
36
}
37

38
define('TITLE', $view->get('title') . ' ' . get_string('by', 'view') . ' ' . $view->formatted_owner());
39

40
$tutorfilefeedbackformrow = '';
41
42
43
44
45
46
47
48
49
50
51
$submittedgroup = $view->get('submittedto');
if ($submittedgroup 
    && record_exists('group_member', 
                     'group', $submittedgroup,
                     'member', $USER->get('id'),
                     'tutor', 1)) {
    // 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.
    $tutorfilefeedbackformrow = "TR(null, TH(null, LABEL(null, '" . get_string('attachfile') . "'))),"
        . "TR(null, TD(null, INPUT({'type':'file', 'name':'attachment'}))),";
52
}
53
$viewbeingwatched = (int)record_exists('usr_watchlist_view', 'usr', $USER->get('id'), 'view', $viewid);
54

55
56
57
$getstring = quotestrings(array(
    'mahara' => array('message', 'cancel'),
    'view' => array('makepublic', 'placefeedback', 'complaint',
58
        'feedbackonthisartefactwillbeprivate', 'notifysiteadministrator',
59
60
        'nopublicfeedback', 'reportobjectionablematerial', 'print')
));
61

62
63
64
$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')) . ")'";
65

66
// Safari doesn't seem to like these inputs to be called 'public', so call them 'ispublic' instead.
67
if (!empty($feedbackisprivate)) {
68
    $makepublic = "TR(null, INPUT({'type':'hidden','name':'ispublic','value':'false'}), TD({'colspan':2}, " 
69
70
71
72
        . $getstring['feedbackonthisartefactwillbeprivate'] . ")),";
}
else {
    $makepublic = "TR(null, TH(null, LABEL(null, " . $getstring['makepublic'] . " ), " 
73
        . "INPUT({'type':'checkbox', 'class':'checkbox', 'name':'ispublic'}))),";
74
75
}

76
$javascript = <<<EOF
Richard Mansfield's avatar
Richard Mansfield committed
77

78
var view = {$viewid};
Richard Mansfield's avatar
Richard Mansfield committed
79
80

function feedbackform() {
81
82
83
84
    if ($('menuform')) {
        removeElement('menuform');
    }
    var form = FORM({'id':'menuform','method':'post'});
Richard Mansfield's avatar
Richard Mansfield committed
85
    submitfeedback = function () {
86
        if (form.attachment && form.attachment.value) {
87
88
89
90
91
92
93
            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();
94
        }
95
96
        else {
            var data = {'view':view, 
97
98
                        'public':form.ispublic.checked,
                        'message':form.message.value};
99
            sendjsonrequest('addfeedback.json.php', data, 'POST', function () { 
100
                removeElement('menuform');
101
                feedbacklist.doupdate();
102
            });
103
104
            return false;
        }
Richard Mansfield's avatar
Richard Mansfield committed
105
106
    }
    appendChildNodes(form, 
107
        TABLE({'border':0, 'cellspacing':0, 'id':'feedback'},
Richard Mansfield's avatar
Richard Mansfield committed
108
109
110
        TBODY(null,
        TR(null, TH(null, LABEL(null, {$getstring['message']}))),
        TR(null, TD(null, TEXTAREA({'rows':5, 'cols':80, 'name':'message'}))),
111
        {$makepublic}
112
        {$tutorfilefeedbackformrow}
Richard Mansfield's avatar
Richard Mansfield committed
113
        TR(null, TD(null,
Richard Mansfield's avatar
Richard Mansfield committed
114
115
                    INPUT({'type':'button', 'class':'button', 
                               'value':{$getstring['placefeedback']},
Richard Mansfield's avatar
Richard Mansfield committed
116
                               'onclick':'submitfeedback();'}),
Richard Mansfield's avatar
Richard Mansfield committed
117
                    INPUT({'type':'button', 'class':'button', 'value':{$getstring['cancel']},
118
                               'onclick':"removeElement('menuform');"}))))));
Richard Mansfield's avatar
Richard Mansfield committed
119
    appendChildNodes('viewmenu', DIV(null, form));
120
    form.message.focus();
Richard Mansfield's avatar
Richard Mansfield committed
121
122
123
124
    return false;
}

function objectionform() {
125
126
127
128
    if ($('menuform')) {
        removeElement('menuform');
    }
    var form = FORM({'id':'menuform','method':'post'});
Richard Mansfield's avatar
Richard Mansfield committed
129
    submitobjection = function () {
130
        var data = {'view':view, 'message':form.message.value};
131
        sendjsonrequest('objectionable.json.php', data, 'POST', function () { removeElement('menuform'); });
Richard Mansfield's avatar
Richard Mansfield committed
132
133
134
        return false;
    }
    appendChildNodes(form, 
135
        TABLE({'border':0, 'cellspacing':0, 'id':'objection'},
Richard Mansfield's avatar
Richard Mansfield committed
136
137
138
139
        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
140
141
                    INPUT({'type':'button', 'class':'button', 
                               'value':{$getstring['notifysiteadministrator']},
Richard Mansfield's avatar
Richard Mansfield committed
142
                               'onclick':'submitobjection();'}),
Richard Mansfield's avatar
Richard Mansfield committed
143
                    INPUT({'type':'button', 'class':'button', 'value':{$getstring['cancel']},
144
                               'onclick':"removeElement('menuform');"}))))));
Richard Mansfield's avatar
Richard Mansfield committed
145
    appendChildNodes('viewmenu', DIV(null, form));
146
    form.message.focus();
Richard Mansfield's avatar
Richard Mansfield committed
147
148
149
    return false;
}

150
function view_menu() {
151
152
153
154
155
156
157
158
    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
159
    appendChildNodes('viewmenu',
160
161
162
        A({'href':'', 'onclick':'window.print();return false;'}, 
            {$getstring['print']})
    );
163
    if (config.loggedin) {
164
165
166
167
168
169
170
171
172
173
174
        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);
175
     }
176

Richard Mansfield's avatar
Richard Mansfield committed
177
178
}

179
180
addLoadEvent(view_menu);

181
// The list of existing feedback.
182
183
184
var feedbacklist = new TableRenderer(
    'feedbacktable',
    'getfeedback.json.php',
185
    [
186
        function (r) {
187
188
            var td = TD(null);
            td.innerHTML = r.message;
189
            if (r.attachid && r.ownedbythisuser) {
190
191
                appendChildNodes(td, DIV(null, {$getstring['feedbackattachmessage']}));
                return td;
192
            }
193
            return td;
194
        },
195
196
197
        'name',
        'date', 
        function (r) {
198
            if (r.ispublic == 1) {
199
200
201
202
203
204
205
                var makePrivate = null;
                if (r.ownedbythisuser) {
                    makePrivate = A({'href': ''}, get_string('makeprivate'));
                    connect(makePrivate, 'onclick', function (e) {
                        sendjsonrequest(
                            'changefeedback.json.php',
                            r,
206
                            'POST',
207
208
209
210
211
212
213
214
215
216
217
218
219
220
                            function (data) {
                                if (!data.error) {
                                    replaceChildNodes(makePrivate.parentNode, '(' + get_string('private') + ')');
                                }
                            }
                        );

                        e.stop();
                    });
                }
                return TD(null, '(' + get_string('public') + ') ', makePrivate);
            }
            return TD(null, '(' + get_string('private') + ')');
        },
221
222
223
224
225
226
227
        function (r) {
            if (r.attachid) {
                return TD(null, A({'href':config.wwwroot + 'artefact/file/download.php?file=' + r.attachid},
                                  r.attachtitle));
            }
            return TD(null);
        }
228
    ]
229
230
);

231
feedbacklist.limit = 10;
232
feedbacklist.view = view;
233
feedbacklist.statevars.push('view');
234
feedbacklist.emptycontent = {$getstring['nopublicfeedback']};
235
236
feedbacklist.updateOnLoad();

Richard Mansfield's avatar
Richard Mansfield committed
237

238
EOF;
Richard Mansfield's avatar
Richard Mansfield committed
239

240
241
$smarty = smarty(
    array('tablerenderer'),
242
    array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">'),
243
    array(
244
        'view' => array(
245
246
247
248
            'public',
            'private',
            'makeprivate',
        ),
249
250
251
    ),
    array(
        'stylesheets' => array('style/views.css'),
252
253
    )
);
254

Richard Mansfield's avatar
Richard Mansfield committed
255
$smarty->assign('INLINEJAVASCRIPT', $javascript);
256
257
258
259
260
261
262
$smarty->assign('viewid', $viewid);
$smarty->assign('viewtitle', $view->get('title'));
$smarty->assign('viewdescription', $view->get('description'));
$smarty->assign('viewcontent', $view->build_columns());
$smarty->assign('viewowner', $view->get('owner'));
$smarty->assign('formattedowner', $view->formatted_owner());

263
264
265
if ($USER->get('id') == $view->get('owner')) {
    $smarty->assign('can_edit', true);
}
266
267
268
$smarty->display('view/view.tpl');

?>