attendance_controller.php 25 KB

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