index.php 12 KB

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