attendance_sheet.php 21 KB

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