Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
/admin/ -> lock.php (source)
   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 file is used to display a categories sub categories, external pages, and settings.
  19   *
  20   * @package    admin
  21   * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once('../config.php');
  26  require_once("{$CFG->libdir}/adminlib.php");
  27  
  28  $contextid = required_param('id', PARAM_INT);
  29  $confirm = optional_param('confirm', null, PARAM_INT);
  30  $returnurl = optional_param('returnurl', null, PARAM_LOCALURL);
  31  
  32  $PAGE->set_url('/admin/lock.php', ['id' => $contextid]);
  33  
  34  list($context, $course, $cm) = get_context_info_array($contextid);
  35  
  36  $parentcontext = $context->get_parent_context();
  37  if ($parentcontext && !empty($parentcontext->locked)) {
  38      // Can't make changes to a context whose parent is locked.
  39      throw new \coding_exception('Not sure how you got here');
  40  }
  41  
  42  if ($course) {
  43      $isfrontpage = ($course->id == SITEID);
  44  } else {
  45      $isfrontpage = false;
  46      $course = $SITE;
  47  }
  48  
  49  require_login($course, false, $cm);
  50  require_capability('moodle/site:managecontextlocks', $context);
  51  
  52  $PAGE->set_pagelayout('admin');
  53  $PAGE->navigation->clear_cache();
  54  
  55  $a = (object) [
  56      'contextname' => $context->get_context_name(),
  57  ];
  58  
  59  if (null !== $confirm && confirm_sesskey()) {
  60      $context->set_locked(!empty($confirm));
  61  
  62      if ($context->locked) {
  63          $lockmessage = get_string('managecontextlocklocked', 'admin', $a);
  64      } else {
  65          $lockmessage = get_string('managecontextlockunlocked', 'admin', $a);
  66      }
  67  
  68      if (empty($returnurl)) {
  69          $returnurl = $context->get_url();
  70      } else {
  71          $returnurl = new moodle_url($returnurl);
  72      }
  73      redirect($returnurl, $lockmessage);
  74  }
  75  
  76  $heading = get_string('managecontextlock', 'admin');
  77  $PAGE->set_title($heading);
  78  $PAGE->set_heading($heading);
  79  
  80  echo $OUTPUT->header();
  81  
  82  if ($context->locked) {
  83      $confirmstring = get_string('confirmcontextunlock', 'admin', $a);
  84      $target = 0;
  85  } else {
  86      $confirmstring = get_string('confirmcontextlock', 'admin', $a);
  87      $target = 1;
  88  }
  89  
  90  $confirmurl = new \moodle_url($PAGE->url, ['confirm' => $target]);
  91  if (!empty($returnurl)) {
  92      $confirmurl->param('returnurl', $returnurl);
  93  }
  94  
  95  echo $OUTPUT->confirm($confirmstring, $confirmurl, $context->get_url());
  96  echo $OUTPUT->footer();