index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. * @author Christian Fasanando <christian1827@gmail.com>
  7. * @author Julio Montoya <gugli100@gmail.com> Bug fixing, sql improvements
  8. *
  9. * @package chamilo.attendance
  10. */
  11. require_once __DIR__.'/../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(
  157. 'url' => api_get_path(WEB_CODE_PATH).'gradebook/index.php?'.api_get_cidreq(),
  158. 'name' => get_lang('ToolGradebook')
  159. );
  160. }
  161. $interbreadcrumb[] = array(
  162. 'url' => 'index.php?'.api_get_cidreq().'&action=attendance_list&'.$student_param,
  163. 'name' => get_lang('ToolAttendance')
  164. );
  165. if ($action == 'attendance_add') {
  166. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('CreateANewAttendance'));
  167. }
  168. if ($action == 'attendance_edit') {
  169. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Edit'));
  170. }
  171. if ($action == 'attendance_sheet_list' || $action == 'attendance_sheet_add') {
  172. $interbreadcrumb[] = array('url' => '#', 'name' => $attendance_data['name']);
  173. }
  174. if ($action == 'calendar_list' || $action == 'calendar_edit' || $action == 'calendar_delete' || $action == 'calendar_all_delete') {
  175. $interbreadcrumb[] = array(
  176. 'url' => 'index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance_id,
  177. 'name' => $attendance_data['name']
  178. );
  179. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('AttendanceCalendar'));
  180. }
  181. if ($action == 'calendar_add') {
  182. $interbreadcrumb[] = array(
  183. 'url' => 'index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance_id,
  184. 'name' => $attendance_data['name']
  185. );
  186. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('AddDateAndTime'));
  187. }
  188. $allowToEdit = api_is_allowed_to_edit(null, true);
  189. // Delete selected attendance
  190. if (isset($_POST['action']) && $_POST['action'] == 'attendance_delete_select' && $allowToEdit) {
  191. $attendanceController->attendance_delete($_POST['id']);
  192. }
  193. if (isset($_POST['action']) && $_POST['action'] == 'attendance_set_invisible_select' && $allowToEdit) {
  194. $attendanceController->attendanceSetInvisible($_POST['id']);
  195. }
  196. if (isset($_POST['action']) && $_POST['action'] == 'attendance_set_visible_select' && $allowToEdit) {
  197. $attendanceController->attendanceSetVisible($_POST['id']);
  198. }
  199. switch ($action) {
  200. case 'attendance_list':
  201. $attendanceController->attendance_list();
  202. break;
  203. case 'attendance_add':
  204. if ($allowToEdit) {
  205. $attendanceController->attendance_add();
  206. } else {
  207. api_not_allowed(true);
  208. }
  209. break;
  210. case 'attendance_edit':
  211. if ($allowToEdit) {
  212. $attendanceController->attendance_edit($attendance_id);
  213. } else {
  214. api_not_allowed(true);
  215. }
  216. break;
  217. case 'attendance_delete':
  218. if ($allowToEdit) {
  219. $attendanceController->attendance_delete($attendance_id);
  220. } else {
  221. api_not_allowed(true);
  222. }
  223. break;
  224. case 'attendance_set_invisible':
  225. if ($allowToEdit) {
  226. $attendanceController->attendanceSetInvisible($attendance_id);
  227. } else {
  228. api_not_allowed(true);
  229. }
  230. break;
  231. case 'attendance_set_visible':
  232. if ($allowToEdit) {
  233. $attendanceController->attendanceSetVisible($attendance_id);
  234. } else {
  235. api_not_allowed(true);
  236. }
  237. break;
  238. /*case 'attendance_restore':
  239. if ($allowToEdit) {
  240. $attendanceController->attendance_restore($attendance_id);
  241. } else {
  242. api_not_allowed(true);
  243. }
  244. break;*/
  245. case 'attendance_sheet_list':
  246. $attendanceController->attendance_sheet(
  247. $action,
  248. $attendance_id,
  249. $student_id,
  250. true
  251. );
  252. break;
  253. case 'attendance_sheet_list_no_edit':
  254. $attendanceController->attendance_sheet(
  255. $action,
  256. $attendance_id,
  257. $student_id,
  258. false
  259. );
  260. break;
  261. case 'attendance_sheet_export_to_pdf':
  262. $attendanceController->attendance_sheet_export_to_pdf(
  263. $action,
  264. $attendance_id,
  265. $student_id,
  266. $course_id
  267. );
  268. break;
  269. case 'attendance_sheet_add':
  270. if ($allowToEdit) {
  271. $attendanceController->attendance_sheet($action, $attendance_id);
  272. } else {
  273. api_not_allowed(true);
  274. }
  275. break;
  276. case 'lock_attendance':
  277. case 'unlock_attendance':
  278. if ($allowToEdit) {
  279. $attendanceController->lock_attendance($action, $attendance_id);
  280. } else {
  281. api_not_allowed(true);
  282. }
  283. break;
  284. case 'calendar_add':
  285. //no break
  286. case 'calendar_edit':
  287. //no break
  288. case 'calendar_all_delete':
  289. //no break
  290. case 'calendar_delete':
  291. if (!$allowToEdit) {
  292. api_not_allowed(true);
  293. }
  294. //no break
  295. case 'calendar_list':
  296. $attendanceController->attendance_calendar(
  297. $action,
  298. $attendance_id,
  299. $calendar_id
  300. );
  301. break;
  302. case 'calendar_logins':
  303. if (api_is_course_admin() || api_is_drh()) {
  304. $attendanceController->getAttendanceBaseInLogin(false, true);
  305. }
  306. break;
  307. default:
  308. $attendanceController->attendance_list();
  309. }