Merge branch 'MDL-33120' of git://github.com/stronk7/moodle
[moodle.git] / admin / enrol.php
blobab14a23440ac9e8bc94f19cecafc38f217fdfce8
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 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());
36 require_login();
37 require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
38 require_sesskey();
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();
47 switch ($action) {
48 case 'disable':
49 unset($enabled[$enrol]);
50 set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
51 $syscontext->mark_dirty(); // resets all enrol caches
52 break;
54 case 'enable':
55 if (!isset($all[$enrol])) {
56 break;
58 $enabled = array_keys($enabled);
59 $enabled[] = $enrol;
60 set_config('enrol_plugins_enabled', implode(',', $enabled));
61 $syscontext->mark_dirty(); // resets all enrol caches
62 break;
64 case 'up':
65 if (!isset($enabled[$enrol])) {
66 break;
68 $enabled = array_keys($enabled);
69 $enabled = array_flip($enabled);
70 $current = $enabled[$enrol];
71 if ($current == 0) {
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));
78 break;
80 case 'down':
81 if (!isset($enabled[$enrol])) {
82 break;
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));
94 break;
96 case 'uninstall':
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);
102 } else {
103 $strplugin = $enrol;
106 if (!$confirm) {
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();
110 exit;
112 } else { // Delete everything!!
113 uninstall_plugin('enrol', $enrol);
114 $syscontext->mark_dirty(); // resets all enrol caches
116 $a = new stdClass();
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();
122 exit;
127 redirect($return);