Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / admin / auth_config.php
blob0281b123cab103806edc6980d0ac0ca448323b18
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 $auth = required_param('auth', PARAM_SAFEDIR);
11 $CFG->pagepath = 'auth/' . $auth;
13 admin_externalpage_setup('authsetting'.$auth);
15 $authplugin = get_auth_plugin($auth);
16 $err = array();
18 $returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageauths";
20 // save configuration changes
21 if ($frm = data_submitted() and confirm_sesskey()) {
22 $frm = stripslashes_recursive($frm);
24 $authplugin->validate_form($frm, $err);
26 if (count($err) == 0) {
28 // save plugin config
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";
35 $name = $matches[1];
36 if (!set_config($name, $value, $plugin)) {
37 error("Problem saving config $name as $value for plugin $plugin");
41 redirect($returnurl);
42 exit;
44 } else {
45 foreach ($err as $key => $value) {
46 $focus = "form.$key";
49 } else {
50 $frm = get_config("auth/$auth");
53 $user_fields = $authplugin->userfields;
54 //$user_fields = array("firstname", "lastname", "email", "phone1", "phone2", "institution", "department", "address", "city", "country", "description", "idnumber", "lang");
56 /// Get the auth title (from core or own auth lang files)
57 $authtitle = $authplugin->get_title();
58 /// Get the auth descriptions (from core or own auth lang files)
59 $authdescription = $authplugin->get_description();
61 // output configuration form
62 admin_externalpage_print_header();
64 // choose an authentication method
65 echo "<form $CFG->frametarget id=\"authmenu\" method=\"post\" action=\"auth_config.php\">\n";
66 echo "<div>\n";
67 echo "<input type=\"hidden\" name=\"sesskey\" value=\"".$USER->sesskey."\" />\n";
68 echo "<input type=\"hidden\" name=\"auth\" value=\"".$auth."\" />\n";
70 // auth plugin description
71 print_simple_box_start('center', '80%');
72 print_heading($authtitle);
73 print_simple_box_start('center', '80%', '', 5, 'informationbox');
74 echo $authdescription;
75 print_simple_box_end();
76 echo "<hr />\n";
77 $authplugin->config_form($frm, $err, $user_fields);
78 print_simple_box_end();
79 echo '<p style="text-align: center"><input type="submit" value="' . get_string("savechanges") . "\" /></p>\n";
80 echo "</div>\n";
81 echo "</form>\n";
83 admin_externalpage_print_footer();
84 exit;
86 /// Functions /////////////////////////////////////////////////////////////////
88 // Good enough for most auth plugins
89 // but some may want a custom one if they are offering
90 // other options
91 // Note: lockconfig_ fields have special handling.
92 function print_auth_lock_options ($auth, $user_fields, $helptext, $retrieveopts, $updateopts) {
94 echo '<tr><td colspan="3">';
95 if ($retrieveopts) {
96 print_heading(get_string('auth_data_mapping', 'auth'));
97 } else {
98 print_heading(get_string('auth_fieldlocks', 'auth'));
100 echo '</td></tr>';
102 $lockoptions = array ('unlocked' => get_string('unlocked', 'auth'),
103 'unlockedifempty' => get_string('unlockedifempty', 'auth'),
104 'locked' => get_string('locked', 'auth'));
105 $updatelocaloptions = array('oncreate' => get_string('update_oncreate', 'auth'),
106 'onlogin' => get_string('update_onlogin', 'auth'));
107 $updateextoptions = array('0' => get_string('update_never', 'auth'),
108 '1' => get_string('update_onupdate', 'auth'));
110 $pluginconfig = get_config("auth/$auth");
112 // helptext is on a field with rowspan
113 if (empty($helptext)) {
114 $helptext = '&nbsp;';
117 foreach ($user_fields as $field) {
119 // Define some vars we'll work with
120 if (!isset($pluginconfig->{"field_map_$field"})) {
121 $pluginconfig->{"field_map_$field"} = '';
123 if (!isset($pluginconfig->{"field_updatelocal_$field"})) {
124 $pluginconfig->{"field_updatelocal_$field"} = '';
126 if (!isset($pluginconfig->{"field_updateremote_$field"})) {
127 $pluginconfig->{"field_updateremote_$field"} = '';
129 if (!isset($pluginconfig->{"field_lock_$field"})) {
130 $pluginconfig->{"field_lock_$field"} = '';
133 // define the fieldname we display to the user
134 $fieldname = $field;
135 if ($fieldname === 'lang') {
136 $fieldname = get_string('language');
137 } elseif (preg_match('/^(.+?)(\d+)$/', $fieldname, $matches)) {
138 $fieldname = get_string($matches[1]) . ' ' . $matches[2];
139 } elseif ($fieldname == 'url') {
140 $fieldname = get_string('webpage');
141 } else {
142 $fieldname = get_string($fieldname);
144 if ($retrieveopts) {
145 $varname = 'field_map_' . $field;
147 echo '<tr valign="top"><td align="right">';
148 echo '<label for="lockconfig_'.$varname.'">'.$fieldname.'</label>';
149 echo '</td><td>';
151 echo "<input id=\"lockconfig_{$varname}\" name=\"lockconfig_{$varname}\" type=\"text\" size=\"30\" value=\"{$pluginconfig->$varname}\" />";
152 echo '<div style="text-align: right">';
153 echo '<label for="menulockconfig_field_updatelocal_'.$field.'">'.get_string('auth_updatelocal', 'auth') . '</label>&nbsp;';
154 choose_from_menu($updatelocaloptions, "lockconfig_field_updatelocal_{$field}", $pluginconfig->{"field_updatelocal_$field"}, "");
155 echo '<br />';
156 if ($updateopts) {
157 echo '<label for="menulockconfig_field_updateremote_'.$field.'">'.get_string('auth_updateremote', 'auth') . '</label>&nbsp;';
158 choose_from_menu($updateextoptions, "lockconfig_field_updateremote_{$field}", $pluginconfig->{"field_updateremote_$field"}, "");
159 echo '<br />';
163 echo '<label for="menulockconfig_field_lock_'.$field.'">'.get_string('auth_fieldlock', 'auth') . '</label>&nbsp;';
164 choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
165 echo '</div>';
166 } else {
167 echo '<tr valign="top"><td align="right">';
168 echo '<label for="menulockconfig_field_lock_'.$field.'">'.$fieldname.'</label>';
169 echo '</td><td>';
170 choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
172 echo '</td>';
173 if (!empty($helptext)) {
174 echo '<td rowspan="' . count($user_fields) . '">' . $helptext . '</td>';
175 $helptext = '';
177 echo '</tr>';