attendance_controller.php 26 KB

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