Merge branch 'wip-MDL-48794-m27' of git://github.com/marinaglancy/moodle into MOODLE_...
[moodle.git] / admin / auth_config.php
blobe1a0fb08c8c1832ca2e44ecfe1a6b2f9452c415e
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_PLUGIN);
10 $PAGE->set_pagetype('admin-auth-' . $auth);
12 admin_externalpage_setup('authsetting'.$auth);
14 $authplugin = get_auth_plugin($auth);
15 $err = array();
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) {
26 // save plugin config
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";
33 $name = $matches[1];
34 set_config($name, $value, $plugin);
37 redirect($returnurl);
38 exit;
40 } else {
41 foreach ($err as $key => $value) {
42 $focus = "form.$key";
45 } else {
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";
64 echo "<div>\n";
65 echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />\n";
66 echo "<input type=\"hidden\" name=\"auth\" value=\"".$auth."\" />\n";
68 // auth plugin description
69 echo $OUTPUT->box_start();
70 echo $OUTPUT->heading($authtitle);
71 echo $OUTPUT->box_start('informationbox');
72 echo $authdescription;
73 echo $OUTPUT->box_end();
74 echo "<hr />\n";
75 $authplugin->config_form($frm, $err, $user_fields);
76 echo $OUTPUT->box_end();
77 echo '<p style="text-align: center"><input type="submit" value="' . get_string("savechanges") . "\" /></p>\n";
78 echo "</div>\n";
79 echo "</form>\n";
81 $PAGE->requires->string_for_js('unmaskpassword', 'core_form');
82 $PAGE->requires->yui_module('moodle-auth-passwordunmask', 'M.auth.passwordunmask');
84 echo $OUTPUT->footer();
85 exit;
87 /// Functions /////////////////////////////////////////////////////////////////
89 // Good enough for most auth plugins
90 // but some may want a custom one if they are offering
91 // other options
92 // Note: lockconfig_ fields have special handling.
93 function print_auth_lock_options($auth, $user_fields, $helptext, $retrieveopts, $updateopts, $customfields = array()) {
94 global $DB, $OUTPUT;
95 echo '<tr><td colspan="3">';
96 if ($retrieveopts) {
97 echo $OUTPUT->heading(get_string('auth_data_mapping', 'auth'));
98 } else {
99 echo $OUTPUT->heading(get_string('auth_fieldlocks', 'auth'));
101 echo '</td></tr>';
103 $lockoptions = array ('unlocked' => get_string('unlocked', 'auth'),
104 'unlockedifempty' => get_string('unlockedifempty', 'auth'),
105 'locked' => get_string('locked', 'auth'));
106 $updatelocaloptions = array('oncreate' => get_string('update_oncreate', 'auth'),
107 'onlogin' => get_string('update_onlogin', 'auth'));
108 $updateextoptions = array('0' => get_string('update_never', 'auth'),
109 '1' => get_string('update_onupdate', 'auth'));
111 $pluginconfig = get_config("auth/$auth");
113 // Helptext is on a field with rowspan.
114 if (empty($helptext)) {
115 $helptext = '&nbsp;';
118 // If we have custom fields then merge them with user fields.
119 if (!empty($customfields)) {
120 $user_fields = array_merge($user_fields, $customfields);
123 if (!empty($customfields)) {
124 $customfieldname = $DB->get_records('user_info_field', null, '', 'shortname, name');
126 foreach ($user_fields as $field) {
127 // Define some vars we'll work with.
128 if (!isset($pluginconfig->{"field_map_$field"})) {
129 $pluginconfig->{"field_map_$field"} = '';
131 if (!isset($pluginconfig->{"field_updatelocal_$field"})) {
132 $pluginconfig->{"field_updatelocal_$field"} = '';
134 if (!isset($pluginconfig->{"field_updateremote_$field"})) {
135 $pluginconfig->{"field_updateremote_$field"} = '';
137 if (!isset($pluginconfig->{"field_lock_$field"})) {
138 $pluginconfig->{"field_lock_$field"} = '';
141 // Define the fieldname we display to the user.
142 $fieldname = $field;
143 if ($fieldname === 'lang') {
144 $fieldname = get_string('language');
145 } elseif (!empty($customfields) && in_array($field, $customfields)) {
146 // If custom field then pick name from database.
147 $fieldshortname = str_replace('profile_field_', '', $fieldname);
148 $fieldname = $customfieldname[$fieldshortname]->name;
149 } elseif (preg_match('/^(.+?)(\d+)$/', $fieldname, $matches)) {
150 $fieldname = get_string($matches[1]) . ' ' . $matches[2];
151 } elseif ($fieldname == 'url') {
152 $fieldname = get_string('webpage');
153 } else {
154 $fieldname = get_string($fieldname);
156 if ($retrieveopts) {
157 $varname = 'field_map_' . $field;
159 echo '<tr valign="top"><td align="right">';
160 echo '<label for="lockconfig_'.$varname.'">'.$fieldname.'</label>';
161 echo '</td><td>';
163 echo "<input id=\"lockconfig_{$varname}\" name=\"lockconfig_{$varname}\" type=\"text\" size=\"30\" value=\"{$pluginconfig->$varname}\" />";
164 echo '<div style="text-align: right">';
165 echo '<label for="menulockconfig_field_updatelocal_'.$field.'">'.get_string('auth_updatelocal', 'auth') . '</label>&nbsp;';
166 echo html_writer::select($updatelocaloptions, "lockconfig_field_updatelocal_{$field}", $pluginconfig->{"field_updatelocal_$field"}, false);
167 echo '<br />';
168 if ($updateopts) {
169 echo '<label for="menulockconfig_field_updateremote_'.$field.'">'.get_string('auth_updateremote', 'auth') . '</label>&nbsp;';
170 echo html_writer::select($updateextoptions, "lockconfig_field_updateremote_{$field}", $pluginconfig->{"field_updateremote_$field"}, false);
171 echo '<br />';
173 echo '<label for="menulockconfig_field_lock_'.$field.'">'.get_string('auth_fieldlock', 'auth') . '</label>&nbsp;';
174 echo html_writer::select($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, false);
175 echo '</div>';
176 } else {
177 echo '<tr valign="top"><td align="right">';
178 echo '<label for="menulockconfig_field_lock_'.$field.'">'.$fieldname.'</label>';
179 echo '</td><td>';
180 echo html_writer::select($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, false);
182 echo '</td>';
183 if (!empty($helptext)) {
184 echo '<td rowspan="' . count($user_fields) . '">' . $helptext . '</td>';
185 $helptext = '';
187 echo '</tr>';