diff --git a/htdocs/adherents/adherent.class.php b/htdocs/adherents/adherent.class.php index 2aa8c4bceff..05be6c0643f 100644 --- a/htdocs/adherents/adherent.class.php +++ b/htdocs/adherents/adherent.class.php @@ -517,8 +517,9 @@ class Adherent /** - \brief fonction qui récupére l'adhérent en donnant son rowid - \param rowid + \brief Fonction qui récupére l'adhérent en donnant son rowid + \param rowid + \return int <0 si KO, >0 si OK */ function fetch($rowid) { @@ -531,13 +532,14 @@ class Adherent $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_pays as p ON d.pays = p.rowid"; $sql.= " WHERE d.rowid = ".$rowid." AND d.fk_adherent_type = t.rowid"; - - $result=$this->db->query( $sql); - if ($result) + dolibarr_syslog("Adherent.class::fetch sql=".$sql); + + $resql=$this->db->query($sql); + if ($resql) { - if ($this->db->num_rows($result)) + if ($this->db->num_rows($resql)) { - $obj = $this->db->fetch_object($result); + $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; $this->statut = $obj->statut; @@ -568,12 +570,13 @@ class Adherent $this->type = $obj->type; $this->need_subscription = ($obj->cotisation=='yes'?1:0); } + return 1; } else { - dolibarr_print_error($this->db); + $this->error=$this->db->error(); + return -1; } - } diff --git a/htdocs/adherents/adherent_type.class.php b/htdocs/adherents/adherent_type.class.php index 2f7bcf7e6be..c44a0b9f4bf 100644 --- a/htdocs/adherents/adherent_type.class.php +++ b/htdocs/adherents/adherent_type.class.php @@ -159,39 +159,43 @@ class AdherentType } /** - \brief fonction qui permet de récupérer le status de l'adhérent - \param rowid -*/ - + \brief Fonction qui permet de récupérer le status de l'adhérent + \param rowid + \return int <0 si KO, >0 si OK + */ function fetch($rowid) - { - $sql = "SELECT d.rowid, d.libelle, d.statut, d.cotisation, d.mail_valid, d.note, d.vote"; - $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d"; - $sql .= " WHERE d.rowid = $rowid"; - - if ( $this->db->query( $sql) ) - { - if ($this->db->num_rows()) - { - $obj = $this->db->fetch_object(); - - $this->id = $obj->rowid; - $this->libelle = $obj->libelle; - $this->statut = $obj->statut; - $this->cotisation = $obj->cotisation; - $this->mail_valid = $obj->mail_valid; - $this->commentaire = $obj->note; - $this->vote = $obj->vote; - } - } - else - { - print $this->db->error(); - } + { + $sql = "SELECT d.rowid, d.libelle, d.statut, d.cotisation, d.mail_valid, d.note, d.vote"; + $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d"; + $sql .= " WHERE d.rowid = ".$rowid; + dolibarr_syslog("Adherent_type::fetch sql=".$sql); - } + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->libelle = $obj->libelle; + $this->statut = $obj->statut; + $this->cotisation = $obj->cotisation; + $this->mail_valid = $obj->mail_valid; + $this->commentaire = $obj->note; + $this->vote = $obj->vote; + } + return 1; + } + else + { + $this->error=$this->db->error(); + return -1; + } + } - function liste_array() + + function liste_array() { $projets = array(); diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index 4edd6218ff1..28de40bc746 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -29,6 +29,7 @@ */ require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/member.lib.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/adherent_type.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/adherent_options.class.php"); @@ -557,13 +558,21 @@ if ($action == 'create') print ''; + // Nom print ''; print ''; + // Prenom print ''; $rowspan=12; print ''; + // Login + print ''; + + // Mot de pass + print ''; + // Type print '\n"; print ''; + + // Adresse print ''; + + // CP print ''; + + // Ville print ''; + + // EMail print ''; - print ''; - print ''; // Date naissance print "'; diff --git a/htdocs/adherents/ldap.php b/htdocs/adherents/ldap.php new file mode 100644 index 00000000000..8d572ed4b2a --- /dev/null +++ b/htdocs/adherents/ldap.php @@ -0,0 +1,200 @@ + + * Copyright (C) 2006 Regis Houssin + * + * 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/adherents/ldap.php + \ingroup ldap + \brief Page fiche LDAP adherent + \version $Revision$ +*/ + +require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/member.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/authldap.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php"); +require_once(DOL_DOCUMENT_ROOT."/adherents/adherent_type.class.php"); + +$user->getrights('commercial'); + +$langs->load("companies"); +$langs->load("members"); +$langs->load("ldap"); + +// Protection quand utilisateur externe +$rowid = isset($_GET["id"])?$_GET["id"]:''; + +$socid=0; +if ($user->societe_id > 0) +{ + $socid = $user->societe_id; +} + + +/* + * Affichage page + */ + +llxHeader(); + +$form = new Form($db); + + +$adh = new Adherent($db); +$adh->id = $rowid; +$result=$adh->fetch($rowid); +if (! $result) +{ + dolibarr_print_error($db,"Failed to get adherent: ".$adh->error); + exit; +} +$adh->fetch_optionals($rowid); + +$adht = new AdherentType($db); +$result=$adht->fetch($adh->typeid); +if (! $result) +{ + dolibarr_print_error($db,"Failed to get type of adherent: ".$adht->error); + exit; +} + + + +/* + * Affichage onglets + */ +$head = member_prepare_head($adh); + +dolibarr_fiche_head($head, 'ldap', $langs->trans("Member").": ".$adh->fullname); + + + +/* + * Fiche en mode visu + */ +print '
'.$langs->trans("Lastname").'*'.$langs->trans("Comments").' :
'.$langs->trans("Firstname").'*
'.$langs->trans("Login").'*
'.$langs->trans("Password").'*
'.$langs->trans("MemberType").'*'; $listetype=$adht->liste_array(); @@ -583,15 +592,21 @@ if ($action == 'create') print "
'.$langs->trans("Company").'
'.$langs->trans("Address").''; print '
'.$langs->trans("Zip").' / '.$langs->trans("Town").'
'.$langs->trans("Country").''; $htmls->select_pays($adh->pays_code?$adh->pays_code:$mysoc->pays_code,'pays_code'); print '
'.$langs->trans("EMail").($conf->global->ADHERENT_MAIL_REQUIRED?'*':'').'
'.$langs->trans("Login").'*
'.$langs->trans("Password").'*
".$langs->trans("Birthday")."\n"; @@ -659,17 +674,13 @@ if ($rowid && $action != 'edit') $html = new Form($db); - /* - * Affichage onglets - */ - $h = 0; + /* + * Affichage onglets + */ + $head = member_prepare_head($adh); - $head[$h][0] = DOL_URL_ROOT.'/adherents/fiche.php?rowid='.$rowid; - $head[$h][1] = $langs->trans("Card"); - $hselected=$h; - $h++; + dolibarr_fiche_head($head, 'general', $langs->trans("Member").": ".$adh->fullname); - dolibarr_fiche_head($head, $hselected, $langs->trans("MemberCard")); // Confirmation de la suppression de l'adhérent if ($action == 'delete') @@ -737,19 +748,26 @@ if ($rowid && $action != 'edit') } - print ''; print ''; + print '
'; + // Ref print ''; + // Nom print ''; print ''; + // Prenom print ''; print ''; - print '\n"; + // Login + print ''; + + // Type + print '\n"; print ''; print ''; @@ -757,7 +775,6 @@ if ($rowid && $action != 'edit') print ''; print ''; print ''; - print ''; // print ''; print ''; print ''; @@ -771,8 +788,8 @@ if ($rowid && $action != 'edit') print "\n"; } - print ''; print "
'.$langs->trans("Ref").''.$adh->id.' 
'.$langs->trans("Lastname").'*'.$adh->nom.' '.$langs->trans("Comments").'
'.$langs->trans("Firstname").'*'.$adh->prenom.' '; print nl2br($adh->commentaire).' 
'.$langs->trans("Type").'*'.$adh->type."
'.$langs->trans("Login").'*'.$adh->login.' 
'.$langs->trans("Type").'*'.$adh->type."
'.$langs->trans("Person").''.$adh->getmorphylib().'
'.$langs->trans("Company").''.$adh->societe.' 
'.$langs->trans("Zip").' / '.$langs->trans("Town").''.$adh->cp.' '.$adh->ville.' 
'.$langs->trans("Country").''.$adh->pays.'
'.$langs->trans("EMail").($conf->global->ADHERENT_MAIL_REQUIRED?'*':'').''.$adh->email.' 
'.$langs->trans("Login").'*'.$adh->login.' 
Pass'.$adh->pass.' 
'.$langs->trans("Birthday").''.$adh->naiss.' 
URL Photo'.$adh->photo.' 
$value".$adh->array_options["options_$key"]." 
\n"; + print ''; print "\n"; @@ -907,13 +924,14 @@ if ($rowid && $action != 'edit') */ if ($user->rights->adherent->cotisation->creer) { + print "\n\n\n"; + print '
'; print "\n"; - print ''; + print ''; + print ''; print ''; } - print ''; + print ''; - print ''; print '
'.$langs->trans("SubscriptionEndDate"); print ''; print ''; - - print '
'.$langs->trans("SubscriptionEndDate").''; if ($adh->datefin) { @@ -968,10 +986,11 @@ if ($rowid && $action != 'edit') print strftime("%Y",($adh->datefin?$adh->datefin:time())).'" >
'; + print ''; + print "\n\n\n"; } print '
'; + +// Ref +print ''; + +// Nom +print ''; +print ''; + +// Prenom +print ''; +print ''; + +// Login +print ''; + +// Type +print '\n"; + +// LDAP DN +$langs->load("admin"); +print '\n"; + +// LDAP Server +print '\n"; +print '\n"; +print '\n"; + +print '
'.$langs->trans("Ref").''.$adh->id.' 
'.$langs->trans("Lastname").'*'.$adh->nom.' 
'.$langs->trans("Firstname").'*'.$adh->prenom.' 
'.$langs->trans("Login").'*'.$adh->login.' 
'.$langs->trans("Type").'*'.$adh->type."
'.$langs->trans("LDAPMemberDn").'*'.$conf->global->LDAP_MEMBER_DN."
'.$langs->trans("LDAPPrimaryServer").'*'.$conf->global->LDAP_SERVER_HOST."
'.$langs->trans("LDAPSecondaryServer").'*'.$conf->global->LDAP_SERVER_HOST_SLAVE."
'.$langs->trans("LDAPServerPort").'*'.$conf->global->LDAP_SERVER_PORT."
'; + +print ''; + +print '
'; + + +print_titre($langs->trans("LDAPInformationsForThisMember")); + +// Affichage attributs LDAP +print ''; + +print ''; +print ''; +print ''; +print ''; + +// 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); + } + if (! $bind) // Si pas de login ou si connexion avec login en echec, on tente en anonyme + { + dolibarr_syslog("ldap.php: bind",LOG_DEBUG); + $bind=$ldap->bind(); + } + + if ($bind) + { + $info["cn"] = trim($adh->prenom." ".$adh->nom); + $info["uid"] = trim($adh->login); + + $dn = $conf->global->LDAP_MEMBER_DN; +// $dn = "cn=".$info["cn"].",".$dn; +// $dn = "uid=".$info["uid"].",".$dn + $search = "(cn=".$info["cn"].")"; + //$search = "(uid=".$info["uid"].")"; + + $result=$ldap->search($dn,$search); + + // Affichage arbre + if (sizeof($result)) + { + $html=new Form($db); + $html->show_ldap_content($result,0,0,true); + } + else + { + print ''; + } + + $ldap->unbind(); + } + else + { + dolibarr_print_error('',$ldap->error); + } + $ldap->close(); +} +else +{ + dolibarr_print_error('',$ldap->error); +} + +print '
'.$langs->trans("LDAPAttributes").''.$langs->trans("Value").'
'.$langs->trans("LDAPRecordNotFound").'
'; + + + + +$db->close(); + +llxFooter('$Date$ - $Revision$'); +?> diff --git a/htdocs/admin/ldap.php b/htdocs/admin/ldap.php index fd9dbb74b64..6bfacacc9d2 100644 --- a/htdocs/admin/ldap.php +++ b/htdocs/admin/ldap.php @@ -32,6 +32,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/authldap.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/ldap.lib.php"); $langs->load("admin"); @@ -74,8 +75,12 @@ if ($_GET["action"] == 'setvalue' && $user->admin) llxHeader(); + +$head = ldap_prepare_head(); + print_fiche_titre($langs->trans("LDAPSetup"),'','setup'); + // Test si fonction LDAP actives if (! function_exists("ldap_connect")) { @@ -86,36 +91,9 @@ if ($mesg) print '
'.$mesg.'
'; else print '
'; -// Onglets -$h = 0; -$head[$h][0] = DOL_URL_ROOT."/admin/ldap.php"; -$head[$h][1] = $langs->trans("LDAPGlobalParameters"); -$hselected=$h; -$h++; -if ($conf->global->LDAP_SYNCHRO_ACTIVE) -{ - $head[$h][0] = DOL_URL_ROOT."/admin/ldap_users.php"; - $head[$h][1] = $langs->trans("LDAPUsersAndGroupsSynchro"); - $h++; -} - -if ($conf->global->LDAP_CONTACT_ACTIVE) -{ - $head[$h][0] = DOL_URL_ROOT."/admin/ldap_contacts.php"; - $head[$h][1] = $langs->trans("LDAPContactsSynchro"); - $h++; -} - -if ($conf->global->LDAP_MEMBERS_ACTIVE) -{ - $head[$h][0] = DOL_URL_ROOT."/admin/ldap_members.php"; - $head[$h][1] = $langs->trans("LDAPMembersSynchro"); - $h++; -} - -dolibarr_fiche_head($head, $hselected, $langs->trans("LDAP")); +dolibarr_fiche_head($head, 'ldap', $langs->trans("LDAP")); $var=true; $html=new Form($db); diff --git a/htdocs/admin/ldap_contacts.php b/htdocs/admin/ldap_contacts.php index aae2f5114ed..49b33ad1f7b 100644 --- a/htdocs/admin/ldap_contacts.php +++ b/htdocs/admin/ldap_contacts.php @@ -32,6 +32,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/authldap.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/ldap.lib.php"); require_once (DOL_DOCUMENT_ROOT."/contact.class.php"); $langs->load("admin"); @@ -47,7 +48,10 @@ if (!$user->admin) if ($_GET["action"] == 'setvalue' && $user->admin) { $error=0; + if (! dolibarr_set_const($db, 'LDAP_KEY_CONTACTS',$_POST["key"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_CONTACT_DN',$_POST["contactdn"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_FULLNAME',$_POST["fieldfullname"])) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_NAME',$_POST["fieldname"])) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_FIRSTNAME',$_POST["fieldfirstname"])) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_MAIL',$_POST["fieldmail"])) $error++; @@ -72,8 +76,11 @@ if ($_GET["action"] == 'setvalue' && $user->admin) llxHeader(); +$head = ldap_prepare_head(); + print_fiche_titre($langs->trans("LDAPSetup"),'','setup'); + // Test si fonction LDAP actives if (! function_exists("ldap_connect")) { @@ -84,36 +91,8 @@ if ($mesg) print '
'.$mesg.'
'; else print '
'; -// Onglets -$h = 0; +dolibarr_fiche_head($head, 'contacts', $langs->trans("LDAP")); -$head[$h][0] = DOL_URL_ROOT."/admin/ldap.php"; -$head[$h][1] = $langs->trans("LDAPGlobalParameters"); -$h++; - -if ($conf->global->LDAP_SYNCHRO_ACTIVE) -{ - $head[$h][0] = DOL_URL_ROOT."/admin/ldap_users.php"; - $head[$h][1] = $langs->trans("LDAPUsersAndGroupsSynchro"); - $h++; -} - -if ($conf->global->LDAP_CONTACT_ACTIVE) -{ - $head[$h][0] = DOL_URL_ROOT."/admin/ldap_contacts.php"; - $head[$h][1] = $langs->trans("LDAPContactsSynchro"); - $hselected=$h; - $h++; -} - -if ($conf->global->LDAP_MEMBERS_ACTIVE) -{ - $head[$h][0] = DOL_URL_ROOT."/admin/ldap_members.php"; - $head[$h][1] = $langs->trans("LDAPMembersSynchro"); - $h++; -} - -dolibarr_fiche_head($head, $hselected, $langs->trans("LDAP")); print $langs->trans("LDAPDescContact").'
'; print '
'; @@ -123,7 +102,8 @@ print '
'; print ''; print ''; -print ''; +print ''; +print ''; print "\n"; $var=true; @@ -133,67 +113,94 @@ $html=new Form($db); // DN Pour les contacts $var=!$var; print ''; +print ''; +print ''; +print ''; +print ''; + +// Common name +$var=!$var; +print ''; +print '"; +print ''; // Name $var=!$var; -print ''; +print ''; +print '"; +print ''; // Firstname $var=!$var; print ''; - +print ''; +print '"; +print ''; // Mail $var=!$var; print ''; +print ''; +print '"; +print ''; // Phone $var=!$var; print ''; +print ''; +print '"; +print ''; // Mobile $var=!$var; print ''; +print ''; +print '"; +print ''; // Fax $var=!$var; print ''; +print ''; +print '"; +print ''; // Address $var=!$var; print ''; +print ''; +print '"; +print ''; // CP $var=!$var; print ''; +print ''; +print '"; +print ''; // Ville $var=!$var; print ''; +print ''; +print '"; +print ''; $var=!$var; -print ''; +print ''; print '
'.$langs->trans("LDAPSynchronizeContacts").''.$langs->trans("LDAPSynchronizeUsers").''.$langs->trans("LDAPNamingAttribute").'
'.$langs->trans("LDAPContactDn").picto_required().''; -print ''; -print ''.$langs->trans("LDAPContactDnExample").'
'.$langs->trans("LDAPContactDnExample").' 
'.$langs->trans("LDAPFieldFullname").''; +print ''; +print ''.$langs->trans("LDAPFieldFullnameExample").'global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_FULLNAME?' checked="true"':'').">
'.$langs->trans("LDAPFieldName").picto_required().''; +print '
'.$langs->trans("LDAPFieldName").''; print ''; -print ''.$langs->trans("LDAPFieldNameExample").'
'.$langs->trans("LDAPFieldNameExample").'global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_NAME?' checked="true"':'').">
'.$langs->trans("LDAPFieldFirstName").''; print ''; -print ''.$langs->trans("LDAPFieldFirstNameExample").'
'.$langs->trans("LDAPFieldFirstNameExample").'global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_FIRSTNAME?' checked="true"':'').">
'.$langs->trans("LDAPFieldMail").''; print ''; -print ''.$langs->trans("LDAPFieldMailExample").'
'.$langs->trans("LDAPFieldMailExample").'global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_MAIL?' checked="true"':'').">
'.$langs->trans("LDAPFieldPhone").''; print ''; -print ''.$langs->trans("LDAPFieldPhoneExample").'
'.$langs->trans("LDAPFieldPhoneExample").'global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_PHONE?' checked="true"':'').">
'.$langs->trans("LDAPFieldMobile").''; print ''; -print ''.$langs->trans("LDAPFieldMobileExample").'
'.$langs->trans("LDAPFieldMobileExample").'global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_MOBILE?' checked="true"':'').">
'.$langs->trans("LDAPFieldFax").''; print ''; -print ''.$langs->trans("LDAPFieldFaxExample").'
'.$langs->trans("LDAPFieldFaxExample").'global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_FAX?' checked="true"':'').">
'.$langs->trans("LDAPFieldAddress").''; print ''; -print ''.$langs->trans("LDAPFieldAddressExample").'
'.$langs->trans("LDAPFieldAddressExample").'global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_ADDRESS?' checked="true"':'').">
'.$langs->trans("LDAPFieldZip").''; print ''; -print ''.$langs->trans("LDAPFieldZipExample").'
'.$langs->trans("LDAPFieldZipExample").'global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_ZIP?' checked="true"':'').">
'.$langs->trans("LDAPFieldTown").''; print ''; -print ''.$langs->trans("LDAPFieldTownExample").'
'.$langs->trans("LDAPFieldTownExample").'global->LDAP_KEY_CONTACTS==$conf->global->LDAP_FIELD_TOWN?' checked="true"':'').">
'; print '
'; diff --git a/htdocs/admin/ldap_members.php b/htdocs/admin/ldap_members.php index 9c01d4ac93a..e97e82d7c88 100644 --- a/htdocs/admin/ldap_members.php +++ b/htdocs/admin/ldap_members.php @@ -34,6 +34,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/adherent_type.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/authldap.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/ldap.lib.php"); $langs->load("admin"); @@ -48,8 +49,10 @@ if (!$user->admin) if ($_GET["action"] == 'setvalue' && $user->admin) { $error=0; + if (! dolibarr_set_const($db, 'LDAP_KEY_MEMBERS',$_POST["key"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_MEMBER_DN',$_POST["user"])) $error++; - if (! dolibarr_set_const($db, 'LDAP_MEMBER_TYPE_DN',$_POST["group"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_FULLNAME',$_POST["fieldfullname"])) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_LOGIN',$_POST["fieldlogin"])) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_LOGIN_SAMBA',$_POST["fieldloginsamba"])) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_NAME',$_POST["fieldname"])) $error++; @@ -73,8 +76,11 @@ if ($_GET["action"] == 'setvalue' && $user->admin) llxHeader(); +$head = ldap_prepare_head(); + print_fiche_titre($langs->trans("LDAPSetup"),'','setup'); + // Test si fonction LDAP actives if (! function_exists("ldap_connect")) { @@ -85,37 +91,8 @@ if ($mesg) print '
'.$mesg.'
'; else print '
'; -// Onglets -$h = 0; +dolibarr_fiche_head($head, 'members', $langs->trans("LDAP")); -$head[$h][0] = DOL_URL_ROOT."/admin/ldap.php"; -$head[$h][1] = $langs->trans("LDAPGlobalParameters"); -$h++; - -if ($conf->global->LDAP_SYNCHRO_ACTIVE) -{ - $head[$h][0] = DOL_URL_ROOT."/admin/ldap_users.php"; - $head[$h][1] = $langs->trans("LDAPUsersAndGroupsSynchro"); - $h++; -} - -if ($conf->global->LDAP_CONTACT_ACTIVE) -{ - $head[$h][0] = DOL_URL_ROOT."/admin/ldap_contacts.php"; - $head[$h][1] = $langs->trans("LDAPContactsSynchro"); - $h++; -} - -if ($conf->global->LDAP_MEMBERS_ACTIVE) -{ - $head[$h][0] = DOL_URL_ROOT."/admin/ldap_members.php"; - $head[$h][1] = $langs->trans("LDAPMembersSynchro"); - $hselected=$h; - $h++; -} - - -dolibarr_fiche_head($head, $hselected, $langs->trans("LDAP")); print $langs->trans("LDAPDescMembers").'
'; print '
'; @@ -130,81 +107,102 @@ $html=new Form($db); print ''; -print ''.$langs->trans("LDAPSynchronizeMembers").''; +print ''.$langs->trans("LDAPSynchronizeUsers").''; +print ''.$langs->trans("LDAPNamingAttribute").''; print "\n"; // DN Pour les adherents $var=!$var; print ''.$langs->trans("LDAPMemberDn").picto_required().''; -print ''; -print ''.$langs->trans("LDAPMemberDnExample").''; - -// DN pour les types -/* -$var=!$var; -print ''.$langs->trans("LDAPMemberTypeDn").picto_required().''; -print ''; -print ''.$langs->trans("LDAPMemberTypeDnExample").''; -*/ +print ''; +print ''.$langs->trans("LDAPMemberDnExample").''; +print ' '; +print ''; // Filtre /* $var=!$var; print ''.$langs->trans("LDAPFilterConnection").picto_required().''; print ''; -print ''.$langs->trans("LDAPFilterConnectionExample").''; +print ''.$langs->trans("LDAPFilterConnectionExample").''; +print ''; */ +// Common name +$var=!$var; +print ''.$langs->trans("LDAPFieldFullname").''; +print ''; +print ''.$langs->trans("LDAPFieldFullnameExample").''; +print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_FULLNAME?' checked="true"':'').">"; +print ''; + // Name $var=!$var; -print ''.$langs->trans("LDAPFieldName").picto_required().''; +print ''.$langs->trans("LDAPFieldName").''; print ''; -print ''.$langs->trans("LDAPFieldNameExample").''; +print ''.$langs->trans("LDAPFieldNameExample").''; +print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_NAME?' checked="true"':'').">"; +print ''; // Firstname $var=!$var; print ''.$langs->trans("LDAPFieldFirstName").''; print ''; -print ''.$langs->trans("LDAPFieldFirstNameExample").''; +print ''.$langs->trans("LDAPFieldFirstNameExample").''; +print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_FIRSTNAME?' checked="true"':'').">"; +print ''; // Login unix $var=!$var; print ''.$langs->trans("LDAPFieldLoginUnix").''; print ''; -print ''.$langs->trans("LDAPFieldLoginExample").''; +print ''.$langs->trans("LDAPFieldLoginExample").''; +print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_LOGIN?' checked="true"':'').">"; +print ''; // Login samba $var=!$var; print ''.$langs->trans("LDAPFieldLoginSamba").''; print ''; -print ''.$langs->trans("LDAPFieldLoginSambaExample").''; +print ''.$langs->trans("LDAPFieldLoginSambaExample").''; +print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_LOGIN_SAMBA?' checked="true"':'').">"; +print ''; // Mail $var=!$var; print ''.$langs->trans("LDAPFieldMail").''; print ''; -print ''.$langs->trans("LDAPFieldMailExample").''; +print ''.$langs->trans("LDAPFieldMailExample").''; +print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_MAIL?' checked="true"':'').">"; +print ''; // Phone $var=!$var; print ''.$langs->trans("LDAPFieldPhone").''; print ''; -print ''.$langs->trans("LDAPFieldPhoneExample").''; - -// Fax -$var=!$var; -print ''.$langs->trans("LDAPFieldFax").''; -print ''; -print ''.$langs->trans("LDAPFieldFaxExample").''; +print ''.$langs->trans("LDAPFieldPhoneExample").''; +print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_PHONE?' checked="true"':'').">"; +print ''; // Mobile $var=!$var; print ''.$langs->trans("LDAPFieldMobile").''; print ''; -print ''.$langs->trans("LDAPFieldMobileExample").''; +print ''.$langs->trans("LDAPFieldMobileExample").''; +print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_MOBILE?' checked="true"':'').">"; +print ''; + +// Fax +$var=!$var; +print ''.$langs->trans("LDAPFieldFax").''; +print ''; +print ''.$langs->trans("LDAPFieldFaxExample").''; +print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_FAX?' checked="true"':'').">"; +print ''; + $var=!$var; -print ''; +print ''; print ''; print ''; diff --git a/htdocs/admin/ldap_users.php b/htdocs/admin/ldap_users.php index b83e3c98914..2c0f6e93140 100644 --- a/htdocs/admin/ldap_users.php +++ b/htdocs/admin/ldap_users.php @@ -34,6 +34,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/user.class.php"); require_once(DOL_DOCUMENT_ROOT."/usergroup.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/authldap.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/ldap.lib.php"); $langs->load("admin"); @@ -48,8 +49,10 @@ if (!$user->admin) if ($_GET["action"] == 'setvalue' && $user->admin) { $error=0; + if (! dolibarr_set_const($db, 'LDAP_KEY_USERS',$_POST["key"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_USER_DN',$_POST["user"])) $error++; - if (! dolibarr_set_const($db, 'LDAP_GROUP_DN',$_POST["group"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_FULLNAME',$_POST["fieldfullname"])) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_LOGIN',$_POST["fieldlogin"])) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_LOGIN_SAMBA',$_POST["fieldloginsamba"])) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_NAME',$_POST["fieldname"])) $error++; @@ -73,8 +76,11 @@ if ($_GET["action"] == 'setvalue' && $user->admin) llxHeader(); +$head = ldap_prepare_head(); + print_fiche_titre($langs->trans("LDAPSetup"),'','setup'); + // Test si fonction LDAP actives if (! function_exists("ldap_connect")) { @@ -85,36 +91,8 @@ if ($mesg) print '
'.$mesg.'
'; else print '
'; -// Onglets -$h = 0; +dolibarr_fiche_head($head, 'users', $langs->trans("LDAP")); -$head[$h][0] = DOL_URL_ROOT."/admin/ldap.php"; -$head[$h][1] = $langs->trans("LDAPGlobalParameters"); -$h++; - -if ($conf->global->LDAP_SYNCHRO_ACTIVE) -{ - $head[$h][0] = DOL_URL_ROOT."/admin/ldap_users.php"; - $head[$h][1] = $langs->trans("LDAPUsersAndGroupsSynchro"); - $hselected=$h; - $h++; -} - -if ($conf->global->LDAP_CONTACT_ACTIVE) -{ - $head[$h][0] = DOL_URL_ROOT."/admin/ldap_contacts.php"; - $head[$h][1] = $langs->trans("LDAPContactsSynchro"); - $h++; -} - -if ($conf->global->LDAP_MEMBERS_ACTIVE) -{ - $head[$h][0] = DOL_URL_ROOT."/admin/ldap_members.php"; - $head[$h][1] = $langs->trans("LDAPMembersSynchro"); - $h++; -} - -dolibarr_fiche_head($head, $hselected, $langs->trans("LDAP")); print $langs->trans("LDAPDescUsers").'
'; print '
'; @@ -129,79 +107,101 @@ $html=new Form($db); print ''; -print ''.$langs->trans("LDAPSynchronizeUsersAndGroup").''; +print ''.$langs->trans("LDAPSynchronizeUsers").''; +print ''.$langs->trans("LDAPNamingAttribute").''; print "\n"; // DN Pour les utilisateurs $var=!$var; print ''.$langs->trans("LDAPUserDn").picto_required().''; -print ''; -print ''.$langs->trans("LDAPUserDnExample").''; - -// DN pour les groupes -$var=!$var; -print ''.$langs->trans("LDAPGroupDn").picto_required().''; -print ''; -print ''.$langs->trans("LDAPGroupDnExample").''; +print ''; +print ''.$langs->trans("LDAPUserDnExample").''; +print ' '; +print ''; // Filtre /* $var=!$var; print ''.$langs->trans("LDAPFilterConnection").picto_required().''; print ''; -print ''.$langs->trans("LDAPFilterConnectionExample").''; +print ''.$langs->trans("LDAPFilterConnectionExample").''; +print ''; */ +// Common name +$var=!$var; +print ''.$langs->trans("LDAPFieldFullname").''; +print ''; +print ''.$langs->trans("LDAPFieldFullnameExample").''; +print 'global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_FULLNAME?' checked="true"':'').">"; +print ''; + // Name $var=!$var; -print ''.$langs->trans("LDAPFieldName").picto_required().''; +print ''.$langs->trans("LDAPFieldName").''; print ''; -print ''.$langs->trans("LDAPFieldNameExample").''; +print ''.$langs->trans("LDAPFieldNameExample").''; +print 'global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_NAME?' checked="true"':'').">"; +print ''; // Firstname $var=!$var; print ''.$langs->trans("LDAPFieldFirstName").''; print ''; -print ''.$langs->trans("LDAPFieldFirstNameExample").''; +print ''.$langs->trans("LDAPFieldFirstNameExample").''; +print 'global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_FIRSTNAME?' checked="true"':'').">"; +print ''; // Login unix $var=!$var; print ''.$langs->trans("LDAPFieldLoginUnix").''; print ''; -print ''.$langs->trans("LDAPFieldLoginExample").''; +print ''.$langs->trans("LDAPFieldLoginExample").''; +print 'global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_LOGIN?' checked="true"':'').">"; +print ''; // Login samba $var=!$var; print ''.$langs->trans("LDAPFieldLoginSamba").''; print ''; -print ''.$langs->trans("LDAPFieldLoginSambaExample").''; +print ''.$langs->trans("LDAPFieldLoginSambaExample").''; +print 'global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_LOGIN_SAMBA?' checked="true"':'').">"; +print ''; // Mail $var=!$var; print ''.$langs->trans("LDAPFieldMail").''; print ''; -print ''.$langs->trans("LDAPFieldMailExample").''; +print ''.$langs->trans("LDAPFieldMailExample").''; +print 'global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_MAIL?' checked="true"':'').">"; +print ''; // Phone $var=!$var; print ''.$langs->trans("LDAPFieldPhone").''; print ''; -print ''.$langs->trans("LDAPFieldPhoneExample").''; - -// Fax -$var=!$var; -print ''.$langs->trans("LDAPFieldFax").''; -print ''; -print ''.$langs->trans("LDAPFieldFaxExample").''; +print ''.$langs->trans("LDAPFieldPhoneExample").''; +print 'global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_PHONE?' checked="true"':'').">"; +print ''; // Mobile $var=!$var; print ''.$langs->trans("LDAPFieldMobile").''; print ''; -print ''.$langs->trans("LDAPFieldMobileExample").''; +print ''.$langs->trans("LDAPFieldMobileExample").''; +print 'global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_MOBILE?' checked="true"':'').">"; +print ''; + +// Fax +$var=!$var; +print ''.$langs->trans("LDAPFieldFax").''; +print ''; +print ''.$langs->trans("LDAPFieldFaxExample").''; +print 'global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_FAX?' checked="true"':'').">"; +print ''; $var=!$var; -print ''; +print ''; print ''; print ''; @@ -219,7 +219,6 @@ if (function_exists("ldap_connect")) { print '
'; print ''.$langs->trans("LDAPTestSynchroUser").''; - print ''.$langs->trans("LDAPTestSynchroGroup").''; print '

'; } @@ -248,32 +247,6 @@ if (function_exists("ldap_connect")) } } - - if ($_GET["action"] == 'testgroup') - { - // Creation contact - $fgroup=new UserGroup($db); - $fgroup->initAsSpecimen(); - - // Test synchro - //$result1=$fgroup->delete_ldap($user); - $result2=$fgroup->update_ldap($user); - $result3=$fgroup->delete_ldap($user); - - if ($result2 > 0) - { - print img_picto('','info').' '; - print ''.$langs->trans("LDAPSynchroOK").'
'; - } - else - { - print img_picto('','error').' '; - print ''.$langs->trans("LDAPSynchroKO"); - print ': '.$fgroup->error; - print '
'; - } - - } } $db->close(); diff --git a/htdocs/conf/conf.class.php b/htdocs/conf/conf.class.php index 24c93f626e8..1df733aaebd 100644 --- a/htdocs/conf/conf.class.php +++ b/htdocs/conf/conf.class.php @@ -119,6 +119,13 @@ class Conf if (! $this->global->MAIN_MENU_BARRELEFT) $this->global->MAIN_MENU_BARRELEFT="default.php"; if (! $this->global->MAIN_MENUFRONT_BARRELEFT) $this->global->MAIN_MENUFRONT_BARRELEFT="default.php"; + // Variable globales LDAP + if (! $this->global->LDAP_KEY_USERS) $this->global->LDAP_KEY_USERS=$this->global->LDAP_FIELD_FULLNAME; + if (! $this->global->LDAP_KEY_GROUPS) $this->global->LDAP_KEY_GROUPS=$this->global->LDAP_FIELD_FULLNAME; + if (! $this->global->LDAP_KEY_CONTACTS) $this->global->LDAP_KEY_CONTACTS=$this->global->LDAP_FIELD_FULLNAME; + if (! $this->global->LDAP_KEY_MEMBERS) $this->global->LDAP_KEY_MEMBERS=$this->global->LDAP_FIELD_FULLNAME; + + /* * Charge l'objet de traduction et positionne langage courant global */ diff --git a/htdocs/contact.class.php b/htdocs/contact.class.php index 6f7098f3217..43ffe06e385 100644 --- a/htdocs/contact.class.php +++ b/htdocs/contact.class.php @@ -233,9 +233,9 @@ class Contact if ($bind) { - $info["cn"] = trim($this->firstname." ".$this->name); - $dn = "cn=".$info["cn"].",".$conf->global->LDAP_CONTACT_DN; - + $info=$this->_load_ldap_info($info); + + $dn = $conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS].",".$conf->global->LDAP_CONTACT_DN; $result=$ldap->delete($dn); return $result; @@ -250,8 +250,81 @@ class Contact } + function _load_ldap_info($info) + { + global $conf,$langs; + + if ($conf->global->LDAP_SERVER_TYPE == 'activedirectory') + { + $info["objectclass"]=array("top", + "person", + "organizationalPerson", + "user"); + } + else + { + $info["objectclass"]=array("top", + "person", + "organizationalPerson", + "inetOrgPerson"); + } + + // Champs + if ($this->fullname && $conf->global->LDAP_FIELD_FULLNAME) $info[$conf->global->LDAP_FIELD_FULLNAME] = $this->fullname; + if ($this->name && $conf->global->LDAP_FIELD_NAME) $info[$conf->global->LDAP_FIELD_NAME] = $this->name; + if ($this->firstname && $conf->global->LDAP_FIELD_FIRSTNAME) $info[$conf->global->LDAP_FIELD_FIRSTNAME] = $this->firstname; + if ($this->poste) $info["title"] = $this->poste; + if ($this->socid > 0) + { + $soc = new Societe($this->db); + $soc->fetch($this->socid); + + $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($this->egroupware_id) == 0) + { + $this->egroupware_id = 1; + } + + $info["phpgwContactOwner"] = $this->egroupware_id; + + if ($this->email) $info["rfc822Mailbox"] = $this->email; + if ($this->phone_mobile) $info["phpgwCellTelephoneNumber"] = $this->phone_mobile; + } + + return $info; + } + + /** - * \brief Creation d'un contact dans l'arbre LDAP + * \brief Creation dans l'arbre LDAP * \param user Utilisateur qui effectue la creation * \return int <0 si ko, >0 si ok */ @@ -294,90 +367,19 @@ class Contact } if ($bind) { - if ($conf->global->LDAP_SERVER_TYPE == 'activedirectory') - { - $info["objectclass"]=array("top", - "person", - "organizationalPerson", - "user"); - } - else - { - $info["objectclass"]=array("top", - "person", - "organizationalPerson", - "inetOrgPerson"); - } + $info=$this->_load_ldap_info($info); - // Champs obligatoires - $info["cn"] = trim($this->firstname." ".$this->name); - if ($this->name) $info[$conf->global->LDAP_FIELD_NAME] = $this->name; - else - { - $langs->load("other"); - $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Name")); - return -1; - } - - // Champs optionnels - if ($this->firstname && $conf->global->LDAP_FIELD_FIRSTNAME) $info[$conf->global->LDAP_FIELD_FIRSTNAME] = $this->firstname; - if ($this->poste) $info["title"] = $this->poste; - if ($this->socid > 0) - { - $soc = new Societe($this->db); - $soc->fetch($this->socid); - - $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->id. ": ".trim($this->firstname." ".$this->name); - - $newdn = "cn=".$info["cn"].",".$conf->global->LDAP_CONTACT_DN; - $olddn = $newdn; - if ($this->old_firstname || $this->old_name) $olddn="cn=".trim($this->old_firstname." ".$this->old_name).",".$conf->global->LDAP_CONTACT_DN; + // Definitition du DN + $dn = $conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS].",".$conf->global->LDAP_CONTACT_DN; + $olddn = $dn; + if (($this->old_firstname || $this->old_name) && $conf->global->LDAP_KEY_CONTACTS=="cn") + $olddn=$conf->global->LDAP_KEY_CONTACTS."=".trim($this->old_firstname." ".$this->old_name).",".$conf->global->LDAP_CONTACT_DN; // On supprime et on insère - dolibarr_syslog("Contact.class::update_ldap olddn=".$olddn." newdn=".$newdn); + dolibarr_syslog("User.class::update_ldap dn=".$dn." olddn=".$olddn); $result = $ldap->delete($olddn); - $result = $ldap->add($newdn, $info); + $result = $ldap->add($dn, $info); if ($result <= 0) { $this->error = ldap_errno($ldap->connection)." ".ldap_error($ldap->connection)." ".$ldap->error; diff --git a/htdocs/contact/ldap.php b/htdocs/contact/ldap.php index e39d1803ca4..6a1a8049728 100644 --- a/htdocs/contact/ldap.php +++ b/htdocs/contact/ldap.php @@ -115,9 +115,21 @@ print ''.$langs->trans("UserTitle").''; print $form->civilite_name($contact->civilite_id); print ''; +// Nom print ''.$langs->trans("Lastname").''.$contact->name.''; + +// Prenom print ''.$langs->trans("Firstname").''.$contact->firstname.''; +// LDAP DN +$langs->load("admin"); +print ''.$langs->trans("LDAPContactDn").'*'.$conf->global->LDAP_CONTACT_DN."\n"; + +// LDAP Server +print ''.$langs->trans("LDAPPrimaryServer").'*'.$conf->global->LDAP_SERVER_HOST."\n"; +print ''.$langs->trans("LDAPSecondaryServer").'*'.$conf->global->LDAP_SERVER_HOST_SLAVE."\n"; +print ''.$langs->trans("LDAPServerPort").'*'.$conf->global->LDAP_SERVER_PORT."\n"; + print ''; print ''; @@ -146,7 +158,7 @@ if ($result) 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 + if (! $bind) // Si pas de login ou si connexion avec login en echec, on tente en anonyme { dolibarr_syslog("ldap.php: bind",LOG_DEBUG); $bind=$ldap->bind(); @@ -155,9 +167,14 @@ if ($result) if ($bind) { $info["cn"] = trim($contact->firstname." ".$contact->name); - $dn = "cn=".$info["cn"].",".$conf->global->LDAP_CONTACT_DN; - $result=$ldap->search($dn,'(objectClass=*)'); + $dn = $conf->global->LDAP_CONTACT_DN; +// $dn = "cn=".$info["cn"].",".$dn; +// $dn = "uid=".$info["uid"].",".$dn + $search = "(cn=".$info["cn"].")"; + //$search = "(uid=".$info["uid"].")"; + + $result=$ldap->search($dn,$search); // Affichage arbre if (sizeof($result)) @@ -169,15 +186,18 @@ if ($result) { print ''.$langs->trans("LDAPRecordNotFound").''; } + + $ldap->unbind(); } else { - dolibarr_print_error('',$ldap); + dolibarr_print_error('',$ldap->error); } + $ldap->close(); } else { - dolibarr_print_error('',$ldap); + dolibarr_print_error('',$ldap->error); } print ''; diff --git a/htdocs/don.class.php b/htdocs/don.class.php index 4dc0617fec0..bf9da0e3e8a 100644 --- a/htdocs/don.class.php +++ b/htdocs/don.class.php @@ -55,7 +55,7 @@ class Don var $statut; var $projet; - var $errorstr; + var $error; /** * \brief Constructeur @@ -186,10 +186,10 @@ class Don */ function print_error_list() { - $num = sizeof($this->errorstr); + $num = sizeof($this->error); for ($i = 0 ; $i < $num ; $i++) { - print "
  • " . $this->errorstr[$i]; + print "
  • " . $this->error[$i]; } } @@ -267,7 +267,7 @@ class Don if ($err) { - $this->errorstr = $error_string; + $this->error = $error_string; return 0; } else diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 3d4555ee897..b5a5b2e7703 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -41,7 +41,7 @@ class Form { var $db; - var $errorstr; + var $error; var $cache_types_paiements_code=array(); var $cache_types_paiements_libelle=array(); @@ -2372,7 +2372,7 @@ class Form */ function error() { - return $this->errorstr; + return $this->error; } diff --git a/htdocs/html.formmail.class.php b/htdocs/html.formmail.class.php index 690dbc94c92..f92ecefc529 100644 --- a/htdocs/html.formmail.class.php +++ b/htdocs/html.formmail.class.php @@ -64,7 +64,7 @@ class FormMail var $substit=array(); var $param=array(); - var $errorstr; + var $error; /** diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 682f809ac22..32756b8bfa5 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -492,14 +492,19 @@ AdherentMailRequired=EMail required to create a new member ##### LDAP setup ##### LDAPSetup=LDAP Setup LDAPGlobalParameters=Global parameters -LDAPUsersAndGroupsSynchro=Users/groups synchro -LDAPContactsSynchro=Contacts synchro +LDAPUsersSynchro=Users +LDAPGroupsSynchro=Groups +LDAPContactsSynchro=Contacts +LDAPMembersSynchro=Members LDAPSynchronization=LDAP synchronisation LDAPFunctionsNotAvailableOnPHP=LDAP functions are not availbale on your PHP -LDAPSynchronizeUsersAndGroup=Synchronize Dolibarr users and groups with LDAP LDAPToDolibarr=LDAP -> Dolibarr DolibarrToLDAP=Dolibarr -> LDAP +LDAPNamingAttribute=Key +LDAPSynchronizeUsers=Synchronize Dolibarr users with LDAP +LDAPSynchronizeGroups=Synchronize Dolibarr groups with LDAP LDAPSynchronizeContacts=Synchronize Dolibarr contacts with LDAP +LDAPSynchronizeMembers=Synchronize members of Dolibarr fundation module with LDAP LDAPTypeExample=OpenLdap, Egroupware or Active Directory LDAPPrimaryServer=LDAP primary server LDAPSecondaryServer=LDAP secondary server @@ -524,8 +529,14 @@ LDAPDnSynchroActiveExample=LDAP to Dolibarr or Dolibarr to LDAP synchronization LDAPDnContactActive=Contacts' synchronization LDAPDnContactActiveYes=Activated synchronization LDAPDnContactActiveExample=Activated/Unactivated synchronization +LDAPDnMemberActive=Members' synchronization +LDAPDnMemberActiveExample=Activated/Unactivated synchronization LDAPContactDn=Dolibarr contacts' DN LDAPContactDnExample=Complete DN (ex: ou=contacts,dc=society,dc=com) +LDAPMemberDn=Dolibarr members' DN +LDAPMemberDnExample=Complete DN (ex: ou=members,dc=society,dc=com) +LDAPMemberTypeDn=Dolibarr member's type DN +LDAPMemberTypeDnExample=Complete DN (ex: ou=type_members,dc=society,dc=com) LDAPTestConnect=Test LDAP connection LDAPTestSynchroContact=Test contact's synchronization LDAPTestSynchroUser=Test user's synchronization @@ -544,35 +555,39 @@ LDAPConnectToDNFailed=Connection au DN (%s) LDAPSetupForVersion3=LDAP server configured for version 3 LDAPSetupForVersion2=LDAP server configured for version 2 LDAPFieldLoginUnix=Login (unix) -LDAPFieldLoginExample=Suggested value : uid +LDAPFieldLoginExample=Example : uid LDAPFilterConnection=Search filter -LDAPFilterConnectionExample=Suggested value : &(objectClass=user)(objectCategory=person) +LDAPFilterConnectionExample=Example : &(objectClass=user)(objectCategory=person) LDAPFieldLoginSamba=Login (samba, activedirectory) -LDAPFieldLoginSambaExample=Suggested value : samaccountname (Samba and ActiveDirectory) +LDAPFieldLoginSambaExample=Example : samaccountname +LDAPFieldFullname=Firstname Name +LDAPFieldFullnameExample=Example : cn LDAPFieldName=Name -LDAPFieldNameExample=Suggested value : sn +LDAPFieldNameExample=Example : sn LDAPFieldFirstName=Firstname -LDAPFieldFirstNameExample=Suggested value : givenname +LDAPFieldFirstNameExample=Example : givenname LDAPFieldMail=Email address -LDAPFieldMailExample=Suggested value : mail +LDAPFieldMailExample=Example : mail LDAPFieldPhone=Phone number -LDAPFieldPhoneExample=Suggested value : telephonenumber +LDAPFieldPhoneExample=Example : telephonenumber LDAPFieldFax=Fax number -LDAPFieldFaxExample=Suggested value : facsimiletelephonenumber +LDAPFieldFaxExample=Example : facsimiletelephonenumber LDAPFieldMobile=Cellular phone -LDAPFieldMobileExample=Suggested value : mobile +LDAPFieldMobileExample=Example : mobile LDAPFieldAddress=Street -LDAPFieldAddressExample=Valeur recommandée : street +LDAPFieldAddressExample=Example : street LDAPFieldZip=Zip -LDAPFieldZipExample=Valeur recommandée : postalcode +LDAPFieldZipExample=Example : postalcode LDAPFieldTown=Town -LDAPFieldTownExample=Valeur recommandée : l +LDAPFieldTownExample=Example : l LDAPParametersAreStillHardCoded=LDAP parametres are still hardcoded (in contact class) LDAPSetupNotComplete=LDAP setup not complete (go on others tabs) LDAPNoUserOrPasswordProvidedAccessIsReadOnly=No administrator or password provided. LDAP access will be anonymous and in read only mode. LDAPDescContact=This page allows you to define LDAP attributes name in LDAP tree for each data found on Dolibarr contacts. LDAPDescUsers=This page allows you to define LDAP attributes name in LDAP tree for each data found on Dolibarr users. -LDAPDescValues=Suggested values are designed for OpenLDAP with following loaded schemas: core.schema, cosine.schema, inetorgperson.schema). If you use thoose values and OpenLDAP, modify your LDAP config file slapd.conf to have all thoose schemas loaded. +LDAPDescGroups=This page allows you to define LDAP attributes name in LDAP tree for each data found on Dolibarr groups. +LDAPDescMembers=This page allows you to define LDAP attributes name in LDAP tree for each data found on Dolibarr members module. +LDAPDescValues=Example values are designed for OpenLDAP with following loaded schemas: core.schema, cosine.schema, inetorgperson.schema). If you use thoose values and OpenLDAP, modify your LDAP config file slapd.conf to have all thoose schemas loaded. ##### Products ##### ProductSetup=Products module setup NumberOfProductShowInSelect=Max number of products in combos select lists (0=no limit) diff --git a/htdocs/langs/en_US/ldap.lang b/htdocs/langs/en_US/ldap.lang index f8ba059e19d..a7e3e52425c 100644 --- a/htdocs/langs/en_US/ldap.lang +++ b/htdocs/langs/en_US/ldap.lang @@ -7,6 +7,7 @@ LdapUacf_ACCOUNTDISABLE=Account is disabled on this domain LDAPInformationsForThisContact=Informations in LDAP database for this contact LDAPInformationsForThisUser=Informations in LDAP database for this user LDAPInformationsForThisGroup=Informations in LDAP database for this group +LDAPInformationsForThisMember=Informations in LDAP database for this member LDAPAttribute=LDAP attribute LDAPAttributes=LDAP attributes LDAPCard=LDAP card diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index a104d861849..6ba481b570d 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -63,6 +63,7 @@ AddActionDone=Add action done Close=Close Close2=Close Confirm=Confirm +ConfirmSendCardByMail=Do you really want to send this card by mail ? Delete=Delete Remove=Remove Resiliate=Resiliate diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index d73e84e82ca..9fb3806f9a8 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -492,14 +492,19 @@ AdherentMailRequired=EMail obligatoire pour cr ##### LDAP setup ##### LDAPSetup=Configuration du module LDAP LDAPGlobalParameters=Paramètres globals -LDAPUsersAndGroupsSynchro=Synchro utilisateurs/groupes -LDAPContactsSynchro=Synchro contacts +LDAPUsersSynchro=Utilisateurs +LDAPGroupsSynchro=Groupes +LDAPContactsSynchro=Contacts +LDAPMembersSynchro=Adhérents LDAPSynchronization=Synchronisation LDAP LDAPFunctionsNotAvailableOnPHP=Les fonctions LDAP ne sont pas disponibles sur votre PHP -LDAPSynchronizeUsersAndGroup=Synchronisation des utilisateurs et groupes Dolibarr avec LDAP LDAPToDolibarr=LDAP -> Dolibarr DolibarrToLDAP=Dolibarr -> LDAP +LDAPNamingAttribute=Clé +LDAPSynchronizeUsers=Synchronisation des utilisateurs Dolibarr avec LDAP +LDAPSynchronizeGroups=Synchronisation des groupes utilisateurs Dolibarr avec LDAP LDAPSynchronizeContacts=Synchronisation des contacts Dolibarr avec LDAP +LDAPSynchronizeMembers=Synchronisation des membres du module adhérents de Dolibarr avec LDAP LDAPTypeExample=OpenLdap, Egroupware ou Active Directory LDAPPrimaryServer=Serveur primaire LDAPSecondaryServer=Serveur secondaire @@ -524,8 +529,14 @@ LDAPDnSynchroActiveExample=Synchronisation de LDAP vers Dolibarr ou Dolibarr ver LDAPDnContactActive=Synchronisation des contacts LDAPDnContactActiveYes=Synchronisation activée LDAPDnContactActiveExample=Synchronisation activée/désactivée +LDAPDnMemberActive=Synchronisation des adhérents +LDAPDnMemberActiveExample=Synchronisation activée/désactivée LDAPContactDn=DN des contacts Dolibarr LDAPContactDnExample=DN complet (ex: ou=contacts,dc=my-domain,dc=com) +LDAPMemberDn=DN des adhérents +LDAPMemberDnExample=DN complet (ex: ou=members,dc=society,dc=com) +LDAPMemberTypeDn=DN des types d'adhérents +LDAPMemberTypeDnExample=DN complet (ex: ou=type_members,dc=society,dc=com) LDAPTestConnect=Tester la connexion LDAP LDAPTestSynchroContact=Tester synchronisation contacts LDAPTestSynchroUser=Tester synchronisation utilisateur @@ -544,35 +555,39 @@ LDAPConnectToDNFailed=Connection au DN (%s) LDAPSetupForVersion3=Serveur LDAP configuré en version 3 LDAPSetupForVersion2=Serveur LDAP configuré en version 2 LDAPFieldLoginUnix=Login (unix) -LDAPFieldLoginExample=Valeur recommandée : uid +LDAPFieldLoginExample=Exemple : uid LDAPFilterConnection=Filtre de recherche -LDAPFilterConnectionExample=Valeur recommandée : &(objectClass=user)(objectCategory=person) +LDAPFilterConnectionExample=Exemple : &(objectClass=user)(objectCategory=person) LDAPFieldLoginSamba=Login (samba, activedirectory) -LDAPFieldLoginSambaExample=Valeur recommandée : samaccountname (Samba et ActiveDirectory) +LDAPFieldLoginSambaExample=Exemple : samaccountname +LDAPFieldFullname=Prénom Nom +LDAPFieldFullnameExample=Exemple : cn LDAPFieldName=Nom -LDAPFieldNameExample=Valeur recommandée : sn +LDAPFieldNameExample=Exemple : sn LDAPFieldFirstName=Prénom -LDAPFieldFirstNameExample=Valeur recommandée : givenname +LDAPFieldFirstNameExample=Exemple : givenname LDAPFieldMail=Email -LDAPFieldMailExample=Valeur recommandée : mail +LDAPFieldMailExample=Exemple : mail LDAPFieldPhone=Téléphone -LDAPFieldPhoneExample=Valeur recommandée : telephonenumber +LDAPFieldPhoneExample=Exemple : telephonenumber LDAPFieldFax=Fax -LDAPFieldFaxExample=Valeur recommandée : facsimiletelephonenumber +LDAPFieldFaxExample=Exemple : facsimiletelephonenumber LDAPFieldMobile=Téléphone portable -LDAPFieldMobileExample=Valeur recommandée : mobile +LDAPFieldMobileExample=Exemple : mobile LDAPFieldAddress=Adresse -LDAPFieldAddressExample=Valeur recommandée : street +LDAPFieldAddressExample=Exemple : street LDAPFieldZip=Code postal -LDAPFieldZipExample=Valeur recommandée : postalcode +LDAPFieldZipExample=Exemple : postalcode LDAPFieldTown=Ville -LDAPFieldTownExample=Valeur recommandée : l +LDAPFieldTownExample=Exemple : l LDAPParametersAreStillHardCoded=Les parametres LDAP sont codés en dur (dans classe contact) LDAPSetupNotComplete=Configuration LDAP incomplète (à compléter sur les autres onglets) LDAPNoUserOrPasswordProvidedAccessIsReadOnly=Administrateur ou mot de passe non renseigné. Les accès LDAP seront donc anonymes et en lecture seule. LDAPDescContact=Cette page permet de définir le nom des attributs de l'arbre LDAP pour chaque informations des contacts Dolibarr. LDAPDescUsers=Cette page permet de définir le nom des attributs de l'arbre LDAP pour chaque informations des utilisateurs Dolibarr. -LDAPDescValues=Les valeurs recommandées sont adaptées à OpenLDAP avec les schemas suivant chargés: core.schema, cosine.schema, inetorgperson.schema). Si vous utiliser les valeurs suggérés et OpenLDAP, modifier votre fichier de configuration LDAP slapd.conf pour avoir tous ces schémas actifs. +LDAPDescGroups=Cette page permet de définir le nom des attributs de l'arbre LDAP pour chaque informations des groupes utilisateurs Dolibarr. +LDAPDescMembers=Cette page permet de définir le nom des attributs de l'arbre LDAP pour chaque informations des membres du module adhérents Dolibarr. +LDAPDescValues=Les valeurs exemples sont adaptées à OpenLDAP avec les schemas suivant chargés: core.schema, cosine.schema, inetorgperson.schema). Si vous utiliser les valeurs suggérés et OpenLDAP, modifier votre fichier de configuration LDAP slapd.conf pour avoir tous ces schémas actifs. ##### Products ##### ProductSetup=Configuration du module Produits NumberOfProductShowInSelect=Nombre de produits max dans les listes déroulantes (0=aucune limite) diff --git a/htdocs/langs/fr_FR/ldap.lang b/htdocs/langs/fr_FR/ldap.lang index 738c3a1d8fa..564c6cec495 100644 --- a/htdocs/langs/fr_FR/ldap.lang +++ b/htdocs/langs/fr_FR/ldap.lang @@ -7,6 +7,7 @@ LdapUacf_ACCOUNTDISABLE=Le compte est d LDAPInformationsForThisContact=Informations en base LDAP pour ce contact LDAPInformationsForThisUser=Informations en base LDAP pour cet utilisateur LDAPInformationsForThisGroup=Informations en base LDAP pour ce groupe +LDAPInformationsForThisMember=Informations en base LDAP pour ce membre LDAPAttribute=Attribut LDAP LDAPAttributes=Attributs LDAP LDAPCard=Fiche LDAP diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index 5e60a74e0be..67fd36fc424 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -63,6 +63,7 @@ AddActionDone=Ajouter action faite Close=Clôturer Close2=Fermer Confirm=Confirmer +ConfirmSendCardByMail=Voulez vous envoyer cette fiche par mail ? Delete=Supprimer Remove=Enlever Resiliate=Résilier diff --git a/htdocs/lib/authldap.lib.php b/htdocs/lib/authldap.lib.php index d7a81b0b4c7..32a7fd1c6ac 100644 --- a/htdocs/lib/authldap.lib.php +++ b/htdocs/lib/authldap.lib.php @@ -174,10 +174,10 @@ class AuthLdap { * 2.1.2 : Simply closes the connection set up earlier. * Returns true if OK, false if there was an error. */ - function close() { - if ( !@ldap_close($this->connection)) { - $this->ldapErrorCode = ldap_errno( $this->connection); - $this->ldapErrorText = ldap_error( $this->connection); + function close() + { + if ($this->connection && ! @ldap_close($this->connection)) + { return false; } else { return true; @@ -192,6 +192,7 @@ class AuthLdap { if ( !$this->result=@ldap_bind( $this->connection)) { $this->ldapErrorCode = ldap_errno( $this->connection); $this->ldapErrorText = ldap_error( $this->connection); + $this->error=$this->ldapErrorCode." ".$this->ldapErrorText; return false; } else { return true; @@ -224,6 +225,7 @@ class AuthLdap { if ( !$this->result = @ldap_bind( $this->connection,$bindDn,$pass)) { $this->ldapErrorCode = ldap_errno( $this->connection); $this->ldapErrorText = ldap_error( $this->connection); + $this->error=$this->ldapErrorCode." ".$this->ldapErrorText; return false; } else { return true; diff --git a/htdocs/lib/ldap.lib.php b/htdocs/lib/ldap.lib.php new file mode 100644 index 00000000000..48f12071397 --- /dev/null +++ b/htdocs/lib/ldap.lib.php @@ -0,0 +1,81 @@ + + * + * 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/ldap.lib.php + \brief Ensemble de fonctions de base pour le module LDAP + \ingroup ldap + \version $Revision$ + + Ensemble de fonctions de base de dolibarr sous forme d'include +*/ + +function ldap_prepare_head() +{ + global $langs, $conf, $user; + $langs->load("ldap"); + + // 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"; + $head[$h][1] = $langs->trans("LDAPUsersSynchro"); + $head[$h][2] = 'users'; + $h++; + } + + if ($conf->global->LDAP_SYNCHRO_ACTIVE) + { + $head[$h][0] = DOL_URL_ROOT."/admin/ldap_groups.php"; + $head[$h][1] = $langs->trans("LDAPGroupsSynchro"); + $head[$h][2] = 'groups'; + $h++; + } + + if ($conf->global->LDAP_CONTACT_ACTIVE) + { + $head[$h][0] = DOL_URL_ROOT."/admin/ldap_contacts.php"; + $head[$h][1] = $langs->trans("LDAPContactsSynchro"); + $head[$h][2] = 'contacts'; + $h++; + } + + if ($conf->global->LDAP_MEMBERS_ACTIVE) + { + $head[$h][0] = DOL_URL_ROOT."/admin/ldap_members.php"; + $head[$h][1] = $langs->trans("LDAPMembersSynchro"); + $head[$h][2] = 'members'; + $h++; + } + + return $head; +} + +?> \ No newline at end of file diff --git a/htdocs/lib/member.lib.php b/htdocs/lib/member.lib.php new file mode 100644 index 00000000000..82596bc4a32 --- /dev/null +++ b/htdocs/lib/member.lib.php @@ -0,0 +1,56 @@ + + * + * 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/memeber.lib.php + \brief Ensemble de fonctions de base pour les adhérents + \version $Revision$ + + Ensemble de fonctions de base de dolibarr sous forme d'include +*/ + +function member_prepare_head($member) +{ + global $langs, $conf; + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT.'/adherents/fiche.php?rowid='.$member->id; + $head[$h][1] = $langs->trans("Card"); + $head[$h][2] = 'general'; + $h++; + + if ($conf->ldap->enabled && $conf->global->LDAP_MEMBERS_ACTIVE) + { + $langs->load("ldap"); + + $head[$h][0] = DOL_URL_ROOT.'/adherents/ldap.php?id='.$member->id; + $head[$h][1] = $langs->trans("LDAPCard"); + $head[$h][2] = 'ldap'; + $h++; + } + + return $head; +} + +?> \ No newline at end of file diff --git a/htdocs/user.class.php b/htdocs/user.class.php index 03cf0560b24..b57d2eb467c 100644 --- a/htdocs/user.class.php +++ b/htdocs/user.class.php @@ -1195,6 +1195,18 @@ class User } + /** + * \brief Creation dans l'arbre LDAP + * \param user Utilisateur qui effectue la creation + * \return int <0 si ko, >0 si ok + */ + function create_ldap($user) + { + dolibarr_syslog("User.class::create_ldap this->id=".$this->id,LOG_DEBUG); + return $this->update_ldap($user); + } + + /** * \brief Mise à jour dans l'arbre LDAP * \param user Utilisateur qui effectue la mise à jour @@ -1227,90 +1239,19 @@ class User } if ($bind) { - if ($conf->global->LDAP_SERVER_TYPE == 'activedirectory') - { - $info["objectclass"]=array("top", - "person", - "organizationalPerson", - "user"); - } - else - { - $info["objectclass"]=array("top", - "person", - "organizationalPerson", - "inetOrgPerson"); - } + $info=$this->_load_ldap_info($info); - // 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; + // Definitition du DN + $dn = $conf->global->LDAP_KEY_USERS."=".$info[$conf->global->LDAP_KEY_USERS].",".$conf->global->LDAP_USER_DN; + $olddn = $dn; + if (($this->old_firstname || $this->old_name) && $conf->global->LDAP_KEY_USERS=="cn") + $olddn=$conf->global->LDAP_KEY_USERS."=".trim($this->old_firstname." ".$this->old_name).",".$conf->global->LDAP_USER_DN; // On supprime et on insère - dolibarr_syslog("User.class::update_ldap olddn=".$olddn." newdn=".$newdn); + dolibarr_syslog("User.class::update_ldap dn=".$dn." olddn=".$olddn); $result = $ldap->delete($olddn); - $result = $ldap->add($newdn, $info); + $result = $ldap->add($dn, $info); if ($result <= 0) { $this->error = ldap_errno($ldap->connection)." ".ldap_error($ldap->connection)." ".$ldap->error; @@ -1374,9 +1315,9 @@ class User if ($bind) { - $info["cn"] = trim($this->prenom." ".$this->nom); - $dn = "cn=".$info["cn"].",".$conf->global->LDAP_USER_DN; - + $info=$this->_load_ldap_info($info); + + $dn = $conf->global->LDAP_KEY_USERS."=".$info[$conf->global->LDAP_KEY_USERS].",".$conf->global->LDAP_USER_DN; $result=$ldap->delete($dn); return $result; @@ -1390,6 +1331,80 @@ class User } } + + function _load_ldap_info($info) + { + global $conf,$langs; + + if ($conf->global->LDAP_SERVER_TYPE == 'activedirectory') + { + $info["objectclass"]=array("top", + "person", + "organizationalPerson", + "user"); + } + else + { + $info["objectclass"]=array("top", + "person", + "organizationalPerson", + "inetOrgPerson"); + } + + // Champs + if ($this->fullname && $conf->global->LDAP_FIELD_FULLNAME) $info[$conf->global->LDAP_FIELD_FULLNAME] = $this->fullname; + if ($this->nom && $conf->global->LDAP_FIELD_NAME) $info[$conf->global->LDAP_FIELD_NAME] = $this->nom; + if ($this->prenom && $conf->global->LDAP_FIELD_FIRSTNAME) $info[$conf->global->LDAP_FIELD_FIRSTNAME] = $this->prenom; + if ($this->login && $conf->global->LDAP_FIELD_LOGIN) $info[$conf->global->LDAP_FIELD_LOGIN] = $this->login; + 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($this->egroupware_id) == 0) + { + $this->egroupware_id = 1; + } + + $info["phpgwContactOwner"] = $this->egroupware_id; + + if ($this->email) $info["rfc822Mailbox"] = $this->email; + if ($this->phone_mobile) $info["phpgwCellTelephoneNumber"] = $this->phone_mobile; + } + + return $info; + } + /** * \brief Initialise le user avec valeurs fictives aléatoire diff --git a/htdocs/user/group/ldap.php b/htdocs/user/group/ldap.php index 05ac304daa6..290c5fb3945 100644 --- a/htdocs/user/group/ldap.php +++ b/htdocs/user/group/ldap.php @@ -84,6 +84,16 @@ print "\n"; print ''.$langs->trans("Note").''; print ''.nl2br($fgroup->note).' '; print "\n"; + +// LDAP DN +$langs->load("admin"); +print ''.$langs->trans("LDAPGroupDn").'*'.$conf->global->LDAP_GROUP_DN."\n"; + +// LDAP Server +print ''.$langs->trans("LDAPPrimaryServer").'*'.$conf->global->LDAP_SERVER_HOST."\n"; +print ''.$langs->trans("LDAPSecondaryServer").'*'.$conf->global->LDAP_SERVER_HOST_SLAVE."\n"; +print ''.$langs->trans("LDAPServerPort").'*'.$conf->global->LDAP_SERVER_PORT."\n"; + print "\n"; print ''; @@ -112,7 +122,7 @@ if ($result) 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 + if (! $bind) // Si pas de login ou si connexion avec login en echec, on tente en anonyme { dolibarr_syslog("ldap.php: bind",LOG_DEBUG); $bind=$ldap->bind(); @@ -120,11 +130,15 @@ if ($result) 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=*)'); + $dn = $conf->global->LDAP_GROUP_DN; +// $dn = "cn=".$info["cn"].",".$dn; +// $dn = "uid=".$info["uid"].",".$dn + $search = "(cn=".$info["cn"].")"; + //$search = "(uid=".$info["uid"].")"; + + $result=$ldap->search($dn,$search); // Affichage arbre if (sizeof($result)) @@ -136,15 +150,18 @@ if ($result) { print ''.$langs->trans("LDAPRecordNotFound").''; } + + $ldap->unbind(); } else { - dolibarr_print_error('',$ldap); + dolibarr_print_error('',$ldap->error); } + $ldap->close(); } else { - dolibarr_print_error('',$ldap); + dolibarr_print_error('',$ldap->error); } print ''; diff --git a/htdocs/user/ldap.php b/htdocs/user/ldap.php index 90f6c86359d..82183f651c2 100644 --- a/htdocs/user/ldap.php +++ b/htdocs/user/ldap.php @@ -100,6 +100,15 @@ else } print ''; +// LDAP DN +$langs->load("admin"); +print ''.$langs->trans("LDAPUserDn").'*'.$conf->global->LDAP_USER_DN."\n"; + +// LDAP Server +print ''.$langs->trans("LDAPPrimaryServer").'*'.$conf->global->LDAP_SERVER_HOST."\n"; +print ''.$langs->trans("LDAPSecondaryServer").'*'.$conf->global->LDAP_SERVER_HOST_SLAVE."\n"; +print ''.$langs->trans("LDAPServerPort").'*'.$conf->global->LDAP_SERVER_PORT."\n"; + print ''; print ''; @@ -128,7 +137,7 @@ if ($result) 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 + if (! $bind) // Si pas de login ou si connexion avec login en echec, on tente en anonyme { dolibarr_syslog("ldap.php: bind",LOG_DEBUG); $bind=$ldap->bind(); @@ -136,11 +145,15 @@ if ($result) 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=*)'); + $dn = $conf->global->LDAP_USER_DN; +// $dn = "cn=".$info["cn"].",".$dn; +// $dn = "uid=".$info["uid"].",".$dn + $search = "(cn=".$info["cn"].")"; + //$search = "(uid=".$info["uid"].")"; + + $result=$ldap->search($dn,$search); // Affichage arbre if (sizeof($result)) @@ -152,15 +165,18 @@ if ($result) { print ''.$langs->trans("LDAPRecordNotFound").''; } + + $ldap->unbind(); } else { - dolibarr_print_error('',$ldap); + dolibarr_print_error('',$ldap->error); } + $ldap->close(); } else { - dolibarr_print_error('',$ldap); + dolibarr_print_error('',$ldap->error); } print ''; diff --git a/htdocs/usergroup.class.php b/htdocs/usergroup.class.php index 1220e3a8779..659ac6a5b9f 100644 --- a/htdocs/usergroup.class.php +++ b/htdocs/usergroup.class.php @@ -425,6 +425,18 @@ class UserGroup } + /** + * \brief Creation dans l'arbre LDAP + * \param user Utilisateur qui effectue la creation + * \return int <0 si ko, >0 si ok + */ + function create_ldap($user) + { + dolibarr_syslog("UserGroup.class::create_ldap this->id=".$this->id,LOG_DEBUG); + return $this->update_ldap($user); + } + + /** * \brief Mise à jour dans l'arbre LDAP * \param user Utilisateur qui effectue la mise à jour @@ -457,45 +469,17 @@ class UserGroup } if ($bind) { - if ($conf->global->LDAP_SERVER_TYPE == 'activedirectory') - { - $info["objectclass"]=array("top", - "person", - "organizationalPerson", - "user"); - } - else - { - $info["objectclass"]=array("top", - "person", - "organizationalPerson", - "inetOrgPerson"); - } + $info=$this->_load_ldap_info($info); - // 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; + // Definitition du DN + $dn = $conf->global->LDAP_KEY_GROUPS."=".$info[$conf->global->LDAP_KEY_GROUPS].",".$conf->global->LDAP_GROUP_DN; + $olddn = $dn; // On supprime et on insère - dolibarr_syslog("UserGroup.class::update_ldap olddn=".$olddn." newdn=".$newdn); + dolibarr_syslog("User.class::update_ldap dn=".$dn." olddn=".$olddn); $result = $ldap->delete($olddn); - $result = $ldap->add($newdn, $info); + $result = $ldap->add($dn, $info); if ($result <= 0) { $this->error = ldap_errno($ldap->connection)." ".ldap_error($ldap->connection)." ".$ldap->error; @@ -558,9 +542,9 @@ class UserGroup if ($bind) { - $info["cn"] = trim($this->nom); - $dn = "cn=".$info["cn"].",".$conf->global->LDAP_GROUP_DN; + $info=$this->_load_ldap_info($info); + $dn = $conf->global->LDAP_KEY_GROUPS."=".$info[$conf->global->LDAP_KEY_GROUPS].",".$conf->global->LDAP_GROUP_DN; $result=$ldap->delete($dn); return $result; @@ -574,6 +558,36 @@ class UserGroup } } + + function _load_ldap_info($info) + { + global $conf,$langs; + + if ($conf->global->LDAP_SERVER_TYPE == 'activedirectory') + { + $info["objectclass"]=array("top", + "person", + "organizationalPerson", + "user"); + } + else + { + $info["objectclass"]=array("top", + "person", + "organizationalPerson", + "inetOrgPerson"); + } + + // Champs + if ($this->fullname && $conf->global->LDAP_FIELD_FULLNAME) $info[$conf->global->LDAP_FIELD_FULLNAME] = $this->fullname; + if ($this->name && $conf->global->LDAP_FIELD_NAME) $info[$conf->global->LDAP_FIELD_NAME] = $this->name; + if ($this->firstname && $conf->global->LDAP_FIELD_FIRSTNAME) $info[$conf->global->LDAP_FIELD_FIRSTNAME] = $this->firstname; + if ($this->note) $info["description"] = $this->note; + + return $info; + } + + /** * \brief Initialise le groupe avec valeurs fictives aléatoire */