-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmysessions.php
241 lines (203 loc) · 10.2 KB
/
mysessions.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
<?php
/*
* This file is part of Totara LMS
*
* Copyright (C) 2009 Catalyst IT LTD
* Copyright (C) 2010 - 2012 Totara Learning Solutions LTD
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Alastair Munro <[email protected]>
* @author Francois Marier <[email protected]>
* @package blocks
* @subpackage facetoface
*/
// Displays sessions for which the current user is a "teacher" (can see attendees' list)
// as well as the ones where the user is signed up (i.e. a "student")
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
require_once('lib.php');
$PAGE->set_context(get_system_context());
require_login();
$timenow = time();
$timelater = $timenow + 13 * WEEKSECS;
$startyear = optional_param('startyear', strftime('%Y', $timenow), PARAM_INT);
$startmonth = optional_param('startmonth', strftime('%m', $timenow), PARAM_INT);
$startday = optional_param('startday', strftime('%d', $timenow), PARAM_INT);
$endyear = optional_param('endyear', strftime('%Y', $timelater), PARAM_INT);
$endmonth = optional_param('endmonth', strftime('%m', $timelater), PARAM_INT);
$endday = optional_param('endday', strftime('%d', $timelater), PARAM_INT);
$userid = optional_param('userid', $USER->id, PARAM_INT);
$action = optional_param('action', '', PARAM_ALPHA); // one of: '', export
$format = optional_param('format', 'ods', PARAM_ALPHA); // one of: ods, xls
// filter options
$coursename = optional_param('coursename', '', PARAM_TEXT);
$courseid = optional_param('courseid', '', PARAM_TEXT);
$trainer = optional_param('trainer', '', PARAM_TEXT);
$location = optional_param('location', '', PARAM_TEXT);
$startdate = make_timestamp($startyear, $startmonth, $startday);
$enddate = make_timestamp($endyear, $endmonth, $endday);
$urlparams = array('startyear' => $startyear, 'startmonth' => $startmonth, 'startday' => $startday,
'endyear' => $endyear, 'endmonth' => $endmonth, 'endday' => $endday, 'userid' => $userid);
$coursenamesql = '';
$coursenameparam = array();
$courseidsql = '';
$courseidparam = array();
if ($coursename) {
$coursenamesql = ' AND c.fullname = ?';
$coursenameparam[] = $coursename;
}
if ($courseid) {
$courseidsql = ' AND c.idnumber = ?';
$courseidparam[] = $courseid;
}
$records = '';
// Get all Face-to-face session dates from the DB
$records = $DB->get_records_sql("SELECT d.id, cm.id AS cmid, c.id AS courseid, c.fullname AS coursename,
c.idnumber as cidnumber, f.name, f.id as facetofaceid, s.id as sessionid,
s.datetimeknown, d.timestart, d.timefinish, su.nbbookings
FROM {facetoface_sessions_dates} d
JOIN {facetoface_sessions} s ON s.id = d.sessionid
JOIN {facetoface} f ON f.id = s.facetoface
LEFT OUTER JOIN (SELECT sessionid, count(sessionid) AS nbbookings
FROM {facetoface_signups} su
LEFT JOIN {facetoface_signups_status} ss
ON ss.signupid = su.id AND ss.superceded = 0
WHERE ss.statuscode >= ?
GROUP BY sessionid) su ON su.sessionid = d.sessionid
JOIN {course} c ON f.course = c.id
JOIN {course_modules} cm ON cm.course = f.course
AND cm.instance = f.id
JOIN {modules} m ON m.id = cm.module
WHERE d.timestart >= ? AND d.timefinish <= ?
AND m.name = 'facetoface'
$coursenamesql
$courseidsql", array_merge(array(MDL_F2F_STATUS_BOOKED, $startdate, $enddate), $coursenameparam, $courseidparam));
$show_location = add_location_info($records);
// Only keep the sessions for which this user can see attendees
$dates = array();
if ($records) {
$capability = 'mod/facetoface:viewattendees';
// Check the system context first
$contextsystem = context_system::instance();
if (has_capability($capability, $contextsystem)) {
// check if the location or trainer filters need to be used
if ($location or $trainer) {
foreach ($records as $record) {
if ($record->location === $location) {
$dates[] = $record;
}
if (isset($record->trainers)) {
foreach ($record->trainers as $t) {
if ($t === $trainer) {
$dates[] = $record;
continue;
}
}
}
}
} else {
$dates = $records;
}
} else {
foreach ($records as $record) {
if ($location || $trainer) {
// Check at course level first
$contextcourse = context_course::instance($record->courseid);
if (has_capability($capability, $contextcourse)) {
if ($record->location === $location) {
$dates[] = $record;
}
if (isset($record->trainers)) {
foreach ($record->trainers as $t) {
if ($t === $trainer) {
$dates[] = $record;
continue;
}
}
}
continue;
}
// Check at module level if the first check failed
$contextmodule = context_module::instance($record->cmid);
if (has_capability($capability, $contextmodule)) {
if ($record->location === $location) {
$dates[] = $record;
}
if (isset($record->trainers)) {
foreach ($record->trainers as $t) {
if ($t === $trainer) {
$dates[] = $record;
continue;
}
}
}
}
}
}
}
}
$nbdates = count($dates);
// Process actions if any
if ('export' == $action) {
export_spreadsheet($dates, $format, true);
exit;
}
// format the session and dates to only show one booking where they span multiple dates
// i.e. multiple days startdate = firstday, finishdate = last day
$groupeddates = group_session_dates($dates);
$pagetitle = format_string(get_string('facetoface', 'facetoface') . ' ' . get_string('sessions', 'block_facetoface'));
$PAGE->navbar->add($pagetitle);
$PAGE->set_title($pagetitle);
$PAGE->set_heading($SITE->fullname);
$PAGE->set_url('/blocks/facetoface/mysessions.php');
$PAGE->set_pagelayout('standard');
echo $OUTPUT->header();
echo $OUTPUT->box_start();
// show tabs
$currenttab = 'attendees';
include_once('tabs.php');
$renderer = $PAGE->get_renderer('block_facetoface');
if (empty($users)) {
// Date range form
echo $OUTPUT->heading(get_string('filters', 'block_facetoface'), 2);
echo html_writer::start_tag('form', array('method' => 'get', 'action' => '')) . html_writer::start_tag('p');
print_facetoface_filters($startdate, $enddate, $coursename, $courseid, $location, $trainer);
echo html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('apply', 'block_facetoface'))) . html_writer::end_tag('p') . html_writer::end_tag('form');
}
// Show all session dates
if ($nbdates > 0) {
echo $OUTPUT->heading(get_string('sessiondatesview', 'block_facetoface'), 2);
echo $renderer->print_dates($groupeddates, true, false, false, false, false, $show_location);
// Export form
echo $OUTPUT->heading(get_string('exportsessiondates', 'block_facetoface'), 3);
echo html_writer::start_tag('form', array('method' => 'post', 'action' => "")) . html_writer::start_tag('p');
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'startyear', 'value' => $startyear));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'startmonth', 'value' => $startmonth));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'startday', 'value' => $startday));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'endyear', 'value' => $endyear));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'endmonth', 'value' => $endmonth));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'endday', 'value' => $endday));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'export'));
echo get_string('format', 'facetoface').': ';
echo html_writer::start_tag('select', array('name' => 'format'));
echo html_writer::tag('option', get_string('excelformat', 'facetoface'), array('value' => 'excel', 'selected' => 'selected'));
echo html_writer::tag('option', get_string('odsformat', 'facetoface'), array('value' => 'ods'));
echo html_writer::end_tag('select');
echo html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('exporttofile', 'facetoface'))). html_writer::end_tag('p') . html_writer::end_tag('form');
} else {
echo $OUTPUT->heading(get_string('sessiondatesview', 'block_facetoface'), 2);
echo html_writer::tag('p', get_string('sessiondatesviewattendeeszero', 'block_facetoface'));
}
echo $OUTPUT->box_end();
echo $OUTPUT->footer();