attendance_sheet.php 17 KB

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