MDL-71913 mod_wiki: Update behat tests
[moodle.git] / admin / enrol.php
blobcfe0636b2984055e0f0d5a678718c9bbcc0a53bb
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 $syscontext = context_system::instance();
48 switch ($action) {
49 case 'disable':
50 unset($enabled[$enrol]);
51 set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
52 core_plugin_manager::reset_caches();
53 $syscontext->mark_dirty(); // resets all enrol caches
54 break;
56 case 'enable':
57 if (!isset($all[$enrol])) {
58 break;
60 $enabled = array_keys($enabled);
61 $enabled[] = $enrol;
62 set_config('enrol_plugins_enabled', implode(',', $enabled));
63 core_plugin_manager::reset_caches();
64 $syscontext->mark_dirty(); // resets all enrol caches
65 break;
67 case 'up':
68 if (!isset($enabled[$enrol])) {
69 break;
71 $enabled = array_keys($enabled);
72 $enabled = array_flip($enabled);
73 $current = $enabled[$enrol];
74 if ($current == 0) {
75 break; //already at the top
77 $enabled = array_flip($enabled);
78 $enabled[$current] = $enabled[$current - 1];
79 $enabled[$current - 1] = $enrol;
80 set_config('enrol_plugins_enabled', implode(',', $enabled));
81 break;
83 case 'down':
84 if (!isset($enabled[$enrol])) {
85 break;
87 $enabled = array_keys($enabled);
88 $enabled = array_flip($enabled);
89 $current = $enabled[$enrol];
90 if ($current == count($enabled) - 1) {
91 break; //already at the end
93 $enabled = array_flip($enabled);
94 $enabled[$current] = $enabled[$current + 1];
95 $enabled[$current + 1] = $enrol;
96 set_config('enrol_plugins_enabled', implode(',', $enabled));
97 break;
99 case 'migrate':
100 if (get_string_manager()->string_exists('pluginname', 'enrol_'.$enrol)) {
101 $strplugin = get_string('pluginname', 'enrol_'.$enrol);
102 } else {
103 $strplugin = $enrol;
106 $PAGE->set_title($strplugin);
107 echo $OUTPUT->header();
109 // This may take a long time.
110 core_php_time_limit::raise();
112 // Disable plugin to prevent concurrent cron execution.
113 unset($enabled[$enrol]);
114 set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
116 echo $OUTPUT->heading(get_string('uninstallmigrating', 'enrol', 'enrol_'.$enrol));
118 require_once("$CFG->dirroot/enrol/manual/locallib.php");
119 enrol_manual_migrate_plugin_enrolments($enrol);
121 echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
123 if (!$return = core_plugin_manager::instance()->get_uninstall_url('enrol_'.$enrol, 'manage')) {
124 $return = new moodle_url('/admin/plugins.php');
126 echo $OUTPUT->continue_button($return);
127 echo $OUTPUT->footer();
128 exit;
132 redirect($return);