diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index d42f67f075a..351debdd3d4 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -1303,11 +1303,6 @@ class Adherent extends CommonObject $this->last_subscription_amount=$montant; $this->last_subscription_date_start=$date; $this->last_subscription_date_end=$datefin; - - // Call trigger - $result=$this->call_trigger('MEMBER_SUBSCRIPTION',$user); - if ($result < 0) { $error++; } - // End call triggers } if (! $error) diff --git a/htdocs/adherents/class/subscription.class.php b/htdocs/adherents/class/subscription.class.php index bb5780db15a..ae8470e3eee 100644 --- a/htdocs/adherents/class/subscription.class.php +++ b/htdocs/adherents/class/subscription.class.php @@ -59,13 +59,16 @@ class Subscription extends CommonObject /** * Function who permitted cretaion of the subscription * - * @param int $userid userid de celui qui insere - * @return int <0 if KO, Id subscription created if OK + * @param User $user User that create + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @return int <0 if KO, Id subscription created if OK */ - function create($userid) + function create($user, $notrigger = false) { global $langs; + $error = 0; + $now=dol_now(); // Check parameters @@ -75,6 +78,8 @@ class Subscription extends CommonObject return -1; } + $this->db->begin(); + $sql = "INSERT INTO ".MAIN_DB_PREFIX."subscription (fk_adherent, datec, dateadh, datef, subscription, note)"; $sql.= " VALUES (".$this->fk_adherent.", '".$this->db->idate($now)."',"; $sql.= " '".$this->db->idate($this->dateh)."',"; @@ -82,17 +87,32 @@ class Subscription extends CommonObject $sql.= " ".$this->amount.","; $sql.= " '".$this->db->escape($this->note)."')"; - dol_syslog(get_class($this)."::create", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."subscription"); - return $this->id; + if ($res===false) { + $error++; + $this->errors[] = $this->db->lasterror(); } - else + + if (! $error) { - $this->error=$this->db->lasterror(); + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); + } + + if (! $error && ! $notrigger) + { + // Call triggers + $result=$this->call_trigger('MEMBER_SUBSCRIPTION_CREATE',$user); + if ($result < 0) { $error++; } + // End call triggers + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); return -1; + } else { + $this->db->commit(); + return $this->id; } } @@ -154,8 +174,10 @@ class Subscription extends CommonObject * @param int $notrigger 0=Disable triggers * @return int <0 if KO, >0 if OK */ - function update($user,$notrigger=0) + function update($user, $notrigger=0) { + $error = 0; + $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."subscription SET "; @@ -177,14 +199,26 @@ class Subscription extends CommonObject $result=$member->fetch($this->fk_adherent); $result=$member->update_end_date($user); - $this->db->commit(); - return 1; + if (! $error && ! $notrigger) { + // Call triggers + $result=$this->call_trigger('MEMBER_SUBSCRIPTION_MODIFY',$user); + if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail + // End call triggers + } } else { - $this->db->rollback(); + $error++; $this->error=$this->db->lasterror(); + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); return -1; + } else { + $this->db->commit(); + return $this->id; } } @@ -192,10 +226,13 @@ class Subscription extends CommonObject * Delete a subscription * * @param User $user User that delete + * @param bool $notrigger false=launch triggers after, true=disable triggers * @return int <0 if KO, 0 if not found, >0 if OK */ - function delete($user) + function delete($user, $notrigger=false) { + $error = 0; + // It subscription is linked to a bank transaction, we get it if ($this->fk_bank > 0) { @@ -206,51 +243,71 @@ class Subscription extends CommonObject $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."subscription WHERE rowid = ".$this->id; - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $num=$this->db->affected_rows($resql); - if ($num) - { - require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; - $member=new Adherent($this->db); - $result=$member->fetch($this->fk_adherent); - $result=$member->update_end_date($user); + if (! $error) { + if (! $notrigger) { + // Call triggers + $result=$this->call_trigger('MEMBER_SUBSCRIPTION_DELETE', $user); + if ($result < 0) { $error++; } // Do also here what you must do to rollback action if trigger fail + // End call triggers + } + } - if ($this->fk_bank > 0 && is_object($accountline) && $accountline->id > 0) // If we found bank account line (this means this->fk_bank defined) + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."subscription WHERE rowid = ".$this->id; + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $num=$this->db->affected_rows($resql); + if ($num) { - $result=$accountline->delete($user); // Return false if refused because line is conciliated - if ($result > 0) + require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; + $member=new Adherent($this->db); + $result=$member->fetch($this->fk_adherent); + $result=$member->update_end_date($user); + + if ($this->fk_bank > 0 && is_object($accountline) && $accountline->id > 0) // If we found bank account line (this means this->fk_bank defined) { - $this->db->commit(); - return 1; + $result=$accountline->delete($user); // Return false if refused because line is conciliated + if ($result > 0) + { + $this->db->commit(); + return 1; + } + else + { + $this->error=$accountline->error; + $this->db->rollback(); + return -1; + } } else { - $this->error=$accountline->error; - $this->db->rollback(); - return -1; + $this->db->commit(); + return 1; } } else { $this->db->commit(); - return 1; + return 0; } } else { - $this->db->commit(); - return 0; + $error++; + $this->error=$this->db->lasterror(); } } - else - { - $this->error=$this->db->lasterror(); + + // Commit or rollback + if ($error) { $this->db->rollback(); return -1; + } else { + $this->db->commit(); + return 1; } } diff --git a/htdocs/blockedlog/admin/blockedlog.php b/htdocs/blockedlog/admin/blockedlog.php index 5e34cb968ae..2da83de5da2 100644 --- a/htdocs/blockedlog/admin/blockedlog.php +++ b/htdocs/blockedlog/admin/blockedlog.php @@ -26,9 +26,7 @@ require_once DOL_DOCUMENT_ROOT.'/blockedlog/lib/blockedlog.lib.php'; require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; -$langs->load("admin"); -$langs->load("other"); -$langs->load("blockedlog"); +$langs->loadLangs(array("admin","other","blockedlog")); if (! $user->admin || empty($conf->blockedlog->enabled)) accessforbidden(); @@ -143,7 +141,7 @@ if ($resql) { while ($obj = $db->fetch_object($resql)) { - $countryArray[$obj->code_iso] = ($obj->code_iso && $langs->transnoentitiesnoconv("Country".$obj->code_iso)!="Country".$obj->code_iso?$langs->transnoentitiesnoconv("Country".$obj->code_iso):($obj->label!='-'?$obj->label:'')); + $countryArray[$obj->code_iso] = ($obj->code_iso && $langs->transnoentitiesnoconv("Country".$obj->code_iso)!="Country".$obj->code_iso?$langs->transnoentitiesnoconv("Country".$obj->code_iso):($obj->label!='-'?$obj->label:'')); } } @@ -162,7 +160,7 @@ print $langs->trans("ListOfTrackedEvents").'