2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * Enrol config manipulation script.
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());
39 require_capability('moodle/site:config', context_system
::instance());
42 $enabled = enrol_get_plugins(true);
43 $all = enrol_get_plugins(false);
45 $return = new moodle_url('/admin/settings.php', array('section'=>'manageenrols'));
47 $syscontext = context_system
::instance();
51 unset($enabled[$enrol]);
52 set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
53 core_plugin_manager
::reset_caches();
54 $syscontext->mark_dirty(); // resets all enrol caches
58 if (!isset($all[$enrol])) {
61 $enabled = array_keys($enabled);
63 set_config('enrol_plugins_enabled', implode(',', $enabled));
64 core_plugin_manager
::reset_caches();
65 $syscontext->mark_dirty(); // resets all enrol caches
69 if (!isset($enabled[$enrol])) {
72 $enabled = array_keys($enabled);
73 $enabled = array_flip($enabled);
74 $current = $enabled[$enrol];
76 break; //already at the top
78 $enabled = array_flip($enabled);
79 $enabled[$current] = $enabled[$current - 1];
80 $enabled[$current - 1] = $enrol;
81 set_config('enrol_plugins_enabled', implode(',', $enabled));
85 if (!isset($enabled[$enrol])) {
88 $enabled = array_keys($enabled);
89 $enabled = array_flip($enabled);
90 $current = $enabled[$enrol];
91 if ($current == count($enabled) - 1) {
92 break; //already at the end
94 $enabled = array_flip($enabled);
95 $enabled[$current] = $enabled[$current +
1];
96 $enabled[$current +
1] = $enrol;
97 set_config('enrol_plugins_enabled', implode(',', $enabled));
101 if (get_string_manager()->string_exists('pluginname', 'enrol_'.$enrol)) {
102 $strplugin = get_string('pluginname', 'enrol_'.$enrol);
107 $PAGE->set_title($strplugin);
108 echo $OUTPUT->header();
110 // This may take a long time.
111 core_php_time_limit
::raise();
113 // Disable plugin to prevent concurrent cron execution.
114 unset($enabled[$enrol]);
115 set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
117 echo $OUTPUT->heading(get_string('uninstallmigrating', 'enrol', 'enrol_'.$enrol));
119 require_once("$CFG->dirroot/enrol/manual/locallib.php");
120 enrol_manual_migrate_plugin_enrolments($enrol);
122 echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
124 if (!$return = core_plugin_manager
::instance()->get_uninstall_url('enrol_'.$enrol, 'manage')) {
125 $return = new moodle_url('/admin/plugins.php');
127 echo $OUTPUT->continue_button($return);
128 echo $OUTPUT->footer();