| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Edit configuration for an individual auth plugin 4 */ 5 6 require_once '../config.php'; 7 require_once $CFG->libdir.'/adminlib.php'; 8 9 $auth = required_param('auth', PARAM_SAFEDIR); 10 11 $CFG->pagepath = 'auth/' . $auth; 12 13 admin_externalpage_setup('authsetting'.$auth); 14 15 $authplugin = get_auth_plugin($auth); 16 $err = array(); 17 18 $returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageauths"; 19 20 // save configuration changes 21 if ($frm = data_submitted() and confirm_sesskey()) { 22 $frm = stripslashes_recursive($frm); 23 24 $authplugin->validate_form($frm, $err); 25 26 if (count($err) == 0) { 27 28 // save plugin config 29 if ($authplugin->process_config($frm)) { 30 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"); 38 } 39 } 40 } 41 redirect($returnurl); 42 exit; 43 } 44 } else { 45 foreach ($err as $key => $value) { 46 $focus = "form.$key"; 47 } 48 } 49 } else { 50 $frm = get_config("auth/$auth"); 51 } 52 53 $user_fields = $authplugin->userfields; 54 //$user_fields = array("firstname", "lastname", "email", "phone1", "phone2", "institution", "department", "address", "city", "country", "description", "idnumber", "lang"); 55 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(); 60 61 // output configuration form 62 admin_externalpage_print_header(); 63 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"; 69 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"; 82 83 admin_externalpage_print_footer(); 84 exit; 85 86 /// Functions ///////////////////////////////////////////////////////////////// 87 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) { 93 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')); 99 } 100 echo '</td></tr>'; 101 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')); 109 110 $pluginconfig = get_config("auth/$auth"); 111 112 // helptext is on a field with rowspan 113 if (empty($helptext)) { 114 $helptext = ' '; 115 } 116 117 foreach ($user_fields as $field) { 118 119 // Define some vars we'll work with 120 if (!isset($pluginconfig->{"field_map_$field"})) { 121 $pluginconfig->{"field_map_$field"} = ''; 122 } 123 if (!isset($pluginconfig->{"field_updatelocal_$field"})) { 124 $pluginconfig->{"field_updatelocal_$field"} = ''; 125 } 126 if (!isset($pluginconfig->{"field_updateremote_$field"})) { 127 $pluginconfig->{"field_updateremote_$field"} = ''; 128 } 129 if (!isset($pluginconfig->{"field_lock_$field"})) { 130 $pluginconfig->{"field_lock_$field"} = ''; 131 } 132 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); 143 } 144 if ($retrieveopts) { 145 $varname = 'field_map_' . $field; 146 147 echo '<tr valign="top"><td align="right">'; 148 echo '<label for="lockconfig_'.$varname.'">'.$fieldname.'</label>'; 149 echo '</td><td>'; 150 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"}, ""); 155 echo '<br />'; 156 if ($updateopts) { 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"}, ""); 159 echo '<br />'; 160 161 162 } 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"}, ""); 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"}, ""); 171 } 172 echo '</td>'; 173 if (!empty($helptext)) { 174 echo '<td rowspan="' . count($user_fields) . '">' . $helptext . '</td>'; 175 $helptext = ''; 176 } 177 echo '</tr>'; 178 } 179 } 180 181 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |