Merge branch 'MDL-62945-master' of https://github.com/HuongNV13/moodle
[moodle.git] / admin / auth.php
blobc83e8482bee437f8ee45fa50e12bced04d7ff54a
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', context_system::instance());
17 $returnurl = new moodle_url('/admin/settings.php', array('section'=>'manageauths'));
19 $PAGE->set_url($returnurl);
21 $action = optional_param('action', '', PARAM_ALPHANUMEXT);
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 \core\session\manager::gc(); // Remove stale sessions.
55 core_plugin_manager::reset_caches();
56 break;
58 case 'enable':
59 // add to enabled list
60 if (!in_array($auth, $authsenabled)) {
61 $authsenabled[] = $auth;
62 $authsenabled = array_unique($authsenabled);
63 set_config('auth', implode(',', $authsenabled));
65 \core\session\manager::gc(); // Remove stale sessions.
66 core_plugin_manager::reset_caches();
67 break;
69 case 'down':
70 $key = array_search($auth, $authsenabled);
71 // check auth plugin is valid
72 if ($key === false) {
73 print_error('pluginnotenabled', 'auth', $returnurl, $auth);
75 // move down the list
76 if ($key < (count($authsenabled) - 1)) {
77 $fsave = $authsenabled[$key];
78 $authsenabled[$key] = $authsenabled[$key + 1];
79 $authsenabled[$key + 1] = $fsave;
80 set_config('auth', implode(',', $authsenabled));
82 break;
84 case 'up':
85 $key = array_search($auth, $authsenabled);
86 // check auth is valid
87 if ($key === false) {
88 print_error('pluginnotenabled', 'auth', $returnurl, $auth);
90 // move up the list
91 if ($key >= 1) {
92 $fsave = $authsenabled[$key];
93 $authsenabled[$key] = $authsenabled[$key - 1];
94 $authsenabled[$key - 1] = $fsave;
95 set_config('auth', implode(',', $authsenabled));
97 break;
99 default:
100 break;
103 redirect($returnurl);