Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

   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 assigment overrides
  19   *
  20   * @package    mod_assign
  21   * @copyright  2016 Ilya Tregubov
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  
  26  require_once(dirname(__FILE__) . '/../../config.php');
  27  require_once($CFG->dirroot.'/mod/assign/lib.php');
  28  require_once($CFG->dirroot.'/mod/assign/locallib.php');
  29  require_once($CFG->dirroot.'/mod/assign/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('assign_overrides', array('id' => $overrideid))) {
  35      print_error('invalidoverrideid', 'assign');
  36  }
  37  
  38  list($course, $cm) = get_course_and_cm_from_instance($override->assignid, 'assign');
  39  $context = context_module::instance($cm->id);
  40  $assign = new assign($context, null, null);
  41  
  42  require_login($course, false, $cm);
  43  
  44  // Check the user has the required capabilities to modify an override.
  45  require_capability('mod/assign:manageoverrides', $context);
  46  
  47  if ($override->groupid) {
  48      if (!groups_group_visible($override->groupid, $course, $cm)) {
  49          print_error('invalidoverrideid', 'assign');
  50      }
  51  } else {
  52      if (!groups_user_groups_visible($course, $override->userid, $cm)) {
  53          print_error('invalidoverrideid', 'assign');
  54      }
  55  }
  56  
  57  $url = new moodle_url('/mod/assign/overridedelete.php', array('id' => $override->id));
  58  $confirmurl = new moodle_url($url, array('id' => $override->id, 'confirm' => 1));
  59  $cancelurl = new moodle_url('/mod/assign/overrides.php', array('cmid' => $cm->id));
  60  
  61  if (!empty($override->userid)) {
  62      $cancelurl->param('mode', 'user');
  63  }
  64  
  65  // If confirm is set (PARAM_BOOL) then we have confirmation of intention to delete.
  66  if ($confirm) {
  67      require_sesskey();
  68  
  69      $assign->delete_override($override->id);
  70  
  71      reorder_group_overrides($assign->get_instance()->id);
  72  
  73      redirect($cancelurl);
  74  }
  75  
  76  // Prepare the page to show the confirmation form.
  77  $stroverride = get_string('override', 'assign');
  78  $title = get_string('deletecheck', null, $stroverride);
  79  
  80  $PAGE->set_url($url);
  81  $PAGE->set_pagelayout('admin');
  82  $PAGE->navbar->add($title);
  83  $PAGE->set_title($title);
  84  $PAGE->set_heading($course->fullname);
  85  
  86  echo $OUTPUT->header();
  87  echo $OUTPUT->heading(format_string($assign->get_instance()->name, true, array('context' => $context)));
  88  
  89  if ($override->groupid) {
  90      $group = $DB->get_record('groups', array('id' => $override->groupid), 'id, name');
  91      $confirmstr = get_string("overridedeletegroupsure", "assign", $group->name);
  92  } else {
  93      $userfieldsapi = \core_user\fields::for_name();
  94      $namefields = $userfieldsapi->get_sql('', false, '', '', false)->selects;
  95      $user = $DB->get_record('user', array('id' => $override->userid),
  96              'id, ' . $namefields);
  97      $confirmstr = get_string("overridedeleteusersure", "assign", fullname($user));
  98  }
  99  
 100  echo $OUTPUT->confirm($confirmstr, $confirmurl, $cancelurl);
 101  
 102  echo $OUTPUT->footer();