1
|
|
|
<?php |
2
|
|
|
/* For licensing terms, see /license.txt */ |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* This file contains class used like controller, |
6
|
|
|
* it should be included inside a dispatcher file (e.g: index.php). |
7
|
|
|
* |
8
|
|
|
* !!! WARNING !!! : ALL DATES IN THIS MODULE ARE STORED IN UTC ! |
9
|
|
|
* DO NOT CONVERT DURING THE TRANSITION FROM CHAMILO 1.8.x TO 2.0 |
10
|
|
|
* |
11
|
|
|
* @author Christian Fasanando <[email protected]> |
12
|
|
|
* @author Julio Montoya <[email protected]> lot of bugfixes + improvements |
13
|
|
|
* |
14
|
|
|
* @package chamilo.attendance |
15
|
|
|
*/ |
16
|
|
|
class AttendanceController |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Constructor. |
20
|
|
|
*/ |
21
|
|
|
public function __construct() |
22
|
|
|
{ |
23
|
|
|
$this->toolname = 'attendance'; |
24
|
|
|
$this->view = new View($this->toolname); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* It's used for listing attendance, |
29
|
|
|
* render to attendance_list view. |
30
|
|
|
*/ |
31
|
|
|
public function attendance_list() |
32
|
|
|
{ |
33
|
|
|
// render to the view |
34
|
|
|
$this->view->set_data([]); |
35
|
|
|
$this->view->set_layout('layout'); |
36
|
|
|
$this->view->set_template('attendance_list'); |
37
|
|
|
$this->view->render(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* It's used for adding attendace, |
42
|
|
|
* render to attendance_add or attendance_list view. |
43
|
|
|
*/ |
44
|
|
|
public function attendance_add() |
45
|
|
|
{ |
46
|
|
|
$attendance = new Attendance(); |
47
|
|
|
$data = []; |
48
|
|
|
if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') { |
49
|
|
|
if (!empty($_POST['title'])) { |
50
|
|
|
$check = Security::check_token(); |
51
|
|
|
$attendanceId = 0; |
52
|
|
|
if ($check) { |
53
|
|
|
$attendance->set_name($_POST['title']); |
54
|
|
|
$attendance->set_description($_POST['description']); |
55
|
|
|
$attendance->set_attendance_qualify_title($_POST['attendance_qualify_title']); |
56
|
|
|
$attendance->set_attendance_weight($_POST['attendance_weight']); |
57
|
|
|
$link_to_gradebook = false; |
58
|
|
|
if (isset($_POST['attendance_qualify_gradebook']) && |
59
|
|
|
$_POST['attendance_qualify_gradebook'] == 1 |
60
|
|
|
) { |
61
|
|
|
$link_to_gradebook = true; |
62
|
|
|
} |
63
|
|
|
$attendance->category_id = isset($_POST['category_id']) ? $_POST['category_id'] : 0; |
64
|
|
|
$attendanceId = $attendance->attendance_add($link_to_gradebook); |
65
|
|
|
|
66
|
|
|
if ($attendanceId) { |
67
|
|
|
$form = new FormValidator('attendance_add'); |
68
|
|
|
Skill::saveSkills($form, ITEM_TYPE_ATTENDANCE, $attendanceId); |
69
|
|
|
} |
70
|
|
|
Security::clear_token(); |
71
|
|
|
} |
72
|
|
|
header('Location: index.php?action=calendar_add&attendance_id='.$attendanceId.'&'.api_get_cidreq()); |
73
|
|
|
exit; |
74
|
|
|
} else { |
75
|
|
|
$data['error'] = true; |
76
|
|
|
$this->view->set_data($data); |
77
|
|
|
$this->view->set_layout('layout'); |
78
|
|
|
$this->view->set_template('attendance_add'); |
79
|
|
|
$this->view->render(); |
80
|
|
|
} |
81
|
|
|
} else { |
82
|
|
|
$this->view->set_data($data); |
83
|
|
|
$this->view->set_layout('layout'); |
84
|
|
|
$this->view->set_template('attendance_add'); |
85
|
|
|
$this->view->render(); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* It's used for editing attendance, |
91
|
|
|
* render to attendance_edit or attendance_list view. |
92
|
|
|
* |
93
|
|
|
* @param int $attendance_id |
94
|
|
|
*/ |
95
|
|
|
public function attendance_edit($attendance_id) |
96
|
|
|
{ |
97
|
|
|
$attendance = new Attendance(); |
98
|
|
|
$data = []; |
99
|
|
|
$attendance_id = intval($attendance_id); |
100
|
|
|
|
101
|
|
|
if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') { |
102
|
|
|
if (!empty($_POST['title'])) { |
103
|
|
|
$check = Security::check_token(); |
104
|
|
|
if ($check) { |
105
|
|
|
$attendance->set_name($_POST['title']); |
106
|
|
|
$attendance->set_description($_POST['description']); |
107
|
|
|
if (isset($_POST['attendance_qualify_title'])) { |
108
|
|
|
$attendance->set_attendance_qualify_title( |
109
|
|
|
$_POST['attendance_qualify_title'] |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
if (isset($_POST['attendance_weight'])) { |
114
|
|
|
$attendance->set_attendance_weight( |
115
|
|
|
$_POST['attendance_weight'] |
116
|
|
|
); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$attendance->category_id = isset($_POST['category_id']) ? $_POST['category_id'] : ''; |
120
|
|
|
$link_to_gradebook = false; |
121
|
|
|
if (isset($_POST['attendance_qualify_gradebook']) && |
122
|
|
|
$_POST['attendance_qualify_gradebook'] == 1 |
123
|
|
|
) { |
124
|
|
|
$link_to_gradebook = true; |
125
|
|
|
} |
126
|
|
|
$attendance->attendance_edit($attendance_id, $link_to_gradebook); |
127
|
|
|
|
128
|
|
|
$form = new FormValidator('attendance_edit'); |
129
|
|
|
Skill::saveSkills($form, ITEM_TYPE_ATTENDANCE, $attendance_id); |
130
|
|
|
Display::addFlash(Display::return_message(get_lang('Updated'))); |
131
|
|
|
|
132
|
|
|
Security::clear_token(); |
133
|
|
|
header('Location:index.php?action=attendance_list&'.api_get_cidreq()); |
134
|
|
|
exit; |
135
|
|
|
} |
136
|
|
|
} else { |
137
|
|
|
$data['attendance_id'] = $_POST['attendance_id']; |
138
|
|
|
$data['error'] = true; |
139
|
|
|
$this->view->set_data($data); |
140
|
|
|
$this->view->set_layout('layout'); |
141
|
|
|
$this->view->set_template('attendance_edit'); |
142
|
|
|
$this->view->render(); |
143
|
|
|
} |
144
|
|
|
} else { |
145
|
|
|
// default values |
146
|
|
|
$attendance_data = $attendance->get_attendance_by_id( |
147
|
|
|
$attendance_id |
148
|
|
|
); |
149
|
|
|
$data['attendance_id'] = $attendance_data['id']; |
150
|
|
|
$data['title'] = $attendance_data['name']; |
151
|
|
|
$data['description'] = $attendance_data['description']; |
152
|
|
|
$data['attendance_qualify_title'] = $attendance_data['attendance_qualify_title']; |
153
|
|
|
$data['attendance_weight'] = $attendance_data['attendance_weight']; |
154
|
|
|
|
155
|
|
|
$this->view->set_data($data); |
156
|
|
|
$this->view->set_layout('layout'); |
157
|
|
|
$this->view->set_template('attendance_edit'); |
158
|
|
|
$this->view->render(); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* It's used for delete attendaces |
164
|
|
|
* render to attendance_list view. |
165
|
|
|
* |
166
|
|
|
* @param int $attendance_id |
167
|
|
|
* |
168
|
|
|
* @return bool |
169
|
|
|
*/ |
170
|
|
|
public function attendance_delete($attendance_id) |
171
|
|
|
{ |
172
|
|
|
$allowDeleteAttendance = api_get_setting('allow_delete_attendance'); |
173
|
|
|
if ($allowDeleteAttendance !== 'true') { |
174
|
|
|
$this->attendance_list(); |
175
|
|
|
|
176
|
|
|
return false; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
$attendance = new Attendance(); |
180
|
|
|
if (!empty($attendance_id)) { |
181
|
|
|
$affected_rows = $attendance->attendance_delete($attendance_id); |
182
|
|
|
Skill::deleteSkillsFromItem($attendance_id, ITEM_TYPE_ATTENDANCE); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
if ($affected_rows) { |
186
|
|
|
$message['message_attendance_delete'] = true; |
187
|
|
|
} |
188
|
|
|
$this->attendance_list(); |
189
|
|
|
|
190
|
|
|
return true; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* It's used for make attendance visible |
195
|
|
|
* render to attendance_list view. |
196
|
|
|
* |
197
|
|
|
* @param int $attendanceId |
198
|
|
|
*/ |
199
|
|
|
public function attendanceSetVisible($attendanceId) |
200
|
|
|
{ |
201
|
|
|
$attendance = new Attendance(); |
202
|
|
|
$affectedRows = null; |
203
|
|
|
if (!empty($attendanceId)) { |
204
|
|
|
$affectedRows = $attendance->changeVisibility($attendanceId, 1); |
205
|
|
|
} |
206
|
|
|
if ($affectedRows) { |
207
|
|
|
$message['message_attendance_delete'] = true; |
208
|
|
|
} |
209
|
|
|
$this->attendance_list(); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* It's used for make attendance invisible |
214
|
|
|
* render to attendance_list view. |
215
|
|
|
* |
216
|
|
|
* @param int $attendanceId |
217
|
|
|
*/ |
218
|
|
|
public function attendanceSetInvisible($attendanceId) |
219
|
|
|
{ |
220
|
|
|
$attendance = new Attendance(); |
221
|
|
|
if (!empty($attendanceId)) { |
222
|
|
|
$affectedRows = $attendance->changeVisibility($attendanceId, 0); |
223
|
|
|
} |
224
|
|
|
if ($affectedRows) { |
225
|
|
|
$message['message_attendance_delete'] = true; |
226
|
|
|
} |
227
|
|
|
$this->attendance_list(); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Restores an attendance entry and fallback to attendances rendering. |
232
|
|
|
* |
233
|
|
|
* @param int $attendance_id |
234
|
|
|
*/ |
235
|
|
|
public function attendance_restore($attendance_id) |
236
|
|
|
{ |
237
|
|
|
$attendance = new Attendance(); |
238
|
|
|
$affected_rows = false; |
239
|
|
|
if (!empty($attendance_id)) { |
240
|
|
|
$affected_rows = $attendance->attendance_restore($attendance_id); |
241
|
|
|
} |
242
|
|
|
if ($affected_rows) { |
243
|
|
|
$message['message_attendance_restore'] = true; |
244
|
|
|
} |
245
|
|
|
$this->attendance_list(); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Lock or unlock an attendance |
250
|
|
|
* render to attendance_list view. |
251
|
|
|
* |
252
|
|
|
* @param string $action (lock_attendance or unlock_attendance) |
253
|
|
|
* @param int $attendance_id |
254
|
|
|
* render to attendance_list view |
255
|
|
|
*/ |
256
|
|
|
public function lock_attendance($action, $attendance_id) |
257
|
|
|
{ |
258
|
|
|
$attendance = new Attendance(); |
259
|
|
|
$attendance_id = intval($attendance_id); |
260
|
|
|
|
261
|
|
|
if ($action == 'lock_attendance') { |
262
|
|
|
$result = $attendance->lock_attendance($attendance_id); |
263
|
|
|
} else { |
264
|
|
|
$result = $attendance->lock_attendance($attendance_id, false); |
265
|
|
|
} |
266
|
|
|
if ($result) { |
267
|
|
|
$message['message_locked_attendance'] = true; |
268
|
|
|
} |
269
|
|
|
$this->attendance_list(); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
public function export($id, $type = 'pdf') |
273
|
|
|
{ |
274
|
|
|
$attendance = new Attendance(); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* It's used for controlling attendance sheet (list, add), |
279
|
|
|
* render to attendance_sheet view. |
280
|
|
|
* |
281
|
|
|
* @param string $action |
282
|
|
|
* @param int $attendance_id |
283
|
|
|
* @param int $student_id |
284
|
|
|
* @param bool $edit |
285
|
|
|
*/ |
286
|
|
|
public function attendance_sheet( |
287
|
|
|
$action, |
288
|
|
|
$attendance_id, |
289
|
|
|
$student_id = 0, |
290
|
|
|
$edit = true |
291
|
|
|
) { |
292
|
|
|
$attendance = new Attendance(); |
293
|
|
|
$data = []; |
294
|
|
|
$data['attendance_id'] = $attendance_id; |
295
|
|
|
$groupId = isset($_REQUEST['group_id']) ? $_REQUEST['group_id'] : null; |
296
|
|
|
$data['users_in_course'] = $attendance->get_users_rel_course($attendance_id, $groupId); |
297
|
|
|
$data['faults'] = []; |
298
|
|
|
|
299
|
|
|
$filter_type = 'today'; |
300
|
|
|
if (!empty($_REQUEST['filter'])) { |
301
|
|
|
$filter_type = $_REQUEST['filter']; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
$isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh( |
305
|
|
|
api_get_user_id(), |
306
|
|
|
api_get_course_info() |
307
|
|
|
) || api_is_drh(); |
308
|
|
|
|
309
|
|
|
if ($edit == true) { |
310
|
|
|
if (api_is_allowed_to_edit(null, true) || $isDrhOfCourse) { |
311
|
|
|
$data['users_presence'] = $attendance->get_users_attendance_sheet( |
312
|
|
|
$attendance_id, |
313
|
|
|
0, |
314
|
|
|
$groupId |
315
|
|
|
); |
316
|
|
|
} |
317
|
|
|
} else { |
318
|
|
|
if (!empty($student_id)) { |
319
|
|
|
$user_id = intval($student_id); |
320
|
|
|
} else { |
321
|
|
|
$user_id = api_get_user_id(); |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
if (api_is_allowed_to_edit(null, true) || |
325
|
|
|
api_is_coach(api_get_session_id(), api_get_course_int_id()) || |
326
|
|
|
$isDrhOfCourse |
327
|
|
|
) { |
328
|
|
|
$data['users_presence'] = $attendance->get_users_attendance_sheet( |
329
|
|
|
$attendance_id, |
330
|
|
|
0, |
331
|
|
|
$groupId |
332
|
|
|
); |
333
|
|
|
} else { |
334
|
|
|
$data['users_presence'] = $attendance->get_users_attendance_sheet( |
335
|
|
|
$attendance_id, |
336
|
|
|
$user_id, |
337
|
|
|
$groupId |
338
|
|
|
); |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
$data['faults'] = $attendance->get_faults_of_user($user_id, $attendance_id, $groupId); |
342
|
|
|
$data['user_id'] = $user_id; |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
$data['next_attendance_calendar_id'] = $attendance->get_next_attendance_calendar_id( |
346
|
|
|
$attendance_id |
347
|
|
|
); |
348
|
|
|
$data['next_attendance_calendar_datetime'] = $attendance->getNextAttendanceCalendarDatetime( |
349
|
|
|
$attendance_id |
350
|
|
|
); |
351
|
|
|
|
352
|
|
|
if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') { |
353
|
|
|
$check = Security::check_token(); |
354
|
|
|
if ($check) { |
355
|
|
|
if (isset($_POST['hidden_input'])) { |
356
|
|
|
foreach ($_POST['hidden_input'] as $cal_id) { |
357
|
|
|
$users_present = []; |
358
|
|
|
if (isset($_POST['check_presence'][$cal_id])) { |
359
|
|
|
$users_present = $_POST['check_presence'][$cal_id]; |
360
|
|
|
} |
361
|
|
|
$attendance->attendance_sheet_add( |
362
|
|
|
$cal_id, |
363
|
|
|
$users_present, |
364
|
|
|
$attendance_id |
365
|
|
|
); |
366
|
|
|
} |
367
|
|
|
} |
368
|
|
|
Security::clear_token(); |
369
|
|
|
} |
370
|
|
|
$data['users_in_course'] = $attendance->get_users_rel_course($attendance_id, $groupId); |
371
|
|
|
$my_calendar_id = null; |
372
|
|
|
if (is_numeric($filter_type)) { |
373
|
|
|
$my_calendar_id = $filter_type; |
374
|
|
|
$filter_type = 'calendar_id'; |
375
|
|
|
} |
376
|
|
|
$data['attendant_calendar'] = $attendance->get_attendance_calendar( |
377
|
|
|
$attendance_id, |
378
|
|
|
$filter_type, |
379
|
|
|
$my_calendar_id, |
380
|
|
|
$groupId |
381
|
|
|
); |
382
|
|
|
$data['attendant_calendar_all'] = $attendance->get_attendance_calendar( |
383
|
|
|
$attendance_id, |
384
|
|
|
'all', |
385
|
|
|
null, |
386
|
|
|
$groupId |
387
|
|
|
); |
388
|
|
|
$data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, 0, $groupId); |
389
|
|
|
$data['next_attendance_calendar_id'] = $attendance->get_next_attendance_calendar_id($attendance_id); |
390
|
|
|
$data['next_attendance_calendar_datetime'] = $attendance->getNextAttendanceCalendarDatetime($attendance_id); |
391
|
|
|
} else { |
392
|
|
|
$data['attendant_calendar_all'] = $attendance->get_attendance_calendar( |
393
|
|
|
$attendance_id, |
394
|
|
|
'all', |
395
|
|
|
null, |
396
|
|
|
$groupId |
397
|
|
|
); |
398
|
|
|
$data['attendant_calendar'] = $attendance->get_attendance_calendar( |
399
|
|
|
$attendance_id, |
400
|
|
|
$filter_type, |
401
|
|
|
null, |
402
|
|
|
$groupId |
403
|
|
|
); |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
$attendanceInfo = $attendance->get_attendance_by_id($attendance_id); |
407
|
|
|
|
408
|
|
|
$allowSignature = api_get_configuration_value('enable_sign_attendance_sheet'); |
409
|
|
|
$allowComment = api_get_configuration_value('attendance_allow_comments'); |
410
|
|
|
$func = isset($_REQUEST['func']) ? $_REQUEST['func'] : null; |
411
|
|
|
$calendarId = isset($_REQUEST['calendar_id']) ? (int) $_REQUEST['calendar_id'] : null; |
412
|
|
|
$fullScreen = ($func == 'fullscreen' && $calendarId > 0 && $allowSignature); |
413
|
|
|
|
414
|
|
|
$data['edit_table'] = intval($edit); |
415
|
|
|
$data['is_locked_attendance'] = $attendance->is_locked_attendance($attendance_id); |
416
|
|
|
$data['allowSignature'] = $allowSignature; |
417
|
|
|
$data['allowComment'] = $allowComment; |
418
|
|
|
$data['fullScreen'] = $fullScreen; |
419
|
|
|
$data['attendanceName'] = $attendanceInfo['name']; |
420
|
|
|
|
421
|
|
|
if ($fullScreen) { |
422
|
|
|
if (api_is_allowed_to_edit()) { |
423
|
|
|
$uinfo = api_get_user_info(); |
424
|
|
|
$cinfo = api_get_course_info(); |
425
|
|
|
$data['calendarId'] = $calendarId; |
426
|
|
|
$data['trainer'] = api_get_person_name($uinfo['firstname'], $uinfo['lastname']); |
427
|
|
|
$data['courseName'] = $cinfo['title']; |
428
|
|
|
$attendanceCalendar = $attendance->get_attendance_calendar( |
429
|
|
|
$attendance_id, |
430
|
|
|
'calendar_id', |
431
|
|
|
$calendarId, |
432
|
|
|
$groupId |
433
|
|
|
); |
434
|
|
|
$data['attendanceCalendar'] = $attendanceCalendar[0]; |
435
|
|
|
$this->view->set_template('attendance_sheet_fullscreen'); |
436
|
|
|
} |
437
|
|
|
} else { |
438
|
|
|
$this->view->set_template('attendance_sheet'); |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
$this->view->set_data($data); |
442
|
|
|
$this->view->set_layout('layout'); |
443
|
|
|
$this->view->render(); |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* It's used for controlling attendance calendar (list, add, edit, delete), |
448
|
|
|
* render to attendance_calendar view. |
449
|
|
|
* |
450
|
|
|
* @param string $action (optional, by default 'calendar_list') |
451
|
|
|
* @param int $attendance_id (optional) |
452
|
|
|
* @param int $calendar_id (optional) |
453
|
|
|
*/ |
454
|
|
|
public function attendance_calendar($action = 'calendar_list', $attendance_id = 0, $calendar_id = 0) |
455
|
|
|
{ |
456
|
|
|
$attendance = new Attendance(); |
457
|
|
|
$calendar_id = intval($calendar_id); |
458
|
|
|
$data = []; |
459
|
|
|
$data['attendance_id'] = $attendance_id; |
460
|
|
|
$attendance_id = intval($attendance_id); |
461
|
|
|
$groupList = isset($_POST['groups']) ? [$_POST['groups']] : []; |
462
|
|
|
|
463
|
|
|
if ($action == 'calendar_add') { |
464
|
|
|
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { |
465
|
|
|
if (!isset($_POST['cancel'])) { |
466
|
|
|
if (isset($_POST['repeat'])) { |
467
|
|
|
//@todo check this error_logs |
468
|
|
|
$start_datetime = api_strtotime( |
469
|
|
|
api_get_utc_datetime($_POST['date_time']), |
470
|
|
|
'UTC' |
471
|
|
|
); |
472
|
|
|
|
473
|
|
|
$end_datetime = api_strtotime(api_get_utc_datetime($_POST['end_date_time'].' 23:59:59'), 'UTC'); |
474
|
|
|
$checkdate = api_is_valid_date(api_get_utc_datetime($_POST['end_date_time'].' 23:59:59')); |
475
|
|
|
|
476
|
|
|
$repeat_type = $_POST['repeat_type']; |
477
|
|
|
if (($end_datetime > $start_datetime) && $checkdate) { |
478
|
|
|
$attendance->attendance_repeat_calendar_add( |
479
|
|
|
$attendance_id, |
480
|
|
|
$start_datetime, |
481
|
|
|
$end_datetime, |
482
|
|
|
$repeat_type, |
483
|
|
|
$groupList, |
484
|
|
|
$_POST |
485
|
|
|
); |
486
|
|
|
$action = 'calendar_list'; |
487
|
|
|
} else { |
488
|
|
|
if (!$checkdate) { |
489
|
|
|
$data['error_checkdate'] = true; |
490
|
|
|
} else { |
491
|
|
|
$data['error_repeat_date'] = true; |
492
|
|
|
} |
493
|
|
|
$data['repeat'] = true; |
494
|
|
|
$action = 'calendar_add'; |
495
|
|
|
} |
496
|
|
|
} else { |
497
|
|
|
$datetime = $_POST['date_time']; |
498
|
|
|
$datetimezone = api_get_utc_datetime($datetime); |
499
|
|
|
if (!empty($datetime)) { |
500
|
|
|
$attendance->set_date_time($datetimezone); |
501
|
|
|
$attendance->attendance_calendar_add($attendance_id, $groupList); |
502
|
|
|
$action = 'calendar_list'; |
503
|
|
|
} else { |
504
|
|
|
$data['error_date'] = true; |
505
|
|
|
$action = 'calendar_add'; |
506
|
|
|
} |
507
|
|
|
} |
508
|
|
|
} else { |
509
|
|
|
$action = 'calendar_list'; |
510
|
|
|
} |
511
|
|
|
} |
512
|
|
|
} elseif ($action === 'calendar_edit') { |
513
|
|
|
$data['calendar_id'] = $calendar_id; |
514
|
|
|
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { |
515
|
|
|
if (!isset($_POST['cancel'])) { |
516
|
|
|
$datetime = $_POST['date_time']; |
517
|
|
|
$datetimezone = api_get_utc_datetime($datetime); |
518
|
|
|
$attendance->set_date_time($datetimezone); |
519
|
|
|
$attendance->attendance_calendar_edit($calendar_id, $attendance_id, $_POST); |
520
|
|
|
$data['calendar_id'] = 0; |
521
|
|
|
$action = 'calendar_list'; |
522
|
|
|
} else { |
523
|
|
|
$action = 'calendar_list'; |
524
|
|
|
} |
525
|
|
|
} |
526
|
|
|
} elseif ($action == 'calendar_delete') { |
527
|
|
|
$attendance->attendance_calendar_delete($calendar_id, $attendance_id); |
528
|
|
|
$action = 'calendar_list'; |
529
|
|
|
} elseif ($action == 'calendar_all_delete') { |
530
|
|
|
$attendance->attendance_calendar_delete(0, $attendance_id, true); |
531
|
|
|
$action = 'calendar_list'; |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
$data['action'] = $action; |
535
|
|
|
$data['attendance_calendar'] = $attendance->get_attendance_calendar( |
536
|
|
|
$attendance_id, |
537
|
|
|
'all', |
538
|
|
|
null, |
539
|
|
|
null, |
540
|
|
|
true |
541
|
|
|
); |
542
|
|
|
$data['is_locked_attendance'] = $attendance->is_locked_attendance($attendance_id); |
543
|
|
|
// render to the view |
544
|
|
|
$this->view->set_data($data); |
545
|
|
|
$this->view->set_layout('layout'); |
546
|
|
|
$this->view->set_template('attendance_calendar'); |
547
|
|
|
$this->view->render(); |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
/** |
551
|
|
|
* Checks the attendance sheet to export XLS. |
552
|
|
|
*/ |
553
|
|
|
public function attendanceSheetExportToXls( |
554
|
|
|
int $attendanceId, |
555
|
|
|
int $studentId = 0, |
556
|
|
|
string $courseCode = '', |
557
|
|
|
?int $groupId, |
558
|
|
|
?string $filter |
559
|
|
|
) { |
560
|
|
|
$attendance = new Attendance(); |
561
|
|
|
$courseInfo = api_get_course_info($courseCode); |
562
|
|
|
$attendance->set_course_id($courseInfo['code']); |
563
|
|
|
|
564
|
|
|
$filterType = 'today'; |
565
|
|
|
if (!empty($filter)) { |
566
|
|
|
$filterType = $filter; |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
$myCalendarId = null; |
570
|
|
|
if (is_numeric($filterType)) { |
571
|
|
|
$myCalendarId = $filterType; |
572
|
|
|
$filterType = 'calendar_id'; |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
$attendance->exportAttendanceSheetToXls( |
576
|
|
|
$attendanceId, |
577
|
|
|
$studentId, |
578
|
|
|
$courseCode, |
579
|
|
|
$groupId, |
580
|
|
|
$filterType, |
581
|
|
|
$myCalendarId |
582
|
|
|
); |
583
|
|
|
} |
584
|
|
|
|
585
|
|
|
/** |
586
|
|
|
* It's used to print attendance sheet. |
587
|
|
|
* |
588
|
|
|
* @param string $action |
589
|
|
|
* @param int $attendance_id |
590
|
|
|
*/ |
591
|
|
|
public function attendance_sheet_export_to_pdf( |
592
|
|
|
$action, |
593
|
|
|
$attendance_id, |
594
|
|
|
$student_id = 0, |
595
|
|
|
$course_id = '' |
596
|
|
|
) { |
597
|
|
|
$attendance = new Attendance(); |
598
|
|
|
$courseInfo = api_get_course_info($course_id); |
599
|
|
|
$attendance->set_course_id($courseInfo['code']); |
600
|
|
|
$groupId = isset($_REQUEST['group_id']) ? $_REQUEST['group_id'] : null; |
601
|
|
|
$data_array = []; |
602
|
|
|
$data_array['attendance_id'] = $attendance_id; |
603
|
|
|
$data_array['users_in_course'] = $attendance->get_users_rel_course($attendance_id, $groupId); |
604
|
|
|
|
605
|
|
|
$filter_type = 'today'; |
606
|
|
|
|
607
|
|
|
if (!empty($_REQUEST['filter'])) { |
608
|
|
|
$filter_type = $_REQUEST['filter']; |
609
|
|
|
} |
610
|
|
|
|
611
|
|
|
$my_calendar_id = null; |
612
|
|
|
if (is_numeric($filter_type)) { |
613
|
|
|
$my_calendar_id = $filter_type; |
614
|
|
|
$filter_type = 'calendar_id'; |
615
|
|
|
} |
616
|
|
|
|
617
|
|
|
$data_array['attendant_calendar'] = $attendance->get_attendance_calendar( |
618
|
|
|
$attendance_id, |
619
|
|
|
$filter_type, |
620
|
|
|
$my_calendar_id, |
621
|
|
|
$groupId |
622
|
|
|
); |
623
|
|
|
|
624
|
|
|
if (api_is_allowed_to_edit(null, true) || api_is_drh()) { |
625
|
|
|
$data_array['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, 0, $groupId); |
626
|
|
|
} else { |
627
|
|
|
if (!empty($student_id)) { |
628
|
|
|
$user_id = intval($student_id); |
629
|
|
|
} else { |
630
|
|
|
$user_id = api_get_user_id(); |
631
|
|
|
} |
632
|
|
|
$data_array['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, $user_id, $groupId); |
633
|
|
|
$data_array['faults'] = $attendance->get_faults_of_user($user_id, $attendance_id, $groupId); |
634
|
|
|
$data_array['user_id'] = $user_id; |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
$data_array['next_attendance_calendar_id'] = $attendance->get_next_attendance_calendar_id($attendance_id); |
638
|
|
|
|
639
|
|
|
// Set headers pdf. |
640
|
|
|
$courseCategory = CourseManager::get_course_category($courseInfo['categoryCode']); |
641
|
|
|
$teacherInfo = CourseManager::get_teacher_list_from_course_code($courseInfo['code']); |
642
|
|
|
$teacherName = null; |
643
|
|
|
foreach ($teacherInfo as $teacherData) { |
644
|
|
|
if ($teacherName != null) { |
645
|
|
|
$teacherName = $teacherName." / "; |
646
|
|
|
} |
647
|
|
|
$teacherName .= api_get_person_name($teacherData['firstname'], $teacherData['lastname']); |
648
|
|
|
} |
649
|
|
|
|
650
|
|
|
// Get data table |
651
|
|
|
$data_table = []; |
652
|
|
|
$head_table = ['#', get_lang('Name')]; |
653
|
|
|
foreach ($data_array['attendant_calendar'] as $class_day) { |
654
|
|
|
$labelDuration = !empty($class_day['duration']) ? get_lang('Duration').' : '.$class_day['duration'] : ''; |
655
|
|
|
$head_table[] = |
656
|
|
|
api_format_date($class_day['date_time'], DATE_FORMAT_NUMBER_NO_YEAR).' '. |
657
|
|
|
api_format_date($class_day['date_time'], TIME_NO_SEC_FORMAT).' '. |
658
|
|
|
$labelDuration; |
659
|
|
|
} |
660
|
|
|
$data_table[] = $head_table; |
661
|
|
|
$data_attendant_calendar = $data_array['attendant_calendar']; |
662
|
|
|
$data_users_presence = $data_array['users_presence']; |
663
|
|
|
$count = 1; |
664
|
|
|
|
665
|
|
|
if (!empty($data_array['users_in_course'])) { |
666
|
|
|
foreach ($data_array['users_in_course'] as $user) { |
667
|
|
|
$cols = 1; |
668
|
|
|
$result = []; |
669
|
|
|
$result['count'] = $count; |
670
|
|
|
$result['full_name'] = api_get_person_name($user['firstname'], $user['lastname']); |
671
|
|
|
foreach ($data_array['attendant_calendar'] as $class_day) { |
672
|
|
|
if ($class_day['done_attendance'] == 1) { |
673
|
|
|
if ($data_users_presence[$user['user_id']][$class_day['id']]['presence'] == 1) { |
674
|
|
|
$result[$class_day['id']] = get_lang('UserAttendedSymbol'); |
675
|
|
|
} else { |
676
|
|
|
$result[$class_day['id']] = '<span style="color:red">'.get_lang('UserNotAttendedSymbol').'</span>'; |
677
|
|
|
} |
678
|
|
|
} else { |
679
|
|
|
$result[$class_day['id']] = ' '; |
680
|
|
|
} |
681
|
|
|
$cols++; |
682
|
|
|
} |
683
|
|
|
$count++; |
684
|
|
|
$data_table[] = $result; |
685
|
|
|
} |
686
|
|
|
} |
687
|
|
|
$max_cols_per_page = 12; //10 dates + 2 name and number |
688
|
|
|
$max_dates_per_page = $max_dates_per_page_original = $max_cols_per_page - 2; //10 |
689
|
|
|
$rows = count($data_table); |
690
|
|
|
|
691
|
|
|
if ($cols > $max_cols_per_page) { |
692
|
|
|
$number_tables = round(($cols - 2) / $max_dates_per_page); |
693
|
|
|
$headers = $data_table[0]; |
694
|
|
|
$all = []; |
695
|
|
|
$tables = []; |
696
|
|
|
$changed = 1; |
697
|
|
|
|
698
|
|
|
for ($i = 0; $i <= $rows; $i++) { |
699
|
|
|
$row = isset($data_table[$i]) ? $data_table[$i] : null; |
700
|
|
|
$key = 1; |
701
|
|
|
$max_dates_per_page = 10; |
702
|
|
|
$item = isset($data_table[$i]) ? $data_table[$i] : null; |
703
|
|
|
$count_j = 0; |
704
|
|
|
|
705
|
|
|
if (!empty($item)) { |
706
|
|
|
foreach ($item as $value) { |
707
|
|
|
if ($count_j >= $max_dates_per_page) { |
708
|
|
|
$key++; |
709
|
|
|
$max_dates_per_page = $max_dates_per_page_original * $key; |
710
|
|
|
//magic hack |
711
|
|
|
$tables[$key][$i][] = $tables[1][$i][0]; |
712
|
|
|
$tables[$key][$i][] = $tables[1][$i][1]; |
713
|
|
|
} |
714
|
|
|
$tables[$key][$i][] = $value; |
715
|
|
|
$count_j++; |
716
|
|
|
} |
717
|
|
|
} |
718
|
|
|
} |
719
|
|
|
|
720
|
|
|
$content = null; |
721
|
|
|
if (!empty($tables)) { |
722
|
|
|
foreach ($tables as $sub_table) { |
723
|
|
|
$content .= Export::convert_array_to_html($sub_table).'<br /><br />'; |
724
|
|
|
} |
725
|
|
|
} |
726
|
|
|
} else { |
727
|
|
|
$content = Export::convert_array_to_html( |
728
|
|
|
$data_table, |
729
|
|
|
['header_attributes' => ['align' => 'center']] |
730
|
|
|
); |
731
|
|
|
} |
732
|
|
|
|
733
|
|
|
$params = [ |
734
|
|
|
'filename' => get_lang('Attendance').'-'.api_get_local_time(), |
735
|
|
|
'pdf_title' => $courseInfo['title'], |
736
|
|
|
'course_code' => $courseInfo['code'], |
737
|
|
|
'add_signatures' => ['Drh', 'Teacher', 'Date'], |
738
|
|
|
'orientation' => 'landscape', |
739
|
|
|
'pdf_teachers' => $teacherName, |
740
|
|
|
'pdf_course_category' => $courseCategory['name'], |
741
|
|
|
'format' => 'A4-L', |
742
|
|
|
'orientation' => 'L', |
743
|
|
|
]; |
744
|
|
|
|
745
|
|
|
Export::export_html_to_pdf($content, $params); |
746
|
|
|
exit; |
|
|
|
|
747
|
|
|
} |
748
|
|
|
|
749
|
|
|
/** |
750
|
|
|
* Gets attendance base in the table: |
751
|
|
|
* TABLE_STATISTIC_TRACK_E_COURSE_ACCESS. |
752
|
|
|
* |
753
|
|
|
* @param bool $showForm |
754
|
|
|
* @param bool $exportToPdf |
755
|
|
|
*/ |
756
|
|
|
public function getAttendanceBaseInLogin($showForm = false, $exportToPdf = true) |
757
|
|
|
{ |
758
|
|
|
$table = null; |
759
|
|
|
$formToDisplay = null; |
760
|
|
|
$startDate = null; |
761
|
|
|
$endDate = null; |
762
|
|
|
|
763
|
|
|
$sessionId = api_get_session_id(); |
764
|
|
|
if ($showForm) { |
765
|
|
|
$form = new FormValidator( |
766
|
|
|
'search', |
767
|
|
|
'post', |
768
|
|
|
api_get_self().'?'.api_get_cidreq().'&action=calendar_logins' |
769
|
|
|
); |
770
|
|
|
$form->addDateRangePicker('range', get_lang('DateRange')); |
771
|
|
|
$form->addButton('submit', get_lang('Submit')); |
772
|
|
|
|
773
|
|
|
if ($form->validate()) { |
774
|
|
|
$values = $form->getSubmitValues(); |
775
|
|
|
|
776
|
|
|
$startDate = api_get_utc_datetime($values['range_start']); |
777
|
|
|
$endDate = api_get_utc_datetime($values['range_end']); |
778
|
|
|
} |
779
|
|
|
$formToDisplay = $form->returnForm(); |
780
|
|
|
} else { |
781
|
|
|
if (!empty($sessionId)) { |
782
|
|
|
$sessionInfo = api_get_session_info($sessionId); |
783
|
|
|
$startDate = $sessionInfo['access_start_date']; |
784
|
|
|
$endDate = $sessionInfo['access_end_date']; |
785
|
|
|
} |
786
|
|
|
} |
787
|
|
|
|
788
|
|
|
$attendance = new Attendance(); |
789
|
|
|
if ($exportToPdf) { |
790
|
|
|
$result = $attendance->exportAttendanceLogin($startDate, $endDate); |
791
|
|
|
if (empty($result)) { |
792
|
|
|
api_not_allowed(true, get_lang('NoDataAvailable')); |
793
|
|
|
} |
794
|
|
|
} |
795
|
|
|
$table = $attendance->getAttendanceLoginTable($startDate, $endDate); |
796
|
|
|
$data = [ |
797
|
|
|
'form' => $formToDisplay, |
798
|
|
|
'table' => $table, |
799
|
|
|
]; |
800
|
|
|
$this->view->set_data($data); |
801
|
|
|
$this->view->set_layout('layout'); |
802
|
|
|
$this->view->set_template('calendar_logins'); |
803
|
|
|
$this->view->render(); |
804
|
|
|
} |
805
|
|
|
} |
806
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.