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_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

View File

@ -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."<BR>\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."<BR>\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."<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='';
}
// 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."<BR>\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."<BR>\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."<BR>\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."<BR>\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."<BR>\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."<BR>\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."<BR>\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."<BR>\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."<BR>\n";
}
}
}

View File

@ -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')