From c2484e3c12b35a60cae68c1f8064e78cce7f3b2d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 1 May 2007 16:26:12 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20champ=20g=E9r=E9=20par=20la=20synchro?= =?UTF-8?q?=20LDAP=20du=20module=20adh=E9rent.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/adherents/adherent.class.php | 45 ++++++++++------ htdocs/admin/ldap_members.php | 79 +++++++++++++++++++++++----- htdocs/langs/en_US/ldap.lang | 5 ++ htdocs/langs/fr_FR/ldap.lang | 5 ++ htdocs/lib/functions.inc.php | 3 +- htdocs/lib/ldap.class.php | 81 +++++++++++++++++++---------- 6 files changed, 160 insertions(+), 58 deletions(-) diff --git a/htdocs/adherents/adherent.class.php b/htdocs/adherents/adherent.class.php index cbad1ebe6a6..dcc2e1dd518 100644 --- a/htdocs/adherents/adherent.class.php +++ b/htdocs/adherents/adherent.class.php @@ -87,6 +87,11 @@ class Adherent var $user_id; var $user_login; + // Fiels loaded by fetch_subscriptions() + var $fistsubscription_date; + var $fistsubscription_amount; + var $lastsubscription_date; + var $lastsubscription_amount; // var $public; var $array_options; @@ -758,7 +763,11 @@ class Adherent /** - \brief Fonction qui récupére l'adhérent en donnant son rowid + \brief Fonction qui récupére pour un adhérent les paramètres + firstsubscription_date + fistrsubscription_amount + lastsubscription_date + lastsubscription_amount \return int <0 si KO, >0 si OK */ function fetch_subscriptions() @@ -780,21 +789,23 @@ class Adherent $i=0; while ($obj = $this->db->fetch_object($resql)) { - if ($i==0) $this->firstsubscription_date=$obj->dateadh; + if ($i==0) + { + $this->firstsubscription_date=$obj->dateadh; + $this->firstsubscription_amount=$obj->cotisation; + } $this->lastsubscription_date=$obj->dateadh; $this->lastsubscription_amount=$obj->cotisation; // TODO Completer avec records - - $i++; } return 1; } else { - $this->error=$this->db->error(); + $this->error=$this->db->error().' sql='.$sql; return -1; } } @@ -1921,6 +1932,11 @@ class Adherent $this->typeid=1; // Id type adherent $this->type='Type adherent'; // Libellé type adherent $this->need_subscription=0; + + $this->firstsubscription_date=time(); + $this->firstsubscription_amount=10; + $this->lastsubscription_date=time(); + $this->lastsubscription_amount=10; } @@ -1956,14 +1972,14 @@ class Adherent // Object classes $info["objectclass"]=split(',',$conf->global->LDAP_MEMBER_OBJECT_CLASS); - // Champs + // Member 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->pass && $conf->global->LDAP_FIELD_PASSWORD) $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass; // this->pass = mot de passe non crypté if ($this->poste && $conf->global->LDAP_FIELD_TITLE) $info[$conf->global->LDAP_FIELD_TITLE] = $this->poste; - if ($this->adresse && $conf->global->LDAP_FIELD_ADDRESS) $info[$conf->global->LDAP_FIELD_ADDRESS] = $this->adresse; + if ($this->adresse && $conf->global->LDAP_FIELD_ADDRESS) $info[$conf->global->LDAP_FIELD_ADDRESS] = $this->adresse; 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->pays && $conf->global->LDAP_FIELD_COUNTRY) $info[$conf->global->LDAP_FIELD_COUNTRY] = $this->pays; @@ -1973,15 +1989,14 @@ class Adherent 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->commentaire && $conf->global->LDAP_FIELD_DESCRIPTION) $info[$conf->global->LDAP_FIELD_DESCRIPTION] = $this->commentaire; - if ($this->naiss && $conf->global->LDAP_FIELD_BIRTHDATE) $info[$conf->global->LDAP_FIELD_BIRTHDATE] = dolibarr_print_date($this->naiss,'%Y%m%d%H%M%SZ'); + if ($this->naiss && $conf->global->LDAP_FIELD_BIRTHDATE) $info[$conf->global->LDAP_FIELD_BIRTHDATE] = dolibarr_print_date($this->naiss,'dayhourldap'); + if ($this->statut && $conf->global->LDAP_FIELD_MEMBER_STATUS) $info[$conf->global->LDAP_FIELD_MEMBER_STATUS] = $this->statut; - if ($_ENV["PARINUX"]) - { - $info["prnxFirstContribution"]=dolibarr_print_date($this->firstsubscription_date,'%Y%m%d%H%M%SZ'); - $info["prnxLastContribution"]=dolibarr_print_date($this->lastsubscription_date,'%Y%m%d%H%M%SZ'); - $info["prnxLastContributionPrice"]=$this->lastsubscription_amount; - $info["prnxStatus"]=$this->statut; - } + // Subscriptions + if ($this->firstsubscription_date && $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE) $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE] = dolibarr_print_date($this->firstsubscription_date,'dayhourldap'); + if ($this->firstsubscription_amount && $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT) $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT] = $this->firstsubscription_amount; + if ($this->lastsubscription_date && $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE) $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE] = dolibarr_print_date($this->lastsubscription_date,'dayhourldap'); + if ($this->lastsubscription_amount && $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT) $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT] = $this->lastsubscription_amount; return $info; } diff --git a/htdocs/admin/ldap_members.php b/htdocs/admin/ldap_members.php index 3ee51c5154d..6eb1bbd4852 100644 --- a/htdocs/admin/ldap_members.php +++ b/htdocs/admin/ldap_members.php @@ -50,9 +50,9 @@ 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_OBJECT_CLASS',$_POST["objectclass"])) $error++; + // Members 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++; @@ -71,6 +71,13 @@ if ($_GET["action"] == 'setvalue' && $user->admin) if (! dolibarr_set_const($db, 'LDAP_FIELD_COUNTRY',$_POST["fieldcountry"])) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_DESCRIPTION',$_POST["fielddescription"])) $error++; if (! dolibarr_set_const($db, 'LDAP_FIELD_BIRTHDATE',$_POST["fieldbirthdate"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_MEMBER_STATUS',$_POST["fieldstatus"])) $error++; + + // Subscriptions + if (! dolibarr_set_const($db, 'LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE', $_POST["fieldfirstsubscriptiondate"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT',$_POST["fieldfirstsubscriptionamount"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE', $_POST["fieldlastsubscriptiondate"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT', $_POST["fieldlastsubscriptionamount"])) $error++; if ($error) { @@ -173,7 +180,7 @@ $var=!$var; print ''.$langs->trans("LDAPFieldFirstName").''; print ''; print ''.$langs->trans("LDAPFieldFirstNameExample").''; -print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_FIRSTNAME?' checked="true"':'').">"; +print ' '; print ''; // Login unix @@ -197,7 +204,7 @@ $var=!$var; print ''.$langs->trans("LDAPFieldPasswordNotCrypted").''; print ''; print ''.$langs->trans("LDAPFieldPasswordExample").''; -print 'global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_PASSWORD?' checked="true"':'').">"; +print ' '; print ''; // Password crypted @@ -205,7 +212,7 @@ $var=!$var; print ''.$langs->trans("LDAPFieldPasswordCrypted").''; print ''; print ''.$langs->trans("LDAPFieldPasswordExample").''; -print 'global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_PASSWORD_CRYPTED?' checked="true"':'').">"; +print ' '; print ''; // Mail @@ -221,7 +228,7 @@ $var=!$var; print ''.$langs->trans("LDAPFieldPhone").''; print ''; print ''.$langs->trans("LDAPFieldPhoneExample").''; -print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_PHONE?' checked="true"':'').">"; +print ' '; print ''; // Phone perso @@ -229,7 +236,7 @@ $var=!$var; print ''.$langs->trans("LDAPFieldPhonePerso").''; print ''; print ''.$langs->trans("LDAPFieldPhonePersoExample").''; -print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_PHONEHOME?' checked="true"':'').">"; +print ' '; print ''; // Mobile @@ -237,7 +244,7 @@ $var=!$var; print ''.$langs->trans("LDAPFieldMobile").''; print ''; print ''.$langs->trans("LDAPFieldMobileExample").''; -print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_MOBILE?' checked="true"':'').">"; +print ' '; print ''; // Fax @@ -245,7 +252,7 @@ $var=!$var; print ''.$langs->trans("LDAPFieldFax").''; print ''; print ''.$langs->trans("LDAPFieldFaxExample").''; -print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_FAX?' checked="true"':'').">"; +print ' '; print ''; // Address @@ -253,7 +260,7 @@ $var=!$var; print ''.$langs->trans("LDAPFieldAddress").''; print ''; print ''.$langs->trans("LDAPFieldAddressExample").''; -print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_ADDRESS?' checked="true"':'').">"; +print ' '; print ''; // CP @@ -261,7 +268,7 @@ $var=!$var; print ''.$langs->trans("LDAPFieldZip").''; print ''; print ''.$langs->trans("LDAPFieldZipExample").''; -print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_ZIP?' checked="true"':'').">"; +print ' '; print ''; // Ville @@ -269,7 +276,7 @@ $var=!$var; print ''.$langs->trans("LDAPFieldTown").''; print ''; print ''.$langs->trans("LDAPFieldTownExample").''; -print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_TOWN?' checked="true"':'').">"; +print ' '; print ''; // Pays @@ -277,7 +284,7 @@ $var=!$var; print ''.$langs->trans("LDAPFieldCountry").''; print ''; print ''.$langs->trans("LDAPFieldCountryExample").''; -print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_COUNTRY?' checked="true"':'').">"; +print ' '; print ''; // Description @@ -285,7 +292,7 @@ $var=!$var; print ''.$langs->trans("LDAPFieldDescription").''; print ''; print ''.$langs->trans("LDAPFieldDescriptionExample").''; -print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_DESCRIPTION?' checked="true"':'').">"; +print ' '; print ''; // Date naissance @@ -293,7 +300,47 @@ $var=!$var; print ''.$langs->trans("LDAPFieldBirthdate").''; print ''; print ''.$langs->trans("LDAPFieldBirthdateExample").''; -print 'global->LDAP_KEY_MEMBERS==$conf->global->LDAP_FIELD_BIRTHDATE?' checked="true"':'').">"; +print ' '; +print ''; + +// Status +$var=!$var; +print ''.$langs->trans("LDAPFieldStatus").''; +print ''; +print ' '; +print ' '; +print ''; + +// First subscription date +$var=!$var; +print ''.$langs->trans("LDAPFieldFirstSubscriptionDate").''; +print ''; +print ' '; +print ' '; +print ''; + +// First subscription amount +$var=!$var; +print ''.$langs->trans("LDAPFieldFirstSubscriptionAmount").''; +print ''; +print ' '; +print ' '; +print ''; + +// Last subscription date +$var=!$var; +print ''.$langs->trans("LDAPFieldLastSubscriptionDate").''; +print ''; +print ' '; +print ' '; +print ''; + +// Last subscription amount +$var=!$var; +print ''.$langs->trans("LDAPFieldLastSubscriptionAmount").''; +print ''; +print ' '; +print ' '; print ''; $var=!$var; @@ -359,6 +406,10 @@ if (function_exists("ldap_connect")) print '
'; } + print "
\n"; + print "LDAP input file used for test:

\n"; + print nl2br($ldap->dump_content($dn,$info)); + print "\n
"; } } diff --git a/htdocs/langs/en_US/ldap.lang b/htdocs/langs/en_US/ldap.lang index 97c087ad216..b1efe366177 100644 --- a/htdocs/langs/en_US/ldap.lang +++ b/htdocs/langs/en_US/ldap.lang @@ -14,6 +14,11 @@ LDAPCard=LDAP card LDAPRecordNotFound=Record not found in LDAP database LDAPUsers=Users in LDAP database LDAPGroups=Groups in LDAP database +LDAPFieldStatus=Status +LDAPFieldFirstSubscriptionDate=First subscription date +LDAPFieldFirstSubscriptionAmount=Fist subscription amount +LDAPFieldLastSubscriptionDate=Last subscription date +LDAPFieldLastSubscriptionAmount=Last subscription amount SynchronizeDolibarr2Ldap=Synchronize user (Dolibarr -> LDAP) UserSynchronized=User synchronized ForceSynchronize=Force synchronizing Dolibarr -> LDAP diff --git a/htdocs/langs/fr_FR/ldap.lang b/htdocs/langs/fr_FR/ldap.lang index 9a7d72a763b..f0ab3533f6c 100644 --- a/htdocs/langs/fr_FR/ldap.lang +++ b/htdocs/langs/fr_FR/ldap.lang @@ -14,6 +14,11 @@ LDAPCard=Fiche LDAP LDAPRecordNotFound=Enregistrement non trouvé dans la base LDAP LDAPUsers=Utilisateurs en base LDAP LDAPGroups=Groupes en base LDAP +LDAPFieldStatus=Statut +LDAPFieldFirstSubscriptionDate=Date première adhésion +LDAPFieldFirstSubscriptionAmount=Montant première adhésion +LDAPFieldLastSubscriptionDate=Date dernière adhésion +LDAPFieldLastSubscriptionAmount=Montant dernière adhésion SynchronizeDolibarr2Ldap=Synchroniser utilisateur (Dolibarr -> LDAP) UserSynchronized=Utilisateur synchronisé ForceSynchronize=Forcer synchro Dolibarr -> LDAP diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php index 704c14138f6..8664acba176 100644 --- a/htdocs/lib/functions.inc.php +++ b/htdocs/lib/functions.inc.php @@ -491,7 +491,7 @@ function dolibarr_time_plus_duree($time,$duration_value,$duration_unit) "%d %b %Y", "%d/%m/%Y %H:%M", "%d/%m/%Y %H:%M:%S", - "day", "daytext", "dayhour", "dayhourtext" + "day", "daytext", "dayhour", "dayhourldap", "dayhourtext" \return string Date formatée ou '' si time null */ function dolibarr_print_date($time,$format='') @@ -504,6 +504,7 @@ function dolibarr_print_date($time,$format='') if ($format == 'day') $format=$conf->format_date_short; if ($format == 'daytext') $format=$conf->format_date_text_short; if ($format == 'dayhour') $format=$conf->format_date_hour_short; + if ($format == 'dayhourldap') $format='%Y%m%d%H%M%SZ'; if ($format == 'dayhourtext') $format=$conf->format_date_hour_text_short; // Si date non définie, on renvoie '' diff --git a/htdocs/lib/ldap.class.php b/htdocs/lib/ldap.class.php index 1cc23ce789b..355572498d0 100644 --- a/htdocs/lib/ldap.class.php +++ b/htdocs/lib/ldap.class.php @@ -652,48 +652,73 @@ class Ldap } + /* + * \brief Build a LDAP message + * \param dn DN entry key + * \param info Attributes array + * \return string Content of file + */ + function dump_content($dn, $info) + { + $content=''; + + // Create file content + if (ereg('^ldap',$this->server[0])) + { + $target="-H ".join(',',$this->server); + } + else + { + $target="-h ".join(',',$this->server)." -p ".$this->serverPort; + } + $content.="# ldapadd $target -c -v -D ".$this->searchUser." -W -f ldapinput.in\n"; + $content.="# ldapmodify $target -c -v -D ".$this->searchUser." -W -f ldapinput.in\n"; + $content.="# ldapdelete $target -c -v -D ".$this->searchUser." -W -f ldapinput.in\n"; + $content.="dn: ".$dn."\n"; + foreach($info as $key => $value) + { + if (! is_array($value)) + { + $content.="$key: $value\n"; + } + else + { + foreach($value as $valuekey => $valuevalue) + { + $content.="$key: $valuevalue\n"; + } + } + } + return $content; + } + /* * \brief Dump a LDAP message to ldapinput.in file * \param dn DN entry key * \param info Attributes array - * \return int <0 si KO, >0 si OK + * \return int <0 if KO, >0 if OK */ function dump($dn, $info) { global $conf; - create_exdir($conf->ldap->dir_temp); + + // Create content + $content=$this->dump_content($dn, $info); + + //Create file + $result=create_exdir($conf->ldap->dir_temp); $file=$conf->ldap->dir_temp.'/ldapinput.in'; $fp=fopen($file,"w"); if ($fp) { - if (ereg('^ldap',$this->server[0])) - { - $target="-H ".join(',',$this->server); - } - else - { - $target="-h ".join(',',$this->server)." -p ".$this->serverPort; - } - fputs($fp,"# ldapadd $target -c -v -D ".$this->searchUser." -W -f ldapinput.in\n"); - fputs($fp,"# ldapmodify $target -c -v -D ".$this->searchUser." -W -f ldapinput.in\n"); - fputs($fp,"# ldapdelete $target -c -v -D ".$this->searchUser." -W -f ldapinput.in\n"); - fputs($fp, "dn: ".$dn."\n"); - foreach($info as $key => $value) - { - if (! is_array($value)) - { - fputs($fp, "$key: $value\n"); - } - else - { - foreach($value as $valuekey => $valuevalue) - { - fputs($fp, "$key: $valuevalue\n"); - } - } - } + fputs($fp, $content); fclose($fp); + return 1; + } + else + { + return -1; } }