Fix: Gestion erreur et mauvais declenchement triggers synchro adherent

This commit is contained in:
Laurent Destailleur 2007-05-02 22:31:51 +00:00
parent b190933fae
commit 3c7720ceea
3 changed files with 177 additions and 80 deletions

View File

@ -87,7 +87,7 @@ class Adherent
var $user_id; var $user_id;
var $user_login; var $user_login;
// Fiels loaded by fetch_subscriptions() // Fields loaded by fetch_subscriptions()
var $fistsubscription_date; var $fistsubscription_date;
var $fistsubscription_amount; var $fistsubscription_amount;
var $lastsubscription_date; var $lastsubscription_date;
@ -515,14 +515,16 @@ class Adherent
/** /**
\brief Fonction qui supprime l'adhérent et les données associées \brief Fonction qui supprime l'adhérent et les données associées
\param rowid \param rowid Id de l'adherent a effacer
\return int <0 si KO, 0 = rien a effacer, >0 si OK \return int <0 si KO, 0=rien a effacer, >0 si OK
*/ */
function delete($rowid) function delete($rowid)
{ {
global $conf, $langs; global $conf, $langs;
$result = 0; $result = 0;
$this->db->begin();
// Suppression options // Suppression options
$sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options WHERE adhid = ".$rowid; $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_id = $obj->user_id;
$this->user_login = $obj->user_login; $this->user_login = $obj->user_login;
// Charge autres propriétés
$result=$this->fetch_subscriptions();
return $result;
}
else
{
return -1;
} }
return 1;
} }
else else
{ {
@ -1005,7 +1015,7 @@ class Adherent
/** /**
* \brief Fonction qui vérifie que l'utilisateur est valide * \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 * \return int <0 si ko, >0 si ok
*/ */
function validate($user) function validate($user)
@ -1021,6 +1031,8 @@ class Adherent
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
$this->statut=1;
$this->use_webcal=($conf->global->PHPWEBCALENDAR_MEMBERSTATUS=='always'?1:0); $this->use_webcal=($conf->global->PHPWEBCALENDAR_MEMBERSTATUS=='always'?1:0);
// Appel des triggers // Appel des triggers
@ -1044,10 +1056,10 @@ class Adherent
/** /**
* \brief Fonction qui résilie un adhérent * \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 * \return int <0 si ko, >0 si ok
*/ */
function resiliate($userid) function resiliate($user)
{ {
global $user,$langs,$conf; global $user,$langs,$conf;
@ -1055,12 +1067,14 @@ class Adherent
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET "; $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET ";
$sql .= "statut=0"; $sql .= "statut=0";
$sql .= ",fk_user_valid=".$userid; $sql .= ",fk_user_valid=".$user->id;
$sql .= " WHERE rowid = ".$this->id; $sql .= " WHERE rowid = ".$this->id;
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
$this->statut=0;
$this->use_webcal=($conf->global->PHPWEBCALENDAR_MEMBERSTATUS=='always'?1:0); $this->use_webcal=($conf->global->PHPWEBCALENDAR_MEMBERSTATUS=='always'?1:0);
// Appel des triggers // Appel des triggers

View File

@ -108,7 +108,6 @@ if ($_REQUEST["action"] == 'update' && ! $_POST["cancel"])
// Charge objet actuel // Charge objet actuel
$result=$adh->fetch($_POST["rowid"]); $result=$adh->fetch($_POST["rowid"]);
$result=$adh->fetch_subscriptions($_POST["rowid"]);
if ($result > 0) if ($result > 0)
{ {
// Modifie valeures // Modifie valeures
@ -353,6 +352,7 @@ if ($_POST["action"] == 'add')
if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes')
{ {
$result=$adh->fetch($rowid);
$result=$adh->delete($rowid); $result=$adh->delete($rowid);
if ($result > 0) if ($result > 0)
{ {
@ -368,34 +368,14 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes')
if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes') if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes')
{ {
$adh->id=$rowid; $result=$adh->fetch($rowid);
$adh->fetch($rowid); $result=$adh->validate($user);
$adht = new AdherentType($db); $adht = new AdherentType($db);
$adht->fetch($adh->typeid); $adht->fetch($adh->typeid);
$result=$adh->validate($user);
if ($result >= 0 && ! sizeof($adh->errors)) if ($result >= 0 && ! sizeof($adh->errors))
{ {
}
else
{
if ($adh->error)
{
$errmsg=$adh->error;
}
else
{
foreach($adh->errors as $error)
{
if ($errmsg) $errmsg.='<br>';
$errmsg.=$error;
}
}
$action='';
}
// Envoi mail validation (selon param du type adherent sinon generique) // Envoi mail validation (selon param du type adherent sinon generique)
if ($adh->email) if ($adh->email)
{ {
@ -417,20 +397,38 @@ if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes')
if ($adh->add_to_abo($adht) < 0) if ($adh->add_to_abo($adht) < 0)
{ {
// error // error
$errmsg.="Echec du rajout de l'utilisateur aux abonnements: ".$adh->error."<BR>\n"; $errmsg.="Echec du rajout de l'utilisateur aux abonnements mailman: ".$adh->error."<BR>\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.='<br>';
$errmsg.=$error;
}
}
$action='';
} }
} }
if ($_POST["action"] == 'confirm_resign' && $_POST["confirm"] == 'yes') if ($_POST["action"] == 'confirm_resign' && $_POST["confirm"] == 'yes')
{ {
$adh->id=$rowid; $result=$adh->fetch($rowid);
$adh->resiliate($user->id); $result=$adh->resiliate($user);
$adh->fetch($rowid);
$adht = new AdherentType($db); $adht = new AdherentType($db);
$adht->fetch($adh->typeid); $adht->fetch($adh->typeid);
if ($result >= 0 && ! sizeof($adh->errors))
{
if ($adh->email) if ($adh->email)
{ {
$result=$adh->send_an_email($adh->email,$conf->adherent->email_resil,$conf->adherent->email_resil_subject); $result=$adh->send_an_email($adh->email,$conf->adherent->email_resil,$conf->adherent->email_resil_subject);
@ -440,16 +438,35 @@ if ($_POST["action"] == 'confirm_resign' && $_POST["confirm"] == 'yes')
if (! $adh->del_to_abo($adht)) if (! $adh->del_to_abo($adht))
{ {
// error // error
$errmsg.="echec de la suppression de l'utilisateur aux abonnements: ".$adh->error."<BR>\n"; $errmsg.="Echec de la suppression de l'utilisateur aux abonnements mailman: ".$adh->error."<BR>\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.='<br>';
$errmsg.=$error;
}
}
$action='';
} }
} }
if ($_POST["action"] == 'confirm_add_glasnost' && $_POST["confirm"] == 'yes') if ($_POST["action"] == 'confirm_add_glasnost' && $_POST["confirm"] == 'yes')
{ {
$adh->id=$rowid; $result=$adh->fetch($rowid);
$adh->fetch($rowid);
$adht = new AdherentType($db); $adht = new AdherentType($db);
$adht->fetch($adh->typeid); $adht->fetch($adh->typeid);
if ($result >= 0 && ! sizeof($adh->errors))
{
if ($adht->vote == 'yes'){ if ($adht->vote == 'yes'){
define("XMLRPC_DEBUG", 1); define("XMLRPC_DEBUG", 1);
if (!$adh->add_to_glasnost()){ if (!$adh->add_to_glasnost()){
@ -457,14 +474,16 @@ if ($_POST["action"] == 'confirm_add_glasnost' && $_POST["confirm"] == 'yes')
} }
XMLRPC_debug_print(); XMLRPC_debug_print();
} }
}
} }
if ($_POST["action"] == 'confirm_del_glasnost' && $_POST["confirm"] == 'yes') if ($_POST["action"] == 'confirm_del_glasnost' && $_POST["confirm"] == 'yes')
{ {
$adh->id=$rowid; $result=$adh->fetch($rowid);
$adh->fetch($rowid);
$adht = new AdherentType($db); $adht = new AdherentType($db);
$adht->fetch($adh->typeid); $adht->fetch($adh->typeid);
if ($result >= 0 && ! sizeof($adh->errors))
{
if ($adht->vote == 'yes'){ if ($adht->vote == 'yes'){
define("XMLRPC_DEBUG", 1); define("XMLRPC_DEBUG", 1);
if(!$adh->del_to_glasnost()){ if(!$adh->del_to_glasnost()){
@ -472,25 +491,30 @@ if ($_POST["action"] == 'confirm_del_glasnost' && $_POST["confirm"] == 'yes')
} }
XMLRPC_debug_print(); XMLRPC_debug_print();
} }
}
} }
if ($_POST["action"] == 'confirm_del_spip' && $_POST["confirm"] == 'yes') if ($_POST["action"] == 'confirm_del_spip' && $_POST["confirm"] == 'yes')
{ {
$adh->id=$rowid; $result=$adh->fetch($rowid);
$adh->fetch($rowid); if ($result >= 0 && ! sizeof($adh->errors))
{
if(!$adh->del_to_spip()){ if(!$adh->del_to_spip()){
$errmsg.="Echec de la suppression de l'utilisateur dans spip: ".$adh->error."<BR>\n"; $errmsg.="Echec de la suppression de l'utilisateur dans spip: ".$adh->error."<BR>\n";
} }
}
} }
if ($_POST["action"] == 'confirm_add_spip' && $_POST["confirm"] == 'yes') if ($_POST["action"] == 'confirm_add_spip' && $_POST["confirm"] == 'yes')
{ {
$adh->id=$rowid; $result=$adh->fetch($rowid);
$adh->fetch($rowid); if ($result >= 0 && ! sizeof($adh->errors))
{
if (!$adh->add_to_spip()) if (!$adh->add_to_spip())
{ {
$errmsg.="Echec du rajout de l'utilisateur dans spip: ".$adh->error."<BR>\n"; $errmsg.="Echec du rajout de l'utilisateur dans spip: ".$adh->error."<BR>\n";
} }
}
} }

View File

@ -280,6 +280,19 @@ class InterfaceLdap
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE) 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') elseif ($action == 'MEMBER_SUBSCRIPTION')
@ -287,6 +300,23 @@ class InterfaceLdap
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE) 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') elseif ($action == 'MEMBER_MODIFY')
@ -308,12 +338,41 @@ class InterfaceLdap
elseif ($action == 'MEMBER_NEW_PASSWORD') elseif ($action == 'MEMBER_NEW_PASSWORD')
{ {
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); 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') elseif ($action == 'MEMBER_RESILIATE')
{ {
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE) 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') elseif ($action == 'MEMBER_DELETE')