3 // This file is part of Moodle - http://moodle.org/
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.
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/>.
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
26 require_once("../config.php");
27 require_once("lib.php");
28 require_once($CFG->libdir
. '/formslib.php');
29 require_once($CFG->libdir
. '/conditionlib.php');
31 $id = required_param('id', PARAM_INT
); // course_sections.id
32 $sectionreturn = optional_param('sr', 0, PARAM_INT
);
34 $PAGE->set_url('/course/editsection.php', array('id'=>$id, 'sr'=> $sectionreturn));
36 $section = $DB->get_record('course_sections', array('id' => $id), '*', MUST_EXIST
);
37 $course = $DB->get_record('course', array('id' => $section->course
), '*', MUST_EXIST
);
38 $sectionnum = $section->section
;
40 require_login($course);
41 $context = context_course
::instance($course->id
);
42 require_capability('moodle/course:update', $context);
44 // Get section_info object with all availability options.
45 $sectioninfo = get_fast_modinfo($course)->get_section_info($sectionnum);
47 $editoroptions = array('context'=>$context ,'maxfiles' => EDITOR_UNLIMITED_FILES
, 'maxbytes'=>$CFG->maxbytes
, 'trusttext'=>false, 'noclean'=>true);
48 $mform = course_get_format($course->id
)->editsection_form($PAGE->url
,
49 array('cs' => $sectioninfo, 'editoroptions' => $editoroptions));
50 // set current value, make an editable copy of section_info object
51 // this will retrieve all format-specific options as well
52 $mform->set_data(convert_to_array($sectioninfo));
54 if ($mform->is_cancelled()){
55 // Form cancelled, return to course.
56 redirect(course_get_url($course, $section, array('sr' => $sectionreturn)));
57 } else if ($data = $mform->get_data()) {
58 // Data submitted and validated, update and return to course.
59 $DB->update_record('course_sections', $data);
60 rebuild_course_cache($course->id
, true);
61 if (isset($data->section
)) {
62 // Usually edit form does not change relative section number but just in case.
63 $sectionnum = $data->section
;
65 if (!empty($CFG->enableavailability
)) {
66 // Update grade and completion conditions.
67 $sectioninfo = get_fast_modinfo($course)->get_section_info($sectionnum);
68 condition_info_section
::update_section_from_form($sectioninfo, $data);
69 rebuild_course_cache($course->id
, true);
71 course_get_format($course->id
)->update_section_format_options($data);
73 // Set section info, as this might not be present in form_data.
74 if (!isset($data->section
)) {
75 $data->section
= $sectionnum;
77 // Trigger an event for course section update.
78 $event = \core\event\course_section_updated
::create(
80 'objectid' => $data->id
,
81 'courseid' => $course->id
,
82 'context' => $context,
83 'other' => array('sectionnum' => $data->section
)
88 $PAGE->navigation
->clear_cache();
89 redirect(course_get_url($course, $section, array('sr' => $sectionreturn)));
92 // The edit form is displayed for the first time or if there was validation error on the previous step.
93 $sectionname = get_section_name($course, $sectionnum);
94 $stredit = get_string('edita', '', " $sectionname");
95 $strsummaryof = get_string('summaryof', '', " $sectionname");
97 $PAGE->set_title($stredit);
98 $PAGE->set_heading($course->fullname
);
99 $PAGE->navbar
->add($stredit);
100 echo $OUTPUT->header();
102 echo $OUTPUT->heading($strsummaryof);
105 echo $OUTPUT->footer();