diff --git a/htdocs/adherents/adherent.class.php b/htdocs/adherents/adherent.class.php index 8bdfb0800a1..9f1eec0fc68 100644 --- a/htdocs/adherents/adherent.class.php +++ b/htdocs/adherents/adherent.class.php @@ -21,15 +21,10 @@ */ /** - \file htdocs/adherents/adherent.class.php - \ingroup adherent - \brief Fichier de la classe permettant la gestion d'un adherent - \author Rodolphe Qiedeville - \author Jean-Louis Bergamo - \author Laurent Destailleur - \author Sebastien Di Cintio - \author Benoit Mortier - \version $Id$ + * \file htdocs/adherents/adherent.class.php + * \ingroup adherent + * \brief Fichier de la classe permettant la gestion d'un adherent + * \version $Id$ */ require_once(DOL_DOCUMENT_ROOT."/commonobject.class.php"); @@ -1923,8 +1918,8 @@ class Adherent extends CommonObject /** * \brief Retourne chaine DN complete dans l'annuaire LDAP pour l'objet * \param info Info string loaded by _load_ldap_info - * \param mode 0=Return DN without key inside (ou=xxx,dc=aaa,dc=bbb) - * 1=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb) + * \param mode 0=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb) + * 1=Return DN without key inside (ou=xxx,dc=aaa,dc=bbb) * 2=Return key only (uid=qqq) * \return string DN */ diff --git a/htdocs/adherents/ldap.php b/htdocs/adherents/ldap.php index ad97e1d4ef8..4186c97718c 100644 --- a/htdocs/adherents/ldap.php +++ b/htdocs/adherents/ldap.php @@ -45,16 +45,6 @@ if ($user->societe_id > 0) $socid = $user->societe_id; } - -/* - * Affichage page - */ - -llxHeader(); - -$html = new Form($db); - - $adh = new Adherent($db); $adh->id = $rowid; $result=$adh->fetch($rowid); @@ -75,17 +65,22 @@ if (! $result) + + + /* - * Affichage onglets + * View */ + +llxHeader(); + +$html = new Form($db); + $head = member_prepare_head($adh); dol_fiche_head($head, 'ldap', $langs->trans("Member"), 0, 'user'); -/* - * Fiche en mode visu - */ print ''; // Ref @@ -129,7 +124,7 @@ $langs->load("admin"); // LDAP DN print '\n"; -// LDAP Cl� +// LDAP Cle print '\n"; // LDAP Server @@ -146,9 +141,10 @@ print ''; print '
'; -print_titre($langs->trans("LDAPInformationsForThisMember")); // Affichage attributs LDAP +print_titre($langs->trans("LDAPInformationsForThisMember")); + print '
LDAP '.$langs->trans("LDAPMemberDn").''.$conf->global->LDAP_MEMBER_DN."
LDAP '.$langs->trans("LDAPNamingAttribute").''.$conf->global->LDAP_KEY_MEMBERS."
'; print ''; diff --git a/htdocs/admin/ldap_contacts.php b/htdocs/admin/ldap_contacts.php index 86a48c095b4..721812b379b 100644 --- a/htdocs/admin/ldap_contacts.php +++ b/htdocs/admin/ldap_contacts.php @@ -19,7 +19,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - + /** \file htdocs/admin/ldap_contacts.php \ingroup ldap @@ -50,7 +50,7 @@ if ($_GET["action"] == 'setvalue' && $user->admin) if (! dolibarr_set_const($db, 'LDAP_CONTACT_DN',$_POST["contactdn"],'chaine',0,'',$conf->entity)) $error++; if (! dolibarr_set_const($db, 'LDAP_CONTACT_OBJECT_CLASS',$_POST["objectclass"],'chaine',0,'',$conf->entity)) $error++; - + if (! dolibarr_set_const($db, 'LDAP_FIELD_FULLNAME',$_POST["fieldfullname"],'chaine',0,'',$conf->entity)) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_NAME',$_POST["fieldname"],'chaine',0,'',$conf->entity)) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_FIRSTNAME',$_POST["fieldfirstname"],'chaine',0,'',$conf->entity)) $error++; @@ -64,7 +64,7 @@ if ($_GET["action"] == 'setvalue' && $user->admin) if (! dolibarr_set_const($db, 'LDAP_FIELD_ZIP',$_POST["fieldzip"],'chaine',0,'',$conf->entity)) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_TOWN',$_POST["fieldtown"],'chaine',0,'',$conf->entity)) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_COUNTRY',$_POST["fieldcountry"],'chaine',0,'',$conf->entity)) $error++; - + if ($error) { dol_print_error($db->error()); @@ -107,7 +107,7 @@ $var=true; print ''; print ''; print "\n"; - + // DN Pour les contacts $var=!$var; @@ -280,8 +280,9 @@ if (function_exists("ldap_connect")) $info=$object->_load_ldap_info(); $dn=$object->_load_ldap_dn($info); - $result2=$ldap->update($dn,$info,$user); - $result3=$ldap->delete($dn); + $result1=$ldap->delete($dn); // To be sure to delete existing records + $result2=$ldap->add($dn,$info,$user); // Now the test + $result3=$ldap->delete($dn); // Clean what we did if ($result2 > 0) { diff --git a/htdocs/admin/ldap_groups.php b/htdocs/admin/ldap_groups.php index b1dde21cf08..9a41285dc3d 100644 --- a/htdocs/admin/ldap_groups.php +++ b/htdocs/admin/ldap_groups.php @@ -19,7 +19,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - + /** \file htdocs/admin/ldap_groups.php \ingroup ldap @@ -43,7 +43,7 @@ if (!$user->admin) /* * Actions */ - + if ($_GET["action"] == 'setvalue' && $user->admin) { $error=0; @@ -51,7 +51,7 @@ if ($_GET["action"] == 'setvalue' && $user->admin) if (! dolibarr_set_const($db, 'LDAP_GROUP_DN',$_POST["group"],'chaine',0,'',$conf->entity)) $error++; if (! dolibarr_set_const($db, 'LDAP_GROUP_OBJECT_CLASS',$_POST["objectclass"],'chaine',0,'',$conf->entity)) $error++; - + if (! dolibarr_set_const($db, 'LDAP_FIELD_FULLNAME',$_POST["fieldfullname"],'chaine',0,'',$conf->entity)) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_NAME',$_POST["fieldname"],'chaine',0,'',$conf->entity)) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_DESCRIPTION',$_POST["fielddescription"],'chaine',0,'',$conf->entity)) $error++; @@ -202,8 +202,9 @@ if (function_exists("ldap_connect")) $info=$object->_load_ldap_info(); $dn=$object->_load_ldap_dn($info); - $result2=$ldap->update($dn,$info,$user); - $result3=$ldap->delete($dn); + $result1=$ldap->delete($dn); // To be sure to delete existing records + $result2=$ldap->add($dn,$info,$user); // Now the test + $result3=$ldap->delete($dn); // Clean what we did if ($result2 > 0) { diff --git a/htdocs/admin/ldap_members.php b/htdocs/admin/ldap_members.php index 162cf5a3873..05d36c00e6a 100644 --- a/htdocs/admin/ldap_members.php +++ b/htdocs/admin/ldap_members.php @@ -19,7 +19,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - + /** \file htdocs/admin/ldap_members.php \ingroup ldap adherent @@ -43,12 +43,12 @@ if (!$user->admin) /* * Actions */ - + if ($_GET["action"] == 'setvalue' && $user->admin) { $error=0; if (! dolibarr_set_const($db, 'LDAP_KEY_MEMBERS',$_POST["key"],'chaine',0,'',$conf->entity)) $error++; - + if (! dolibarr_set_const($db, 'LDAP_MEMBER_DN',$_POST["user"],'chaine',0,'',$conf->entity)) $error++; if (! dolibarr_set_const($db, 'LDAP_MEMBER_OBJECT_CLASS',$_POST["objectclass"],'chaine',0,'',$conf->entity)) $error++; // Members @@ -394,8 +394,9 @@ if (function_exists("ldap_connect")) $info=$object->_load_ldap_info(); $dn=$object->_load_ldap_dn($info); - $result2=$ldap->update($dn,$info,$user); - $result3=$ldap->delete($dn); + $result1=$ldap->delete($dn); // To be sure to delete existing records + $result2=$ldap->add($dn,$info,$user); // Now the test + $result3=$ldap->delete($dn); // Clean what we did if ($result2 > 0) { @@ -419,7 +420,7 @@ if (function_exists("ldap_connect")) print '
'; print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'
'; } - + print "
\n"; print "LDAP input file used for test:

\n"; print nl2br($ldap->dump_content($dn,$info)); diff --git a/htdocs/admin/ldap_users.php b/htdocs/admin/ldap_users.php index 584f3ddb73f..41f6afaec14 100644 --- a/htdocs/admin/ldap_users.php +++ b/htdocs/admin/ldap_users.php @@ -19,7 +19,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - + /** \file htdocs/admin/ldap_users.php \ingroup ldap @@ -43,7 +43,7 @@ if (!$user->admin) /* * Actions */ - + if ($_GET["action"] == 'setvalue' && $user->admin) { $error=0; @@ -51,7 +51,7 @@ if ($_GET["action"] == 'setvalue' && $user->admin) if (! dolibarr_set_const($db, 'LDAP_USER_DN',$_POST["user"],'chaine',0,'',$conf->entity)) $error++; if (! dolibarr_set_const($db, 'LDAP_USER_OBJECT_CLASS',$_POST["objectclass"],'chaine',0,'',$conf->entity)) $error++; - + if (! dolibarr_set_const($db, 'LDAP_FILTER_CONNECTION',$_POST["filterconnection"],'chaine',0,'',$conf->entity)) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_FULLNAME',$_POST["fieldfullname"],'chaine',0,'',$conf->entity)) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_LOGIN',$_POST["fieldlogin"],'chaine',0,'',$conf->entity)) $error++; @@ -102,7 +102,7 @@ print '
'; print ''; print ''; - + $html=new Form($db); print '
'.$langs->trans("LDAPSynchronizeUsers").'
'; @@ -286,7 +286,7 @@ if (function_exists("ldap_connect")) $object->initAsSpecimen(); // TODO Mutualize code following with other ldap_xxxx.php pages - + // Test synchro $ldap=new Ldap(); $result=$ldap->connect_bind(); @@ -296,8 +296,9 @@ if (function_exists("ldap_connect")) $info=$object->_load_ldap_info(); $dn=$object->_load_ldap_dn($info); - $result2=$ldap->update($dn,$info,$user); - $result3=$ldap->delete($dn); + $result1=$ldap->delete($dn); // To be sure to delete existing records + $result2=$ldap->add($dn,$info,$user); // Now the test + $result3=$ldap->delete($dn); // Clean what we did if ($result2 > 0) { diff --git a/htdocs/contact.class.php b/htdocs/contact.class.php index 58d98f21908..7bae25a07da 100644 --- a/htdocs/contact.class.php +++ b/htdocs/contact.class.php @@ -137,12 +137,14 @@ class Contact extends CommonObject * \param id Id du contact a mettre a jour * \param user Objet utilisateur qui effectue la mise a jour * \param notrigger 0=non, 1=oui - * \return int <0 si erreur, >0 si ok + * \return int <0 if KO, >0 if OK */ function update($id, $user=0, $notrigger=0) { global $conf, $langs; + $error=0; + $this->id = $id; // Nettoyage parametres @@ -155,6 +157,8 @@ class Contact extends CommonObject $this->phone_mobile=trim($this->phone_mobile); $this->fax=trim($this->fax); + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET "; if ($this->socid > 0) $sql .= " fk_soc='".addslashes($this->socid)."',"; if ($this->socid == -1) $sql .= " fk_soc=null,"; @@ -179,32 +183,45 @@ class Contact extends CommonObject dol_syslog("Contact::update sql=".$sql,LOG_DEBUG); $result = $this->db->query($sql); - if (! $result) + if ($result) { + if (! $error && ! $notrigger) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('CONTACT_MODIFY',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -$error; + } + } + else + { + $this->db->rollback(); + $this->error=$this->db->lasterror().' sql='.$sql; dol_syslog("Contact::update Error ".$this->error,LOG_ERR); return -1; } - - if (! $notrigger) - { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('CONTACT_MODIFY',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - } - - return 1; } /** * \brief Retourne chaine DN complete dans l'annuaire LDAP pour l'objet * \param info Info string loaded by _load_ldap_info - * \param mode 0=Return DN without key inside (ou=xxx,dc=aaa,dc=bbb) - * 1=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb) + * \param mode 0=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb) + * 1=Return DN without key inside (ou=xxx,dc=aaa,dc=bbb) * 2=Return key only (uid=qqq) * \return string DN */ diff --git a/htdocs/contact/ldap.php b/htdocs/contact/ldap.php index 4956be54e0e..daff969c321 100644 --- a/htdocs/contact/ldap.php +++ b/htdocs/contact/ldap.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2006-2009 Laurent Destailleur * Copyright (C) 2006 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -39,6 +39,11 @@ $contactid = isset($_GET["id"])?$_GET["id"]:''; if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'contact', $contactid, 'socpeople'); +$contact = new Contact($db); +$contact->fetch($_GET["id"], $user); + + + /* * View @@ -48,18 +53,11 @@ llxHeader(); $form = new Form($db); -$contact = new Contact($db); -$contact->fetch($_GET["id"], $user); - - $head = contact_prepare_head($contact); dol_fiche_head($head, 'ldap', $langs->trans("Contact"), 0, 'contact'); -/* - * Fiche en mode visu - */ print '
'; // Ref @@ -94,7 +92,7 @@ print ''; // LDAP DN print '\n"; -// LDAP Cl� +// LDAP Cle print '\n"; // LDAP Server @@ -109,9 +107,9 @@ print ''; print '
'; +// Affichage attributs LDAP print_titre($langs->trans("LDAPInformationsForThisContact")); -// Affichage attributs LDAP print '
LDAP '.$langs->trans("LDAPContactDn").''.$conf->global->LDAP_CONTACT_DN."
LDAP '.$langs->trans("LDAPNamingAttribute").''.$conf->global->LDAP_KEY_CONTACTS."
'; print ''; diff --git a/htdocs/includes/triggers/interface_modLdap_Ldapsynchro.class.php b/htdocs/includes/triggers/interface_modLdap_Ldapsynchro.class.php index 0e943747e4f..3d21b51a5ff 100644 --- a/htdocs/includes/triggers/interface_modLdap_Ldapsynchro.class.php +++ b/htdocs/includes/triggers/interface_modLdap_Ldapsynchro.class.php @@ -135,10 +135,15 @@ class InterfaceLdapsynchro $ldap=new Ldap(); $ldap->connect_bind(); - $info=$object->_load_ldap_info(); + $oldobject=$object; // TODO Get oldobject + + $oldinfo=$oldobject->_load_ldap_info(); + $olddn=$oldobject->_load_ldap_dn($oldinfo); + + $info=$object->_load_ldap_info(); $dn=$object->_load_ldap_dn($info); - $result=$ldap->update($dn,$info,$user); + $result=$ldap->update($dn,$info,$user,$olddn); if ($result < 0) { $this->error="ErrorLDAP"." ".$ldap->error; @@ -200,10 +205,15 @@ class InterfaceLdapsynchro $ldap=new Ldap(); $ldap->connect_bind(); - $info=$object->_load_ldap_info(); + $oldobject=$object; // TODO Get oldobject + + $oldinfo=$oldobject->_load_ldap_info(); + $olddn=$oldobject->_load_ldap_dn($oldinfo); + + $info=$object->_load_ldap_info(); $dn=$object->_load_ldap_dn($info); - $result=$ldap->update($dn,$info,$user); + $result=$ldap->update($dn,$info,$user,$olddn); if ($result < 0) { $this->error="ErrorLDAP"." ".$ldap->error; @@ -258,10 +268,15 @@ class InterfaceLdapsynchro $ldap=new Ldap(); $ldap->connect_bind(); + $oldobject=$object; // TODO Get oldobject + + $oldinfo=$oldobject->_load_ldap_info(); + $olddn=$oldobject->_load_ldap_dn($oldinfo); + $info=$object->_load_ldap_info(); $dn=$object->_load_ldap_dn($info); - $result=$ldap->update($dn,$info,$user); + $result=$ldap->update($dn,$info,$user,$olddn); if ($result < 0) { $this->error="ErrorLDAP"." ".$ldap->error; @@ -320,10 +335,15 @@ class InterfaceLdapsynchro $ldap=new Ldap(); $ldap->connect_bind(); - $info=$object->_load_ldap_info(); + $oldobject=$object; // TODO Get oldobject + + $oldinfo=$oldobject->_load_ldap_info(); + $olddn=$oldobject->_load_ldap_dn($oldinfo); + + $info=$object->_load_ldap_info(); $dn=$object->_load_ldap_dn($info); - $result=$ldap->update($dn,$info,$user); + $result=$ldap->update($dn,$info,$user,$olddn); if ($result < 0) { $this->error="ErrorLDAP"." ".$ldap->error; @@ -347,10 +367,15 @@ class InterfaceLdapsynchro $ldap=new Ldap(); $ldap->connect_bind(); - $info=$object->_load_ldap_info(); + $oldobject=$object; // TODO Get oldobject + + $oldinfo=$oldobject->_load_ldap_info(); + $olddn=$oldobject->_load_ldap_dn($oldinfo); + + $info=$object->_load_ldap_info(); $dn=$object->_load_ldap_dn($info); - $result=$ldap->update($dn,$info,$user); + $result=$ldap->update($dn,$info,$user,$olddn); if ($result < 0) { $this->error="ErrorLDAP"." ".$ldap->error; @@ -367,10 +392,15 @@ class InterfaceLdapsynchro $ldap=new Ldap(); $ldap->connect_bind(); - $info=$object->_load_ldap_info(); + $oldobject=$object; // TODO Get oldobject + + $oldinfo=$oldobject->_load_ldap_info(); + $olddn=$oldobject->_load_ldap_dn($oldinfo); + + $info=$object->_load_ldap_info(); $dn=$object->_load_ldap_dn($info); - $result=$ldap->update($dn,$info,$user); + $result=$ldap->update($dn,$info,$user,$olddn); if ($result < 0) { $this->error="ErrorLDAP"." ".$ldap->error; @@ -412,10 +442,15 @@ class InterfaceLdapsynchro $ldap=new Ldap(); $ldap->connect_bind(); - $info=$object->_load_ldap_info(); + $oldobject=$object; // TODO Get oldobject + + $oldinfo=$oldobject->_load_ldap_info(); + $olddn=$oldobject->_load_ldap_dn($oldinfo); + + $info=$object->_load_ldap_info(); $dn=$object->_load_ldap_dn($info); - $result=$ldap->update($dn,$info,$user); + $result=$ldap->update($dn,$info,$user,$olddn); if ($result < 0) { $this->error="ErrorLDAP"." ".$ldap->error; diff --git a/htdocs/langs/en_US/ldap.lang b/htdocs/langs/en_US/ldap.lang index bd6c5b413b4..6271c4fd834 100644 --- a/htdocs/langs/en_US/ldap.lang +++ b/htdocs/langs/en_US/ldap.lang @@ -23,5 +23,6 @@ LDAPFieldLastSubscriptionDate=Last subscription date LDAPFieldLastSubscriptionAmount=Last subscription amount SynchronizeDolibarr2Ldap=Synchronize user (Dolibarr -> LDAP) UserSynchronized=User synchronized +GroupSynchronized=Group synchronized ForceSynchronize=Force synchronizing Dolibarr -> LDAP ErrorFailedToReadLDAP=Failed to read LDAP database. Check LDAP module setup and database accessibility. \ No newline at end of file diff --git a/htdocs/langs/fr_FR/ldap.lang b/htdocs/langs/fr_FR/ldap.lang index e337b4d38b3..cd5002a7752 100644 --- a/htdocs/langs/fr_FR/ldap.lang +++ b/htdocs/langs/fr_FR/ldap.lang @@ -23,5 +23,6 @@ LDAPFieldLastSubscriptionDate=Date dernière adhésion LDAPFieldLastSubscriptionAmount=Montant dernière adhésion SynchronizeDolibarr2Ldap=Synchroniser utilisateur (Dolibarr -> LDAP) UserSynchronized=Utilisateur synchronisé +GroupSynchronized=Groupe synchronisé ForceSynchronize=Forcer synchro Dolibarr -> LDAP ErrorFailedToReadLDAP=Echec de la lecture de l'annuaire LDAP. Vérifier la configuration du module LDAP et l'accessibilité de l'annuaire. \ No newline at end of file diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index d195c58ddbb..d66b2e4f5ac 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -2620,11 +2620,11 @@ function dol_entity_decode($stringhtml,$pagecodeto='UTF-8') } /** - \brief Check if a string is a correct iso string - If not, it will we considered not HTML encoded even if it is by FPDF. - \remarks Example, if string contains euro symbol that has ascii code 128. - \param s String to check - \return int 0 if bad iso, 1 if good iso + * \brief Check if a string is a correct iso string + * If not, it will we considered not HTML encoded even if it is by FPDF. + * \remarks Example, if string contains euro symbol that has ascii code 128. + * \param s String to check + * \return int 0 if bad iso, 1 if good iso */ function dol_string_is_good_iso($s) { diff --git a/htdocs/lib/ldap.class.php b/htdocs/lib/ldap.class.php index 84754782d06..7200c5d89e4 100644 --- a/htdocs/lib/ldap.class.php +++ b/htdocs/lib/ldap.class.php @@ -388,50 +388,6 @@ class Ldap } - /** - * \brief Mise à jour dans l'arbre LDAP - * \param dn DN - * \param info Tableau info - * \param user Objet user qui fait l'opération - * \return int <0 si ko, >0 si ok - * \remarks Ldap object connect and bind must have been done - */ - function update($dn,$info,$user,$olddn='') - { - global $conf, $langs; - - if (! $this->connection) - { - $this->error=$langs->trans("NotConnected"); - return -2; - } - if (! $this->bind) - { - $this->error=$langs->trans("NotConnected"); - return -3; - } - - if (! $olddn) $olddn=$dn; - - dol_syslog("Ldap::update dn=".$dn." olddn=".$olddn); - - // On supprime et on insère - $result = $this->delete($olddn); - $result = $this->add($dn, $info, $user); - if ($result <= 0) - { - $this->error = ldap_errno($this->connection)." ".ldap_error($this->connection)." ".$this->error; - dol_syslog("Ldap::update ".$this->error,LOG_ERR); - //print_r($info); - return -1; - } - else - { - dol_syslog("Ldap::update done successfully"); - return 1; - } - } - /** * \brief Checks a username and password - does this by logging on to the @@ -482,8 +438,9 @@ class Ldap * \brief Add a LDAP entry * \param dn DN entry key * \param info Attributes array - * \param user Objet utilisateru qui crée - * \return int <0 si KO, >0 si OK + * \param user Objet user that create + * \return int <0 if KO, >0 if OK + * \remarks Ldap object connect and bind must have been done */ function add($dn, $info, $user) { @@ -491,6 +448,18 @@ class Ldap dol_syslog("Ldap::add dn=".$dn." info=".join(',',$info)); + // Check parameters + if (! $this->connection) + { + $this->error="NotConnected"; + return -2; + } + if (! $this->bind) + { + $this->error="NotConnected"; + return -3; + } + // Encode to LDAP page code $dn=$this->convFromOutputCharset($dn,$this->ldapcharset); foreach($info as $key => $val) @@ -516,10 +485,116 @@ class Ldap } } + /** + * \brief Modify a LDAP entry + * \param dn DN entry key + * \param info Attributes array + * \param user Objet user that modify + * \return int <0 if KO, >0 if OK + * \remarks Ldap object connect and bind must have been done + */ + function modify($dn, $info, $user) + { + global $conf; + + dol_syslog("Ldap::modify dn=".$dn." info=".join(',',$info)); + + // Check parameters + if (! $this->connection) + { + $this->error="NotConnected"; + return -2; + } + if (! $this->bind) + { + $this->error="NotConnected"; + return -3; + } + + // Encode to LDAP page code + $dn=$this->convFromOutputCharset($dn,$this->ldapcharset); + foreach($info as $key => $val) + { + if (! is_array($val)) $info[$key]=$this->convFromOutputCharset($val,$this->ldapcharset); + } + + $this->dump($dn,$info); + + //print_r($info); + $result=@ldap_modify($this->connection, $dn, $info); + + if ($result) + { + dol_syslog("Ldap::modify successfull", LOG_DEBUG); + return 1; + } + else + { + $this->error=@ldap_error($this->connection); + dol_syslog("Ldap::modify failed: ".$this->error, LOG_ERR); + return -1; + } + } + + /** + * \brief Modify a LDAP entry (to use if dn != olddn) + * \param dn DN entry key + * \param info Attributes array + * \param user Objet user that delete + * \param olddn Old DN entry key (before update) + * \return int <0 if KO, >0 if OK + * \remarks Ldap object connect and bind must have been done + */ + function update($dn,$info,$user,$olddn) + { + global $conf; + + dol_syslog("Ldap::update dn=".$dn." olddn=".$olddn); + + // Check parameters + if (! $this->connection) + { + $this->error="NotConnected"; + return -2; + } + if (! $this->bind) + { + $this->error="NotConnected"; + return -3; + } + + if (! $olddn || $olddn != $dn) + { + // This case is not used for the moment + $result = $this->add($dn, $info, $user); + if ($result > 0 && $olddn && $olddn != $dn) $result = $this->delete($olddn); // If add fails, we do not try to delete old one + } + else + { + $result = $this->delete($olddn); + $result = $this->add($dn, $info, $user); + //$result = $this->modify($dn, $info, $user); // TODO Must use modify instead of delete/add when olddn is received (for the moment olddn is dn) + } + if ($result <= 0) + { + $this->error = ldap_errno($this->connection)." ".ldap_error($this->connection)." ".$this->error; + dol_syslog("Ldap::update ".$this->error,LOG_ERR); + //print_r($info); + return -1; + } + else + { + dol_syslog("Ldap::update done successfully"); + return 1; + } + } + + /** * \brief Delete a LDAP entry * \param dn DN entry key * \return int <0 si KO, >0 si OK + * \remarks Ldap object connect and bind must have been done */ function delete($dn) { @@ -527,6 +602,18 @@ class Ldap dol_syslog("Ldap::delete Delete LDAP entry dn=".$dn); + // Check parameters + if (! $this->connection) + { + $this->error="NotConnected"; + return -2; + } + if (! $this->bind) + { + $this->error="NotConnected"; + return -3; + } + // Encode to LDAP page code $dn=$this->convFromOutputCharset($dn,$this->ldapcharset); @@ -1101,32 +1188,32 @@ class Ldap /** - * \brief Convert a string into output/memory charset - * \param str String to convert - * \param pagecodefrom Page code of src string - * \return string Converted string - */ - function convToOutputCharset($str,$pagecodefrom='UTF-8') - { - global $conf; - if ($pagecodefrom == 'ISO-8859-1' && $conf->file->character_set_client == 'UTF-8') $str=utf8_encode($str); + * \brief Convert a string into output/memory charset + * \param str String to convert + * \param pagecodefrom Page code of src string + * \return string Converted string + */ + function convToOutputCharset($str,$pagecodefrom='UTF-8') + { + global $conf; + if ($pagecodefrom == 'ISO-8859-1' && $conf->file->character_set_client == 'UTF-8') $str=utf8_encode($str); if ($pagecodefrom == 'UTF-8' && $conf->file->character_set_client == 'ISO-8859-1') $str=utf8_decode($str); return $str; - } + } /** - * \brief Convert a string from output/memory charset - * \param str String to convert - * \param pagecodeto Page code for result string - * \return string Converted string - */ - function convFromOutputCharset($str,$pagecodeto='UTF-8') - { - global $conf; - if ($pagecodeto == 'ISO-8859-1' && $conf->file->character_set_client == 'UTF-8') $str=utf8_decode($str); + * \brief Convert a string from output/memory charset + * \param str String to convert + * \param pagecodeto Page code for result string + * \return string Converted string + */ + function convFromOutputCharset($str,$pagecodeto='UTF-8') + { + global $conf; + if ($pagecodeto == 'ISO-8859-1' && $conf->file->character_set_client == 'UTF-8') $str=utf8_decode($str); if ($pagecodeto == 'UTF-8' && $conf->file->character_set_client == 'ISO-8859-1') $str=utf8_encode($str); return $str; - } + } } diff --git a/htdocs/lib/ldap.lib.php b/htdocs/lib/ldap.lib.php index 5ec4f74e791..41879b2dccd 100644 --- a/htdocs/lib/ldap.lib.php +++ b/htdocs/lib/ldap.lib.php @@ -37,12 +37,12 @@ function ldap_prepare_head() // Onglets $head=array(); $h = 0; - + $head[$h][0] = DOL_URL_ROOT."/admin/ldap.php"; $head[$h][1] = $langs->trans("LDAPGlobalParameters"); $head[$h][2] = 'ldap'; $h++; - + if ($conf->global->LDAP_SYNCHRO_ACTIVE) { $head[$h][0] = DOL_URL_ROOT."/admin/ldap_users.php"; @@ -58,7 +58,7 @@ function ldap_prepare_head() $head[$h][2] = 'groups'; $h++; } - + if ($conf->societe->enabled && $conf->global->LDAP_CONTACT_ACTIVE) { $head[$h][0] = DOL_URL_ROOT."/admin/ldap_contacts.php"; @@ -66,7 +66,7 @@ function ldap_prepare_head() $head[$h][2] = 'contacts'; $h++; } - + if ($conf->adherent->enabled && $conf->global->LDAP_MEMBER_ACTIVE) { $head[$h][0] = DOL_URL_ROOT."/admin/ldap_members.php"; @@ -86,7 +86,7 @@ function show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass) { global $langs, $conf, $user; //print 'key='.$key.' dn='.$dn.' objectclass='.$objectclass; - + print '
'; if (! function_exists("ldap_connect")) { @@ -122,7 +122,7 @@ function show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass) function show_ldap_content($result,$level,$count,$var,$hide=0) { global $bc, $conf; - + $count++; if ($count > 1000) return -1; // To avoid infinite loop if (! is_array($result)) return -1; @@ -132,16 +132,16 @@ function show_ldap_content($result,$level,$count,$var,$hide=0) if ("$key" == "objectclass") continue; if ("$key" == "count") continue; if ("$key" == "dn") continue; - + if ("$val" == "objectclass") continue; if ("$val" == $lastkey[$level]) continue; - + $lastkey[$level]=$key; - - if (is_array($val)) + + if (is_array($val)) { $hide=0; - if (! is_numeric($key)) + if (! is_numeric($key)) { $var=!$var; print ''; } } diff --git a/htdocs/user.class.php b/htdocs/user.class.php index 6696b3b4bd4..7d30a2d8ca0 100644 --- a/htdocs/user.class.php +++ b/htdocs/user.class.php @@ -1414,11 +1414,11 @@ class User extends CommonObject if ($result) { - return 0; + return 0; } else { - print $this->db->error(); + print $this->db->error(); } } @@ -1566,8 +1566,8 @@ class User extends CommonObject /** * \brief Retourne chaine DN complete dans l'annuaire LDAP pour l'objet * \param info Info string loaded by _load_ldap_info - * \param mode 0=Return DN without key inside (ou=xxx,dc=aaa,dc=bbb) - * 1=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb) + * \param mode 0=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb) + * 1= * 2=Return key only (uid=qqq) * \return string DN */ @@ -1581,6 +1581,11 @@ class User extends CommonObject return $dn; } + /** + * \brief Initialise tableau info (tableau des attributs LDAP) + * \return array Tableau info des attributs + */ + /** * \brief Initialise tableau info (tableau des attributs LDAP) diff --git a/htdocs/user/group/fiche.php b/htdocs/user/group/fiche.php index 5092d0285b3..a3c1b9f50b5 100644 --- a/htdocs/user/group/fiche.php +++ b/htdocs/user/group/fiche.php @@ -144,8 +144,8 @@ if ($_POST["action"] == 'update') $editgroup = new Usergroup($db, $_GET["id"]); $editgroup->fetch($_GET["id"]); - $editgroup->nom = $_POST["group"]; - $editgroup->note = $_POST["note"]; + $editgroup->nom = trim($_POST["group"]); + $editgroup->note = dol_htmlcleanlastbr($_POST["note"]); $ret=$editgroup->update(); diff --git a/htdocs/user/group/ldap.php b/htdocs/user/group/ldap.php index 79b6bad75c0..635d3b38d69 100644 --- a/htdocs/user/group/ldap.php +++ b/htdocs/user/group/ldap.php @@ -42,33 +42,62 @@ if ($user->societe_id > 0) $socid = $user->societe_id; } - - -/* - * Affichage page - */ - -llxHeader(); - -$form = new Form($db); - $fgroup = new Usergroup($db, $_GET["id"]); $fgroup->fetch($_GET["id"]); $fgroup->getrights(); /* - * Affichage onglets + * Actions */ -$head = group_prepare_head($fgroup); -dol_fiche_head($head, 'ldap', $langs->trans("Group")); +if ($_GET["action"] == 'dolibarr2ldap') +{ + $message=""; + + $db->begin(); + + $ldap=new Ldap(); + $result=$ldap->connect_bind(); + + $oldobject=$fgroup; // TODO Get oldobject + + $oldinfo=$oldobject->_load_ldap_info(); + $olddn=$oldobject->_load_ldap_dn($oldinfo); + + $info=$fgroup->_load_ldap_info(); + $dn=$fgroup->_load_ldap_dn($info); + $result=$ldap->add($dn,$info,$user); + $result=$ldap->update($dn,$info,$user,$olddn); + + if ($result >= 0) + { + $message.='
'.$langs->trans("GroupSynchronized").'
'; + $db->commit(); + } + else + { + $message.='
'.$ldap->error.'
'; + $db->rollback(); + } +} + /* - * Fiche en mode visu + * View */ + +llxHeader(); + +$form = new Form($db); + + +$head = group_prepare_head($fgroup); + +dol_fiche_head($head, 'ldap', $langs->trans("Group")); + print '
'; @@ -153,8 +153,9 @@ function show_ldap_content($result,$level,$count,$var,$hide=0) } else { - if ($hide) print eregi_replace('.','*',$val); - else print $val; + $newstring=@htmlentities($val,ENT_COMPAT,'UTF-8'); // Make entity encoding + if ($hide) print eregi_replace('.','*',$newstring); + else print $newstring; print '
'; // Ref @@ -97,7 +126,7 @@ $langs->load("admin"); // LDAP DN print '\n"; -// LDAP Clé +// LDAP Cle print '\n"; // LDAP Server @@ -109,12 +138,29 @@ print "
LDAP '.$langs->trans("LDAPGroupDn").''.$conf->global->LDAP_GROUP_DN."
LDAP '.$langs->trans("LDAPNamingAttribute").''.$conf->global->LDAP_KEY_GROUPS."
\n"; print ''; -print '
'; +if ($message) { print $message; } + + +/* + * Barre d'actions + */ + +print '
'; + +if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') +{ + print ''.$langs->trans("ForceSynchronize").''; +} + +print "
\n"; + +if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') print "
\n"; -print_titre($langs->trans("LDAPInformationsForThisGroup")); // Affichage attributs LDAP +print_titre($langs->trans("LDAPInformationsForThisGroup")); + print ''; print ''; diff --git a/htdocs/user/ldap.php b/htdocs/user/ldap.php index f4ff52deb44..111e38e4282 100644 --- a/htdocs/user/ldap.php +++ b/htdocs/user/ldap.php @@ -61,9 +61,15 @@ if ($_GET["action"] == 'dolibarr2ldap') $ldap=new Ldap(); $result=$ldap->connect_bind(); + $oldobject=$fuser; // TODO Get oldobject + + $oldinfo=$oldobject->_load_ldap_info(); + $olddn=$oldobject->_load_ldap_dn($oldinfo); + $info=$fuser->_load_ldap_info(); $dn=$fuser->_load_ldap_dn($info); - $result=$ldap->update($dn,$info,$user); // Marche en creation LDAP et mise a jour + $result=$ldap->add($dn,$info,$user); + $result=$ldap->update($dn,$info,$user,$olddn); if ($result >= 0) { @@ -146,7 +152,7 @@ if ($conf->global->LDAP_SERVER_TYPE == "activedirectory") // LDAP DN print '\n"; -// LDAP Cl� +// LDAP Cle print '\n"; // LDAP Server diff --git a/htdocs/usergroup.class.php b/htdocs/usergroup.class.php index 5fdcd9201aa..6b91fbf2c0c 100644 --- a/htdocs/usergroup.class.php +++ b/htdocs/usergroup.class.php @@ -525,8 +525,8 @@ class UserGroup extends CommonObject /** * \brief Retourne chaine DN complete dans l'annuaire LDAP pour l'objet * \param info Info string loaded by _load_ldap_info - * \param mode 0=Return DN without key inside (ou=xxx,dc=aaa,dc=bbb) - * 1=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb) + * \param mode 0=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb) + * 1=Return DN without key inside (ou=xxx,dc=aaa,dc=bbb) * 2=Return key only (uid=qqq) * \return string DN */ @@ -534,7 +534,7 @@ class UserGroup extends CommonObject { global $conf; $dn=''; - if ($mode==0) $dn=$conf->global->LDAP_KEY_GROUPS."=".$info[$conf->global->LDAP_KEY_GROUPS].",".$conf->global->LDAP_USER_DN; + if ($mode==0) $dn=$conf->global->LDAP_KEY_GROUPS."=".$info[$conf->global->LDAP_KEY_GROUPS].",".$conf->global->LDAP_GROUP_DN; if ($mode==1) $dn=$conf->global->LDAP_GROUP_DN; if ($mode==2) $dn=$conf->global->LDAP_KEY_GROUPS."=".$info[$conf->global->LDAP_KEY_GROUPS]; return $dn; diff --git a/scripts/adherents/sync_member_dolibarr2ldap.php b/scripts/adherents/sync_member_dolibarr2ldap.php index c9090de0134..261d098926b 100644 --- a/scripts/adherents/sync_member_dolibarr2ldap.php +++ b/scripts/adherents/sync_member_dolibarr2ldap.php @@ -122,10 +122,16 @@ if ($resql) print $langs->transnoentities("UpdateMember")." rowid=".$member->id." ".$member->fullname; - $info=$member->_load_ldap_info(); + $oldobject=$member; + + $oldinfo=$oldobject->_load_ldap_info(); + $olddn=$oldobject->_load_ldap_dn($oldinfo); + + $info=$member->_load_ldap_info(); $dn=$member->_load_ldap_dn($info); - $result=$ldap->update($dn,$info,$user); + $result=$ldap->add($dn,$info,$user); // Wil fail if already exists + $result=$ldap->update($dn,$info,$user,$olddn); if ($result > 0) { print " - ".$langs->transnoentities("OK"); diff --git a/scripts/company/sync_contacts_dolibarr2ldap.php b/scripts/company/sync_contacts_dolibarr2ldap.php index e3001859e95..df6b8ceac54 100644 --- a/scripts/company/sync_contacts_dolibarr2ldap.php +++ b/scripts/company/sync_contacts_dolibarr2ldap.php @@ -86,10 +86,16 @@ if ($resql) print $langs->trans("UpdateContact")." rowid=".$contact->id." ".$contact->getFullName($langs); + $oldobject=$contact; + + $oldinfo=$oldobject->_load_ldap_info(); + $olddn=$oldobject->_load_ldap_dn($oldinfo); + $info=$contact->_load_ldap_info(); $dn=$contact->_load_ldap_dn($info); - $result=$ldap->update($dn,$info,$user); + $result=$ldap->add($dn,$info,$user); // Wil fail if already exists + $result=$ldap->update($dn,$info,$user,$olddn); if ($result > 0) { print " - ".$langs->trans("OK"); diff --git a/scripts/user/sync_group_dolibarr2ldap.php b/scripts/user/sync_group_dolibarr2ldap.php index e4b560924e8..8f3890d1a60 100644 --- a/scripts/user/sync_group_dolibarr2ldap.php +++ b/scripts/user/sync_group_dolibarr2ldap.php @@ -28,7 +28,7 @@ // Test si mode batch $sapi_type = php_sapi_name(); -$script_file=__FILE__; +$script_file=__FILE__; if (eregi('([^\\\/]+)$',$script_file,$reg)) $script_file=$reg[1]; if (substr($sapi_type, 0, 3) == 'cgi') { @@ -37,7 +37,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') { } if (! isset($argv[1]) || ! $argv[1]) { - print "Usage: $script_file now\n"; + print "Usage: $script_file now\n"; exit; } $now=$argv[1]; @@ -59,7 +59,7 @@ print "***** $script_file ($version) *****\n"; if (! $conf->global->LDAP_SYNCHRO_ACTIVE) { print $langs->trans("LDAPSynchronizationNotSetupInDolibarr"); - exit 1; + exit 1; } */ @@ -74,7 +74,7 @@ if ($resql) $ldap=new Ldap(); $ldap->connect_bind(); - + while ($i < $num) { $ldap->error=""; @@ -84,13 +84,19 @@ if ($resql) $fgroup = new UserGroup($db); $fgroup->id = $obj->rowid; $fgroup->fetch($fgroup->id); - + print $langs->trans("UpdateGroup")." rowid=".$fgroup->id." ".$fgroup->nom; - $info=$fgroup->_load_ldap_info(); + $oldobject=$fgroup; + + $oldinfo=$oldobject->_load_ldap_info(); + $olddn=$oldobject->_load_ldap_dn($oldinfo); + + $info=$fgroup->_load_ldap_info(); $dn=$fgroup->_load_ldap_dn($info); - - $result=$ldap->update($dn,$info,$user); + + $result=$ldap->add($dn,$info,$user); // Wil fail if already exists + $result=$ldap->update($dn,$info,$user,$olddn); if ($result > 0) { print " - ".$langs->trans("OK"); diff --git a/scripts/user/sync_user_dolibarr2ldap.php b/scripts/user/sync_user_dolibarr2ldap.php index 6cdbd4737f5..d4a5745864c 100644 --- a/scripts/user/sync_user_dolibarr2ldap.php +++ b/scripts/user/sync_user_dolibarr2ldap.php @@ -28,7 +28,7 @@ // Test si mode batch $sapi_type = php_sapi_name(); -$script_file=__FILE__; +$script_file=__FILE__; if (eregi('([^\\\/]+)$',$script_file,$reg)) $script_file=$reg[1]; if (substr($sapi_type, 0, 3) == 'cgi') { @@ -37,7 +37,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') { } if (! isset($argv[1]) || ! $argv[1]) { - print "Usage: $script_file now\n"; + print "Usage: $script_file now\n"; exit; } $now=$argv[1]; @@ -59,7 +59,7 @@ print "***** $script_file ($version) *****\n"; if (! $conf->global->LDAP_SYNCHRO_ACTIVE) { print $langs->trans("LDAPSynchronizationNotSetupInDolibarr"); - exit 1; + exit 1; } */ @@ -84,13 +84,19 @@ if ($resql) $fuser = new User($db); $fuser->id = $obj->rowid; $fuser->fetch(); - + print $langs->trans("UpdateUser")." rowid=".$fuser->id." ".$fuser->fullname; - $info=$fuser->_load_ldap_info(); + $oldobject=$fuser; + + $oldinfo=$oldobject->_load_ldap_info(); + $olddn=$oldobject->_load_ldap_dn($oldinfo); + + $info=$fuser->_load_ldap_info(); $dn=$fuser->_load_ldap_dn($info); - $result=$ldap->update($dn,$info,$user); + $result=$ldap->add($dn,$info,$user); // Wil fail if already exists + $result=$ldap->update($dn,$info,$user,$olddn); if ($result > 0) { print " - ".$langs->trans("OK");
LDAP '.$langs->trans("LDAPUserDn").''.$conf->global->LDAP_USER_DN."
LDAP '.$langs->trans("LDAPNamingAttribute").''.$conf->global->LDAP_KEY_USERS."