/** * This method is used for thematic advance control (update, insert or listing) * @param string Action * render to thematic_advance.php */ public function thematic_advance($action) { $courseInfo = api_get_course_info(); $thematic = new Thematic($courseInfo); $attendance = new Attendance(); $data = array(); // get data for attendance input select $attendance_list = $attendance->get_attendances_list(); $attendance_select = array(); $attendance_select[0] = get_lang('SelectAnAttendance'); foreach ($attendance_list as $attendance_id => $attendance_data) { $attendance_select[$attendance_id] = $attendance_data['name']; } $thematic_id = intval($_REQUEST['thematic_id']); $thematic_advance_id = intval($_REQUEST['thematic_advance_id']); $thematic_advance_data = array(); switch ($action) { case 'thematic_advance_delete': if (!empty($thematic_advance_id)) { if (api_is_allowed_to_edit(null, true)) { $affected_rows = $thematic->thematic_advance_destroy($thematic_advance_id); } $action = 'thematic_list'; header('Location: index.php'); exit; } break; case 'thematic_advance_list': if (!api_is_allowed_to_edit(null, true)) { echo ''; exit; } if ($_REQUEST['start_date_type'] == 1 && empty($_REQUEST['start_date_by_attendance']) || !empty($_REQUEST['duration_in_hours']) && !is_numeric($_REQUEST['duration_in_hours'])) { if ($_REQUEST['start_date_type'] == 1 && empty($_REQUEST['start_date_by_attendance'])) { $start_date_error = true; $data['start_date_error'] = $start_date_error; } if (!empty($_REQUEST['duration_in_hours']) && !is_numeric($_REQUEST['duration_in_hours'])) { $duration_error = true; $data['duration_error'] = $duration_error; } $data['action'] = $_REQUEST['action']; $data['thematic_id'] = $_REQUEST['thematic_id']; $data['attendance_select'] = $attendance_select; if (isset($_REQUEST['thematic_advance_id'])) { $data['thematic_advance_id'] = $_REQUEST['thematic_advance_id']; $thematic_advance_data = $thematic->get_thematic_advance_list($_REQUEST['thematic_advance_id']); $data['thematic_advance_data'] = $thematic_advance_data; } } else { if ($_REQUEST['thematic_advance_token'] == $_SESSION['thematic_advance_token'] && api_is_allowed_to_edit(null, true)) { $thematic_advance_id = $_REQUEST['thematic_advance_id']; $thematic_id = $_REQUEST['thematic_id']; $content = $_REQUEST['content']; $duration = $_REQUEST['duration_in_hours']; if (isset($_REQUEST['start_date_type']) && $_REQUEST['start_date_type'] == 2) { $start_date = $thematic->build_datetime_from_array($_REQUEST['custom_start_date']); $attendance_id = 0; } else { $start_date = $_REQUEST['start_date_by_attendance']; $attendance_id = $_REQUEST['attendance_select']; } $thematic->set_thematic_advance_attributes($thematic_advance_id, $thematic_id, $attendance_id, $content, $start_date, $duration); $affected_rows = $thematic->thematic_advance_save(); if ($affected_rows) { // get last done thematic advance before move thematic list $last_done_thematic_advance = $thematic->get_last_done_thematic_advance(); // update done advances with de current thematic list if (!empty($last_done_thematic_advance)) { $update_done_advances = $thematic->update_done_thematic_advances($last_done_thematic_advance); } } } } break; default: $thematic_advance_data = $thematic->get_thematic_advance_list($thematic_advance_id); break; } // get calendar select by attendance id $calendar_select = array(); if (!empty($thematic_advance_data)) { if (!empty($thematic_advance_data['attendance_id'])) { $attendance_calendar = $attendance->get_attendance_calendar($thematic_advance_data['attendance_id']); if (!empty($attendance_calendar)) { foreach ($attendance_calendar as $calendar) { $calendar_select[$calendar['date_time']] = $calendar['date_time']; } } } } $data['action'] = $action; $data['thematic_id'] = $thematic_id; $data['thematic_advance_id'] = $thematic_advance_id; $data['attendance_select'] = $attendance_select; $data['thematic_advance_data'] = $thematic_advance_data; $data['calendar_select'] = $calendar_select; // render to the view $this->view->set_data($data); $this->view->set_layout('layout'); $this->view->set_template('thematic_advance'); $this->view->render(); }