forked from Kylegoslin/moodle-block_cmanager
-
Notifications
You must be signed in to change notification settings - Fork 6
/
review_request.php
executable file
·164 lines (131 loc) · 5.46 KB
/
review_request.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
<?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 2014-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;
$formPath = "$CFG->libdir/formslib.php";
require_once($formPath);
require_once('lib/displayLists.php');
require_login();
/** Navigation Bar **/
$PAGE->navbar->ignore_active();
$PAGE->navbar->add(get_string('cmanagerDisplay', 'block_cmanager'), new moodle_url('/blocks/cmanager/module_manager.php'));
$PAGE->navbar->add(get_string('modrequestfacility', 'block_cmanager'));
$mid = optional_param('id', '', PARAM_INT);
$PAGE->set_url('/blocks/cmanager/review_request.php', ['id'=> $mid]);
$PAGE->set_context(context_system::instance());
$PAGE->set_heading(get_string('requestReview_Summary', 'block_cmanager'));
$PAGE->set_title(get_string('requestReview_Summary', 'block_cmanager'));
echo $OUTPUT->header();
if (!empty($mid)) {
$_SESSION['mid'] = $mid;
} else {
$mid = $_SESSION['mid'];
}
$context = context_system::instance();
if (has_capability('block/cmanager:addrecord',$context)) {
} else {
print_error(get_string('cannotrequestcourse', 'block_cmanager'));
}
/**
* Review request
*
* Allow the user to review their request
* @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_review_request_form extends moodleform {
function definition() {
global $CFG, $currentSess, $mid, $USER, $DB;
$mform =& $this->_form; // Don't forget the underscore!
$mform->addElement('html', '<p>' . get_string('requestReview_intro1','block_cmanager') . '</p>');
$mform->addElement('html', '<p>' . get_string('requestReview_intro2','block_cmanager') . '</p>');
$rec = $DB->get_recordset_select('block_cmanager_records', 'id = ' . $mid);
$displayModHTML = block_cmanager_display_admin_list($rec, false, false, false, '');
$mform->addElement('html', $displayModHTML);
$buttonarray=array();
$buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('requestReview_SubmitRequest','block_cmanager'));
$buttonarray[] = &$mform->createElement('submit', 'alter', get_string('requestReview_AlterRequest','block_cmanager'));
$buttonarray[] = &$mform->createElement('cancel', 'cancel', get_string('requestReview_CancelRequest','block_cmanager'));
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
}
}
$mform = new block_cmanager_review_request_form();
if ($mform->is_cancelled()) {
// Delete the record
$DB->delete_records_select('block_cmanager_records', "id = $mid");
echo "<script>window.location='module_manager.php'</script>";
die;
} else if ($fromform=$mform->get_data()) {
// If alter was pressed.
if (isset($_POST['alter'])) {
echo "<script>window.location='course_request.php?mode=2&edit=$mid'</script>";
die;
}
require_once('cmanager_email.php');
global $mid;
global $CFG;
global $USER;
$rec = $DB->get_record('block_cmanager_records', array('id'=>$mid));
$replaceValues = array();
$replaceValues['[course_code'] = $rec->modcode;
$replaceValues['[course_name]'] = $rec->modname;
//$replaceValues['[p_code]'] = $rec->progcode;
//$replaceValues['[p_name]'] = $rec->progname;
$replaceValues['[e_key]'] = 'No key set';
$replaceValues['[full_link]'] = get_string('requestReview_ccdne','block_cmanager');
$replaceValues['[loc]'] = get_string('reviewLocation', 'block_cmanager') . ': ';
$replaceValues['[req_link]'] = $CFG->wwwroot .'/blocks/cmanager/view_summary.php?id=' . $mid;
// Send email to admin saying we are requesting a new mod
block_cmanager_request_new_mod_email_admins($replaceValues);
// Send email to user to track that we are requesting a new mod
block_cmanager_request_new_mod_email_user($USER->id, $replaceValues);
// Return to module manager
if (isset($_SESSION['CRMisAdmin'])) {
if ($_SESSION['CRMisAdmin'] == true) {
echo "<script>window.location='cmanager_admin.php'</script>";
die;
}
} else {
echo "<script>window.location='module_manager.php'</script>";
die;
}
} else {
$mform->focus();
$mform->set_data($mform);
$mform->display();
echo $OUTPUT->footer();
}
/**
* Get a user id
*/
function block_cmanager_get_username($id){
global $DB;
return $DB->get_field_select('user', 'username', "id = '$id'");
}
?>