attendance_sheet.php 19 KB

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