3 * Edit configuration for an individual auth plugin
6 require_once '../config.php';
7 require_once $CFG->libdir
.'/adminlib.php';
9 $adminroot = admin_get_root();
10 admin_externalpage_setup('userauthentication', $adminroot);
11 $auth = optional_param('auth', '', PARAM_SAFEDIR
);
12 $authplugin = get_auth_plugin($auth);
15 // save configuration changes
16 if ($frm = data_submitted()) {
18 if (!confirm_sesskey()) {
19 error(get_string('confirmsesskeybad', 'error'));
22 if (method_exists($authplugin, 'validate_form')) {
23 $authplugin->validate_form($frm, $err);
26 if (count($err) == 0) {
29 if ($authplugin->process_config($frm)) {
31 // save field lock configuration
32 foreach ($frm as $name => $value) {
33 if (preg_match('/^lockconfig_(.+?)$/', $name, $matches)) {
34 $plugin = "auth/$auth";
36 if (!set_config($name, $value, $plugin)) {
37 notify("Problem saving config $name as $value for plugin $plugin");
41 redirect("auth.php?sesskey=$USER->sesskey", get_string("changessaved"), 1);
45 foreach ($err as $key => $value) {
50 $frm = get_config("auth/$auth");
53 $user_fields = array("firstname", "lastname", "email", "phone1", "phone2", "department", "address", "city", "country", "description", "idnumber", "lang");
55 $modules = get_list_of_plugins('auth');
56 foreach ($modules as $module) {
57 $options[$module] = get_string("auth_{$module}title", 'auth');
61 // output configuration form
62 admin_externalpage_print_header($adminroot);
64 // choose an authentication method
65 echo "<form $CFG->frametarget id=\"authmenu\" method=\"post\" action=\"auth_config.php\">\n";
66 echo "<input type=\"hidden\" name=\"sesskey\" value=\"".$USER->sesskey
."\" />\n";
67 echo "<input type=\"hidden\" name=\"auth\" value=\"".$auth."\" />\n";
69 // auth plugin description
70 print_simple_box_start('center', '80%');
71 print_heading($options[$auth]);
72 print_simple_box_start('center', '60%', '', 5, 'informationbox');
73 print_string("auth_{$auth}description", 'auth');
74 print_simple_box_end();
76 $authplugin->config_form($frm, $err);
77 print_simple_box_end();
78 echo '<center><p><input type="submit" value="' . get_string("savechanges") . "\" /></p></center>\n";
81 admin_externalpage_print_footer($adminroot);
84 /// Functions /////////////////////////////////////////////////////////////////
86 // Good enough for most auth plugins
87 // but some may want a custom one if they are offering
89 // Note: lockconfig_ fields have special handling.
90 function print_auth_lock_options ($auth, $user_fields, $helptext, $retrieveopts, $updateopts) {
92 echo '<tr><td colspan="3">';
94 print_heading(get_string('auth_data_mapping', 'auth'));
96 print_heading(get_string('auth_fieldlocks', 'auth'));
100 $lockoptions = array ('unlocked' => get_string('unlocked', 'auth'),
101 'unlockedifempty' => get_string('unlockedifempty', 'auth'),
102 'locked' => get_string('locked', 'auth'));
103 $updatelocaloptions = array('oncreate' => get_string('update_oncreate', 'auth'),
104 'onlogin' => get_string('update_onlogin', 'auth'));
105 $updateextoptions = array('0' => get_string('update_never', 'auth'),
106 '1' => get_string('update_onupdate', 'auth'));
108 $pluginconfig = get_config("auth/$auth");
110 // helptext is on a field with rowspan
111 if (empty($helptext)) {
112 $helptext = ' ';
115 foreach ($user_fields as $field) {
117 // Define some vars we'll work with
118 if (!isset($pluginconfig->{"field_map_$field"})) {
119 $pluginconfig->{"field_map_$field"} = '';
121 if (!isset($pluginconfig->{"field_updatelocal_$field"})) {
122 $pluginconfig->{"field_updatelocal_$field"} = '';
124 if (!isset($pluginconfig->{"field_updateremote_$field"})) {
125 $pluginconfig->{"field_updateremote_$field"} = '';
127 if (!isset($pluginconfig->{"field_lock_$field"})) {
128 $pluginconfig->{"field_lock_$field"} = '';
131 // define the fieldname we display to the user
133 if ($fieldname === 'lang') {
134 $fieldname = get_string('language');
135 } elseif (preg_match('/^(.+?)(\d+)$/', $fieldname, $matches)) {
136 $fieldname = get_string($matches[1]) . ' ' . $matches[2];
138 $fieldname = get_string($fieldname);
141 echo '<tr valign="top"><td align="right">';
146 $varname = 'field_map_' . $field;
148 echo "<input name=\"lockconfig_{$varname}\" type=\"text\" size=\"30\" value=\"{$pluginconfig->$varname}\" />";
149 echo '<div align="right">';
150 echo get_string('auth_updatelocal', 'auth') . ' ';
151 choose_from_menu($updatelocaloptions, "lockconfig_field_updatelocal_{$field}", $pluginconfig->{"field_updatelocal_$field"}, "");
154 echo get_string('auth_updateremote', 'auth') . ' ';
156 choose_from_menu($updateextoptions, "lockconfig_field_updateremote_{$field}", $pluginconfig->{"field_updateremote_$field"}, "");
161 echo get_string('auth_fieldlock', 'auth') . ' ';
162 choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
165 choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
168 if (!empty($helptext)) {
169 echo '<td rowspan="' . count($user_fields) . '">' . $helptext . '</td>';