attendance_sheet.php 21 KB

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