attendance_controller.php 27 KB

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