Merge branch 'MDL-69102-310' of https://github.com/martygilbert/moodle into MOODLE_31...
[moodle.git] / admin / auth.php
blobc45b0da93cf5bddfc44a88352ac58ea1ebbf511b
1 <?php
3 /**
4 * Allows admin to edit all auth plugin settings.
6 * JH: copied and Hax0rd from admin/enrol.php and admin/filters.php
8 */
10 require_once('../config.php');
11 require_once($CFG->libdir.'/adminlib.php');
12 require_once($CFG->libdir.'/tablelib.php');
14 require_admin();
16 $returnurl = new moodle_url('/admin/settings.php', array('section'=>'manageauths'));
18 $PAGE->set_url($returnurl);
20 $action = optional_param('action', '', PARAM_ALPHANUMEXT);
21 $auth = optional_param('auth', '', PARAM_PLUGIN);
23 get_enabled_auth_plugins(true); // fix the list of enabled auths
24 if (empty($CFG->auth)) {
25 $authsenabled = array();
26 } else {
27 $authsenabled = explode(',', $CFG->auth);
30 if (!empty($auth) and !exists_auth_plugin($auth)) {
31 print_error('pluginnotinstalled', 'auth', $returnurl, $auth);
34 ////////////////////////////////////////////////////////////////////////////////
35 // process actions
37 if (!confirm_sesskey()) {
38 redirect($returnurl);
41 switch ($action) {
42 case 'disable':
43 // remove from enabled list
44 $key = array_search($auth, $authsenabled);
45 if ($key !== false) {
46 unset($authsenabled[$key]);
47 set_config('auth', implode(',', $authsenabled));
50 if ($auth == $CFG->registerauth) {
51 set_config('registerauth', '');
53 \core\session\manager::gc(); // Remove stale sessions.
54 core_plugin_manager::reset_caches();
55 break;
57 case 'enable':
58 // add to enabled list
59 if (!in_array($auth, $authsenabled)) {
60 $authsenabled[] = $auth;
61 $authsenabled = array_unique($authsenabled);
62 set_config('auth', implode(',', $authsenabled));
64 \core\session\manager::gc(); // Remove stale sessions.
65 core_plugin_manager::reset_caches();
66 break;
68 case 'down':
69 $key = array_search($auth, $authsenabled);
70 // check auth plugin is valid
71 if ($key === false) {
72 print_error('pluginnotenabled', 'auth', $returnurl, $auth);
74 // move down the list
75 if ($key < (count($authsenabled) - 1)) {
76 $fsave = $authsenabled[$key];
77 $authsenabled[$key] = $authsenabled[$key + 1];
78 $authsenabled[$key + 1] = $fsave;
79 set_config('auth', implode(',', $authsenabled));
81 break;
83 case 'up':
84 $key = array_search($auth, $authsenabled);
85 // check auth is valid
86 if ($key === false) {
87 print_error('pluginnotenabled', 'auth', $returnurl, $auth);
89 // move up the list
90 if ($key >= 1) {
91 $fsave = $authsenabled[$key];
92 $authsenabled[$key] = $authsenabled[$key - 1];
93 $authsenabled[$key - 1] = $fsave;
94 set_config('auth', implode(',', $authsenabled));
96 break;
98 default:
99 break;
102 redirect($returnurl);