Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Allows the admin to configure blocks (hide/show, uninstall and configure)
19
 *
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
23
 */
24
 
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");
29
 
30
admin_externalpage_setup('manageblocks');
31
 
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);
36
 
37
$strmanageblocks = get_string('manageblocks');
38
 
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}");
43
 
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
48
        );
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
55
        );
56
 
57
        // Settings not required - only pages.
58
        admin_get_root(true, false);
59
    }
60
 
61
    // Redirect back to the page with out any params.
62
    redirect(new moodle_url('/admin/blocks.php'));
63
}
64
 
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
71
    );
72
    // Settings not required - only pages.
73
    admin_get_root(true, false);
74
}
75
 
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
82
    );
83
    // Settings not required - only pages.
84
    admin_get_root(true, false);
85
}
86
 
87
echo $OUTPUT->header();
88
echo $OUTPUT->heading($strmanageblocks);
89
echo $OUTPUT->notification(get_string('noteunneededblocks', 'admin'), 'info', false);
90
 
91
// Print the table of all blocks.
92
$table = new \core_admin\table\block_management_table();
93
$table->out();
94
echo $OUTPUT->footer();