index.php 11 KB

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