index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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","'.api_get_path(WEB_CODE_PATH).'img/lock.gif");
  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","'.api_get_path(WEB_CODE_PATH).'img/unlock.gif");
  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").attr("checked",true);
  128. } else {
  129. $(".checkboxes_col_"+calendar_id+" input:checkbox").attr("checked",false);
  130. }
  131. });
  132. $(".attendance-sheet-content .row_odd, .attendance-sheet-content .row_even").mouseover(function() {
  133. $(".row_odd").css({"background-color":"#F9F9F9"});
  134. $(".row_even").css({"background-color":"#FFF"});
  135. });
  136. $(".attendance-sheet-content .row_odd, .attendance-sheet-content .row_even").mouseout(function() {
  137. $(".row_odd").css({"background-color":"#F9F9F9"});
  138. $(".row_even").css({"background-color":"#FFF"});
  139. });
  140. });
  141. </script>';
  142. // interbreadcrumbs
  143. if (!empty($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
  144. $_SESSION['gradebook'] = Security::remove_XSS($_GET['gradebook']);
  145. $gradebook = $_SESSION['gradebook'];
  146. } elseif (empty($_GET['gradebook'])) {
  147. unset($_SESSION['gradebook']);
  148. $gradebook = '';
  149. }
  150. $param_gradebook = '';
  151. if (isset($_SESSION['gradebook'])) {
  152. $param_gradebook = '&gradebook='.$gradebook;
  153. }
  154. $student_param = '';
  155. $student_id = null;
  156. if (api_is_drh() && isset($_GET['student_id'])) {
  157. $student_id = intval($_GET['student_id']);
  158. $student_param = '&student_id='.$student_id;
  159. $student_info = api_get_user_info($student_id);
  160. $interbreadcrumb[] = array(
  161. 'url' => api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id,
  162. 'name' => $student_info['complete_name']
  163. );
  164. }
  165. if (!empty($gradebook)) {
  166. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'gradebook/index.php', 'name' => get_lang('ToolGradebook'));
  167. }
  168. $interbreadcrumb[] = array('url' => 'index.php?'.api_get_cidreq().'&action=attendance_list'.$param_gradebook.$student_param, 'name' => get_lang('ToolAttendance'));
  169. if ($action == 'attendance_add') {
  170. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('CreateANewAttendance'));
  171. }
  172. if ($action == 'attendance_edit') {
  173. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Edit'));
  174. }
  175. if ($action == 'attendance_sheet_list' || $action == 'attendance_sheet_add') {
  176. $interbreadcrumb[] = array('url' => '#', 'name' => $attendance_data['name']);
  177. }
  178. if ($action == 'calendar_list' || $action == 'calendar_edit' || $action == 'calendar_delete' || $action == 'calendar_all_delete') {
  179. $interbreadcrumb[] = array('url' => 'index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance_id.$param_gradebook, 'name' => $attendance_data['name']);
  180. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('AttendanceCalendar'));
  181. }
  182. if ($action == 'calendar_add') {
  183. $interbreadcrumb[] = array('url' => 'index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance_id.$param_gradebook, 'name' => $attendance_data['name']);
  184. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('AddDateAndTime'));
  185. }
  186. // Delete selected attendance
  187. if (isset($_POST['action']) && $_POST['action'] == 'attendance_delete_select') {
  188. $attendanceController->attendance_delete($_POST['id']);
  189. }
  190. if (isset($_POST['action']) && $_POST['action'] == 'attendance_set_invisible_select') {
  191. $attendanceController->attendanceSetInvisible($_POST['id']);
  192. }
  193. if (isset($_POST['action']) && $_POST['action'] == 'attendance_set_visible_select') {
  194. $attendanceController->attendanceSetVisible($_POST['id']);
  195. }
  196. // Distpacher actions to controller
  197. switch ($action) {
  198. case 'attendance_list':
  199. $attendanceController->attendance_list();
  200. break;
  201. case 'attendance_add':
  202. if (api_is_allowed_to_edit(null, true)) {
  203. $attendanceController->attendance_add();
  204. } else {
  205. api_not_allowed();
  206. }
  207. break;
  208. case 'attendance_edit':
  209. if (api_is_allowed_to_edit(null, true)) {
  210. $attendanceController->attendance_edit($attendance_id);
  211. } else {
  212. api_not_allowed();
  213. }
  214. break;
  215. case 'attendance_delete':
  216. if (api_is_allowed_to_edit(null, true)) {
  217. $attendanceController->attendance_delete($attendance_id);
  218. } else {
  219. api_not_allowed();
  220. }
  221. break;
  222. case 'attendance_set_invisible':
  223. if (api_is_allowed_to_edit(null, true)) {
  224. $attendanceController->attendanceSetInvisible($attendance_id);
  225. } else {
  226. api_not_allowed();
  227. }
  228. break;
  229. case 'attendance_set_visible':
  230. if (api_is_allowed_to_edit(null, true)) {
  231. $attendanceController->attendanceSetVisible($attendance_id);
  232. } else {
  233. api_not_allowed();
  234. }
  235. break;
  236. /*case 'attendance_restore':
  237. if (api_is_allowed_to_edit(null, true)) {
  238. $attendanceController->attendance_restore($attendance_id);
  239. } else {
  240. api_not_allowed();
  241. }
  242. break;*/
  243. case 'attendance_sheet_list':
  244. $attendanceController->attendance_sheet($action, $attendance_id, $student_id, true);
  245. break;
  246. case 'attendance_sheet_list_no_edit':
  247. $attendanceController->attendance_sheet($action, $attendance_id, $student_id, false);
  248. break;
  249. case 'attendance_sheet_export_to_pdf':
  250. $attendanceController->attendance_sheet_export_to_pdf($action, $attendance_id, $student_id, $course_id);
  251. break;
  252. case 'attendance_sheet_add' :
  253. if (api_is_allowed_to_edit(null, true)) {
  254. $attendanceController->attendance_sheet($action, $attendance_id);
  255. } else {
  256. api_not_allowed();
  257. }
  258. break;
  259. case 'lock_attendance':
  260. case 'unlock_attendance':
  261. if (api_is_allowed_to_edit(null, true)) {
  262. $attendanceController->lock_attendance($action, $attendance_id);
  263. } else {
  264. api_not_allowed();
  265. }
  266. break;
  267. case 'calendar_add':
  268. case 'calendar_edit':
  269. case 'calendar_all_delete':
  270. case 'calendar_delete':
  271. if (!api_is_allowed_to_edit(null, true)) {
  272. api_not_allowed();
  273. }
  274. case 'calendar_list':
  275. $attendanceController->attendance_calendar($action, $attendance_id, $calendar_id);
  276. break;
  277. case 'calendar_logins':
  278. if (api_is_allowed_to_edit(null, true) || api_is_drh()) {
  279. $attendanceController->getAttendanceBaseInLogin(false, true);
  280. }
  281. break;
  282. default :
  283. $attendanceController->attendance_list();
  284. }