index.php 12 KB

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