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
25require_once('../config.php');
26require_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
34list($context, $course, $cm) = get_context_info_array($contextid);
35
36$parentcontext = $context->get_parent_context();
37if ($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
42if ($course) {
43    $isfrontpage = ($course->id == SITEID);
44} else {
45    $isfrontpage = false;
46    $course = $SITE;
47}
48
49require_login($course, false, $cm);
50require_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
59if (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
80echo $OUTPUT->header();
81
82if ($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]);
91if (!empty($returnurl)) {
92    $confirmurl->param('returnurl', $returnurl);
93}
94
95echo $OUTPUT->confirm($confirmstring, $confirmurl, $context->get_url());
96echo $OUTPUT->footer();
97