index.php 6.4 KB
Newer Older
Richard Mansfield's avatar
Richard Mansfield committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
/**
 * This program is part of Mahara
 *
 *  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 2 of the License, or
 *  (at your option) any later version.
 *
 *  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.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 *
 * @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);
require(dirname(dirname(__FILE__)) . '/init.php');

$wwwroot = get_config('wwwroot');

$strings = array('accessstartdate', 'accessenddate', 'artefacts', 'delete', 'description', 
33
                 'editaccess', 'editview', 'editviewinformation', 'submitted', 
34
                 'submitview', 'submitviewquestion', 'unknownerror');
Richard Mansfield's avatar
Richard Mansfield committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
$getstring = array();
foreach ($strings as $string) {
    $getstring[$string] = "'" . get_string($string) . "'";
}

/* This is a slightly dodgy use of the table renderer: I'm outputting
   five <tr> elements for each item of data coming from the database.
   Maybe I need a repeated-paginated-thing renderer? */

    //var assess = SELECT({'name':'community'});

$javascript = <<<JAVASCRIPT
var viewlist = new TableRenderer(
    'viewlist',
    'myviews.json.php',
Richard Mansfield's avatar
Richard Mansfield committed
50
    [null,null]
Richard Mansfield's avatar
Richard Mansfield committed
51
52
53
54
55
56
57
);

viewlist.rowfunction = function(r, n, data) {
    return map(partial(TR,null),[title(r,data.communities), startdate(r), enddate(r), 
                                 description(r), artefacts(r)]);
}

58
function title(r, communities) {
Richard Mansfield's avatar
Richard Mansfield committed
59
60
61
62
63
64
65
66
    var editinfo = INPUT({'type':'button','value':{$getstring['editviewinformation']}});
    editinfo.onclick = function () { submitform(r.id, 'editinfo'); };
    var edit = INPUT({'type':'button','value':{$getstring['editview']}});
    edit.onclick = function () { submitform(r.id, 'edit'); };
    var editaccess = INPUT({'type':'button','value':{$getstring['editaccess']}});
    editaccess.onclick = function () { submitform(r.id, 'editaccess'); };
    var del = INPUT({'type':'button','value':{$getstring['delete']}});
    del.onclick = function () { submitform(r.id, 'delete'); };
67
    if (r.submittedto) {
68
        var assess = get_string('viewsubmittedto', r.submittedto);
Richard Mansfield's avatar
Richard Mansfield committed
69
70
    }
    else {
71
        var assess = assessselect(r.id,communities);
Richard Mansfield's avatar
Richard Mansfield committed
72
73
74
75
76
77
78
79
80
81
    }
    var f = FORM({'id':('form'+r.id),'method':'post','enctype':'multipart/form-data',
                  'encoding':'multipart/form-data','onsubmit':"return formsubmit('"+r.id+"');"},
                 DIV(null,[editinfo,edit,editaccess,del]),
                 DIV(null,assess));
    return [TD({'style':'font-size: 110%;'},r.title),
            TD(null,f)];
}

function communityoption(community) {
82
    return OPTION({'value':community.id},community.name);
Richard Mansfield's avatar
Richard Mansfield committed
83
84
}

85
86
function assessselect(viewid, communitylist) {
    if (communitylist.length < 1) {
Richard Mansfield's avatar
Richard Mansfield committed
87
88
        return null;
    }
89
90
91
92
    var submitview = INPUT({'type':'button','value':{$getstring['submitview']}});
    submitview.onclick = function () { submitform(viewid, 'submitview'); };
    return [SELECT({'name':'community'},map(communityoption, communitylist)), submitview];
            
Richard Mansfield's avatar
Richard Mansfield committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
}

function startdate(r) {
    return [TD(null,{$getstring['accessstartdate']}),
            TD(r.startdate)];
}

function enddate(r) {
    return [TD(null,{$getstring['accessenddate']}),
            TD(r.enddate)];
}

function description(r) {
    return [TD(null,{$getstring['description']}),
            TD(r.description)];
}

function renderartefact(a) {
    return LI(null,A({'href':'{$wwwroot}viewartefact?id='+a.id},a.title));
}

function artefacts(r) {
    return [TD(null,{$getstring['artefacts']}),
            TD(null,UL(null,map(renderartefact,r.artefacts)))];
}

function deleteview(viewid) {
    processingStart();
    var req = getXMLHttpRequest();
    req.open('POST','delete.json.php');
    req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
    var d = sendXMLHttpRequest(req,queryString({'viewid':viewid}));
    d.addCallbacks(json_success, json_error);
    return false;
}

129
130
131
132
133
134
135
136
137
138
139
140
141
142
function submitview(viewid, communityid) {
    var answer = confirm({$getstring['submitviewquestion']});
    if (!answer) {
        return;
    }
    processingStart();
    var req = getXMLHttpRequest();
    req.open('POST','submit.json.php');
    req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
    var d = sendXMLHttpRequest(req,queryString({'viewid':viewid,'communityid':communityid}));
    d.addCallbacks(json_success, json_error);
    return false;
}

Richard Mansfield's avatar
Richard Mansfield committed
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
function json_success(result) {
    var data = evalJSONRequest(result);
    var errtype = false;
    if (!data.error) { 
        errtype = 'info';
    }
    else if (data.error == 'local') {
        errtype = 'error';
    }
    else {
        global_error_handler(data);
    }
    if (errtype) {
        displayMessage(data.message,errtype);
        viewlist.doupdate();
        processingStop();
    }
}

function json_error(result) {
    displayMessage({$getstring['unknownerror']},'error');
    processingStop();
}

function submitform(viewid, action) {
    if (action == 'delete') {
        return deleteview(viewid);
    }
    var form = $('form' + viewid);
172
173
174
    if (action == 'submitview') {
        return submitview(viewid, form.community.value);
    }
Richard Mansfield's avatar
Richard Mansfield committed
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
    var page = 'index.php';
    if (action == 'editinfo') {
        page = 'editmetadata.php';
    }
    if (action == 'edit') {
        page = 'edit.php';
    }
    if (action == 'editaccess') {
        page = 'editaccess.php';
    }
    setNodeAttribute(form, 'action', page);
    appendChildNodes(form, INPUT({'type':'hidden','name':'viewid','value':viewid}));
    form.submit();
    return false;
}

viewlist.limit = 5;
viewlist.updateOnLoad();

JAVASCRIPT;

196
$smarty = smarty(array('tablerenderer'), array(), array('viewsubmittedto'));
Richard Mansfield's avatar
Richard Mansfield committed
197
$smarty->assign('site_menu', site_menu());
198
$smarty->assign('searchform', searchform());
Richard Mansfield's avatar
Richard Mansfield committed
199
200
201
202
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->display('view/index.tpl');

?>