attendance_sheet.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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_int_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. foreach ($attendance_states as $id => $state) {
  72. echo $attendance_obj->get_attendance_state_button($id, true).'&nbsp;';
  73. }
  74. ?>
  75. <script>
  76. var original_url = '';
  77. $("#filter_id").on('change', function() {
  78. filter = $(this).val();
  79. if (original_url == '') {
  80. original_url = $("#pdf_export").attr('href');
  81. }
  82. new_url = original_url + "&filter=" +filter
  83. $("#pdf_export").attr('href', new_url);
  84. });
  85. function UpdateTableHeaders() {
  86. $("div.divTableWithFloatingHeader").each(function() {
  87. var originalHeaderRow = $(".tableFloatingHeaderOriginal", this);
  88. var floatingHeaderRow = $(".tableFloatingHeader", this);
  89. var offset = $(this).offset();
  90. var scrollTop = $(window).scrollTop();
  91. if ((scrollTop > offset.top) && (scrollTop < offset.top + $(this).height())) {
  92. floatingHeaderRow.css("visibility", "hidden");
  93. var topbar = 0;
  94. if ($("#topbar").length != 0) {
  95. topbar = $("#topbar").height();
  96. } else {
  97. if ($(".subnav").length != 0) {
  98. topbar = $(".subnav").height();
  99. }
  100. }
  101. var top_value = Math.min(scrollTop - offset.top, $(this).height() - floatingHeaderRow.height()) + topbar;
  102. floatingHeaderRow.css("top", top_value + "px");
  103. // Copy cell widths from original header
  104. $("th", floatingHeaderRow).each(function(index) {
  105. var cellWidth = $("th", originalHeaderRow).eq(index).css('width');
  106. $(this).css('width', cellWidth);
  107. });
  108. // Copy row width from whole table
  109. floatingHeaderRow.css("width", $(this).css("width"));
  110. floatingHeaderRow.css("visibility", "visible");
  111. floatingHeaderRow.css("z-index", "1000");
  112. originalHeaderRow.css("height", "40px");
  113. } else {
  114. floatingHeaderRow.css("visibility", "hidden");
  115. floatingHeaderRow.css("top", "0px");
  116. }
  117. });
  118. }
  119. function save_checkboxes() {
  120. $('#form_attendance_sheet').submit();
  121. }
  122. $(document).ready(function() {
  123. $('.switch').click(function() {
  124. var state = 0;
  125. var my_class = 'btn';
  126. var current_class = '';
  127. var my_button = $(this);
  128. if (my_button.is('.disabled')) {
  129. return false;
  130. }
  131. if (my_button.is('.btn')) {
  132. current_class = 'btn';
  133. state = 1;
  134. my_class = 'btn-success';
  135. }
  136. if (my_button.is('.btn-success')) {
  137. current_class = 'btn-success';
  138. state = 0;
  139. my_class = 'btn-danger';
  140. }
  141. if (my_button.is('.btn-danger')) {
  142. current_class = 'btn-danger';
  143. state = 2;
  144. my_class = 'btn-info';
  145. }
  146. if (my_button.is('.btn-info')) {
  147. current_class = 'btn-info';
  148. state = 3;
  149. my_class = 'btn-warning';
  150. }
  151. if (my_button.is('.btn-warning')) {
  152. current_class = 'btn-warning';
  153. state = 4;
  154. my_class = 'btn';
  155. }
  156. var id = my_button.attr('id');
  157. $('#hidden_'+id).attr('value', 'state_'+state+'_'+id);
  158. my_button.attr('data-state', state);
  159. my_button.removeClass(current_class);
  160. my_button.addClass('btn b1');
  161. my_button.addClass(my_class);
  162. });
  163. $("table.tableWithFloatingHeader").each(function() {
  164. $(this).wrap("<div class=\"divTableWithFloatingHeader\" style=\"position:relative\"></div>");
  165. var originalHeaderRow = $("tr:first", this)
  166. originalHeaderRow.before(originalHeaderRow.clone());
  167. var clonedHeaderRow = $("tr:first", this)
  168. clonedHeaderRow.addClass("tableFloatingHeader");
  169. clonedHeaderRow.css("position", "absolute");
  170. clonedHeaderRow.css("top", "0px");
  171. clonedHeaderRow.css("left", $(this).css("margin-left"));
  172. clonedHeaderRow.css("visibility", "hidden");
  173. originalHeaderRow.addClass("tableFloatingHeaderOriginal");
  174. });
  175. UpdateTableHeaders();
  176. $(window).scroll(UpdateTableHeaders);
  177. $(window).resize(UpdateTableHeaders);
  178. });
  179. </script>
  180. <form id="form_attendance_sheet" method="post" action="index.php?action=attendance_sheet_add&<?php echo api_get_cidreq().$param_gradebook.$param_filter ?>&attendance_id=<?php echo $attendance_id?>" >
  181. <div class="attendance-sheet-content" style="width:100%;background-color:#E1E1E1;margin-top:20px;">
  182. <div class="divTableWithFloatingHeader attendance-users-table" style="width:45%;float:left;margin:0px;padding:0px;">
  183. <table class="tableWithFloatingHeader data_table" width="100%">
  184. <thead>
  185. <tr class="tableFloatingHeader" style="position: absolute; top: 0px; left: 0px; visibility: hidden; margin:0px;padding:0px" >
  186. <th width="10px"><?php echo '#'; ?></th>
  187. <th width="10px"><?php echo get_lang('Photo')?></th>
  188. <th width="100px"><?php echo get_lang('LastName')?></th>
  189. <th width="100px"><?php echo get_lang('FirstName')?></th>
  190. <th width="100px"><?php echo get_lang('AttendancesFaults')?></th>
  191. </tr>
  192. <tr class="tableFloatingHeaderOriginal" >
  193. <th height="65px" width="10px"><?php echo '#';?></th>
  194. <th width="10px"><?php echo get_lang('Photo')?></th>
  195. <th width="150px"><?php echo get_lang('LastName')?></th>
  196. <th width="140px"><?php echo get_lang('FirstName')?></th>
  197. <th width="92px"><?php echo get_lang('AttendancesFaults')?></th>
  198. </tr>
  199. </thead>
  200. <tbody>
  201. <?php
  202. $i = 1;
  203. $class = '';
  204. foreach ($users_in_course as $data) {
  205. $faults = 0;
  206. if ($i%2 == 0) {
  207. $class='row_odd';
  208. } else {
  209. $class='row_even';
  210. }
  211. $username = api_htmlentities(sprintf(get_lang('LoginX'), $data['username']), ENT_QUOTES);
  212. ?>
  213. <tr class="<?php echo $class ?>">
  214. <td><center><?php echo $i ?></center></td>
  215. <td><?php echo $data['photo'] ?></td>
  216. <td><span title="<?php echo $username ?>"><?php echo $data['lastname'] ?></span></td>
  217. <td><?php echo $data['firstname'] ?></td>
  218. <td>
  219. <div class="attendance-faults-bar">
  220. <?php echo Display::label($data['attendance_result'], $data['result_color_bar']); ?>
  221. </div>
  222. </td>
  223. </tr>
  224. <?php
  225. $i++;
  226. }
  227. ?>
  228. </tbody>
  229. </table>
  230. </div>
  231. <?php
  232. echo '<div class="divTableWithFloatingHeader attendance-calendar-table" style="margin:0px;padding:0px;float:left;width:55%;overflow:auto;overflow-y:hidden;">';
  233. echo '<table class="tableWithFloatingHeader data_table" width="100%">';
  234. echo '<thead>';
  235. $result = null;
  236. if (count($attendant_calendar) > 0 ) {
  237. foreach ($attendant_calendar as $calendar) {
  238. $date = $calendar['date'];
  239. $time = $calendar['time'];
  240. $datetime = $date.'<br />'.$time;
  241. $datetime = api_format_date($calendar['date_time'], DATE_FORMAT_NUMBER_NO_YEAR);
  242. $img_lock = Display::return_icon('lock.gif',get_lang('DateUnLock'),array('class'=>'img_lock','id'=>'datetime_column_'.$calendar['id']));
  243. if (!empty($calendar['done_attendance'])){
  244. $datetime = '<font color="blue">'.$datetime.'</font>';
  245. }
  246. $disabled_check = 'disabled = "true"';
  247. if ($next_attendance_calendar_id == $calendar['id']) {
  248. $input_hidden = '<input type="hidden" id="hidden_input_'.$calendar['id'].'" name="hidden_input[]" value="'.$calendar['id'].'" />';
  249. $disabled_check = '';
  250. $img_lock = Display::return_icon('unlock.gif',get_lang('DateLock'),array('class'=>'img_unlock','id'=>'datetime_column_'.$calendar['id']));
  251. } else {
  252. $input_hidden = '<input type="hidden" id="hidden_input_'.$calendar['id'].'" name="hidden_input[]" value="" />';
  253. }
  254. $result .= '<th width="800px" style="text-align:center">';
  255. $result .= '<center><div style="width:40px;">'.$datetime.'<br />';
  256. if (api_is_allowed_to_edit(null, true)) {
  257. $result .= '<span id="attendance_lock" style="cursor:pointer">'.(!$is_locked_attendance || api_is_platform_admin()?$img_lock:'').'</span>';
  258. }
  259. if ($is_locked_attendance == false) {
  260. if (api_is_allowed_to_edit(null, true)) {
  261. $result .= $input_hidden.'</div><center></th>';
  262. }
  263. }
  264. }
  265. } else {
  266. $result = '<th width="2000px"><span><a href="index.php?'.api_get_cidreq().'&action=calendar_list&attendance_id='.$attendance_id.$param_gradebook.'">';
  267. $result .= Display::return_icon('attendance_calendar.png',get_lang('AttendanceCalendar'),'',ICON_SIZE_MEDIUM).' '.get_lang('GoToAttendanceCalendar').'</a></span></th>';
  268. }
  269. echo '<tr class="tableFloatingHeader row_odd" style="position: absolute; top: 0px; left: 0px; visibility: hidden; margin:0px;padding:0px">';
  270. echo $result;
  271. echo '</tr>';
  272. echo '<tr class="tableWithFloatingHeader row_odd">';
  273. echo $result;
  274. echo '</tr>';
  275. echo '</thead>';
  276. echo '<tbody>';
  277. $i = 0;
  278. $default_presence_value = $attendance_obj->get_default_attendance_state();
  279. foreach ($users_in_course as $user) {
  280. $class = '';
  281. if ($i % 2 == 0) {
  282. $class = 'row_even';
  283. } else {
  284. $class = 'row_odd';
  285. }
  286. echo '<tr class="'.$class.'">';
  287. if (count($attendant_calendar) > 0 ) {
  288. foreach ($attendant_calendar as $calendar) {
  289. $presence = $default_presence_value;
  290. if (isset($users_presence[$user['user_id']][$calendar['id']]['presence'])) {
  291. $presence = isset($users_presence[$user['user_id']][$calendar['id']]['presence']) ? $users_presence[$user['user_id']][$calendar['id']]['presence'] : $default_presence_value;
  292. } else {
  293. //if the user wasn't registered at that time, consider unchecked
  294. if ($next_attendance_calendar_datetime == 0 || $calendar['date_time'] < $next_attendance_calendar_datetime) {
  295. $presence = $default_presence_value;
  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 style="text-align:center; height:20px">';
  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. foreach ($attendance_states as $key => $state) {
  313. $input_checked = null;
  314. if ($key == $presence) {
  315. $input_checked = " checked=checked";
  316. }
  317. //echo Display::tag('label', '<input type="checkbox" name="check_presence['.$calendar['id'].'][]" value = "state_'.$key.'_'.$user['user_id'].'" '.$disabled.' '.$input_checked.' />&nbsp;'.$state, array('class'=> 'checkbox'));
  318. }
  319. $link_id = 'link_'.$key.'_'.$user['user_id'].'_'.$calendar['id'];
  320. $attributes = array('id' => $link_id, 'class' => 'switch '.$disabled);
  321. echo $attendance_obj->get_attendance_state_button($presence, false, $attributes);
  322. echo '<input id = "hidden_'.$link_id.'" type="hidden" name="check_presence['.$calendar['id'].'][]" '.$input_checked.' value="'.$presence.'" />';
  323. echo '<span class="anchor_'.$calendar['id'].'"></span>';
  324. } else {
  325. echo $presence ? Display::return_icon('checkbox_on.gif',get_lang('Presence')) : Display::return_icon('checkbox_off.gif',get_lang('Presence'));
  326. }
  327. } else {
  328. switch($presence) {
  329. case 1:
  330. echo Display::return_icon('accept.png',get_lang('Attended'));
  331. break;
  332. case 0:
  333. echo Display::return_icon('exclamation.png',get_lang('NotAttended'));
  334. break;
  335. case -1:
  336. //echo Display::return_icon('warning.png',get_lang('NotAttended'));
  337. break;
  338. }
  339. }
  340. echo '</div>';
  341. echo '</td>';
  342. }
  343. } else {
  344. echo '<td class="checkboxes_col_'.$calendar['id'].'">';
  345. echo '<div style="height:20px">';
  346. echo '<center>&nbsp;</center>
  347. </div>
  348. </td>';
  349. }
  350. echo '</tr>';
  351. $i++ ;
  352. }
  353. echo '</tbody></table>';
  354. echo '</div></div>';
  355. ?>
  356. <div class="clear"></div>
  357. <div style="margin-top:20px;">
  358. <?php if (!$is_locked_attendance || api_is_platform_admin()) {
  359. if (api_is_allowed_to_edit(null, true)) {
  360. ?>
  361. <button onclick="save_checkboxes();" type="button" class="save"><?php echo get_lang('Save') ?></button>
  362. <?php }
  363. }
  364. ?>
  365. </div>
  366. </form>
  367. <?php
  368. } else {
  369. echo Display::display_warning_message('<a href="'.api_get_path(WEB_CODE_PATH).'user/user.php?'.api_get_cidreq().'">'.get_lang('ThereAreNoRegisteredLearnersInsidetheCourse').'</a>', false);
  370. }
  371. } else {
  372. echo Display::page_header(get_lang('AttendanceSheetReport'));
  373. // View for students
  374. ?>
  375. <?php if(!empty($users_presence)) { ?>
  376. <div>
  377. <table width="250px;">
  378. <tr>
  379. <td><?php echo get_lang('ToAttend').': ' ?></td>
  380. <td><center><div class="attendance-faults-bar" style="background-color:<?php echo (!empty($faults['color_bar'])?$faults['color_bar']:'none') ?>">
  381. <?php echo $faults['faults'].'/'.$faults['total'].' ('.$faults['faults_porcent'].'%)' ?></div></center>
  382. </td>
  383. </tr>
  384. </table>
  385. </div>
  386. <?php } ?>
  387. <table class="data_table">
  388. <tr class="row_odd" >
  389. <th><?php echo get_lang('Attendance')?></th>
  390. </tr>
  391. <?php
  392. if (!empty($users_presence)) {
  393. $i = 0;
  394. foreach ($users_presence[$user_id] as $presence) {
  395. $class = '';
  396. if ($i%2==0) {
  397. $class = 'row_even';
  398. } else {
  399. $class = 'row_odd';
  400. }
  401. ?>
  402. <tr class="<?php echo $class ?>">
  403. <td>
  404. <?php
  405. echo $attendance_obj->get_attendance_state_button($presence['presence']);
  406. //echo $presence['presence']?Display::return_icon('checkbox_on.gif',get_lang('Presence')):Display::return_icon('checkbox_off.gif',get_lang('Presence'))
  407. echo "&nbsp; ".$presence['date_time'] ?>
  408. </td>
  409. </tr>
  410. <?php }
  411. } else { ?>
  412. <tr><td>
  413. <center><?php echo get_lang('YouDoNotHaveDoneAttendances')?></center></td>
  414. </tr>
  415. <?php }
  416. ?>
  417. </table>
  418. <?php } ?>