Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * This page handles deleting lesson overrides
  19   *
  20   * @package    mod_lesson
  21   * @copyright  2015 Jean-Michel vedrine
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  
  26  require_once(__DIR__ . '/../../config.php');
  27  require_once($CFG->dirroot.'/mod/lesson/lib.php');
  28  require_once($CFG->dirroot.'/mod/lesson/locallib.php');
  29  require_once($CFG->dirroot.'/mod/lesson/override_form.php');
  30  
  31  $overrideid = required_param('id', PARAM_INT);
  32  $confirm = optional_param('confirm', false, PARAM_BOOL);
  33  
  34  if (! $override = $DB->get_record('lesson_overrides', array('id' => $overrideid))) {
  35      print_error('invalidoverrideid', 'lesson');
  36  }
  37  
  38  $lesson = new lesson($DB->get_record('lesson', array('id' => $override->lessonid), '*', MUST_EXIST));
  39  
  40  if (! $cm = get_coursemodule_from_instance("lesson", $lesson->id, $lesson->course)) {
  41      print_error('invalidcoursemodule');
  42  }
  43  $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
  44  
  45  $context = context_module::instance($cm->id);
  46  
  47  require_login($course, false, $cm);
  48  
  49  // Check the user has the required capabilities to modify an override.
  50  require_capability('mod/lesson:manageoverrides', $context);
  51  
  52  if ($override->groupid) {
  53      if (!groups_group_visible($override->groupid, $course, $cm)) {
  54          print_error('invalidoverrideid', 'lesson');
  55      }
  56  } else {
  57      if (!groups_user_groups_visible($course, $override->userid, $cm)) {
  58          print_error('invalidoverrideid', 'lesson');
  59      }
  60  }
  61  
  62  $url = new moodle_url('/mod/lesson/overridedelete.php', array('id' => $override->id));
  63  $confirmurl = new moodle_url($url, array('id' => $override->id, 'confirm' => 1));
  64  $cancelurl = new moodle_url('/mod/lesson/overrides.php', array('cmid' => $cm->id));
  65  
  66  if (!empty($override->userid)) {
  67      $cancelurl->param('mode', 'user');
  68  }
  69  
  70  // If confirm is set (PARAM_BOOL) then we have confirmation of intention to delete.
  71  if ($confirm) {
  72      require_sesskey();
  73  
  74      $lesson->delete_override($override->id);
  75  
  76      redirect($cancelurl);
  77  }
  78  
  79  // Prepare the page to show the confirmation form.
  80  $stroverride = get_string('override', 'lesson');
  81  $title = get_string('deletecheck', null, $stroverride);
  82  
  83  $PAGE->set_url($url);
  84  $PAGE->set_pagelayout('admin');
  85  $PAGE->navbar->add($title);
  86  $PAGE->set_title($title);
  87  $PAGE->set_heading($course->fullname);
  88  
  89  echo $OUTPUT->header();
  90  echo $OUTPUT->heading(format_string($lesson->name, true, array('context' => $context)));
  91  
  92  if ($override->groupid) {
  93      $group = $DB->get_record('groups', array('id' => $override->groupid), 'id, name');
  94      $confirmstr = get_string("overridedeletegroupsure", "lesson", $group->name);
  95  } else {
  96      $namefields = get_all_user_name_fields(true);
  97      $user = $DB->get_record('user', array('id' => $override->userid),
  98              'id, ' . $namefields);
  99      $confirmstr = get_string("overridedeleteusersure", "lesson", fullname($user));
 100  }
 101  
 102  echo $OUTPUT->confirm($confirmstr, $confirmurl, $cancelurl);
 103  
 104  echo $OUTPUT->footer();