MDL-24419 (3): Add new parameter to format_float for shorter display
[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');
29require_once('editsection_form.php');
578fdd0a 30
d9cb06dc 31$id = required_param('id',PARAM_INT); // Week/topic ID
a5a38c94 32$sectionreturn = optional_param('sectionreturn', 0, PARAM_BOOL);
578fdd0a 33
a5a38c94 34$PAGE->set_url('/course/editsection.php', array('id'=>$id, 'sectionreturn'=> $sectionreturn));
2fdcf5e3 35
09eb2151
DM
36$section = $DB->get_record('course_sections', array('id' => $id), '*', MUST_EXIST);
37$course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST);
d9cb06dc 38
39require_login($course);
40$context = get_context_instance(CONTEXT_COURSE, $course->id);
41require_capability('moodle/course:update', $context);
42
ef106e5b 43$editoroptions = array('context'=>$context ,'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'noclean'=>true);
64f93798 44$section = file_prepare_standard_editor($section, 'summary', $editoroptions, $context, 'course', 'section', $section->id);
e34a326f 45$section->usedefaultname = (is_null($section->name));
a5a38c94 46$mform = new editsection_form($PAGE->url, array('course'=>$course, 'editoroptions'=>$editoroptions));
09eb2151 47$mform->set_data($section); // set current value
578fdd0a 48
a5a38c94
DP
49if ($sectionreturn) {
50 $returnurl = course_get_url($course, $section->section);
51} else {
52 $returnurl = course_get_url($course);
53}
54
578fdd0a 55/// If data submitted, then process and store.
d9cb06dc 56if ($mform->is_cancelled()){
a5a38c94 57 redirect($returnurl);
578fdd0a 58
d9cb06dc 59} else if ($data = $mform->get_data()) {
0f4ab67d
SH
60 if (empty($data->usedefaultname)) {
61 $section->name = $data->name;
62 } else {
63 $section->name = null;
64 }
64f93798 65 $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course', 'section', $section->id);
09eb2151
DM
66 $section->summary = $data->summary;
67 $section->summaryformat = $data->summaryformat;
0f4ab67d 68 $DB->update_record('course_sections', $section);
d9cb06dc 69 add_to_log($course->id, "course", "editsection", "editsection.php?id=$section->id", "$section->section");
0a5ece3d 70 $PAGE->navigation->clear_cache();
a5a38c94 71 redirect($returnurl);
d9cb06dc 72}
578fdd0a 73
7487c856
SH
74$sectionname = get_section_name($course, $section);
75$stredit = get_string('edita', '', " $sectionname");
76$strsummaryof = get_string('summaryof', '', " $sectionname");
d9cb06dc 77
78$PAGE->set_title($stredit);
e34a326f 79$PAGE->set_heading($course->fullname);
d9cb06dc 80$PAGE->navbar->add($stredit);
d9cb06dc 81echo $OUTPUT->header();
578fdd0a 82
b54a0547 83echo $OUTPUT->heading($strsummaryof);
a19a06d0 84
d9cb06dc 85$mform->display();
0831fd78 86echo $OUTPUT->footer();