3 * Edit configuration for an individual auth plugin
6 require_once '../config.php';
7 require_once $CFG->libdir
.'/adminlib.php';
9 admin_externalpage_setup('userauthentication');
10 $auth = required_param('auth', PARAM_SAFEDIR
);
11 $authplugin = get_auth_plugin($auth);
14 // save configuration changes
15 if ($frm = data_submitted()) {
17 if (!confirm_sesskey()) {
18 error(get_string('confirmsesskeybad', 'error'));
21 $frm = stripslashes_recursive($frm);
23 $authplugin->validate_form($frm, $err);
25 if (count($err) == 0) {
28 if ($authplugin->process_config($frm)) {
30 // save field lock configuration
31 foreach ($frm as $name => $value) {
32 if (preg_match('/^lockconfig_(.+?)$/', $name, $matches)) {
33 $plugin = "auth/$auth";
35 if (!set_config($name, $value, $plugin)) {
36 error("Problem saving config $name as $value for plugin $plugin");
44 foreach ($err as $key => $value) {
49 $frm = get_config("auth/$auth");
52 $user_fields = array("firstname", "lastname", "email", "phone1", "phone2", "department", "address", "city", "country", "description", "idnumber", "lang");
54 $modules = get_list_of_plugins('auth');
55 foreach ($modules as $module) {
56 $options[$module] = get_string("auth_{$module}title", 'auth');
60 // output configuration form
61 admin_externalpage_print_header();
63 // choose an authentication method
64 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, $user_fields);
77 print_simple_box_end();
78 echo '<p style="text-align: center"><input type="submit" value="' . get_string("savechanges") . "\" /></p>\n";
82 admin_externalpage_print_footer();
85 /// Functions /////////////////////////////////////////////////////////////////
87 // Good enough for most auth plugins
88 // but some may want a custom one if they are offering
90 // Note: lockconfig_ fields have special handling.
91 function print_auth_lock_options ($auth, $user_fields, $helptext, $retrieveopts, $updateopts) {
93 echo '<tr><td colspan="3">';
95 print_heading(get_string('auth_data_mapping', 'auth'));
97 print_heading(get_string('auth_fieldlocks', 'auth'));
101 $lockoptions = array ('unlocked' => get_string('unlocked', 'auth'),
102 'unlockedifempty' => get_string('unlockedifempty', 'auth'),
103 'locked' => get_string('locked', 'auth'));
104 $updatelocaloptions = array('oncreate' => get_string('update_oncreate', 'auth'),
105 'onlogin' => get_string('update_onlogin', 'auth'));
106 $updateextoptions = array('0' => get_string('update_never', 'auth'),
107 '1' => get_string('update_onupdate', 'auth'));
109 $pluginconfig = get_config("auth/$auth");
111 // helptext is on a field with rowspan
112 if (empty($helptext)) {
113 $helptext = ' ';
116 foreach ($user_fields as $field) {
118 // Define some vars we'll work with
119 if (!isset($pluginconfig->{"field_map_$field"})) {
120 $pluginconfig->{"field_map_$field"} = '';
122 if (!isset($pluginconfig->{"field_updatelocal_$field"})) {
123 $pluginconfig->{"field_updatelocal_$field"} = '';
125 if (!isset($pluginconfig->{"field_updateremote_$field"})) {
126 $pluginconfig->{"field_updateremote_$field"} = '';
128 if (!isset($pluginconfig->{"field_lock_$field"})) {
129 $pluginconfig->{"field_lock_$field"} = '';
132 // define the fieldname we display to the user
134 if ($fieldname === 'lang') {
135 $fieldname = get_string('language');
136 } elseif (preg_match('/^(.+?)(\d+)$/', $fieldname, $matches)) {
137 $fieldname = get_string($matches[1]) . ' ' . $matches[2];
139 $fieldname = get_string($fieldname);
143 $varname = 'field_map_' . $field;
145 echo '<tr valign="top"><td align="right">';
146 echo '<label for="lockconfig_'.$varname.'">'.$fieldname.'</label>';
149 echo "<input id=\"lockconfig_{$varname}\" name=\"lockconfig_{$varname}\" type=\"text\" size=\"30\" value=\"{$pluginconfig->$varname}\" />";
150 echo '<div style="text-align: right">';
151 echo '<label for="menulockconfig_field_updatelocal_'.$field.'">'.get_string('auth_updatelocal', 'auth') . '</label> ';
152 choose_from_menu($updatelocaloptions, "lockconfig_field_updatelocal_{$field}", $pluginconfig->{"field_updatelocal_$field"}, "");
155 echo '<label for="menulockconfig_field_updateremote_'.$field.'">'.get_string('auth_updateremote', 'auth') . '</label> ';
156 choose_from_menu($updateextoptions, "lockconfig_field_updateremote_{$field}", $pluginconfig->{"field_updateremote_$field"}, "");
161 echo '<label for="menulockconfig_field_lock_'.$field.'">'.get_string('auth_fieldlock', 'auth') . '</label> ';
162 choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
165 echo '<tr valign="top"><td align="right">';
166 echo '<label for="menulockconfig_field_lock_'.$field.'">'.$fieldname.'</label>';
168 choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
171 if (!empty($helptext)) {
172 echo '<td rowspan="' . count($user_fields) . '">' . $helptext . '</td>';