diff -Naur /root/Desktop/old/ldap/auth.php auth/ldap/auth.php --- /root/Desktop/old/ldap/auth.php 2009-10-19 13:23:06.000000000 +0200 +++ auth/ldap/auth.php 2009-10-19 14:02:42.000000000 +0200 @@ -221,6 +221,17 @@ $values = array($values); } $ldapval = NULL; + if (!empty($this->config->{'field_pattern_'. $key}) && trim($this->config->{'field_pattern_'. $key}) != "") { + $pattern = "/" . $this->config->{'field_pattern_'. $key} . "/i"; + } else { + $pattern = "/.*/i"; + } + + $default_val = ""; + if (!empty($this->config->{'field_default_'. $key})) { + $default_val = $this->config->{'field_default_'. $key}; + } + foreach ($values as $value) { if ((moodle_strtolower($value) == 'dn') || (moodle_strtolower($value) == 'distinguishedname')) { $result[$key] = $user_dn; @@ -229,16 +240,27 @@ continue; // wrong data mapping! } if (is_array($user_entry[0][$value])) { - $newval = $textlib->convert($user_entry[0][$value][0], $this->config->ldapencoding, 'utf-8'); + $tmp_values = $user_entry[0][$value]; } else { - $newval = $textlib->convert($user_entry[0][$value], $this->config->ldapencoding, 'utf-8'); + $tmp_values = array($user_entry[0][$value]); } + + $newval = NULL; + foreach ($tmp_values as $tmp_val) { + if (@preg_match($pattern, $tmp_val)) { + $newval = $textlib->convert($tmp_val, $this->config->ldapencoding, 'utf-8'); + break; + } + } + if (!empty($newval)) { // favour ldap entries that are set $ldapval = $newval; } } if (!is_null($ldapval)) { $result[$key] = $ldapval; + } else if ($default_val != "") { + $result[$key] = $default_val; } } @@ -2015,6 +2037,7 @@ * @param array $page An object containing all the data for this page. */ function config_form($config, $err, $user_fields) { + require 'functions.php'; include 'config.html'; } diff -Naur /root/Desktop/old/ldap/config.html auth/ldap/config.html --- /root/Desktop/old/ldap/config.html 2009-05-28 10:32:38.000000000 +0200 +++ auth/ldap/config.html 2009-10-19 14:21:04.000000000 +0200 @@ -486,12 +486,14 @@ $help = get_string('auth_ldapextrafields','auth'); $help .= get_string('auth_updatelocal_expl','auth'); +$help .= get_string('auth_ldap_updatepattern_expl','auth'); +$help .= get_string('auth_ldap_updatedefault_expl','auth'); $help .= get_string('auth_fieldlock_expl','auth'); $help .= get_string('auth_updateremote_expl','auth'); $help .= '
'; $help .= get_string('auth_updateremote_ldap','auth'); -print_auth_lock_options('ldap', $user_fields, $help, true, true); +print_auth_lock_match_options($config, $user_fields, $help, true, true); ?> diff -Naur /root/Desktop/old/ldap/functions.php auth/ldap/functions.php --- /root/Desktop/old/ldap/functions.php 1970-01-01 01:00:00.000000000 +0100 +++ auth/ldap/functions.php 2009-10-19 13:12:09.000000000 +0200 @@ -0,0 +1,109 @@ +'; + if ($retrieveopts) { + print_heading(get_string('auth_data_mapping', 'auth')); + } else { + print_heading(get_string('auth_fieldlocks', 'auth')); + } + echo ''; + + $lockoptions = array ('unlocked' => get_string('unlocked', 'auth'), + 'unlockedifempty' => get_string('unlockedifempty', 'auth'), + 'locked' => get_string('locked', 'auth')); + $updatelocaloptions = array('oncreate' => get_string('update_oncreate', 'auth'), + 'onlogin' => get_string('update_onlogin', 'auth')); + $updateextoptions = array('0' => get_string('update_never', 'auth'), + '1' => get_string('update_onupdate', 'auth')); + + // helptext is on a field with rowspan + if (empty($helptext)) { + $helptext = ' '; + } + + foreach ($user_fields as $field) { + + // Define some vars we'll work with + if (!isset($pluginconfig->{"field_map_$field"})) { + $pluginconfig->{"field_map_$field"} = ''; + } + if (!isset($pluginconfig->{"field_updatelocal_$field"})) { + $pluginconfig->{"field_updatelocal_$field"} = ''; + } + if (!isset($pluginconfig->{"field_updateremote_$field"})) { + $pluginconfig->{"field_updateremote_$field"} = ''; + } + if (!isset($pluginconfig->{"field_lock_$field"})) { + $pluginconfig->{"field_lock_$field"} = ''; + } + if (!isset($pluginconfig->{"field_pattern_$field"})) { + $pluginconfig->{"field_pattern_$field"} = ''; + } + if (!isset($pluginconfig->{"field_default_$field"})) { + $pluginconfig->{"field_default_$field"} = ''; + } + + // define the fieldname we display to the user + $fieldname = $field; + if ($fieldname === 'lang') { + $fieldname = get_string('language'); + } elseif (preg_match('/^(.+?)(\d+)$/', $fieldname, $matches)) { // used for phone1 and phone2 + $fieldname = get_string($matches[1]) . ' ' . $matches[2]; + } elseif ($fieldname == 'url') { + $fieldname = get_string('webpage'); + } else { + $fieldname = get_string($fieldname); + } + if ($retrieveopts) { + $varname = 'field_map_' . $field; + + echo ''; + echo ''; + echo ''; + + echo "$varname}\" />"; + echo '
'; + echo ' '; + choose_from_menu($updatelocaloptions, "lockconfig_field_updatelocal_{$field}", $pluginconfig->{"field_updatelocal_$field"}, ""); + echo '
'; + + $varname = 'field_pattern_' . $field; + echo ' '; + echo "$varname}\" />"; + echo '
'; + + $varname = 'field_default_' . $field; + echo ' '; + echo "$varname}\" />"; + echo '
'; + if ($updateopts) { + echo ' '; + choose_from_menu($updateextoptions, "lockconfig_field_updateremote_{$field}", $pluginconfig->{"field_updateremote_$field"}, ""); + echo '
'; + + + } + echo ' '; + choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, ""); + echo '
'; + } else { + echo ''; + echo ''; + echo ''; + choose_from_menu($lockoptions, "lockconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, ""); + } + echo ''; + if (!empty($helptext)) { + echo '' . $helptext . ''; + $helptext = ''; + } + echo ''; + } +} +?>