weekly release 2.6dev
[moodle.git] / course / editsection.php
CommitLineData
d9cb06dc 1<?php
578fdd0a 2
d9cb06dc 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.
14//
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/>.
578fdd0a 17
d9cb06dc 18/**
fc79ede5 19 * Edit the section basic information and availability
d9cb06dc 20 *
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
24 */
578fdd0a 25
d9cb06dc 26require_once("../config.php");
27require_once("lib.php");
ce4dfd27 28require_once($CFG->libdir . '/conditionlib.php');
29
fc79ede5 30$id = required_param('id', PARAM_INT); // course_sections.id
b8514b6a 31$sectionreturn = optional_param('sr', 0, PARAM_INT);
578fdd0a 32
b8514b6a 33$PAGE->set_url('/course/editsection.php', array('id'=>$id, 'sr'=> $sectionreturn));
2fdcf5e3 34
09eb2151
DM
35$section = $DB->get_record('course_sections', array('id' => $id), '*', MUST_EXIST);
36$course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST);
fc79ede5 37$sectionnum = $section->section;
d9cb06dc 38
39require_login($course);
9a5e297b 40$context = context_course::instance($course->id);
d9cb06dc 41require_capability('moodle/course:update', $context);
42
fc79ede5
MG
43// get section_info object with all availability options
44$sectioninfo = get_fast_modinfo($course)->get_section_info($sectionnum);
578fdd0a 45
fc79ede5
MG
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));
a5a38c94 52
d9cb06dc 53if ($mform->is_cancelled()){
fc79ede5
MG
54 // form cancelled, return to course
55 redirect(course_get_url($course, $section, array('sr' => $sectionreturn)));
d9cb06dc 56} else if ($data = $mform->get_data()) {
fc79ede5
MG
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;
ce4dfd27 63 }
ce4dfd27 64 if (!empty($CFG->enableavailability)) {
65 // Update grade and completion conditions
fc79ede5
MG
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);
ce4dfd27 69 }
fc79ede5 70 course_get_format($course->id)->update_section_format_options($data);
ce4dfd27 71
fc79ede5 72 add_to_log($course->id, "course", "editsection", "editsection.php?id=$id", "$sectionnum");
0a5ece3d 73 $PAGE->navigation->clear_cache();
fc79ede5 74 redirect(course_get_url($course, $section, array('sr' => $sectionreturn)));
d9cb06dc 75}
578fdd0a 76
fc79ede5
MG
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);
7487c856
SH
80$stredit = get_string('edita', '', " $sectionname");
81$strsummaryof = get_string('summaryof', '', " $sectionname");
d9cb06dc 82
83$PAGE->set_title($stredit);
e34a326f 84$PAGE->set_heading($course->fullname);
d9cb06dc 85$PAGE->navbar->add($stredit);
d9cb06dc 86echo $OUTPUT->header();
578fdd0a 87
b54a0547 88echo $OUTPUT->heading($strsummaryof);
a19a06d0 89
d9cb06dc 90$mform->display();
0831fd78 91echo $OUTPUT->footer();