view.php 10.6 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
21
22
 *
 * @package    mahara
 * @subpackage core
 * @author     Richard Mansfield <richard.mansfield@catalyst.net.nz>
 * @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

36
$viewid = param_integer('id');
37
38
$new = param_boolean('new');

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

44
define('TITLE', $view->get('title') . ' ' . get_string('by', 'view') . ' ' . $view->formatted_owner());
45
46
$heading = '<a href="' . get_config('wwwroot') . 'view/view.php?id=' . $view->get('id') .'">' . hsc($view->get('title')) . '</a> ' . get_string('by', 'view') . ' <a href="' . get_config('wwwroot') .'user/view.php?id=' . $view->get('owner'). '">' . $view->formatted_owner() . '</a>';

47

48
$tutorfilefeedbackformrow = '';
49
50
51
52
53
54
55
56
57
58
59
$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'}))),";
60
}
61
$viewbeingwatched = (int)record_exists('usr_watchlist_view', 'usr', $USER->get('id'), 'view', $viewid);
62

63
64
65
$getstring = quotestrings(array(
    'mahara' => array('message', 'cancel'),
    'view' => array('makepublic', 'placefeedback', 'complaint',
66
        'feedbackonthisartefactwillbeprivate', 'notifysiteadministrator',
67
68
        'nopublicfeedback', 'reportobjectionablematerial', 'print')
));
69

70
71
72
$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')) . ")'";
73

74
// Safari doesn't seem to like these inputs to be called 'public', so call them 'ispublic' instead.
75
if (!empty($feedbackisprivate)) {
76
    $makepublic = "TR(null, INPUT({'type':'hidden','name':'ispublic','value':'false'}), TD({'colspan':2}, " 
77
78
79
80
        . $getstring['feedbackonthisartefactwillbeprivate'] . ")),";
}
else {
    $makepublic = "TR(null, TH(null, LABEL(null, " . $getstring['makepublic'] . " ), " 
81
        . "INPUT({'type':'checkbox', 'class':'checkbox', 'name':'ispublic'}))),";
82
83
}

84
$javascript = <<<EOF
Richard Mansfield's avatar
Richard Mansfield committed
85

86
var view = {$viewid};
Richard Mansfield's avatar
Richard Mansfield committed
87
88

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

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

158
function view_menu() {
159
160
161
162
163
164
165
166
    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
167
    appendChildNodes('viewmenu',
168
169
170
        A({'href':'', 'onclick':'window.print();return false;'}, 
            {$getstring['print']})
    );
171
    if (config.loggedin) {
172
173
174
175
176
177
178
179
180
181
182
        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);
183
     }
184

Richard Mansfield's avatar
Richard Mansfield committed
185
186
}

187
188
addLoadEvent(view_menu);

189
// The list of existing feedback.
190
191
192
var feedbacklist = new TableRenderer(
    'feedbacktable',
    'getfeedback.json.php',
193
    [
194
        function (r) {
195
196
            var td = TD(null);
            td.innerHTML = r.message;
197
            if (r.attachid && r.ownedbythisuser) {
198
199
                appendChildNodes(td, DIV(null, {$getstring['feedbackattachmessage']}));
                return td;
200
            }
201
            return td;
202
        },
203
204
205
        'name',
        'date', 
        function (r) {
206
            if (r.ispublic == 1) {
207
208
209
210
211
212
213
                var makePrivate = null;
                if (r.ownedbythisuser) {
                    makePrivate = A({'href': ''}, get_string('makeprivate'));
                    connect(makePrivate, 'onclick', function (e) {
                        sendjsonrequest(
                            'changefeedback.json.php',
                            r,
214
                            'POST',
215
216
217
218
219
220
221
222
223
224
225
226
227
228
                            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') + ')');
        },
229
230
231
232
233
234
235
        function (r) {
            if (r.attachid) {
                return TD(null, A({'href':config.wwwroot + 'artefact/file/download.php?file=' + r.attachid},
                                  r.attachtitle));
            }
            return TD(null);
        }
236
    ]
237
238
);

239
feedbacklist.limit = 10;
240
feedbacklist.view = view;
241
feedbacklist.statevars.push('view');
242
feedbacklist.emptycontent = {$getstring['nopublicfeedback']};
243
244
feedbacklist.updateOnLoad();

Richard Mansfield's avatar
Richard Mansfield committed
245

246
EOF;
Richard Mansfield's avatar
Richard Mansfield committed
247

248
249
$smarty = smarty(
    array('tablerenderer'),
250
    array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">'),
251
    array(
252
        'view' => array(
253
254
255
256
            'public',
            'private',
            'makeprivate',
        ),
257
258
259
    ),
    array(
        'stylesheets' => array('style/views.css'),
260
261
    )
);
262
263
$smarty->assign('heading', $heading);
$smarty->assign('noheadingescape', true);
Richard Mansfield's avatar
Richard Mansfield committed
264
$smarty->assign('INLINEJAVASCRIPT', $javascript);
265
266
267
268
269
270
271
$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());

272
273
if ($USER->get('id') == $view->get('owner')) {
    $smarty->assign('can_edit', true);
274
    $smarty->assign('new', $new);
275
}
276
277
278
$smarty->display('view/view.tpl');

?>