mnethosturl was never being restored. Detected while checking MDL-9309
[pfb-moodle.git] / admin / auth.php
blobd6ab820a1ac48aaa55ee7e11f1bad184732192d0
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 $adminroot = admin_get_root();
15 admin_externalpage_setup('userauthentication', $adminroot);
17 $action = optional_param('action', '', PARAM_ACTION);
18 $auth = optional_param('auth', '', PARAM_SAFEDIR);
20 // get currently installed and enabled auth plugins
21 $authsavailable = get_list_of_plugins('auth');
23 //revert auth_plugins_enabled
24 if (isset($CFG->auth_plugins_enabled)) {
25 set_config('auth', $CFG->auth_plugins_enabled);
26 delete_records('config', 'name', 'auth_plugins_enabled');
27 unset($CFG->auth_plugins_enabled);
30 get_enabled_auth_plugins(true); // fix the list of enabled auths
31 if (empty($CFG->auth)) {
32 $authsenabled = array();
33 } else {
34 $authsenabled = explode(',', $CFG->auth);
37 if (!isset($CFG->registerauth)) {
38 set_config('registerauth', '');
41 if (!isset($CFG->auth_instructions)) {
42 set_config('auth_instructions', '');
45 if (!empty($auth) and !exists_auth_plugin($auth)) {
46 error(get_string('pluginnotinstalled', 'auth', $auth), $url);
50 ////////////////////////////////////////////////////////////////////////////////
51 // process actions
53 $status = '';
55 switch ($action) {
57 case 'save':
58 if (data_submitted() and confirm_sesskey()) {
60 // save settings
61 set_config('guestloginbutton', required_param('guestloginbutton', PARAM_BOOL));
62 set_config('alternateloginurl', stripslashes(trim(required_param('alternateloginurl', 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 $displayauths[$auth] = get_string("auth_{$auth}title", 'auth');
144 if ($authplugin->can_signup()) {
145 $registrationauths[$auth] = get_string("auth_{$auth}title", 'auth');
149 foreach ($authsavailable as $auth) {
150 if (array_key_exists($auth, $displayauths)) {
151 continue; //already in the list
153 $authplugin = get_auth_plugin($auth);
154 $displayauths[$auth] = get_string("auth_{$auth}title", 'auth');
155 if ($authplugin->can_signup()) {
156 $registrationauths[$auth] = get_string("auth_{$auth}title", 'auth');
160 // build the display table
161 $table = new flexible_table('auth_admin_table');
162 $table->define_columns(array('name', 'enable', 'order', 'settings'));
163 $table->define_headers(array($txt->name, $txt->enable, $txt->updown, $txt->settings));
164 $table->define_baseurl("{$CFG->wwwroot}/{$CFG->admin}/auth.php");
165 $table->set_attribute('id', 'blocks');
166 $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
167 $table->setup();
169 //add always enabled plugins first
170 $displayname = "<span>".$displayauths['manual']."</span>";
171 $settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&amp;auth=manual\">{$txt->settings}</a>";
172 $table->add_data(array($displayname, '', '', $settings));
173 $displayname = "<span>".$displayauths['nologin']."</span>";
174 $settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&amp;auth=nologin\">{$txt->settings}</a>";
175 $table->add_data(array($displayname, '', '', $settings));
178 // iterate through auth plugins and add to the display table
179 $updowncount = 1;
180 $authcount = count($authsenabled);
181 $url = "auth.php?sesskey=" . sesskey();
182 foreach ($displayauths as $auth => $name) {
183 if ($auth == 'manual' or $auth == 'nologin') {
184 continue;
186 // hide/show link
187 if (in_array($auth, $authsenabled)) {
188 $hideshow = "<a href=\"$url&amp;action=disable&amp;auth=$auth\">";
189 $hideshow .= "<img src=\"{$CFG->pixpath}/i/hide.gif\" class=\"icon\" alt=\"disable\" /></a>";
190 // $hideshow = "<a href=\"$url&amp;action=disable&amp;auth=$auth\"><input type=\"checkbox\" checked /></a>";
191 $enabled = true;
192 $displayname = "<span>$name</span>";
194 else {
195 $hideshow = "<a href=\"$url&amp;action=enable&amp;auth=$auth\">";
196 $hideshow .= "<img src=\"{$CFG->pixpath}/i/show.gif\" class=\"icon\" alt=\"enable\" /></a>";
197 // $hideshow = "<a href=\"$url&amp;action=enable&amp;auth=$auth\"><input type=\"checkbox\" /></a>";
198 $enabled = false;
199 $displayname = "<span class=\"dimmed_text\">$name</span>";
202 // up/down link (only if auth is enabled)
203 $updown = '';
204 if ($enabled) {
205 if ($updowncount > 1) {
206 $updown .= "<a href=\"$url&amp;action=up&amp;auth=$auth\">";
207 $updown .= "<img src=\"{$CFG->pixpath}/t/up.gif\" alt=\"up\" /></a>&nbsp;";
209 else {
210 $updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" class=\"icon\" alt=\"\" />&nbsp;";
212 if ($updowncount < $authcount) {
213 $updown .= "<a href=\"$url&amp;action=down&amp;auth=$auth\">";
214 $updown .= "<img src=\"{$CFG->pixpath}/t/down.gif\" alt=\"down\" /></a>";
216 else {
217 $updown .= "<img src=\"{$CFG->pixpath}/spacer.gif\" class=\"icon\" alt=\"\" />";
219 ++ $updowncount;
222 // settings link
223 $settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&amp;auth=$auth\">{$txt->settings}</a>";
225 // add a row to the table
226 $table->add_data(array($displayname, $hideshow, $updown, $settings));
229 // output form
230 admin_externalpage_print_header($adminroot);
232 //print stus messages
233 if ($status !== '') {
234 notify($status, 'notifysuccess');
237 print_simple_box(get_string('configauthenticationplugins', 'admin'), 'center', '700');
239 $table->print_html();
241 ////////////////////////////////////////////////////////////////////////////////
243 $guestoptions = array();
244 $guestoptions[0] = get_string("hide");
245 $guestoptions[1] = get_string("show");
247 echo '<hr />';
249 echo '<form '.$CFG->frametarget.' id="adminsettings" method="post" action="auth.php">';
250 echo '<div class="settingsform">';
251 print_heading(get_string('auth_common_settings', 'auth'));
252 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
253 echo '<input type="hidden" name="action" value="save" />';
254 echo '<fieldset>';
255 ##echo '<table cellspacing="0" cellpadding="5" border="0" style="margin-left:auto;margin-right:auto">';
257 // User self registration
258 echo '<div class="form-item" id="admin-register">';
259 echo '<label for = "menuregister">' . get_string("selfregistration", "auth");
260 echo '<span class="form-shortname">registerauth</span>';
261 echo '</label>';
262 choose_from_menu($registrationauths, "register", $CFG->registerauth, "");
263 echo '<div class="description">' . get_string("selfregistration_help", "auth") . '</div>';
264 echo '</div>';
266 // Login as guest button enabled
267 echo '<div class="form-item" id="admin-guestloginbutton">';
268 echo '<label for = "menuguestloginbutton">' . get_string("guestloginbutton", "auth");
269 echo '<span class="form-shortname">guestloginbutton</span>';
270 echo '</label>';
271 choose_from_menu($guestoptions, "guestloginbutton", $CFG->guestloginbutton, "");
272 echo '<div class="description">' . get_string("showguestlogin", "auth") . '</div>';
273 echo '</div>';
275 /// An alternate url for the login form. It means we can use login forms that are integrated
276 /// into non-moodle pages
277 echo '<div class="form-item" id="admin-alternateloginurl">';
278 echo '<label for = "alternateloginurl">' . get_string("alternateloginurl", "auth");
279 echo '<span class="form-shortname">alternateloginurl</span>';
280 echo '</label>';
281 echo '<input type="text" size="60" name="alternateloginurl" id="alternateloginurl" value="'.$CFG->alternateloginurl."\" />\n";
282 echo '<div class="description">' . get_string("alternatelogin", "auth", htmlspecialchars($CFG->wwwroot.'/login/index.php')) . '</div>';
283 echo '</div>';
285 /// Instructions about login/password
286 /// to be showed to users
287 echo '<div class="form-item" id="admin-auth_instructions">';
288 echo '<label for = "auth_instructions">' . get_string("instructions", "auth");
289 echo '<span class="form-shortname">auth_instructions</span>';
290 echo '</label>';
291 echo '<textarea cols="30" rows="4" name="auth_instructions" id="auth_instructions">'.s($CFG->auth_instructions)."</textarea>\n";
292 echo '<div class="description">' . get_string("authinstructions", "auth") . '</div>';
293 echo '</div>';
295 echo '</fieldset>';
297 ////////////////////////////////////////////////////////////////////////////////
298 echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges', 'admin').'" /></div>';
299 echo '</div>';
300 echo '</form>';
301 admin_externalpage_print_footer($adminroot);