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

@ -1,20 +1,20 @@
<?php
/* Advance Targeting Emailling for mass emailing module
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file comm/mailing/class/advtargetemailing.class.php
@ -114,17 +114,17 @@ class AdvanceTargetingMailing extends CommonObject
$this->db = $db;
$this->select_target_type = array(
'2' => $langs->trans('Contacts'),
'1' => $langs->trans('Contacts').'+'.$langs->trans('ThirdParty'),
'3' => $langs->trans('ThirdParty'),
'4' => $langs->trans('ContactsWithThirdpartyFilter')
'2' => $langs->trans('Contacts'),
'1' => $langs->trans('Contacts').'+'.$langs->trans('ThirdParty'),
'3' => $langs->trans('ThirdParty'),
'4' => $langs->trans('ContactsWithThirdpartyFilter')
);
$this->type_statuscommprospect = array(
-1 => $langs->trans("StatusProspect-1"),
0 => $langs->trans("StatusProspect0"),
1 => $langs->trans("StatusProspect1"),
2 => $langs->trans("StatusProspect2"),
3 => $langs->trans("StatusProspect3")
-1 => $langs->trans("StatusProspect-1"),
0 => $langs->trans("StatusProspect0"),
1 => $langs->trans("StatusProspect1"),
2 => $langs->trans("StatusProspect2"),
3 => $langs->trans("StatusProspect3")
);
}
@ -141,11 +141,19 @@ class AdvanceTargetingMailing extends CommonObject
$error = 0;
// Clean parameters
if (isset($this->fk_element)) $this->fk_element = (int) $this->fk_element;
if (isset($this->type_element)) $this->type_element = trim($this->type_element);
if (isset($this->fk_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->filtervalue)) $this->filtervalue = trim($this->filtervalue);
if (isset($this->name)) {
$this->name = trim($this->name);
}
if (isset($this->filtervalue)) {
$this->filtervalue = trim($this->filtervalue);
}
// Check parameters
// 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);
$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");
}
// Commit or rollback
if ($error)
{
foreach ($this->errors as $errmsg)
{
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@ -225,10 +232,8 @@ class AdvanceTargetingMailing extends CommonObject
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
@ -286,10 +291,8 @@ class AdvanceTargetingMailing extends CommonObject
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
@ -351,10 +354,8 @@ class AdvanceTargetingMailing extends CommonObject
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
@ -392,10 +393,18 @@ class AdvanceTargetingMailing extends CommonObject
$error = 0;
// Clean parameters
if (isset($this->fk_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->filtervalue)) $this->filtervalue = trim($this->filtervalue);
if (isset($this->fk_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->filtervalue)) {
$this->filtervalue = trim($this->filtervalue);
}
// Check parameters
// Put here code to add a control on parameters values
@ -421,10 +430,8 @@ class AdvanceTargetingMailing extends CommonObject
}
// Commit or rollback
if ($error)
{
foreach ($this->errors as $errmsg)
{
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@ -450,21 +457,20 @@ class AdvanceTargetingMailing extends CommonObject
$this->db->begin();
if (!$error)
{
if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."advtargetemailing";
$sql .= " WHERE rowid=".$this->id;
dol_syslog(get_class($this)."::delete sql=".$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
if ($error)
{
foreach ($this->errors as $errmsg)
{
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@ -590,7 +596,7 @@ class AdvanceTargetingMailing extends CommonObject
$extrafields->fetch_name_optionals_label($elementtype);
foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$val) {
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $val) {
if (($extrafields->attributes[$elementtype]['type'][$key] == 'varchar') ||
($extrafields->attributes[$elementtype]['type'][$key] == 'text')) {
if (!empty($arrayquery['options_'.$key])) {
@ -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);
$i = 0;
if ($num)
{
while ($i < $num)
{
if ($num) {
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
$this->thirdparty_lines[$i] = $obj->rowid;
@ -701,8 +707,7 @@ class AdvanceTargetingMailing extends CommonObject
}
if ($arrayquery['contact_no_email'] != '') {
$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'])."'))";
} 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'])."'))";
@ -731,7 +736,7 @@ class AdvanceTargetingMailing extends CommonObject
$extrafields->fetch_name_optionals_label($elementtype);
foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$val) {
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $val) {
if (($extrafields->attributes[$elementtype]['type'][$key] == 'varchar') ||
($extrafields->attributes[$elementtype]['type'][$key] == 'text')) {
if (!empty($arrayquery['options_'.$key.'_cnct'])) {
@ -833,7 +838,7 @@ class AdvanceTargetingMailing extends CommonObject
$extrafields->fetch_name_optionals_label($elementtype);
foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$val) {
foreach ($extrafields->attributes[$elementtype]['label'] as $key => $val) {
if (($extrafields->attributes[$elementtype]['type'][$key] == 'varchar') ||
($extrafields->attributes[$elementtype]['type'][$key] == 'text')) {
if (!empty($arrayquery['options_'.$key])) {
@ -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);
@ -874,10 +881,8 @@ class AdvanceTargetingMailing extends CommonObject
$num = $this->db->num_rows($resql);
$i = 0;
if ($num)
{
while ($i < $num)
{
if ($num) {
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
$this->contact_lines[$i] = $obj->rowid;