MDL-51427 user: correctly use strings for phone1 and phone2
[moodle.git] / admin / auth_config.php
CommitLineData
d14383e0 1<?php
2/**
3 * Edit configuration for an individual auth plugin
4 */
16ce6c0d 5
d14383e0 6require_once '../config.php';
7require_once $CFG->libdir.'/adminlib.php';
8
aff24313 9$auth = required_param('auth', PARAM_PLUGIN);
ad5d5997 10$PAGE->set_pagetype('admin-auth-' . $auth);
77b4ca5f 11
220a90c5 12admin_externalpage_setup('authsetting'.$auth);
13
d14383e0 14$authplugin = get_auth_plugin($auth);
15$err = array();
16
220a90c5 17$returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageauths";
d14383e0 18
220a90c5 19// save configuration changes
294ce987 20if ($frm = data_submitted() and confirm_sesskey()) {
f4f2b8fb 21
6bc1e5d5 22 $authplugin->validate_form($frm, $err);
d14383e0 23
24 if (count($err) == 0) {
25
26 // save plugin config
27 if ($authplugin->process_config($frm)) {
28
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];
5e2f308b 34 set_config($name, $value, $plugin);
d14383e0 35 }
36 }
220a90c5 37 redirect($returnurl);
d14383e0 38 exit;
39 }
40 } else {
41 foreach ($err as $key => $value) {
42 $focus = "form.$key";
43 }
16ce6c0d 44 }
d14383e0 45} else {
d33b19a5
DM
46 $frmlegacystyle = get_config('auth/'.$auth);
47 $frmnewstyle = get_config('auth_'.$auth);
48 $frm = (object)array_merge((array)$frmlegacystyle, (array)$frmnewstyle);
d14383e0 49}
50
4105caff 51$user_fields = $authplugin->userfields;
52//$user_fields = array("firstname", "lastname", "email", "phone1", "phone2", "institution", "department", "address", "city", "country", "description", "idnumber", "lang");
d14383e0 53
d660c423 54/// Get the auth title (from core or own auth lang files)
2a5f4a88 55 $authtitle = $authplugin->get_title();
d660c423 56/// Get the auth descriptions (from core or own auth lang files)
2a5f4a88 57 $authdescription = $authplugin->get_description();
d14383e0 58
59// output configuration form
61ef8f9f 60echo $OUTPUT->header();
d14383e0 61
d14383e0 62// choose an authentication method
4aea3cc7 63echo "<form id=\"authmenu\" method=\"post\" action=\"auth_config.php\">\n";
77a297d2 64echo "<div>\n";
d4a1fcaf 65echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />\n";
60af2703 66echo "<input type=\"hidden\" name=\"auth\" value=\"".$auth."\" />\n";
d14383e0 67
68// auth plugin description
8fbce1c8 69echo $OUTPUT->box_start();
2fff8846 70echo $OUTPUT->heading($authtitle);
8fbce1c8 71echo $OUTPUT->box_start('informationbox');
d660c423 72echo $authdescription;
8fbce1c8 73echo $OUTPUT->box_end();
d14383e0 74echo "<hr />\n";
57d135a1 75$authplugin->config_form($frm, $err, $user_fields);
8fbce1c8 76echo $OUTPUT->box_end();
77a297d2 77echo '<p style="text-align: center"><input type="submit" value="' . get_string("savechanges") . "\" /></p>\n";
78echo "</div>\n";
d14383e0 79echo "</form>\n";
80
a668a7e4
PS
81$PAGE->requires->string_for_js('unmaskpassword', 'core_form');
82$PAGE->requires->yui_module('moodle-auth-passwordunmask', 'M.auth.passwordunmask');
6e0ace38 83
73d6f52f 84echo $OUTPUT->footer();
d14383e0 85exit;
86
87/// Functions /////////////////////////////////////////////////////////////////
88
89// Good enough for most auth plugins
90// but some may want a custom one if they are offering
91// other options
16ce6c0d 92// Note: lockconfig_ fields have special handling.
57d135a1 93function print_auth_lock_options($auth, $user_fields, $helptext, $retrieveopts, $updateopts, $customfields = array()) {
b88adb55 94 global $DB, $OUTPUT;
d14383e0 95 echo '<tr><td colspan="3">';
96 if ($retrieveopts) {
2fff8846 97 echo $OUTPUT->heading(get_string('auth_data_mapping', 'auth'));
d14383e0 98 } else {
2fff8846 99 echo $OUTPUT->heading(get_string('auth_fieldlocks', 'auth'));
d14383e0 100 }
101 echo '</td></tr>';
102
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'));
16ce6c0d 110
d14383e0 111 $pluginconfig = get_config("auth/$auth");
a5c96d06 112
57d135a1 113 // Helptext is on a field with rowspan.
d14383e0 114 if (empty($helptext)) {
57d135a1 115 $helptext = '&nbsp;';
d14383e0 116 }
117
57d135a1
RT
118 // If we have custom fields then merge them with user fields.
119 if (!empty($customfields)) {
120 $user_fields = array_merge($user_fields, $customfields);
121 }
d14383e0 122
d8372b54
RT
123 if (!empty($customfields)) {
124 $customfieldname = $DB->get_records('user_info_field', null, '', 'shortname, name');
125 }
57d135a1
RT
126 foreach ($user_fields as $field) {
127 // Define some vars we'll work with.
a5c96d06 128 if (!isset($pluginconfig->{"field_map_$field"})) {
b7dc2256 129 $pluginconfig->{"field_map_$field"} = '';
130 }
a5c96d06 131 if (!isset($pluginconfig->{"field_updatelocal_$field"})) {
b7dc2256 132 $pluginconfig->{"field_updatelocal_$field"} = '';
133 }
a5c96d06 134 if (!isset($pluginconfig->{"field_updateremote_$field"})) {
b7dc2256 135 $pluginconfig->{"field_updateremote_$field"} = '';
136 }
a5c96d06 137 if (!isset($pluginconfig->{"field_lock_$field"})) {
b7dc2256 138 $pluginconfig->{"field_lock_$field"} = '';
139 }
d14383e0 140
57d135a1 141 // Define the fieldname we display to the user.
d14383e0 142 $fieldname = $field;
143 if ($fieldname === 'lang') {
144 $fieldname = get_string('language');
57d135a1
RT
145 } elseif (!empty($customfields) && in_array($field, $customfields)) {
146 // If custom field then pick name from database.
147 $fieldshortname = str_replace('profile_field_', '', $fieldname);
d8372b54 148 $fieldname = $customfieldname[$fieldshortname]->name;
acf25086
JH
149 } elseif ($fieldname == 'url') {
150 $fieldname = get_string('webpage');
d14383e0 151 } else {
152 $fieldname = get_string($fieldname);
20207b82 153 }
d14383e0 154 if ($retrieveopts) {
155 $varname = 'field_map_' . $field;
156
16ce6c0d 157 echo '<tr valign="top"><td align="right">';
158 echo '<label for="lockconfig_'.$varname.'">'.$fieldname.'</label>';
159 echo '</td><td>';
160
161 echo "<input id=\"lockconfig_{$varname}\" name=\"lockconfig_{$varname}\" type=\"text\" size=\"30\" value=\"{$pluginconfig->$varname}\" />";
77a297d2 162 echo '<div style="text-align: right">';
16ce6c0d 163 echo '<label for="menulockconfig_field_updatelocal_'.$field.'">'.get_string('auth_updatelocal', 'auth') . '</label>&nbsp;';
d776d59e 164 echo html_writer::select($updatelocaloptions, "lockconfig_field_updatelocal_{$field}", $pluginconfig->{"field_updatelocal_$field"}, false);
d14383e0 165 echo '<br />';
166 if ($updateopts) {
16ce6c0d 167 echo '<label for="menulockconfig_field_updateremote_'.$field.'">'.get_string('auth_updateremote', 'auth') . '</label>&nbsp;';
d776d59e 168 echo html_writer::select($updateextoptions, "lockconfig_field_updateremote_{$field}", $pluginconfig->{"field_updateremote_$field"}, false);
d14383e0 169 echo '<br />';
d14383e0 170 }
16ce6c0d 171 echo '<label for="menulockconfig_field_lock_'.$field.'">'.get_string('auth_fieldlock', 'auth') . '</label>&nbsp;';
d776d59e 172 echo html_writer::select($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, false);
d14383e0 173 echo '</div>';
174 } else {
16ce6c0d 175 echo '<tr valign="top"><td align="right">';
176 echo '<label for="menulockconfig_field_lock_'.$field.'">'.$fieldname.'</label>';
177 echo '</td><td>';
d776d59e 178 echo html_writer::select($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, false);
d14383e0 179 }
180 echo '</td>';
181 if (!empty($helptext)) {
182 echo '<td rowspan="' . count($user_fields) . '">' . $helptext . '</td>';
183 $helptext = '';
184 }
185 echo '</tr>';
186 }
d8372b54 187}