MDL-35510 theme_mymobile: RTL fixes for course and category names in style/jmobile11_...
[moodle.git] / course / editsection.php
blob549bd981a1e8126747bf9968feafad2e4bfba6af
1 <?php
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.
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/>.
18 /**
19 * Edit the introduction of a section
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
26 require_once("../config.php");
27 require_once("lib.php");
28 require_once($CFG->libdir.'/filelib.php');
29 require_once($CFG->libdir . '/gradelib.php');
30 require_once($CFG->libdir . '/completionlib.php');
31 require_once($CFG->libdir . '/conditionlib.php');
33 require_once('editsection_form.php');
35 $id = required_param('id',PARAM_INT); // Week/topic ID
36 $sectionreturn = optional_param('sr', 0, PARAM_INT);
38 $PAGE->set_url('/course/editsection.php', array('id'=>$id, 'sr'=> $sectionreturn));
40 $section = $DB->get_record('course_sections', array('id' => $id), '*', MUST_EXIST);
41 $course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST);
43 require_login($course);
44 $context = context_course::instance($course->id);
45 require_capability('moodle/course:update', $context);
47 $editoroptions = array('context'=>$context ,'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'noclean'=>true);
48 $section = file_prepare_standard_editor($section, 'summary', $editoroptions, $context, 'course', 'section', $section->id);
49 $section->usedefaultname = (is_null($section->name));
51 if (!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;
57 $section->conditionsfield = $sectioninfo->conditionsfield;
60 $mform = new editsection_form($PAGE->url, array('course' => $course, 'editoroptions' => $editoroptions,
61 'cs' => $section, 'showavailability' => $section->showavailability));
62 $mform->set_data($section); // set current value
64 $returnurl = course_get_url($course, $sectionreturn);
66 /// If data submitted, then process and store.
67 if ($mform->is_cancelled()){
68 redirect($returnurl);
70 } else if ($data = $mform->get_data()) {
71 if (empty($data->usedefaultname)) {
72 $section->name = $data->name;
73 } else {
74 $section->name = null;
76 $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course', 'section', $section->id);
77 $section->summary = $data->summary;
78 $section->summaryformat = $data->summaryformat;
79 if (!empty($CFG->enableavailability)) {
80 $section->availablefrom = $data->availablefrom;
81 $section->availableuntil = $data->availableuntil;
82 if (isset($data->groupingid)) {
83 $section->groupingid = $data->groupingid;
85 $section->showavailability = $data->showavailability;
87 $DB->update_record('course_sections', $section);
88 if (!empty($CFG->enableavailability)) {
89 // Update grade and completion conditions
90 condition_info_section::update_section_from_form($section, $data);
92 rebuild_course_cache($course->id);
94 add_to_log($course->id, "course", "editsection", "editsection.php?id=$section->id", "$section->section");
95 $PAGE->navigation->clear_cache();
96 redirect($returnurl);
99 $sectionname = get_section_name($course, $section);
100 $stredit = get_string('edita', '', " $sectionname");
101 $strsummaryof = get_string('summaryof', '', " $sectionname");
103 $PAGE->set_title($stredit);
104 $PAGE->set_heading($course->fullname);
105 $PAGE->navbar->add($stredit);
106 echo $OUTPUT->header();
108 echo $OUTPUT->heading($strsummaryof);
110 $mform->display();
111 echo $OUTPUT->footer();