Merge branch 'wip-mdl-30993' of git://github.com/rajeshtaneja/moodle
[moodle.git] / admin / auth.php
blob93711ee832416d66e7a951b5c570f8a14180f07a
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_login();
15 require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
17 $returnurl = new moodle_url('/admin/settings.php', array('section'=>'manageauths'));
19 $PAGE->set_url($returnurl);
21 $action = optional_param('action', '', PARAM_ACTION);
22 $auth = optional_param('auth', '', PARAM_PLUGIN);
24 get_enabled_auth_plugins(true); // fix the list of enabled auths
25 if (empty($CFG->auth)) {
26 $authsenabled = array();
27 } else {
28 $authsenabled = explode(',', $CFG->auth);
31 if (!empty($auth) and !exists_auth_plugin($auth)) {
32 print_error('pluginnotinstalled', 'auth', $returnurl, $auth);
35 ////////////////////////////////////////////////////////////////////////////////
36 // process actions
38 if (!confirm_sesskey()) {
39 redirect($returnurl);
42 switch ($action) {
43 case 'disable':
44 // remove from enabled list
45 $key = array_search($auth, $authsenabled);
46 if ($key !== false) {
47 unset($authsenabled[$key]);
48 set_config('auth', implode(',', $authsenabled));
51 if ($auth == $CFG->registerauth) {
52 set_config('registerauth', '');
54 session_gc(); // remove stale sessions
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 session_gc(); // remove stale sessions
65 break;
67 case 'down':
68 $key = array_search($auth, $authsenabled);
69 // check auth plugin is valid
70 if ($key === false) {
71 print_error('pluginnotenabled', 'auth', $returnurl, $auth);
73 // move down the list
74 if ($key < (count($authsenabled) - 1)) {
75 $fsave = $authsenabled[$key];
76 $authsenabled[$key] = $authsenabled[$key + 1];
77 $authsenabled[$key + 1] = $fsave;
78 set_config('auth', implode(',', $authsenabled));
80 break;
82 case 'up':
83 $key = array_search($auth, $authsenabled);
84 // check auth is valid
85 if ($key === false) {
86 print_error('pluginnotenabled', 'auth', $returnurl, $auth);
88 // move up the list
89 if ($key >= 1) {
90 $fsave = $authsenabled[$key];
91 $authsenabled[$key] = $authsenabled[$key - 1];
92 $authsenabled[$key - 1] = $fsave;
93 set_config('auth', implode(',', $authsenabled));
95 break;
97 default:
98 break;
101 redirect($returnurl);