forked from Kylegoslin/moodle-block_cmanager
-
Notifications
You must be signed in to change notification settings - Fork 6
/
cmanager_admin_arch.php
executable file
·292 lines (216 loc) · 8.56 KB
/
cmanager_admin_arch.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
<?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
* @copyright 2021-2022 Michael Milette (TNG Consulting Inc.), Daniel Keaman
* @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');
require_once('lib/boot.php');
/** Navigation Bar **/
$PAGE->navbar->ignore_active();
$PAGE->navbar->add(get_string('cmanagerDisplay', 'block_cmanager'), new moodle_url('/blocks/cmanager/cmanager_admin.php'));
$PAGE->navbar->add(get_string('allarchivedrequests', 'block_cmanager'));
$PAGE->set_url('/blocks/cmanager/cmanager_admin.php');
$PAGE->set_context(context_system::instance());
$PAGE->set_heading(get_string('allarchivedrequests', 'block_cmanager'));
$PAGE->set_title(get_string('allarchivedrequests', 'block_cmanager'));
echo $OUTPUT->header();
$context = context_system::instance();
if (has_capability('block/cmanager:approverecord',$context)) {
} else {
print_error(get_string('cannotviewrecords', 'block_cmanager'));
}
?>
<script src="js/jquery/jquery-3.3.1.min.js"></script>
<script src="js/jquery/jquery-ui.1.12.1.min.js"></script>
<script type="text/javascript">
var deleteRec = 0;
function cancelConfirm(id,langString) {
deleteRec = id;
console.log("deleting rec" + deleteRec);
$("#delete_modal").modal();
}
/**
* This function is used to save the text from the
* categories when they are changed.
*/
function saveChangedCategory(fieldvalue, recordId){
$.post("ajax_functions.php", { type: 'updatecategory', value: fieldvalue, recId: recordId },
function(data) {
alert("Changes have been saved!");
});
}
</script>
<style>
tr:nth-child(odd) { background-color:#eee; }
tr:nth-child(even) { background-color:#fff; }
</style>
<?php
/**
* Admin Arch
*
* Display admin arch page
* @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_adminarch_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);
$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` = (Select id from ".$CFG->prefix."user where `firstname` LIKE '%{$searchText}%' OR `lastname` LIKE '%{$searchText}%' OR `username` LIKE '%{$searchText}%')";
}
}
}
echo "
<script>
// Open the selected archived request page
function goToPage(){
var page = document.getElementById('pageNumber');
window.location = 'cmanager_admin_arch.php?view=history&p=' + page.value;
}
</script>";
// Arch Requests Dropdow
$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'");
$additionalSearchQuery = '';
if ($_POST && isset($_POST['archsearch'])) {
$archSearchText = required_param('archsearchtext', PARAM_TEXT);
$archSearchType = required_param('archsearchtype', PARAM_TEXT);
if (!empty($archSearchText) && !empty($archSearchType)) {
if($archSearchType == 'code') {
$additionalSearchQuery = " AND `modcode` LIKE '%{$archSearchText}%'";
}
else if ($archSearchType == 'title') {
$additionalSearchQuery = " AND `modname` LIKE '%{$archSearchText}%'";
}
else if($archSearchType == 'requester') {
$additionalSearchQuery = " AND `createdbyid` = (Select id from ".$CFG->prefix."user where `firstname` LIKE '%{$archSearchText}%' OR `lastname` LIKE '%{$archSearchText}%' OR `username` LIKE '%{$archSearchText}%')";
}
}
}
$numberOfRecords = $DB->count_records_sql("SELECT count(id) FROM " . $CFG->prefix ."block_cmanager_records WHERE status = 'COMPLETE' OR status = 'REQUEST DENIED'" . $additionalSearchQuery);
$numberOfPages = ceil($numberOfRecords / 10) -1;
$selectedOption = '';
$archRequestsDropdown = ' <br>View Page:
<select onchange="goToPage();" name="pageNumber" id="pageNumber">';
$i = 1;
while ($i < $numberOfPages+1) {
if (isset($_GET['p'])) {
if (required_param('p', PARAM_INT) == $i) {
$selectedOption = 'selected = "yes"';
}
}
$archRequestsDropdown .= '<option ' .$selectedOption .' value="' . $i. '">' . $i. '</option>';
$i++;
$selectedOption = '';
}
if ($numberOfRecords % 2) {
} else {
if (isset($_GET['p'])) {
if (required_param('p', PARAM_INT) == $i) {
$selectedOption = 'selected = "yes"';
}
}
$archRequestsDropdown .= '<option '. $selectedOption.'="' . $i. '"> ' . $i.'</option>';
}
$archRequestsDropdown .= '</select>';
// -----------------------------------------------------------------------------------------
// if a page number is selected
if (isset($_GET['p'])) {
$selected_page_number = required_param('p', PARAM_INT);
$fromLimit = ($selected_page_number -1) * 10;
$toLimit = $fromLimit + 10;
} else {
$fromLimit = 0;
$toLimit = 10;
}
$pendingList = $DB->get_records_sql("SELECT * FROM ". $CFG->prefix ."block_cmanager_records
WHERE status = 'COMPLETE' OR status = 'REQUEST DENIED'" . $additionalSearchQuery . "
order by id desc LIMIT $fromLimit, $toLimit");
$outputHTML = '';
$outputHTML .= $archRequestsDropdown;
$outputHTML .= '<h2>'. get_string('archivedrequests','block_cmanager').'</h2>';
$outputHTML .= block_cmanager_display_admin_list($pendingList, true, false, false, 'admin_arch');
$mform->addElement('html', $outputHTML);
} // Close the function
} // Close the class
$mform = new block_cmanager_adminarch_form();
if ($mform->is_cancelled()) {
} else if ($fromform=$mform->get_data()) {
//this branch is where you process validated data.
} else {
}
if ($_POST && isset($_POST['archsearch'])) {
$archSearchText = required_param('archsearchtext', PARAM_TEXT);
$archSearchType = required_param('archsearchtype', PARAM_TEXT);
echo "<script>document.getElementById('archsearchtext').value = '$archSearchText'; ";
echo "
var desiredValue = '$archSearchType';
var el = document.getElementById('archsearchtype');
for(var i=0; i<el.options.length; i++) {
if ( el.options[i].value == desiredValue ) {
el.selectedIndex = i;
break;
}
}
</script>
";
}
$mform->focus();
$mform->display();
echo $OUTPUT->footer();
// Modal for deleting requests
echo generateGenericConfirm('delete_modal', get_string('alert', 'block_cmanager') ,
get_string('configure_delete', 'block_cmanager'),
get_string('yesDeleteRecords', 'block_cmanager'));
?>
<script>
// delete request ok button click handler
$("#okdelete_modal").click(function(){
window.location = "deleteRequest.php?t=adminarch&&id=" + deleteRec;
});
</script>
<script src="js/bootstrap.min.js"/>