MDL-78962 core/loadingicon: remove jQuery requirement in the API
[moodle.git] / admin / updatesetting.php
blobda4004ebdd2b4c8a41b24ead5f9aeedd4ed90df5
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 * Generic plugin config manipulation script.
20 * @package admin
21 * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 define('NO_OUTPUT_BUFFERING', true);
27 require_once('../config.php');
28 require_once($CFG->libdir.'/adminlib.php');
30 $action = required_param('action', PARAM_ALPHANUMEXT);
31 $plugin = required_param('plugin', PARAM_PLUGIN);
32 $type = required_param('type', PARAM_PLUGIN);
34 $PAGE->set_url('/admin/updatesetting.php');
35 $PAGE->set_context(context_system::instance());
37 require_admin();
38 require_sesskey();
40 $plugintypeclass = "\\core\\plugininfo\\{$type}";
42 $plugins = \core_plugin_manager::instance()->get_plugins_of_type($type);
43 $sortorder = array_values($plugintypeclass::get_enabled_plugins());
45 $return = $plugintypeclass::get_manage_url();
47 if (!array_key_exists($plugin, $plugins)) {
48 redirect($return);
51 switch ($action) {
52 case 'disable':
53 $class = \core_plugin_manager::resolve_plugininfo_class($type);
54 $class::enable_plugin($plugin, false);
55 break;
57 case 'enable':
58 $class = \core_plugin_manager::resolve_plugininfo_class($type);
59 $class::enable_plugin($plugin, true);
60 break;
62 case 'up':
63 if (($pos = array_search($plugin, $sortorder)) > 0) {
64 $tmp = $sortorder[$pos - 1];
65 $sortorder[$pos - 1] = $sortorder[$pos];
66 $sortorder[$pos] = $tmp;
67 $plugintypeclass::set_enabled_plugins($sortorder);
69 break;
71 case 'down':
72 if ((($pos = array_search($plugin, $sortorder)) !== false) && ($pos < count($sortorder) - 1)) {
73 $tmp = $sortorder[$pos + 1];
74 $sortorder[$pos + 1] = $sortorder[$pos];
75 $sortorder[$pos] = $tmp;
76 $plugintypeclass::set_enabled_plugins($sortorder);
78 break;
81 redirect($return);