Merge branch 'MDL-68867-311' of https://github.com/lameze/moodle into MOODLE_311_STABLE
[moodle.git] / admin / auth.php
blob0044a429d7e776a77c4731aa795c1c7d25b05932
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 $value = implode(',', $authsenabled);
48 add_to_config_log('auth', $CFG->auth, $value, 'core');
49 set_config('auth', $value);
52 if ($auth == $CFG->registerauth) {
53 set_config('registerauth', '');
55 \core\session\manager::gc(); // Remove stale sessions.
56 core_plugin_manager::reset_caches();
57 break;
59 case 'enable':
60 // add to enabled list
61 if (!in_array($auth, $authsenabled)) {
62 $authsenabled[] = $auth;
63 $authsenabled = array_unique($authsenabled);
64 $value = implode(',', $authsenabled);
65 add_to_config_log('auth', $CFG->auth, $value, 'core');
66 set_config('auth', $value);
69 \core\session\manager::gc(); // Remove stale sessions.
70 core_plugin_manager::reset_caches();
71 break;
73 case 'down':
74 $key = array_search($auth, $authsenabled);
75 // check auth plugin is valid
76 if ($key === false) {
77 print_error('pluginnotenabled', 'auth', $returnurl, $auth);
79 // move down the list
80 if ($key < (count($authsenabled) - 1)) {
81 $fsave = $authsenabled[$key];
82 $authsenabled[$key] = $authsenabled[$key + 1];
83 $authsenabled[$key + 1] = $fsave;
84 $value = implode(',', $authsenabled);
85 add_to_config_log('auth', $CFG->auth, $value, 'core');
86 set_config('auth', $value);
88 break;
90 case 'up':
91 $key = array_search($auth, $authsenabled);
92 // check auth is valid
93 if ($key === false) {
94 print_error('pluginnotenabled', 'auth', $returnurl, $auth);
96 // move up the list
97 if ($key >= 1) {
98 $fsave = $authsenabled[$key];
99 $authsenabled[$key] = $authsenabled[$key - 1];
100 $authsenabled[$key - 1] = $fsave;
101 $value = implode(',', $authsenabled);
102 add_to_config_log('auth', $CFG->auth, $value, 'core');
103 set_config('auth', $value);
105 break;
107 default:
108 break;
111 redirect($returnurl);