Merge branch 'MDL-79059-master-2' of https://github.com/junpataleta/moodle
[moodle.git] / admin / blocks.php
blob7d2355080cf827b0f3c67798e4fcc45c858a428e
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 * Allows the admin to configure blocks (hide/show, uninstall and configure)
20 * @package core_admin
21 * @copyright 2023 Andrew Lyons <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");
27 require_once("{$CFG->libdir}/blocklib.php");
28 require_once("{$CFG->libdir}/tablelib.php");
30 admin_externalpage_setup('manageblocks');
32 $plugin = optional_param('plugin', '', PARAM_PLUGIN);
33 $action = optional_param('action', '', PARAM_ALPHA);
34 $unprotect = optional_param('unprotect', 0, PARAM_PLUGIN);
35 $protect = optional_param('protect', 0, PARAM_PLUGIN);
37 $strmanageblocks = get_string('manageblocks');
39 // If data submitted, then process and store.
40 if (!empty($plugin) && !empty($action) && confirm_sesskey()) {
41 $manager = \core_plugin_manager::resolve_plugininfo_class('block');
42 $pluginname = get_string('pluginname', "block_{$plugin}");
44 if ($action === 'disable' && $manager::enable_plugin($plugin, 0)) {
45 \core\notification::add(
46 get_string('plugin_disabled', 'core_admin', $pluginname),
47 \core\notification::SUCCESS
49 // Settings not required - only pages.
50 admin_get_root(true, false);
51 } else if ($action === 'enable' && $manager::enable_plugin($plugin, 1)) {
52 \core\notification::add(
53 get_string('plugin_enabled', 'core_admin', $pluginname),
54 \core\notification::SUCCESS
57 // Settings not required - only pages.
58 admin_get_root(true, false);
61 // Redirect back to the page with out any params.
62 redirect(new moodle_url('/admin/blocks.php'));
65 if (!empty($protect) && confirm_sesskey()) {
66 block_manager::protect_block($protect);
67 $pluginname = get_string('pluginname', "block_{$protect}");
68 \core\notification::add(
69 get_string('blockprotected', 'core_admin', $pluginname),
70 \core\notification::SUCCESS
72 // Settings not required - only pages.
73 admin_get_root(true, false);
76 if (!empty($unprotect) && confirm_sesskey()) {
77 block_manager::unprotect_block($unprotect);
78 $pluginname = get_string('pluginname', "block_{$unprotect}");
79 \core\notification::add(
80 get_string('blockunprotected', 'core_admin', $pluginname),
81 \core\notification::SUCCESS
83 // Settings not required - only pages.
84 admin_get_root(true, false);
87 echo $OUTPUT->header();
88 echo $OUTPUT->heading($strmanageblocks);
89 echo $OUTPUT->notification(get_string('noteunneededblocks', 'admin'), 'info', false);
91 // Print the table of all blocks.
92 $table = new \core_admin\table\block_management_table();
93 $table->out();
94 echo $OUTPUT->footer();