-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathreport2.php
375 lines (334 loc) · 16.3 KB
/
report2.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
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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/>.
/**
* New report.php for booked users, users on waiting list, deleted users etc.
*
* @package mod_booking
* @author Bernhard Fischer
* @copyright 2024 Wunderbyte GmbH <info@wunderbyte.at>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
require_once($CFG->dirroot . '/mod/booking/lib.php');
use mod_booking\booking;
use mod_booking\option\dates_handler;
use mod_booking\output\booked_users;
use mod_booking\singleton_service;
use mod_booking\utils\wb_payment;
global $PAGE, $SITE;
if (!get_config('booking', 'bookingstracker') || !wb_payment::pro_version_is_activated()) {
require_login(1, false);
$PAGE->set_url(new moodle_url('/mod/booking/report2.php'));
echo "<div class='alert alert-warning'>" . get_string('error:bookingstrackernotactivated', 'mod_booking') . "</div>";
}
$PAGE->requires->js_call_amd('mod_booking/bookingjslib', 'init');
$optiondateid = optional_param('optiondateid', 0, PARAM_INT);
$optionid = optional_param('optionid', 0, PARAM_INT);
$cmid = optional_param('cmid', 0, PARAM_INT);
$courseid = optional_param('courseid', 0, PARAM_INT);
$ticketicon = '<i class="fa fa-fw fa-sm fa-ticket" aria-hidden="true"></i> ';
$linkicon = '<i class="fa fa-fw fa-xs fa-external-link" aria-hidden="true"></i> ';
$divider = "<span class='mt-1 ml-1 mr-1 mt-4'>
<i class='fa-solid fa-2xs fa-angle-right' aria-hidden='true' style='color: gray;'></i>
</span>";
$r2syscontext = context_system::instance();
$r2syscap = has_capability('mod/booking:managebookedusers', $r2syscontext);
$r2systemurl = new moodle_url('/mod/booking/report2.php');
if (!empty($optiondateid)) {
// We are in optiondate (session) scope.
$PAGE->set_url(new moodle_url('/mod/booking/report2.php', ['optionid' => $optionid, 'optiondateid' => $optiondateid]));
$scopes = ['system', 'course', 'instance', 'option', 'optiondate'];
$scope = 'optiondate'; // A specific date of a booking option.
$scopeid = $optiondateid;
if (empty($optionid)) {
$optionid = $DB->get_field('booking_optiondates', 'optionid', ['id' => $optiondateid]);
}
$optionsettings = singleton_service::get_instance_of_booking_option_settings($optionid);
$cmid = $optionsettings->cmid;
$bookingsettings = singleton_service::get_instance_of_booking_settings_by_cmid($cmid);
[$course, $cm] = get_course_and_cm_from_cmid($cmid);
$courseid = $course->id;
require_course_login($course, false, $cm);
$urlparams = ["optionid" => $optionid, "optiondateid" => $optiondateid]; // For PAGE url.
// Define scope contexts.
$r2coursecontext = context_course::instance($courseid);
$r2instancecontext = context_module::instance($cmid);
// Check capabilities.
require_capability('mod/booking:readresponses', $r2instancecontext);
require_capability('mod/booking:managebookedusers', $r2instancecontext);
if (
(
has_capability('mod/booking:updatebooking', $r2instancecontext)
|| (
has_capability('mod/booking:addeditownoption', $r2instancecontext)
&& booking_check_if_teacher($optionid)
)
) == false
) {
throw new moodle_exception('nopermissions');
}
$r2courseurl = new moodle_url('/mod/booking/report2.php', ['courseid' => $courseid]);
$r2instanceurl = new moodle_url('/mod/booking/report2.php', ['cmid' => $cmid]);
$r2optionurl = new moodle_url('/mod/booking/report2.php', ['optionid' => $optionid]);
// To create the correct links.
$r2coursecap = has_capability('mod/booking:managebookedusers', $r2coursecontext);
$r2instancecap = has_capability('mod/booking:managebookedusers', $r2instancecontext);
// Get the optiondate record from DB.
$optiondate = $DB->get_record('booking_optiondates', ['id' => $optiondateid]);
$prettydatestring = dates_handler::prettify_optiondates_start_end(
$optiondate->coursestarttime,
$optiondate->courseendtime,
current_language(),
true
);
// We only show links, if we have the matching capabilities.
$heading = get_string('managebookedusers_heading', 'mod_booking', $optionsettings->get_title_with_prefix()) .
" - " . $prettydatestring;
$navhtml = "<div class='report2-nav mb-3 flex-wrap-container'>" .
($r2syscap ? "<a href='{$r2systemurl}' class='report2-system-border'>" :
"<span class='report2-system-border'>") .
$ticketicon . booking::shorten_text($SITE->fullname) .
($r2syscap ? "</a>" : "</span>") .
$divider .
($r2coursecap ? "<a href='{$r2courseurl}' class='report2-course-border'>" :
"<span class='report2-course-border'>") .
$ticketicon . booking::shorten_text($course->fullname) .
($r2coursecap ? "</a>" : "</span>") .
$divider .
($r2instancecap ? "<a href='{$r2instanceurl}' class='report2-instance-border'>" :
"<span class='report2-instance-border'>") .
$ticketicon . booking::shorten_text($bookingsettings->name) .
($r2instancecap ? "</a>" : "</span>") .
$divider .
"<a href='{$r2optionurl}' class='report2-option-border'>" .
$ticketicon . $optionsettings->get_title_with_prefix() .
"</a>";
// Create a navigation dropdown for all optiondates (sessions) of the booking option.
$optiondates = $optionsettings->sessions;
if (!empty($optiondates) && count($optiondates) > 1) {
$data['optiondatesexist'] = true;
foreach ($optiondates as &$optiondate) {
$optiondate = (array) $optiondate;
$optiondate['prettydate'] = dates_handler::prettify_optiondates_start_end(
$optiondate['coursestarttime'],
$optiondate['courseendtime'],
current_language(),
true
);
$dateurl = new moodle_url('/mod/booking/report2.php', [
'optionid' => $optionid,
'optiondateid' => $optiondate['id'],
]);
$optiondate['dateurl'] = $dateurl->out(false);
}
$firstentry['prettydate'] = get_string('choose...', 'mod_booking');
$firstentry['dateurl'] = $PAGE->url; // The current page.
array_unshift($optiondates, $firstentry);
$data['optiondates'] = array_values((array) $optiondates);
// Now we just append the dropdown to the navigation HTML.
$navhtml .= $divider . $OUTPUT->render_from_template('mod_booking/report/navigation_dropdown', $data);
}
$navhtml .= "</div>";
} else if (!empty($optionid)) {
// We are in option scope.
$PAGE->set_url(new moodle_url('/mod/booking/report2.php', ['optionid' => $optionid]));
$scopes = ['system', 'course', 'instance', 'option'];
$optionsettings = singleton_service::get_instance_of_booking_option_settings($optionid);
$cmid = $optionsettings->cmid;
$bookingsettings = singleton_service::get_instance_of_booking_settings_by_cmid($cmid);
[$course, $cm] = get_course_and_cm_from_cmid($cmid);
$courseid = $course->id;
require_course_login($course, false, $cm);
$scope = 'option'; // If we have an optionid, we want the report for this booking option.
$scopeid = $optionid;
$urlparams = ["optionid" => $optionid]; // For PAGE url.
$r2courseurl = new moodle_url('/mod/booking/report2.php', ['courseid' => $courseid]);
$r2instanceurl = new moodle_url('/mod/booking/report2.php', ['cmid' => $cmid]);
$r2optionurl = new moodle_url('/mod/booking/view.php', [
'id' => $cmid,
'optionid' => $optionid,
'whichview' => 'showonlyone',
]);
// Define scope contexts.
$r2coursecontext = context_course::instance($courseid);
$r2instancecontext = context_module::instance($cmid);
// Check capabilities.
require_capability('mod/booking:readresponses', $r2instancecontext);
require_capability('mod/booking:managebookedusers', $r2instancecontext);
if (
(
has_capability('mod/booking:updatebooking', $r2instancecontext)
|| (
has_capability('mod/booking:addeditownoption', $r2instancecontext)
&& booking_check_if_teacher($optionid)
)
) == false
) {
throw new moodle_exception('nopermissions');
}
// To create the correct links.
$r2coursecap = has_capability('mod/booking:managebookedusers', $r2coursecontext);
$r2instancecap = has_capability('mod/booking:managebookedusers', $r2instancecontext);
// We only show links, if we have the matching capabilities.
$heading = get_string('managebookedusers_heading', 'mod_booking', $optionsettings->get_title_with_prefix());
$navhtml = "<div class='report2-nav mb-3 flex-wrap-container'>" .
($r2syscap ? "<a href='{$r2systemurl}' class='report2-system-border'>" :
"<span class='report2-system-border'>") .
$ticketicon . booking::shorten_text($SITE->fullname) .
($r2syscap ? "</a>" : "</span>") .
$divider .
($r2coursecap ? "<a href='{$r2courseurl}' class='report2-course-border'>" :
"<span class='report2-course-border'>") .
$ticketicon . booking::shorten_text($course->fullname) .
($r2coursecap ? "</a>" : "</span>") .
$divider .
($r2instancecap ? "<a href='{$r2instanceurl}' class='report2-instance-border'>" :
"<span class='report2-instance-border'>") .
$ticketicon . booking::shorten_text($bookingsettings->name) .
($r2instancecap ? "</a>" : "</span>") .
$divider .
"<a href='{$r2optionurl}' class='report2-option-border'>" .
$linkicon . $optionsettings->get_title_with_prefix() .
"</a>";
// Create a navigation dropdown for all optiondates (sessions) of the booking option.
$optiondates = $optionsettings->sessions;
if (!empty($optiondates) && count($optiondates) > 1) {
$data['optiondatesexist'] = true;
foreach ($optiondates as &$optiondate) {
$optiondate = (array) $optiondate;
$optiondate['prettydate'] = dates_handler::prettify_optiondates_start_end(
$optiondate['coursestarttime'],
$optiondate['courseendtime'],
current_language(),
true
);
$dateurl = new moodle_url('/mod/booking/report2.php', [
'optionid' => $optionid,
'optiondateid' => $optiondate['id'],
]);
$optiondate['dateurl'] = $dateurl->out(false);
}
$firstentry['prettydate'] = get_string('choose...', 'mod_booking');
$firstentry['dateurl'] = $PAGE->url; // The current page.
array_unshift($optiondates, $firstentry);
$data['optiondates'] = array_values((array) $optiondates);
// Now we just append the dropdown to the navigation HTML.
$navhtml .= $divider . $OUTPUT->render_from_template('mod_booking/report/navigation_dropdown', $data);
}
$navhtml .= "</div>";
} else if (!empty($cmid)) {
// We are in instance scope.
$PAGE->set_url(new moodle_url('/mod/booking/report2.php', ['cmid' => $cmid]));
$scopes = ['system', 'course', 'instance'];
$scope = 'instance';
$scopeid = $cmid;
$bookingsettings = singleton_service::get_instance_of_booking_settings_by_cmid($cmid);
[$course, $cm] = get_course_and_cm_from_cmid($cmid);
$courseid = $course->id;
require_course_login($course, false, $cm);
$urlparams = ["cmid" => $cmid]; // For PAGE url.
$r2courseurl = new moodle_url('/mod/booking/report2.php', ['courseid' => $courseid]);
$r2instanceurl = new moodle_url('/mod/booking/view.php', ['id' => $cmid]);
// Define scope contexts.
$r2coursecontext = context_course::instance($courseid);
$r2instancecontext = context_module::instance($cmid);
// To create the correct links.
$r2coursecap = has_capability('mod/booking:managebookedusers', $r2coursecontext);
$r2instancecap = has_capability('mod/booking:managebookedusers', $r2instancecontext);
require_capability('mod/booking:readresponses', $r2instancecontext);
require_capability('mod/booking:managebookedusers', $r2instancecontext);
// We only show links, if we have the matching capabilities.
$heading = get_string('managebookedusers_heading', 'mod_booking', $bookingsettings->name);
$navhtml =
($r2syscap ? "<a href='{$r2systemurl}' class='report2-system-border'>" :
"<span class='report2-system-border'>") .
$ticketicon . booking::shorten_text($SITE->fullname) .
($r2syscap ? "</a>" : "</span>") .
$divider .
($r2coursecap ? "<a href='{$r2courseurl}' class='report2-course-border'>" :
"<span class='report2-course-border'>") .
$ticketicon . booking::shorten_text($course->fullname) .
($r2coursecap ? "</a>" : "</span>") .
$divider .
"<a href='{$r2instanceurl}' class='report2-instance-border'>" .
$linkicon . $bookingsettings->name .
"</a>";
} else if (!empty($courseid)) {
// We are in course scope.
$PAGE->set_url(new moodle_url('/mod/booking/report2.php', ['courseid' => $courseid]));
$scopes = ['system', 'course'];
$scope = 'course'; // A moodle course containing (a) booking option(s).
$scopeid = $courseid;
$course = get_course($courseid);
require_course_login($course, false);
$urlparams = ["courseid" => $courseid]; // For PAGE url.
$r2courseurl = new moodle_url('/course/view.php', ['id' => $courseid]);
// Define scope contexts.
$r2coursecontext = context_course::instance($courseid);
// To create the correct links.
$r2coursecap = has_capability('mod/booking:managebookedusers', $r2coursecontext);
require_capability('mod/booking:readresponses', $r2coursecontext);
require_capability('mod/booking:managebookedusers', $r2coursecontext);
// We only show links, if we have the matching capabilities.
$heading = get_string('managebookedusers_heading', 'mod_booking', $course->fullname);
$navhtml =
($r2syscap ? "<a href='{$r2systemurl}' class='report2-system-border'>" :
"<span class='report2-system-border'>") .
$ticketicon . booking::shorten_text($SITE->fullname) .
($r2syscap ? "</a>" : "</span>") .
$divider .
"<a href='$r2courseurl' class='report2-course-border'>" .
$linkicon . $course->fullname .
"</a>";
} else {
// We are in system scope.
$PAGE->set_url(new moodle_url('/mod/booking/report2.php'));
$scopes = ['system'];
require_login(1, false);
$scope = 'system'; // The whole site.
$scopeid = 0;
$urlparams = []; // For PAGE url.
$r2systemurl = new moodle_url('/');
require_capability('mod/booking:readresponses', $r2syscontext);
require_capability('mod/booking:managebookedusers', $r2syscontext);
// We only show links, if we have the matching capabilities.
$heading = get_string('managebookedusers_heading', 'mod_booking', $SITE->fullname);
$navhtml =
"<a href='$r2systemurl' class='report2-system-border'>" .
$linkicon . $SITE->fullname .
"</a>";
}
// Navigation stylings cannot be done in styles.css because of string localization.
echo booking::generate_localized_css_for_navigation_labels('report2', $scopes);
$url = new moodle_url('/mod/booking/report2.php', $urlparams);
$PAGE->set_url($url);
echo $OUTPUT->header();
echo $OUTPUT->heading("<div class='mt-3 mb-5'>$navhtml</div>" .
"<div class='mb-5'>" . $ticketicon . $heading . "</div>");
// Now we render the booked users for the provided scope.
$data = new booked_users(
$scope,
$scopeid,
true,
true,
true,
true,
true,
$cmid
);
$renderer = $PAGE->get_renderer('mod_booking');
echo $renderer->render_booked_users($data);
echo $OUTPUT->footer();