forked from Kylegoslin/moodle-block_cmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmanager_admin.php
executable file
·360 lines (248 loc) · 9.14 KB
/
cmanager_admin.php
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<?php
// ---------------------------------------------------------
// block_cmanager 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.
//
// block_cmanager 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
//
// COURSE REQUEST MANAGER BLOCK FOR MOODLE
// by Kyle Goslin & Daniel McSweeney
// Copyright 2012-2018 - Institute of Technology Blanchardstown.
// ---------------------------------------------------------
/**
* COURSE REQUEST MANAGER
*
* @package block_cmanager
* @copyright 2018 Kyle Goslin, Daniel McSweeney
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
global $CFG, $DB;
$formPath = "$CFG->libdir/formslib.php";
require_once($formPath);
require_login();
require_once('../../course/lib.php');
require_once('lib/displayLists.php');
/** Navigation Bar **/
$PAGE->navbar->ignore_active();
$PAGE->navbar->add(get_string('cmanagerDisplay', 'block_cmanager'), new moodle_url('/blocks/cmanager/cmanager_admin.php'));
$PAGE->set_url('/blocks/cmanager/cmanager_admin.php');
$PAGE->set_context(context_system::instance());
$PAGE->set_heading(get_string('pluginname', 'block_cmanager'));
$PAGE->set_title(get_string('pluginname', 'block_cmanager'));
echo $OUTPUT->header();
$_SESSION['CRMisAdmin'] = true;
$context = context_system::instance();
if (has_capability('block/cmanager:approverecord',$context)) {
} else {
print_error(get_string('cannotviewconfig', 'block_cmanager'));
}
?>
<link rel="stylesheet" type="text/css" href="css/main.css" />
<script src="js/jquery/jquery-3.3.1.min.js"></script>
<script src="js/jquery/jquery-ui.1.12.1.min.js"></script>
<style>
#map { float:left; width:80%; }
#wrapper {float:left; width:100%;}
#list { background:#eee; list-style:none; padding:0; }
#existingrequest { background:#000; }
select
{
width:150px;
}
tr:nth-child(odd) { background-color:#eee; }
tr:nth-child(even) { background-color:#fff; }
</style>
<script type="text/javascript">
function cancelConfirm(id,langString) {
var answer = confirm(langString)
if (answer){
window.location = "deleterequest.php?t=a&&id=" + id;
}
}
function quickApproveConfirm(id,langString) {
var answer = confirm(langString)
if (answer){
window.location = "admin/bulk_approve.php?mul=" + id;
}
}
var checkedIds = ['null'];
// List of currently selected Ids for use
// with the bulk actions
function addIdToList(id) {
var i = checkedIds.length;
var found = false;
while (i--) {
if (checkedIds[i] === id) {
checkedIds[i] = 'null';
found = true;
}
}
if (found === false) {
checkedIds.push(id);
}
}
/**
* This function is used to save the text from the
* categories when they are changed.
*/
function saveChangedCategory(recordId) {
var fieldvalue = document.getElementById('menucat' + recordId).value;
$.post("ajax_functions.php", { type: 'updatecategory', value: fieldvalue, recId: recordId },
function(data) {
//
});
}
</script>
<?php
/**
* Admin console
*
* Admin console interface
* @package block_cmanager
* @copyright 2018 Kyle Goslin, Daniel McSweeney
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_cmanager_admin_form extends moodleform {
function definition() {
global $CFG;
global $USER, $DB;
$mform =& $this->_form; // Don't forget the underscore!
$selectQuery = "status = 'PENDING' ORDER BY id ASC";
// If search is enabled then use the
// search parameters
if ($_POST && isset($_POST['search'])) {
$searchText = required_param('searchtext', PARAM_TEXT);
// if nothing was entered for the search string
// send them back with a warning message.
if($searchText == ""){
echo '<script>alert("'.get_string('cmanager_admin_enterstring','block_cmanager').'"); window.location="cmanager_admin.php"; </script>';
die;
}
$searchType = required_param('searchtype', PARAM_TEXT);
if (!empty($searchText) && !empty($searchType)) {
if ($searchType == 'code') {
$selectQuery = "`modcode` LIKE '%{$searchText}%'";
}
else if($searchType == 'title') {
$selectQuery = "`modname` LIKE '%{$searchText}%'";
}
else if ($searchType == 'requester') {
$selectQuery = "`createdbyid` IN (Select id from ".$CFG->prefix.
"user where `firstname` LIKE '%{$searchText}%' OR `lastname`
LIKE '%{$searchText}%' OR `username` LIKE '%{$searchText}%')";
}
}
// if ($searchType != 'requester'){
$selectQuery .= " AND status = 'PENDING' ORDER BY id ASC";
// }
}
// Get the list of records
$pendingList = $DB->get_recordset_select('block_cmanager_records', $select=$selectQuery);
$outputHTML = block_cmanager_display_admin_list($pendingList, true, true, true, 'admin_queue');
$mform->addElement('header', 'mainheader', '<span style="font-size:18px">'.get_string('currentrequests','block_cmanager').'</span>');
$bulkActions = "<p></p>
<div style=\"width: 200px; text-align:left; padding:10px; font-size:11pt; background-color: #eee\">
<b>".get_string('bulkactions','block_cmanager')."</b>
<br>
<input type=\"checkbox\" onClick=\"toggle(this)\" /> Select All<br/>
<select id=\"bulk\" onchange='bulkaction();'>
<option></option>
<option value =\"Approve\"'>".get_string('bulkapprove','block_cmanager')."</option>
<option value=\"Deny\">".get_string('deny','block_cmanager')."</option>
<option value =\"Delete\"'>".get_string('delete','block_cmanager')."</option>
</select>
<p></p>
</div>";
$page1_fieldname1 = $DB->get_field_select('block_cmanager_config', 'value', "varname='page1_fieldname1'");
$page1_fieldname2 = $DB->get_field_select('block_cmanager_config', 'value', "varname='page1_fieldname2'");
$searchHTML = '
<div style="width: 200px; background-color:#eee; padding:10px; ">
<form action="cmanager_admin.php?search=1" method="post">
<b><span style="font-size:11pt">'.get_string('search_side_text', 'block_cmanager').'</span></b>
<br> <input type="text" name="searchtext" id="searchtext"></input><br>
<span style="font-size:11pt">
<select name="searchtype" id="searchtype">
<option value="code">'.$page1_fieldname1.'</option>
<option value="title">'.$page1_fieldname2.'</option>
<option value="requester">' . get_string('searchAuthor', 'block_cmanager').'</option>
</select>
</span>
<br>
<span style="font-size:11pt">
<input type="submit" value="'.get_string('searchbuttontext', 'block_cmanager').'" name="search"></input>
</span>
</form>
';
if ($_POST && isset($_POST['search'])) {
$searchHTML .= '<br><p></p><a href="cmanager_admin.php">['.get_string('clearsearch', 'block_cmanager').']</a>';
}
$searchHTML .= '</div>';
$mainBody ='
<div id="pagemain">
<div id="leftpanel" style="padding-right:10px; width:200px; float:left; height:100%">' .$searchHTML .''. $bulkActions . '</div>
<div id="rightpanel" style=" margin-left:250px;">
<div id="wrapper">'. $outputHTML .'</div>
</div>
</div>';
$mform->addElement('html', $mainBody);
} // Close the function
} // Close the class
echo "<script>
// When the select all option is picked in the bulk actions
// this is the function that is run.
function toggle(source) {
checkboxes = document.getElementsByName('groupedcheck');
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
addIdToList(checkboxes[i].id);
}
}
function bulkaction(){
var cur = document.getElementById('bulk');
if(cur.value == 'Delete'){
$.post(\"ajax_functions.php\", { type: \"del\", values: checkedIds},
function(data) {
window.location='cmanager_admin.php';
});
}
if(cur.value == 'Deny'){
window.location='admin/bulk_deny.php?mul=' + checkedIds;
}
if(cur.value == 'Approve'){
window.location='admin/bulk_approve.php?mul=' + checkedIds;
}
}
</script>";
$mform = new block_cmanager_admin_form();
if ($mform->is_cancelled()) {
} else if ($fromform=$mform->get_data()) {
} else {
}
$mform->focus();
$mform->display();
echo $OUTPUT->footer();
if ($_POST && isset($_POST['search'])) {
$searchText = required_param('searchtext', PARAM_TEXT);
$searchType = required_param('searchtype', PARAM_TEXT);
echo "<script>document.getElementById('searchtext').value = '$searchText'; ";
echo "
var desiredValue = '$searchType';
var el = document.getElementById('searchtype');
for(var i=0; i<el.options.length; i++) {
if ( el.options[i].value == desiredValue ) {
el.selectedIndex = i;
break;
}
}
</script>
";
}