attendance_sheet.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * View (MVC patter) for attendance sheet (list, edit, add)
  5. * @author Christian Fasanando <christian1827@gmail.com>
  6. * @author Julio Montoya reworked 2010
  7. * @package chamilo.attendance
  8. */
  9. // Protect a course script
  10. api_protect_course_script(true);
  11. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  12. api_get_user_id(),
  13. api_get_course_info()
  14. );
  15. if (api_is_allowed_to_edit(null, true) ||
  16. api_is_coach(api_get_session_id(), api_get_course_int_id()) ||
  17. $isDrhOfCourse
  18. ) {
  19. $groupId = isset($_REQUEST['group_id']) ? intval($_REQUEST['group_id']) : null;
  20. $form = new FormValidator(
  21. 'filter',
  22. 'post',
  23. 'index.php?action=attendance_sheet_list&'.api_get_cidreq().'&attendance_id='.$attendance_id,
  24. null,
  25. array(),
  26. 'inline'
  27. );
  28. $values = array(
  29. 'all' => get_lang('All'),
  30. 'today' => get_lang('Today'),
  31. 'all_done' => get_lang('AllDone'),
  32. 'all_not_done' => get_lang('AllNotDone')
  33. );
  34. $today = api_convert_and_format_date(null, DATE_FORMAT_SHORT);
  35. $exists_attendance_today = false;
  36. if (!empty($attendant_calendar_all)) {
  37. $values[''] = '---------------';
  38. foreach ($attendant_calendar_all as $attendance_date) {
  39. $includeCalendar = true;
  40. if (isset($attendance_date['groups']) && !empty($groupId)) {
  41. foreach ($attendance_date['groups'] as $group) {
  42. if ($groupId == $group['group_id']) {
  43. $includeCalendar = true;
  44. break;
  45. } else {
  46. $includeCalendar = false;
  47. }
  48. }
  49. }
  50. if ($today == $attendance_date['date']) {
  51. $exists_attendance_today = true;
  52. }
  53. if ($includeCalendar) {
  54. $values[$attendance_date['id']] = $attendance_date['date_time'];
  55. }
  56. }
  57. }
  58. if (!$exists_attendance_today) {
  59. echo Display::return_message(
  60. get_lang('ThereIsNoClassScheduledTodayTryPickingAnotherDay'),
  61. 'warning'
  62. );
  63. }
  64. $form->addSelect(
  65. 'filter',
  66. get_lang('Filter'),
  67. $values,
  68. ['id' => 'filter_id', 'onchange' => 'submit();']
  69. );
  70. $groupList = GroupManager::get_group_list(null, null, 1);
  71. $groupIdList = array('--');
  72. foreach ($groupList as $group) {
  73. $groupIdList[$group['id']] = $group['name'];
  74. }
  75. if (!empty($groupList)) {
  76. $form->addSelect('group_id', get_lang('Group'), $groupIdList);
  77. }
  78. if (isset($_REQUEST['filter'])) {
  79. if (in_array($_REQUEST['filter'], array_keys($values))) {
  80. $default_filter = $_REQUEST['filter'];
  81. }
  82. } else {
  83. $default_filter = 'today';
  84. }
  85. $renderer = $form->defaultRenderer();
  86. $renderer->setCustomElementTemplate('<div class="col-md-2">{label}</div><div class="col-md-10"> {element} </div>');
  87. $form->setDefaults(
  88. array(
  89. 'filter' => $default_filter,
  90. 'group_id' => $groupId
  91. )
  92. );
  93. if (!$is_locked_attendance || api_is_platform_admin()) {
  94. $actionsLeft = '<a style="float:left;" href="index.php?'.api_get_cidreq().'&action=calendar_list&attendance_id='.$attendance_id.'">'.
  95. Display::return_icon('attendance_calendar.png', get_lang('AttendanceCalendar'), '', ICON_SIZE_MEDIUM).'</a>';
  96. $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.'">'.
  97. Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>';
  98. $actionsRight = $form->returnForm();
  99. $toolbar = Display::toolbarAction('toolbar-attendance', array($actionsLeft, $actionsRight));
  100. echo $toolbar;
  101. }
  102. $message_information = get_lang('AttendanceSheetDescription');
  103. if (!empty($message_information)) {
  104. $message = '<strong>'.get_lang('Information').'</strong><br />';
  105. $message .= $message_information;
  106. echo Display::return_message($message, 'normal', false);
  107. }
  108. if ($is_locked_attendance) {
  109. echo Display::return_message(get_lang('TheAttendanceSheetIsLocked'), 'warning', false);
  110. }
  111. $param_filter = '&filter='.Security::remove_XSS($default_filter).'&group_id='.$groupId;
  112. if (count($users_in_course) > 0) {
  113. ?>
  114. <script>
  115. var original_url = '';
  116. $("#filter_id").on('change', function() {
  117. filter = $(this).val();
  118. if (original_url == '') {
  119. original_url = $("#pdf_export").attr('href');
  120. }
  121. new_url = original_url + "&filter=" +filter
  122. $("#pdf_export").attr('href', new_url);
  123. });
  124. function UpdateTableHeaders() {
  125. $("div.divTableWithFloatingHeader").each(function() {
  126. var originalHeaderRow = $(".tableFloatingHeaderOriginal", this);
  127. var floatingHeaderRow = $(".tableFloatingHeader", this);
  128. var offset = $(this).offset();
  129. var scrollTop = $(window).scrollTop();
  130. if ((scrollTop > offset.top) && (scrollTop < offset.top + $(this).height())) {
  131. floatingHeaderRow.css("visibility", "hidden");
  132. var topbar = 0;
  133. if ($("#topbar").length != 0) {
  134. topbar = $("#topbar").height();
  135. } else {
  136. if ($(".subnav").length != 0) {
  137. topbar = $(".subnav").height();
  138. }
  139. }
  140. var top_value = Math.min(scrollTop - offset.top, $(this).height() - floatingHeaderRow.height()) + topbar;
  141. floatingHeaderRow.css("top", top_value + "px");
  142. // Copy cell widths from original header
  143. $("th", floatingHeaderRow).each(function(index) {
  144. var cellWidth = $("th", originalHeaderRow).eq(index).css('width');
  145. $(this).css('width', cellWidth);
  146. });
  147. // Copy row width from whole table
  148. floatingHeaderRow.css("width", $(this).css("width"));
  149. floatingHeaderRow.css("visibility", "visible");
  150. floatingHeaderRow.css("z-index", "1000");
  151. originalHeaderRow.css("height", "64px");
  152. } else {
  153. floatingHeaderRow.css("visibility", "hidden");
  154. floatingHeaderRow.css("top", "0px");
  155. }
  156. });
  157. }
  158. $(document).ready(function() {
  159. $("table.tableWithFloatingHeader").each(function() {
  160. $(this).wrap("<div class=\"divTableWithFloatingHeader\" style=\"position:relative\"></div>");
  161. var originalHeaderRow = $("tr:first", this)
  162. originalHeaderRow.before(originalHeaderRow.clone());
  163. var clonedHeaderRow = $("tr:first", this)
  164. clonedHeaderRow.addClass("tableFloatingHeader");
  165. clonedHeaderRow.css("position", "absolute");
  166. clonedHeaderRow.css("top", "0px");
  167. clonedHeaderRow.css("left", $(this).css("margin-left"));
  168. clonedHeaderRow.css("visibility", "hidden");
  169. originalHeaderRow.addClass("tableFloatingHeaderOriginal");
  170. });
  171. UpdateTableHeaders();
  172. $(window).scroll(UpdateTableHeaders);
  173. $(window).resize(UpdateTableHeaders);
  174. });
  175. </script>
  176. <form method="post" action="index.php?action=attendance_sheet_add&<?php echo api_get_cidreq().$param_filter ?>&attendance_id=<?php echo $attendance_id?>" >
  177. <div class="attendance-sheet-content" style="width:100%;background-color:#E1E1E1;margin-top:20px;">
  178. <div class="divTableWithFloatingHeader attendance-users-table" style="width:45%;float:left;margin:0px;padding:0px;">
  179. <table class="tableWithFloatingHeader data_table" width="100%">
  180. <thead>
  181. <tr class="tableFloatingHeader" style="position: absolute; top: 0px; left: 0px; visibility: hidden; margin:0px;padding:0px" >
  182. <th width="10px"><?php echo '#'; ?></th>
  183. <th width="10px"><?php echo get_lang('Photo')?></th>
  184. <th width="100px"><?php echo get_lang('LastName')?></th>
  185. <th width="100px"><?php echo get_lang('FirstName')?></th>
  186. <th width="100px"><?php echo get_lang('AttendancesFaults')?></th>
  187. </tr>
  188. <tr class="tableFloatingHeaderOriginal" >
  189. <th width="10px"><?php echo '#'; ?></th>
  190. <th width="10px"><?php echo get_lang('Photo')?></th>
  191. <th width="150px"><?php echo get_lang('LastName')?></th>
  192. <th width="140px"><?php echo get_lang('FirstName')?></th>
  193. <th width="100px"><?php echo get_lang('AttendancesFaults')?></th>
  194. </tr>
  195. </thead>
  196. <tbody>
  197. <?php
  198. $i = 1;
  199. $class = '';
  200. foreach ($users_in_course as $data) {
  201. $faults = 0;
  202. if ($i % 2 == 0) {
  203. $class = 'row_odd';
  204. } else {
  205. $class = 'row_even';
  206. }
  207. $username = api_htmlentities(
  208. sprintf(get_lang('LoginX'), $data['username']),
  209. ENT_QUOTES
  210. );
  211. ?>
  212. <tr class="<?php echo $class ?>">
  213. <td><center><?php echo $i ?></center></td>
  214. <td><?php echo $data['photo'] ?></td>
  215. <td><span title="<?php echo $username ?>"><?php echo $data['lastname'] ?></span></td>
  216. <td><?php echo $data['firstname'] ?></td>
  217. <td>
  218. <div class="attendance-faults-bar" style="background-color:<?php echo (!empty($data['result_color_bar']) ? $data['result_color_bar'] : 'none') ?>">
  219. <?php echo $data['attendance_result'] ?>
  220. </div>
  221. </td>
  222. </tr>
  223. <?php
  224. $i++;
  225. }
  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. array('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'), array('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. ?>
  358. <div class="row">
  359. <div class="col-md-12">
  360. <?php if (!$is_locked_attendance || api_is_platform_admin()) {
  361. if (api_is_allowed_to_edit(null, true)) { ?>
  362. <button type="submit" class="btn btn-primary"><?php echo get_lang('Save') ?></button>
  363. <?php }
  364. } ?>
  365. </div>
  366. </div>
  367. </form>
  368. <?php
  369. } else {
  370. echo Display::return_message(
  371. '<a href="'.api_get_path(WEB_CODE_PATH).'user/user.php?'.api_get_cidreq().'">'.
  372. get_lang('ThereAreNoRegisteredLearnersInsidetheCourse').'</a>',
  373. 'warning',
  374. false
  375. );
  376. }
  377. } else {
  378. echo Display::page_header(get_lang('AttendanceSheetReport'));
  379. // View for students
  380. ?>
  381. <?php if (!empty($users_presence)) { ?>
  382. <div>
  383. <table width="250px;">
  384. <tr>
  385. <td><?php echo get_lang('ToAttend').': ' ?></td>
  386. <td>
  387. <center><div class="attendance-faults-bar" style="background-color:<?php echo (!empty($faults['color_bar']) ? $faults['color_bar'] : 'none') ?>">
  388. <?php echo $faults['faults'].'/'.$faults['total'].' ('.$faults['faults_porcent'].'%)' ?></div></center>
  389. </td>
  390. </tr>
  391. </table>
  392. </div>
  393. <?php } ?>
  394. <table class="data_table">
  395. <tr class="row_odd" >
  396. <th><?php echo get_lang('Attendance')?></th>
  397. </tr>
  398. <?php
  399. if (!empty($users_presence)) {
  400. $i = 0;
  401. foreach ($users_presence[$user_id] as $presence) {
  402. $class = '';
  403. if ($i % 2 == 0) {
  404. $class = 'row_even';
  405. } else {
  406. $class = 'row_odd';
  407. }
  408. ?>
  409. <tr class="<?php echo $class ?>">
  410. <td>
  411. <?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) ?>
  412. <?php echo "&nbsp; ".$presence['date_time'] ?>
  413. </td>
  414. </tr>
  415. <?php }
  416. } else { ?>
  417. <tr><td>
  418. <center><?php echo get_lang('YouDoNotHaveDoneAttendances')?></center></td>
  419. </tr>
  420. <?php }
  421. ?>
  422. </table>
  423. <?php } ?>