attendance_sheet.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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 = 'all';
  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. floatingHeaderRow.css("z-index", "1000");
  83. originalHeaderRow.css("height", "80px");
  84. } else {
  85. floatingHeaderRow.css("visibility", "hidden");
  86. floatingHeaderRow.css("top", "0px");
  87. }
  88. });
  89. }
  90. $(document).ready(function() {
  91. $("table.tableWithFloatingHeader").each(function() {
  92. $(this).wrap("<div class=\"divTableWithFloatingHeader\" style=\"position:relative\"></div>");
  93. var originalHeaderRow = $("tr:first", this)
  94. originalHeaderRow.before(originalHeaderRow.clone());
  95. var clonedHeaderRow = $("tr:first", this)
  96. clonedHeaderRow.addClass("tableFloatingHeader");
  97. clonedHeaderRow.css("position", "absolute");
  98. clonedHeaderRow.css("top", "0px");
  99. clonedHeaderRow.css("left", $(this).css("margin-left"));
  100. clonedHeaderRow.css("visibility", "hidden");
  101. originalHeaderRow.addClass("tableFloatingHeaderOriginal");
  102. });
  103. UpdateTableHeaders();
  104. $(window).scroll(UpdateTableHeaders);
  105. $(window).resize(UpdateTableHeaders);
  106. });
  107. </script>
  108. <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?>" >
  109. <div class="attendance-sheet-content" style="width:100%;background-color:#E1E1E1;margin-top:20px;">
  110. <div class="divTableWithFloatingHeader attendance-users-table" style="width:55%;float:left;margin:0px;padding:0px;">
  111. <table class="tableWithFloatingHeader data_table" width="100%">
  112. <thead>
  113. <tr class="tableFloatingHeader" style="position: absolute; top: 0px; left: 0px; visibility: hidden; margin:0px;padding:0px" >
  114. <th width="10px"><?php echo '#'; ?></th>
  115. <th width="10px"><?php echo get_lang('Photo')?></th>
  116. <th width="100px"><?php echo get_lang('LastName')?></th>
  117. <th width="100px"><?php echo get_lang('FirstName')?></th>
  118. <th width="100px"><?php echo get_lang('LoginName')?></th>
  119. <th width="100px"><?php echo get_lang('AttendancesFaults')?></th>
  120. </tr>
  121. <tr class="tableFloatingHeaderOriginal" >
  122. <th height="65px" width="10px"><?php echo '#';?></th>
  123. <th width="10px"><?php echo get_lang('Photo')?></th>
  124. <th width="150px"><?php echo get_lang('LastName')?></th>
  125. <th width="140px"><?php echo get_lang('FirstName')?></th>
  126. <th width="100px"><?php echo get_lang('LoginName')?></th>
  127. <th width="100px"><?php echo get_lang('AttendancesFaults')?></th>
  128. </tr>
  129. </thead>
  130. <tbody>
  131. <?php
  132. $i = 1;
  133. $class = '';
  134. foreach ($users_in_course as $data) {
  135. $faults = 0;
  136. if ($i%2 == 0) {$class='row_odd';}
  137. else {$class='row_even';}
  138. ?>
  139. <tr class="<?php echo $class ?>">
  140. <td><center><?php echo $i ?></center></td>
  141. <td><?php echo $data['photo'] ?></td>
  142. <td><?php echo $data['lastname'] ?></td>
  143. <td><?php echo $data['firstname'] ?></td>
  144. <td><?php echo $data['username'] ?></td>
  145. <td>
  146. <div style="height:28px">
  147. <center>
  148. <div class="attendance-faults-bar" style="background-color:<?php echo (!empty($data['result_color_bar'])?$data['result_color_bar']:'none') ?>">
  149. <?php echo $data['attendance_result'] ?></div>
  150. </center>
  151. </div>
  152. </td>
  153. </tr>
  154. <?php
  155. $i++;
  156. }
  157. ?>
  158. </tbody>
  159. </table>
  160. </div>
  161. <div class="divTableWithFloatingHeader attendance-calendar-table" style="margin:0px;padding:0px;float:left;width:45%;overflow:auto;overflow-y:hidden;">
  162. <table class="tableWithFloatingHeader data_table" width="100%">
  163. <thead>
  164. <?php
  165. if (count($attendant_calendar) > 0 ) {
  166. foreach ($attendant_calendar as $calendar) {
  167. $date = $calendar['date'];
  168. $time = $calendar['time'];
  169. $datetime = $date.'<br />'.$time;
  170. $img_lock = Display::return_icon('lock.gif',get_lang('DateUnLock'),array('class'=>'img_lock','id'=>'datetime_column_'.$calendar['id']));
  171. if (!empty($calendar['done_attendance'])){
  172. $datetime = '<font color="blue">'.$date.'<br />'.$time.'</font>';
  173. }
  174. $disabled_check = 'disabled = "true"';
  175. $input_hidden = '<input type="hidden" id="hidden_input_'.$calendar['id'].'" name="hidden_input[]" value="" disabled />';
  176. if ($next_attendance_calendar_id == $calendar['id']) {
  177. $input_hidden = '<input type="hidden" id="hidden_input_'.$calendar['id'].'" name="hidden_input[]" value="'.$calendar['id'].'" />';
  178. $disabled_check = '';
  179. $img_lock = Display::return_icon('unlock.gif',get_lang('DateLock'),array('class'=>'img_unlock','id'=>'datetime_column_'.$calendar['id']));
  180. }
  181. $result .= '<th height="80px" width="800px">';
  182. $result .= '<center><div style="font-size:10px;width:80px;">'.$datetime.'&nbsp;';
  183. $result .= '<span id="attendance_lock" style="cursor:pointer">'.(!$is_locked_attendance || api_is_platform_admin()?$img_lock:'').'</span>';
  184. $result .= '<br /><input type="checkbox" class="checkbox_head_'.$calendar['id'].'" id="checkbox_head_'.$calendar['id'].'" '.$disabled_check.' checked="checked" />'.$input_hidden.'</div></center></th>';
  185. }
  186. } else {
  187. $result = '<th width="2000px"><span><a href="index.php?'.api_get_cidreq().'&action=calendar_list&attendance_id='.$attendance_id.$param_gradebook.'">';
  188. $result .= Display::return_icon('attendance_calendar.png',get_lang('AttendanceCalendar'),'','32').' '.get_lang('GoToAttendanceCalendar').'</a></span></th>';
  189. }
  190. ?>
  191. <tr class="tableFloatingHeader row_odd" style="position: absolute; top: 0px; left: 0px; visibility: hidden; margin:0px;padding:0px" >
  192. <?php echo $result; ?>
  193. </tr>
  194. <tr class="tableWithFloatingHeader row_odd">
  195. <?php echo $result; ?>
  196. </tr>
  197. </thead>
  198. <tbody>
  199. <?php
  200. $i = 0;
  201. foreach ($users_in_course as $user) {
  202. $class = '';
  203. if ($i%2==0) {$class = 'row_even';}
  204. else {$class = 'row_odd';}
  205. ?>
  206. <tr class="<?php echo $class ?>">
  207. <?php
  208. if (count($attendant_calendar) > 0 ) {
  209. foreach ($attendant_calendar as $calendar) {
  210. $checked = 'checked';
  211. if (isset($users_presence[$user['user_id']][$calendar['id']]['presence'])) {
  212. $presence = $users_presence[$user['user_id']][$calendar['id']]['presence'];
  213. if (intval($presence) == 1) {
  214. $checked = 'checked';
  215. } else {
  216. $checked = '';
  217. }
  218. } else {
  219. //if the user wasn't registered at that time, consider unchecked
  220. if ($next_attendance_calendar_datetime == 0 || $calendar['date_time'] < $next_attendance_calendar_datetime) {
  221. $checked = '';
  222. }
  223. }
  224. $disabled = 'disabled';
  225. $style_td = '';
  226. if ($next_attendance_calendar_id == $calendar['id']) {
  227. if ($i%2==0)
  228. $style_td = 'background-color:#eee;';
  229. else
  230. $style_td = 'background-color:#dcdcdc;';
  231. $disabled = '';
  232. }
  233. ?>
  234. <td style="<?php echo $style_td ?>" class="checkboxes_col_<?php echo $calendar['id'] ?>">
  235. <div style="height:20px">
  236. <center>
  237. <?php if (!$is_locked_attendance || api_is_platform_admin()) { ?>
  238. <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>
  239. <?php } else {
  240. echo $presence?Display::return_icon('checkbox_on.gif',get_lang('Presence')):Display::return_icon('checkbox_off.gif',get_lang('Presence'));
  241. } ?>
  242. </center>
  243. </div>
  244. </td>
  245. <?php }
  246. } else { ?>
  247. <td class="checkboxes_col_<?php echo $calendar['id'] ?>">
  248. <div style="height:20px">
  249. <center>&nbsp;</center>
  250. </div>
  251. </td>
  252. <?php } ?>
  253. </tr>
  254. <?php $i++ ;
  255. }
  256. ?>
  257. </tbody>
  258. </table>
  259. </div>
  260. </div>
  261. <div class="clear"></div>
  262. <div style="margin-top:20px;">
  263. <?php if (!$is_locked_attendance || api_is_platform_admin()) { ?>
  264. <button type="submit" class="save"><?php echo get_lang('Save') ?></button><?php } ?>
  265. </div>
  266. </form>
  267. <?php
  268. } else {
  269. echo Display::display_warning_message('<a href="'.api_get_path(WEB_CODE_PATH).'user/user.php?'.api_get_cidreq().'">'.get_lang('ThereAreNoRegisteredLearnersInsidetheCourse').'</a>', false);
  270. }
  271. } else {
  272. // View for students
  273. ?>
  274. <h3><?php echo get_lang('AttendanceSheetReport') ?></h3>
  275. <?php if(!empty($users_presence)) { ?>
  276. <div>
  277. <table width="250px;">
  278. <tr>
  279. <td><?php echo get_lang('ToAttend').': ' ?></td>
  280. <td><center><div class="attendance-faults-bar" style="background-color:<?php echo (!empty($faults['color_bar'])?$faults['color_bar']:'none') ?>">
  281. <?php echo $faults['faults'].'/'.$faults['total'].' ('.$faults['faults_porcent'].'%)' ?></div></center>
  282. </td>
  283. </tr>
  284. </table>
  285. </div>
  286. <?php } ?>
  287. <table class="data_table">
  288. <tr class="row_odd" >
  289. <th><?php echo get_lang('Attendance')?></th>
  290. </tr>
  291. <?php
  292. if (!empty($users_presence)) {
  293. $i = 0;
  294. foreach($users_presence[$user_id] as $presence) {
  295. $class = '';
  296. if ($i%2==0) {$class = 'row_even';}
  297. else {$class = 'row_odd';}
  298. ?>
  299. <tr class="<?php echo $class ?>">
  300. <td>
  301. <?php echo $presence['presence']?Display::return_icon('checkbox_on.gif',get_lang('Presence')):Display::return_icon('checkbox_off.gif',get_lang('Presence')) ?>
  302. <?php echo "&nbsp; ".$presence['date_time'] ?>
  303. </td>
  304. </tr>
  305. <?php }
  306. } else { ?>
  307. <tr><td>
  308. <center><?php echo get_lang('YouDoNotHaveDoneAttendances')?></center></td>
  309. </tr>
  310. <?php }
  311. ?>
  312. </table>
  313. <?php } ?>