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_SAFEDIR
);
31 $confirm = optional_param('confirm', 0, PARAM_BOOL
);
33 $PAGE->set_url('/admin/enrol.php');
36 require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
));
39 $enabled = enrol_get_plugins(true);
40 $all = enrol_get_plugins(false);
42 $return = new moodle_url('/admin/settings.php', array('section'=>'manageenrols'));
46 unset($enabled[$enrol]);
47 set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
51 if (!isset($all[$enrol])) {
54 $enabled = array_keys($enabled);
56 set_config('enrol_plugins_enabled', implode(',', $enabled));
60 if (!isset($enabled[$enrol])) {
63 $enabled = array_keys($enabled);
64 $enabled = array_flip($enabled);
65 $current = $enabled[$enrol];
67 break; //already at the top
69 $enabled = array_flip($enabled);
70 $enabled[$current] = $enabled[$current - 1];
71 $enabled[$current - 1] = $enrol;
72 set_config('enrol_plugins_enabled', implode(',', $enabled));
76 if (!isset($enabled[$enrol])) {
79 $enabled = array_keys($enabled);
80 $enabled = array_flip($enabled);
81 $current = $enabled[$enrol];
82 if ($current == count($enabled) - 1) {
83 break; //already at the end
85 $enabled = array_flip($enabled);
86 $enabled[$current] = $enabled[$current +
1];
87 $enabled[$current +
1] = $enrol;
88 set_config('enrol_plugins_enabled', implode(',', $enabled));
92 echo $OUTPUT->header();
93 echo $OUTPUT->heading(get_string('enrolments', 'enrol'));
95 if (get_string_manager()->string_exists('pluginname', 'enrol_'.$enrol)) {
96 $strplugin = get_string('pluginname', 'enrol_'.$enrol);
102 $uurl = new moodle_url('/admin/enrol.php', array('action'=>'uninstall', 'enrol'=>$enrol, 'sesskey'=>sesskey(), 'confirm'=>1));
103 echo $OUTPUT->confirm(get_string('uninstallconfirm', 'enrol', $strplugin), $uurl, $return);
104 echo $OUTPUT->footer();
107 } else { // Delete everything!!
108 uninstall_plugin('enrol', $enrol);
110 $a->plugin
= $strplugin;
111 $a->directory
= "$CFG->dirroot/enrol/$enrol";
112 echo $OUTPUT->notification(get_string('uninstalldeletefiles', 'enrol', $a), 'notifysuccess');
113 echo $OUTPUT->continue_button($return);
114 echo $OUTPUT->footer();