MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / admin / auth.php
blobfabfa5e69dcae5758ddc8cdb03f8fc666b54c341
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 admin_externalpage_setup('userauthentication');
16 $action = optional_param('action', '', PARAM_ACTION);
17 $auth = optional_param('auth', '', PARAM_SAFEDIR);
19 // get currently installed and enabled auth plugins
20 $authsavailable = get_list_of_plugins('auth');
22 //revert auth_plugins_enabled
23 if (isset($CFG->auth_plugins_enabled)) {
24 set_config('auth', $CFG->auth_plugins_enabled);
25 delete_records('config', 'name', 'auth_plugins_enabled');
26 unset($CFG->auth_plugins_enabled);
29 get_enabled_auth_plugins(true); // fix the list of enabled auths
30 if (empty($CFG->auth)) {
31 $authsenabled = array();
32 } else {
33 $authsenabled = explode(',', $CFG->auth);
36 if (!isset($CFG->registerauth)) {
37 set_config('registerauth', '');
40 if (!isset($CFG->auth_instructions)) {
41 set_config('auth_instructions', '');
44 if (!empty($auth) and !exists_auth_plugin($auth)) {
45 error(get_string('pluginnotinstalled', 'auth', $auth), $url);
49 ////////////////////////////////////////////////////////////////////////////////
50 // process actions
52 $status = '';
54 switch ($action) {
56 case 'save':
57 if (data_submitted() and confirm_sesskey()) {
59 // save settings
60 set_config('guestloginbutton', required_param('guestloginbutton', PARAM_BOOL));
61 set_config('alternateloginurl', stripslashes(trim(required_param('alternateloginurl', PARAM_RAW))));
62 set_config('registerauth', required_param('register', PARAM_SAFEDIR));
63 set_config('auth_instructions', stripslashes(trim(required_param('auth_instructions', PARAM_RAW))));
65 // enable registerauth in $CFG->auth if needed
66 if (!empty($CFG->registerauth) and !in_array($CFG->registerauth, $authsenabled)) {
67 $authsenabled[] = $CFG->registerauth;
68 set_config('auth', implode(',', $authsenabled));
70 $status = get_string('changessaved');
72 break;
74 case 'disable':
75 // remove from enabled list
76 $key = array_search($auth, $authsenabled);
77 if ($key !== false) {
78 unset($authsenabled[$key]);
79 set_config('auth', implode(',', $authsenabled));
82 if ($auth == $CFG->registerauth) {
83 set_config('registerauth', '');
85 break;
87 case 'enable':
88 // add to enabled list
89 if (!in_array($auth, $authsenabled)) {
90 $authsenabled[] = $auth;
91 $authsenabled = array_unique($authsenabled);
92 set_config('auth', implode(',', $authsenabled));
94 break;
96 case 'down':
97 $key = array_search($auth, $authsenabled);
98 // check auth plugin is valid
99 if ($key === false) {
100 error(get_string('pluginnotenabled', 'auth', $auth), $url);
102 // move down the list
103 if ($key < (count($authsenabled) - 1)) {
104 $fsave = $authsenabled[$key];
105 $authsenabled[$key] = $authsenabled[$key + 1];
106 $authsenabled[$key + 1] = $fsave;
107 set_config('auth', implode(',', $authsenabled));
109 break;
111 case 'up':
112 $key = array_search($auth, $authsenabled);
113 // check auth is valid
114 if ($key === false) {
115 error(get_string('pluginnotenabled', 'auth', $auth), $url);
117 // move up the list
118 if ($key >= 1) {
119 $fsave = $authsenabled[$key];
120 $authsenabled[$key] = $authsenabled[$key - 1];
121 $authsenabled[$key - 1] = $fsave;
122 set_config('auth', implode(',', $authsenabled));
124 break;
126 default:
127 break;
130 // display strings
131 $txt = get_strings(array('authenticationplugins', 'users', 'administration',
132 'settings', 'edit', 'name', 'enable', 'disable',
133 'up', 'down', 'none'));
134 $txt->updown = "$txt->up/$txt->down";
136 // construct the display array, with enabled auth plugins at the top, in order
137 $displayauths = array();
138 $registrationauths = array();
139 $registrationauths[''] = $txt->disable;
140 foreach ($authsenabled as $auth) {
141 $authplugin = get_auth_plugin($auth);
142 /// Get the auth title (from core or own auth lang files)
143 $authtitle = get_string("auth_{$auth}title", "auth");
144 if ($authtitle == "[[auth_{$auth}title]]") {
145 $authtitle = get_string("auth_{$auth}title", "auth_{$auth}");
147 /// Apply titles
148 $displayauths[$auth] = $authtitle;
149 if ($authplugin->can_signup()) {
150 $registrationauths[$auth] = $authtitle;
154 foreach ($authsavailable as $auth) {
155 if (array_key_exists($auth, $displayauths)) {
156 continue; //already in the list
158 $authplugin = get_auth_plugin($auth);
159 /// Get the auth title (from core or own auth lang files)
160 $authtitle = get_string("auth_{$auth}title", "auth");
161 if ($authtitle == "[[auth_{$auth}title]]") {
162 $authtitle = get_string("auth_{$auth}title", "auth_{$auth}");
164 /// Apply titles
165 $displayauths[$auth] = $authtitle;
166 if ($authplugin->can_signup()) {
167 $registrationauths[$auth] = $authtitle;
171 // build the display table
172 $table = new flexible_table('auth_admin_table');
173 $table->define_columns(array('name', 'enable', 'order', 'settings'));
174 $table->define_headers(array($txt->name, $txt->enable, $txt->updown, $txt->settings));
175 $table->define_baseurl("{$CFG->wwwroot}/{$CFG->admin}/auth.php");
176 $table->set_attribute('id', 'blocks');
177 $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
178 $table->setup();
180 //add always enabled plugins first
181 $displayname = "<span>".$displayauths['manual']."</span>";
182 $settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&amp;auth=manual\">{$txt->settings}</a>";
183 $table->add_data(array($displayname, '', '', $settings));
184 $displayname = "<span>".$displayauths['nologin']."</span>";
185 $settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&amp;auth=nologin\">{$txt->settings}</a>";
186 $table->add_data(array($displayname, '', '', $settings));
189 // iterate through auth plugins and add to the display table
190 $updowncount = 1;
191 $authcount = count($authsenabled);
192 $url = "auth.php?sesskey=" . sesskey();
193 foreach ($displayauths as $auth => $name) {
194 if ($auth == 'manual' or $auth == 'nologin') {
195 continue;
197 // hide/show link
198 if (in_array($auth, $authsenabled)) {
199 $hideshow = "<a href=\"$url&amp;action=disable&amp;auth=$auth\">";
200 $hideshow .= "<img src=\"{$CFG->pixpath}/i/hide.gif\" class=\"icon\" alt=\"disable\" /></a>";
201 // $hideshow = "<a href=\"$url&amp;action=disable&amp;auth=$auth\"><input type=\"checkbox\" checked /></a>";
202 $enabled = true;
203 $displayname = "<span>$name</span>";
205 else {
206 $hideshow = "<a href=\"$url&amp;action=enable&amp;auth=$auth\">";
207 $hideshow .= "<img src=\"{$CFG->pixpath}/i/show.gif\" class=\"icon\" alt=\"enable\" /></a>";
208 // $hideshow = "<a href=\"$url&amp;action=enable&amp;auth=$auth\"><input type=\"checkbox\" /></a>";
209 $enabled = false;
210 $displayname = "<span class=\"dimmed_text\">$name</span>";
213 // up/down link (only if auth is enabled)
214 $updown = '';
215 if ($enabled) {
216 if ($updowncount > 1) {
217 $updown .= "<a href=\"$url&amp;action=up&amp;auth=$auth\">";
218 $updown .= "<img src=\"{$CFG->pixpath}/t/up.gif\" alt=\"up\" /></a>&nbsp;";
220 else {
221 $updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" class=\"icon\" alt=\"\" />&nbsp;";
223 if ($updowncount < $authcount) {
224 $updown .= "<a href=\"$url&amp;action=down&amp;auth=$auth\">";
225 $updown .= "<img src=\"{$CFG->pixpath}/t/down.gif\" alt=\"down\" /></a>";
227 else {
228 $updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" class=\"icon\" alt=\"\" />";
230 ++ $updowncount;
233 // settings link
234 $settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&amp;auth=$auth\">{$txt->settings}</a>";
236 // add a row to the table
237 $table->add_data(array($displayname, $hideshow, $updown, $settings));
240 // output form
241 admin_externalpage_print_header();
243 //print stus messages
244 if ($status !== '') {
245 notify($status, 'notifysuccess');
248 print_simple_box(get_string('configauthenticationplugins', 'admin'), 'center', '700');
250 $table->print_html();
252 ////////////////////////////////////////////////////////////////////////////////
254 $guestoptions = array();
255 $guestoptions[0] = get_string("hide");
256 $guestoptions[1] = get_string("show");
258 echo '<hr />';
260 echo '<form '.$CFG->frametarget.' id="adminsettings" method="post" action="auth.php">';
261 echo '<div class="settingsform clearfix">';
262 print_heading(get_string('auth_common_settings', 'auth'));
263 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
264 echo '<input type="hidden" name="action" value="save" />';
265 echo '<fieldset>';
266 ##echo '<table cellspacing="0" cellpadding="5" border="0" style="margin-left:auto;margin-right:auto">';
268 // User self registration
269 echo '<div class="form-item" id="admin-register">';
270 echo '<label for = "menuregister">' . get_string("selfregistration", "auth");
271 echo '<span class="form-shortname">registerauth</span>';
272 echo '</label>';
273 choose_from_menu($registrationauths, "register", $CFG->registerauth, "");
274 echo '<div class="description">' . get_string("selfregistration_help", "auth") . '</div>';
275 echo '</div>';
277 // Login as guest button enabled
278 echo '<div class="form-item" id="admin-guestloginbutton">';
279 echo '<label for = "menuguestloginbutton">' . get_string("guestloginbutton", "auth");
280 echo '<span class="form-shortname">guestloginbutton</span>';
281 echo '</label>';
282 choose_from_menu($guestoptions, "guestloginbutton", $CFG->guestloginbutton, "");
283 echo '<div class="description">' . get_string("showguestlogin", "auth") . '</div>';
284 echo '</div>';
286 /// An alternate url for the login form. It means we can use login forms that are integrated
287 /// into non-moodle pages
288 echo '<div class="form-item" id="admin-alternateloginurl">';
289 echo '<label for = "alternateloginurl">' . get_string("alternateloginurl", "auth");
290 echo '<span class="form-shortname">alternateloginurl</span>';
291 echo '</label>';
292 echo '<input type="text" size="60" name="alternateloginurl" id="alternateloginurl" value="'.$CFG->alternateloginurl."\" />\n";
293 echo '<div class="description">' . get_string("alternatelogin", "auth", htmlspecialchars($CFG->wwwroot.'/login/index.php')) . '</div>';
294 echo '</div>';
296 /// Instructions about login/password
297 /// to be showed to users
298 echo '<div class="form-item" id="admin-auth_instructions">';
299 echo '<label for = "auth_instructions">' . get_string("instructions", "auth");
300 echo '<span class="form-shortname">auth_instructions</span>';
301 echo '</label>';
302 echo '<textarea cols="30" rows="4" name="auth_instructions" id="auth_instructions">'.s($CFG->auth_instructions)."</textarea>\n";
303 echo '<div class="description">' . get_string("authinstructions", "auth") . '</div>';
304 echo '</div>';
306 echo '</fieldset>';
308 ////////////////////////////////////////////////////////////////////////////////
309 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges', 'admin').'" /></div>';
310 echo '</div>';
311 echo '</form>';
312 admin_externalpage_print_footer();