Search moodle.org's
Developer Documentation


  • Bug fixes for general core bugs in 2.8.x ended 9 November 2015 (12 months).
  • Bug fixes for security issues in 2.8.x ended 9 May 2016 (18 months).
  • minimum PHP 5.4.4 (always use latest PHP 5.4.x or 5.5.x on Windows - http://windows.php.net/download/), PHP 7 is NOT supported
  • Differences Between: [Versions 28 and 29] [Versions 28 and 30] [Versions 28 and 31] [Versions 28 and 32] [Versions 28 and 33] [Versions 28 and 34] [Versions 28 and 35] [Versions 28 and 36] [Versions 28 and 37]

       1  <?php
       2  
       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/>.
      17  
      18  /**
      19   * Edit the section basic information and availability
      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   */
      25  
      26  require_once("../config.php");
      27  require_once ("lib.php");
      28  require_once($CFG->libdir . '/formslib.php');
      29  require_once($CFG->libdir . '/conditionlib.php');
      30  
      31  $id = required_param('id', PARAM_INT);    // course_sections.id
      32  $sectionreturn = optional_param('sr', 0, PARAM_INT);
      33  
      34  $PAGE->set_url('/course/editsection.php', array('id'=>$id, 'sr'=> $sectionreturn));
      35  
      36  $section = $DB->get_record('course_sections', array('id' => $id), '*', MUST_EXIST);
      37  $course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST);
      38  $sectionnum = $section->section;
      39  
      40  require_login($course);
      41  $context = context_course::instance($course->id);
      42  require_capability('moodle/course:update', $context);
      43  
      44  // Get section_info object with all availability options.
      45  $sectioninfo = get_fast_modinfo($course)->get_section_info($sectionnum);
      46  
      47  $editoroptions = array('context'=>$context ,'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'noclean'=>true);
      48  $mform = course_get_format($course->id)->editsection_form($PAGE->url,
      49          array('cs' => $sectioninfo, 'editoroptions' => $editoroptions));
      50  // set current value, make an editable copy of section_info object
      51  // this will retrieve all format-specific options as well
      52  $initialdata = convert_to_array($sectioninfo);
      53  if (!empty($CFG->enableavailability)) {
      54      $initialdata['availabilityconditionsjson'] = $sectioninfo->availability;
      55  }
      56  $mform->set_data($initialdata);
      57  
      58  if ($mform->is_cancelled()){
      59      // Form cancelled, return to course.
      60      redirect(course_get_url($course, $section, array('sr' => $sectionreturn)));
      61  } else if ($data = $mform->get_data()) {
      62      // Data submitted and validated, update and return to course.
      63  
      64      // For consistency, we set the availability field to 'null' if it is empty.
      65      if (!empty($CFG->enableavailability)) {
      66          // Renamed field.
      67          $data->availability = $data->availabilityconditionsjson;
      68          unset($data->availabilityconditionsjson);
      69          if ($data->availability === '') {
      70              $data->availability = null;
      71          }
      72      }
      73      $DB->update_record('course_sections', $data);
      74      rebuild_course_cache($course->id, true);
      75      if (isset($data->section)) {
      76          // Usually edit form does not change relative section number but just in case.
      77          $sectionnum = $data->section;
      78      }
      79      course_get_format($course->id)->update_section_format_options($data);
      80  
      81      // Set section info, as this might not be present in form_data.
      82      if (!isset($data->section))  {
      83          $data->section = $sectionnum;
      84      }
      85      // Trigger an event for course section update.
      86      $event = \core\event\course_section_updated::create(
      87              array(
      88                  'objectid' => $data->id,
      89                  'courseid' => $course->id,
      90                  'context' => $context,
      91                  'other' => array('sectionnum' => $data->section)
      92              )
      93          );
      94      $event->trigger();
      95  
      96      $PAGE->navigation->clear_cache();
      97      redirect(course_get_url($course, $section, array('sr' => $sectionreturn)));
      98  }
      99  
     100  // The edit form is displayed for the first time or if there was validation error on the previous step.
     101  $sectionname  = get_section_name($course, $sectionnum);
     102  $stredit      = get_string('edita', '', " $sectionname");
     103  $strsummaryof = get_string('summaryof', '', " $sectionname");
     104  
     105  $PAGE->set_title($stredit);
     106  $PAGE->set_heading($course->fullname);
     107  $PAGE->navbar->add($stredit);
     108  echo $OUTPUT->header();
     109  
     110  echo $OUTPUT->heading($strsummaryof);
     111  
     112  $mform->display();
     113  echo $OUTPUT->footer();
    

    Search This Site: