attendance_sheet.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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) || api_is_coach(api_get_session_id(), api_get_course_id())) {
  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_list&'.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.'&filter='.$default_filter.'">'.
  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) {
  162. $class='row_odd';
  163. } else {
  164. $class='row_even';
  165. }
  166. $username = api_htmlentities(sprintf(get_lang('LoginX'), $data['username']), ENT_QUOTES);
  167. ?>
  168. <tr class="<?php echo $class ?>">
  169. <td><center><?php echo $i ?></center></td>
  170. <td><?php echo $data['photo'] ?></td>
  171. <td><span title="<?php echo $username ?>"><?php echo $data['lastname'] ?></span></td>
  172. <td><?php echo $data['firstname'] ?></td>
  173. <td>
  174. <div class="attendance-faults-bar" style="background-color:<?php echo (!empty($data['result_color_bar'])?$data['result_color_bar']:'none') ?>">
  175. <?php echo $data['attendance_result'] ?>
  176. </div>
  177. </td>
  178. </tr>
  179. <?php
  180. $i++;
  181. }
  182. ?>
  183. </tbody>
  184. </table>
  185. </div>
  186. <?php
  187. echo '<div class="divTableWithFloatingHeader attendance-calendar-table" style="margin:0px;padding:0px;float:left;width:55%;overflow:auto;overflow-y:hidden;">';
  188. echo '<table class="tableWithFloatingHeader data_table" width="100%">';
  189. echo '<thead>';
  190. if (count($attendant_calendar) > 0 ) {
  191. foreach ($attendant_calendar as $calendar) {
  192. $date = $calendar['date'];
  193. $time = $calendar['time'];
  194. $datetime = $date.'<br />'.$time;
  195. $img_lock = Display::return_icon('lock.gif',get_lang('DateUnLock'),array('class'=>'img_lock','id'=>'datetime_column_'.$calendar['id']));
  196. if (!empty($calendar['done_attendance'])){
  197. $datetime = '<font color="blue">'.$date.'<br />'.$time.'</font>';
  198. }
  199. $disabled_check = 'disabled = "true"';
  200. $input_hidden = '<input type="hidden" id="hidden_input_'.$calendar['id'].'" name="hidden_input[]" value="" disabled />';
  201. if ($next_attendance_calendar_id == $calendar['id']) {
  202. $input_hidden = '<input type="hidden" id="hidden_input_'.$calendar['id'].'" name="hidden_input[]" value="'.$calendar['id'].'" />';
  203. $disabled_check = '';
  204. $img_lock = Display::return_icon('unlock.gif',get_lang('DateLock'),array('class'=>'img_unlock','id'=>'datetime_column_'.$calendar['id']));
  205. }
  206. $result .= '<th width="800px">';
  207. $result .= '<center><div style="font-size:10px;width:125px;">'.$datetime.'&nbsp;';
  208. if (api_is_allowed_to_edit(null, true)) {
  209. $result .= '<span id="attendance_lock" style="cursor:pointer">'.(!$is_locked_attendance || api_is_platform_admin()?$img_lock:'').'</span>';
  210. }
  211. if ($is_locked_attendance == false) {
  212. if (api_is_allowed_to_edit(null, true)) {
  213. $result .= '<br /><input type="checkbox" class="checkbox_head_'.$calendar['id'].'" id="checkbox_head_'.$calendar['id'].'" '.$disabled_check.' checked="checked" />'.$input_hidden.'</div></center></th>';
  214. }
  215. }
  216. }
  217. } else {
  218. $result = '<th width="2000px"><span><a href="index.php?'.api_get_cidreq().'&action=calendar_list&attendance_id='.$attendance_id.$param_gradebook.'">';
  219. $result .= Display::return_icon('attendance_calendar.png',get_lang('AttendanceCalendar'),'',ICON_SIZE_MEDIUM).' '.get_lang('GoToAttendanceCalendar').'</a></span></th>';
  220. }
  221. echo '<tr class="tableFloatingHeader row_odd" style="position: absolute; top: 0px; left: 0px; visibility: hidden; margin:0px;padding:0px">';
  222. echo $result;
  223. echo '</tr>';
  224. echo '<tr class="tableWithFloatingHeader row_odd">';
  225. echo $result;
  226. echo '</tr>';
  227. echo '</thead>';
  228. echo '<tbody>';
  229. $i = 0;
  230. foreach ($users_in_course as $user) {
  231. $class = '';
  232. if ($i%2 == 0) {
  233. $class = 'row_even';
  234. } else {
  235. $class = 'row_odd';
  236. }
  237. echo '<tr class="'.$class.'">';
  238. if (count($attendant_calendar) > 0 ) {
  239. foreach ($attendant_calendar as $calendar) {
  240. $checked = 'checked';
  241. $presence = -1;
  242. if (isset($users_presence[$user['user_id']][$calendar['id']]['presence'])) {
  243. $presence = $users_presence[$user['user_id']][$calendar['id']]['presence'];
  244. if (intval($presence) == 1) {
  245. $checked = 'checked';
  246. } else {
  247. $checked = '';
  248. }
  249. } else {
  250. //if the user wasn't registered at that time, consider unchecked
  251. if ($next_attendance_calendar_datetime == 0 || $calendar['date_time'] < $next_attendance_calendar_datetime) {
  252. $checked = '';
  253. }
  254. }
  255. $disabled = 'disabled';
  256. $style_td = '';
  257. if ($next_attendance_calendar_id == $calendar['id']) {
  258. if ($i%2==0)
  259. $style_td = 'background-color:#eee;';
  260. else
  261. $style_td = 'background-color:#dcdcdc;';
  262. $disabled = '';
  263. }
  264. echo '<td style="'.$style_td.'" class="checkboxes_col_'.$calendar['id'].'">';
  265. echo '<div style="height:20px">';
  266. echo '<center>';
  267. if (api_is_allowed_to_edit(null, true)) {
  268. if (!$is_locked_attendance || api_is_platform_admin()) {
  269. echo '<input type="checkbox" name="check_presence['.$calendar['id'].'][]" value="'.$user['user_id'].'" '.$disabled.' '.$checked.' />';
  270. echo '<span class="anchor_'.$calendar['id'].'"></span>';
  271. } else {
  272. echo $presence ? Display::return_icon('checkbox_on.gif',get_lang('Presence')) : Display::return_icon('checkbox_off.gif',get_lang('Presence'));
  273. }
  274. } else {
  275. switch($presence) {
  276. case 1:
  277. echo Display::return_icon('accept.png',get_lang('Attended'));
  278. break;
  279. case 0:
  280. echo Display::return_icon('exclamation.png',get_lang('NotAttended'));
  281. break;
  282. case -1:
  283. //echo Display::return_icon('warning.png',get_lang('NotAttended'));
  284. break;
  285. }
  286. }
  287. echo '</center>';
  288. echo '</div>';
  289. echo '</td>';
  290. }
  291. } else {
  292. echo '<td class="checkboxes_col_'.$calendar['id'].'">';
  293. echo '<div style="height:20px">';
  294. echo '<center>&nbsp;</center>
  295. </div>
  296. </td>';
  297. }
  298. echo '</tr>';
  299. $i++ ;
  300. }
  301. echo '</tbody></table>';
  302. echo '</div></div>';
  303. ?>
  304. <div class="clear"></div>
  305. <div style="margin-top:20px;">
  306. <?php if (!$is_locked_attendance || api_is_platform_admin()) {
  307. if (api_is_allowed_to_edit(null, true)) {
  308. ?>
  309. <button type="submit" class="save"><?php echo get_lang('Save') ?></button>
  310. <?php }
  311. }
  312. ?>
  313. </div>
  314. </form>
  315. <?php
  316. } else {
  317. echo Display::display_warning_message('<a href="'.api_get_path(WEB_CODE_PATH).'user/user.php?'.api_get_cidreq().'">'.get_lang('ThereAreNoRegisteredLearnersInsidetheCourse').'</a>', false);
  318. }
  319. } else {
  320. echo Display::page_header(get_lang('AttendanceSheetReport'));
  321. // View for students
  322. ?>
  323. <?php if(!empty($users_presence)) { ?>
  324. <div>
  325. <table width="250px;">
  326. <tr>
  327. <td><?php echo get_lang('ToAttend').': ' ?></td>
  328. <td><center><div class="attendance-faults-bar" style="background-color:<?php echo (!empty($faults['color_bar'])?$faults['color_bar']:'none') ?>">
  329. <?php echo $faults['faults'].'/'.$faults['total'].' ('.$faults['faults_porcent'].'%)' ?></div></center>
  330. </td>
  331. </tr>
  332. </table>
  333. </div>
  334. <?php } ?>
  335. <table class="data_table">
  336. <tr class="row_odd" >
  337. <th><?php echo get_lang('Attendance')?></th>
  338. </tr>
  339. <?php
  340. if (!empty($users_presence)) {
  341. $i = 0;
  342. foreach ($users_presence[$user_id] as $presence) {
  343. $class = '';
  344. if ($i%2==0) {
  345. $class = 'row_even';
  346. } else {
  347. $class = 'row_odd';
  348. }
  349. ?>
  350. <tr class="<?php echo $class ?>">
  351. <td>
  352. <?php echo $presence['presence']?Display::return_icon('checkbox_on.gif',get_lang('Presence')):Display::return_icon('checkbox_off.gif',get_lang('Presence')) ?>
  353. <?php echo "&nbsp; ".$presence['date_time'] ?>
  354. </td>
  355. </tr>
  356. <?php }
  357. } else { ?>
  358. <tr><td>
  359. <center><?php echo get_lang('YouDoNotHaveDoneAttendances')?></center></td>
  360. </tr>
  361. <?php }
  362. ?>
  363. </table>
  364. <?php } ?>