MDL-35768 create table course_format_options, increase length of course.format field
[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/**
19 * Edit the introduction of a section
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");
28require_once($CFG->libdir.'/filelib.php');
ce4dfd27 29require_once($CFG->libdir . '/gradelib.php');
30require_once($CFG->libdir . '/completionlib.php');
31require_once($CFG->libdir . '/conditionlib.php');
32
d9cb06dc 33require_once('editsection_form.php');
578fdd0a 34
d9cb06dc 35$id = required_param('id',PARAM_INT); // Week/topic ID
b8514b6a 36$sectionreturn = optional_param('sr', 0, PARAM_INT);
578fdd0a 37
b8514b6a 38$PAGE->set_url('/course/editsection.php', array('id'=>$id, 'sr'=> $sectionreturn));
2fdcf5e3 39
09eb2151
DM
40$section = $DB->get_record('course_sections', array('id' => $id), '*', MUST_EXIST);
41$course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST);
d9cb06dc 42
43require_login($course);
9a5e297b 44$context = context_course::instance($course->id);
d9cb06dc 45require_capability('moodle/course:update', $context);
46
ef106e5b 47$editoroptions = array('context'=>$context ,'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'noclean'=>true);
64f93798 48$section = file_prepare_standard_editor($section, 'summary', $editoroptions, $context, 'course', 'section', $section->id);
e34a326f 49$section->usedefaultname = (is_null($section->name));
ce4dfd27 50
51if (!empty($CFG->enableavailability)) {
52 // Get section availability conditions from sectioncache.
53 $modinfo = get_fast_modinfo($course);
54 $sectioninfo = $modinfo->get_section_info($section->section);
55 $section->conditionsgrade = $sectioninfo->conditionsgrade;
56 $section->conditionscompletion = $sectioninfo->conditionscompletion;
e01fbcf7 57 $section->conditionsfield = $sectioninfo->conditionsfield;
ce4dfd27 58}
59
60$mform = new editsection_form($PAGE->url, array('course' => $course, 'editoroptions' => $editoroptions,
61 'cs' => $section, 'showavailability' => $section->showavailability));
09eb2151 62$mform->set_data($section); // set current value
578fdd0a 63
b8514b6a 64$returnurl = course_get_url($course, $sectionreturn);
a5a38c94 65
578fdd0a 66/// If data submitted, then process and store.
d9cb06dc 67if ($mform->is_cancelled()){
a5a38c94 68 redirect($returnurl);
578fdd0a 69
d9cb06dc 70} else if ($data = $mform->get_data()) {
0f4ab67d
SH
71 if (empty($data->usedefaultname)) {
72 $section->name = $data->name;
73 } else {
74 $section->name = null;
75 }
64f93798 76 $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course', 'section', $section->id);
09eb2151
DM
77 $section->summary = $data->summary;
78 $section->summaryformat = $data->summaryformat;
ce4dfd27 79 if (!empty($CFG->enableavailability)) {
80 $section->availablefrom = $data->availablefrom;
81 $section->availableuntil = $data->availableuntil;
b61670c7 82 if (isset($data->groupingid)) {
ce4dfd27 83 $section->groupingid = $data->groupingid;
84 }
85 $section->showavailability = $data->showavailability;
86 }
0f4ab67d 87 $DB->update_record('course_sections', $section);
ce4dfd27 88 if (!empty($CFG->enableavailability)) {
89 // Update grade and completion conditions
90 condition_info_section::update_section_from_form($section, $data);
91 }
92 rebuild_course_cache($course->id);
93
d9cb06dc 94 add_to_log($course->id, "course", "editsection", "editsection.php?id=$section->id", "$section->section");
0a5ece3d 95 $PAGE->navigation->clear_cache();
a5a38c94 96 redirect($returnurl);
d9cb06dc 97}
578fdd0a 98
7487c856
SH
99$sectionname = get_section_name($course, $section);
100$stredit = get_string('edita', '', " $sectionname");
101$strsummaryof = get_string('summaryof', '', " $sectionname");
d9cb06dc 102
103$PAGE->set_title($stredit);
e34a326f 104$PAGE->set_heading($course->fullname);
d9cb06dc 105$PAGE->navbar->add($stredit);
d9cb06dc 106echo $OUTPUT->header();
578fdd0a 107
b54a0547 108echo $OUTPUT->heading($strsummaryof);
a19a06d0 109
d9cb06dc 110$mform->display();
0831fd78 111echo $OUTPUT->footer();