MDL-76059 forms: graceful early exit for invalid button elements.
[moodle.git] / admin / enrol.php
blob9cbb352110af4804b66e8458e8e3b9b9a7c89b85
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 * Enrol config manipulation script.
20 * @package core
21 * @subpackage enrol
22 * @copyright 2010 Petr Skoda {@link http://skodak.org}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 define('NO_OUTPUT_BUFFERING', true);
28 require_once('../config.php');
29 require_once($CFG->libdir.'/adminlib.php');
31 $action = required_param('action', PARAM_ALPHANUMEXT);
32 $enrol = required_param('enrol', PARAM_PLUGIN);
33 $confirm = optional_param('confirm', 0, PARAM_BOOL);
35 $PAGE->set_url('/admin/enrol.php');
36 $PAGE->set_context(context_system::instance());
38 require_admin();
39 require_sesskey();
41 $enabled = enrol_get_plugins(true);
42 $all = enrol_get_plugins(false);
44 $return = new moodle_url('/admin/settings.php', array('section'=>'manageenrols'));
46 switch ($action) {
47 case 'disable':
48 $class = \core_plugin_manager::resolve_plugininfo_class('enrol');
49 $class::enable_plugin($enrol, false);
50 break;
52 case 'enable':
53 if (!isset($all[$enrol])) {
54 break;
56 $class = \core_plugin_manager::resolve_plugininfo_class('enrol');
57 $class::enable_plugin($enrol, true);
58 break;
60 case 'up':
61 if (!isset($enabled[$enrol])) {
62 break;
64 $enabled = array_keys($enabled);
65 $enabled = array_flip($enabled);
66 $current = $enabled[$enrol];
67 if ($current == 0) {
68 break; //already at the top
70 $enabled = array_flip($enabled);
71 $enabled[$current] = $enabled[$current - 1];
72 $enabled[$current - 1] = $enrol;
73 set_config('enrol_plugins_enabled', implode(',', $enabled));
74 break;
76 case 'down':
77 if (!isset($enabled[$enrol])) {
78 break;
80 $enabled = array_keys($enabled);
81 $enabled = array_flip($enabled);
82 $current = $enabled[$enrol];
83 if ($current == count($enabled) - 1) {
84 break; //already at the end
86 $enabled = array_flip($enabled);
87 $enabled[$current] = $enabled[$current + 1];
88 $enabled[$current + 1] = $enrol;
89 set_config('enrol_plugins_enabled', implode(',', $enabled));
90 break;
92 case 'migrate':
93 if (get_string_manager()->string_exists('pluginname', 'enrol_'.$enrol)) {
94 $strplugin = get_string('pluginname', 'enrol_'.$enrol);
95 } else {
96 $strplugin = $enrol;
99 $PAGE->set_title($strplugin);
100 echo $OUTPUT->header();
102 // This may take a long time.
103 core_php_time_limit::raise();
105 // Disable plugin to prevent concurrent cron execution.
106 unset($enabled[$enrol]);
107 set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
109 echo $OUTPUT->heading(get_string('uninstallmigrating', 'enrol', 'enrol_'.$enrol));
111 require_once("$CFG->dirroot/enrol/manual/locallib.php");
112 enrol_manual_migrate_plugin_enrolments($enrol);
114 echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
116 if (!$return = core_plugin_manager::instance()->get_uninstall_url('enrol_'.$enrol, 'manage')) {
117 $return = new moodle_url('/admin/plugins.php');
119 echo $OUTPUT->continue_button($return);
120 echo $OUTPUT->footer();
121 exit;
125 redirect($return);