index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Template (front controller in MVC pattern) used for distpaching to the controllers depend on the current action
  5. * @author Christian Fasanando <christian1827@gmail.com>
  6. * @author Julio Montoya <gugli100@gmail.com> Bug fixing, sql improvements
  7. *
  8. * @package chamilo.attendance
  9. */
  10. // including files
  11. ////require_once '../inc/global.inc.php';
  12. require_once 'attendance_controller.php';
  13. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/fe/exportgradebook.php';
  14. $current_course_tool = TOOL_ATTENDANCE;
  15. // current section
  16. $this_section = SECTION_COURSES;
  17. // protect a course script
  18. api_protect_course_script(true);
  19. // Get actions
  20. $actions = array(
  21. 'attendance_list',
  22. 'attendance_sheet_list',
  23. 'attendance_sheet_add',
  24. 'attendance_add',
  25. 'attendance_edit',
  26. 'attendance_delete',
  27. 'attendance_delete_select',
  28. 'attendance_set_invisible',
  29. 'attendance_set_invisible_select',
  30. 'attendance_set_visible',
  31. 'attendance_set_visible_select',
  32. 'attendance_restore',
  33. 'attendance_sheet_export_to_pdf',
  34. 'attendance_sheet_list_no_edit',
  35. 'calendar_logins'
  36. );
  37. $actions_calendar = array(
  38. 'calendar_list',
  39. 'calendar_add',
  40. 'calendar_edit',
  41. 'calendar_delete',
  42. 'calendar_all_delete'
  43. );
  44. $action = 'attendance_list';
  45. $course_id = '';
  46. if (isset($_GET['cidReq'])) {
  47. $course_id = $_GET['cidReq'];
  48. }
  49. if (isset($_GET['action']) &&
  50. (in_array($_GET['action'], $actions) || in_array($_GET['action'], $actions_calendar))
  51. ) {
  52. $action = $_GET['action'];
  53. }
  54. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') {
  55. $action = 'attendance_list';
  56. }
  57. // get attendance id
  58. $attendance_id = 0;
  59. if (isset($_GET['attendance_id'])) {
  60. $attendance_id = intval($_GET['attendance_id']);
  61. }
  62. // get calendar id
  63. $calendar_id = '';
  64. if (isset($_GET['calendar_id'])) {
  65. $calendar_id = intval($_GET['calendar_id']);
  66. }
  67. // instance attendance object for using like library here
  68. $attendance = new Attendance();
  69. // attendance controller object
  70. $attendanceController = new AttendanceController();
  71. $attendance_data = array();
  72. // get attendance data
  73. if (!empty($attendance_id)) {
  74. // attendance data by id
  75. $attendance_data = $attendance->get_attendance_by_id($attendance_id);
  76. }
  77. $htmlHeadXtra[] = '<script>
  78. $(function() {
  79. $("table th img").click(function() {
  80. var col_id = this.id;
  81. var col_split = col_id.split("_");
  82. var calendar_id = col_split[2];
  83. var class_img = $(this).attr("class");
  84. if (class_img == "img_unlock") {
  85. //lock
  86. $(".checkbox_head_"+calendar_id).attr("disabled", true);
  87. $(".row_odd td.checkboxes_col_"+calendar_id).css({"opacity":"1","background-color":"#F9F9F9", "border-left":"none","border-right":"none"});
  88. $(".row_even td.checkboxes_col_"+calendar_id).css({"opacity":"1","background-color":"#FFF", "border-left":"none","border-right":"none"});
  89. $(".checkboxes_col_"+calendar_id+" input:checkbox").attr("disabled",true);
  90. $(this).attr("src","'.Display::returnIconPath('lock-closed.png').'");
  91. $(this).attr("title","'.get_lang('DateUnLock').'");
  92. $(this).attr("alt","'.get_lang('DateUnLock').'");
  93. $(this).attr("class","img_lock");
  94. $("#hidden_input_"+calendar_id).attr("value","");
  95. $("#hidden_input_"+calendar_id).attr("disabled",true);
  96. return false;
  97. } else {
  98. //Unlock
  99. $(".checkbox_head_"+calendar_id).attr("disabled", false);
  100. $(".checkbox_head_"+calendar_id).removeAttr("disabled");
  101. $(".row_odd td.checkboxes_col_"+calendar_id).css({"opacity":"1","background-color":"#dcdcdc", "border-left":"1px #bbb solid", "border-right":"1px #bbb solid", "z-index":"1" });
  102. $(".row_even td.checkboxes_col_"+calendar_id).css({"opacity":"1","background-color":"#eee", "border-left":"1px #bbb solid", "border-right":"1px #bbb solid", "z-index":"1" });
  103. $(".checkboxes_col_"+calendar_id).mouseover(function() {
  104. //$(".checkbox_head_"+calendar_id).removeAttr("opacity");
  105. //$("row_even td.checkboxes_col_"+calendar_id).css({"opacity":"1","background-color":"red", "border-left":"1px #EEEE00 solid", "border-right":"1px #EEEE00 solid" , "border-bottom":"1px #ccc solid" });
  106. //$("row_odd td.checkboxes_col_"+calendar_id).css({"opacity":"1","background-color":"#FFF", "border-left":"1px #EEEE00 solid", "border-right":"1px #EEEE00 solid" , "border-bottom":"1px #ccc solid" });
  107. });
  108. $(".checkboxes_col_"+calendar_id).mouseout(function() {
  109. // $("row_even td.checkboxes_col_"+calendar_id).css({"opacity":"1","background-color":"#F9F9F9", "border-left":"1px #EEEE00 solid", "border-right":"1px #EEEE00 solid" , "border-bottom":"1px #ccc solid" });
  110. // $("row_odd td.checkboxes_col_"+calendar_id).css({"opacity":"1","background-color":"#FFF", "border-left":"1px #EEEE00 solid", "border-right":"1px #EEEE00 solid" , "border-bottom":"1px #ccc solid" });
  111. });
  112. $(".checkboxes_col_"+calendar_id+" input:checkbox").attr("disabled",false);
  113. $(this).attr("src","'.Display::returnIconPath('lock-open.png').'");
  114. $(this).attr("title","'.get_lang('DateLock').'");
  115. $(this).attr("alt","'.get_lang('DateLock').'");
  116. $(this).attr("class","img_unlock");
  117. $("#hidden_input_"+calendar_id).attr("disabled",false);
  118. $("#hidden_input_"+calendar_id).attr("value",calendar_id);
  119. return false;
  120. }
  121. });
  122. $("table th input:checkbox").click(function() {
  123. var col_id = this.id;
  124. var col_split = col_id.split("_");
  125. var calendar_id = col_split[2];
  126. if (this.checked) {
  127. $(".checkboxes_col_"+calendar_id+" input:checkbox").prop("checked",true);
  128. $(".checkboxes_col_"+calendar_id+"").addClass("row_selected");
  129. } else {
  130. $(".checkboxes_col_"+calendar_id+" input:checkbox").prop("checked",false);
  131. $(".checkboxes_col_"+calendar_id+"").removeClass("row_selected");
  132. }
  133. });
  134. $(".attendance-sheet-content .row_odd, .attendance-sheet-content .row_even").mouseover(function() {
  135. $(".row_odd").css({"background-color":"#F9F9F9"});
  136. $(".row_even").css({"background-color":"#FFF"});
  137. });
  138. $(".attendance-sheet-content .row_odd, .attendance-sheet-content .row_even").mouseout(function() {
  139. $(".row_odd").css({"background-color":"#F9F9F9"});
  140. $(".row_even").css({"background-color":"#FFF"});
  141. });
  142. });
  143. </script>';
  144. $student_param = '';
  145. $student_id = null;
  146. if (api_is_drh() && isset($_GET['student_id'])) {
  147. $student_id = intval($_GET['student_id']);
  148. $student_param = '&student_id='.$student_id;
  149. $student_info = api_get_user_info($student_id);
  150. $interbreadcrumb[] = array(
  151. 'url' => api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id,
  152. 'name' => $student_info['complete_name']
  153. );
  154. }
  155. if (api_is_in_gradebook()) {
  156. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'gradebook/index.php?'.api_get_cidreq(), 'name' => get_lang('ToolGradebook'));
  157. }
  158. $interbreadcrumb[] = array('url' => 'index.php?'.api_get_cidreq().'&action=attendance_list&'.$student_param, 'name' => get_lang('ToolAttendance'));
  159. if ($action == 'attendance_add') {
  160. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('CreateANewAttendance'));
  161. }
  162. if ($action == 'attendance_edit') {
  163. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Edit'));
  164. }
  165. if ($action == 'attendance_sheet_list' || $action == 'attendance_sheet_add') {
  166. $interbreadcrumb[] = array('url' => '#', 'name' => $attendance_data['name']);
  167. }
  168. if ($action == 'calendar_list' || $action == 'calendar_edit' || $action == 'calendar_delete' || $action == 'calendar_all_delete') {
  169. $interbreadcrumb[] = array('url' => 'index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance_id, 'name' => $attendance_data['name']);
  170. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('AttendanceCalendar'));
  171. }
  172. if ($action == 'calendar_add') {
  173. $interbreadcrumb[] = array('url' => 'index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance_id, 'name' => $attendance_data['name']);
  174. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('AddDateAndTime'));
  175. }
  176. // Delete selected attendance
  177. if (isset($_POST['action']) && $_POST['action'] == 'attendance_delete_select') {
  178. $attendanceController->attendance_delete($_POST['id']);
  179. }
  180. if (isset($_POST['action']) && $_POST['action'] == 'attendance_set_invisible_select') {
  181. $attendanceController->attendanceSetInvisible($_POST['id']);
  182. }
  183. if (isset($_POST['action']) && $_POST['action'] == 'attendance_set_visible_select') {
  184. $attendanceController->attendanceSetVisible($_POST['id']);
  185. }
  186. // Distpacher actions to controller
  187. switch ($action) {
  188. case 'attendance_list':
  189. $attendanceController->attendance_list();
  190. break;
  191. case 'attendance_add':
  192. if (api_is_allowed_to_edit(null, true)) {
  193. $attendanceController->attendance_add();
  194. } else {
  195. api_not_allowed();
  196. }
  197. break;
  198. case 'attendance_edit':
  199. if (api_is_allowed_to_edit(null, true)) {
  200. $attendanceController->attendance_edit($attendance_id);
  201. } else {
  202. api_not_allowed();
  203. }
  204. break;
  205. case 'attendance_delete':
  206. if (api_is_allowed_to_edit(null, true)) {
  207. $attendanceController->attendance_delete($attendance_id);
  208. } else {
  209. api_not_allowed();
  210. }
  211. break;
  212. case 'attendance_set_invisible':
  213. if (api_is_allowed_to_edit(null, true)) {
  214. $attendanceController->attendanceSetInvisible($attendance_id);
  215. } else {
  216. api_not_allowed();
  217. }
  218. break;
  219. case 'attendance_set_visible':
  220. if (api_is_allowed_to_edit(null, true)) {
  221. $attendanceController->attendanceSetVisible($attendance_id);
  222. } else {
  223. api_not_allowed();
  224. }
  225. break;
  226. /*case 'attendance_restore':
  227. if (api_is_allowed_to_edit(null, true)) {
  228. $attendanceController->attendance_restore($attendance_id);
  229. } else {
  230. api_not_allowed();
  231. }
  232. break;*/
  233. case 'attendance_sheet_list':
  234. $attendanceController->attendance_sheet($action, $attendance_id, $student_id, true);
  235. break;
  236. case 'attendance_sheet_list_no_edit':
  237. $attendanceController->attendance_sheet($action, $attendance_id, $student_id, false);
  238. break;
  239. case 'attendance_sheet_export_to_pdf':
  240. $attendanceController->attendance_sheet_export_to_pdf($action, $attendance_id, $student_id, $course_id);
  241. break;
  242. case 'attendance_sheet_add' :
  243. if (api_is_allowed_to_edit(null, true)) {
  244. $attendanceController->attendance_sheet($action, $attendance_id);
  245. } else {
  246. api_not_allowed();
  247. }
  248. break;
  249. case 'lock_attendance':
  250. case 'unlock_attendance':
  251. if (api_is_allowed_to_edit(null, true)) {
  252. $attendanceController->lock_attendance($action, $attendance_id);
  253. } else {
  254. api_not_allowed();
  255. }
  256. break;
  257. case 'calendar_add':
  258. case 'calendar_edit':
  259. case 'calendar_all_delete':
  260. case 'calendar_delete':
  261. if (!api_is_allowed_to_edit(null, true)) {
  262. api_not_allowed();
  263. }
  264. case 'calendar_list':
  265. $attendanceController->attendance_calendar($action, $attendance_id, $calendar_id);
  266. break;
  267. case 'calendar_logins':
  268. if (api_is_allowed_to_edit(null, true) || api_is_drh()) {
  269. $attendanceController->getAttendanceBaseInLogin(false, true);
  270. }
  271. break;
  272. default :
  273. $attendanceController->attendance_list();
  274. }