attendance_controller.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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 attendace,
  27. * render to attendance_list view
  28. * @param boolean true for listing history (optional)
  29. * @param array message for showing by action['edit','add','delete'] (optional)
  30. */
  31. public function attendance_list($history = false, $messages = array())
  32. {
  33. $data = array();
  34. // render to the view
  35. $this->view->set_data($data);
  36. $this->view->set_layout('layout');
  37. $this->view->set_template('attendance_list');
  38. $this->view->render();
  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 = array();
  48. if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
  49. if (!empty($_POST['title'])) {
  50. $check = Security::check_token();
  51. if ($check) {
  52. $attendance->set_name($_POST['title']);
  53. $attendance->set_description($_POST['description']);
  54. $attendance->set_attendance_qualify_title($_POST['attendance_qualify_title']);
  55. $attendance->set_attendance_weight($_POST['attendance_weight']);
  56. $link_to_gradebook = false;
  57. if ( isset($_POST['attendance_qualify_gradebook']) && $_POST['attendance_qualify_gradebook'] == 1 ) {
  58. $link_to_gradebook = true;
  59. }
  60. $attendance->category_id = $_POST['category_id'];
  61. $last_id = $attendance->attendance_add($link_to_gradebook);
  62. Security::clear_token();
  63. }
  64. header('location:index.php?action=calendar_add&attendance_id='.$last_id.'&'.api_get_cidreq());
  65. exit;
  66. } else {
  67. $data['error'] = true;
  68. $this->view->set_data($data);
  69. $this->view->set_layout('layout');
  70. $this->view->set_template('attendance_add');
  71. $this->view->render();
  72. }
  73. } else {
  74. $this->view->set_data($data);
  75. $this->view->set_layout('layout');
  76. $this->view->set_template('attendance_add');
  77. $this->view->render();
  78. }
  79. }
  80. /**
  81. * It's used for editing attendace,
  82. * render to attendance_edit or attendance_list view
  83. * @param int attendance id
  84. */
  85. public function attendance_edit($attendance_id)
  86. {
  87. $attendance = new Attendance();
  88. $data = array();
  89. $attendance_id = intval($attendance_id);
  90. if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
  91. if (!empty($_POST['title'])) {
  92. $check = Security::check_token();
  93. if ($check) {
  94. $attendance->set_name($_POST['title']);
  95. $attendance->set_description($_POST['description']);
  96. if (isset($_POST['attendance_qualify_title'])) {
  97. $attendance->set_attendance_qualify_title(
  98. $_POST['attendance_qualify_title']
  99. );
  100. }
  101. if (isset($_POST['attendance_weight'])) {
  102. $attendance->set_attendance_weight(
  103. $_POST['attendance_weight']
  104. );
  105. }
  106. $attendance->category_id = isset($_POST['category_id']) ? $_POST['category_id'] : '';
  107. $link_to_gradebook = false;
  108. if (isset($_POST['attendance_qualify_gradebook']) &&
  109. $_POST['attendance_qualify_gradebook'] == 1
  110. ) {
  111. $link_to_gradebook = true;
  112. }
  113. $attendance->attendance_edit($attendance_id,$link_to_gradebook);
  114. Security::clear_token();
  115. header('location:index.php?action=attendance_list&'.api_get_cidreq());
  116. exit;
  117. }
  118. } else {
  119. $data['attendance_id'] = $_POST['attendance_id'];
  120. $data['error'] = true;
  121. $this->view->set_data($data);
  122. $this->view->set_layout('layout');
  123. $this->view->set_template('attendance_edit');
  124. $this->view->render();
  125. }
  126. } else {
  127. // default values
  128. $attendance_data = $attendance->get_attendance_by_id(
  129. $attendance_id
  130. );
  131. $data['attendance_id'] = $attendance_data['id'];
  132. $data['title'] = $attendance_data['name'];
  133. $data['description'] = $attendance_data['description'];
  134. $data['attendance_qualify_title'] = $attendance_data['attendance_qualify_title'];
  135. $data['attendance_weight'] = $attendance_data['attendance_weight'];
  136. $this->view->set_data($data);
  137. $this->view->set_layout('layout');
  138. $this->view->set_template('attendance_edit');
  139. $this->view->render();
  140. }
  141. }
  142. /**
  143. * It's used for delete attendaces
  144. * render to attendance_list view
  145. * @param int attendance id
  146. */
  147. public function attendance_delete($attendance_id)
  148. {
  149. $allowDeleteAttendance = api_get_setting('attendance.allow_delete_attendance');
  150. if ($allowDeleteAttendance !== 'true') {
  151. $this->attendance_list();
  152. return false;
  153. }
  154. $attendance = new Attendance();
  155. if (!empty($attendance_id)) {
  156. $affected_rows = $attendance->attendance_delete($attendance_id);
  157. }
  158. if ($affected_rows) {
  159. $message['message_attendance_delete'] = true;
  160. }
  161. $this->attendance_list();
  162. }
  163. /**
  164. * It's used for make attendance visible
  165. * render to attendance_list view
  166. * @param int $attendanceId
  167. */
  168. public function attendanceSetVisible($attendanceId)
  169. {
  170. $attendance = new Attendance();
  171. $affectedRows = null;
  172. if (!empty($attendanceId)) {
  173. $affectedRows = $attendance->changeVisibility($attendanceId, 1);
  174. }
  175. if ($affectedRows) {
  176. $message['message_attendance_delete'] = true;
  177. }
  178. $this->attendance_list();
  179. }
  180. /**
  181. * It's used for make attendance invisible
  182. * render to attendance_list view
  183. * @param int $attendanceId
  184. */
  185. public function attendanceSetInvisible($attendanceId)
  186. {
  187. $attendance = new Attendance();
  188. if (!empty($attendanceId)) {
  189. $affectedRows = $attendance->changeVisibility($attendanceId, 0);
  190. }
  191. if ($affectedRows) {
  192. $message['message_attendance_delete'] = true;
  193. }
  194. $this->attendance_list();
  195. }
  196. /**
  197. * Restores an attendance entry and fallback to attendances rendering
  198. * @param int $attendance_id
  199. */
  200. public function attendance_restore($attendance_id)
  201. {
  202. $attendance = new Attendance();
  203. if (!empty($attendance_id)) {
  204. $affected_rows = $attendance->attendance_restore($attendance_id);
  205. }
  206. if ($affected_rows) {
  207. $message['message_attendance_restore'] = true;
  208. }
  209. $this->attendance_list();
  210. }
  211. /**
  212. * Lock or unlock an attendance
  213. * render to attendance_list view
  214. * @param string $action (lock_attendance or unlock_attendance)
  215. * @param int $attendance_id
  216. * render to attendance_list view
  217. */
  218. public function lock_attendance($action, $attendance_id)
  219. {
  220. $attendance = new Attendance();
  221. $attendance_id = intval($attendance_id);
  222. if ($action == 'lock_attendance') {
  223. $result = $attendance->lock_attendance($attendance_id);
  224. } else {
  225. $result = $attendance->lock_attendance($attendance_id, false);
  226. }
  227. if ($result) {
  228. $message['message_locked_attendance'] = true;
  229. }
  230. $this->attendance_list();
  231. }
  232. public function export($id, $type = 'pdf')
  233. {
  234. $attendance = new Attendance();
  235. }
  236. /**
  237. * It's used for controlling attendance sheet (list, add),
  238. * render to attendance_sheet view
  239. * @param string $action
  240. * @param int $attendance_id
  241. * @param int $student_id
  242. * @param bool $edit
  243. */
  244. public function attendance_sheet($action, $attendance_id, $student_id = 0, $edit = true)
  245. {
  246. $attendance = new Attendance();
  247. $data = array();
  248. $data['attendance_id'] = $attendance_id;
  249. $groupId = isset($_REQUEST['group_id']) ? $_REQUEST['group_id'] : null;
  250. $data['users_in_course'] = $attendance->get_users_rel_course($attendance_id, $groupId);
  251. $filter_type = 'today';
  252. if (!empty($_REQUEST['filter'])) {
  253. $filter_type = $_REQUEST['filter'];
  254. }
  255. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  256. api_get_user_id(),
  257. api_get_course_info()
  258. );
  259. if ($edit == true) {
  260. if (api_is_allowed_to_edit(null, true) || $isDrhOfCourse) {
  261. $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, 0, $groupId);
  262. }
  263. } else {
  264. if (!empty($student_id)) {
  265. $user_id = intval($student_id);
  266. } else {
  267. $user_id = api_get_user_id();
  268. }
  269. if (api_is_allowed_to_edit(null, true) ||
  270. api_is_coach(api_get_session_id(), api_get_course_int_id()) ||
  271. $isDrhOfCourse
  272. ) {
  273. $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, 0, $groupId);
  274. } else {
  275. $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, $user_id, $groupId);
  276. }
  277. $data['faults'] = $attendance->get_faults_of_user($user_id, $attendance_id, $groupId);
  278. $data['user_id'] = $user_id;
  279. }
  280. $data['next_attendance_calendar_id'] = $attendance->get_next_attendance_calendar_id($attendance_id);
  281. $data['next_attendance_calendar_datetime'] = $attendance->get_next_attendance_calendar_datetime($attendance_id);
  282. if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
  283. if (isset($_POST['hidden_input'])) {
  284. foreach ($_POST['hidden_input'] as $cal_id) {
  285. $users_present = array();
  286. if (isset($_POST['check_presence'][$cal_id])) {
  287. $users_present = $_POST['check_presence'][$cal_id];
  288. }
  289. $attendance->attendance_sheet_add(
  290. $cal_id,
  291. $users_present,
  292. $attendance_id
  293. );
  294. }
  295. }
  296. $data['users_in_course'] = $attendance->get_users_rel_course($attendance_id, $groupId);
  297. $my_calendar_id = null;
  298. if (is_numeric($filter_type)) {
  299. $my_calendar_id = $filter_type;
  300. $filter_type = 'calendar_id';
  301. }
  302. $data['attendant_calendar'] = $attendance->get_attendance_calendar(
  303. $attendance_id,
  304. $filter_type,
  305. $my_calendar_id,
  306. $groupId
  307. );
  308. $data['attendant_calendar_all'] = $attendance->get_attendance_calendar($attendance_id, 'all', null, $groupId);
  309. $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, 0, $groupId);
  310. $data['next_attendance_calendar_id'] = $attendance->get_next_attendance_calendar_id($attendance_id);
  311. $data['next_attendance_calendar_datetime'] = $attendance->get_next_attendance_calendar_datetime($attendance_id);
  312. } else {
  313. $data['attendant_calendar_all'] = $attendance->get_attendance_calendar($attendance_id, 'all', null, $groupId);
  314. $data['attendant_calendar'] = $attendance->get_attendance_calendar($attendance_id, $filter_type, null, $groupId);
  315. }
  316. $data['edit_table'] = intval($edit);
  317. $data['is_locked_attendance'] = $attendance->is_locked_attendance($attendance_id);
  318. $this->view->set_data($data);
  319. $this->view->set_layout('layout');
  320. $this->view->set_template('attendance_sheet');
  321. $this->view->render();
  322. }
  323. /**
  324. * It's used for controlling attendance calendar (list, add, edit, delete),
  325. * render to attendance_calendar view
  326. * @param string $action (optional, by default 'calendar_list')
  327. * @param int $attendance_id (optional)
  328. * @param int $calendar_id (optional)
  329. */
  330. public function attendance_calendar($action = 'calendar_list', $attendance_id = 0, $calendar_id = 0)
  331. {
  332. $attendance = new Attendance();
  333. $calendar_id = intval($calendar_id);
  334. $data = array();
  335. $data['attendance_id'] = $attendance_id;
  336. $attendance_id = intval($attendance_id);
  337. $groupList = isset($_POST['groups']) ? array($_POST['groups']) : array();
  338. if ($action == 'calendar_add') {
  339. if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
  340. if (!isset($_POST['cancel'])) {
  341. if (isset($_POST['repeat'])) {
  342. //@todo check this error_logs
  343. $start_datetime = api_strtotime(
  344. api_get_utc_datetime($_POST['date_time']), 'UTC'
  345. );
  346. $end_datetime = api_strtotime(api_get_utc_datetime($_POST['end_date_time'].' 23:59:59'), 'UTC');
  347. $checkdate = api_is_valid_date(api_get_utc_datetime($_POST['end_date_time'].' 23:59:59'));
  348. $repeat_type = $_POST['repeat_type'];
  349. if (($end_datetime > $start_datetime) && $checkdate) {
  350. $attendance->attendance_repeat_calendar_add(
  351. $attendance_id,
  352. $start_datetime,
  353. $end_datetime,
  354. $repeat_type,
  355. $groupList
  356. );
  357. $action = 'calendar_list';
  358. } else {
  359. if (!$checkdate) {
  360. $data['error_checkdate'] = true;
  361. } else {
  362. $data['error_repeat_date'] = true;
  363. }
  364. $data['repeat'] = true;
  365. $action = 'calendar_add';
  366. }
  367. } else {
  368. $datetime = $_POST['date_time'];
  369. $datetimezone = api_get_utc_datetime($datetime);
  370. if (!empty($datetime)) {
  371. $attendance->set_date_time($datetimezone);
  372. $attendance->attendance_calendar_add($attendance_id, $groupList);
  373. $action = 'calendar_list';
  374. } else {
  375. $data['error_date'] = true;
  376. $action = 'calendar_add';
  377. }
  378. }
  379. } else {
  380. $action = 'calendar_list';
  381. }
  382. }
  383. } else if ($action === 'calendar_edit') {
  384. $data['calendar_id'] = $calendar_id;
  385. if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
  386. if (!isset($_POST['cancel'])) {
  387. $datetime = $_POST['date_time'];
  388. $datetimezone = api_get_utc_datetime($datetime);
  389. $attendance->set_date_time($datetimezone);
  390. $attendance->attendance_calendar_edit($calendar_id, $attendance_id);
  391. $data['calendar_id'] = 0;
  392. $action = 'calendar_list';
  393. } else {
  394. $action = 'calendar_list';
  395. }
  396. }
  397. } else if ($action == 'calendar_delete') {
  398. $attendance->attendance_calendar_delete($calendar_id, $attendance_id);
  399. $action = 'calendar_list';
  400. } else if ($action == 'calendar_all_delete') {
  401. $attendance->attendance_calendar_delete(0, $attendance_id, true);
  402. $action = 'calendar_list';
  403. }
  404. $data['action'] = $action;
  405. $data['attendance_calendar'] = $attendance->get_attendance_calendar(
  406. $attendance_id,
  407. 'all',
  408. null,
  409. null,
  410. true
  411. );
  412. $data['is_locked_attendance'] = $attendance->is_locked_attendance($attendance_id);
  413. // render to the view
  414. $this->view->set_data($data);
  415. $this->view->set_layout('layout');
  416. $this->view->set_template('attendance_calendar');
  417. $this->view->render();
  418. }
  419. /**
  420. * It's used to print attendance sheet
  421. * @param string $action
  422. * @param int $attendance_id
  423. */
  424. public function attendance_sheet_export_to_pdf($action, $attendance_id, $student_id = 0, $course_id = '')
  425. {
  426. $attendance = new Attendance();
  427. $courseInfo = CourseManager::get_course_information($course_id);
  428. $attendance->set_course_id($courseInfo['code']);
  429. $groupId = isset($_REQUEST['group_id']) ? $_REQUEST['group_id'] : null;
  430. $data_array = array();
  431. $data_array['attendance_id'] = $attendance_id;
  432. $data_array['users_in_course'] = $attendance->get_users_rel_course($attendance_id, $groupId);
  433. $filter_type = 'today';
  434. if (!empty($_REQUEST['filter'])) {
  435. $filter_type = $_REQUEST['filter'];
  436. }
  437. $my_calendar_id = null;
  438. if (is_numeric($filter_type)) {
  439. $my_calendar_id = $filter_type;
  440. $filter_type = 'calendar_id';
  441. }
  442. $data_array['attendant_calendar'] = $attendance->get_attendance_calendar(
  443. $attendance_id,
  444. $filter_type,
  445. $my_calendar_id,
  446. $groupId
  447. );
  448. if (api_is_allowed_to_edit(null, true) || api_is_drh()) {
  449. $data_array['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, 0, $groupId);
  450. } else {
  451. if (!empty($student_id)) {
  452. $user_id = intval($student_id);
  453. } else {
  454. $user_id = api_get_user_id();
  455. }
  456. $data_array['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, $user_id, $groupId);
  457. $data_array['faults'] = $attendance->get_faults_of_user($user_id, $attendance_id, $groupId);
  458. $data_array['user_id'] = $user_id;
  459. }
  460. $data_array['next_attendance_calendar_id'] = $attendance->get_next_attendance_calendar_id($attendance_id);
  461. // Set headers pdf.
  462. $courseCategory = CourseManager::get_course_category($courseInfo['category_code']);
  463. $teacherInfo = CourseManager::getTeacherListFromCourse(
  464. $courseInfo['real_id']
  465. );
  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' => true,
  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. * @throws ViewException
  567. */
  568. public function getAttendanceBaseInLogin($showForm = false, $exportToPdf = true)
  569. {
  570. $table = null;
  571. $formToDisplay = null;
  572. $startDate = null;
  573. $endDate = null;
  574. $sessionId = api_get_session_id();
  575. if ($showForm) {
  576. $form = new FormValidator(
  577. 'search',
  578. 'post',
  579. api_get_self() . '?' . api_get_cidreq(
  580. ) . '&action=calendar_logins'
  581. );
  582. $form->addDateRangePicker('range', get_lang('DateRange'));
  583. $form->addButton('submit', get_lang('Submit'));
  584. if ($form->validate()) {
  585. $values = $form->getSubmitValues();
  586. $startDate = api_get_utc_datetime($values['range_start']);
  587. $endDate = api_get_utc_datetime($values['range_end']);
  588. }
  589. $formToDisplay = $form->returnForm();
  590. } else {
  591. if (!empty($sessionId)) {
  592. $sessionInfo = api_get_session_info($sessionId);
  593. $startDate = $sessionInfo['access_start_date'];
  594. $endDate = $sessionInfo['access_end_date'];
  595. }
  596. }
  597. $attendance = new Attendance();
  598. if ($exportToPdf) {
  599. $result = $attendance->exportAttendanceLogin($startDate, $endDate);
  600. if (empty($result)) {
  601. api_not_allowed(true, get_lang('NoDataAvailable'));
  602. }
  603. }
  604. $table = $attendance->getAttendanceLoginTable($startDate, $endDate);
  605. $data = array(
  606. 'form' => $formToDisplay,
  607. 'table' => $table
  608. );
  609. $this->view->set_data($data);
  610. $this->view->set_layout('layout');
  611. $this->view->set_template('calendar_logins');
  612. $this->view->render();
  613. }
  614. }