/** * This method is used for thematic plan control (update, insert or listing) * @param string Action * render to thematic_plan.php */ public function thematic_plan($action) { $courseInfo = api_get_course_info(); $thematic = new Thematic($courseInfo); $data = array(); $error = false; if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { if (isset($_POST['action']) && ($_POST['action'] == 'thematic_plan_add' || $_POST['action'] == 'thematic_plan_edit')) { if (isset($_POST['title'])) { if ($_POST['thematic_plan_token'] == $_SESSION['thematic_plan_token']) { if (api_is_allowed_to_edit(null, true)) { $title_list = $_REQUEST['title']; $description_list = $_REQUEST['description']; $description_type = $_REQUEST['description_type']; $delete_list = $_REQUEST['delete']; foreach ($title_list as $id => $title) { $thematic_plan_id = $id; if (!$thematic->get_thematic_data_by_id($id)) { $thematic_plan_id = null; } $thematic->set_thematic_plan_attributes($_REQUEST['thematic_id'], $title, $description_list[$id], $description_type[$id], $thematic_plan_id); if (isset($delete_list[$id]) && !empty($delete_list[$id])) { $thematic->thematic_plan_delete(); } else { $affected_rows = $thematic->thematic_plan_save(); } } unset($_SESSION['thematic_plan_token']); $data['message'] = 'ok'; } $data['action'] = 'thematic_plan_list'; } } else { $error = true; $action = $_POST['action']; $data['error'] = $error; $data['thematic_plan_data'] = $thematic->get_thematic_plan_data($_POST['thematic_id'], $_POST['description_type']); $data['thematic_id'] = $_POST['thematic_id']; $data['description_type'] = $_POST['description_type']; $data['action'] = $action; $data['default_thematic_plan_title'] = $thematic->get_default_thematic_plan_title(); $data['default_thematic_plan_icon'] = $thematic->get_default_thematic_plan_icon(); $data['default_thematic_plan_question'] = $thematic->get_default_question(); $data['next_description_type'] = $thematic->get_next_description_type($_POST['thematic_id']); // render to the view $this->view->set_data($data); $this->view->set_layout('layout'); $this->view->set_template('thematic_plan'); $this->view->render(); } } } $thematic_id = intval($_GET['thematic_id']); if ($action == 'thematic_plan_list') { $data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id); } $description_type = intval($_GET['description_type']); if (!empty($thematic_id) && !empty($description_type)) { if ($action == 'thematic_plan_delete') { if (api_is_allowed_to_edit(null, true)) { $affected_rows = $thematic->thematic_plan_destroy($thematic_id, $description_type); } $data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id); $action = 'thematic_plan_list'; } else { $data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id, $description_type); } $data['thematic_id'] = $thematic_id; $data['description_type'] = $description_type; } else { if (!empty($thematic_id) && $action == 'thematic_plan_list') { $data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id); $data['thematic_id'] = $thematic_id; } } $data['thematic_id'] = $thematic_id; $data['action'] = $action; $data['default_thematic_plan_title'] = $thematic->get_default_thematic_plan_title(); $data['default_thematic_plan_icon'] = $thematic->get_default_thematic_plan_icon(); $data['next_description_type'] = $thematic->get_next_description_type($thematic_id); $data['default_thematic_plan_question'] = $thematic->get_default_question(); $data['thematic_data'] = $thematic->get_thematic_list($thematic_id); //render to the view $this->view->set_data($data); $this->view->set_layout('layout'); $this->view->set_template('thematic_plan'); $this->view->render(); exit; }