2005-01-05 16:26:05 +01:00
< ? php
2009-01-25 23:04:55 +01:00
/* Copyright ( C ) 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2016-11-11 14:03:57 +01:00
* Copyright ( C ) 2005 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ inodbox . com >
2005-01-05 16:26:05 +01:00
*
* 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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2005-01-05 16:26:05 +01:00
* ( 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
2011-08-03 02:45:22 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2005-01-05 16:26:05 +01:00
*/
2005-05-14 02:36:01 +02:00
/**
2010-06-05 17:32:18 +02:00
* \file htdocs / comm / mailing / class / mailing . class . php
2008-12-04 18:37:28 +01:00
* \ingroup mailing
2012-03-31 15:42:33 +02:00
* \brief File of class to manage emailings module
2008-11-10 15:20:02 +01:00
*/
2005-01-05 16:26:05 +01:00
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php' ;
2008-12-04 18:37:28 +01:00
2005-01-05 16:26:05 +01:00
2005-05-14 02:36:01 +02:00
/**
2012-03-31 15:42:33 +02:00
* Class to manage emailings module
2008-11-10 15:20:02 +01:00
*/
2008-12-04 18:37:28 +01:00
class Mailing extends CommonObject
2005-01-05 16:26:05 +01:00
{
2018-08-23 17:07:27 +02:00
/**
* @ var string ID to identify managed object
*/
2011-09-20 19:19:46 +02:00
public $element = 'mailing' ;
2018-09-02 11:12:07 +02:00
2018-08-22 18:12:44 +02:00
/**
* @ var string Name of table without prefix where object is stored
*/
2011-09-20 19:19:46 +02:00
public $table_element = 'mailing' ;
2018-09-02 11:12:07 +02:00
2018-09-04 14:46:10 +02:00
/**
* @ var string String with name of icon for myobject . Must be the part after the 'object_' into object_myobject . png
*/
2016-11-11 01:55:53 +01:00
public $picto = 'email' ;
2018-01-29 12:46:07 +01:00
2018-09-04 14:46:10 +02:00
public $titre ;
public $sujet ;
public $body ;
public $nbemail ;
public $bgcolor ;
public $bgimage ;
2005-01-05 16:26:05 +01:00
2018-09-04 14:46:10 +02:00
public $statut ; // Status 0=Draft, 1=Validated, 2=Sent partially, 3=Sent completely
2018-01-29 12:46:07 +01:00
2018-09-04 14:46:10 +02:00
public $email_from ;
public $email_replyto ;
public $email_errorsto ;
2005-01-05 16:26:05 +01:00
2018-09-04 14:46:10 +02:00
public $joined_file1 ;
public $joined_file2 ;
public $joined_file3 ;
public $joined_file4 ;
2010-04-17 11:47:25 +02:00
2018-09-04 14:46:10 +02:00
public $user_creat ;
public $user_valid ;
2008-11-10 15:20:02 +01:00
2018-09-04 14:46:10 +02:00
public $date_creat ;
public $date_valid ;
2015-02-26 13:03:17 +01:00
2018-09-04 14:46:10 +02:00
public $extraparams = array ();
2008-11-10 15:20:02 +01:00
2014-05-29 14:26:27 +02:00
public $statut_dest = array ();
public $statuts = array ();
2008-11-10 15:20:02 +01:00
2018-09-04 20:48:35 +02:00
/**
2012-02-16 18:39:22 +01:00
* Constructor
*
2018-09-04 20:48:35 +02:00
* @ param DoliDb $db Database handler
2008-11-10 15:20:02 +01:00
*/
2012-06-13 09:26:29 +02:00
function __construct ( $db )
2005-01-05 16:26:05 +01:00
{
2012-02-16 18:39:22 +01:00
$this -> db = $db ;
2008-11-10 15:20:02 +01:00
2009-12-17 16:52:37 +01:00
// List of language codes for status
$this -> statuts [ 0 ] = 'MailingStatusDraft' ;
$this -> statuts [ 1 ] = 'MailingStatusValidated' ;
$this -> statuts [ 2 ] = 'MailingStatusSentPartialy' ;
$this -> statuts [ 3 ] = 'MailingStatusSentCompletely' ;
2015-02-26 13:03:17 +01:00
2014-05-29 14:26:27 +02:00
$this -> statut_dest [ - 1 ] = 'MailingStatusError' ;
2017-05-04 13:41:37 +02:00
$this -> statut_dest [ 0 ] = 'MailingStatusNotSent' ;
2014-05-29 14:26:27 +02:00
$this -> statut_dest [ 1 ] = 'MailingStatusSent' ;
$this -> statut_dest [ 2 ] = 'MailingStatusRead' ;
2016-02-12 14:21:44 +01:00
$this -> statut_dest [ 3 ] = 'MailingStatusReadAndUnsubscribe' ; // Read but ask to not be contacted anymore
2005-01-05 16:26:05 +01:00
}
2005-02-12 00:41:42 +01:00
2008-11-10 15:20:02 +01:00
/**
2012-03-18 19:23:01 +01:00
* Create an EMailing
*
* @ param User $user Object of user making creation
* @ return int - 1 if error , Id of created object if OK
2008-11-10 15:20:02 +01:00
*/
function create ( $user )
2005-01-05 16:26:05 +01:00
{
2009-04-28 22:35:01 +02:00
global $conf , $langs ;
2008-11-10 15:20:02 +01:00
$this -> db -> begin ();
$this -> titre = trim ( $this -> titre );
$this -> email_from = trim ( $this -> email_from );
if ( ! $this -> email_from )
{
$this -> error = $langs -> trans ( " ErrorMailFromRequired " );
return - 1 ;
}
2012-05-09 17:14:46 +02:00
2012-04-30 15:01:25 +02:00
$now = dol_now ();
2008-11-10 15:20:02 +01:00
2010-05-17 14:43:36 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " mailing " ;
2009-04-28 22:35:01 +02:00
$sql .= " (date_creat, fk_user_creat, entity) " ;
2014-03-15 23:12:00 +01:00
$sql .= " VALUES (' " . $this -> db -> idate ( $now ) . " ', " . $user -> id . " , " . $conf -> entity . " ) " ;
2008-11-10 15:20:02 +01:00
if ( ! $this -> titre )
{
$this -> titre = $langs -> trans ( " NoTitle " );
}
2014-06-12 11:31:53 +02:00
dol_syslog ( " Mailing::Create " , LOG_DEBUG );
2008-11-10 15:20:02 +01:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
2010-05-17 14:43:36 +02:00
$this -> id = $this -> db -> last_insert_id ( MAIN_DB_PREFIX . " mailing " );
2008-11-10 15:20:02 +01:00
2009-07-03 11:50:34 +02:00
if ( $this -> update ( $user ) > 0 )
2008-11-10 15:20:02 +01:00
{
$this -> db -> commit ();
}
else
{
2012-06-15 11:20:09 +02:00
$this -> error = $this -> db -> lasterror ();
2008-11-10 15:20:02 +01:00
$this -> db -> rollback ();
return - 1 ;
}
return $this -> id ;
}
else
{
$this -> error = $this -> db -> lasterror ();
$this -> db -> rollback ();
return - 1 ;
}
2005-01-05 16:26:05 +01:00
}
2008-11-10 15:20:02 +01:00
/**
2012-03-18 19:23:01 +01:00
* Update emailing record
*
* @ param User $user Object of user making change
* @ return int < 0 if KO , > 0 if OK
2008-11-10 15:20:02 +01:00
*/
2009-05-25 00:01:19 +02:00
function update ( $user )
2005-01-05 16:26:05 +01:00
{
2008-11-10 15:20:02 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " mailing " ;
2011-02-24 19:11:12 +01:00
$sql .= " SET titre = ' " . $this -> db -> escape ( $this -> titre ) . " ' " ;
$sql .= " , sujet = ' " . $this -> db -> escape ( $this -> sujet ) . " ' " ;
$sql .= " , body = ' " . $this -> db -> escape ( $this -> body ) . " ' " ;
2017-05-12 16:55:11 +02:00
$sql .= " , email_from = ' " . $this -> db -> escape ( $this -> email_from ) . " ' " ;
$sql .= " , email_replyto = ' " . $this -> db -> escape ( $this -> email_replyto ) . " ' " ;
$sql .= " , email_errorsto = ' " . $this -> db -> escape ( $this -> email_errorsto ) . " ' " ;
$sql .= " , bgcolor = ' " . ( $this -> bgcolor ? $this -> db -> escape ( $this -> bgcolor ) : null ) . " ' " ;
$sql .= " , bgimage = ' " . ( $this -> bgimage ? $this -> db -> escape ( $this -> bgimage ) : null ) . " ' " ;
2008-11-10 15:20:02 +01:00
$sql .= " WHERE rowid = " . $this -> id ;
2014-06-12 11:31:53 +02:00
dol_syslog ( " Mailing::Update " , LOG_DEBUG );
2008-11-10 15:20:02 +01:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
return 1 ;
}
else
{
$this -> error = $this -> db -> lasterror ();
return - 1 ;
}
2005-01-05 16:26:05 +01:00
}
2008-11-10 15:20:02 +01:00
2006-11-02 02:42:49 +01:00
/**
2012-03-18 19:23:01 +01:00
* Get object from database
*
* @ param int $rowid Id of emailing
* @ return int < 0 if KO , > 0 if OK
2008-11-10 15:20:02 +01:00
*/
2006-11-02 02:42:49 +01:00
function fetch ( $rowid )
2005-01-05 16:26:05 +01:00
{
2013-02-22 15:02:06 +01:00
global $conf ;
2015-02-26 13:03:17 +01:00
2009-05-19 15:27:44 +02:00
$sql = " SELECT m.rowid, m.titre, m.sujet, m.body, m.bgcolor, m.bgimage " ;
2012-06-13 09:26:29 +02:00
$sql .= " , m.email_from, m.email_replyto, m.email_errorsto " ;
$sql .= " , m.statut, m.nbemail " ;
$sql .= " , m.fk_user_creat, m.fk_user_valid " ;
$sql .= " , m.date_creat " ;
$sql .= " , m.date_valid " ;
$sql .= " , m.date_envoi " ;
$sql .= " , m.extraparams " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " mailing as m " ;
2015-11-21 10:55:23 +01:00
$sql .= " WHERE m.rowid = " . ( int ) $rowid ;
2008-11-10 15:20:02 +01:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::fetch " , LOG_DEBUG );
2006-11-02 02:42:49 +01:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
if ( $this -> db -> num_rows ( $result ))
{
$obj = $this -> db -> fetch_object ( $result );
2008-11-10 15:20:02 +01:00
2012-06-13 09:26:29 +02:00
$this -> id = $obj -> rowid ;
$this -> ref = $obj -> rowid ;
$this -> statut = $obj -> statut ;
$this -> nbemail = $obj -> nbemail ;
$this -> titre = $obj -> titre ;
2015-02-26 13:03:17 +01:00
$this -> sujet = $obj -> sujet ;
2013-02-22 15:02:06 +01:00
if ( ! empty ( $conf -> global -> FCKEDITOR_ENABLE_MAILING ) && dol_textishtml ( dol_html_entity_decode ( $obj -> body , ENT_COMPAT | ENT_HTML401 ))) {
$this -> body = dol_html_entity_decode ( $obj -> body , ENT_COMPAT | ENT_HTML401 );
} else {
$this -> body = $obj -> body ;
}
2015-02-26 13:03:17 +01:00
2012-06-13 09:26:29 +02:00
$this -> bgcolor = $obj -> bgcolor ;
$this -> bgimage = $obj -> bgimage ;
$this -> email_from = $obj -> email_from ;
$this -> email_replyto = $obj -> email_replyto ;
$this -> email_errorsto = $obj -> email_errorsto ;
$this -> user_creat = $obj -> fk_user_creat ;
$this -> user_valid = $obj -> fk_user_valid ;
$this -> date_creat = $this -> db -> jdate ( $obj -> date_creat );
$this -> date_valid = $this -> db -> jdate ( $obj -> date_valid );
$this -> date_envoi = $this -> db -> jdate ( $obj -> date_envoi );
2015-02-26 13:03:17 +01:00
2012-06-13 09:26:29 +02:00
$this -> extraparams = ( array ) json_decode ( $obj -> extraparams , true );
2008-11-10 15:20:02 +01:00
2006-11-02 02:42:49 +01:00
return 1 ;
}
else
{
2012-05-09 17:14:46 +02:00
dol_syslog ( get_class ( $this ) . " ::fetch Erreur -1 " );
2006-11-02 02:42:49 +01:00
return - 1 ;
}
}
else
{
2012-05-09 17:14:46 +02:00
dol_syslog ( get_class ( $this ) . " ::fetch Erreur -2 " );
2006-11-02 02:42:49 +01:00
return - 2 ;
}
2005-01-05 16:26:05 +01:00
}
2008-11-10 15:20:02 +01:00
/**
2012-03-18 19:23:01 +01:00
* Load an object from its id and create a new one in database
*
* @ param int $fromid Id of object to clone
2012-03-31 15:42:33 +02:00
* @ param int $option1 1 = Copy content , 0 = Forget content
* @ param int $option2 Not used
2012-03-18 19:23:01 +01:00
* @ return int New id of clone
2008-11-10 15:20:02 +01:00
*/
function createFromClone ( $fromid , $option1 , $option2 )
{
global $user , $langs ;
2009-01-25 23:04:55 +01:00
2008-11-10 15:20:02 +01:00
$error = 0 ;
2009-01-25 23:04:55 +01:00
2008-11-10 15:20:02 +01:00
$object = new Mailing ( $this -> db );
2005-01-05 16:26:05 +01:00
2015-02-26 13:03:17 +01:00
$object -> context [ 'createfromclone' ] = 'createfromclone' ;
2008-11-10 15:20:02 +01:00
$this -> db -> begin ();
2005-01-05 16:26:05 +01:00
2008-11-10 15:20:02 +01:00
// Load source object
$object -> fetch ( $fromid );
$object -> id = 0 ;
$object -> statut = 0 ;
2008-11-20 22:30:23 +01:00
// Clear fields
2012-03-31 15:42:33 +02:00
$object -> titre = $langs -> trans ( " CopyOf " ) . ' ' . $object -> titre . ' ' . dol_print_date ( dol_now ());
2008-11-10 15:20:02 +01:00
// If no option copy content
if ( empty ( $option1 ))
{
2009-01-25 23:04:55 +01:00
// Clear values
2008-11-20 22:30:23 +01:00
$object -> nbemail = 0 ;
$object -> sujet = '' ;
$object -> body = '' ;
2009-05-19 19:14:17 +02:00
$object -> bgcolor = '' ;
$object -> bgimage = '' ;
2008-11-10 15:20:02 +01:00
2008-11-20 22:30:23 +01:00
$object -> email_from = '' ;
$object -> email_replyto = '' ;
$object -> email_errorsto = '' ;
2008-11-10 15:20:02 +01:00
2008-11-20 22:30:23 +01:00
$object -> user_creat = $user -> id ;
$object -> user_valid = '' ;
2008-11-10 15:20:02 +01:00
2008-11-20 22:30:23 +01:00
$object -> date_creat = '' ;
$object -> date_valid = '' ;
$object -> date_envoi = '' ;
2008-11-10 15:20:02 +01:00
}
// Create clone
$result = $object -> create ( $user );
// Other options
2009-01-25 23:04:55 +01:00
if ( $result < 0 )
2008-11-10 15:20:02 +01:00
{
$this -> error = $object -> error ;
$error ++ ;
}
2009-01-25 23:04:55 +01:00
2008-11-10 15:20:02 +01:00
if ( ! $error )
{
2014-04-28 17:18:11 +02:00
//Clone target
if ( ! empty ( $option2 )) {
2015-02-26 13:03:17 +01:00
2014-04-28 17:18:11 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/modules/mailings/modules_mailings.php' ;
2015-02-26 13:03:17 +01:00
2014-04-28 17:18:11 +02:00
$mailing_target = new MailingTargets ( $this -> db );
2015-02-26 13:03:17 +01:00
2014-04-28 17:18:11 +02:00
$target_array = array ();
2015-02-26 13:03:17 +01:00
2014-04-28 17:18:11 +02:00
$sql = " SELECT fk_contact, " ;
$sql .= " lastname, " ;
$sql .= " firstname, " ;
$sql .= " email, " ;
$sql .= " other, " ;
$sql .= " source_url, " ;
$sql .= " source_id , " ;
$sql .= " source_type " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " mailing_cibles " ;
$sql .= " WHERE fk_mailing = " . $fromid ;
2015-02-26 13:03:17 +01:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::createFromClone " , LOG_DEBUG );
2014-04-28 17:18:11 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
if ( $this -> db -> num_rows ( $result ))
{
while ( $obj = $this -> db -> fetch_object ( $result )) {
2015-02-26 13:03:17 +01:00
2014-04-28 17:18:11 +02:00
$target_array [] = array ( 'fk_contact' => $obj -> fk_contact ,
'lastname' => $obj -> lastname ,
'firstname' => $obj -> firstname ,
2015-02-26 13:03:17 +01:00
'email' => $obj -> email ,
2014-04-28 17:18:11 +02:00
'other' => $obj -> other ,
'source_url' => $obj -> source_url ,
'source_id' => $obj -> source_id ,
'source_type' => $obj -> source_type );
}
}
}
else
{
$this -> error = $this -> db -> lasterror ();
return - 1 ;
}
2015-02-26 13:03:17 +01:00
2014-04-28 17:18:11 +02:00
$mailing_target -> add_to_target ( $object -> id , $target_array );
}
2008-11-10 15:20:02 +01:00
}
2009-01-25 23:04:55 +01:00
2015-02-26 13:03:17 +01:00
unset ( $object -> context [ 'createfromclone' ]);
2008-11-10 15:20:02 +01:00
// End
if ( ! $error )
{
$this -> db -> commit ();
return $object -> id ;
}
else
{
$this -> db -> rollback ();
return - 1 ;
}
2005-01-05 16:26:05 +01:00
}
2008-11-10 15:20:02 +01:00
/**
2012-03-18 19:23:01 +01:00
* Validate emailing
*
* @ param User $user Objet user qui valide
* @ return int < 0 if KO , > 0 if OK
2008-11-10 15:20:02 +01:00
*/
function valid ( $user )
2005-01-05 16:26:05 +01:00
{
2012-03-23 18:19:50 +01:00
$now = dol_now ();
2012-03-31 15:42:33 +02:00
2008-11-10 15:20:02 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " mailing " ;
2014-03-15 23:12:00 +01:00
$sql .= " SET statut = 1, date_valid = ' " . $this -> db -> idate ( $now ) . " ', fk_user_valid= " . $user -> id ;
2009-02-18 22:48:07 +01:00
$sql .= " WHERE rowid = " . $this -> id ;
2008-11-10 15:20:02 +01:00
2014-06-12 11:31:53 +02:00
dol_syslog ( " Mailing::valid " , LOG_DEBUG );
2009-02-18 22:48:07 +01:00
if ( $this -> db -> query ( $sql ))
2008-11-10 15:20:02 +01:00
{
2009-02-18 22:48:07 +01:00
return 1 ;
2008-11-10 15:20:02 +01:00
}
else
{
2009-02-18 22:48:07 +01:00
$this -> error = $this -> db -> lasterror ();
return - 1 ;
2008-11-10 15:20:02 +01:00
}
2005-01-05 16:26:05 +01:00
}
2008-11-10 15:20:02 +01:00
2009-02-18 22:48:07 +01:00
2008-11-10 15:20:02 +01:00
/**
2012-03-18 19:23:01 +01:00
* Delete emailing
*
* @ param int $rowid id du mailing a supprimer
* @ return int 1 en cas de succes
2008-11-10 15:20:02 +01:00
*/
function delete ( $rowid )
2005-01-05 16:26:05 +01:00
{
2008-11-10 15:20:02 +01:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " mailing " ;
2009-02-18 22:48:07 +01:00
$sql .= " WHERE rowid = " . $rowid ;
2008-11-10 15:20:02 +01:00
2014-06-12 11:31:53 +02:00
dol_syslog ( " Mailing::delete " , LOG_DEBUG );
2009-02-18 22:48:07 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
2015-06-01 12:29:10 +02:00
return $this -> delete_targets ();
2009-02-18 22:48:07 +01:00
}
else
{
$this -> error = $this -> db -> lasterror ();
return - 1 ;
}
}
2018-01-29 12:46:07 +01:00
2018-09-02 18:49:23 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2015-06-01 12:29:10 +02:00
/**
* Delete targets emailing
*
* @ return int 1 if OK , 0 if error
*/
function delete_targets ()
{
2018-09-02 18:49:23 +02:00
// phpcs:enable
2015-06-01 12:29:10 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " mailing_cibles " ;
$sql .= " WHERE fk_mailing = " . $this -> id ;
dol_syslog ( " Mailing::delete_targets " , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
return 1 ;
}
else
{
$this -> error = $this -> db -> lasterror ();
return 0 ;
}
}
2009-02-18 22:48:07 +01:00
2018-09-02 18:49:23 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2009-02-18 22:48:07 +01:00
/**
2012-03-18 19:23:01 +01:00
* Change status of each recipient
*
* @ param User $user Objet user qui valide
* @ return int < 0 if KO , > 0 if OK
2009-02-18 22:48:07 +01:00
*/
function reset_targets_status ( $user )
{
2018-09-02 18:49:23 +02:00
// phpcs:enable
2009-02-18 22:48:07 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " mailing_cibles " ;
$sql .= " SET statut = 0 " ;
$sql .= " WHERE fk_mailing = " . $this -> id ;
2014-06-12 11:31:53 +02:00
dol_syslog ( " Mailing::reset_targets_status " , LOG_DEBUG );
2009-02-18 22:48:07 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
return 1 ;
}
else
{
$this -> error = $this -> db -> lasterror ();
return - 1 ;
}
2005-01-05 16:26:05 +01:00
}
2008-11-10 15:20:02 +01:00
2018-01-29 12:46:07 +01:00
2016-02-12 14:21:44 +01:00
/**
* Count number of target with status
*
2018-01-29 12:46:07 +01:00
* @ param string $mode Mode ( 'alreadysent' = Sent success or error , 'alreadysentok' = Sent success , 'alreadysentko' = Sent error )
2016-02-13 08:10:13 +01:00
* @ return int Nb of target with status
2016-02-12 14:21:44 +01:00
*/
function countNbOfTargets ( $mode )
{
$sql = " SELECT COUNT(rowid) as nb FROM " . MAIN_DB_PREFIX . " mailing_cibles " ;
$sql .= " WHERE fk_mailing = " . $this -> id ;
if ( $mode == 'alreadysent' ) $sql .= " AND statut <> 0 " ;
2018-01-29 12:46:07 +01:00
elseif ( $mode == 'alreadysentok' ) $sql .= " AND statut > 0 " ;
elseif ( $mode == 'alreadysentko' ) $sql .= " AND statut = -1 " ;
else
2016-02-12 14:21:44 +01:00
{
$this -> error = 'BadValueForParameterMode' ;
return - 2 ;
}
2018-01-29 12:46:07 +01:00
2016-02-12 14:21:44 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$obj = $this -> db -> fetch_object ( $resql );
if ( $obj ) return $obj -> nb ;
}
else
{
$this -> error = $this -> db -> lasterror ();
return - 1 ;
}
return 0 ;
}
2018-01-29 12:46:07 +01:00
2008-11-10 15:20:02 +01:00
2018-09-23 15:58:33 +02:00
/**
* Return a link to the object card ( with optionaly the picto )
*
* @ param int $withpicto Include picto in link ( 0 = No picto , 1 = Include picto into link , 2 = Only picto )
* @ param string $option On what the link point to ( 'nolink' , ... )
* @ param int $notooltip 1 = Disable tooltip
* @ param string $morecss Add more css on link
* @ param int $save_lastsearch_value - 1 = Auto , 0 = No save of lastsearch_values when clicking , 1 = Save lastsearch_values whenclicking
* @ return string String with URL
*/
function getNomUrl ( $withpicto = 0 , $option = '' , $notooltip = 0 , $morecss = '' , $save_lastsearch_value =- 1 )
{
global $db , $conf , $langs , $hookmanager ;
global $dolibarr_main_authentication , $dolibarr_main_demo ;
global $menumanager ;
if ( ! empty ( $conf -> dol_no_mouse_hover )) $notooltip = 1 ; // Force disable tooltips
$result = '' ;
$companylink = '' ;
$label = '<u>' . $langs -> trans ( " ShowEmailing " ) . '</u>' ;
$label .= '<br>' ;
$label .= '<b>' . $langs -> trans ( 'Ref' ) . ':</b> ' . $this -> ref ;
$url = DOL_URL_ROOT . '/comm/mailing/card.php?id=' . $this -> id ;
if ( $option != 'nolink' )
{
// Add param to save lastsearch_values or not
$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 ( $add_save_lastsearch_values ) $url .= '&save_lastsearch_values=1' ;
}
$linkclose = '' ;
if ( empty ( $notooltip ))
{
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ))
{
$label = $langs -> trans ( " ShowEmailing " );
$linkclose .= ' alt="' . dol_escape_htmltag ( $label , 1 ) . '"' ;
}
$linkclose .= ' title="' . dol_escape_htmltag ( $label , 1 ) . '"' ;
$linkclose .= ' class="classfortooltip' . ( $morecss ? ' ' . $morecss : '' ) . '"' ;
/*
$hookmanager -> initHooks ( array ( 'myobjectdao' ));
$parameters = array ( 'id' => $this -> id );
$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 ;
*/
}
else $linkclose = ( $morecss ? ' class="' . $morecss . '"' : '' );
$linkstart = '<a href="' . $url . '"' ;
$linkstart .= $linkclose . '>' ;
$linkend = '</a>' ;
$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 != 2 ) $result .= $this -> ref ;
$result .= $linkend ;
//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
global $action ;
$hookmanager -> initHooks ( array ( 'emailingdao' ));
$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
if ( $reshook > 0 ) $result = $hookmanager -> resPrint ;
else $result .= $hookmanager -> resPrint ;
return $result ;
}
2006-06-25 17:52:12 +02:00
/**
2018-01-29 12:46:07 +01:00
* Return label of status of emailing ( draft , validated , ... )
2012-03-18 19:23:01 +01:00
*
* @ param int $mode 0 = libelle long , 1 = libelle court , 2 = Picto + Libelle court , 3 = Picto , 4 = Picto + Libelle long
* @ return string Label
2006-06-25 17:52:12 +02:00
*/
function getLibStatut ( $mode = 0 )
{
return $this -> LibStatut ( $this -> statut , $mode );
}
2018-09-02 11:12:07 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2006-06-25 17:52:12 +02:00
/**
2012-03-18 19:23:01 +01:00
* Renvoi le libelle d ' un statut donne
*
* @ param int $statut Id statut
* @ param int $mode 0 = libelle long , 1 = libelle court , 2 = Picto + Libelle court , 3 = Picto , 4 = Picto + Libelle long , 5 = Libelle court + Picto
* @ return string Label
2006-06-25 17:52:12 +02:00
*/
function LibStatut ( $statut , $mode = 0 )
{
2018-09-02 11:12:07 +02:00
// phpcs:enable
2006-06-25 17:52:12 +02:00
global $langs ;
$langs -> load ( 'mails' );
2018-09-02 11:12:07 +02:00
if ( $mode == 0 || $mode == 1 )
2006-06-25 17:52:12 +02:00
{
2009-12-17 16:52:37 +01:00
return $langs -> trans ( $this -> statuts [ $statut ]);
2006-06-25 17:52:12 +02:00
}
2018-09-02 11:12:07 +02:00
elseif ( $mode == 2 )
2006-06-25 17:52:12 +02:00
{
2009-12-17 16:52:37 +01:00
if ( $statut == 0 ) return img_picto ( $langs -> trans ( $this -> statuts [ $statut ]), 'statut0' ) . ' ' . $langs -> trans ( $this -> statuts [ $statut ]);
if ( $statut == 1 ) return img_picto ( $langs -> trans ( $this -> statuts [ $statut ]), 'statut1' ) . ' ' . $langs -> trans ( $this -> statuts [ $statut ]);
if ( $statut == 2 ) return img_picto ( $langs -> trans ( $this -> statuts [ $statut ]), 'statut3' ) . ' ' . $langs -> trans ( $this -> statuts [ $statut ]);
if ( $statut == 3 ) return img_picto ( $langs -> trans ( $this -> statuts [ $statut ]), 'statut6' ) . ' ' . $langs -> trans ( $this -> statuts [ $statut ]);
2006-06-25 17:52:12 +02:00
}
2018-09-02 11:12:07 +02:00
elseif ( $mode == 3 )
2006-06-25 17:52:12 +02:00
{
if ( $statut == 0 ) return img_picto ( $langs -> trans ( $this -> statuts [ $statut ]), 'statut0' );
if ( $statut == 1 ) return img_picto ( $langs -> trans ( $this -> statuts [ $statut ]), 'statut1' );
if ( $statut == 2 ) return img_picto ( $langs -> trans ( $this -> statuts [ $statut ]), 'statut3' );
if ( $statut == 3 ) return img_picto ( $langs -> trans ( $this -> statuts [ $statut ]), 'statut6' );
}
2018-09-02 11:12:07 +02:00
elseif ( $mode == 4 )
2006-06-25 17:52:12 +02:00
{
2009-12-17 16:52:37 +01:00
if ( $statut == 0 ) return img_picto ( $langs -> trans ( $this -> statuts [ $statut ]), 'statut0' ) . ' ' . $langs -> trans ( $this -> statuts [ $statut ]);
if ( $statut == 1 ) return img_picto ( $langs -> trans ( $this -> statuts [ $statut ]), 'statut1' ) . ' ' . $langs -> trans ( $this -> statuts [ $statut ]);
if ( $statut == 2 ) return img_picto ( $langs -> trans ( $this -> statuts [ $statut ]), 'statut3' ) . ' ' . $langs -> trans ( $this -> statuts [ $statut ]);
if ( $statut == 3 ) return img_picto ( $langs -> trans ( $this -> statuts [ $statut ]), 'statut6' ) . ' ' . $langs -> trans ( $this -> statuts [ $statut ]);
2006-06-25 17:52:12 +02:00
}
2018-09-02 11:12:07 +02:00
elseif ( $mode == 5 )
2006-06-25 17:52:12 +02:00
{
2009-12-17 16:52:37 +01:00
if ( $statut == 0 ) return $langs -> trans ( $this -> statuts [ $statut ]) . ' ' . img_picto ( $langs -> trans ( $this -> statuts [ $statut ]), 'statut0' );
if ( $statut == 1 ) return $langs -> trans ( $this -> statuts [ $statut ]) . ' ' . img_picto ( $langs -> trans ( $this -> statuts [ $statut ]), 'statut1' );
if ( $statut == 2 ) return $langs -> trans ( $this -> statuts [ $statut ]) . ' ' . img_picto ( $langs -> trans ( $this -> statuts [ $statut ]), 'statut3' );
if ( $statut == 3 ) return $langs -> trans ( $this -> statuts [ $statut ]) . ' ' . img_picto ( $langs -> trans ( $this -> statuts [ $statut ]), 'statut6' );
2006-06-25 17:52:12 +02:00
}
}
2008-11-10 15:20:02 +01:00
2015-02-26 13:03:17 +01:00
2014-05-29 14:26:27 +02:00
/**
* Renvoi le libelle d ' un statut donne
2016-11-11 14:03:57 +01:00
* TODO Add class mailin_target . class . php
2014-05-29 14:26:27 +02:00
*
* @ param int $statut Id statut
* @ param int $mode 0 = libelle long , 1 = libelle court , 2 = Picto + Libelle court , 3 = Picto , 4 = Picto + Libelle long , 5 = Libelle court + Picto
2016-11-11 14:03:57 +01:00
* @ param strin $desc Desc error
2014-05-29 14:26:27 +02:00
* @ return string Label
*/
2017-05-13 18:50:55 +02:00
public static function libStatutDest ( $statut , $mode = 0 , $desc = '' )
2014-05-29 14:26:27 +02:00
{
global $langs ;
$langs -> load ( 'mails' );
2015-02-26 13:03:17 +01:00
2014-05-29 14:26:27 +02:00
if ( $mode == 0 )
{
2015-12-04 17:32:17 +01:00
return $langs -> trans ( 'MailingStatusError' );
2014-05-29 14:26:27 +02:00
}
2018-09-02 11:12:07 +02:00
elseif ( $mode == 1 )
2014-05-29 14:26:27 +02:00
{
2015-12-04 17:32:17 +01:00
return $langs -> trans ( 'MailingStatusSent' );
2014-05-29 14:26:27 +02:00
}
2018-09-02 11:12:07 +02:00
elseif ( $mode == 2 )
2014-05-29 14:26:27 +02:00
{
2016-11-11 14:03:57 +01:00
if ( $statut ==- 1 ) return $langs -> trans ( " MailingStatusError " ) . ' ' . img_error ( $desc );
2017-01-29 20:33:08 +01:00
if ( $statut == 1 ) return $langs -> trans ( " MailingStatusSent " ) . ' ' . img_picto ( $langs -> trans ( " MailingStatusSent " ), 'statut6' );
if ( $statut == 2 ) return $langs -> trans ( " MailingStatusRead " ) . ' ' . img_picto ( $langs -> trans ( " MailingStatusRead " ), 'statut4' );
if ( $statut == 3 ) return $langs -> trans ( " MailingStatusNotContact " ) . ' ' . img_picto ( $langs -> trans ( " MailingStatusNotContact " ), 'statut3' );
2014-05-29 14:26:27 +02:00
}
2018-09-02 11:12:07 +02:00
elseif ( $mode == 3 )
2014-05-29 14:26:27 +02:00
{
2016-11-11 14:03:57 +01:00
if ( $statut ==- 1 ) return $langs -> trans ( " MailingStatusError " ) . ' ' . img_error ( $desc );
2017-01-29 20:33:08 +01:00
if ( $statut == 1 ) return $langs -> trans ( " MailingStatusSent " ) . ' ' . img_picto ( $langs -> trans ( " MailingStatusSent " ), 'statut6' );
if ( $statut == 2 ) return $langs -> trans ( " MailingStatusRead " ) . ' ' . img_picto ( $langs -> trans ( " MailingStatusRead " ), 'statut4' );
if ( $statut == 3 ) return $langs -> trans ( " MailingStatusNotContact " ) . ' ' . img_picto ( $langs -> trans ( " MailingStatusNotContact " ), 'statut3' );
2014-05-29 14:26:27 +02:00
}
2018-09-02 11:12:07 +02:00
elseif ( $mode == 4 )
2014-05-29 14:26:27 +02:00
{
2016-11-11 14:03:57 +01:00
if ( $statut ==- 1 ) return $langs -> trans ( " MailingStatusError " ) . ' ' . img_error ( $desc );
2017-01-29 20:33:08 +01:00
if ( $statut == 1 ) return $langs -> trans ( " MailingStatusSent " ) . ' ' . img_picto ( $langs -> trans ( " MailingStatusSent " ), 'statut6' );
if ( $statut == 2 ) return $langs -> trans ( " MailingStatusRead " ) . ' ' . img_picto ( $langs -> trans ( " MailingStatusRead " ), 'statut4' );
if ( $statut == 3 ) return $langs -> trans ( " MailingStatusNotContact " ) . ' ' . img_picto ( $langs -> trans ( " MailingStatusNotContact " ), 'statut3' );
2014-05-29 14:26:27 +02:00
}
2018-09-02 11:12:07 +02:00
elseif ( $mode == 5 )
2014-05-29 14:26:27 +02:00
{
2017-01-29 20:33:08 +01:00
if ( $statut ==- 1 ) return $langs -> trans ( " MailingStatusError " ) . ' ' . img_error ( $desc );
if ( $statut == 1 ) return $langs -> trans ( " MailingStatusSent " ) . ' ' . img_picto ( $langs -> trans ( " MailingStatusSent " ), 'statut6' );
if ( $statut == 2 ) return $langs -> trans ( " MailingStatusRead " ) . ' ' . img_picto ( $langs -> trans ( " MailingStatusRead " ), 'statut4' );
if ( $statut == 3 ) return $langs -> trans ( " MailingStatusNotContact " ) . ' ' . img_picto ( $langs -> trans ( " MailingStatusNotContact " ), 'statut3' );
}
2018-09-02 11:12:07 +02:00
elseif ( $mode == 6 )
2017-01-29 20:33:08 +01:00
{
if ( $statut ==- 1 ) return $langs -> trans ( " MailingStatusError " ) . ' ' . img_error ( $desc );
if ( $statut == 1 ) return $langs -> trans ( " MailingStatusSent " ) . ' ' . img_picto ( $langs -> trans ( " MailingStatusSent " ), 'statut6' );
if ( $statut == 2 ) return $langs -> trans ( " MailingStatusRead " ) . ' ' . img_picto ( $langs -> trans ( " MailingStatusRead " ), 'statut4' );
if ( $statut == 3 ) return $langs -> trans ( " MailingStatusNotContact " ) . ' ' . img_picto ( $langs -> trans ( " MailingStatusNotContact " ), 'statut3' );
2014-05-29 14:26:27 +02:00
}
}
2005-01-05 16:26:05 +01:00
}