index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. 'lock_attendance',
  39. 'unlock_attendance'
  40. );
  41. $actions_calendar = array('calendar_list', 'calendar_add', 'calendar_edit', 'calendar_delete', 'calendar_all_delete');
  42. $action = 'attendance_list';
  43. $course_id = '';
  44. if (isset($_GET['cidReq'])){
  45. $course_id = $_GET['cidReq'];
  46. }
  47. if (isset($_GET['action']) && (in_array($_GET['action'],$actions) || in_array($_GET['action'],$actions_calendar))) {
  48. $action = $_GET['action'];
  49. }
  50. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') {
  51. $action = 'attendance_list';
  52. }
  53. // get attendance id
  54. $attendance_id = 0;
  55. if (isset($_GET['attendance_id'])) {
  56. $attendance_id = intval($_GET['attendance_id']);
  57. }
  58. // get calendar id
  59. $calendar_id = '';
  60. if (isset($_GET['calendar_id'])) {
  61. $calendar_id = intval($_GET['calendar_id']);
  62. }
  63. // instance attendance object for using like library here
  64. $attendance = new Attendance();
  65. // attendance controller object
  66. $attendance_controller = new AttendanceController();
  67. // get attendance data
  68. if (!empty($attendance_id)) {
  69. // attendance data by id
  70. $attendance_data = $attendance->get_attendance_by_id($attendance_id);
  71. }
  72. $htmlHeadXtra[] = api_get_jqgrid_js();
  73. $htmlHeadXtra[] = '<script>
  74. $(function() {
  75. $("table th img").click(function() {
  76. var col_id = this.id;
  77. var col_split = col_id.split("_");
  78. var calendar_id = col_split[2];
  79. var class_img = $(this).attr("class");
  80. if (class_img == "img_unlock") {
  81. //lock
  82. $(".checkbox_head_"+calendar_id).attr("disabled", true);
  83. $(".row_odd td.checkboxes_col_"+calendar_id).css({"opacity":"1","background-color":"#F9F9F9", "border-left":"none","border-right":"none"});
  84. $(".row_even td.checkboxes_col_"+calendar_id).css({"opacity":"1","background-color":"#FFF", "border-left":"none","border-right":"none"});
  85. $(".checkboxes_col_"+calendar_id+" input:checkbox").attr("disabled",true);
  86. $(this).attr("src","'.api_get_path(WEB_CODE_PATH).'img/lock.gif");
  87. $(this).attr("title","'.get_lang('DateUnLock').'");
  88. $(this).attr("alt","'.get_lang('DateUnLock').'");
  89. $(this).attr("class","img_lock");
  90. $("#hidden_input_"+calendar_id).attr("value","");
  91. $("#hidden_input_"+calendar_id).attr("disabled",true);
  92. $(".checkboxes_col_"+calendar_id).find(".switch").each(function(index) {
  93. $(this).addClass("disabled");
  94. });
  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).find(".switch").each(function(index) {
  112. $(this).removeClass("disabled");
  113. });
  114. $(this).attr("src","'.api_get_path(WEB_CODE_PATH).'img/unlock.gif");
  115. $(this).attr("title","'.get_lang('DateLock').'");
  116. $(this).attr("alt","'.get_lang('DateLock').'");
  117. $(this).attr("class","img_unlock");
  118. $("#hidden_input_"+calendar_id).attr("disabled",false);
  119. $("#hidden_input_"+calendar_id).attr("value",calendar_id);
  120. return false;
  121. }
  122. });
  123. $("table th input:checkbox").click(function() {
  124. var col_id = this.id;
  125. var col_split = col_id.split("_");
  126. var calendar_id = col_split[2];
  127. if (this.checked) {
  128. $(".checkboxes_col_"+calendar_id+" input:checkbox").attr("checked",true);
  129. } else {
  130. $(".checkboxes_col_"+calendar_id+" input:checkbox").attr("checked",false);
  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. $(".advanced_parameters").click(function() {
  142. if ($("#id_qualify").css("display") == "none") {
  143. $("#id_qualify").css("display","block");
  144. $("#img_plus_and_minus").html(\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\');
  145. } else {
  146. $("#id_qualify").css("display","none");
  147. $("#img_plus_and_minus").html(\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\');
  148. }
  149. });
  150. });
  151. </script>';
  152. // interbreadcrumbs
  153. if (!empty($_GET['gradebook']) && $_GET['gradebook']=='view' ) {
  154. $_SESSION['gradebook']=Security::remove_XSS($_GET['gradebook']);
  155. $gradebook= $_SESSION['gradebook'];
  156. } elseif (empty($_GET['gradebook'])) {
  157. unset($_SESSION['gradebook']);
  158. $gradebook= '';
  159. }
  160. $param_gradebook = '';
  161. if (isset($_SESSION['gradebook'])) {
  162. $param_gradebook = '&gradebook='.$gradebook;
  163. }
  164. $student_param = '';
  165. $student_id = null;
  166. if (api_is_drh() && isset($_GET['student_id'])) {
  167. $student_id = intval($_GET['student_id']);
  168. $student_param = '&student_id='.$student_id;
  169. $student_info = api_get_user_info($student_id);
  170. $student_name = api_get_person_name($student_info['firstname'],$student_info['lastname']);
  171. $interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id, 'name' => $student_name);
  172. }
  173. if (!empty($gradebook)) {
  174. $interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'gradebook/index.php', 'name' => get_lang('ToolGradebook'));
  175. }
  176. $interbreadcrumb[] = array ('url' => 'index.php?'.api_get_cidreq().'&action=attendance_list'.$param_gradebook.$student_param, 'name' => get_lang('ToolAttendance'));
  177. if ($action == 'attendance_add') {
  178. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('CreateANewAttendance'));
  179. }
  180. if ($action == 'attendance_edit') {
  181. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('Edit'));
  182. }
  183. if ($action == 'attendance_sheet_list' || $action == 'attendance_sheet_add') {
  184. $interbreadcrumb[] = array ('url' => '#', 'name' => $attendance_data['name']);
  185. }
  186. if ($action == 'calendar_list' || $action == 'calendar_edit' || $action == 'calendar_delete' || $action == 'calendar_all_delete') {
  187. $interbreadcrumb[] = array ('url' => 'index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance_id.$param_gradebook, 'name' => $attendance_data['name']);
  188. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('AttendanceCalendar'));
  189. }
  190. if ($action == 'calendar_add') {
  191. $interbreadcrumb[] = array ('url' => 'index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance_id.$param_gradebook, 'name' => $attendance_data['name']);
  192. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('AddDateAndTime'));
  193. }
  194. // delete selected attendance
  195. if (isset($_POST['action']) && $_POST['action'] == 'attendance_delete_select') {
  196. $attendance_controller->attendance_delete($_POST['id']);
  197. }
  198. // distpacher actions to controller
  199. switch ($action) {
  200. case 'attendance_list':
  201. $attendance_controller->attendance_list();
  202. break;
  203. case 'attendance_add':
  204. if (api_is_allowed_to_edit(null, true)) {
  205. $attendance_controller->attendance_add();
  206. } else {
  207. api_not_allowed();
  208. }
  209. break;
  210. case 'attendance_edit' :
  211. if (api_is_allowed_to_edit(null, true)) {
  212. $attendance_controller->attendance_edit($attendance_id);
  213. } else {
  214. api_not_allowed();
  215. }
  216. break;
  217. case 'attendance_delete' :
  218. if (api_is_allowed_to_edit(null, true)) {
  219. $attendance_controller->attendance_delete($attendance_id);
  220. } else {
  221. api_not_allowed();
  222. }
  223. break;
  224. case 'attendance_restore':
  225. if (api_is_allowed_to_edit(null, true)) {
  226. $attendance_controller->attendance_restore($attendance_id);
  227. } else {
  228. api_not_allowed();
  229. }
  230. break;
  231. case 'attendance_sheet_list':
  232. $edit_content = api_is_allowed_to_edit(null, true);
  233. $attendance_controller->attendance_sheet($action, $attendance_id, $student_id, $edit_content);
  234. break;
  235. case 'attendance_sheet_list_no_edit':
  236. $attendance_controller->attendance_sheet($action, $attendance_id, $student_id, false);
  237. break;
  238. case 'attendance_sheet_export_to_pdf':
  239. $attendance_controller->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. $attendance_controller->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. $attendance_controller->lock_attendance($action, $attendance_id);
  252. } else {
  253. api_not_allowed();
  254. }
  255. break;
  256. case 'calendar_add' :
  257. case 'calendar_edit' :
  258. case 'calendar_all_delete' :
  259. case 'calendar_delete' :
  260. if (!api_is_allowed_to_edit(null, true)) {
  261. api_not_allowed();
  262. }
  263. case 'calendar_list' :
  264. $attendance_controller->attendance_calendar($action, $attendance_id, $calendar_id);
  265. break;
  266. default :
  267. $attendance_controller->attendance_list();
  268. }