index.php 12 KB

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