From 54a71b8d9371e390b1aee52a5d8390ec8271238a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 26 Apr 2007 00:08:06 +0000 Subject: [PATCH] =?UTF-8?q?Fix:=20Gros=20bug=20dans=20les=20fonctions=20LD?= =?UTF-8?q?AP=20qui=20ne=20g=E9rait=20pas=20bien=20la=20majuscule,=20minus?= =?UTF-8?q?cule.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/user/fiche.php | 107 ++++++++++++++++++++++++++++-------------- 1 file changed, 72 insertions(+), 35 deletions(-) diff --git a/htdocs/user/fiche.php b/htdocs/user/fiche.php index a0a436f0d66..200502d3e74 100644 --- a/htdocs/user/fiche.php +++ b/htdocs/user/fiche.php @@ -325,22 +325,29 @@ if ($_POST["action"] == 'adduserldap') { $selecteduser = $_POST['users']; - $justthese = array( + $required_fields = array( $conf->global->LDAP_FIELD_NAME, $conf->global->LDAP_FIELD_FIRSTNAME, - $conf->global->LDAP_FIELD_UID, + $conf->global->LDAP_FIELD_LOGIN, $conf->global->LDAP_FIELD_LOGIN_SAMBA, - $conf->global->LDAP_FIELD_MAIL, + $conf->global->LDAP_FIELD_PASSWORD, + $conf->global->LDAP_FIELD_PASSWORD_CRYPTED, $conf->global->LDAP_FIELD_PHONE, $conf->global->LDAP_FIELD_FAX, $conf->global->LDAP_FIELD_MOBILE, + $conf->global->LDAP_FIELD_MAIL, $conf->global->LDAP_FIELD_SID); $ldap = new Ldap(); $result = $ldap->connect_bind(); if ($result >= 0) { - $ldapusers = $ldap->getUsers($selecteduser, $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $justthese); + // Remove from required_fields all entries not configured in LDAP (empty) and duplicated + $required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement"))); + + $ldapusers = $ldap->getUsers($selecteduser, $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields); + //print_r($ldapusers); + if (is_array($ldapusers)) { foreach ($ldapusers as $key => $attribute) @@ -349,6 +356,8 @@ if ($_POST["action"] == 'adduserldap') $ldap_prenom = $attribute[$conf->global->LDAP_FIELD_FIRSTNAME]; $ldap_login = $attribute[$conf->global->LDAP_FIELD_LOGIN]; $ldap_loginsmb = $attribute[$conf->global->LDAP_FIELD_LOGIN_SAMBA]; + $ldap_pass = $attribute[$conf->global->LDAP_FIELD_PASSWORD]; + $ldap_pass_crypted = $attribute[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED]; $ldap_phone = $attribute[$conf->global->LDAP_FIELD_PHONE]; $ldap_fax = $attribute[$conf->global->LDAP_FIELD_FAX]; $ldap_mobile = $attribute[$conf->global->LDAP_FIELD_MOBILE]; @@ -387,9 +396,6 @@ if (($action == 'create') || ($action == 'adduserldap')) print $langs->trans("CreateInternalUserDesc"); print "
"; print "
"; - - if ($message) { print $message.'
'; } - if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr') { @@ -398,48 +404,39 @@ if (($action == 'create') || ($action == 'adduserldap')) * si on est en synchro LDAP vers Dolibarr */ - print "\n\n\n"; - print '
'; - $ldap = new Ldap(); $result = $ldap->connect_bind(); if ($result >= 0) { - $justthese=array($conf->global->LDAP_KEY_USERS, + $required_fields=array($conf->global->LDAP_KEY_USERS, $conf->global->LDAP_FIELD_FULLNAME, $conf->global->LDAP_FIELD_NAME, $conf->global->LDAP_FIELD_FIRSTNAME, $conf->global->LDAP_FIELD_LOGIN, $conf->global->LDAP_FIELD_LOGIN_SAMBA); - - $ldapusers = $ldap->getUsers('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $justthese, 1); + + // Remove from required_fields all entries not configured in LDAP (empty) and duplicated + $required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement"))); + + // Get from LDAP database an array of results + $ldapusers = $ldap->getUsers('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 1); if (is_array($ldapusers)) { $liste=array(); foreach ($ldapusers as $key => $ldapuser) { - $record=''; - foreach ($justthese as $value) + // Define the label string for this user + $label=''; + foreach ($required_fields as $value) { if ($value) { - $record.=$value."=".$ldapuser[$value]." "; + $label.=$value."=".$ldapuser[$value]." "; } } - $liste[$key] = $record; + $liste[$key] = $label; } - print '
'; - print ''; - print '
'; - print $langs->trans("LDAPUsers"); - print ''; - print ''; - print $html->select_array('users', $liste, '', 1); - print ''; - print ''; - print '
'; - print '
'; } else { @@ -450,10 +447,33 @@ if (($action == 'create') || ($action == 'adduserldap')) { $message='
'.$ldap->error.'
'; } + } + + if ($message) { print $message.'
'; } + + if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr') + { + // Si la liste des users est rempli, on affiche la liste deroulante + if (is_array($liste)) + { + print "\n\n\n"; + + print '
'; + print ''; + print ''; + print '
'; + print $langs->trans("LDAPUsers"); + print ''; + print ''; + print $html->select_array('users', $liste, '', 1); + print ''; + print ''; + print '
'; + print '
'; - print "
"; - print "\n\n\n"; - print '
'; + print "\n\n\n"; + print '
'; + } } print '
'; @@ -462,8 +482,10 @@ if (($action == 'create') || ($action == 'adduserldap')) print ''; + print ''; + // Nom - print "".''; + print ''; print ''; // Prenom - print ''; + print ''; print ''; print ''; @@ -1294,5 +1325,11 @@ else $db->close(); +function dolValidElement($element) { + return (trim($element) != ''); +} + llxFooter('$Date$ - $Revision$'); ?> + +
'.$langs->trans("Lastname").'*'.$langs->trans("Lastname").'*'; if ($ldap_nom) { @@ -477,7 +499,7 @@ if (($action == 'create') || ($action == 'adduserldap')) print '
'.$langs->trans("Firstname").'
'.$langs->trans("Firstname").''; if ($ldap_prenom) { @@ -522,17 +544,26 @@ if (($action == 'create') || ($action == 'adduserldap')) $generated_password=$genhandler->getNewGeneratedPassword(); } } + $password=$generated_password; // Mot de passe print '
'.$langs->trans("Password").''; if ($ldap_sid) { - print 'mot de passe du domaine'; + print 'Mot de passe du domaine'; } else { - print ''; + if ($ldap_pass) + { + print ''; + print eregi_replace('.','*',$ldap_pass); + } + else + { + print ''; + } } print '