attendance_sheet.php 20 KB

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