index.php 11 KB

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