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 require_once('../config.php');
27 require_once($CFG->libdir
.'/adminlib.php');
29 $action = required_param('action', PARAM_ACTION
);
30 $enrol = required_param('enrol', PARAM_PLUGIN
);
31 $confirm = optional_param('confirm', 0, PARAM_BOOL
);
33 $PAGE->set_url('/admin/enrol.php');
34 $PAGE->set_context(context_system
::instance());
37 require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
));
40 $enabled = enrol_get_plugins(true);
41 $all = enrol_get_plugins(false);
43 $return = new moodle_url('/admin/settings.php', array('section'=>'manageenrols'));
45 $syscontext = context_system
::instance();
49 unset($enabled[$enrol]);
50 set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
51 $syscontext->mark_dirty(); // resets all enrol caches
55 if (!isset($all[$enrol])) {
58 $enabled = array_keys($enabled);
60 set_config('enrol_plugins_enabled', implode(',', $enabled));
61 $syscontext->mark_dirty(); // resets all enrol caches
65 if (!isset($enabled[$enrol])) {
68 $enabled = array_keys($enabled);
69 $enabled = array_flip($enabled);
70 $current = $enabled[$enrol];
72 break; //already at the top
74 $enabled = array_flip($enabled);
75 $enabled[$current] = $enabled[$current - 1];
76 $enabled[$current - 1] = $enrol;
77 set_config('enrol_plugins_enabled', implode(',', $enabled));
81 if (!isset($enabled[$enrol])) {
84 $enabled = array_keys($enabled);
85 $enabled = array_flip($enabled);
86 $current = $enabled[$enrol];
87 if ($current == count($enabled) - 1) {
88 break; //already at the end
90 $enabled = array_flip($enabled);
91 $enabled[$current] = $enabled[$current +
1];
92 $enabled[$current +
1] = $enrol;
93 set_config('enrol_plugins_enabled', implode(',', $enabled));
97 echo $OUTPUT->header();
98 echo $OUTPUT->heading(get_string('enrolments', 'enrol'));
100 if (get_string_manager()->string_exists('pluginname', 'enrol_'.$enrol)) {
101 $strplugin = get_string('pluginname', 'enrol_'.$enrol);
107 $uurl = new moodle_url('/admin/enrol.php', array('action'=>'uninstall', 'enrol'=>$enrol, 'sesskey'=>sesskey(), 'confirm'=>1));
108 echo $OUTPUT->confirm(get_string('uninstallconfirm', 'enrol', $strplugin), $uurl, $return);
109 echo $OUTPUT->footer();
112 } else { // Delete everything!!
113 uninstall_plugin('enrol', $enrol);
114 $syscontext->mark_dirty(); // resets all enrol caches
117 $a->plugin
= $strplugin;
118 $a->directory
= "$CFG->dirroot/enrol/$enrol";
119 echo $OUTPUT->notification(get_string('uninstalldeletefiles', 'enrol', $a), 'notifysuccess');
120 echo $OUTPUT->continue_button($return);
121 echo $OUTPUT->footer();