Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / admin / auth_config.php
bloba75f4ed20f6f824565532aa73b7f23bdb86cf77d
1 <?php
2 /**
3 * Edit configuration for an individual auth plugin
4 */
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);
12 $err = array();
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) {
27 // save plugin config
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";
34 $name = $matches[1];
35 if (!set_config($name, $value, $plugin)) {
36 error("Problem saving config $name as $value for plugin $plugin");
40 redirect("auth.php");
41 exit;
43 } else {
44 foreach ($err as $key => $value) {
45 $focus = "form.$key";
48 } else {
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');
58 asort($options);
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";
65 echo "<div>\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();
75 echo "<hr />\n";
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";
79 echo "</div>\n";
80 echo "</form>\n";
82 admin_externalpage_print_footer();
83 exit;
85 /// Functions /////////////////////////////////////////////////////////////////
87 // Good enough for most auth plugins
88 // but some may want a custom one if they are offering
89 // other options
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">';
94 if ($retrieveopts) {
95 print_heading(get_string('auth_data_mapping', 'auth'));
96 } else {
97 print_heading(get_string('auth_fieldlocks', 'auth'));
99 echo '</td></tr>';
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 = '&nbsp;';
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
133 $fieldname = $field;
134 if ($fieldname === 'lang') {
135 $fieldname = get_string('language');
136 } elseif (preg_match('/^(.+?)(\d+)$/', $fieldname, $matches)) {
137 $fieldname = get_string($matches[1]) . ' ' . $matches[2];
138 } else {
139 $fieldname = get_string($fieldname);
142 if ($retrieveopts) {
143 $varname = 'field_map_' . $field;
145 echo '<tr valign="top"><td align="right">';
146 echo '<label for="lockconfig_'.$varname.'">'.$fieldname.'</label>';
147 echo '</td><td>';
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>&nbsp;';
152 choose_from_menu($updatelocaloptions, "lockconfig_field_updatelocal_{$field}", $pluginconfig->{"field_updatelocal_$field"}, "");
153 echo '<br />';
154 if ($updateopts) {
155 echo '<label for="menulockconfig_field_updateremote_'.$field.'">'.get_string('auth_updateremote', 'auth') . '</label>&nbsp;';
156 choose_from_menu($updateextoptions, "lockconfig_field_updateremote_{$field}", $pluginconfig->{"field_updateremote_$field"}, "");
157 echo '<br />';
161 echo '<label for="menulockconfig_field_lock_'.$field.'">'.get_string('auth_fieldlock', 'auth') . '</label>&nbsp;';
162 choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
163 echo '</div>';
164 } else {
165 echo '<tr valign="top"><td align="right">';
166 echo '<label for="menulockconfig_field_lock_'.$field.'">'.$fieldname.'</label>';
167 echo '</td><td>';
168 choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
170 echo '</td>';
171 if (!empty($helptext)) {
172 echo '<td rowspan="' . count($user_fields) . '">' . $helptext . '</td>';
173 $helptext = '';
175 echo '</tr>';