Merge branch 'MDL-27515_m19' of git://github.com/rwijaya/moodle into MOODLE_19_STABLE
[moodle.git] / admin / auth.php
blob41faab54ddc4362c59587fa40583389327e18ab3
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 = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageauths";
19 $action = optional_param('action', '', PARAM_ACTION);
20 $auth = optional_param('auth', '', PARAM_SAFEDIR);
22 // get currently installed and enabled auth plugins
23 $authsavailable = get_list_of_plugins('auth');
25 get_enabled_auth_plugins(true); // fix the list of enabled auths
26 if (empty($CFG->auth)) {
27 $authsenabled = array();
28 } else {
29 $authsenabled = explode(',', $CFG->auth);
32 if (!empty($auth) and !exists_auth_plugin($auth)) {
33 print_error('pluginnotinstalled', 'auth', $url, $auth);
36 ////////////////////////////////////////////////////////////////////////////////
37 // process actions
39 if (!confirm_sesskey()) {
40 redirect($returnurl);
43 switch ($action) {
44 case 'disable':
45 // remove from enabled list
46 $key = array_search($auth, $authsenabled);
47 if ($key !== false) {
48 unset($authsenabled[$key]);
49 set_config('auth', implode(',', $authsenabled));
52 if ($auth == $CFG->registerauth) {
53 set_config('registerauth', '');
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 break;
66 case 'down':
67 $key = array_search($auth, $authsenabled);
68 // check auth plugin is valid
69 if ($key === false) {
70 print_error('pluginnotenabled', 'auth', $url, $auth);
72 // move down the list
73 if ($key < (count($authsenabled) - 1)) {
74 $fsave = $authsenabled[$key];
75 $authsenabled[$key] = $authsenabled[$key + 1];
76 $authsenabled[$key + 1] = $fsave;
77 set_config('auth', implode(',', $authsenabled));
79 break;
81 case 'up':
82 $key = array_search($auth, $authsenabled);
83 // check auth is valid
84 if ($key === false) {
85 print_error('pluginnotenabled', 'auth', $url, $auth);
87 // move up the list
88 if ($key >= 1) {
89 $fsave = $authsenabled[$key];
90 $authsenabled[$key] = $authsenabled[$key - 1];
91 $authsenabled[$key - 1] = $fsave;
92 set_config('auth', implode(',', $authsenabled));
94 break;
96 default:
97 break;
100 redirect ($returnurl);