index.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 Carlos Vargas (link to attendance tool )<litox84@gmail.com>
  7. * @author Julio Montoya <gugli100@gmail.com> Bug fixing, sql improvements
  8. *
  9. * @package chamilo.attendance
  10. */
  11. // name of the language file that needs to be included
  12. $language_file = array ('course_description', 'pedaSuggest', 'userInfo', 'admin', 'agenda','tracking');
  13. // including files
  14. require_once '../inc/global.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 'attendance_controller.php';
  18. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  19. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  20. require_once api_get_path(LIBRARY_PATH).'sortabletable.class.php';
  21. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  22. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  23. // current section
  24. $this_section = SECTION_COURSES;
  25. // protect a course script
  26. api_protect_course_script(true);
  27. // get actions
  28. $actions = array('attendance_list', 'attendance_sheet_list', 'attendance_sheet_add', 'attendance_add', 'attendance_edit', 'attendance_delete', 'attendance_delete_select');
  29. $actions_calendar = array('calendar_list', 'calendar_add', 'calendar_edit', 'calendar_delete', 'calendar_all_delete');
  30. $action = 'attendance_list';
  31. if (isset($_GET['action']) && (in_array($_GET['action'],$actions) || in_array($_GET['action'],$actions_calendar))) {
  32. $action = $_GET['action'];
  33. }
  34. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') {
  35. $action = 'attendance_list';
  36. }
  37. // get attendance id
  38. $attendance_id = 0;
  39. if (isset($_GET['attendance_id'])) {
  40. $attendance_id = intval($_GET['attendance_id']);
  41. }
  42. // get calendar id
  43. $calendar_id = '';
  44. if (isset($_GET['calendar_id'])) {
  45. $calendar_id = intval($_GET['calendar_id']);
  46. }
  47. // instance attendance object for using like library here
  48. $attendance = new Attendance();
  49. // attendance controller object
  50. $attendance_controller = new AttendanceController();
  51. // get attendance data
  52. if (!empty($attendance_id)) {
  53. // attendance data by id
  54. $attendance_data = $attendance->get_attendance_by_id($attendance_id);
  55. }
  56. //jquery thickbox already called from main/inc/header.inc.php
  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. $("#checkbox_head_"+calendar_id).attr("disabled",true);
  66. $(".row_odd td.checkboxes_col_"+calendar_id).css({"background-color":"#F2F2F2"});
  67. $(".row_even td.checkboxes_col_"+calendar_id).css({"background-color":"#FFF"});
  68. $(".checkboxes_col_"+calendar_id+" input:checkbox").attr("disabled",true);
  69. $(this).attr("src","'.api_get_path(WEB_CODE_PATH).'img/lock.gif");
  70. $(this).attr("title","'.get_lang('DateUnLock').'");
  71. $(this).attr("alt","'.get_lang('DateUnLock').'");
  72. $(this).attr("class","img_lock");
  73. $("#hidden_input_"+calendar_id).attr("value","");
  74. $("#hidden_input_"+calendar_id).attr("disabled",true);
  75. return false;
  76. } else {
  77. $("#checkbox_head_"+calendar_id).attr("disabled",false);
  78. $(".checkboxes_col_"+calendar_id).css({"background-color":"#e1e1e1"});
  79. $(".checkboxes_col_"+calendar_id+" input:checkbox").attr("disabled",false);
  80. $(this).attr("src","'.api_get_path(WEB_CODE_PATH).'img/unlock.gif");
  81. $(this).attr("title","'.get_lang('DateLock').'");
  82. $(this).attr("alt","'.get_lang('DateLock').'");
  83. $(this).attr("class","img_unlock");
  84. $("#hidden_input_"+calendar_id).attr("disabled",false);
  85. $("#hidden_input_"+calendar_id).attr("value",calendar_id);
  86. return false;
  87. }
  88. });
  89. $("table th input:checkbox").click(function() {
  90. var col_id = this.id;
  91. var col_split = col_id.split("_");
  92. var calendar_id = col_split[2];
  93. if ($("#"+col_id).is(":checked")) {
  94. $(".checkboxes_col_"+calendar_id+" input:checkbox").attr("checked",true);
  95. } else {
  96. $(".checkboxes_col_"+calendar_id+" input:checkbox").attr("checked",false);
  97. }
  98. });
  99. $(".attendance-sheet-content .row_odd, .attendance-sheet-content .row_even").mouseover(function() {
  100. $(".row_odd").css({"background-color":"#F2F2F2"});
  101. $(".row_even").css({"background-color":"#FFF"});
  102. });
  103. $(".attendance-sheet-content .row_odd, .attendance-sheet-content .row_even").mouseout(function() {
  104. $(".row_odd").css({"background-color":"#F2F2F2"});
  105. $(".row_even").css({"background-color":"#FFF"});
  106. });
  107. $(".advanced_parameters").click(function() {
  108. if ($("#id_qualify").css("display") == "none") {
  109. $("#id_qualify").css("display","block");
  110. $("#img_plus_and_minus").html(\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\');
  111. } else {
  112. $("#id_qualify").css("display","none");
  113. $("#img_plus_and_minus").html(\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\');
  114. }
  115. });
  116. });
  117. </script>';
  118. // interbreadcrumbs
  119. if (!empty($_GET['gradebook']) && $_GET['gradebook']=='view' ) {
  120. $_SESSION['gradebook']=Security::remove_XSS($_GET['gradebook']);
  121. $gradebook= $_SESSION['gradebook'];
  122. } elseif (empty($_GET['gradebook'])) {
  123. unset($_SESSION['gradebook']);
  124. $gradebook= '';
  125. }
  126. $param_gradebook = '';
  127. if (isset($_SESSION['gradebook'])) {
  128. $param_gradebook = '&gradebook='.$gradebook;
  129. }
  130. $student_param = '';
  131. if (api_is_drh() && isset($_GET['student_id'])) {
  132. $student_id = intval($_GET['student_id']);
  133. $student_param = '&student_id='.$student_id;
  134. $student_info = api_get_user_info($student_id);
  135. $student_name = api_get_person_name($student_info['firstname'],$student_info['lastname']);
  136. $interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id, 'name' => $student_name);
  137. }
  138. if (!empty($gradebook)) {
  139. $interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'gradebook/index.php', 'name' => get_lang('ToolGradebook'));
  140. }
  141. $interbreadcrumb[] = array ('url' => 'index.php?'.api_get_cidreq().'&action=attendance_list'.$param_gradebook.$student_param, 'name' => get_lang('ToolAttendance'));
  142. if ($action == 'attendance_add') {
  143. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('CreateANewAttendance'));
  144. }
  145. if ($action == 'attendance_edit') {
  146. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('Edit'));
  147. }
  148. if ($action == 'attendance_sheet_list' || $action == 'attendance_sheet_add') {
  149. $interbreadcrumb[] = array ('url' => '#', 'name' => $attendance_data['name']);
  150. }
  151. if ($action == 'calendar_list' || $action == 'calendar_edit' || $action == 'calendar_delete' || $action == 'calendar_all_delete') {
  152. $interbreadcrumb[] = array ('url' => 'index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance_id.$param_gradebook, 'name' => $attendance_data['name']);
  153. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('AttendanceCalendar'));
  154. }
  155. if ($action == 'calendar_add') {
  156. $interbreadcrumb[] = array ('url' => 'index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance_id.$param_gradebook, 'name' => $attendance_data['name']);
  157. $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('AddDateAndTime'));
  158. }
  159. // delete selected attendance
  160. if (isset($_POST['action']) && $_POST['action'] == 'attendance_delete_select') {
  161. $attendance_controller->attendance_delete($_POST['id']);
  162. }
  163. // distpacher actions to controller
  164. switch ($action) {
  165. case 'attendance_list' :
  166. $attendance_controller->attendance_list();
  167. break;
  168. case 'attendance_add' :
  169. $attendance_controller->attendance_add();
  170. break;
  171. case 'attendance_edit' :
  172. $attendance_controller->attendance_edit($attendance_id);
  173. break;
  174. case 'attendance_delete':
  175. $attendance_controller->attendance_delete($attendance_id);
  176. break;
  177. case 'attendance_sheet_list':
  178. $attendance_controller->attendance_sheet($action, $attendance_id, $student_id);
  179. break;
  180. case 'attendance_sheet_add' :
  181. $attendance_controller->attendance_sheet($action, $attendance_id);
  182. break;
  183. case 'calendar_list' :
  184. case 'calendar_add' :
  185. case 'calendar_edit' :
  186. case 'calendar_all_delete':
  187. case 'calendar_delete' :
  188. $attendance_controller->attendance_calendar($action, $attendance_id, $calendar_id);
  189. break;
  190. default :
  191. $attendance_controller->attendance_list();
  192. }
  193. ?>