forked from Kylegoslin/moodle-block_cmanager
-
Notifications
You must be signed in to change notification settings - Fork 6
/
cmanager_config.php
executable file
·410 lines (318 loc) · 18 KB
/
cmanager_config.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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<?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-2014 - 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;
require_once("$CFG->libdir/formslib.php");
require_login();
require_once('validate_admin.php');
require_once('lib/boot.php');
$PAGE->set_url('/blocks/cmanager/cmanager_config.php');
$PAGE->set_context(context_system::instance());
/** 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('configurecoursemanagersettings', 'block_cmanager'), new moodle_url('/blocks/cmanager/cmanager_confighome.php'));
$PAGE->navbar->add(get_string('emailConfig', 'block_cmanager'));
$PAGE->set_heading(get_string('configureemailsettings', 'block_cmanager'));
$PAGE->set_title(get_string('configureemailsettings', 'block_cmanager'));
echo $OUTPUT->header();
$context = context_system::instance();
if (has_capability('block/cmanager:viewconfig',$context)) {
} else {
print_error(get_string('cannotviewconfig', 'block_cmanager'));
}
?>
<head>
<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>
<script>
function cancelConfirm(i,langString) {
var answer = confirm(langString)
if (answer){
window.location = "cmanager_config.php?t=d&&id=" + i;
}
else{
}
}
/**
* This function is used to save the text from the
* list of textareas using ajax.
*/
function saveChangedText(object, idname, langString){
var fieldvalue = object.value;
$.post("ajax_functions.php", { type: 'updatefield', value: fieldvalue, id: idname },
function(data) {
$("#saved").modal();
});
}
</script>
</head>
<?php
// If any records were set to be deleted.
if (isset($_GET['t']) && isset($_GET['id'])) {
if (required_param('t', PARAM_TEXT) == 'd') {
$deleteId = required_param('id', PARAM_INT);
// Delete the record
$deleteQuery = "id = $deleteId";
$DB->delete_records_select('block_cmanager_config', $deleteQuery);
echo "<script>window.location='cmanager_config.php';</script>";
}
}
/**
* Config form form cmanager
*
* @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_config_form extends moodleform {
function definition() {
global $CFG;
global $currentSess;
global $mid;
global $USER, $DB;
$currentRecord = $DB->get_record('block_cmanager_records', array('id'=> $currentSess));
$mform =& $this->_form; // Don't forget the underscore!
// Back Button
$mform->addElement('html', '<p><a href="cmanager_confighome.php" class="btn btn-default"><img src="icons/back.png" alt=""> '.get_string('back','block_cmanager').'</a></p>');
// Email text box
$approvedTextRecord = $DB->get_record('block_cmanager_config', array('varname'=>'approved_text'));
$emailText = '';
if ($approvedTextRecord != null) {
$emailText = $approvedTextRecord->value;
}
// Approved user email
$approved_user_email = $DB->get_record('block_cmanager_config', array('varname'=>'approveduseremail'));
$approved_user_email_value = '';
if (!empty($approved_user_email)) {
$approved_user_email_value = stripslashes($approved_user_email->value);
}
// Approved admin email
$approved_admin_email = $DB->get_record('block_cmanager_config', array('varname'=>'approvedadminemail'));
$approved_admin_email_value = '';
if (!empty($approved_admin_email)) {
$approved_admin_email_value = stripslashes($approved_admin_email->value);
}
// Request new module user
$request_new_module_user = $DB->get_record('block_cmanager_config', array('varname'=>'requestnewmoduleuser'));
$request_new_module_user_value = '';
if (!empty($request_new_module_user)) {
$request_new_module_user_value = stripslashes($request_new_module_user->value);
}
// Request new module admin
$request_new_module_admin = $DB->get_record('block_cmanager_config', array('varname'=>'requestnewmoduleadmin'));
$request_new_module_admin_value = '';
if (!empty($request_new_module_admin)) {
$request_new_module_admin_value = stripslashes($request_new_module_admin->value);
}
// Comment email admin
$comment_email_admin = $DB->get_record('block_cmanager_config', array('varname'=>'commentemailadmin'));
$comment_email_admin_value = '';
if (!empty($comment_email_admin)) {
$comment_email_admin_value = stripslashes($comment_email_admin->value);
}
// Comment email user
$comment_email_user = $DB->get_record('block_cmanager_config', array('varname'=>'commentemailuser'));
$comment_email_user_value = '';
if (!empty($comment_email_user)) {
$comment_email_user_value = stripslashes($comment_email_user->value);
}
// Request denied admin
$module_request_denied_admin = $DB->get_record('block_cmanager_config', array('varname'=>'modulerequestdeniedadmin'));
$module_request_denied_admin_value = '';
if (!empty($module_request_denied_admin)) {
$module_request_denied_admin_value = stripslashes($module_request_denied_admin->value);
}
// Request denied user
$module_request_denied_user = $DB->get_record('block_cmanager_config', array('varname'=>'modulerequestdenieduser'));
$module_request_denied_user_value = '';
if (!empty($module_request_denied_user)) {
$module_request_denied_user_value = stripslashes($module_request_denied_user->value);
}
// Handover current
$handover_current = $DB->get_record('block_cmanager_config', array('varname'=>'handovercurrent'));
$handover_current_value = '';
if (!empty($handover_current)) {
$handover_current_value = stripslashes($handover_current->value);
}
//Handover user
$handover_user = $DB->get_record('block_cmanager_config', array('varname'=>'handoveruser'));
$handover_user_value = '';
if (!empty($handover_user)) {
$handover_user_value = stripslashes($handover_user->value);
}
// Handover admin
$handover_admin = $DB->get_record('block_cmanager_config', array('varname'=>'handoveradmin'));
$handover_admin_value = '';
if (!empty($handover_admin)) {
$handover_admin_value = stripslashes($handover_admin->value);
}
$statsCode = get_string('totalRequests','block_cmanager').':';
$whereQuery = "varname = 'admin_email'";
$modRecords = $DB->get_recordset_select('block_cmanager_config', $whereQuery);
//get the current values for naming and autoKey from the database and use in the setting of seleted values for dropdowns
$autoKey = $DB->get_field_select('block_cmanager_config', 'value', "varname = 'autoKey'");
$naming = $DB->get_field_select('block_cmanager_config', 'value', "varname = 'naming'");
$snaming = $DB->get_field_select('block_cmanager_config', 'value', "varname = 'snaming'");
$emailSender = $DB->get_field_select('block_cmanager_config', 'value', "varname = 'emailSender'");
$selfcat = $DB->get_field_select('block_cmanager_config', 'value', "varname = 'selfcat'");
/////////////////////////////////////////////////////////////////////////////////////////////////////////
$fragment1 = '
<h3>' . get_string('emailConfigSectionHeader','block_cmanager') . '</h3>
<p>'.get_string('emailConfigInfo','block_cmanager').'</p>
<div class="row">
<div class="col-sm-1">' .get_string('config_addemail','block_cmanager') . '</div>
<div class="col-sm-3">';
foreach ($modRecords as $record) {
$fragment1 .= '<div class="row">';
$fragment1 .= '<div class="col-sm-9">' . $record->value . '</div>';
$fragment1 .= '<div class="col-sm-3"><a onclick="cancelConfirm('. $record->id .',\''.get_string('configure_deleteMail','block_cmanager').'\')" href="#" aria-label="' . get_string('formBuilder_confirmDelete','block_cmanager') . '" title="' . get_string('formBuilder_confirmDelete','block_cmanager') . '"><i class="icon fa fa-trash fa-fw" aria-hidden="true"></i></a></div>';
$fragment1 .= '</div>';
}
$fragment1 .= '
<div class="row">
<div class="col-sm-12">
<input type="text" name="newemail" id="newemail"/>
<input class="btn btn-default" type="submit" name="addemailbutton" id="addemailbutton" value="'.get_string('SaveEMail','block_cmanager').'">
</div>
</div>
</div>
</div>
<h3 class="mt-4">' . get_string('emailConfigContents','block_cmanager').'</h3>
<p>'.get_string('emailConfigHeader','block_cmanager').'</p>
<ul>
<li>' . get_string('email_courseCode','block_cmanager').': <strong>[course_code]</strong></li>
<li>' . get_string('email_courseName','block_cmanager').': <strong>[course_name]</strong></li>
<li>' . get_string('email_enrolmentKey','block_cmanager').': <strong>[e_key]</strong></li>
<li>' . get_string('email_fullURL','block_cmanager').': <strong>[full_link]</strong></li>
<li>' . get_string('email_sumLink','block_cmanager').': <strong>[req_link]</strong></li>
</ul>
<h3 class="mt-4">' . get_string('email_newCourseApproved','block_cmanager') . ' - ' . get_string('email_UserMail','block_cmanager') . '</h3>
<p>' . get_string('configure_leaveblankmail','block_cmanager') . '</p>
<textarea name="approveduseremail" id="approveduseremail" style="width:70%; height: 250px;">'.$approved_user_email_value.'</textarea><br>
<input class="btn btn-default" type="button" value="'.get_string('SaveChanges','block_cmanager').'" onClick="saveChangedText(approveduseremail, \'approveduseremail\',\''.get_string('ChangesSaved','block_cmanager').'\')"/><br>
<h3 class="mt-4">'.get_string('email_newCourseApproved','block_cmanager').' - '.get_string('email_AdminMail','block_cmanager') . '</h3>
<p> ' .get_string('configure_leaveblankmail','block_cmanager') . '</p>
<textarea name="approvedadminemail" id="approvedadminemail" style="width:70%; height: 250px;">'.$approved_admin_email_value.'</textarea><br>
<input class="btn btn-default" type="button" value="'.get_string('SaveChanges','block_cmanager').'" onClick="saveChangedText(approvedadminemail, \'approvedadminemail\')"/><br>
<h3 class="mt-4">'.get_string('email_requestNewModule','block_cmanager').' - '.get_string('email_UserMail','block_cmanager') . '</h3>
<p>' . get_string('configure_leaveblankmail','block_cmanager') . '</p>
<textarea name="requestnewmoduleuser" id="requestnewmoduleuser" style="width:70%; height: 250px;">'.$request_new_module_user_value.'</textarea><br>
<input class="btn btn-default" type="button" value="' . get_string('SaveChanges','block_cmanager') . '" onClick="saveChangedText(requestnewmoduleuser, \'requestnewmoduleuser\')"/><br>
<h3 class="mt-4">'.get_string('email_requestNewModule','block_cmanager').' - '.get_string('email_AdminMail','block_cmanager') . '</h3>
<p>' . get_string('configure_leaveblankmail','block_cmanager') . '</p>
<textarea name="requestnewmoduleadmin" id="requestnewmoduleadmin" style="width:70%; height: 250px;">'.$request_new_module_admin_value.'</textarea><br>
<input class="btn btn-default" type="button" value="' . get_string('SaveChanges','block_cmanager') . '" onClick="saveChangedText(requestnewmoduleadmin, \'requestnewmoduleadmin\')"/>
<h3 class="mt-4">'.get_string('email_commentNotification','block_cmanager').' - '.get_string('email_AdminMail','block_cmanager') . '</h3>
<p>' . get_string('configure_leaveblankmail','block_cmanager') . '</p>
<textarea name="commentemailadmin" id="commentemailadmin" style="width:70%; height: 250px;">'.$comment_email_admin_value.'</textarea><br>
<input class="btn btn-default" type="button" value="' . get_string('SaveChanges','block_cmanager') . '" onClick="saveChangedText(commentemailadmin, \'commentemailadmin\')"/>
<h3 class="mt-4">'.get_string('email_commentNotification','block_cmanager').' - '.get_string('email_UserMail','block_cmanager') . '</h3>
<p>' . get_string('configure_leaveblankmail','block_cmanager') . '</p>
<textarea name="commentemailuser" id="commentemailuser" style="width:70%; height: 250px;">'.$comment_email_user_value.'</textarea><br>
<input class="btn btn-default" type="button" value="' . get_string('SaveChanges','block_cmanager') . '" onClick="saveChangedText(commentemailuser, \'commentemailuser\')"/>
<h3 class="mt-4">'.get_string('email_requestDenied','block_cmanager').' - '.get_string('email_AdminMail','block_cmanager') . '</h3>
<p>' . get_string('configure_leaveblankmail','block_cmanager') . '</p>
<textarea name="modulerequestdeniedadmin" id="modulerequestdeniedadmin" style="width:70%; height: 250px;">'.$module_request_denied_admin_value.'</textarea><br>
<input class="btn btn-default" type="button" value="' . get_string('SaveChanges','block_cmanager') . '" onClick="saveChangedText(modulerequestdeniedadmin, \'modulerequestdeniedadmin\')"/>
<h3 class="mt-4">'.get_string('email_requestDenied','block_cmanager').' - '.get_string('email_UserMail','block_cmanager') . '</h3>
<p>' . get_string('configure_leaveblankmail','block_cmanager') . '</p>
<textarea name="modulerequestdenieduser" id="modulerequestdenieduser" style="width:70%; height: 250px;">'.$module_request_denied_user_value.'</textarea><br>
<input class="btn btn-default" type="button" value="' . get_string('SaveChanges','block_cmanager') . '" onClick="saveChangedText(modulerequestdenieduser, \'modulerequestdenieduser\')"/>
<h3 class="mt-4">'.get_string('email_handover','block_cmanager').' - '.get_string('email_currentOwner','block_cmanager') . '</h3>
<p>' . get_string('configure_leaveblankmail','block_cmanager') . '</p>
<textarea name="handovercurrent" id="handovercurrent" style="width:70%; height: 250px;">'.$handover_current_value.'</textarea><br>
<input class="btn btn-default" type="button" value="' . get_string('SaveChanges','block_cmanager') . '" onClick="saveChangedText(handovercurrent, \'handovercurrent\')"/>
<h3 class="mt-4">'.get_string('email_handover','block_cmanager').' - '.get_string('email_UserMail','block_cmanager') . '</h3>
<p>' . get_string('configure_leaveblankmail','block_cmanager') . '</p>
<textarea name="handoveruser" id="handoveruser" style="width:70%; height: 250px;">'.$handover_user_value.'</textarea><br>
<input class="btn btn-default" type="button" value="' . get_string('SaveChanges','block_cmanager') . '" onClick="saveChangedText(handoveruser, \'handoveruser\')"/>
<h3 class="mt-4">'.get_string('email_handover','block_cmanager').' - '.get_string('email_AdminMail','block_cmanager') . '</h3>
<p>' . get_string('configure_leaveblankmail','block_cmanager') . '</p>
<textarea name="handoveradmin" id="handoveradmin" style="width:70%; height: 250px;">'.$handover_admin_value.'</textarea><br>
<input class="btn btn-default" type="button" value="' . get_string('SaveChanges','block_cmanager') . '" onClick="saveChangedText(handoveradmin, \'handoveradmin\')"/>
';
/////////////////////////////////////////////////////////////////////////////////////////////////////////
$mainSlider = '
<p></p>
<p></p>
'. $fragment1.'
';
//add the main slider
$mform->addElement('html', $mainSlider);
}
}
$mform = new block_cmanager_config_form();
if ($mform->is_cancelled()) {
echo "<script>window.location='../cmanager_admin.php';</script>";
die;
} else if (isset($_POST['addemailbutton'])) {
global $USER;
global $CFG;
// Add an email address
$post_email = required_param('newemail', PARAM_EMAIL);
if ($post_email != '' && block_cmanager_validate_email($post_email)) {
$newrec = new stdClass();
$newrec->varname = 'admin_email';
$newrec->value = $post_email;
$DB->insert_record('block_cmanager_config', $newrec);
}
echo "<script>window.location='cmanager_config.php';</script>";
die;
} else {
$mform->focus();
$mform->set_data($mform);
$mform->display();
echo $OUTPUT->footer();
}
echo generateGenericPop('saved', get_string('ChangesSaved','block_cmanager'), get_string('ChangesSaved','block_cmanager'), get_string('ok','block_cmanager') );
/**
* Very basic funciton for validating an email address.
* This should really be replaced with something a little better!
*/
function block_cmanager_validate_email($email) {
$valid = true;
if ($email == '') {
$valid = false;
}
$pos = strpos($email, '.');
if ($pos === false) {
$valid = false;
}
$pos = strpos($email, '@');
if ($pos === false) {
$valid = false;
}
if ($valid) {
return true;
} else {
return false;
}
}