*
*/
-require_once dirname(dirname(__FILE__)) . '/config.php';
-require_once $CFG->libdir . '/tablelib.php';
+require_once('../config.php');
require_once($CFG->libdir.'/adminlib.php');
+require_once($CFG->libdir.'/tablelib.php');
$adminroot = admin_get_root();
admin_externalpage_setup('userauthentication', $adminroot);
+$action = optional_param('action', '', PARAM_ACTION);
+$auth = optional_param('auth', '', PARAM_SAFEDIR);
+
// get currently installed and enabled auth plugins
$authsavailable = get_list_of_plugins('auth');
-if (empty($CFG->auth_plugins_enabled)) {
- set_config('auth_plugins_enabled', $CFG->auth);
- $CFG->auth_plugins_enabled = $CFG->auth;
+
+//revert auth_plugins_enabled
+if (isset($CFG->auth_plugins_enabled)) {
+ set_config('auth', $CFG->auth_plugins_enabled);
+ delete_records('config', 'name', 'auth_plugins_enabled');
+ unset($CFG->auth_plugins_enabled);
}
-$authsenabled = explode(',', $CFG->auth_plugins_enabled);
-// save form
-if ($form = data_submitted()) {
+if (empty($CFG->auth)) {
+ $authsenabled = array();
+} else {
+ $authsenabled = explode(',', $CFG->auth);
+ $authsenabled = array_unique($authsenabled);
+}
- if (!confirm_sesskey()) {
- error(get_string('confirmsesskeybad', 'error'));
- }
+$key = array_search('manual', $authsenabled);
+if ($key !== false) {
+ unset($authsenabled[$key]); // manual is always enabled anyway
+ set_config('auth', implode(',', $authsenabled));
+}
- if (! isset($form->guestloginbutton)) {
- $form->guestloginbutton = 1;
- }
- if (empty($form->alternateloginurl)) {
- $form->alternateloginurl = '';
- }
- if (empty($form->register)) {
- $form->register = 'manual';
- }
- set_config('guestloginbutton', $form->guestloginbutton);
- set_config('alternateloginurl', $form->alternateloginurl);
- set_config('auth', $form->register);
-
- // add $CFG->auth to auth_plugins_enabled list
- if (!array_search($form->register, $authsenabled)) {
- $authsenabled[] = $form->register;
- $authsenabled = array_unique($authsenabled);
- set_config('auth_plugins_enabled', implode(',', $authsenabled));
- }
+if (!isset($CFG->registerauth)) {
+ set_config('registerauth', '');
+}
+
+if (!isset($CFG->auth_instructions)) {
+ set_config('auth_instructions', '');
+}
+
+if (!empty($auth) and !exists_auth_plugin($auth)) {
+ error(get_string('pluginnotinstalled', 'auth', $auth), $url);
}
-// grab GET/POST parameters
-$params = new object();
-$params->action = optional_param('action', '', PARAM_ACTION);
-$params->auth = optional_param('auth', $CFG->auth, PARAM_ALPHANUM);
////////////////////////////////////////////////////////////////////////////////
// process actions
-switch ($params->action) {
+$status = '';
+
+switch ($action) {
+
+ case 'save':
+ if (data_submitted() and confirm_sesskey()) {
+
+ // save settings
+ set_config('guestloginbutton', required_param('guestloginbutton', PARAM_BOOL));
+ set_config('alternateloginurl', stripslashes(trim(required_param('alternateloginurl', PARAM_RAW))));
+ set_config('registerauth', required_param('register', PARAM_SAFEDIR));
+ set_config('auth_instructions', stripslashes(trim(required_param('auth_instructions', PARAM_RAW))));
+
+ // enable registerauth in $CFG->auth if needed
+ if (!empty($CFG->registerauth) and !in_array($CFG->registerauth, $authsenabled)) {
+ $authsenabled[] = $CFG->registerauth;
+ set_config('auth', implode(',', $authsenabled));
+ }
+ $status = get_string('changessaved');
+ }
+ break;
case 'disable':
- // remove from enabled list
- $key = array_search($params->auth, $authsenabled);
- if ($key !== false and $params->auth != $CFG->auth) {
+ // remove from enabled list
+ $key = array_search($auth, $authsenabled);
+ if ($key !== false) {
unset($authsenabled[$key]);
- set_config('auth_plugins_enabled', implode(',', $authsenabled));
+ set_config('auth', implode(',', $authsenabled));
+ }
+
+ if ($auth == $CFG->registerauth) {
+ set_config('registerauth', '');
}
break;
-
+
case 'enable':
- // check auth plugin is valid first
- if (!exists_auth_plugin($params->auth)) {
- error(get_string('pluginnotinstalled', 'auth', $params->auth), $url);
- }
// add to enabled list
- if (!array_search($params->auth, $authsenabled)) {
- $authsenabled[] = $params->auth;
+ if (!in_array($auth, $authsenabled)) {
+ $authsenabled[] = $auth;
$authsenabled = array_unique($authsenabled);
- set_config('auth_plugins_enabled', implode(',', $authsenabled));
+ set_config('auth', implode(',', $authsenabled));
}
break;
-
+
case 'down':
- $key = array_search($params->auth, $authsenabled);
+ $key = array_search($auth, $authsenabled);
// check auth plugin is valid
if ($key === false) {
- error(get_string('pluginnotenabled', 'auth', $params->auth), $url);
+ error(get_string('pluginnotenabled', 'auth', $auth), $url);
}
// move down the list
if ($key < (count($authsenabled) - 1)) {
$fsave = $authsenabled[$key];
$authsenabled[$key] = $authsenabled[$key + 1];
$authsenabled[$key + 1] = $fsave;
- set_config('auth_plugins_enabled', implode(',', $authsenabled));
+ set_config('auth', implode(',', $authsenabled));
}
break;
-
+
case 'up':
- $key = array_search($params->auth, $authsenabled);
+ $key = array_search($auth, $authsenabled);
// check auth is valid
if ($key === false) {
- error(get_string('pluginnotenabled', 'auth', $params->auth), $url);
+ error(get_string('pluginnotenabled', 'auth', $auth), $url);
}
// move up the list
if ($key >= 1) {
$fsave = $authsenabled[$key];
$authsenabled[$key] = $authsenabled[$key - 1];
$authsenabled[$key - 1] = $fsave;
- set_config('auth_plugins_enabled', implode(',', $authsenabled));
+ set_config('auth', implode(',', $authsenabled));
}
break;
-
- case 'save':
- // save settings
- set_config('auth_plugins_enabled', implode(',', $authsenabled));
- set_config('auth', $authsenabled[0]);
- redirect("auth.php?sesskey=$USER->sesskey", get_string('changessaved'), 1);
- break;
default:
break;
// construct the display array, with enabled auth plugins at the top, in order
$displayauths = array();
$registrationauths = array();
-$registrationauths['manual'] = $txt->disable;
+$registrationauths[''] = $txt->disable;
foreach ($authsenabled as $auth) {
- $displayauths[$auth] = get_string("auth_{$auth}title", 'auth');
$authplugin = get_auth_plugin($auth);
+ $displayauths[$auth] = get_string("auth_{$auth}title", 'auth');
if (method_exists($authplugin, 'user_signup')) {
$registrationauths[$auth] = get_string("auth_{$auth}title", 'auth');
- }
+ }
}
+
foreach ($authsavailable as $auth) {
- if (!array_key_exists($auth, $displayauths)) {
- $displayauths[$auth] = get_string("auth_{$auth}title", 'auth');
+ if (array_key_exists($auth, $displayauths)) {
+ continue; //already in the list
}
$authplugin = get_auth_plugin($auth);
+ $displayauths[$auth] = get_string("auth_{$auth}title", 'auth');
if (method_exists($authplugin, 'user_signup')) {
$registrationauths[$auth] = get_string("auth_{$auth}title", 'auth');
- }
+ }
}
// build the display table
$table->set_attribute('cellpadding', '5');
$table->setup();
+//add always enabled plugins first
+$displayname = "<span>".$displayauths['manual']."</span>";
+$settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&auth=manual\">{$txt->settings}</a>";
+$table->add_data(array($displayname, '', '', $settings));
+$displayname = "<span>".$displayauths['nologin']."</span>";
+$settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&auth=nologin\">{$txt->settings}</a>";
+$table->add_data(array($displayname, '', '', $settings));
+
+
// iterate through auth plugins and add to the display table
$updowncount = 1;
$authcount = count($authsenabled);
$url = "auth.php?sesskey=" . sesskey();
foreach ($displayauths as $auth => $name) {
+ if ($auth == 'manual' or $auth == 'nologin') {
+ continue;
+ }
// hide/show link
if (in_array($auth, $authsenabled)) {
$hideshow = "<a href=\"$url&action=disable&auth=$auth\">";
}
++ $updowncount;
}
-
+
// settings link
$settings = "<a href=\"auth_config.php?sesskey={$USER->sesskey}&auth=$auth\">{$txt->settings}</a>";
// output form
admin_externalpage_print_header($adminroot);
+
+//print stus messages
+if ($status !== '') {
+ notify($status, 'notifysuccess');
+}
+
print_simple_box(get_string('configauthenticationplugins', 'admin'), 'center', '700');
-echo "<form $CFG->frametarget id=\"authmenu\" method=\"post\" action=\"auth.php\">";
-echo "<fieldset class=\"invisiblefieldset\"><input type=\"hidden\" name=\"sesskey\" value=\"".$USER->sesskey."\" /></fieldset>";
print_table($table);
////////////////////////////////////////////////////////////////////////////////
+$guestoptions = array();
$guestoptions[0] = get_string("hide");
$guestoptions[1] = get_string("show");
echo '<hr />';
print_heading(get_string('auth_common_settings', 'auth'));
+
+echo '<form '.$CFG->frametarget.' id="authmenu" method="post" action="auth.php">';
+echo '<fieldset class="invisiblefieldset"><input type="hidden" name="sesskey" value="'.sesskey().'" />';
+echo '<input type="hidden" name="action" value="save" /></fieldset>';
+
echo '<table cellspacing="0" cellpadding="5" border="0" style="margin-left:auto;margin-right:auto">';
// User self registration
echo "<tr valign=\"top\">\n";
-echo "<td align=\"right\" style=\"white-space:nowrap\">\n";
+echo "<td align=\"right\" style=\"white-space:nowrap\">\n<label for=\"menuregister\">";
print_string("selfregistration", "auth");
-echo ":</td>\n";
+echo "</label></td>\n";
echo "<td>\n";
-choose_from_menu($registrationauths, "register", $CFG->auth, "");
+choose_from_menu($registrationauths, "register", $CFG->registerauth, "");
echo "</td>\n";
echo "<td>\n";
print_string("selfregistration_help", "auth");
// Login as guest button enabled
echo "<tr valign=\"top\">\n";
-echo "<td style=\"white-space:nowrap;text-align:right\">\n";
+echo "<td style=\"white-space:nowrap;text-align:right\">\n<label for=\"menuguestloginbutton\">";
print_string("guestloginbutton", "auth");
-echo ":</td>\n";
+echo "</label></td>\n";
echo "<td>\n";
choose_from_menu($guestoptions, "guestloginbutton", $CFG->guestloginbutton, "");
echo "</td>\n";
/// An alternate url for the login form. It means we can use login forms that are integrated
/// into non-moodle pages
echo "<tr valign=\"top\">\n";
-echo "<td align=\"right\" style=\"white-space:nowrap\">\n";
+echo "<td align=\"right\" style=\"white-space:nowrap\">\n<label for=\"alternateloginurl\">";
print_string('alternateloginurl', 'auth');
-echo "</td>\n";
+echo "</label></td>\n";
echo "<td>\n";
-echo '<input type="text" size="40" name="alternateloginurl" alt="'.get_string('alternateloginurl', 'auth').'" value="'.$CFG->alternateloginurl."\" />\n";
+echo '<input type="text" size="40" name="alternateloginurl" id="alternateloginurl" value="'.$CFG->alternateloginurl."\" />\n";
echo "</td>\n";
echo "<td>\n";
print_string('alternatelogin', 'auth', htmlspecialchars($CFG->wwwroot.'/login/index.php'));
echo "</td>\n";
echo "</tr>\n";
+echo "<tr valign=\"top\">\n";
+echo "<td align=\"right\" style=\"white-space:nowrap\">\n<label for=\"auth_instructions\">";
+print_string('instructions', 'auth');
+echo "</label></td>\n";
+echo "<td>\n";
+echo '<textarea cols="30" rows="4" name="auth_instructions" id="auth_instructions">'.s($CFG->auth_instructions)."</textarea>\n";
+echo "</td>\n";
+echo "<td>\n";
+print_string('authinstructions', 'auth');
+echo "</td>\n";
+echo "</tr>\n";
+
echo "</table>\n";
////////////////////////////////////////////////////////////////////////////////
-
echo '<div style="text-align:center"><input type="submit" value="'.get_string('savechanges').'" /></div>';
echo '</form>';
admin_externalpage_print_footer($adminroot);
/**
* Edit configuration for an individual auth plugin
*/
-
+
require_once '../config.php';
require_once $CFG->libdir.'/adminlib.php';
$adminroot = admin_get_root();
admin_externalpage_setup('userauthentication', $adminroot);
-$auth = optional_param('auth', '', PARAM_SAFEDIR);
+$auth = required_param('auth', PARAM_SAFEDIR);
$authplugin = get_auth_plugin($auth);
$err = array();
if (preg_match('/^lockconfig_(.+?)$/', $name, $matches)) {
$plugin = "auth/$auth";
$name = $matches[1];
- if (!set_config($name, $value, $plugin)) {
- notify("Problem saving config $name as $value for plugin $plugin");
+ if (!set_config($name, $value, $plugin)) {
+ error("Problem saving config $name as $value for plugin $plugin");
}
}
}
- redirect("auth.php?sesskey=$USER->sesskey", get_string("changessaved"), 1);
+ redirect("auth.php?sesskey=$USER->sesskey");
exit;
}
} else {
foreach ($err as $key => $value) {
$focus = "form.$key";
}
- }
+ }
} else {
$frm = get_config("auth/$auth");
}
print_string("auth_{$auth}description", 'auth');
print_simple_box_end();
echo "<hr />\n";
-$authplugin->config_form($frm, $err);
+$authplugin->config_form($frm, $err, $user_fields);
print_simple_box_end();
echo '<center><p><input type="submit" value="' . get_string("savechanges") . "\" /></p></center>\n";
echo "</form>\n";
// Good enough for most auth plugins
// but some may want a custom one if they are offering
// other options
-// Note: lockconfig_ fields have special handling.
+// Note: lockconfig_ fields have special handling.
function print_auth_lock_options ($auth, $user_fields, $helptext, $retrieveopts, $updateopts) {
echo '<tr><td colspan="3">';
'onlogin' => get_string('update_onlogin', 'auth'));
$updateextoptions = array('0' => get_string('update_never', 'auth'),
'1' => get_string('update_onupdate', 'auth'));
-
+
$pluginconfig = get_config("auth/$auth");
// helptext is on a field with rowspan
$fieldname = get_string($fieldname);
}
- echo '<tr valign="top"><td align="right">';
- echo $fieldname;
- echo '</td><td>';
-
if ($retrieveopts) {
$varname = 'field_map_' . $field;
- echo "<input name=\"lockconfig_{$varname}\" type=\"text\" size=\"30\" value=\"{$pluginconfig->$varname}\" />";
+ echo '<tr valign="top"><td align="right">';
+ echo '<label for="lockconfig_'.$varname.'">'.$fieldname.'</label>';
+ echo '</td><td>';
+
+ echo "<input id=\"lockconfig_{$varname}\" name=\"lockconfig_{$varname}\" type=\"text\" size=\"30\" value=\"{$pluginconfig->$varname}\" />";
echo '<div align="right">';
- echo get_string('auth_updatelocal', 'auth') . ' ';
+ echo '<label for="menulockconfig_field_updatelocal_'.$field.'">'.get_string('auth_updatelocal', 'auth') . '</label> ';
choose_from_menu($updatelocaloptions, "lockconfig_field_updatelocal_{$field}", $pluginconfig->{"field_updatelocal_$field"}, "");
echo '<br />';
if ($updateopts) {
- echo get_string('auth_updateremote', 'auth') . ' ';
- ' ';
+ echo '<label for="menulockconfig_field_updateremote_'.$field.'">'.get_string('auth_updateremote', 'auth') . '</label> ';
choose_from_menu($updateextoptions, "lockconfig_field_updateremote_{$field}", $pluginconfig->{"field_updateremote_$field"}, "");
echo '<br />';
}
- echo get_string('auth_fieldlock', 'auth') . ' ';
+ echo '<label for="menulockconfig_field_lock_'.$field.'">'.get_string('auth_fieldlock', 'auth') . '</label> ';
choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
echo '</div>';
} else {
+ echo '<tr valign="top"><td align="right">';
+ echo '<label for="menulockconfig_field_lock_'.$field.'">'.$fieldname.'</label>';
+ echo '</td><td>';
choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
}
echo '</td>';