MDL-35238 Unzip the downloaded package and redirect to the upgrade page
[moodle.git] / course / editsection.php
blobc75e3dc0ba4f439f370e6629ce6dcf15de1401b0
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Edit the section basic information and availability
21 * @copyright 1999 Martin Dougiamas http://dougiamas.com
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @package course
26 require_once("../config.php");
27 require_once("lib.php");
28 require_once($CFG->libdir . '/conditionlib.php');
30 $id = required_param('id', PARAM_INT); // course_sections.id
31 $sectionreturn = optional_param('sr', 0, PARAM_INT);
33 $PAGE->set_url('/course/editsection.php', array('id'=>$id, 'sr'=> $sectionreturn));
35 $section = $DB->get_record('course_sections', array('id' => $id), '*', MUST_EXIST);
36 $course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST);
37 $sectionnum = $section->section;
39 require_login($course);
40 $context = context_course::instance($course->id);
41 require_capability('moodle/course:update', $context);
43 // get section_info object with all availability options
44 $sectioninfo = get_fast_modinfo($course)->get_section_info($sectionnum);
46 $editoroptions = array('context'=>$context ,'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'noclean'=>true);
47 $mform = course_get_format($course->id)->editsection_form($PAGE->url,
48 array('cs' => $sectioninfo, 'editoroptions' => $editoroptions));
49 // set current value, make an editable copy of section_info object
50 // this will retrieve all format-specific options as well
51 $mform->set_data(convert_to_array($sectioninfo));
53 if ($mform->is_cancelled()){
54 // form cancelled, return to course
55 redirect(course_get_url($course, $section, array('sr' => $sectionreturn)));
56 } else if ($data = $mform->get_data()) {
57 // data submitted and validated, update and return to course
58 $DB->update_record('course_sections', $data);
59 rebuild_course_cache($course->id, true);
60 if (isset($data->section)) {
61 // usually edit form does not change relative section number but just in case
62 $sectionnum = $data->section;
64 if (!empty($CFG->enableavailability)) {
65 // Update grade and completion conditions
66 $sectioninfo = get_fast_modinfo($course)->get_section_info($sectionnum);
67 condition_info_section::update_section_from_form($sectioninfo, $data);
68 rebuild_course_cache($course->id, true);
70 course_get_format($course->id)->update_section_format_options($data);
72 add_to_log($course->id, "course", "editsection", "editsection.php?id=$id", "$sectionnum");
73 $PAGE->navigation->clear_cache();
74 redirect(course_get_url($course, $section, array('sr' => $sectionreturn)));
77 // the edit form is displayed for the first time or there was a validation
78 // error on the previous step. Display the edit form:
79 $sectionname = get_section_name($course, $sectionnum);
80 $stredit = get_string('edita', '', " $sectionname");
81 $strsummaryof = get_string('summaryof', '', " $sectionname");
83 $PAGE->set_title($stredit);
84 $PAGE->set_heading($course->fullname);
85 $PAGE->navbar->add($stredit);
86 echo $OUTPUT->header();
88 echo $OUTPUT->heading($strsummaryof);
90 $mform->display();
91 echo $OUTPUT->footer();