From 3c7720ceea1f6c4a45d8afd3c306ee0c04ace6c8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 2 May 2007 22:31:51 +0000 Subject: [PATCH] Fix: Gestion erreur et mauvais declenchement triggers synchro adherent --- htdocs/adherents/adherent.class.php | 32 +++- htdocs/adherents/fiche.php | 164 ++++++++++-------- .../triggers/interface_ldap.class.php | 61 ++++++- 3 files changed, 177 insertions(+), 80 deletions(-) diff --git a/htdocs/adherents/adherent.class.php b/htdocs/adherents/adherent.class.php index f197dbc3a53..81988cdc330 100644 --- a/htdocs/adherents/adherent.class.php +++ b/htdocs/adherents/adherent.class.php @@ -87,7 +87,7 @@ class Adherent var $user_id; var $user_login; - // Fiels loaded by fetch_subscriptions() + // Fields loaded by fetch_subscriptions() var $fistsubscription_date; var $fistsubscription_amount; var $lastsubscription_date; @@ -515,14 +515,16 @@ class Adherent /** \brief Fonction qui supprime l'adhérent et les données associées - \param rowid - \return int <0 si KO, 0 = rien a effacer, >0 si OK + \param rowid Id de l'adherent a effacer + \return int <0 si KO, 0=rien a effacer, >0 si OK */ function delete($rowid) { global $conf, $langs; $result = 0; + $this->db->begin(); + // Suppression options $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options WHERE adhid = ".$rowid; @@ -751,8 +753,16 @@ class Adherent $this->user_id = $obj->user_id; $this->user_login = $obj->user_login; + + // Charge autres propriétés + $result=$this->fetch_subscriptions(); + + return $result; } - return 1; + else + { + return -1; + } } else { @@ -1005,7 +1015,7 @@ class Adherent /** * \brief Fonction qui vérifie que l'utilisateur est valide - * \param userid userid adhérent à valider + * \param user user adhérent qui valide * \return int <0 si ko, >0 si ok */ function validate($user) @@ -1021,8 +1031,10 @@ class Adherent $result = $this->db->query($sql); if ($result) { - $this->use_webcal=($conf->global->PHPWEBCALENDAR_MEMBERSTATUS=='always'?1:0); + $this->statut=1; + $this->use_webcal=($conf->global->PHPWEBCALENDAR_MEMBERSTATUS=='always'?1:0); + // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); $interface=new Interfaces($this->db); @@ -1044,10 +1056,10 @@ class Adherent /** * \brief Fonction qui résilie un adhérent - * \param userid userid adhérent à résilier + * \param user user adhérent qui résilie * \return int <0 si ko, >0 si ok */ - function resiliate($userid) + function resiliate($user) { global $user,$langs,$conf; @@ -1055,12 +1067,14 @@ class Adherent $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET "; $sql .= "statut=0"; - $sql .= ",fk_user_valid=".$userid; + $sql .= ",fk_user_valid=".$user->id; $sql .= " WHERE rowid = ".$this->id; $result = $this->db->query($sql); if ($result) { + $this->statut=0; + $this->use_webcal=($conf->global->PHPWEBCALENDAR_MEMBERSTATUS=='always'?1:0); // Appel des triggers diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index 68618d2ef51..632b192faba 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -108,7 +108,6 @@ if ($_REQUEST["action"] == 'update' && ! $_POST["cancel"]) // Charge objet actuel $result=$adh->fetch($_POST["rowid"]); - $result=$adh->fetch_subscriptions($_POST["rowid"]); if ($result > 0) { // Modifie valeures @@ -353,6 +352,7 @@ if ($_POST["action"] == 'add') if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') { + $result=$adh->fetch($rowid); $result=$adh->delete($rowid); if ($result > 0) { @@ -368,19 +368,41 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes') { - $adh->id=$rowid; - $adh->fetch($rowid); + $result=$adh->fetch($rowid); + $result=$adh->validate($user); $adht = new AdherentType($db); $adht->fetch($adh->typeid); - $result=$adh->validate($user); if ($result >= 0 && ! sizeof($adh->errors)) { + // Envoi mail validation (selon param du type adherent sinon generique) + if ($adh->email) + { + if (isset($adht->mail_valid) && $adht->mail_valid) + { + $result=$adh->send_an_email($adh->email,$adht->mail_valid,$conf->adherent->email_valid_subject); + } + else + { + $result=$adh->send_an_email($adh->email,$conf->global->ADHERENT_MAIL_VALID,$conf->global->ADHERENT_MAIL_VALID_SUBJECT); + } + if ($result < 0) + { + $errmsg.=$adh->error; + } + } + // Rajoute l'utilisateur dans les divers abonnements (mailman, spip, etc...) + if ($adh->add_to_abo($adht) < 0) + { + // error + $errmsg.="Echec du rajout de l'utilisateur aux abonnements mailman: ".$adh->error."
\n"; + } } else { + // \TODO Mettre fonction qui fabrique errmsg depuis this->error||this->errors if ($adh->error) { $errmsg=$adh->error; @@ -395,102 +417,104 @@ if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes') } $action=''; } - - // Envoi mail validation (selon param du type adherent sinon generique) - if ($adh->email) - { - if (isset($adht->mail_valid) && $adht->mail_valid) - { - $result=$adh->send_an_email($adh->email,$adht->mail_valid,$conf->adherent->email_valid_subject); - } - else - { - $result=$adh->send_an_email($adh->email,$conf->global->ADHERENT_MAIL_VALID,$conf->global->ADHERENT_MAIL_VALID_SUBJECT); - } - if ($result < 0) - { - $errmsg.=$adh->error; - } - } - - // Rajoute l'utilisateur dans les divers abonnements (mailman, spip, etc...) - if ($adh->add_to_abo($adht) < 0) - { - // error - $errmsg.="Echec du rajout de l'utilisateur aux abonnements: ".$adh->error."
\n"; - } - } if ($_POST["action"] == 'confirm_resign' && $_POST["confirm"] == 'yes') { - $adh->id=$rowid; - $adh->resiliate($user->id); - $adh->fetch($rowid); + $result=$adh->fetch($rowid); + $result=$adh->resiliate($user); $adht = new AdherentType($db); $adht->fetch($adh->typeid); - if ($adh->email) + if ($result >= 0 && ! sizeof($adh->errors)) { - $result=$adh->send_an_email($adh->email,$conf->adherent->email_resil,$conf->adherent->email_resil_subject); + if ($adh->email) + { + $result=$adh->send_an_email($adh->email,$conf->adherent->email_resil,$conf->adherent->email_resil_subject); + } + + // supprime l'utilisateur des divers abonnements .. + if (! $adh->del_to_abo($adht)) + { + // error + $errmsg.="Echec de la suppression de l'utilisateur aux abonnements mailman: ".$adh->error."
\n"; + } + } + else + { + // \TODO Mettre fonction qui fabrique errmsg depuis this->error||this->errors + if ($adh->error) + { + $errmsg=$adh->error; + } + else + { + foreach($adh->errors as $error) + { + if ($errmsg) $errmsg.='
'; + $errmsg.=$error; + } + } + $action=''; } - - // supprime l'utilisateur des divers abonnements .. - if (! $adh->del_to_abo($adht)) - { - // error - $errmsg.="echec de la suppression de l'utilisateur aux abonnements: ".$adh->error."
\n"; - } } if ($_POST["action"] == 'confirm_add_glasnost' && $_POST["confirm"] == 'yes') { - $adh->id=$rowid; - $adh->fetch($rowid); + $result=$adh->fetch($rowid); $adht = new AdherentType($db); $adht->fetch($adh->typeid); - if ($adht->vote == 'yes'){ - define("XMLRPC_DEBUG", 1); - if (!$adh->add_to_glasnost()){ - $errmsg.="Echec du rajout de l'utilisateur dans glasnost: ".$adh->error."
\n"; - } - XMLRPC_debug_print(); - } + if ($result >= 0 && ! sizeof($adh->errors)) + { + if ($adht->vote == 'yes'){ + define("XMLRPC_DEBUG", 1); + if (!$adh->add_to_glasnost()){ + $errmsg.="Echec du rajout de l'utilisateur dans glasnost: ".$adh->error."
\n"; + } + XMLRPC_debug_print(); + } + } } if ($_POST["action"] == 'confirm_del_glasnost' && $_POST["confirm"] == 'yes') { - $adh->id=$rowid; - $adh->fetch($rowid); + $result=$adh->fetch($rowid); $adht = new AdherentType($db); $adht->fetch($adh->typeid); - if ($adht->vote == 'yes'){ - define("XMLRPC_DEBUG", 1); - if(!$adh->del_to_glasnost()){ - $errmsg.="Echec de la suppression de l'utilisateur dans glasnost: ".$adh->error."
\n"; - } - XMLRPC_debug_print(); - } + if ($result >= 0 && ! sizeof($adh->errors)) + { + if ($adht->vote == 'yes'){ + define("XMLRPC_DEBUG", 1); + if(!$adh->del_to_glasnost()){ + $errmsg.="Echec de la suppression de l'utilisateur dans glasnost: ".$adh->error."
\n"; + } + XMLRPC_debug_print(); + } + } } if ($_POST["action"] == 'confirm_del_spip' && $_POST["confirm"] == 'yes') { - $adh->id=$rowid; - $adh->fetch($rowid); - if(!$adh->del_to_spip()){ - $errmsg.="Echec de la suppression de l'utilisateur dans spip: ".$adh->error."
\n"; - } + $result=$adh->fetch($rowid); + if ($result >= 0 && ! sizeof($adh->errors)) + { + if(!$adh->del_to_spip()){ + $errmsg.="Echec de la suppression de l'utilisateur dans spip: ".$adh->error."
\n"; + } + } } if ($_POST["action"] == 'confirm_add_spip' && $_POST["confirm"] == 'yes') { - $adh->id=$rowid; - $adh->fetch($rowid); - if (!$adh->add_to_spip()) - { - $errmsg.="Echec du rajout de l'utilisateur dans spip: ".$adh->error."
\n"; - } + $result=$adh->fetch($rowid); + if ($result >= 0 && ! sizeof($adh->errors)) + { + if (!$adh->add_to_spip()) + { + $errmsg.="Echec du rajout de l'utilisateur dans spip: ".$adh->error."
\n"; + } + } } diff --git a/htdocs/includes/triggers/interface_ldap.class.php b/htdocs/includes/triggers/interface_ldap.class.php index 79a43cb7968..32d88b61399 100644 --- a/htdocs/includes/triggers/interface_ldap.class.php +++ b/htdocs/includes/triggers/interface_ldap.class.php @@ -280,6 +280,19 @@ class InterfaceLdap dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE) { + # If status field is setup to be synchronized + if ($conf->global->LDAP_FIELD_MEMBER_STATUS) + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + $result=$ldap->update($dn,$info,$user); + if ($result < 0) $this->error=$langs->trans("ErrorLDAP")." ".$ldap->error; + return $result; + } } } elseif ($action == 'MEMBER_SUBSCRIPTION') @@ -287,6 +300,23 @@ class InterfaceLdap dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE) { + # If subscriptions fields are setup to be synchronized + if ($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE + || $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT + || $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE + || $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT + || $conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION) + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + $result=$ldap->update($dn,$info,$user); + if ($result < 0) $this->error=$langs->trans("ErrorLDAP")." ".$ldap->error; + return $result; + } } } elseif ($action == 'MEMBER_MODIFY') @@ -308,12 +338,41 @@ class InterfaceLdap elseif ($action == 'MEMBER_NEW_PASSWORD') { dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } + if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE) + { + # If password field is setup to be synchronized + if ($conf->global->LDAP_FIELD_PASSWORD || $conf->global->LDAP_FIELD_PASSWORD_CRYPTED) + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + $result=$ldap->update($dn,$info,$user); + if ($result < 0) $this->error=$langs->trans("ErrorLDAP")." ".$ldap->error; + return $result; + } + } + } elseif ($action == 'MEMBER_RESILIATE') { dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE) { + # If status field is setup to be synchronized + if ($conf->global->LDAP_FIELD_MEMBER_STATUS) + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + $result=$ldap->update($dn,$info,$user); + if ($result < 0) $this->error=$langs->trans("ErrorLDAP")." ".$ldap->error; + return $result; + } } } elseif ($action == 'MEMBER_DELETE')