attendance_sheet.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * View (MVC patter) for attendance sheet (list, edit, add).
  5. *
  6. * @author Christian Fasanando <christian1827@gmail.com>
  7. * @author Julio Montoya reworked 2010
  8. *
  9. * @package chamilo.attendance
  10. */
  11. // Protect a course script
  12. api_protect_course_script(true);
  13. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  14. api_get_user_id(),
  15. api_get_course_info()
  16. ) || api_is_drh();
  17. if (api_is_allowed_to_edit(null, true) ||
  18. api_is_coach(api_get_session_id(), api_get_course_int_id()) ||
  19. $isDrhOfCourse
  20. ) {
  21. $groupId = isset($_REQUEST['group_id']) ? intval($_REQUEST['group_id']) : null;
  22. $form = new FormValidator(
  23. 'filter',
  24. 'post',
  25. 'index.php?action=attendance_sheet_list&'.api_get_cidreq().'&attendance_id='.$attendance_id,
  26. null,
  27. [],
  28. 'inline'
  29. );
  30. $values = [
  31. 'all' => get_lang('All'),
  32. 'today' => get_lang('Today'),
  33. 'all_done' => get_lang('AllDone'),
  34. 'all_not_done' => get_lang('AllNotDone'),
  35. ];
  36. $today = api_convert_and_format_date(null, DATE_FORMAT_SHORT);
  37. $exists_attendance_today = false;
  38. if (!empty($attendant_calendar_all)) {
  39. $values[''] = '---------------';
  40. foreach ($attendant_calendar_all as $attendance_date) {
  41. $includeCalendar = true;
  42. if (isset($attendance_date['groups']) && !empty($groupId)) {
  43. foreach ($attendance_date['groups'] as $group) {
  44. if ($groupId == $group['group_id']) {
  45. $includeCalendar = true;
  46. break;
  47. } else {
  48. $includeCalendar = false;
  49. }
  50. }
  51. }
  52. if ($today == $attendance_date['date']) {
  53. $exists_attendance_today = true;
  54. }
  55. if ($includeCalendar) {
  56. $values[$attendance_date['id']] = $attendance_date['date_time'];
  57. }
  58. }
  59. }
  60. if (!$exists_attendance_today) {
  61. echo Display::return_message(
  62. get_lang('ThereIsNoClassScheduledTodayTryPickingAnotherDay'),
  63. 'warning'
  64. );
  65. }
  66. $form->addSelect(
  67. 'filter',
  68. get_lang('Filter'),
  69. $values,
  70. ['id' => 'filter_id', 'onchange' => 'submit();']
  71. );
  72. $groupList = GroupManager::get_group_list(null, null, 1);
  73. $groupIdList = ['--'];
  74. foreach ($groupList as $group) {
  75. $groupIdList[$group['id']] = $group['name'];
  76. }
  77. if (!empty($groupList)) {
  78. $form->addSelect('group_id', get_lang('Group'), $groupIdList);
  79. }
  80. if (isset($_REQUEST['filter'])) {
  81. if (in_array($_REQUEST['filter'], array_keys($values))) {
  82. $default_filter = $_REQUEST['filter'];
  83. }
  84. } else {
  85. $default_filter = 'today';
  86. }
  87. $renderer = $form->defaultRenderer();
  88. $renderer->setCustomElementTemplate('<div class="col-md-2">{label}</div><div class="col-md-10"> {element} </div>');
  89. $form->setDefaults(
  90. [
  91. 'filter' => $default_filter,
  92. 'group_id' => $groupId,
  93. ]
  94. );
  95. if (!$is_locked_attendance || api_is_platform_admin()) {
  96. $actionsLeft = '<a style="float:left;" href="index.php?'.api_get_cidreq().'&action=calendar_list&attendance_id='.$attendance_id.'">'.
  97. Display::return_icon('attendance_calendar.png', get_lang('AttendanceCalendar'), '', ICON_SIZE_MEDIUM).'</a>';
  98. $actionsLeft .= '<a id="pdf_export" style="float:left;" href="index.php?'.api_get_cidreq().'&action=attendance_sheet_export_to_pdf&attendance_id='.$attendance_id.'&filter='.$default_filter.'&group_id='.$groupId.'">'.
  99. Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>';
  100. $actionsRight = $form->returnForm();
  101. $toolbar = Display::toolbarAction('toolbar-attendance', [$actionsLeft, $actionsRight]);
  102. echo $toolbar;
  103. }
  104. $message_information = get_lang('AttendanceSheetDescription');
  105. if (!empty($message_information)) {
  106. $message = '<strong>'.get_lang('Information').'</strong><br />';
  107. $message .= $message_information;
  108. echo Display::return_message($message, 'normal', false);
  109. }
  110. if ($is_locked_attendance) {
  111. echo Display::return_message(get_lang('TheAttendanceSheetIsLocked'), 'warning', false);
  112. }
  113. $param_filter = '&filter='.Security::remove_XSS($default_filter).'&group_id='.$groupId;
  114. if (count($users_in_course) > 0) {
  115. ?>
  116. <script>
  117. var original_url = '';
  118. $("#filter_id").on('change', function() {
  119. filter = $(this).val();
  120. if (original_url == '') {
  121. original_url = $("#pdf_export").attr('href');
  122. }
  123. new_url = original_url + "&filter=" +filter
  124. $("#pdf_export").attr('href', new_url);
  125. });
  126. function UpdateTableHeaders() {
  127. $("div.divTableWithFloatingHeader").each(function() {
  128. var originalHeaderRow = $(".tableFloatingHeaderOriginal", this);
  129. var floatingHeaderRow = $(".tableFloatingHeader", this);
  130. var offset = $(this).offset();
  131. var scrollTop = $(window).scrollTop();
  132. if ((scrollTop > offset.top) && (scrollTop < offset.top + $(this).height())) {
  133. floatingHeaderRow.css("visibility", "hidden");
  134. var topbar = 0;
  135. if ($("#topbar").length != 0) {
  136. topbar = $("#topbar").height();
  137. } else {
  138. if ($(".subnav").length != 0) {
  139. topbar = $(".subnav").height();
  140. }
  141. }
  142. var top_value = Math.min(scrollTop - offset.top, $(this).height() - floatingHeaderRow.height()) + topbar;
  143. floatingHeaderRow.css("top", top_value + "px");
  144. // Copy cell widths from original header
  145. $("th", floatingHeaderRow).each(function(index) {
  146. var cellWidth = $("th", originalHeaderRow).eq(index).css('width');
  147. $(this).css('width', cellWidth);
  148. });
  149. // Copy row width from whole table
  150. floatingHeaderRow.css("width", $(this).css("width"));
  151. floatingHeaderRow.css("visibility", "visible");
  152. floatingHeaderRow.css("z-index", "1000");
  153. originalHeaderRow.css("height", "64px");
  154. } else {
  155. floatingHeaderRow.css("visibility", "hidden");
  156. floatingHeaderRow.css("top", "0px");
  157. }
  158. });
  159. }
  160. $(function() {
  161. $("table.tableWithFloatingHeader").each(function() {
  162. $(this).wrap("<div class=\"divTableWithFloatingHeader\" style=\"position:relative\"></div>");
  163. var originalHeaderRow = $("tr:first", this)
  164. originalHeaderRow.before(originalHeaderRow.clone());
  165. var clonedHeaderRow = $("tr:first", this)
  166. clonedHeaderRow.addClass("tableFloatingHeader");
  167. clonedHeaderRow.css("position", "absolute");
  168. clonedHeaderRow.css("top", "0px");
  169. clonedHeaderRow.css("left", $(this).css("margin-left"));
  170. clonedHeaderRow.css("visibility", "hidden");
  171. originalHeaderRow.addClass("tableFloatingHeaderOriginal");
  172. });
  173. UpdateTableHeaders();
  174. $(window).scroll(UpdateTableHeaders);
  175. $(window).resize(UpdateTableHeaders);
  176. });
  177. </script>
  178. <form method="post" action="index.php?action=attendance_sheet_add&<?php echo api_get_cidreq().$param_filter; ?>&attendance_id=<?php echo $attendance_id; ?>" >
  179. <div class="attendance-sheet-content" style="width:100%;background-color:#E1E1E1;margin-top:20px;">
  180. <div class="divTableWithFloatingHeader attendance-users-table" style="width:45%;float:left;margin:0px;padding:0px;">
  181. <table class="tableWithFloatingHeader data_table" width="100%">
  182. <thead>
  183. <tr class="tableFloatingHeader" style="position: absolute; top: 0px; left: 0px; visibility: hidden; margin:0px;padding:0px" >
  184. <th width="10px"><?php echo '#'; ?></th>
  185. <th width="10px"><?php echo get_lang('Photo'); ?></th>
  186. <th width="100px"><?php echo get_lang('LastName'); ?></th>
  187. <th width="100px"><?php echo get_lang('FirstName'); ?></th>
  188. <th width="100px"><?php echo get_lang('AttendancesFaults'); ?></th>
  189. </tr>
  190. <tr class="tableFloatingHeaderOriginal" >
  191. <th width="10px"><?php echo '#'; ?></th>
  192. <th width="10px"><?php echo get_lang('Photo'); ?></th>
  193. <th width="150px"><?php echo get_lang('LastName'); ?></th>
  194. <th width="140px"><?php echo get_lang('FirstName'); ?></th>
  195. <th width="100px"><?php echo get_lang('AttendancesFaults'); ?></th>
  196. </tr>
  197. </thead>
  198. <tbody>
  199. <?php
  200. $i = 1;
  201. $class = '';
  202. foreach ($users_in_course as $data) {
  203. $faults = 0;
  204. if ($i % 2 == 0) {
  205. $class = 'row_odd';
  206. } else {
  207. $class = 'row_even';
  208. }
  209. $username = api_htmlentities(
  210. sprintf(get_lang('LoginX'), $data['username']),
  211. ENT_QUOTES
  212. ); ?>
  213. <tr class="<?php echo $class; ?>">
  214. <td><center><?php echo $i; ?></center></td>
  215. <td><?php echo $data['photo']; ?></td>
  216. <td><span title="<?php echo $username; ?>"><?php echo $data['lastname']; ?></span></td>
  217. <td><?php echo $data['firstname']; ?></td>
  218. <td>
  219. <div class="attendance-faults-bar" style="background-color:<?php echo !empty($data['result_color_bar']) ? $data['result_color_bar'] : 'none'; ?>">
  220. <?php echo $data['attendance_result']; ?>
  221. </div>
  222. </td>
  223. </tr>
  224. <?php
  225. $i++;
  226. } ?>
  227. </tbody>
  228. </table>
  229. </div>
  230. <?php
  231. echo '<div class="divTableWithFloatingHeader attendance-calendar-table" style="margin:0px;padding:0px;float:left;width:55%;overflow:auto;overflow-y:hidden;">';
  232. echo '<table class="tableWithFloatingHeader data_table" width="100%">';
  233. echo '<thead>';
  234. $result = null;
  235. if (count($attendant_calendar) > 0) {
  236. foreach ($attendant_calendar as $calendar) {
  237. $date = $calendar['date'];
  238. $time = $calendar['time'];
  239. $datetime = '<div class="grey">'.$date.' - '.$time.'</div>';
  240. $img_lock = Display::return_icon(
  241. 'lock-closed.png',
  242. get_lang('DateUnLock'),
  243. ['class' => 'img_lock', 'id' => 'datetime_column_'.$calendar['id']]
  244. );
  245. if (!empty($calendar['done_attendance'])) {
  246. $datetime = '<div class="blue">'.$date.' - '.$time.'</div>';
  247. }
  248. $disabled_check = 'disabled = "true"';
  249. $input_hidden = '<input type="hidden" id="hidden_input_'.$calendar['id'].'" name="hidden_input[]" value="" disabled />';
  250. if ($next_attendance_calendar_id == $calendar['id']) {
  251. $input_hidden = '<input type="hidden" id="hidden_input_'.$calendar['id'].'" name="hidden_input[]" value="'.$calendar['id'].'" />';
  252. $disabled_check = '';
  253. $img_lock = Display::return_icon('lock-closed.png', get_lang('DateLock'), ['class' => 'img_unlock', 'id' => 'datetime_column_'.$calendar['id']]);
  254. }
  255. $result .= '<th>';
  256. $result .= '<div class="date-attendance">'.$datetime.'&nbsp;';
  257. if (api_is_allowed_to_edit(null, true)) {
  258. $result .= '<span id="attendance_lock" style="cursor:pointer">'.(!$is_locked_attendance || api_is_platform_admin() ? $img_lock : '').'</span>';
  259. }
  260. if ($is_locked_attendance == false) {
  261. if (api_is_allowed_to_edit(null, true)) {
  262. $result .= '<input type="checkbox" class="checkbox_head_'.$calendar['id'].'" id="checkbox_head_'.$calendar['id'].'" '.$disabled_check.' checked="checked" />'.$input_hidden.'</div></th>';
  263. }
  264. }
  265. }
  266. } else {
  267. $result = '<th width="2000px"><span><a href="index.php?'.api_get_cidreq().'&action=calendar_list&attendance_id='.$attendance_id.'">';
  268. $result .= Display::return_icon('attendance_calendar.png', get_lang('AttendanceCalendar'), '', ICON_SIZE_MEDIUM).' '.get_lang('GoToAttendanceCalendar').'</a></span></th>';
  269. }
  270. echo '<tr class="tableFloatingHeader row_odd" style="position: absolute; top: 0px; left: 0px; visibility: hidden; margin:0px;padding:0px">';
  271. echo $result;
  272. echo '</tr>';
  273. echo '<tr class="tableWithFloatingHeader row_odd tableFloatingHeaderOriginal">';
  274. echo $result;
  275. echo '</tr>';
  276. echo '</thead>';
  277. echo '<tbody>';
  278. $i = 0;
  279. foreach ($users_in_course as $user) {
  280. $class = '';
  281. if ($i % 2 == 0) {
  282. $class = 'row_even';
  283. } else {
  284. $class = 'row_odd';
  285. }
  286. echo '<tr class="'.$class.'">';
  287. if (count($attendant_calendar) > 0) {
  288. foreach ($attendant_calendar as $calendar) {
  289. $checked = 'checked';
  290. $presence = -1;
  291. if (isset($users_presence[$user['user_id']][$calendar['id']]['presence'])) {
  292. $presence = $users_presence[$user['user_id']][$calendar['id']]['presence'];
  293. if (intval($presence) == 1) {
  294. $checked = 'checked';
  295. } else {
  296. $checked = '';
  297. }
  298. } else {
  299. //if the user wasn't registered at that time, consider unchecked
  300. if ($next_attendance_calendar_datetime == 0 ||
  301. $calendar['date_time'] < $next_attendance_calendar_datetime
  302. ) {
  303. $checked = '';
  304. }
  305. }
  306. $disabled = 'disabled';
  307. $style_td = '';
  308. if ($next_attendance_calendar_id == $calendar['id']) {
  309. if ($i % 2 == 0) {
  310. $style_td = 'background-color:#eee;';
  311. } else {
  312. $style_td = 'background-color:#dcdcdc;';
  313. }
  314. $disabled = '';
  315. }
  316. echo '<td style="'.$style_td.'" class="checkboxes_col_'.$calendar['id'].'">';
  317. echo '<div class="check">';
  318. if (api_is_allowed_to_edit(null, true)) {
  319. if (!$is_locked_attendance || api_is_platform_admin()) {
  320. echo '<input type="checkbox" name="check_presence['.$calendar['id'].'][]" value="'.$user['user_id'].'" '.$disabled.' '.$checked.' />';
  321. echo '<span class="anchor_'.$calendar['id'].'"></span>';
  322. } else {
  323. echo $presence ? Display::return_icon('checkbox_on.png', get_lang('Presence'), null, ICON_SIZE_TINY) : Display::return_icon('checkbox_off.png', get_lang('Presence'), null, ICON_SIZE_TINY);
  324. }
  325. } else {
  326. switch ($presence) {
  327. case 1:
  328. echo Display::return_icon('accept.png', get_lang('Attended'));
  329. break;
  330. case 0:
  331. echo Display::return_icon('exclamation.png', get_lang('NotAttended'));
  332. break;
  333. case -1:
  334. //echo Display::return_icon('warning.png',get_lang('NotAttended'));
  335. break;
  336. }
  337. }
  338. echo '</div>';
  339. echo '</td>';
  340. }
  341. } else {
  342. $calendarClass = null;
  343. if (isset($calendar)) {
  344. $calendarClass = "checkboxes_col_".$calendar['id'];
  345. }
  346. echo '<td class="'.$calendarClass.'">';
  347. echo '<div>';
  348. echo '<center>&nbsp;</center>
  349. </div>
  350. </td>';
  351. }
  352. echo '</tr>';
  353. $i++;
  354. }
  355. echo '</tbody></table>';
  356. echo '</div></div>'; ?>
  357. <div class="row">
  358. <div class="col-md-12">
  359. <?php if (!$is_locked_attendance || api_is_platform_admin()) {
  360. if (api_is_allowed_to_edit(null, true)) {
  361. ?>
  362. <button type="submit" class="btn btn-primary"><?php echo get_lang('Save'); ?></button>
  363. <?php
  364. }
  365. } ?>
  366. </div>
  367. </div>
  368. </form>
  369. <?php
  370. } else {
  371. echo Display::return_message(
  372. '<a href="'.api_get_path(WEB_CODE_PATH).'user/user.php?'.api_get_cidreq().'">'.
  373. get_lang('ThereAreNoRegisteredLearnersInsidetheCourse').'</a>',
  374. 'warning',
  375. false
  376. );
  377. }
  378. } else {
  379. echo Display::page_header(get_lang('AttendanceSheetReport'));
  380. // View for students?>
  381. <?php if (!empty($users_presence)) {
  382. ?>
  383. <div>
  384. <table width="250px;">
  385. <tr>
  386. <td><?php echo get_lang('ToAttend').': '; ?></td>
  387. <td>
  388. <center><div class="attendance-faults-bar" style="background-color:<?php echo !empty($faults['color_bar']) ? $faults['color_bar'] : 'none'; ?>">
  389. <?php echo $faults['faults'].'/'.$faults['total'].' ('.$faults['faults_porcent'].'%)'; ?></div></center>
  390. </td>
  391. </tr>
  392. </table>
  393. </div>
  394. <?php
  395. } ?>
  396. <table class="data_table">
  397. <tr class="row_odd" >
  398. <th><?php echo get_lang('Attendance'); ?></th>
  399. </tr>
  400. <?php
  401. if (!empty($users_presence)) {
  402. $i = 0;
  403. foreach ($users_presence[$user_id] as $presence) {
  404. $class = '';
  405. if ($i % 2 == 0) {
  406. $class = 'row_even';
  407. } else {
  408. $class = 'row_odd';
  409. } ?>
  410. <tr class="<?php echo $class; ?>">
  411. <td>
  412. <?php echo $presence['presence'] ? Display::return_icon('checkbox_on.png', get_lang('Presence'), null, ICON_SIZE_TINY) : Display::return_icon('checkbox_off.png', get_lang('Presence'), null, ICON_SIZE_TINY); ?>
  413. <?php echo "&nbsp; ".$presence['date_time']; ?>
  414. </td>
  415. </tr>
  416. <?php
  417. }
  418. } else {
  419. ?>
  420. <tr><td>
  421. <center><?php echo get_lang('YouDoNotHaveDoneAttendances'); ?></center></td>
  422. </tr>
  423. <?php
  424. } ?>
  425. </table>
  426. <?php
  427. } ?>