MDL-10689:
[moodle-linuxchix.git] / admin / auth_config.php
bloba9cb8fd18ab3e2c7991ad0006c3b01bdd0dc3291
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 /// Get the auth title (from core or own auth lang files)
55 $authtitle = get_string("auth_{$auth}title", "auth");
56 if ($authtitle == "[[auth_{$auth}title]]") {
57 $authtitle = get_string("auth_{$auth}title", "auth_{$auth}");
59 /// Get the auth descriptions (from core or own auth lang files)
60 $authdescription = get_string("auth_{$auth}description", "auth");
61 if ($authdescription == "[[auth_{$auth}description]]") {
62 $authdescription = get_string("auth_{$auth}description", "auth_{$auth}");
65 // output configuration form
66 admin_externalpage_print_header();
68 // choose an authentication method
69 echo "<form $CFG->frametarget id=\"authmenu\" method=\"post\" action=\"auth_config.php\">\n";
70 echo "<div>\n";
71 echo "<input type=\"hidden\" name=\"sesskey\" value=\"".$USER->sesskey."\" />\n";
72 echo "<input type=\"hidden\" name=\"auth\" value=\"".$auth."\" />\n";
74 // auth plugin description
75 print_simple_box_start('center', '80%');
76 print_heading($authtitle);
77 print_simple_box_start('center', '80%', '', 5, 'informationbox');
78 echo $authdescription;
79 print_simple_box_end();
80 echo "<hr />\n";
81 $authplugin->config_form($frm, $err, $user_fields);
82 print_simple_box_end();
83 echo '<p style="text-align: center"><input type="submit" value="' . get_string("savechanges") . "\" /></p>\n";
84 echo "</div>\n";
85 echo "</form>\n";
87 admin_externalpage_print_footer();
88 exit;
90 /// Functions /////////////////////////////////////////////////////////////////
92 // Good enough for most auth plugins
93 // but some may want a custom one if they are offering
94 // other options
95 // Note: lockconfig_ fields have special handling.
96 function print_auth_lock_options ($auth, $user_fields, $helptext, $retrieveopts, $updateopts) {
98 echo '<tr><td colspan="3">';
99 if ($retrieveopts) {
100 print_heading(get_string('auth_data_mapping', 'auth'));
101 } else {
102 print_heading(get_string('auth_fieldlocks', 'auth'));
104 echo '</td></tr>';
106 $lockoptions = array ('unlocked' => get_string('unlocked', 'auth'),
107 'unlockedifempty' => get_string('unlockedifempty', 'auth'),
108 'locked' => get_string('locked', 'auth'));
109 $updatelocaloptions = array('oncreate' => get_string('update_oncreate', 'auth'),
110 'onlogin' => get_string('update_onlogin', 'auth'));
111 $updateextoptions = array('0' => get_string('update_never', 'auth'),
112 '1' => get_string('update_onupdate', 'auth'));
114 $pluginconfig = get_config("auth/$auth");
116 // helptext is on a field with rowspan
117 if (empty($helptext)) {
118 $helptext = '&nbsp;';
121 foreach ($user_fields as $field) {
123 // Define some vars we'll work with
124 if (!isset($pluginconfig->{"field_map_$field"})) {
125 $pluginconfig->{"field_map_$field"} = '';
127 if (!isset($pluginconfig->{"field_updatelocal_$field"})) {
128 $pluginconfig->{"field_updatelocal_$field"} = '';
130 if (!isset($pluginconfig->{"field_updateremote_$field"})) {
131 $pluginconfig->{"field_updateremote_$field"} = '';
133 if (!isset($pluginconfig->{"field_lock_$field"})) {
134 $pluginconfig->{"field_lock_$field"} = '';
137 // define the fieldname we display to the user
138 $fieldname = $field;
139 if ($fieldname === 'lang') {
140 $fieldname = get_string('language');
141 } elseif (preg_match('/^(.+?)(\d+)$/', $fieldname, $matches)) {
142 $fieldname = get_string($matches[1]) . ' ' . $matches[2];
143 } else {
144 $fieldname = get_string($fieldname);
147 if ($retrieveopts) {
148 $varname = 'field_map_' . $field;
150 echo '<tr valign="top"><td align="right">';
151 echo '<label for="lockconfig_'.$varname.'">'.$fieldname.'</label>';
152 echo '</td><td>';
154 echo "<input id=\"lockconfig_{$varname}\" name=\"lockconfig_{$varname}\" type=\"text\" size=\"30\" value=\"{$pluginconfig->$varname}\" />";
155 echo '<div style="text-align: right">';
156 echo '<label for="menulockconfig_field_updatelocal_'.$field.'">'.get_string('auth_updatelocal', 'auth') . '</label>&nbsp;';
157 choose_from_menu($updatelocaloptions, "lockconfig_field_updatelocal_{$field}", $pluginconfig->{"field_updatelocal_$field"}, "");
158 echo '<br />';
159 if ($updateopts) {
160 echo '<label for="menulockconfig_field_updateremote_'.$field.'">'.get_string('auth_updateremote', 'auth') . '</label>&nbsp;';
161 choose_from_menu($updateextoptions, "lockconfig_field_updateremote_{$field}", $pluginconfig->{"field_updateremote_$field"}, "");
162 echo '<br />';
166 echo '<label for="menulockconfig_field_lock_'.$field.'">'.get_string('auth_fieldlock', 'auth') . '</label>&nbsp;';
167 choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
168 echo '</div>';
169 } else {
170 echo '<tr valign="top"><td align="right">';
171 echo '<label for="menulockconfig_field_lock_'.$field.'">'.$fieldname.'</label>';
172 echo '</td><td>';
173 choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
175 echo '</td>';
176 if (!empty($helptext)) {
177 echo '<td rowspan="' . count($user_fields) . '">' . $helptext . '</td>';
178 $helptext = '';
180 echo '</tr>';