Merge branch 'MDL-77608-401' of https://github.com/paulholden/moodle into MOODLE_401_...
[moodle.git] / admin / lock.php
blob3041ded67ae4933a7cf3cb844c9ae7b1c0a70bad
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.
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/>.
17 /**
18 * This file is used to display a categories sub categories, external pages, and settings.
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
25 require_once('../config.php');
26 require_once("{$CFG->libdir}/adminlib.php");
28 $contextid = required_param('id', PARAM_INT);
29 $confirm = optional_param('confirm', null, PARAM_INT);
30 $returnurl = optional_param('returnurl', null, PARAM_LOCALURL);
32 $PAGE->set_url('/admin/lock.php', ['id' => $contextid]);
34 list($context, $course, $cm) = get_context_info_array($contextid);
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');
42 if ($course) {
43 $isfrontpage = ($course->id == SITEID);
44 } else {
45 $isfrontpage = false;
46 $course = $SITE;
49 require_login($course, false, $cm);
50 require_capability('moodle/site:managecontextlocks', $context);
52 $PAGE->set_pagelayout('admin');
53 $PAGE->navigation->clear_cache();
55 $a = (object) [
56 'contextname' => $context->get_context_name(),
59 if (null !== $confirm && confirm_sesskey()) {
60 $context->set_locked(!empty($confirm));
62 if ($context->locked) {
63 $lockmessage = get_string('managecontextlocklocked', 'admin', $a);
64 } else {
65 $lockmessage = get_string('managecontextlockunlocked', 'admin', $a);
68 if (empty($returnurl)) {
69 $returnurl = $context->get_url();
70 } else {
71 $returnurl = new moodle_url($returnurl);
73 redirect($returnurl, $lockmessage);
76 $heading = get_string('managecontextlock', 'admin');
77 $PAGE->set_title($heading);
78 $PAGE->set_heading($heading);
80 echo $OUTPUT->header();
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;
90 $confirmurl = new \moodle_url($PAGE->url, ['confirm' => $target]);
91 if (!empty($returnurl)) {
92 $confirmurl->param('returnurl', $returnurl);
95 echo $OUTPUT->confirm($confirmstring, $confirmurl, $context->get_url());
96 echo $OUTPUT->footer();