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_PLUGIN
);
10 $PAGE->set_pagetype('admin-auth-' . $auth);
12 admin_externalpage_setup('authsetting'.$auth);
14 $authplugin = get_auth_plugin($auth);
17 $returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageauths";
19 // save configuration changes
20 if ($frm = data_submitted() and confirm_sesskey()) {
22 $authplugin->validate_form($frm, $err);
24 if (count($err) == 0) {
27 if ($authplugin->process_config($frm)) {
29 // save field lock configuration
30 foreach ($frm as $name => $value) {
31 if (preg_match('/^lockconfig_(.+?)$/', $name, $matches)) {
32 $plugin = "auth/$auth";
34 set_config($name, $value, $plugin);
41 foreach ($err as $key => $value) {
46 $frmlegacystyle = get_config('auth/'.$auth);
47 $frmnewstyle = get_config('auth_'.$auth);
48 $frm = (object)array_merge((array)$frmlegacystyle, (array)$frmnewstyle);
51 $user_fields = $authplugin->userfields
;
52 //$user_fields = array("firstname", "lastname", "email", "phone1", "phone2", "institution", "department", "address", "city", "country", "description", "idnumber", "lang");
54 /// Get the auth title (from core or own auth lang files)
55 $authtitle = $authplugin->get_title();
56 /// Get the auth descriptions (from core or own auth lang files)
57 $authdescription = $authplugin->get_description();
59 // output configuration form
60 echo $OUTPUT->header();
62 // choose an authentication method
63 echo "<form id=\"authmenu\" method=\"post\" action=\"auth_config.php\">\n";
65 echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />\n";
66 echo "<input type=\"hidden\" name=\"auth\" value=\"".$auth."\" />\n";
67 // HACK to prevent browsers from automatically inserting the user's password into the wrong fields.
68 echo prevent_form_autofill_password();
70 // auth plugin description
71 echo $OUTPUT->box_start();
72 echo $OUTPUT->heading($authtitle);
73 echo $OUTPUT->box_start('informationbox');
74 echo $authdescription;
75 echo $OUTPUT->box_end();
77 $authplugin->config_form($frm, $err, $user_fields);
78 echo $OUTPUT->box_end();
79 echo '<p style="text-align: center"><input type="submit" value="' . get_string("savechanges") . "\" /></p>\n";
83 $PAGE->requires
->string_for_js('unmaskpassword', 'core_form');
84 $PAGE->requires
->yui_module('moodle-auth-passwordunmask', 'M.auth.passwordunmask');
86 echo $OUTPUT->footer();
89 /// Functions /////////////////////////////////////////////////////////////////
91 // Good enough for most auth plugins
92 // but some may want a custom one if they are offering
94 // Note: lockconfig_ fields have special handling.
95 function print_auth_lock_options($auth, $user_fields, $helptext, $retrieveopts, $updateopts, $customfields = array()) {
97 echo '<tr><td colspan="3">';
99 echo $OUTPUT->heading(get_string('auth_data_mapping', 'auth'));
101 echo $OUTPUT->heading(get_string('auth_fieldlocks', 'auth'));
105 $lockoptions = array ('unlocked' => get_string('unlocked', 'auth'),
106 'unlockedifempty' => get_string('unlockedifempty', 'auth'),
107 'locked' => get_string('locked', 'auth'));
108 $updatelocaloptions = array('oncreate' => get_string('update_oncreate', 'auth'),
109 'onlogin' => get_string('update_onlogin', 'auth'));
110 $updateextoptions = array('0' => get_string('update_never', 'auth'),
111 '1' => get_string('update_onupdate', 'auth'));
113 $pluginconfig = get_config("auth/$auth");
115 // Helptext is on a field with rowspan.
116 if (empty($helptext)) {
117 $helptext = ' ';
120 // If we have custom fields then merge them with user fields.
121 if (!empty($customfields)) {
122 $user_fields = array_merge($user_fields, $customfields);
125 if (!empty($customfields)) {
126 $customfieldname = $DB->get_records('user_info_field', null, '', 'shortname, name');
128 foreach ($user_fields as $field) {
129 // Define some vars we'll work with.
130 if (!isset($pluginconfig->{"field_map_$field"})) {
131 $pluginconfig->{"field_map_$field"} = '';
133 if (!isset($pluginconfig->{"field_updatelocal_$field"})) {
134 $pluginconfig->{"field_updatelocal_$field"} = '';
136 if (!isset($pluginconfig->{"field_updateremote_$field"})) {
137 $pluginconfig->{"field_updateremote_$field"} = '';
139 if (!isset($pluginconfig->{"field_lock_$field"})) {
140 $pluginconfig->{"field_lock_$field"} = '';
143 // Define the fieldname we display to the user.
145 if ($fieldname === 'lang') {
146 $fieldname = get_string('language');
147 } elseif (!empty($customfields) && in_array($field, $customfields)) {
148 // If custom field then pick name from database.
149 $fieldshortname = str_replace('profile_field_', '', $fieldname);
150 $fieldname = $customfieldname[$fieldshortname]->name
;
151 } elseif (preg_match('/^(.+?)(\d+)$/', $fieldname, $matches)) {
152 $fieldname = get_string($matches[1]) . ' ' . $matches[2];
153 } elseif ($fieldname == 'url') {
154 $fieldname = get_string('webpage');
156 $fieldname = get_string($fieldname);
159 $varname = 'field_map_' . $field;
161 echo '<tr valign="top"><td align="right">';
162 echo '<label for="lockconfig_'.$varname.'">'.$fieldname.'</label>';
165 echo "<input id=\"lockconfig_{$varname}\" name=\"lockconfig_{$varname}\" type=\"text\" size=\"30\" value=\"{$pluginconfig->$varname}\" />";
166 echo '<div style="text-align: right">';
167 echo '<label for="menulockconfig_field_updatelocal_'.$field.'">'.get_string('auth_updatelocal', 'auth') . '</label> ';
168 echo html_writer
::select($updatelocaloptions, "lockconfig_field_updatelocal_{$field}", $pluginconfig->{"field_updatelocal_$field"}, false);
171 echo '<label for="menulockconfig_field_updateremote_'.$field.'">'.get_string('auth_updateremote', 'auth') . '</label> ';
172 echo html_writer
::select($updateextoptions, "lockconfig_field_updateremote_{$field}", $pluginconfig->{"field_updateremote_$field"}, false);
175 echo '<label for="menulockconfig_field_lock_'.$field.'">'.get_string('auth_fieldlock', 'auth') . '</label> ';
176 echo html_writer
::select($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, false);
179 echo '<tr valign="top"><td align="right">';
180 echo '<label for="menulockconfig_field_lock_'.$field.'">'.$fieldname.'</label>';
182 echo html_writer
::select($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, false);
185 if (!empty($helptext)) {
186 echo '<td rowspan="' . count($user_fields) . '">' . $helptext . '</td>';