123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * This file contains class used like controller, it should be included inside a dispatcher file (e.g: index.php)
- *
- * !!! WARNING !!! : ALL DATES IN THIS MODULE ARE STORED IN UTC ! DO NOT CONVERT DURING THE TRANSITION FROM CHAMILO 1.8.x TO 2.0
- *
- * @author Christian Fasanando <christian1827@gmail.com>
- * @package chamilo.attendance
- */
- /**
- * Controller script. Prepares the common background variables to give to the scripts corresponding to
- * the requested action
- * @package chamilo.attendance
- */
-
- class AttendanceController
- {
-
- /**
- * Constructor
- */
- public function __construct() {
- $this->toolname = 'attendance';
- $this->view = new View($this->toolname);
- }
-
- /**
- * It's used for listing attendace,
- * render to attendance_list view
- * @param boolean true for listing history (optional)
- * @param array message for showing by action['edit','add','delete'] (optional)
- */
- public function attendance_list($history=false,$messages=array()) {
-
- $attendance = new Attendance();
- $data = array();
-
- // render to the view
- $this->view->set_data($data);
- $this->view->set_layout('layout');
- $this->view->set_template('attendance_list');
- $this->view->render();
- }
-
- /**
- * It's used for adding attendace,
- * render to attendance_add or attendance_list view
- */
- public function attendance_add() {
-
- $attendance = new Attendance();
- $data = array();
-
- if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
- $check = Security::check_token();
- if ($check) {
- $attendance->set_name($_POST['title']);
- $attendance->set_description($_POST['description']);
- $attendance->set_attendance_qualify_title($_POST['attendance_qualify_title']);
- $attendance->set_attendance_weight($_POST['attendance_weight']);
- $link_to_gradebook = false;
- if ( isset($_POST['attendance_qualify_gradebook']) && $_POST['attendance_qualify_gradebook'] == 1 ) {
- $link_to_gradebook = true;
- }
- $last_id = $attendance->attendance_add($link_to_gradebook);
- Security::clear_token();
- }
-
- if ($last_id) {
- $this->attendance_sheet('calendar_list',$last_id);
- } else {
- $data['error_attendance_add'] = true;
- $this->view->set_data($data);
- $this->view->set_layout('layout');
- $this->view->set_template('attendance_add');
- $this->view->render();
- }
- } else {
- $this->view->set_data($data);
- $this->view->set_layout('layout');
- $this->view->set_template('attendance_add');
- $this->view->render();
- }
- }
-
- /**
- * It's used for editing attendace,
- * render to attendance_edit or attendance_list view
- * @param int attendance id
- */
- public function attendance_edit($attendance_id) {
- $attendance = new Attendance();
- $data = array();
- $attendance_id = intval($attendance_id);
- if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
- $check = Security::check_token();
- if ($check) {
- $attendance->set_name($_POST['title']);
- $attendance->set_description($_POST['description']);
- $attendance->set_attendance_qualify_title($_POST['attendance_qualify_title']);
- $attendance->set_attendance_weight($_POST['attendance_weight']);
-
- $link_to_gradebook = false;
- if ( isset($_POST['attendance_qualify_gradebook']) && $_POST['attendance_qualify_gradebook'] == 1 ) {
- $link_to_gradebook = true;
- }
- $affected_rows = $attendance->attendance_edit($attendance_id,$link_to_gradebook);
- Security::clear_token();
- }
-
-
-
- if ($affected_rows) {
- $data['message_edit'] = true;
- }
- $this->attendance_list();
- } else {
- // default values
- $attendance_data = $attendance->get_attendance_by_id($attendance_id);
- $data['attendance_id'] = $attendance_data['id'];
- $data['title'] = $attendance_data['name'];
- $data['description'] = $attendance_data['description'];
- $data['attendance_qualify_title'] = $attendance_data['attendance_qualify_title'];
- $data['attendance_weight'] = $attendance_data['attendance_weight'];
- $this->view->set_data($data);
- $this->view->set_layout('layout');
- $this->view->set_template('attendance_edit');
- $this->view->render();
- }
- }
-
- /**
- * It's used for delete attendace,
- * render to attendance_list view
- * @param int attendance id
- */
- public function attendance_delete($attendance_id) {
- $attendance = new Attendance();
- //$attendance_id = intval($attendance_id);
- if (!empty($attendance_id)) {
- $affected_rows = $attendance->attendance_delete($attendance_id);
- }
- if ($affected_rows) {
- $message['message_attendance_delete'] = true;
- }
- $this->attendance_list();
- }
-
- /**
- * It's used for controlling attendace sheet (list, add),
- * render to attendance_sheet view
- * @param string action
- * @param int attendance id
- */
- public function attendance_sheet($action, $attendance_id, $student_id = 0) {
- $attendance = new Attendance();
- $data = array();
- $data['attendance_id'] = $attendance_id;
- $data['users_in_course'] = $attendance->get_users_rel_course($attendance_id);
- $data['attendant_calendar'] = $attendance->get_attendance_calendar($attendance_id);
- if (api_is_allowed_to_edit(null, true)) {
- $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id);
- } else {
- if (!empty($student_id)) {
- $user_id = intval($student_id);
- } else {
- $user_id = api_get_user_id();
- }
- $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, $user_id);
- $data['faults'] = $attendance->get_faults_of_user($user_id, $attendance_id);
- $data['user_id'] = $user_id;
- }
-
- $data['next_attendance_calendar_id'] = $attendance->get_next_attendance_calendar_id($attendance_id);
-
- if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
- if (isset($_POST['hidden_input'])) {
- foreach ($_POST['hidden_input'] as $cal_id) {
- $users_present = array();
- if (isset($_POST['check_presence'][$cal_id])) {
- $users_present = $_POST['check_presence'][$cal_id];
- }
- $affected_rows = $attendance->attendance_sheet_add($cal_id,$users_present,$attendance_id);
- }
- }
- $data['users_in_course'] = $attendance->get_users_rel_course($attendance_id);
- $data['attendant_calendar'] = $attendance->get_attendance_calendar($attendance_id);
- $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id);
- $data['next_attendance_calendar_id'] = $attendance->get_next_attendance_calendar_id($attendance_id);
- }
-
- $this->view->set_data($data);
- $this->view->set_layout('layout');
- $this->view->set_template('attendance_sheet');
- $this->view->render();
- }
- /**
- * It's used for controlling attendace calendar (list, add, edit, delete),
- * render to attendance_calendar view
- * @param string action (optional, by default 'calendar_list')
- * @param int attendance id (optional)
- * @param int calendar id (optional)
- */
- public function attendance_calendar($action = 'calendar_list',$attendance_id = 0, $calendar_id = 0) {
- $attendance = new Attendance();
- $calendar_id = intval($calendar_id);
- $data = array();
- $data['attendance_id'] = $attendance_id;
- $attendance_id = intval($attendance_id);
- if ($action == 'calendar_add') {
- if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
- if (!isset($_POST['cancel'])) {
- $datetime = $attendance->build_datetime_from_array($_POST['date_time']);
- $datetimezone = api_get_utc_datetime($datetime);
- if (!empty($datetime)) {
- $attendance->set_date_time($datetimezone);
- $affected_rows = $attendance->attendant_calendar_add($attendance_id);
- } else {
- $data['error_date'] = true;
- }
- $action = 'calendar_list';
- } else {
- $action = 'calendar_list';
- }
- }
- } else if ($action == 'calendar_edit') {
- $data['calendar_id'] = $calendar_id;
- if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
- if (!isset($_POST['cancel'])) {
- $datetime = $attendance->build_datetime_from_array($_POST['date_time']);
- $datetimezone = api_get_utc_datetime($datetime);
- $attendance->set_date_time($datetimezone);
- $affected_rows = $attendance->attendant_calendar_edit($calendar_id, $attendance_id);
- $data['calendar_id'] = 0;
- $action = 'calendar_list';
- } else {
- $action = 'calendar_list';
- }
- }
- } else if ($action == 'calendar_delete') {
- $affected_rows = $attendance->attendance_calendar_delete($calendar_id, $attendance_id);
- $action = 'calendar_list';
- } else if ($action == 'calendar_all_delete') {
- $affected_rows = $attendance->attendance_calendar_delete(0, $attendance_id, true);
- $action = 'calendar_list';
- }
- $data['action'] = $action;
- $data['attendance_calendar'] = $attendance->get_attendance_calendar($attendance_id);
- // render to the view
- $this->view->set_data($data);
- $this->view->set_layout('layout');
- $this->view->set_template('attendance_calendar');
- $this->view->render();
- }
-
- }
- ?>
|