Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/auth_config.php
Go to the documentation of this file.
00001 <?php
00006 require_once '../config.php';
00007 require_once $CFG->libdir.'/adminlib.php';
00008 
00009 $auth = required_param('auth', PARAM_PLUGIN);
00010 $PAGE->set_pagetype('admin-auth-' . $auth);
00011 
00012 admin_externalpage_setup('authsetting'.$auth);
00013 
00014 $authplugin = get_auth_plugin($auth);
00015 $err = array();
00016 
00017 $returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageauths";
00018 
00019 // save configuration changes
00020 if ($frm = data_submitted() and confirm_sesskey()) {
00021 
00022     $authplugin->validate_form($frm, $err);
00023 
00024     if (count($err) == 0) {
00025 
00026         // save plugin config
00027         if ($authplugin->process_config($frm)) {
00028 
00029             // save field lock configuration
00030             foreach ($frm as $name => $value) {
00031                 if (preg_match('/^lockconfig_(.+?)$/', $name, $matches)) {
00032                     $plugin = "auth/$auth";
00033                     $name   = $matches[1];
00034                     set_config($name, $value, $plugin);
00035                 }
00036             }
00037             redirect($returnurl);
00038             exit;
00039         }
00040     } else {
00041         foreach ($err as $key => $value) {
00042             $focus = "form.$key";
00043         }
00044     }
00045 } else {
00046     $frmlegacystyle = get_config('auth/'.$auth);
00047     $frmnewstyle    = get_config('auth_'.$auth);
00048     $frm = (object)array_merge((array)$frmlegacystyle, (array)$frmnewstyle);
00049 }
00050 
00051 $user_fields = $authplugin->userfields;
00052 //$user_fields = array("firstname", "lastname", "email", "phone1", "phone2", "institution", "department", "address", "city", "country", "description", "idnumber", "lang");
00053 
00055     $authtitle = $authplugin->get_title();
00057     $authdescription = $authplugin->get_description();
00058 
00059 // output configuration form
00060 echo $OUTPUT->header();
00061 
00062 // choose an authentication method
00063 echo "<form id=\"authmenu\" method=\"post\" action=\"auth_config.php\">\n";
00064 echo "<div>\n";
00065 echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />\n";
00066 echo "<input type=\"hidden\" name=\"auth\" value=\"".$auth."\" />\n";
00067 
00068 // auth plugin description
00069 echo $OUTPUT->box_start();
00070 echo $OUTPUT->heading($authtitle);
00071 echo $OUTPUT->box_start('informationbox');
00072 echo $authdescription;
00073 echo $OUTPUT->box_end();
00074 echo "<hr />\n";
00075 $authplugin->config_form($frm, $err, $user_fields);
00076 echo $OUTPUT->box_end();
00077 echo '<p style="text-align: center"><input type="submit" value="' . get_string("savechanges") . "\" /></p>\n";
00078 echo "</div>\n";
00079 echo "</form>\n";
00080 
00081 echo $OUTPUT->footer();
00082 exit;
00083 
00085 
00086 // Good enough for most auth plugins
00087 // but some may want a custom one if they are offering
00088 // other options
00089 // Note: lockconfig_ fields have special handling.
00090 function print_auth_lock_options ($auth, $user_fields, $helptext, $retrieveopts, $updateopts) {
00091     global $OUTPUT;
00092     echo '<tr><td colspan="3">';
00093     if ($retrieveopts) {
00094         echo $OUTPUT->heading(get_string('auth_data_mapping', 'auth'));
00095     } else {
00096         echo $OUTPUT->heading(get_string('auth_fieldlocks', 'auth'));
00097     }
00098     echo '</td></tr>';
00099 
00100     $lockoptions = array ('unlocked'        => get_string('unlocked', 'auth'),
00101                           'unlockedifempty' => get_string('unlockedifempty', 'auth'),
00102                           'locked'          => get_string('locked', 'auth'));
00103     $updatelocaloptions = array('oncreate'  => get_string('update_oncreate', 'auth'),
00104                                 'onlogin'   => get_string('update_onlogin', 'auth'));
00105     $updateextoptions = array('0'  => get_string('update_never', 'auth'),
00106                               '1'   => get_string('update_onupdate', 'auth'));
00107 
00108     $pluginconfig = get_config("auth/$auth");
00109 
00110     // helptext is on a field with rowspan
00111     if (empty($helptext)) {
00112                 $helptext = '&nbsp;';
00113     }
00114 
00115     foreach ($user_fields as $field) {
00116 
00117         // Define some vars we'll work with
00118         if (!isset($pluginconfig->{"field_map_$field"})) {
00119             $pluginconfig->{"field_map_$field"} = '';
00120         }
00121         if (!isset($pluginconfig->{"field_updatelocal_$field"})) {
00122             $pluginconfig->{"field_updatelocal_$field"} = '';
00123         }
00124         if (!isset($pluginconfig->{"field_updateremote_$field"})) {
00125             $pluginconfig->{"field_updateremote_$field"} = '';
00126         }
00127         if (!isset($pluginconfig->{"field_lock_$field"})) {
00128             $pluginconfig->{"field_lock_$field"} = '';
00129         }
00130 
00131         // define the fieldname we display to the  user
00132         $fieldname = $field;
00133         if ($fieldname === 'lang') {
00134             $fieldname = get_string('language');
00135         } elseif (preg_match('/^(.+?)(\d+)$/', $fieldname, $matches)) {
00136             $fieldname =  get_string($matches[1]) . ' ' . $matches[2];
00137         } elseif ($fieldname == 'url') {
00138             $fieldname = get_string('webpage');
00139         } else {
00140             $fieldname = get_string($fieldname);
00141         }
00142         if ($retrieveopts) {
00143             $varname = 'field_map_' . $field;
00144 
00145             echo '<tr valign="top"><td align="right">';
00146             echo '<label for="lockconfig_'.$varname.'">'.$fieldname.'</label>';
00147             echo '</td><td>';
00148 
00149             echo "<input id=\"lockconfig_{$varname}\" name=\"lockconfig_{$varname}\" type=\"text\" size=\"30\" value=\"{$pluginconfig->$varname}\" />";
00150             echo '<div style="text-align: right">';
00151             echo '<label for="menulockconfig_field_updatelocal_'.$field.'">'.get_string('auth_updatelocal', 'auth') . '</label>&nbsp;';
00152             echo html_writer::select($updatelocaloptions, "lockconfig_field_updatelocal_{$field}", $pluginconfig->{"field_updatelocal_$field"}, false);
00153             echo '<br />';
00154             if ($updateopts) {
00155                 echo '<label for="menulockconfig_field_updateremote_'.$field.'">'.get_string('auth_updateremote', 'auth') . '</label>&nbsp;';
00156                 echo html_writer::select($updateextoptions, "lockconfig_field_updateremote_{$field}", $pluginconfig->{"field_updateremote_$field"}, false);
00157                 echo '<br />';
00158 
00159 
00160             }
00161             echo '<label for="menulockconfig_field_lock_'.$field.'">'.get_string('auth_fieldlock', 'auth') . '</label>&nbsp;';
00162             echo html_writer::select($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, false);
00163             echo '</div>';
00164         } else {
00165             echo '<tr valign="top"><td align="right">';
00166             echo '<label for="menulockconfig_field_lock_'.$field.'">'.$fieldname.'</label>';
00167             echo '</td><td>';
00168             echo html_writer::select($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, false);
00169         }
00170         echo '</td>';
00171         if (!empty($helptext)) {
00172             echo '<td rowspan="' . count($user_fields) . '">' . $helptext . '</td>';
00173             $helptext = '';
00174         }
00175         echo '</tr>';
00176     }
00177 }
00178 
00179 
 All Data Structures Namespaces Files Functions Variables Enumerations