This commit is contained in:
Frédéric FRANCE 2020-11-27 00:25:45 +01:00
parent bb09c84417
commit fa6d02fb3f
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1

View File

@ -141,11 +141,19 @@ class AdvanceTargetingMailing extends CommonObject
$error = 0; $error = 0;
// Clean parameters // Clean parameters
if (isset($this->fk_element)) $this->fk_element = (int) $this->fk_element; if (isset($this->fk_element)) {
if (isset($this->type_element)) $this->type_element = trim($this->type_element); $this->fk_element = (int) $this->fk_element;
}
if (isset($this->type_element)) {
$this->type_element = trim($this->type_element);
}
if (isset($this->name)) $this->name = trim($this->name); if (isset($this->name)) {
if (isset($this->filtervalue)) $this->filtervalue = trim($this->filtervalue); $this->name = trim($this->name);
}
if (isset($this->filtervalue)) {
$this->filtervalue = trim($this->filtervalue);
}
// Check parameters // Check parameters
// Put here code to add control on parameters values // Put here code to add control on parameters values
@ -175,18 +183,17 @@ class AdvanceTargetingMailing extends CommonObject
dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
if (!$error) if (!$error) {
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."advtargetemailing"); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."advtargetemailing");
} }
// Commit or rollback // Commit or rollback
if ($error) if ($error) {
{ foreach ($this->errors as $errmsg) {
foreach ($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg); $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
} }
@ -225,10 +232,8 @@ class AdvanceTargetingMailing extends CommonObject
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql) {
{ if ($this->db->num_rows($resql)) {
if ($this->db->num_rows($resql))
{
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid; $this->id = $obj->rowid;
@ -286,10 +291,8 @@ class AdvanceTargetingMailing extends CommonObject
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql) {
{ if ($this->db->num_rows($resql)) {
if ($this->db->num_rows($resql))
{
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid; $this->id = $obj->rowid;
@ -351,10 +354,8 @@ class AdvanceTargetingMailing extends CommonObject
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql) {
{ if ($this->db->num_rows($resql)) {
if ($this->db->num_rows($resql))
{
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid; $this->id = $obj->rowid;
@ -392,10 +393,18 @@ class AdvanceTargetingMailing extends CommonObject
$error = 0; $error = 0;
// Clean parameters // Clean parameters
if (isset($this->fk_element)) $this->fk_element = (int) $this->fk_element; if (isset($this->fk_element)) {
if (isset($this->type_element)) $this->type_element = trim($this->type_element); $this->fk_element = (int) $this->fk_element;
if (isset($this->name)) $this->name = trim($this->name); }
if (isset($this->filtervalue)) $this->filtervalue = trim($this->filtervalue); if (isset($this->type_element)) {
$this->type_element = trim($this->type_element);
}
if (isset($this->name)) {
$this->name = trim($this->name);
}
if (isset($this->filtervalue)) {
$this->filtervalue = trim($this->filtervalue);
}
// Check parameters // Check parameters
// Put here code to add a control on parameters values // Put here code to add a control on parameters values
@ -421,10 +430,8 @@ class AdvanceTargetingMailing extends CommonObject
} }
// Commit or rollback // Commit or rollback
if ($error) if ($error) {
{ foreach ($this->errors as $errmsg) {
foreach ($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg); $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
} }
@ -450,21 +457,20 @@ class AdvanceTargetingMailing extends CommonObject
$this->db->begin(); $this->db->begin();
if (!$error) if (!$error) {
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."advtargetemailing"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."advtargetemailing";
$sql .= " WHERE rowid=".$this->id; $sql .= " WHERE rowid=".$this->id;
dol_syslog(get_class($this)."::delete sql=".$sql); dol_syslog(get_class($this)."::delete sql=".$sql);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
} }
// Commit or rollback // Commit or rollback
if ($error) if ($error) {
{ foreach ($this->errors as $errmsg) {
foreach ($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg); $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
} }
@ -620,7 +626,9 @@ class AdvanceTargetingMailing extends CommonObject
} }
} }
if (count($sqlwhere) > 0) $sql .= " WHERE ".implode(" AND ", $sqlwhere); if (count($sqlwhere) > 0) {
$sql .= " WHERE ".implode(" AND ", $sqlwhere);
}
} }
@ -631,10 +639,8 @@ class AdvanceTargetingMailing extends CommonObject
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
$i = 0; $i = 0;
if ($num) if ($num) {
{ while ($i < $num) {
while ($i < $num)
{
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->thirdparty_lines[$i] = $obj->rowid; $this->thirdparty_lines[$i] = $obj->rowid;
@ -701,8 +707,7 @@ class AdvanceTargetingMailing extends CommonObject
} }
if ($arrayquery['contact_no_email'] != '') { if ($arrayquery['contact_no_email'] != '') {
$tmpwhere = ''; $tmpwhere = '';
if (!empty($arrayquery['contact_no_email'])) if (!empty($arrayquery['contact_no_email'])) {
{
$tmpwhere .= "(t.email IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE t.entity IN (".getEntity('mailing').") AND email = '".$this->db->escape($arrayquery['contact_no_email'])."'))"; $tmpwhere .= "(t.email IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE t.entity IN (".getEntity('mailing').") AND email = '".$this->db->escape($arrayquery['contact_no_email'])."'))";
} else { } else {
$tmpwhere .= "(t.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE t.entity IN (".getEntity('mailing').") AND email = '".$this->db->escape($arrayquery['contact_no_email'])."'))"; $tmpwhere .= "(t.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE t.entity IN (".getEntity('mailing').") AND email = '".$this->db->escape($arrayquery['contact_no_email'])."'))";
@ -864,7 +869,9 @@ class AdvanceTargetingMailing extends CommonObject
} }
} }
} }
if (count($sqlwhere) > 0) $sql .= " WHERE ".implode(" AND ", $sqlwhere); if (count($sqlwhere) > 0) {
$sql .= " WHERE ".implode(" AND ", $sqlwhere);
}
} }
dol_syslog(get_class($this)."::query_contact sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::query_contact sql=".$sql, LOG_DEBUG);
@ -874,10 +881,8 @@ class AdvanceTargetingMailing extends CommonObject
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
$i = 0; $i = 0;
if ($num) if ($num) {
{ while ($i < $num) {
while ($i < $num)
{
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->contact_lines[$i] = $obj->rowid; $this->contact_lines[$i] = $obj->rowid;