MDL-11977:
[moodle-linuxchix.git] / admin / auth.php
blobb36655180fd652117aaddf51431b3dcedfc45d9d
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('forgottenpasswordurl', stripslashes(trim(required_param('forgottenpasswordurl', PARAM_RAW))));
63 set_config('registerauth', required_param('register', PARAM_SAFEDIR));
64 set_config('auth_instructions', stripslashes(trim(required_param('auth_instructions', PARAM_RAW))));
66 // enable registerauth in $CFG->auth if needed
67 if (!empty($CFG->registerauth) and !in_array($CFG->registerauth, $authsenabled)) {
68 $authsenabled[] = $CFG->registerauth;
69 set_config('auth', implode(',', $authsenabled));
71 $status = get_string('changessaved');
73 break;
75 case 'disable':
76 // remove from enabled list
77 $key = array_search($auth, $authsenabled);
78 if ($key !== false) {
79 unset($authsenabled[$key]);
80 set_config('auth', implode(',', $authsenabled));
83 if ($auth == $CFG->registerauth) {
84 set_config('registerauth', '');
86 break;
88 case 'enable':
89 // add to enabled list
90 if (!in_array($auth, $authsenabled)) {
91 $authsenabled[] = $auth;
92 $authsenabled = array_unique($authsenabled);
93 set_config('auth', implode(',', $authsenabled));
95 break;
97 case 'down':
98 $key = array_search($auth, $authsenabled);
99 // check auth plugin is valid
100 if ($key === false) {
101 error(get_string('pluginnotenabled', 'auth', $auth), $url);
103 // move down the list
104 if ($key < (count($authsenabled) - 1)) {
105 $fsave = $authsenabled[$key];
106 $authsenabled[$key] = $authsenabled[$key + 1];
107 $authsenabled[$key + 1] = $fsave;
108 set_config('auth', implode(',', $authsenabled));
110 break;
112 case 'up':
113 $key = array_search($auth, $authsenabled);
114 // check auth is valid
115 if ($key === false) {
116 error(get_string('pluginnotenabled', 'auth', $auth), $url);
118 // move up the list
119 if ($key >= 1) {
120 $fsave = $authsenabled[$key];
121 $authsenabled[$key] = $authsenabled[$key - 1];
122 $authsenabled[$key - 1] = $fsave;
123 set_config('auth', implode(',', $authsenabled));
125 break;
127 default:
128 break;
131 // display strings
132 $txt = get_strings(array('authenticationplugins', 'users', 'administration',
133 'settings', 'edit', 'name', 'enable', 'disable',
134 'up', 'down', 'none'));
135 $txt->updown = "$txt->up/$txt->down";
137 // construct the display array, with enabled auth plugins at the top, in order
138 $displayauths = array();
139 $registrationauths = array();
140 $registrationauths[''] = $txt->disable;
141 foreach ($authsenabled as $auth) {
142 $authplugin = get_auth_plugin($auth);
143 /// Get the auth title (from core or own auth lang files)
144 $authtitle = get_string("auth_{$auth}title", "auth");
145 if ($authtitle == "[[auth_{$auth}title]]") {
146 $authtitle = get_string("auth_{$auth}title", "auth_{$auth}");
148 /// Apply titles
149 $displayauths[$auth] = $authtitle;
150 if ($authplugin->can_signup()) {
151 $registrationauths[$auth] = $authtitle;
155 foreach ($authsavailable as $auth) {
156 if (array_key_exists($auth, $displayauths)) {
157 continue; //already in the list
159 $authplugin = get_auth_plugin($auth);
160 /// Get the auth title (from core or own auth lang files)
161 $authtitle = get_string("auth_{$auth}title", "auth");
162 if ($authtitle == "[[auth_{$auth}title]]") {
163 $authtitle = get_string("auth_{$auth}title", "auth_{$auth}");
165 /// Apply titles
166 $displayauths[$auth] = $authtitle;
167 if ($authplugin->can_signup()) {
168 $registrationauths[$auth] = $authtitle;
172 // build the display table
173 $table = new flexible_table('auth_admin_table');
174 $table->define_columns(array('name', 'enable', 'order', 'settings'));
175 $table->define_headers(array($txt->name, $txt->enable, $txt->updown, $txt->settings));
176 $table->define_baseurl("{$CFG->wwwroot}/{$CFG->admin}/auth.php");
177 $table->set_attribute('id', 'blocks');
178 $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
179 $table->setup();
181 //add always enabled plugins first
182 $displayname = "<span>".$displayauths['manual']."</span>";
183 $settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&amp;auth=manual\">{$txt->settings}</a>";
184 $table->add_data(array($displayname, '', '', $settings));
185 $displayname = "<span>".$displayauths['nologin']."</span>";
186 $settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&amp;auth=nologin\">{$txt->settings}</a>";
187 $table->add_data(array($displayname, '', '', $settings));
190 // iterate through auth plugins and add to the display table
191 $updowncount = 1;
192 $authcount = count($authsenabled);
193 $url = "auth.php?sesskey=" . sesskey();
194 foreach ($displayauths as $auth => $name) {
195 if ($auth == 'manual' or $auth == 'nologin') {
196 continue;
198 // hide/show link
199 if (in_array($auth, $authsenabled)) {
200 $hideshow = "<a href=\"$url&amp;action=disable&amp;auth=$auth\">";
201 $hideshow .= "<img src=\"{$CFG->pixpath}/i/hide.gif\" class=\"icon\" alt=\"disable\" /></a>";
202 // $hideshow = "<a href=\"$url&amp;action=disable&amp;auth=$auth\"><input type=\"checkbox\" checked /></a>";
203 $enabled = true;
204 $displayname = "<span>$name</span>";
206 else {
207 $hideshow = "<a href=\"$url&amp;action=enable&amp;auth=$auth\">";
208 $hideshow .= "<img src=\"{$CFG->pixpath}/i/show.gif\" class=\"icon\" alt=\"enable\" /></a>";
209 // $hideshow = "<a href=\"$url&amp;action=enable&amp;auth=$auth\"><input type=\"checkbox\" /></a>";
210 $enabled = false;
211 $displayname = "<span class=\"dimmed_text\">$name</span>";
214 // up/down link (only if auth is enabled)
215 $updown = '';
216 if ($enabled) {
217 if ($updowncount > 1) {
218 $updown .= "<a href=\"$url&amp;action=up&amp;auth=$auth\">";
219 $updown .= "<img src=\"{$CFG->pixpath}/t/up.gif\" alt=\"up\" /></a>&nbsp;";
221 else {
222 $updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" class=\"icon\" alt=\"\" />&nbsp;";
224 if ($updowncount < $authcount) {
225 $updown .= "<a href=\"$url&amp;action=down&amp;auth=$auth\">";
226 $updown .= "<img src=\"{$CFG->pixpath}/t/down.gif\" alt=\"down\" /></a>";
228 else {
229 $updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" class=\"icon\" alt=\"\" />";
231 ++ $updowncount;
234 // settings link
235 $settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&amp;auth=$auth\">{$txt->settings}</a>";
237 // add a row to the table
238 $table->add_data(array($displayname, $hideshow, $updown, $settings));
241 // output form
242 admin_externalpage_print_header();
244 //print stus messages
245 if ($status !== '') {
246 notify($status, 'notifysuccess');
249 print_simple_box(get_string('configauthenticationplugins', 'admin'), 'center', '700');
251 $table->print_html();
253 ////////////////////////////////////////////////////////////////////////////////
255 $guestoptions = array();
256 $guestoptions[0] = get_string("hide");
257 $guestoptions[1] = get_string("show");
259 echo '<hr />';
261 echo '<form '.$CFG->frametarget.' id="adminsettings" method="post" action="auth.php">';
262 echo '<div class="settingsform clearfix">';
263 print_heading(get_string('auth_common_settings', 'auth'));
264 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
265 echo '<input type="hidden" name="action" value="save" />';
266 echo '<fieldset>';
267 ##echo '<table cellspacing="0" cellpadding="5" border="0" style="margin-left:auto;margin-right:auto">';
269 // User self registration
270 echo '<div class="form-item" id="admin-register">';
271 echo '<label for = "menuregister">' . get_string("selfregistration", "auth");
272 echo '<span class="form-shortname">registerauth</span>';
273 echo '</label>';
274 choose_from_menu($registrationauths, "register", $CFG->registerauth, "");
275 echo '<div class="description">' . get_string("selfregistration_help", "auth") . '</div>';
276 echo '</div>';
278 // Login as guest button enabled
279 echo '<div class="form-item" id="admin-guestloginbutton">';
280 echo '<label for = "menuguestloginbutton">' . get_string("guestloginbutton", "auth");
281 echo '<span class="form-shortname">guestloginbutton</span>';
282 echo '</label>';
283 choose_from_menu($guestoptions, "guestloginbutton", $CFG->guestloginbutton, "");
284 echo '<div class="description">' . get_string("showguestlogin", "auth") . '</div>';
285 echo '</div>';
287 /// An alternate url for the login form. It means we can use login forms that are integrated
288 /// into non-moodle pages
289 echo '<div class="form-item" id="admin-alternateloginurl">';
290 echo '<label for = "alternateloginurl">' . get_string("alternateloginurl", "auth");
291 echo '<span class="form-shortname">alternateloginurl</span>';
292 echo '</label>';
293 echo '<input type="text" size="60" name="alternateloginurl" id="alternateloginurl" value="'.s($CFG->alternateloginurl)."\" />\n";
294 echo '<div class="description">' . get_string("alternatelogin", "auth", htmlspecialchars($CFG->wwwroot.'/login/index.php')) . '</div>';
295 echo '</div>';
297 /// An alternate url for lost passwords. It means we can use external lost password
298 /// recovery for all users. Effectively disables built-in processes!!!
299 echo '<div class="form-item" id="admin-forgottenpasswordurl">';
300 echo '<label for = "forgottenpasswordurl">' . get_string("forgottenpasswordurl", "auth");
301 echo '<span class="form-shortname">forgottenpasswordurl</span>';
302 echo '</label>';
303 echo '<input type="text" size="60" name="forgottenpasswordurl" id="forgottenpasswordurl" value="'.s($CFG->forgottenpasswordurl)."\" />\n";
304 echo '<div class="description">' . get_string("forgottenpassword", "auth" ) . '</div>';
305 echo '</div>';
307 /// Instructions about login/password
308 /// to be showed to users
309 echo '<div class="form-item" id="admin-auth_instructions">';
310 echo '<label for = "auth_instructions">' . get_string("instructions", "auth");
311 echo '<span class="form-shortname">auth_instructions</span>';
312 echo '</label>';
313 echo '<textarea cols="30" rows="4" name="auth_instructions" id="auth_instructions">'.s($CFG->auth_instructions)."</textarea>\n";
314 echo '<div class="description">' . get_string("authinstructions", "auth") . '</div>';
315 echo '</div>';
317 echo '</fieldset>';
319 ////////////////////////////////////////////////////////////////////////////////
320 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges', 'admin').'" /></div>';
321 echo '</div>';
322 echo '</form>';
323 admin_externalpage_print_footer();