forked from Kylegoslin/moodle-block_cmanager
-
Notifications
You must be signed in to change notification settings - Fork 6
/
course_exists.php
executable file
·162 lines (123 loc) · 5.71 KB
/
course_exists.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
<?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");
require_once("$CFG->libdir/formslib.php");
require_once("lib.php");
require_login();
global $CFG, $DB, $USER;
/** 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('courseexists', 'block_cmanager'));
$PAGE->set_url('/blocks/cmanager/course_exists.php');
$PAGE->set_context(context_system::instance());
$PAGE->set_heading(get_string('courseexists', 'block_cmanager'));
$PAGE->set_title(get_string('courseexists', 'block_cmanager'));
// Main variable for storing the current session id.
$currentSess = '00';
$currentSess = $_SESSION['cmanager_session'];
?>
<link rel="stylesheet" type="text/css" href="css/main.css" />
<?php
class block_cmanager_course_exists_form extends moodleform {
function definition() {
global $CFG, $DB, $currentSess;
$norequestcontrol = !empty(get_config('block_cmanager', 'norequestcontrol'));
$currentRecord = $DB->get_record('block_cmanager_records', array('id'=>$currentSess));
$mform =& $this->_form; // Don't forget the underscore!
// Page description text
$mform->addElement('html', '<p>' . get_string('modexists','block_cmanager') . '</p>');
$mform->addElement('html', '<table class="table table-striped">');
// Get out record
$currentRecord = $DB->get_record('block_cmanager_records', array('id'=>$currentSess));
$modCode = $currentRecord->modcode;
$modTitle = $currentRecord->modname;
$modMode = $currentRecord->modmode;
$spaceCheck = substr($modCode, 0, 4) . ' ' . substr($modCode, 4, strlen($modCode));
$selectQuery = "shortname LIKE '%$modCode%'
OR (shortname LIKE '%$spaceCheck%'
AND shortname LIKE '%$modMode%')
OR shortname LIKE '%$spaceCheck%'";
$recordsExist = $DB->record_exists_select('course', $selectQuery);
$allRecords = $DB->get_recordset_select('course', $select=$selectQuery);
// Table heading.
$showactions = empty($norequestcontrol) ? '<th>' . get_string('actions','block_cmanager') . '</th>' : '';
$mform->addElement('html', '
<tr>
<th>' . get_string('modcode','block_cmanager') . '</th>
<th>' . get_string('modname','block_cmanager') . '</th>
<th>' . get_string('catlocation','block_cmanager'). '</th>
<th>' . get_string('lecturingstaff','block_cmanager') . '</th>
' . $showactions . '
</tr>
');
foreach($allRecords as $record){
// Get the full category name
$categoryName = $DB->get_record('course_categories', array('id'=>$record->category));
// Get lecturer info
$lecturersHTML = block_cmanager_get_lecturers($record->id);
// Check if the category name is blank
if(!empty($categoryName->name)){
$catLocation = $categoryName->name;
} else {
$catLocation = ' ';
}
$showactions = empty($norequestcontrol) ? '<td><a href="requests/request_control.php?id=' . $record->id . '">' .
get_string('request_requestControl','block_cmanager') . '</a></td>' : '';
$mform->addElement('html', '
<tr>
<th>' . format_string($record->shortname) . '</th>
<td>' . format_string($record->fullname) .'</td>
<td>' . format_string($catLocation) . '</td>
<td>' . $lecturersHTML . '</td>
' . $showactions . '
</tr>
');
}
$mform->addElement('html', '</table>');
// Button: None of these? Continue.
if (empty($norequestcontrol)) {
$showactions = 'course_new.php?status=None';
} else {
$showactions = 'course_request.php?mode=1';
}
$mform->addElement('html', '<p><a class="btn btn-default" href="' . $showactions . '">' .
get_string('noneofthese','block_cmanager') . '</a></p>');
$mform->closeHeaderBefore('buttonar');
}
}
$mform = new block_cmanager_course_exists_form();//name of the form you defined in file above.
if ($mform->is_cancelled()){
} else if ($fromform=$mform->get_data()){
} else {
echo $OUTPUT->header();
$mform->focus();
$mform->set_data($mform);
$mform->display();
echo $OUTPUT->footer();
}