diff --git a/htdocs/contact.class.php b/htdocs/contact.class.php index 94d8016b3b15ba440bd7bd1cb7f960cce314b47a..af3ff8abdc45f58dd92a490b658044421bec2b2e 100644 --- a/htdocs/contact.class.php +++ b/htdocs/contact.class.php @@ -114,8 +114,11 @@ class Contact // Fin appel triggers // \todo Mettre en trigger - $this->create_ldap($user); - + if ($conf->ldap->enabled && $conf->global->LDAP_CONTACT_ACTIVE) + { + $this->create_ldap($user); + } + return $this->id; } else @@ -188,7 +191,10 @@ class Contact // Fin appel triggers // \todo Mettre en trigger - $this->update_ldap($user); + if ($conf->ldap->enabled && $conf->global->LDAP_CONTACT_ACTIVE) + { + $this->update_ldap($user); + } } @@ -257,7 +263,7 @@ class Contact /** - * \brief Mise � jour du contact dans l'arbre LDAP + * \brief Mise � jour dans l'arbre LDAP * \param user Utilisateur qui effectue la mise � jour * \return int <0 si ko, >0 si ok */ @@ -265,7 +271,7 @@ class Contact { global $conf, $langs; - if (! $conf->ldap->enabled || ! $conf->global->LDAP_CONTACT_ACTIVE) return 0; + //if (! $conf->ldap->enabled || ! $conf->global->LDAP_CONTACT_ACTIVE) return 0; $info = array(); @@ -626,8 +632,9 @@ class Contact } /* - * \brief Efface le contact de la base et �ventuellement de l'annuaire LDAP - * \param id id du contact a effacer + * \brief Efface le contact de la base et �ventuellement de l'annuaire LDAP + * \param id id du contact a effacer + * \return int <0 si ko, >0 si ok */ function delete($id) { @@ -664,19 +671,22 @@ class Contact $result=$interface->run_triggers('CONTACT_DELETE',$this,$user,$langs,$conf); // Fin appel triggers - // \todo Mettre en trigger - - // On modifie contact avec anciens noms - $savname=$this->name; - $savfirstname=$this->firstname; - $this->name=$this->old_name; - $this->firstname=$this->old_firstname; - - $this->delete_ldap($user); - - $this->name=$savname; - $this->firstname=$savfirstname; + if ($conf->ldap->enabled && $conf->global->LDAP_CONTACT_ACTIVE) + { + // On modifie contact avec anciens noms + $savname=$this->name; + $savfirstname=$this->firstname; + $this->name=$this->old_name; + $this->firstname=$this->old_firstname; + + $this->delete_ldap($user); + + $this->name=$savname; + $this->firstname=$savfirstname; + } + + return 1; } diff --git a/htdocs/contact/ldap.php b/htdocs/contact/ldap.php index 6f4d55366b5f5a0ff3223607558726affaf334f1..e39d1803ca4273900602b8cc19cb8717c2ec418e 100644 --- a/htdocs/contact/ldap.php +++ b/htdocs/contact/ldap.php @@ -21,9 +21,9 @@ */ /** - \file htdocs/contact/exportimport.php - \ingroup societe - \brief Onglet exports-imports d'un contact + \file htdocs/contact/ldap.php + \ingroup ldap + \brief Page fiche LDAP contact \version $Revision$ */ @@ -127,15 +127,14 @@ print '<br>'; print_titre($langs->trans("LDAPInformationsForThisContact")); -// Affichage actions sur contact +// Affichage attributs LDAP print '<table width="100%" class="noborder">'; print '<tr class="liste_titre">'; -print '<td>'.$langs->trans("LDAPAttribute").'</td>'; +print '<td>'.$langs->trans("LDAPAttributes").'</td>'; print '<td>'.$langs->trans("Value").'</td>'; print '</tr>'; - // Lecture LDAP $ldap=new AuthLdap(); $result=$ldap->connect(); @@ -155,14 +154,21 @@ if ($result) if ($bind) { - $info["cn"] = utf8_encode(trim($contact->firstname." ".$contact->name)); + $info["cn"] = trim($contact->firstname." ".$contact->name); $dn = "cn=".$info["cn"].",".$conf->global->LDAP_CONTACT_DN; $result=$ldap->search($dn,'(objectClass=*)'); // Affichage arbre - $html=new Form($db); - $html->show_ldap_content($result,0,0,true); + if (sizeof($result)) + { + $html=new Form($db); + $html->show_ldap_content($result,0,0,true); + } + else + { + print '<tr><td colspan="2">'.$langs->trans("LDAPRecordNotFound").'</td></tr>'; + } } else { diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index cec098e45a3e114a01ec4b390d9aed909c592659..9248786b77f83ff9fa0212867f4837f787033878 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -546,7 +546,6 @@ LDAPFieldLoginUnix=Login (unix) LDAPFieldLoginExample=Suggested value : uid LDAPFilterConnection=Search filter LDAPFilterConnectionExample=Suggested value : &(objectClass=user)(objectCategory=person) -LDAPAttributes=LDAP attributes LDAPFieldLoginSamba=Login (samba, activedirectory) LDAPFieldLoginSambaExample=Suggested value : samaccountname (Samba and ActiveDirectory) LDAPFieldName=Name diff --git a/htdocs/langs/en_US/ldap.lang b/htdocs/langs/en_US/ldap.lang index 03d4c11fcef5250bd87716a41b908f35f038e625..f8ba059e19df0ef9b0794aa0caa4580ddae7267f 100644 --- a/htdocs/langs/en_US/ldap.lang +++ b/htdocs/langs/en_US/ldap.lang @@ -6,5 +6,10 @@ LdapUacf_DONT_EXPIRE_PASSWORD=Password never expires LdapUacf_ACCOUNTDISABLE=Account is disabled on this domain LDAPInformationsForThisContact=Informations in LDAP database for this contact LDAPInformationsForThisUser=Informations in LDAP database for this user -LDAPAttribute=Attribute -LDAPCard=LDAP card \ No newline at end of file +LDAPInformationsForThisGroup=Informations in LDAP database for this group +LDAPAttribute=LDAP attribute +LDAPAttributes=LDAP attributes +LDAPCard=LDAP card +LDAPRecordNotFound=Record not found in LDAP database +LDAPUsers=Users in LDAP database +LDAPGroups=Groups in LDAP database \ No newline at end of file diff --git a/htdocs/langs/fr_BE/admin.lang b/htdocs/langs/fr_BE/admin.lang index 5f9198a6c7a2e8e5f89c24c18204fedeee3c2e81..d1b55e475ec484422a510dca126c921205dac1fd 100644 --- a/htdocs/langs/fr_BE/admin.lang +++ b/htdocs/langs/fr_BE/admin.lang @@ -518,7 +518,6 @@ LDAPFieldLogin=Attribut login LDAPFieldLoginExample=Attribut par d�faut: uid LDAPFilterConnection=Filtre de recherche LDAPFilterConnectionExample=Filtre par d�faut : &(objectClass=user)(objectCategory=person) -LDAPAttributes=Attributs LDAP LDAPFieldLoginSamba=Login LDAPFieldLoginSambaExample=Attribut par d�faut: samaccountname (Samba and Active Directory) LDAPFieldName=Non diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 5bccca9ff750fbb943d48ad57d063faf9de9ab5b..d20428bc1948e71ea3840364c1886327d572a37f 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -546,7 +546,6 @@ LDAPFieldLoginUnix=Login (unix) LDAPFieldLoginExample=Valeur recommand�e : uid LDAPFilterConnection=Filtre de recherche LDAPFilterConnectionExample=Valeur recommand�e : &(objectClass=user)(objectCategory=person) -LDAPAttributes=Attributs LDAP LDAPFieldLoginSamba=Login (samba, activedirectory) LDAPFieldLoginSambaExample=Valeur recommand�e : samaccountname (Samba et ActiveDirectory) LDAPFieldName=Nom diff --git a/htdocs/langs/fr_FR/ldap.lang b/htdocs/langs/fr_FR/ldap.lang index 510592b640a1c0fcb33bf7cdad40bcef9166cbb5..738c3a1d8fa2e89ef5d54442fbad6970a6be305b 100644 --- a/htdocs/langs/fr_FR/ldap.lang +++ b/htdocs/langs/fr_FR/ldap.lang @@ -6,5 +6,10 @@ LdapUacf_DONT_EXPIRE_PASSWORD=Le mot de passe n'expire jamais LdapUacf_ACCOUNTDISABLE=Le compte est d�sactiv� sur le domaine LDAPInformationsForThisContact=Informations en base LDAP pour ce contact LDAPInformationsForThisUser=Informations en base LDAP pour cet utilisateur -LDAPAttribute=Attribut +LDAPInformationsForThisGroup=Informations en base LDAP pour ce groupe +LDAPAttribute=Attribut LDAP +LDAPAttributes=Attributs LDAP LDAPCard=Fiche LDAP +LDAPRecordNotFound=Enregistrement non trouv� dans la base LDAP +LDAPUsers=Utilisateurs en base LDAP +LDAPGroups=Groupes en base LDAP diff --git a/htdocs/lib/authldap.lib.php b/htdocs/lib/authldap.lib.php index 02ca9917d4ad175cfa755989a6f9b04188e6f26a..d7a81b0b4c77e9e72e8459304a38c700230f7cf7 100644 --- a/htdocs/lib/authldap.lib.php +++ b/htdocs/lib/authldap.lib.php @@ -26,7 +26,7 @@ /** \file htdocs/lib/authldap.lib.php - \brief Librairie contenant les fonctions pour acc�der au serveur LDAP + \brief Classe de gestion d'annuaire LDAP \author Rodolphe Quiedeville \author Benoit Mortier \author Regis Houssin @@ -545,8 +545,10 @@ class AuthLdap { * username. The search criteria is a standard LDAP query - * returns all * users. The $attributeArray variable contains the required user detail field names */ - function getUsers( $search, $attributeArray) { - + function getUsers( $search, $attributeArray) + { + $userslist=array(); + // Perform the search and get the entry handles // if the directory is AD, then bind first with the search user first @@ -555,7 +557,7 @@ class AuthLdap { } $filter = '('.$this->filter.'('.$this->getUserIdentifier().'='.$search.'))'; - +//print "zzz".$filter; $this->result = @ldap_search( $this->connection, $this->people, $filter); if (!$this->result) @@ -592,16 +594,8 @@ class AuthLdap { } } - if ( !@asort( $userslist)) { - /* Sort into alphabetical order. If this fails, it's because there - ** were no results returned (array is empty) - so just return false. - */ - $this->ldapErrorCode = -1; - $this->ldapErrorText = "No users found matching search criteria ".$search; - return false; - } + asort($userslist); return $userslist; - } /** @@ -649,22 +643,30 @@ class AuthLdap { } /** - * \brief fonction de recherche avec filtre - * \param dn de recherche - * \param filtre de recherche (ex: sn=nom_personne) + * \brief Fonction de recherche avec filtre + * \param checkDn DN de recherche + * \param filter filtre de recherche (ex: sn=nom_personne) + * \remarks this->conneciton doit etre d�fini donc la methode bind ou authbind doit avoir deja �t� appel�e */ - function search( $checkDn, $filter) { - + function search($checkDn, $filter) + { // Perform the search and get the entry handles + if ($this->serverType != "activedirectory") + { + $checkDn=utf8_decode($checkDn); + } + dolibarr_syslog("authldap.lib::search checkDn=".$checkDn." filter=".$filer); + // if the directory is AD, then bind first with the search user first if ($this->serverType == "activedirectory") { $this->authBind($this->searchUser, $this->searchPassword); } - $this->result = @ldap_search( $this->connection, $checkDn, $filter); + + $this->result = @ldap_search($this->connection, $checkDn, $filter); - $result = @ldap_get_entries( $this->connection, $this->result); + $result = @ldap_get_entries($this->connection, $this->result); if (!$result) { diff --git a/htdocs/lib/usergroups.lib.php b/htdocs/lib/usergroups.lib.php new file mode 100644 index 0000000000000000000000000000000000000000..f320f1e501d2d429b9e8548624f5c9f332de6a1a --- /dev/null +++ b/htdocs/lib/usergroups.lib.php @@ -0,0 +1,111 @@ +<?php +/* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * or see http://www.gnu.org/ + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/lib/usergroups.lib.php + \brief Ensemble de fonctions de base pour les utilisaterus et groupes + \version $Revision$ + + Ensemble de fonctions de base de dolibarr sous forme d'include +*/ + +function user_prepare_head($user) +{ + global $langs, $conf; + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT.'/user/fiche.php?id='.$user->id; + $head[$h][1] = $langs->trans("UserCard"); + $head[$h][2] = 'user'; + $h++; + + if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE) + { + $langs->load("ldap"); + $head[$h][0] = DOL_URL_ROOT.'/user/ldap.php?id='.$user->id; + $head[$h][1] = $langs->trans("LDAPCard"); + $head[$h][2] = 'ldap'; + $h++; + } + + $head[$h][0] = DOL_URL_ROOT.'/user/perms.php?id='.$user->id; + $head[$h][1] = $langs->trans("UserRights"); + $head[$h][2] = 'rights'; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/user/param_ihm.php?id='.$user->id; + $head[$h][1] = $langs->trans("UserGUISetup"); + $head[$h][2] = 'guisetup'; + $h++; + + if ($conf->bookmark4u->enabled) + { + $head[$h][0] = DOL_URL_ROOT.'/user/addon.php?id='.$user->id; + $head[$h][1] = $langs->trans("Bookmark4u"); + $head[$h][2] = 'bookmark4u'; + $h++; + } + + if ($conf->clicktodial->enabled) + { + $head[$h][0] = DOL_URL_ROOT.'/user/clicktodial.php?id='.$user->id; + $head[$h][1] = $langs->trans("ClickToDial"); + $head[$h][2] = 'clicktodial'; + $h++; + } + + return $head; +} + + +function group_prepare_head($group) +{ + global $langs, $conf; + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT.'/user/group/fiche.php?id='.$group->id; + $head[$h][1] = $langs->trans("GroupCard"); + $head[$h][2] = 'group'; + $h++; + + if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE) + { + $langs->load("ldap"); + $head[$h][0] = DOL_URL_ROOT.'/user/group/ldap.php?id='.$group->id; + $head[$h][1] = $langs->trans("LDAPCard"); + $head[$h][2] = 'ldap'; + $h++; + } + + $head[$h][0] = DOL_URL_ROOT.'/user/group/perms.php?id='.$group->id; + $head[$h][1] = $langs->trans("GroupRights"); + $head[$h][2] = 'rights'; + $h++; + + return $head; +} + +?> \ No newline at end of file diff --git a/htdocs/user.class.php b/htdocs/user.class.php index ed9fbcd64964efc02b0be230a67e9cafbaedc50e..a7f687f961c0f8697a0a82c6328100a7328f9743 100644 --- a/htdocs/user.class.php +++ b/htdocs/user.class.php @@ -125,6 +125,7 @@ class User $sql .= " WHERE u.rowid = ".$this->id; } + dolibarr_syslog("User.class::fetch this->id=".$this->id." login=".$login); $result = $this->db->query($sql); if ($result) { @@ -136,7 +137,7 @@ class User $this->nom = $obj->name; $this->prenom = $obj->firstname; - $this->fullname = $this->prenom . ' ' . $this->nom; + $this->fullname = trim($this->prenom . ' ' . $this->nom); $this->code = $obj->code; $this->login = $obj->login; $this->pass = $obj->pass; @@ -1192,7 +1193,155 @@ class User if ($statut == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5'); } } - + + + /** + * \brief Mise � jour dans l'arbre LDAP + * \param user Utilisateur qui effectue la mise � jour + * \return int <0 si ko, >0 si ok + */ + function update_ldap($user) + { + global $conf, $langs; + + //if (! $conf->ldap->enabled || ! $conf->global->LDAP_SYNCHRO_ACTIVE) return 0; + + $info = array(); + + dolibarr_syslog("User.class::update_ldap this->id=".$this->id,LOG_DEBUG); + + $ldap=new AuthLdap(); + $result=$ldap->connect(); + if ($result) + { + $bind=''; + if ($conf->global->LDAP_ADMIN_DN && $conf->global->LDAP_ADMIN_PASS) + { + dolibarr_syslog("User.class::update_ldap authBind user=".$conf->global->LDAP_ADMIN_DN,LOG_DEBUG); + $bind=$ldap->authBind($conf->global->LDAP_ADMIN_DN,$conf->global->LDAP_ADMIN_PASS); + } + else + { + dolibarr_syslog("User.class::update_ldap bind",LOG_DEBUG); + $bind=$ldap->bind(); + } + if ($bind) + { + if ($conf->global->LDAP_SERVER_TYPE == 'activedirectory') + { + $info["objectclass"]=array("top", + "person", + "organizationalPerson", + "user"); + } + else + { + $info["objectclass"]=array("top", + "person", + "organizationalPerson", + "inetOrgPerson"); + } + + // Champs obligatoires + $info["cn"] = trim($this->prenom." ".$this->nom); + if ($this->nom) $info[$conf->global->LDAP_FIELD_NAME] = $this->nom; + else + { + $langs->load("other"); + $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Name")); + return -1; + } + + // Champs optionnels + if ($this->prenom && $conf->global->LDAP_FIELD_FIRSTNAME) $info[$conf->global->LDAP_FIELD_FIRSTNAME] = $this->prenom; + if ($this->poste) $info["title"] = $this->poste; + if ($this->societe_id > 0) + { + $soc = new Societe($this->db); + $soc->fetch($this->societe_id); + + $info["o"] = $soc->nom; + if ($soc->client == 1) $info["businessCategory"] = "Customers"; + if ($soc->client == 2) $info["businessCategory"] = "Prospects"; + if ($soc->fournisseur == 1) $info["businessCategory"] = "Suppliers"; + } + if ($this->address && $conf->global->LDAP_FIELD_ADDRESS) $info[$conf->global->LDAP_FIELD_ADDRESS] = $this->address; + if ($this->cp && $conf->global->LDAP_FIELD_ZIP) $info[$conf->global->LDAP_FIELD_ZIP] = $this->cp; + if ($this->ville && $conf->global->LDAP_FIELD_TOWN) $info[$conf->global->LDAP_FIELD_TOWN] = $this->ville; + if ($this->phone_pro && $conf->global->LDAP_FIELD_PHONE) $info[$conf->global->LDAP_FIELD_PHONE] = $this->phone_pro; + if ($this->phone_perso) $info["homePhone"] = $this->phone_perso; + if ($this->phone_mobile && $conf->global->LDAP_FIELD_MOBILE) $info[$conf->global->LDAP_FIELD_MOBILE] = $this->phone_mobile; + if ($this->fax && $conf->global->LDAP_FIELD_FAX) $info[$conf->global->LDAP_FIELD_FAX] = $this->fax; + if ($this->note) $info["description"] = $this->note; + if ($this->email && $conf->global->LDAP_FIELD_MAIL) $info[$conf->global->LDAP_FIELD_MAIL] = $this->email; + + if ($conf->global->LDAP_SERVER_TYPE == 'egroupware') + { + $info["objectclass"][4] = "phpgwContact"; // compatibilite egroupware + + $info['uidnumber'] = $this->id; + + $info['phpgwTz'] = 0; + $info['phpgwMailType'] = 'INTERNET'; + $info['phpgwMailHomeType'] = 'INTERNET'; + + $info["phpgwContactTypeId"] = 'n'; + $info["phpgwContactCatId"] = 0; + $info["phpgwContactAccess"] = "public"; + + if (strlen($user->egroupware_id) == 0) + { + $user->egroupware_id = 1; + } + + $info["phpgwContactOwner"] = $user->egroupware_id; + + if ($this->email) $info["rfc822Mailbox"] = $this->email; + if ($this->phone_mobile) $info["phpgwCellTelephoneNumber"] = $this->phone_mobile; + } + + $info["uid"] = "Dolibarr ".$this->ldap_sid; + + $newdn = "cn=".$info["cn"].",".$conf->global->LDAP_USER_DN; + $olddn = $newdn; + if ($this->old_firstname || $this->old_name) $olddn="cn=".trim($this->old_firstname." ".$this->old_name).",".$conf->global->LDAP_CONTACT_DN; + + // On supprime et on ins�re + dolibarr_syslog("User.class::update_ldap olddn=".$olddn." newdn=".$newdn); + + $result = $ldap->delete($olddn); + $result = $ldap->add($newdn, $info); + if ($result <= 0) + { + $this->error = ldap_errno($ldap->connection)." ".ldap_error($ldap->connection)." ".$ldap->error; + dolibarr_syslog("User.class::update_ldap ".$this->error,LOG_ERROR); + //print_r($info); + return -1; + } + else + { + dolibarr_syslog("User.class::update_ldap rowid=".$this->id." added in LDAP"); + } + + $ldap->unbind(); + + return 1; + } + else + { + $this->error = "Error ".ldap_errno($ldap->connection)." ".ldap_error($ldap->connection); + dolibarr_syslog("User.class::update_ldap bind failed",LOG_DEBUG); + return -1; + } + } + else + { + $this->error="Failed to connect to LDAP server !"; + dolibarr_syslog("User.class::update_ldap Connexion failed",LOG_DEBUG); + return -1; + } + } + } ?> diff --git a/htdocs/user/addon.php b/htdocs/user/addon.php index 18e3d72401e9211e52fd6fcc55ebf0b522db350d..abac132026d1befa7841f17c159917372fde3b3e 100644 --- a/htdocs/user/addon.php +++ b/htdocs/user/addon.php @@ -28,6 +28,7 @@ require("./pre.inc.php"); require_once DOL_DOCUMENT_ROOT."/bookmark4u.class.php"; +require_once(DOL_DOCUMENT_ROOT."/lib/usergroups.lib.php"); $langs->load("users"); @@ -45,6 +46,7 @@ if ($_GET["action"] == 'create_bk4u_login') if ($result > 0) { Header("Location: addon.php?id=".$_GET["id"]); + exit; } else { @@ -71,40 +73,13 @@ if ($_GET["id"]) $bk4u->get_bk4u_uid($fuser); - /* - * Affichage onglets - */ - - $h = 0; - - $head[$h][0] = DOL_URL_ROOT.'/user/fiche.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("UserCard"); - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/user/perms.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("UserRights"); - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/user/param_ihm.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("UserGUISetup"); - $h++; + /* + * Affichage onglets + */ + $head = user_prepare_head($fuser); - if ($conf->bookmark4u->enabled) - { - $head[$h][0] = DOL_URL_ROOT.'/user/addon.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("Bookmark4u"); - $hselected=$h; - $h++; - } - - if ($conf->clicktodial->enabled) - { - $head[$h][0] = DOL_URL_ROOT.'/user/clicktodial.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("ClickToDial"); - $h++; - } + dolibarr_fiche_head($head, 'bookmark4u', $langs->trans("User").": ".$fuser->fullname); - dolibarr_fiche_head($head, $hselected, $langs->trans("User").": ".$fuser->fullname); /* * Fiche en mode visu @@ -125,7 +100,7 @@ if ($_GET["id"]) print "</tr>\n"; - print "<tr>".'<td width="25%" valign="top">'.$langs->trans("Login Boobkmark4u").'</td>'; + print "<tr>".'<td width="25%" valign="top">'.$langs->trans("Login Bookmark4u").'</td>'; print '<td class="valeur">'; if ($bk4u->uid == 0) diff --git a/htdocs/user/clicktodial.php b/htdocs/user/clicktodial.php index 4a9e43eb49063189041a324d101b34c4ecf575a4..7053a89f6b16af6882d5a0087f7e5e6cdb2f7b31 100644 --- a/htdocs/user/clicktodial.php +++ b/htdocs/user/clicktodial.php @@ -27,7 +27,7 @@ */ require("./pre.inc.php"); -require_once DOL_DOCUMENT_ROOT."/bookmark4u.class.php"; +require_once(DOL_DOCUMENT_ROOT."/lib/usergroups.lib.php"); $langs->load("users"); @@ -64,43 +64,13 @@ if ($_GET["id"]) $fuser->fetch(); $fuser->fetch_clicktodial(); - $bk4u = new Bookmark4u($db); - $bk4u->get_bk4u_uid($fuser); - /* - * Affichage onglets - */ - - $h = 0; - - $head[$h][0] = DOL_URL_ROOT.'/user/fiche.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("UserCard"); - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/user/perms.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("UserRights"); - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/user/param_ihm.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("UserGUISetup"); - $h++; - - if ($conf->bookmark4u->enabled) - { - $head[$h][0] = DOL_URL_ROOT.'/user/addon.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("Bookmark4u"); - $h++; - } - - if ($conf->clicktodial->enabled) - { - $head[$h][0] = DOL_URL_ROOT.'/user/clicktodial.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("ClickToDial"); - $hselected=$h; - $h++; - } + /* + * Affichage onglets + */ + $head = user_prepare_head($fuser); - dolibarr_fiche_head($head, $hselected, $langs->trans("User").": ".$fuser->fullname); + dolibarr_fiche_head($head, 'clicktodial', $langs->trans("User").": ".$fuser->fullname); /* * Fiche en mode visu diff --git a/htdocs/user/fiche.php b/htdocs/user/fiche.php index 475ee6ea182ede6797bafa08ef36912740586877..bd7f3cbf57ae659a62c19b80ae09497813f27c5e 100644 --- a/htdocs/user/fiche.php +++ b/htdocs/user/fiche.php @@ -33,6 +33,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/authldap.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/usergroups.lib.php"); // Defini si peux creer un utilisateur ou gerer groupe sur un utilisateur @@ -50,7 +51,6 @@ if ($_GET["id"]) $caneditpassword=( (($user->id == $_GET["id"]) && $user->rights->user->self->password) || (($user->id != $_GET["id"]) && $user->rights->user->user->password) ); } - if ($user->id <> $_GET["id"] && ! $canreadperms) { accessforbidden(); @@ -60,10 +60,10 @@ $langs->load("users"); $langs->load("companies"); $langs->load("ldap"); +$action=isset($_GET["action"])?$_GET["action"]:$_POST["action"]; $form = new Form($db); -$action=isset($_GET["action"])?$_GET["action"]:$_POST["action"]; /** @@ -116,7 +116,7 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes") } } -//reactive un compte ldap +// Reactive un compte ldap if ($conf->ldap->enabled && $_GET["action"] == 'reactivate' && $candisableuser) { if ($_GET["id"] <> $user->id) @@ -236,75 +236,75 @@ if ($_GET["action"] == 'removegroup' && $caneditfield) } } -if ($_POST["action"] == 'update' && $caneditfield) +if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $caneditfield) { - $message=""; + $message=""; - $db->begin(); + $db->begin(); - $edituser = new User($db, $_GET["id"]); - $edituser->fetch(); - - $edituser->oldpass = $edituser->pass; - - $edituser->nom = trim($_POST["nom"]); - $edituser->prenom = trim($_POST["prenom"]); - $edituser->login = trim($_POST["login"]); - $edituser->pass = trim($_POST["pass"]); - $edituser->admin = trim($_POST["admin"]); - $edituser->office_phone = trim($_POST["office_phone"]); - $edituser->office_fax = trim($_POST["office_fax"]); - $edituser->user_mobile = trim($_POST["user_mobile"]); - $edituser->email = trim($_POST["email"]); - $edituser->note = trim($_POST["note"]); - $edituser->webcal_login = trim($_POST["webcal_login"]); - - $ret=$edituser->update(); - if ($ret < 0) - { - if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { - $message.='<div class="error">'.$langs->trans("ErrorLoginAlreadyExists",$edituser->login).'</div>'; - } - else - { - $message.='<div class="error">'.$edituser->error.'</div>'; - } - } - if ($ret >= 0 && isset($_POST["password"]) && $_POST["password"] !='' ) - { - $ret=$edituser->password($user,$password,$conf->password_encrypted,1); - if ($ret < 0) - { - $message.='<div class="error">'.$edituser->error.'</div>'; - } - } + $edituser = new User($db, $_GET["id"]); + $edituser->fetch(); - if (isset($_FILES['photo']['tmp_name']) && trim($_FILES['photo']['tmp_name'])) - { - // Si une photo est fournie avec le formulaire - if (! is_dir($conf->users->dir_output)) - { - create_exdir($conf->users->dir_output); - } - if (is_dir($conf->users->dir_output)) - { - $newfile=$conf->users->dir_output . "/" . $edituser->id . ".jpg"; - if (! doliMoveFileUpload($_FILES['photo']['tmp_name'],$newfile)) - { - $message .= '<div class="error">'.$langs->trans("ErrorFailedToSaveFile").'</div>'; - } - } - } + $edituser->oldpass = $edituser->pass; - if ($ret >= 0) - { - $message.='<div class="ok">'.$langs->trans("UserModified").'</div>'; - $db->commit(); - } else - { - $db->rollback; - } + $edituser->nom = trim($_POST["nom"]); + $edituser->prenom = trim($_POST["prenom"]); + $edituser->login = trim($_POST["login"]); + $edituser->pass = trim($_POST["pass"]); + $edituser->admin = trim($_POST["admin"]); + $edituser->office_phone = trim($_POST["office_phone"]); + $edituser->office_fax = trim($_POST["office_fax"]); + $edituser->user_mobile = trim($_POST["user_mobile"]); + $edituser->email = trim($_POST["email"]); + $edituser->note = trim($_POST["note"]); + $edituser->webcal_login = trim($_POST["webcal_login"]); + + $ret=$edituser->update(); + if ($ret < 0) + { + if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $message.='<div class="error">'.$langs->trans("ErrorLoginAlreadyExists",$edituser->login).'</div>'; + } + else + { + $message.='<div class="error">'.$edituser->error.'</div>'; + } + } + if ($ret >= 0 && isset($_POST["password"]) && $_POST["password"] !='' ) + { + $ret=$edituser->password($user,$password,$conf->password_encrypted,1); + if ($ret < 0) + { + $message.='<div class="error">'.$edituser->error.'</div>'; + } + } + + if (isset($_FILES['photo']['tmp_name']) && trim($_FILES['photo']['tmp_name'])) + { + // Si une photo est fournie avec le formulaire + if (! is_dir($conf->users->dir_output)) + { + create_exdir($conf->users->dir_output); + } + if (is_dir($conf->users->dir_output)) + { + $newfile=$conf->users->dir_output . "/" . $edituser->id . ".jpg"; + if (! doliMoveFileUpload($_FILES['photo']['tmp_name'],$newfile)) + { + $message .= '<div class="error">'.$langs->trans("ErrorFailedToSaveFile").'</div>'; + } + } + } + + if ($ret >= 0) + { + $message.='<div class="ok">'.$langs->trans("UserModified").'</div>'; + $db->commit(); + } else + { + $db->rollback; + } } @@ -346,7 +346,9 @@ if ((($_POST["action"] == 'confirm_password' && $_POST["confirm"] == 'yes') - +/* + * Affichage page + */ llxHeader('',$langs->trans("UserCard")); @@ -354,90 +356,108 @@ $html = new Form($db); if (($action == 'create') || ($action == 'adduserldap')) { - /* ************************************************************************** */ - /* */ - /* Affichage fiche en mode cr�ation */ - /* */ - /* ************************************************************************** */ + /* ************************************************************************** */ + /* */ + /* Affichage fiche en mode cr�ation */ + /* */ + /* ************************************************************************** */ + + print_titre($langs->trans("NewUser")); + print "<br>"; + + print $langs->trans("CreateInternalUserDesc"); + print "<br>"; + print "<br>"; + + if ($message) { print $message.'<br>'; } + + /* + * Affiche formulaire d'ajout d'un compte depuis LDAP + * si on est en synchro LDAP vers Dolibarr + */ + if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr') + { + $name = $conf->global->LDAP_FIELD_NAME; + $firstname = $conf->global->LDAP_FIELD_FIRSTNAME; + $mail = $conf->global->LDAP_FIELD_MAIL; + $phone = $conf->global->LDAP_FIELD_PHONE; + $fax = $conf->global->LDAP_FIELD_FAX; + $mobile = $conf->global->LDAP_FIELD_MOBILE; + $login = $conf->global->LDAP_FIELD_LOGIN_SAMBA; + $SID = "objectsid"; + + $ldap = new AuthLdap(); + + if ($ldap->connect()) + { + $bind=''; + if ($conf->global->LDAP_ADMIN_DN && $conf->global->LDAP_ADMIN_PASS) + { + dolibarr_syslog("user/fiche.php authBind user=".$conf->global->LDAP_ADMIN_DN,LOG_DEBUG); + $bind=$ldap->authBind($conf->global->LDAP_ADMIN_DN,$conf->global->LDAP_ADMIN_PASS); + } + else + { + dolibarr_syslog("user/fiche.php bind",LOG_DEBUG); + $bind=$ldap->bind(); + } + if ($bind) + { + $justthese = array($name, $firstname, $login); + $ldapusers = $ldap->getUsers('*', $justthese); - print_titre($langs->trans("NewUser")); - print "<br>"; + //print "eee".$justthese." r ".$ldapusers; + //print_r($justthese); - print $langs->trans("CreateInternalUserDesc"); - print "<br>"; - print "<br>"; - - if ($message) { print $message.'<br>'; } - - /* - * ajout utilisateur ldap - */ - if ($conf->ldap->enabled) - { - if ($conf->global->LDAP_SERVER_HOST && $conf->global->LDAP_ADMIN_DN && $conf->global->LDAP_ADMIN_PASS) - { - $name = $conf->global->LDAP_FIELD_NAME; - $firstname = $conf->global->LDAP_FIELD_FIRSTNAME; - $mail = $conf->global->LDAP_FIELD_MAIL; - $phone = $conf->global->LDAP_FIELD_PHONE; - $fax = $conf->global->LDAP_FIELD_FAX; - $mobile = $conf->global->LDAP_FIELD_MOBILE; - $login = $conf->global->LDAP_FIELD_LOGIN_SAMBA; - $SID = "objectsid"; - - $ldap = new AuthLdap(); - - if ($ldap->connect()) - { - $justthese = array( $name, $firstname, $login); - $ldapusers = $ldap->getUsers('*', $justthese); - - if ($ldapusers) - { - $html = new Form($db); - - foreach ($ldapusers as $key => $ldapuser) - { - if($ldapuser[$name] != "") - $liste[$ldapuser[$login]] = utf8_decode($ldapuser[$name])." ".utf8_decode($ldapuser[$firstname]); - } - - print '<form name="add_user_ldap" action="'.$_SERVER["PHP_SELF"].'" method="post">'; - print '<input type="hidden" name="action" value="adduserldap">'; - print $html->select_array('users', $liste, '', 1); - print '<input type="submit" class="button" value="'.$langs->trans('Add').'">'; - print '</form>'; - print "<br>"; - } - - if ($action == 'adduserldap') - { - $selecteduser = $_POST['users']; - $justthese = array( $login, - $name, - $firstname, - $mail, - $phone, - $fax, - $mobile, - $SID); - - $selectedUser = $ldap->getUsers($selecteduser, $justthese); - - if ($selectedUser) - { - foreach ($selectedUser as $key => $attribute) - { - $ldap_nom = utf8_decode($attribute[$name]?$attribute[$name]:''); - $ldap_prenom = utf8_decode($attribute[$firstname]?$attribute[$firstname]:''); - $ldap_login = utf8_decode($attribute[$login]?$attribute[$login]:''); - $ldap_phone = utf8_decode($attribute[$phone]?$attribute[$phone]:''); - $ldap_fax = utf8_decode($attribute[$fax]?$attribute[$fax]:''); - $ldap_mobile = utf8_decode($attribute[$mobile]?$attribute[$mobile]:''); - $ldap_mail = utf8_decode($attribute[$mail]?$attribute[$mail]:''); - $ldap_SID = $attribute[$SID]; - //$ldap_SID = bin2hex($attribute[$SID]); - } + foreach ($ldapusers as $key => $ldapuser) + { + if($ldapuser[$name] != "") + $liste[$ldapuser[$login]] = utf8_decode($ldapuser[$name])." ".utf8_decode($ldapuser[$firstname]); + } + + print '<form name="add_user_ldap" action="'.$_SERVER["PHP_SELF"].'" method="post">'; + print '<table><tr><td>'; + print $langs->trans("LDAPUsers"); + print '</td>'; + print '<td>'; + print '<input type="hidden" name="action" value="adduserldap">'; + print $html->select_array('users', $liste, '', 1); + print '</td><td>'; + print '<input type="submit" class="button" value="'.$langs->trans('Add').'">'; + print '</td></tr></table>'; + print '</form>'; + print "<br>"; + + // Action (a mettre dans actions) + if ($action == 'adduserldap') + { + $selecteduser = $_POST['users']; + $justthese = array( $login, + $name, + $firstname, + $mail, + $phone, + $fax, + $mobile, + $SID); + + $selectedUser = $ldap->getUsers($selecteduser, $justthese); + + if ($selectedUser) + { + foreach ($selectedUser as $key => $attribute) + { + $ldap_nom = utf8_decode($attribute[$name]?$attribute[$name]:''); + $ldap_prenom = utf8_decode($attribute[$firstname]?$attribute[$firstname]:''); + $ldap_login = utf8_decode($attribute[$login]?$attribute[$login]:''); + $ldap_phone = utf8_decode($attribute[$phone]?$attribute[$phone]:''); + $ldap_fax = utf8_decode($attribute[$fax]?$attribute[$fax]:''); + $ldap_mobile = utf8_decode($attribute[$mobile]?$attribute[$mobile]:''); + $ldap_mail = utf8_decode($attribute[$mail]?$attribute[$mail]:''); + $ldap_SID = $attribute[$SID]; + //$ldap_SID = bin2hex($attribute[$SID]); + } + } } } } @@ -446,158 +466,166 @@ if (($action == 'create') || ($action == 'adduserldap')) print $ldap->ldapErrorCode; print $ldap->ldapErrorText; } - if (!$ldap->close()) + if (! $ldap->close()) { print $ldap->ldapErrorCode; print $ldap->ldapErrorText; } } -} - - print '<form action="fiche.php" method="post" name="createuser">'; - print '<input type="hidden" name="action" value="add">'; - if ($ldap_SID) print '<input type="hidden" name="ldap_sid" value="'.$ldap_SID.'">'; - - print '<table class="border" width="100%">'; - - print "<tr>".'<td valign="top">'.$langs->trans("Lastname").'</td>'; - print '<td>'; - if ($ldap_nom) - { - print '<input type="hidden" name="nom" value="'.$ldap_nom.'">'; - print $ldap_nom; - } - else - { - print '<input size="30" type="text" name="nom" value="">'; - } - print '</td></tr>'; - - print '<tr><td valign="top" width="20%">'.$langs->trans("Firstname").'</td>'; - print '<td>'; - if ($ldap_prenom) - { - print '<input type="hidden" name="prenom" value="'.$ldap_prenom.'">'; - print $ldap_prenom; - } - else - { - print '<input size="30" type="text" name="prenom" value="">'; - } - print '</td></tr>'; - - print '<tr><td valign="top">'.$langs->trans("Login").'</td>'; - print '<td>'; - if ($ldap_login) - { - print '<input type="hidden" name="login" value="'.$ldap_login.'">'; - print $ldap_login; - } - else - { - print '<input size="20" maxsize="24" type="text" name="login" value="">'; - } - print '</td></tr>'; - - if (!$ldap_SID) - { - $generated_password=''; - if ($conf->global->USER_PASSWORD_GENERATED) - { - $nomclass="modGeneratePass".ucfirst($conf->global->USER_PASSWORD_GENERATED); - $nomfichier=$nomclass.".class.php"; - //print DOL_DOCUMENT_ROOT."/includes/modules/security/generate/".$nomclass; - require_once(DOL_DOCUMENT_ROOT."/includes/modules/security/generate/".$nomfichier); - $genhandler=new $nomclass($db,$conf,$lang,$user); - $generated_password=$genhandler->getNewGeneratedPassword(); - } - } - - print '<tr><td valign="top">'.$langs->trans("Password").'</td>'; - print '<td>'; - if ($ldap_SID) - { - print 'mot de passe du domaine'; - } - else - { - print '<input size="30" maxsize="32" type="text" name="password" value="'.$generated_password.'">'; - } - print '</td></tr>'; - - if ($user->admin) - { - print '<tr><td valign="top">'.$langs->trans("Administrator").'</td>'; - print '<td>'; - $form->selectyesnonum('admin',0); - print "</td></tr>\n"; - } - - print '<tr><td valign="top">'.$langs->trans("Type").'</td>'; - print '<td>'; - print $html->textwithhelp($langs->trans("Internal"),$langs->trans("InternalExternalDesc")); - print '</td></tr>'; - - - print '<tr><td valign="top">'.$langs->trans("Phone").'</td>'; - print '<td>'; - if ($ldap_phone) - { - print '<input type="hidden" name="office_phone" value="'.$ldap_phone.'">'; - print $ldap_phone; - } - else - { - print '<input size="20" type="text" name="office_phone" value="">'; - } - print '</td></tr>'; - - print '<tr><td valign="top">'.$langs->trans("Fax").'</td>'; - print '<td>'; - if ($ldap_fax) - { - print '<input type="hidden" name="office_fax" value="'.$ldap_fax.'">'; - print $ldap_fax; - } - else - { - print '<input size="20" type="text" name="office_fax" value="">'; - } - print '</td></tr>'; - - print '<tr><td valign="top">'.$langs->trans("Mobile").'</td>'; - print '<td>'; - if ($ldap_mobile) - { - print '<input type="hidden" name="user_mobile" value="'.$ldap_mobile.'">'; - print $ldap_mobile; - } - else - { - print '<input size="20" type="text" name="user_mobile" value="">'; - } - print '</td></tr>'; - + + print '<form action="fiche.php" method="post" name="createuser">'; + print '<input type="hidden" name="action" value="add">'; + if ($ldap_SID) print '<input type="hidden" name="ldap_sid" value="'.$ldap_SID.'">'; + + print '<table class="border" width="100%">'; + + // Nom + print "<tr>".'<td valign="top">'.$langs->trans("Lastname").'</td>'; + print '<td>'; + if ($ldap_nom) + { + print '<input type="hidden" name="nom" value="'.$ldap_nom.'">'; + print $ldap_nom; + } + else + { + print '<input size="30" type="text" name="nom" value="">'; + } + print '</td></tr>'; + + // Prenom + print '<tr><td valign="top" width="20%">'.$langs->trans("Firstname").'</td>'; + print '<td>'; + if ($ldap_prenom) + { + print '<input type="hidden" name="prenom" value="'.$ldap_prenom.'">'; + print $ldap_prenom; + } + else + { + print '<input size="30" type="text" name="prenom" value="">'; + } + print '</td></tr>'; + + // Login + print '<tr><td valign="top">'.$langs->trans("Login").'</td>'; + print '<td>'; + if ($ldap_login) + { + print '<input type="hidden" name="login" value="'.$ldap_login.'">'; + print $ldap_login; + } + else + { + print '<input size="20" maxsize="24" type="text" name="login" value="">'; + } + print '</td></tr>'; + + if (!$ldap_SID) + { + $generated_password=''; + if ($conf->global->USER_PASSWORD_GENERATED) + { + $nomclass="modGeneratePass".ucfirst($conf->global->USER_PASSWORD_GENERATED); + $nomfichier=$nomclass.".class.php"; + //print DOL_DOCUMENT_ROOT."/includes/modules/security/generate/".$nomclass; + require_once(DOL_DOCUMENT_ROOT."/includes/modules/security/generate/".$nomfichier); + $genhandler=new $nomclass($db,$conf,$lang,$user); + $generated_password=$genhandler->getNewGeneratedPassword(); + } + } + + // Mot de passe + print '<tr><td valign="top">'.$langs->trans("Password").'</td>'; + print '<td>'; + if ($ldap_SID) + { + print 'mot de passe du domaine'; + } + else + { + print '<input size="30" maxsize="32" type="text" name="password" value="'.$generated_password.'">'; + } + print '</td></tr>'; + + // Administrateur + if ($user->admin) + { + print '<tr><td valign="top">'.$langs->trans("Administrator").'</td>'; + print '<td>'; + $form->selectyesnonum('admin',0); + print "</td></tr>\n"; + } + + // Type + print '<tr><td valign="top">'.$langs->trans("Type").'</td>'; + print '<td>'; + print $html->textwithhelp($langs->trans("Internal"),$langs->trans("InternalExternalDesc")); + print '</td></tr>'; + + // Tel + print '<tr><td valign="top">'.$langs->trans("Phone").'</td>'; + print '<td>'; + if ($ldap_phone) + { + print '<input type="hidden" name="office_phone" value="'.$ldap_phone.'">'; + print $ldap_phone; + } + else + { + print '<input size="20" type="text" name="office_phone" value="">'; + } + print '</td></tr>'; + + // Fax + print '<tr><td valign="top">'.$langs->trans("Fax").'</td>'; + print '<td>'; + if ($ldap_fax) + { + print '<input type="hidden" name="office_fax" value="'.$ldap_fax.'">'; + print $ldap_fax; + } + else + { + print '<input size="20" type="text" name="office_fax" value="">'; + } + print '</td></tr>'; + + // Tel portable + print '<tr><td valign="top">'.$langs->trans("Mobile").'</td>'; + print '<td>'; + if ($ldap_mobile) + { + print '<input type="hidden" name="user_mobile" value="'.$ldap_mobile.'">'; + print $ldap_mobile; + } + else + { + print '<input size="20" type="text" name="user_mobile" value="">'; + } + print '</td></tr>'; + // EMail - print '<tr><td valign="top">'.$langs->trans("EMail").'</td>'; - print '<td>'; - if ($ldap_mail) - { - print '<input type="hidden" name="email" value="'.$ldap_mail.'">'; - print $ldap_mail; - } - else - { - print '<input size="40" type="text" name="email" value="">'; - } - print '</td></tr>'; - - print '<tr><td valign="top">'; - print $langs->trans("Note"); - print '</td><td>'; + print '<tr><td valign="top">'.$langs->trans("EMail").'</td>'; + print '<td>'; + if ($ldap_mail) + { + print '<input type="hidden" name="email" value="'.$ldap_mail.'">'; + print $ldap_mail; + } + else + { + print '<input size="40" type="text" name="email" value="">'; + } + print '</td></tr>'; + + // Note + print '<tr><td valign="top">'; + print $langs->trans("Note"); + print '</td><td>'; if ($conf->fckeditor->enabled) { - require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); + require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); $doleditor=new DolEditor('note','',180,'dolibarr_notes','',false); $doleditor->Create(); } @@ -606,18 +634,18 @@ if (($action == 'create') || ($action == 'adduserldap')) print '<textarea class="flat" name="note" rows="'.ROWS_4.'" cols="90">'; print '</textarea>'; } - print "</td></tr>\n"; - - // Autres caract�ristiques issus des autres modules - if ($conf->webcal->enabled) - { - print "<tr>".'<td valign="top">'.$langs->trans("LoginWebcal").'</td>'; - print '<td><input size="30" type="text" name="webcal_login" value=""></td></tr>'; - } - - print "<tr>".'<td align="center" colspan="2"><input class="button" value="'.$langs->trans("CreateUser").'" type="submit"></td></tr>'; - print "</table>\n"; - print "</form>"; + print "</td></tr>\n"; + + // Autres caract�ristiques issus des autres modules + if ($conf->webcal->enabled) + { + print "<tr>".'<td valign="top">'.$langs->trans("LoginWebcal").'</td>'; + print '<td><input size="30" type="text" name="webcal_login" value=""></td></tr>'; + } + + print "<tr>".'<td align="center" colspan="2"><input class="button" value="'.$langs->trans("CreateUser").'" type="submit"></td></tr>'; + print "</table>\n"; + print "</form>"; } else { @@ -660,40 +688,12 @@ else } } - /* - * Affichage onglets - */ - - $h = 0; - - $head[$h][0] = DOL_URL_ROOT.'/user/fiche.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("UserCard"); - $hselected=$h; - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/user/perms.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("UserRights"); - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/user/param_ihm.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("UserGUISetup"); - $h++; - - if ($conf->bookmark4u->enabled) - { - $head[$h][0] = DOL_URL_ROOT.'/user/addon.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("Bookmark4u"); - $h++; - } - - if ($conf->clicktodial->enabled) - { - $head[$h][0] = DOL_URL_ROOT.'/user/clicktodial.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("ClickToDial"); - $h++; - } - - dolibarr_fiche_head($head, $hselected, $langs->trans("User").": ".$fuser->fullname); + /* + * Affichage onglets + */ + $head = user_prepare_head($fuser); + + dolibarr_fiche_head($head, 'user', $langs->trans("User").": ".$fuser->fullname); /* @@ -749,9 +749,11 @@ else { print '<table class="border" width="100%">'; - $rowspan=15; - print '<tr><td width="25%" valign="top">'.$langs->trans("Lastname").'</td>'; - print '<td width="50%">'.$fuser->nom.'</td>'; + $rowspan=17; + + // Ref + print '<tr><td width="25%" valign="top">'.$langs->trans("Ref").'</td>'; + print '<td width="50%">'.$fuser->id.'</td>'; print '<td align="center" valign="middle" width="25%" rowspan="'.$rowspan.'">'; if (file_exists($conf->users->dir_output."/".$fuser->id.".jpg")) { @@ -763,6 +765,12 @@ else } print '</td></tr>'; + // Nom + print '<tr><td width="25%" valign="top">'.$langs->trans("Lastname").'</td>'; + print '<td width="50%">'.$fuser->nom.'</td>'; + print "</tr>\n"; + + // Prenom print '<tr><td width="25%" valign="top">'.$langs->trans("Firstname").'</td>'; print '<td width="50%">'.$fuser->prenom.'</td>'; print "</tr>\n"; @@ -1077,12 +1085,11 @@ else print '<input type="hidden" name="action" value="update">'; print '<table width="100%" class="border">'; - $rowspan=11; + $rowspan=13; - print '<tr><td width="25%" valign="top">'.$langs->trans("Lastname").'</td>'; + print '<tr><td width="25%" valign="top">'.$langs->trans("Ref").'</td>'; print '<td width="50%">'; - if ($caneditfield) print '<input class="flat" size="30" type="text" name="nom" value="'.$fuser->nom.'">'; - else print $fuser->nom; + print $fuser->id; print '</td>'; print '<td align="center" valign="middle" width="25%" rowspan="'.$rowspan.'">'; if (file_exists($conf->users->dir_output."/".$fuser->id.".jpg")) @@ -1102,6 +1109,14 @@ else } print '</td></tr>'; + // Nom + print "<tr>".'<td valign="top">'.$langs->trans("Name").'</td>'; + print '<td>'; + if ($caneditfield) print '<input size="30" type="text" class="flat" name="nom" value="'.$fuser->nom.'">'; + else print $fuser->nom; + print '</td></tr>'; + + // Prenom print "<tr>".'<td valign="top">'.$langs->trans("Firstname").'</td>'; print '<td>'; if ($caneditfield) print '<input size="30" type="text" class="flat" name="prenom" value="'.$fuser->prenom.'">'; @@ -1257,13 +1272,19 @@ else else print $fuser->webcal_login; print '</td></tr>'; } - print '<tr><td align="center" colspan="3"><input value="'.$langs->trans("Save").'" class="button" type="submit"></td></tr>'; + + print '<tr><td align="center" colspan="3">'; + print '<input value="'.$langs->trans("Save").'" class="button" type="submit" name="save">'; + print ' '; + print '<input value="'.$langs->trans("Cancel").'" class="button" type="submit" name="cancel">'; + print '</td></tr>'; print '</table>'; print '</form>'; + + print '</div>'; } - print '</div>'; $ldap->close; } } diff --git a/htdocs/user/group/fiche.php b/htdocs/user/group/fiche.php index 31817e01bd382dd838c8da161e36a509b4518e41..172dfffa473c62505b6721e5a33989d8ec9b0e3a 100644 --- a/htdocs/user/group/fiche.php +++ b/htdocs/user/group/fiche.php @@ -27,6 +27,7 @@ */ require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/usergroups.lib.php"); // Defini si peux lire/modifier utilisateurs et permisssions @@ -180,22 +181,12 @@ else $group = new UserGroup($db); $group->fetch($_GET["id"]); - /* - * Affichage onglets - */ - - $h = 0; - - $head[$h][0] = DOL_URL_ROOT.'/user/group/fiche.php?id='.$group->id; - $head[$h][1] = $langs->trans("GroupCard"); - $hselected=$h; - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/user/group/perms.php?id='.$group->id; - $head[$h][1] = $langs->trans("GroupRights"); - $h++; - - dolibarr_fiche_head($head, $hselected, $langs->trans("Group").": ".$group->nom); + /* + * Affichage onglets + */ + $head = group_prepare_head($group); + + dolibarr_fiche_head($head, 'group', $langs->trans("Group").": ".$group->nom); /* @@ -212,12 +203,16 @@ else * Fiche en mode visu */ - if ($_GET["action"] != 'edit') { - + if ($_GET["action"] != 'edit') + { print '<table class="border" width="100%">'; + + // Nom print '<tr><td width="25%" valign="top">'.$langs->trans("Name").'</td>'; print '<td width="75%" class="valeur">'.$group->nom.'</td>'; print "</tr>\n"; + + // Note print '<tr><td width="25%" valign="top">'.$langs->trans("Note").'</td>'; print '<td class="valeur">'.nl2br($group->note).' </td>'; print "</tr>\n"; diff --git a/htdocs/user/group/ldap.php b/htdocs/user/group/ldap.php new file mode 100644 index 0000000000000000000000000000000000000000..05ac304daa6bced07941228ba871ef9f07a7333e --- /dev/null +++ b/htdocs/user/group/ldap.php @@ -0,0 +1,158 @@ +<?php +/* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net> + * Copyright (C) 2006 Regis Houssin <regis.houssin@cap-networks.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/user/group/ldap.php + \ingroup ldap + \brief Page fiche LDAP groupe + \version $Revision$ +*/ + +require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/usergroups.lib.php"); +require_once (DOL_DOCUMENT_ROOT."/lib/authldap.lib.php"); + +$user->getrights('commercial'); + +$langs->load("companies"); +$langs->load("ldap"); + +// Protection quand utilisateur externe +$contactid = isset($_GET["id"])?$_GET["id"]:''; + +$socid=0; +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 + */ +$head = group_prepare_head($fgroup); + +dolibarr_fiche_head($head, 'ldap', $langs->trans("Group").": ".$fgroup->nom); + + + +/* + * Fiche en mode visu + */ +print '<table class="border" width="100%">'; + +// Nom +print '<tr><td width="25%" valign="top">'.$langs->trans("Name").'</td>'; +print '<td width="75%" class="valeur">'.$fgroup->nom.'</td>'; +print "</tr>\n"; + +// Note +print '<tr><td width="25%" valign="top">'.$langs->trans("Note").'</td>'; +print '<td class="valeur">'.nl2br($fgroup->note).' </td>'; +print "</tr>\n"; +print "</table>\n"; + +print '</div>'; + +print '<br>'; + + +print_titre($langs->trans("LDAPInformationsForThisGroup")); + +// Affichage attributs LDAP +print '<table width="100%" class="noborder">'; + +print '<tr class="liste_titre">'; +print '<td>'.$langs->trans("LDAPAttributes").'</td>'; +print '<td>'.$langs->trans("Value").'</td>'; +print '</tr>'; + +// Lecture LDAP +$ldap=new AuthLdap(); +$result=$ldap->connect(); +if ($result) +{ + $bind=''; + if ($conf->global->LDAP_ADMIN_DN && $conf->global->LDAP_ADMIN_PASS) + { + dolibarr_syslog("ldap.php: authBind user=".$conf->global->LDAP_ADMIN_DN,LOG_DEBUG); + $bind=$ldap->authBind($conf->global->LDAP_ADMIN_DN,$conf->global->LDAP_ADMIN_PASS); + } + else + { + dolibarr_syslog("ldap.php: bind",LOG_DEBUG); + $bind=$ldap->bind(); + } + + if ($bind) + { +// $info["cn"] = $ldap->getUserIdentifier()."=".$fuser->uname; + $info["cn"] = trim($fgroup->nom); + $dn = "cn=".$info["cn"].",".$conf->global->LDAP_GROUP_DN; + + $result=$ldap->search($dn,'(objectClass=*)'); + + // Affichage arbre + if (sizeof($result)) + { + $html=new Form($db); + $html->show_ldap_content($result,0,0,true); + } + else + { + print '<tr><td colspan="2">'.$langs->trans("LDAPRecordNotFound").'</td></tr>'; + } + } + else + { + dolibarr_print_error('',$ldap); + } +} +else +{ + dolibarr_print_error('',$ldap); +} + +print '</table>'; + + + + +$db->close(); + +llxFooter('$Date$ - $Revision$'); +?> diff --git a/htdocs/user/group/perms.php b/htdocs/user/group/perms.php index a960a3ca34b78d626344fc09bd5aed3234cfaa9d..67c45be18c39a602ed25dc99f79ac2846feef2a8 100644 --- a/htdocs/user/group/perms.php +++ b/htdocs/user/group/perms.php @@ -28,8 +28,8 @@ \version $Revision$ */ - require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/usergroups.lib.php"); $langs->load("users"); @@ -74,23 +74,13 @@ if ($_GET["id"]) $fgroup->fetch($_GET["id"]); $fgroup->getrights(); - /* - * Affichage onglets - */ - - $h = 0; - - $head[$h][0] = DOL_URL_ROOT.'/user/group/fiche.php?id='.$fgroup->id; - $head[$h][1] = $langs->trans("GroupCard"); - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/user/group/perms.php?id='.$fgroup->id; - $head[$h][1] = $langs->trans("GroupRights"); - $hselected=$h; - $h++; + /* + * Affichage onglets + */ + $head = group_prepare_head($fgroup); + dolibarr_fiche_head($head, 'rights', $langs->trans("Group").": ".$fgroup->nom); - dolibarr_fiche_head($head, $hselected, $langs->trans("Group").": ".$fgroup->nom); $db->begin(); diff --git a/htdocs/user/ldap.php b/htdocs/user/ldap.php new file mode 100644 index 0000000000000000000000000000000000000000..90f6c86359de8d5dd16ff40010ae930836588f91 --- /dev/null +++ b/htdocs/user/ldap.php @@ -0,0 +1,174 @@ +<?php +/* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net> + * Copyright (C) 2006 Regis Houssin <regis.houssin@cap-networks.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/user/ldap.php + \ingroup ldap + \brief Page fiche LDAP utilisateur + \version $Revision$ +*/ + +require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/usergroups.lib.php"); +require_once (DOL_DOCUMENT_ROOT."/lib/authldap.lib.php"); + +$user->getrights('commercial'); + +$langs->load("companies"); +$langs->load("ldap"); + +// Protection quand utilisateur externe +$contactid = isset($_GET["id"])?$_GET["id"]:''; + +$socid=0; +if ($user->societe_id > 0) +{ + $socid = $user->societe_id; +} + + +/* + * Affichage page + */ + +llxHeader(); + +$form = new Form($db); + +$fuser = new User($db, $_GET["id"]); +$fuser->fetch(); +$fuser->getrights(); + + +/* + * Affichage onglets + */ +$head = user_prepare_head($fuser); + +dolibarr_fiche_head($head, 'ldap', $langs->trans("User").": ".$fuser->fullname); + + + +/* + * Fiche en mode visu + */ +print '<table class="border" width="100%">'; + +// Ref +print '<tr><td width="25%" valign="top">'.$langs->trans("Ref").'</td>'; +print '<td>'.$fuser->id.'</td>'; +print '</tr>'; + +// Nom +print '<tr><td width="25%" valign="top">'.$langs->trans("Lastname").'</td>'; +print '<td>'.$fuser->nom.'</td>'; +print "</tr>\n"; + +// Prenom +print '<tr><td width="25%" valign="top">'.$langs->trans("Firstname").'</td>'; +print '<td>'.$fuser->prenom.'</td>'; +print "</tr>\n"; + +// Login +print '<tr><td width="25%" valign="top">'.$langs->trans("Login").'</td>'; +if ($fuser->ldap_sid) +{ + print '<td class="warning">'.$langs->trans("LoginAccountDisableInDolibarr").'</td>'; +} +else +{ + print '<td>'.$fuser->login.'</td>'; +} +print '</tr>'; + +print '</table>'; + +print '</div>'; + +print '<br>'; + + +print_titre($langs->trans("LDAPInformationsForThisUser")); + +// Affichage attributs LDAP +print '<table width="100%" class="noborder">'; + +print '<tr class="liste_titre">'; +print '<td>'.$langs->trans("LDAPAttributes").'</td>'; +print '<td>'.$langs->trans("Value").'</td>'; +print '</tr>'; + +// Lecture LDAP +$ldap=new AuthLdap(); +$result=$ldap->connect(); +if ($result) +{ + $bind=''; + if ($conf->global->LDAP_ADMIN_DN && $conf->global->LDAP_ADMIN_PASS) + { + dolibarr_syslog("ldap.php: authBind user=".$conf->global->LDAP_ADMIN_DN,LOG_DEBUG); + $bind=$ldap->authBind($conf->global->LDAP_ADMIN_DN,$conf->global->LDAP_ADMIN_PASS); + } + else + { + dolibarr_syslog("ldap.php: bind",LOG_DEBUG); + $bind=$ldap->bind(); + } + + if ($bind) + { +// $info["cn"] = $ldap->getUserIdentifier()."=".$fuser->uname; + $info["cn"] = trim($fuser->prenom." ".$fuser->nom); + $dn = "cn=".$info["cn"].",".$conf->global->LDAP_USER_DN; + + $result=$ldap->search($dn,'(objectClass=*)'); + + // Affichage arbre + if (sizeof($result)) + { + $html=new Form($db); + $html->show_ldap_content($result,0,0,true); + } + else + { + print '<tr><td colspan="2">'.$langs->trans("LDAPRecordNotFound").'</td></tr>'; + } + } + else + { + dolibarr_print_error('',$ldap); + } +} +else +{ + dolibarr_print_error('',$ldap); +} + +print '</table>'; + + + + +$db->close(); + +llxFooter('$Date$ - $Revision$'); +?> diff --git a/htdocs/user/param_ihm.php b/htdocs/user/param_ihm.php index f28e964c402378aa4774458e3aefb46e0cb3b860..2bda9ee620d7991746a82c2c9ae1ca834992c9e5 100644 --- a/htdocs/user/param_ihm.php +++ b/htdocs/user/param_ihm.php @@ -1,5 +1,5 @@ <?php -/* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net> +/* Copyright (C) 2005-2006 Laurent Destailleur <eldy@users.sourceforge.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,8 +25,8 @@ \version $Revision$ */ - require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/usergroups.lib.php"); $langs->load("companies"); $langs->load("products"); @@ -93,43 +93,12 @@ if ($_POST["action"] == 'update') llxHeader(); - /* * Affichage onglets */ +$head = user_prepare_head($fuser); -$h = 0; - -$head[$h][0] = DOL_URL_ROOT.'/user/fiche.php?id='.$fuser->id; -$head[$h][1] = $langs->trans("UserCard"); -$h++; - -$head[$h][0] = DOL_URL_ROOT.'/user/perms.php?id='.$fuser->id; -$head[$h][1] = $langs->trans("UserRights"); -$h++; - -$head[$h][0] = DOL_URL_ROOT.'/user/param_ihm.php?id='.$fuser->id; -$head[$h][1] = $langs->trans("UserGUISetup"); -$hselected=$h; -$h++; - -if ($conf->bookmark4u->enabled) -{ - $head[$h][0] = DOL_URL_ROOT.'/user/addon.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("Bookmark4u"); - $h++; -} - -if ($conf->clicktodial->enabled) -{ - $head[$h][0] = DOL_URL_ROOT.'/user/clicktodial.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("ClickToDial"); - $h++; -} - -dolibarr_fiche_head($head, $hselected, $langs->trans("User").": ".$fuser->fullname); - - +dolibarr_fiche_head($head, 'guisetup', $langs->trans("User").": ".$fuser->fullname); if ($_GET["action"] == 'edit') diff --git a/htdocs/user/perms.php b/htdocs/user/perms.php index e36851c176608346eb9bec1ed1047956a0d09784..77d61b13408e32ffb6454f66a63b58db25064546 100644 --- a/htdocs/user/perms.php +++ b/htdocs/user/perms.php @@ -28,8 +28,8 @@ \version $Revision$ */ - require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/usergroups.lib.php"); $langs->load("users"); @@ -75,40 +75,13 @@ if ($_GET["id"]) $fuser->fetch(); $fuser->getrights(); - /* - * Affichage onglets - */ - - $h = 0; - - $head[$h][0] = DOL_URL_ROOT.'/user/fiche.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("UserCard"); - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/user/perms.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("UserRights"); - $hselected=$h; - $h++; + /* + * Affichage onglets + */ + $head = user_prepare_head($fuser); - $head[$h][0] = DOL_URL_ROOT.'/user/param_ihm.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("UserGUISetup"); - $h++; - - if ($conf->bookmark4u->enabled) - { - $head[$h][0] = DOL_URL_ROOT.'/user/addon.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("Bookmark4u"); - $h++; - } - - if ($conf->clicktodial->enabled) - { - $head[$h][0] = DOL_URL_ROOT.'/user/clicktodial.php?id='.$fuser->id; - $head[$h][1] = $langs->trans("ClickToDial"); - $h++; - } + dolibarr_fiche_head($head, 'rights', $langs->trans("User").": ".$fuser->fullname); - dolibarr_fiche_head($head, $hselected, $langs->trans("User").": ".$fuser->fullname); $db->begin(); diff --git a/htdocs/usergroup.class.php b/htdocs/usergroup.class.php index 84a7ae7a46137ebccd58a4e3b399a80b79807e7c..0a8dad3adb90c6b01e2af04fe8d1b79ac160004c 100644 --- a/htdocs/usergroup.class.php +++ b/htdocs/usergroup.class.php @@ -423,7 +423,110 @@ class UserGroup } } - + + + /** + * \brief Mise � jour dans l'arbre LDAP + * \param user Utilisateur qui effectue la mise � jour + * \return int <0 si ko, >0 si ok + */ + function update_ldap($user) + { + global $conf, $langs; + + //if (! $conf->ldap->enabled || ! $conf->global->LDAP_SYNCHRO_ACTIVE) return 0; + + $info = array(); + + dolibarr_syslog("UserGroup.class::update_ldap this->id=".$this->id,LOG_DEBUG); + + $ldap=new AuthLdap(); + $result=$ldap->connect(); + if ($result) + { + $bind=''; + if ($conf->global->LDAP_ADMIN_DN && $conf->global->LDAP_ADMIN_PASS) + { + dolibarr_syslog("UserGroup.class::update_ldap authBind user=".$conf->global->LDAP_ADMIN_DN,LOG_DEBUG); + $bind=$ldap->authBind($conf->global->LDAP_ADMIN_DN,$conf->global->LDAP_ADMIN_PASS); + } + else + { + dolibarr_syslog("UserGroup.class::update_ldap bind",LOG_DEBUG); + $bind=$ldap->bind(); + } + if ($bind) + { + if ($conf->global->LDAP_SERVER_TYPE == 'activedirectory') + { + $info["objectclass"]=array("top", + "person", + "organizationalPerson", + "user"); + } + else + { + $info["objectclass"]=array("top", + "person", + "organizationalPerson", + "inetOrgPerson"); + } + + // Champs obligatoires + $info["cn"] = trim($this->nom); + if ($this->nom) $info[$conf->global->LDAP_FIELD_NAME] = $this->nom; + else + { + $langs->load("other"); + $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Name")); + return -1; + } + + // Champs optionnels + if ($this->note) $info["description"] = $this->note; + + $info["uid"] = "Dolibarr ".$this->id; + + $newdn = "cn=".$info["cn"].",".$conf->global->LDAP_GROUP_DN; + $olddn = $newdn; + if ($this->old_name) $olddn="cn=".trim($this->old_name).",".$conf->global->LDAP_CONTACT_DN; + + // On supprime et on ins�re + dolibarr_syslog("UserGroup.class::update_ldap olddn=".$olddn." newdn=".$newdn); + + $result = $ldap->delete($olddn); + $result = $ldap->add($newdn, $info); + if ($result <= 0) + { + $this->error = ldap_errno($ldap->connection)." ".ldap_error($ldap->connection)." ".$ldap->error; + dolibarr_syslog("UserGroup.class::update_ldap ".$this->error,LOG_ERROR); + //print_r($info); + return -1; + } + else + { + dolibarr_syslog("UserGroup.class::update_ldap rowid=".$this->id." added in LDAP"); + } + + $ldap->unbind(); + + return 1; + } + else + { + $this->error = "Error ".ldap_errno($ldap->connection)." ".ldap_error($ldap->connection); + dolibarr_syslog("UserGroup.class::update_ldap bind failed",LOG_DEBUG); + return -1; + } + } + else + { + $this->error="Failed to connect to LDAP server !"; + dolibarr_syslog("UserGroup.class::update_ldap Connexion failed",LOG_DEBUG); + return -1; + } + } + } ?>