index.php 11 KB

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