MDL-41806 Add assessors to moodle_url class
[moodle.git] / admin / enrol.php
blob59f77c53aee3c3db3a4578b37e61a79c1e6cd807
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_login();
39 require_capability('moodle/site:config', context_system::instance());
40 require_sesskey();
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();
49 switch ($action) {
50 case 'disable':
51 unset($enabled[$enrol]);
52 set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
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 $syscontext->mark_dirty(); // resets all enrol caches
64 break;
66 case 'up':
67 if (!isset($enabled[$enrol])) {
68 break;
70 $enabled = array_keys($enabled);
71 $enabled = array_flip($enabled);
72 $current = $enabled[$enrol];
73 if ($current == 0) {
74 break; //already at the top
76 $enabled = array_flip($enabled);
77 $enabled[$current] = $enabled[$current - 1];
78 $enabled[$current - 1] = $enrol;
79 set_config('enrol_plugins_enabled', implode(',', $enabled));
80 break;
82 case 'down':
83 if (!isset($enabled[$enrol])) {
84 break;
86 $enabled = array_keys($enabled);
87 $enabled = array_flip($enabled);
88 $current = $enabled[$enrol];
89 if ($current == count($enabled) - 1) {
90 break; //already at the end
92 $enabled = array_flip($enabled);
93 $enabled[$current] = $enabled[$current + 1];
94 $enabled[$current + 1] = $enrol;
95 set_config('enrol_plugins_enabled', implode(',', $enabled));
96 break;
98 case 'migrate':
99 if (get_string_manager()->string_exists('pluginname', 'enrol_'.$enrol)) {
100 $strplugin = get_string('pluginname', 'enrol_'.$enrol);
101 } else {
102 $strplugin = $enrol;
105 $PAGE->set_title($strplugin);
106 echo $OUTPUT->header();
108 // This may take a long time.
109 set_time_limit(0);
111 // Disable plugin to prevent concurrent cron execution.
112 unset($enabled[$enrol]);
113 set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
115 echo $OUTPUT->heading(get_string('uninstallmigrating', 'enrol', 'enrol_'.$enrol));
117 require_once("$CFG->dirroot/enrol/manual/locallib.php");
118 enrol_manual_migrate_plugin_enrolments($enrol);
120 echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
122 if (!$return = plugin_manager::instance()->get_uninstall_url('enrol_'.$enrol)) {
123 $return = new moodle_url('/admin/plugins.php');
125 echo $OUTPUT->continue_button($return);
126 echo $OUTPUT->footer();
127 exit;
131 redirect($return);