attendance_sheet.php 21 KB

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