The handlers now throw moodle1_convert_exception instead of convert_exception
[moodle.git] / admin / enrol.php
blob26e430ef8f707fcfee65f3ecc10666567203d4aa
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_SAFEDIR);
31 $confirm = optional_param('confirm', 0, PARAM_BOOL);
33 $PAGE->set_url('/admin/enrol.php');
35 require_login();
36 require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
37 require_sesskey();
39 $enabled = enrol_get_plugins(true);
40 $all = enrol_get_plugins(false);
42 $return = new moodle_url('/admin/settings.php', array('section'=>'manageenrols'));
44 switch ($action) {
45 case 'disable':
46 unset($enabled[$enrol]);
47 set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
48 break;
50 case 'enable':
51 if (!isset($all[$enrol])) {
52 break;
54 $enabled = array_keys($enabled);
55 $enabled[] = $enrol;
56 set_config('enrol_plugins_enabled', implode(',', $enabled));
57 break;
59 case 'up':
60 if (!isset($enabled[$enrol])) {
61 break;
63 $enabled = array_keys($enabled);
64 $enabled = array_flip($enabled);
65 $current = $enabled[$enrol];
66 if ($current == 0) {
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));
73 break;
75 case 'down':
76 if (!isset($enabled[$enrol])) {
77 break;
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));
89 break;
91 case 'uninstall':
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);
97 } else {
98 $strplugin = $enrol;
101 if (!$confirm) {
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();
105 exit;
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();
115 exit;
120 redirect($return);