commit
0834e4801e
@ -1,20 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Advance Targeting Emailling for mass emailing module
|
/* Advance Targeting Emailling for mass emailing module
|
||||||
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
|
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file comm/mailing/class/advtargetemailing.class.php
|
* \file comm/mailing/class/advtargetemailing.class.php
|
||||||
@ -33,16 +33,6 @@ class AdvanceTargetingMailing extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public $db;
|
public $db;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string Error code (or message)
|
|
||||||
*/
|
|
||||||
public $error = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string[] Error codes (or messages)
|
|
||||||
*/
|
|
||||||
public $errors = array();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string ID to identify managed object
|
* @var string ID to identify managed object
|
||||||
*/
|
*/
|
||||||
@ -58,17 +48,54 @@ class AdvanceTargetingMailing extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public $id;
|
public $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string name
|
||||||
|
*/
|
||||||
public $name;
|
public $name;
|
||||||
public $entity;
|
|
||||||
|
/**
|
||||||
|
* @var int element id
|
||||||
|
*/
|
||||||
public $fk_element;
|
public $fk_element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string type element
|
||||||
|
*/
|
||||||
public $type_element;
|
public $type_element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string filter value
|
||||||
|
*/
|
||||||
public $filtervalue;
|
public $filtervalue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int user author id
|
||||||
|
*/
|
||||||
public $fk_user_author;
|
public $fk_user_author;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int|string datec
|
||||||
|
*/
|
||||||
public $datec = '';
|
public $datec = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int user mod id
|
||||||
|
*/
|
||||||
public $fk_user_mod;
|
public $fk_user_mod;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int|string tms
|
||||||
|
*/
|
||||||
public $tms = '';
|
public $tms = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array select target type
|
||||||
|
*/
|
||||||
public $select_target_type = array();
|
public $select_target_type = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array type status comm prospect
|
||||||
|
*/
|
||||||
public $type_statuscommprospect = array();
|
public $type_statuscommprospect = array();
|
||||||
public $thirdparty_lines;
|
public $thirdparty_lines;
|
||||||
public $contact_lines;
|
public $contact_lines;
|
||||||
@ -87,17 +114,17 @@ class AdvanceTargetingMailing extends CommonObject
|
|||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
|
|
||||||
$this->select_target_type = array(
|
$this->select_target_type = array(
|
||||||
'2' => $langs->trans('Contacts'),
|
'2' => $langs->trans('Contacts'),
|
||||||
'1' => $langs->trans('Contacts').'+'.$langs->trans('ThirdParty'),
|
'1' => $langs->trans('Contacts').'+'.$langs->trans('ThirdParty'),
|
||||||
'3' => $langs->trans('ThirdParty'),
|
'3' => $langs->trans('ThirdParty'),
|
||||||
'4' => $langs->trans('ContactsWithThirdpartyFilter')
|
'4' => $langs->trans('ContactsWithThirdpartyFilter')
|
||||||
);
|
);
|
||||||
$this->type_statuscommprospect = array(
|
$this->type_statuscommprospect = array(
|
||||||
-1 => $langs->trans("StatusProspect-1"),
|
-1 => $langs->trans("StatusProspect-1"),
|
||||||
0 => $langs->trans("StatusProspect0"),
|
0 => $langs->trans("StatusProspect0"),
|
||||||
1 => $langs->trans("StatusProspect1"),
|
1 => $langs->trans("StatusProspect1"),
|
||||||
2 => $langs->trans("StatusProspect2"),
|
2 => $langs->trans("StatusProspect2"),
|
||||||
3 => $langs->trans("StatusProspect3")
|
3 => $langs->trans("StatusProspect3")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,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
|
||||||
@ -148,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);
|
||||||
}
|
}
|
||||||
@ -198,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;
|
||||||
@ -259,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;
|
||||||
@ -324,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;
|
||||||
@ -365,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
|
||||||
@ -394,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);
|
||||||
}
|
}
|
||||||
@ -423,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);
|
||||||
}
|
}
|
||||||
@ -563,7 +596,7 @@ class AdvanceTargetingMailing extends CommonObject
|
|||||||
|
|
||||||
$extrafields->fetch_name_optionals_label($elementtype);
|
$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') ||
|
if (($extrafields->attributes[$elementtype]['type'][$key] == 'varchar') ||
|
||||||
($extrafields->attributes[$elementtype]['type'][$key] == 'text')) {
|
($extrafields->attributes[$elementtype]['type'][$key] == 'text')) {
|
||||||
if (!empty($arrayquery['options_'.$key])) {
|
if (!empty($arrayquery['options_'.$key])) {
|
||||||
@ -593,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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -604,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;
|
||||||
@ -674,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'])."'))";
|
||||||
@ -704,7 +736,7 @@ class AdvanceTargetingMailing extends CommonObject
|
|||||||
|
|
||||||
$extrafields->fetch_name_optionals_label($elementtype);
|
$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') ||
|
if (($extrafields->attributes[$elementtype]['type'][$key] == 'varchar') ||
|
||||||
($extrafields->attributes[$elementtype]['type'][$key] == 'text')) {
|
($extrafields->attributes[$elementtype]['type'][$key] == 'text')) {
|
||||||
if (!empty($arrayquery['options_'.$key.'_cnct'])) {
|
if (!empty($arrayquery['options_'.$key.'_cnct'])) {
|
||||||
@ -806,7 +838,7 @@ class AdvanceTargetingMailing extends CommonObject
|
|||||||
|
|
||||||
$extrafields->fetch_name_optionals_label($elementtype);
|
$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') ||
|
if (($extrafields->attributes[$elementtype]['type'][$key] == 'varchar') ||
|
||||||
($extrafields->attributes[$elementtype]['type'][$key] == 'text')) {
|
($extrafields->attributes[$elementtype]['type'][$key] == 'text')) {
|
||||||
if (!empty($arrayquery['options_'.$key])) {
|
if (!empty($arrayquery['options_'.$key])) {
|
||||||
@ -837,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);
|
||||||
@ -847,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;
|
||||||
|
|||||||
@ -46,25 +46,96 @@ class Mailing extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public $picto = 'email';
|
public $picto = 'email';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string title
|
||||||
|
*/
|
||||||
public $title;
|
public $title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string subject
|
||||||
|
*/
|
||||||
public $sujet;
|
public $sujet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string body
|
||||||
|
*/
|
||||||
public $body;
|
public $body;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int number of email
|
||||||
|
*/
|
||||||
public $nbemail;
|
public $nbemail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string background color
|
||||||
|
*/
|
||||||
public $bgcolor;
|
public $bgcolor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string background image
|
||||||
|
*/
|
||||||
public $bgimage;
|
public $bgimage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int status
|
||||||
|
*/
|
||||||
public $statut; // Status 0=Draft, 1=Validated, 2=Sent partially, 3=Sent completely
|
public $statut; // Status 0=Draft, 1=Validated, 2=Sent partially, 3=Sent completely
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string email from
|
||||||
|
*/
|
||||||
public $email_from;
|
public $email_from;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string email reply to
|
||||||
|
*/
|
||||||
public $email_replyto;
|
public $email_replyto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string email errors to
|
||||||
|
*/
|
||||||
public $email_errorsto;
|
public $email_errorsto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string first joined file
|
||||||
|
*/
|
||||||
public $joined_file1;
|
public $joined_file1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string second joined file
|
||||||
|
*/
|
||||||
public $joined_file2;
|
public $joined_file2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string third joined file
|
||||||
|
*/
|
||||||
public $joined_file3;
|
public $joined_file3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string fourth joined file
|
||||||
|
*/
|
||||||
public $joined_file4;
|
public $joined_file4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int id of user create
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
public $user_creation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int id of user create
|
||||||
|
*/
|
||||||
public $user_creat;
|
public $user_creat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int id of user validate
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
public $user_validation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int id of user validate
|
||||||
|
*/
|
||||||
public $user_valid;
|
public $user_valid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,12 +143,24 @@ class Mailing extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public $date_creat;
|
public $date_creat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int date validate
|
||||||
|
*/
|
||||||
public $date_valid;
|
public $date_valid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array extraparams
|
||||||
|
*/
|
||||||
public $extraparams = array();
|
public $extraparams = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array statut dest
|
||||||
|
*/
|
||||||
public $statut_dest = array();
|
public $statut_dest = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array statuts
|
||||||
|
*/
|
||||||
public $statuts = array();
|
public $statuts = array();
|
||||||
|
|
||||||
|
|
||||||
@ -118,8 +201,7 @@ class Mailing extends CommonObject
|
|||||||
$this->title = trim($this->title);
|
$this->title = trim($this->title);
|
||||||
$this->email_from = trim($this->email_from);
|
$this->email_from = trim($this->email_from);
|
||||||
|
|
||||||
if (!$this->email_from)
|
if (!$this->email_from) {
|
||||||
{
|
|
||||||
$this->error = $langs->trans("ErrorMailFromRequired");
|
$this->error = $langs->trans("ErrorMailFromRequired");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -130,19 +212,16 @@ class Mailing extends CommonObject
|
|||||||
$sql .= " (date_creat, fk_user_creat, entity)";
|
$sql .= " (date_creat, fk_user_creat, entity)";
|
||||||
$sql .= " VALUES ('".$this->db->idate($now)."', ".$user->id.", ".$conf->entity.")";
|
$sql .= " VALUES ('".$this->db->idate($now)."', ".$user->id.", ".$conf->entity.")";
|
||||||
|
|
||||||
if (!$this->title)
|
if (!$this->title) {
|
||||||
{
|
|
||||||
$this->title = $langs->trans("NoTitle");
|
$this->title = $langs->trans("NoTitle");
|
||||||
}
|
}
|
||||||
|
|
||||||
dol_syslog("Mailing::Create", LOG_DEBUG);
|
dol_syslog("Mailing::Create", LOG_DEBUG);
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result)
|
if ($result) {
|
||||||
{
|
|
||||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."mailing");
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."mailing");
|
||||||
|
|
||||||
if ($this->update($user) > 0)
|
if ($this->update($user) > 0) {
|
||||||
{
|
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
} else {
|
} else {
|
||||||
$this->error = $this->db->lasterror();
|
$this->error = $this->db->lasterror();
|
||||||
@ -175,12 +254,11 @@ class Mailing extends CommonObject
|
|||||||
$sql .= ", email_errorsto = '".$this->db->escape($this->email_errorsto)."'";
|
$sql .= ", email_errorsto = '".$this->db->escape($this->email_errorsto)."'";
|
||||||
$sql .= ", bgcolor = '".($this->bgcolor ? $this->db->escape($this->bgcolor) : null)."'";
|
$sql .= ", bgcolor = '".($this->bgcolor ? $this->db->escape($this->bgcolor) : null)."'";
|
||||||
$sql .= ", bgimage = '".($this->bgimage ? $this->db->escape($this->bgimage) : null)."'";
|
$sql .= ", bgimage = '".($this->bgimage ? $this->db->escape($this->bgimage) : null)."'";
|
||||||
$sql .= " WHERE rowid = ".$this->id;
|
$sql .= " WHERE rowid = ".(int) $this->id;
|
||||||
|
|
||||||
dol_syslog("Mailing::Update", LOG_DEBUG);
|
dol_syslog("Mailing::Update", LOG_DEBUG);
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result)
|
if ($result) {
|
||||||
{
|
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
$this->error = $this->db->lasterror();
|
$this->error = $this->db->lasterror();
|
||||||
@ -211,10 +289,8 @@ class Mailing extends CommonObject
|
|||||||
|
|
||||||
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
|
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result)
|
if ($result) {
|
||||||
{
|
if ($this->db->num_rows($result)) {
|
||||||
if ($this->db->num_rows($result))
|
|
||||||
{
|
|
||||||
$obj = $this->db->fetch_object($result);
|
$obj = $this->db->fetch_object($result);
|
||||||
|
|
||||||
$this->id = $obj->rowid;
|
$this->id = $obj->rowid;
|
||||||
@ -286,8 +362,7 @@ class Mailing extends CommonObject
|
|||||||
$object->title = $langs->trans("CopyOf").' '.$object->title.' '.dol_print_date(dol_now());
|
$object->title = $langs->trans("CopyOf").' '.$object->title.' '.dol_print_date(dol_now());
|
||||||
|
|
||||||
// If no option copy content
|
// If no option copy content
|
||||||
if (empty($option1))
|
if (empty($option1)) {
|
||||||
{
|
|
||||||
// Clear values
|
// Clear values
|
||||||
$object->nbemail = 0;
|
$object->nbemail = 0;
|
||||||
$object->sujet = '';
|
$object->sujet = '';
|
||||||
@ -312,15 +387,13 @@ class Mailing extends CommonObject
|
|||||||
$result = $object->create($user);
|
$result = $object->create($user);
|
||||||
|
|
||||||
// Other options
|
// Other options
|
||||||
if ($result < 0)
|
if ($result < 0) {
|
||||||
{
|
|
||||||
$this->error = $object->error;
|
$this->error = $object->error;
|
||||||
$this->errors = array_merge($this->errors, $object->errors);
|
$this->errors = array_merge($this->errors, $object->errors);
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$error)
|
if (!$error) {
|
||||||
{
|
|
||||||
// Clone recipient targets
|
// Clone recipient targets
|
||||||
if (!empty($option2)) {
|
if (!empty($option2)) {
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
|
||||||
@ -341,10 +414,8 @@ class Mailing extends CommonObject
|
|||||||
$sql .= " WHERE fk_mailing = ".$fromid;
|
$sql .= " WHERE fk_mailing = ".$fromid;
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result)
|
if ($result) {
|
||||||
{
|
if ($this->db->num_rows($result)) {
|
||||||
if ($this->db->num_rows($result))
|
|
||||||
{
|
|
||||||
while ($obj = $this->db->fetch_object($result)) {
|
while ($obj = $this->db->fetch_object($result)) {
|
||||||
$target_array[] = array(
|
$target_array[] = array(
|
||||||
'fk_contact'=>$obj->fk_contact,
|
'fk_contact'=>$obj->fk_contact,
|
||||||
@ -370,8 +441,7 @@ class Mailing extends CommonObject
|
|||||||
unset($object->context['createfromclone']);
|
unset($object->context['createfromclone']);
|
||||||
|
|
||||||
// End
|
// End
|
||||||
if (!$error)
|
if (!$error) {
|
||||||
{
|
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return $object->id;
|
return $object->id;
|
||||||
} else {
|
} else {
|
||||||
@ -395,8 +465,7 @@ class Mailing extends CommonObject
|
|||||||
$sql .= " WHERE rowid = ".$this->id;
|
$sql .= " WHERE rowid = ".$this->id;
|
||||||
|
|
||||||
dol_syslog("Mailing::valid", LOG_DEBUG);
|
dol_syslog("Mailing::valid", LOG_DEBUG);
|
||||||
if ($this->db->query($sql))
|
if ($this->db->query($sql)) {
|
||||||
{
|
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
$this->error = $this->db->lasterror();
|
$this->error = $this->db->lasterror();
|
||||||
@ -418,8 +487,7 @@ class Mailing extends CommonObject
|
|||||||
|
|
||||||
dol_syslog("Mailing::delete", LOG_DEBUG);
|
dol_syslog("Mailing::delete", LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
return $this->delete_targets();
|
return $this->delete_targets();
|
||||||
} else {
|
} else {
|
||||||
$this->error = $this->db->lasterror();
|
$this->error = $this->db->lasterror();
|
||||||
@ -441,8 +509,7 @@ class Mailing extends CommonObject
|
|||||||
|
|
||||||
dol_syslog("Mailing::delete_targets", LOG_DEBUG);
|
dol_syslog("Mailing::delete_targets", LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
$this->error = $this->db->lasterror();
|
$this->error = $this->db->lasterror();
|
||||||
@ -467,8 +534,7 @@ class Mailing extends CommonObject
|
|||||||
|
|
||||||
dol_syslog("Mailing::reset_targets_status", LOG_DEBUG);
|
dol_syslog("Mailing::reset_targets_status", LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
$this->error = $this->db->lasterror();
|
$this->error = $this->db->lasterror();
|
||||||
@ -487,19 +553,23 @@ class Mailing extends CommonObject
|
|||||||
{
|
{
|
||||||
$sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_cibles";
|
$sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_cibles";
|
||||||
$sql .= " WHERE fk_mailing = ".$this->id;
|
$sql .= " WHERE fk_mailing = ".$this->id;
|
||||||
if ($mode == 'alreadysent') $sql .= " AND statut <> 0";
|
if ($mode == 'alreadysent') {
|
||||||
elseif ($mode == 'alreadysentok') $sql .= " AND statut > 0";
|
$sql .= " AND statut <> 0";
|
||||||
elseif ($mode == 'alreadysentko') $sql .= " AND statut = -1";
|
} elseif ($mode == 'alreadysentok') {
|
||||||
else {
|
$sql .= " AND statut > 0";
|
||||||
|
} elseif ($mode == 'alreadysentko') {
|
||||||
|
$sql .= " AND statut = -1";
|
||||||
|
} else {
|
||||||
$this->error = 'BadValueForParameterMode';
|
$this->error = 'BadValueForParameterMode';
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql) {
|
||||||
{
|
|
||||||
$obj = $this->db->fetch_object($resql);
|
$obj = $this->db->fetch_object($resql);
|
||||||
if ($obj) return $obj->nb;
|
if ($obj) {
|
||||||
|
return $obj->nb;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->error = $this->db->lasterror();
|
$this->error = $this->db->lasterror();
|
||||||
return -1;
|
return -1;
|
||||||
@ -524,7 +594,9 @@ class Mailing extends CommonObject
|
|||||||
global $dolibarr_main_authentication, $dolibarr_main_demo;
|
global $dolibarr_main_authentication, $dolibarr_main_demo;
|
||||||
global $menumanager;
|
global $menumanager;
|
||||||
|
|
||||||
if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
|
if (!empty($conf->dol_no_mouse_hover)) {
|
||||||
|
$notooltip = 1; // Force disable tooltips
|
||||||
|
}
|
||||||
|
|
||||||
$result = '';
|
$result = '';
|
||||||
$companylink = '';
|
$companylink = '';
|
||||||
@ -535,19 +607,20 @@ class Mailing extends CommonObject
|
|||||||
|
|
||||||
$url = DOL_URL_ROOT.'/comm/mailing/card.php?id='.$this->id;
|
$url = DOL_URL_ROOT.'/comm/mailing/card.php?id='.$this->id;
|
||||||
|
|
||||||
if ($option != 'nolink')
|
if ($option != 'nolink') {
|
||||||
{
|
|
||||||
// Add param to save lastsearch_values or not
|
// Add param to save lastsearch_values or not
|
||||||
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
|
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
|
||||||
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
|
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
|
||||||
if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
|
$add_save_lastsearch_values = 1;
|
||||||
|
}
|
||||||
|
if ($add_save_lastsearch_values) {
|
||||||
|
$url .= '&save_lastsearch_values=1';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$linkclose = '';
|
$linkclose = '';
|
||||||
if (empty($notooltip))
|
if (empty($notooltip)) {
|
||||||
{
|
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
|
||||||
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
|
|
||||||
{
|
|
||||||
$label = $langs->trans("ShowEMailing");
|
$label = $langs->trans("ShowEMailing");
|
||||||
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
|
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
|
||||||
}
|
}
|
||||||
@ -560,15 +633,21 @@ class Mailing extends CommonObject
|
|||||||
$reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
$reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
||||||
if ($reshook > 0) $linkclose = $hookmanager->resPrint;
|
if ($reshook > 0) $linkclose = $hookmanager->resPrint;
|
||||||
*/
|
*/
|
||||||
} else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
|
} else {
|
||||||
|
$linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
|
||||||
|
}
|
||||||
|
|
||||||
$linkstart = '<a href="'.$url.'"';
|
$linkstart = '<a href="'.$url.'"';
|
||||||
$linkstart .= $linkclose.'>';
|
$linkstart .= $linkclose.'>';
|
||||||
$linkend = '</a>';
|
$linkend = '</a>';
|
||||||
|
|
||||||
$result .= $linkstart;
|
$result .= $linkstart;
|
||||||
if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
|
if ($withpicto) {
|
||||||
if ($withpicto != 2) $result .= $this->ref;
|
$result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
|
||||||
|
}
|
||||||
|
if ($withpicto != 2) {
|
||||||
|
$result .= $this->ref;
|
||||||
|
}
|
||||||
$result .= $linkend;
|
$result .= $linkend;
|
||||||
//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
|
//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
|
||||||
|
|
||||||
@ -576,8 +655,11 @@ class Mailing extends CommonObject
|
|||||||
$hookmanager->initHooks(array('emailingdao'));
|
$hookmanager->initHooks(array('emailingdao'));
|
||||||
$parameters = array('id'=>$this->id, 'getnomurl'=>$result);
|
$parameters = array('id'=>$this->id, 'getnomurl'=>$result);
|
||||||
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
||||||
if ($reshook > 0) $result = $hookmanager->resPrint;
|
if ($reshook > 0) {
|
||||||
else $result .= $hookmanager->resPrint;
|
$result = $hookmanager->resPrint;
|
||||||
|
} else {
|
||||||
|
$result .= $hookmanager->resPrint;
|
||||||
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@ -611,8 +693,12 @@ class Mailing extends CommonObject
|
|||||||
$labelStatusShort = $langs->trans($this->statuts[$status]);
|
$labelStatusShort = $langs->trans($this->statuts[$status]);
|
||||||
|
|
||||||
$statusType = 'status'.$status;
|
$statusType = 'status'.$status;
|
||||||
if ($status == 2) $statusType = 'status3';
|
if ($status == 2) {
|
||||||
if ($status == 3) $statusType = 'status6';
|
$statusType = 'status3';
|
||||||
|
}
|
||||||
|
if ($status == 3) {
|
||||||
|
$statusType = 'status6';
|
||||||
|
}
|
||||||
|
|
||||||
return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
|
return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
|
||||||
}
|
}
|
||||||
@ -647,9 +733,15 @@ class Mailing extends CommonObject
|
|||||||
$labelStatusShort[3] = $langs->trans('MailingStatusNotContact');
|
$labelStatusShort[3] = $langs->trans('MailingStatusNotContact');
|
||||||
|
|
||||||
$statusType = 'status'.$status;
|
$statusType = 'status'.$status;
|
||||||
if ($status == -1) $statusType = 'status8';
|
if ($status == -1) {
|
||||||
if ($status == 1) $statusType = 'status6';
|
$statusType = 'status8';
|
||||||
if ($status == 2) $statusType = 'status4';
|
}
|
||||||
|
if ($status == 1) {
|
||||||
|
$statusType = 'status6';
|
||||||
|
}
|
||||||
|
if ($status == 2) {
|
||||||
|
$statusType = 'status4';
|
||||||
|
}
|
||||||
|
|
||||||
$param = array();
|
$param = array();
|
||||||
if ($status == - 1) {
|
if ($status == - 1) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user