MDL-20487 - improve accessibility issue for survey page layout and string.
[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
578fdd0a 32
a6855934 33$PAGE->set_url('/course/editsection.php', array('id'=>$id));
2fdcf5e3 34
d9cb06dc 35if (! $section = $DB->get_record("course_sections", array("id"=>$id))) {
36 print_error("sectionnotexist");
37}
38
39if (! $course = $DB->get_record("course", array("id"=>$section->course))) {
40 print_error("invalidcourseid");
41}
42
43require_login($course);
44$context = get_context_instance(CONTEXT_COURSE, $course->id);
45require_capability('moodle/course:update', $context);
46
47$draftitemid = file_get_submitted_draft_itemid('summary');
48$currenttext = file_prepare_draft_area($draftitemid, $context->id, 'course_section', $section->id, array('subdirs'=>true), $section->summary);
49
50$mform = new editsection_form(null, $course);
51$data = array('id'=>$section->id, 'summary'=>array('text'=>$currenttext, 'format'=>FORMAT_HTML, 'itemid'=>$draftitemid));
52$mform->set_data($data); // set defaults
578fdd0a 53
54/// If data submitted, then process and store.
d9cb06dc 55if ($mform->is_cancelled()){
56 redirect($CFG->wwwroot.'/course/view.php?id='.$course->id);
578fdd0a 57
d9cb06dc 58} else if ($data = $mform->get_data()) {
578fdd0a 59
d9cb06dc 60 $text = file_save_draft_area_files($data->summary['itemid'], $context->id, 'course_section', $section->id, array('subdirs'=>true), $data->summary['text']);
61 $DB->set_field("course_sections", "summary", $text, array("id"=>$section->id));
62 add_to_log($course->id, "course", "editsection", "editsection.php?id=$section->id", "$section->section");
63 redirect("view.php?id=$course->id");
64}
578fdd0a 65
116ae3b2 66/// Inelegant hack for bug 3408
d9cb06dc 67if ($course->format == 'site') {
68 $sectionname = get_string('site');
0831fd78 69 $stredit = get_string('edita', '', " $sectionname");
d9cb06dc 70 $strsummaryof = get_string('summaryof', '', " $sectionname");
71} else {
72 $sectionname = get_section_name($course->format);
0831fd78 73 $stredit = get_string('edita', '', " $sectionname $section->section");
d9cb06dc 74 $strsummaryof = get_string('summaryof', '', " $sectionname $section->section");
75}
76
77$PAGE->set_title($stredit);
78$PAGE->navbar->add($stredit);
79$PAGE->set_focuscontrol('theform.summary');
80echo $OUTPUT->header();
578fdd0a 81
4bcc5118 82echo $OUTPUT->heading_with_help($strsummaryof, 'summaries');
a19a06d0 83
d9cb06dc 84$mform->display();
0831fd78 85echo $OUTPUT->footer();