3 * Edit configuration for an individual auth plugin
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);
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) {
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 error("Problem saving config $name as $value for plugin $plugin");
45 foreach ($err as $key => $value) {
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";
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();
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";
83 admin_externalpage_print_footer();
86 /// Functions /////////////////////////////////////////////////////////////////
88 // Good enough for most auth plugins
89 // but some may want a custom one if they are offering
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">';
96 print_heading(get_string('auth_data_mapping', 'auth'));
98 print_heading(get_string('auth_fieldlocks', 'auth'));
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 = ' ';
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
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');
142 $fieldname = get_string($fieldname);
145 $varname = 'field_map_' . $field;
147 echo '<tr valign="top"><td align="right">';
148 echo '<label for="lockconfig_'.$varname.'">'.$fieldname.'</label>';
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> ';
154 choose_from_menu($updatelocaloptions, "lockconfig_field_updatelocal_{$field}", $pluginconfig->{"field_updatelocal_$field"}, "");
157 echo '<label for="menulockconfig_field_updateremote_'.$field.'">'.get_string('auth_updateremote', 'auth') . '</label> ';
158 choose_from_menu($updateextoptions, "lockconfig_field_updateremote_{$field}", $pluginconfig->{"field_updateremote_$field"}, "");
163 echo '<label for="menulockconfig_field_lock_'.$field.'">'.get_string('auth_fieldlock', 'auth') . '</label> ';
164 choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
167 echo '<tr valign="top"><td align="right">';
168 echo '<label for="menulockconfig_field_lock_'.$field.'">'.$fieldname.'</label>';
170 choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
173 if (!empty($helptext)) {
174 echo '<td rowspan="' . count($user_fields) . '">' . $helptext . '</td>';