index.php 13 KB

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