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
);
34 $migrate = optional_param('migrate', 0, PARAM_BOOL
);
36 $PAGE->set_url('/admin/enrol.php');
37 $PAGE->set_context(context_system
::instance());
40 require_capability('moodle/site:config', context_system
::instance());
43 $enabled = enrol_get_plugins(true);
44 $all = enrol_get_plugins(false);
46 $return = new moodle_url('/admin/settings.php', array('section'=>'manageenrols'));
48 $syscontext = context_system
::instance();
52 unset($enabled[$enrol]);
53 set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
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 $syscontext->mark_dirty(); // resets all enrol caches
68 if (!isset($enabled[$enrol])) {
71 $enabled = array_keys($enabled);
72 $enabled = array_flip($enabled);
73 $current = $enabled[$enrol];
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));
84 if (!isset($enabled[$enrol])) {
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));
100 if (get_string_manager()->string_exists('pluginname', 'enrol_'.$enrol)) {
101 $strplugin = get_string('pluginname', 'enrol_'.$enrol);
106 $PAGE->set_title($strplugin);
107 echo $OUTPUT->header();
110 echo $OUTPUT->heading(get_string('enrolments', 'enrol'));
112 $deleteurl = new moodle_url('/admin/enrol.php', array('action'=>'uninstall', 'enrol'=>$enrol, 'sesskey'=>sesskey(), 'confirm'=>1, 'migrate'=>0));
113 $migrateurl = new moodle_url('/admin/enrol.php', array('action'=>'uninstall', 'enrol'=>$enrol, 'sesskey'=>sesskey(), 'confirm'=>1, 'migrate'=>1));
115 $migrate = new single_button($migrateurl, get_string('uninstallmigrate', 'enrol'));
116 $delete = new single_button($deleteurl, get_string('uninstalldelete', 'enrol'));
117 $cancel = new single_button($return, get_string('cancel'), 'get');
119 $buttons = $OUTPUT->render($delete) . $OUTPUT->render($cancel);
120 if ($enrol !== 'manual') {
121 $buttons = $OUTPUT->render($migrate) . $buttons;
124 echo $OUTPUT->box_start('generalbox', 'notice');
125 echo html_writer
::tag('p', markdown_to_html(get_string('uninstallconfirm', 'enrol', $strplugin)));
126 echo html_writer
::tag('div', $buttons, array('class' => 'buttons'));
127 echo $OUTPUT->box_end();
129 echo $OUTPUT->footer();
133 // This may take a long time.
136 // Disable plugin to prevent concurrent cron execution.
137 unset($enabled[$enrol]);
138 set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
141 echo $OUTPUT->heading(get_string('uninstallmigrating', 'enrol', 'enrol_'.$enrol));
143 require_once("$CFG->dirroot/enrol/manual/locallib.php");
144 enrol_manual_migrate_plugin_enrolments($enrol);
146 echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
149 // Delete everything!!
150 uninstall_plugin('enrol', $enrol);
151 $syscontext->mark_dirty(); // Resets all enrol caches.
154 $a->plugin
= $strplugin;
155 $a->directory
= "$CFG->dirroot/enrol/$enrol";
156 echo $OUTPUT->notification(get_string('uninstalldeletefiles', 'enrol', $a), 'notifysuccess');
157 echo $OUTPUT->continue_button($return);
158 echo $OUTPUT->footer();