2012-08-22 23:27:53 +02:00
< ? php
2012-03-23 20:03:57 +01:00
/* Copyright ( C ) 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2019-12-13 15:52:08 +01:00
* Copyright ( C ) 2005 - 2019 Laurent Destailleur < eldy @ uers . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2016 Regis Houssin < regis . houssin @ inodbox . com >
2021-05-08 09:20:59 +02:00
* Copyright ( C ) 2021 Waël Almoman < info @ almoman . 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2005-01-05 16:26:05 +01:00
*/
2005-04-07 01:49:06 +02:00
/**
2014-09-18 21:18:25 +02:00
* \file htdocs / comm / mailing / card . php
2009-04-05 22:14:49 +02:00
* \ingroup mailing
2009-05-16 18:51:09 +02:00
* \brief Fiche mailing , onglet general
2009-04-05 22:14:49 +02:00
*/
2005-01-14 20:24:00 +01:00
2020-11-27 20:20:04 +01:00
if ( ! defined ( 'NOSTYLECHECK' )) {
define ( 'NOSTYLECHECK' , '1' );
}
2013-03-24 19:00:58 +01:00
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/emailing.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/comm/mailing/class/mailing.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php' ;
2016-03-05 12:20:58 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php' ;
2005-01-05 16:26:05 +01:00
2018-05-26 20:32:23 +02:00
// Load translation files required by the page
2005-01-14 20:24:00 +01:00
$langs -> load ( " mails " );
2020-04-10 10:59:32 +02:00
$id = ( GETPOST ( 'mailid' , 'int' ) ? GETPOST ( 'mailid' , 'int' ) : GETPOST ( 'id' , 'int' ));
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2021-03-25 16:59:47 +01:00
$cancel = GETPOST ( 'cancel' );
2020-04-10 10:59:32 +02:00
$confirm = GETPOST ( 'confirm' , 'alpha' );
$urlfrom = GETPOST ( 'urlfrom' );
2012-06-14 20:08:46 +02:00
2020-04-10 10:59:32 +02:00
$object = new Mailing ( $db );
2021-06-04 11:53:12 +02:00
2020-04-10 10:59:32 +02:00
$result = $object -> fetch ( $id );
2012-03-23 20:03:57 +01:00
2012-06-13 09:26:29 +02:00
$extrafields = new ExtraFields ( $db );
2013-04-01 19:43:26 +02:00
// fetch optionals attributes and labels
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
2013-04-01 19:43:26 +02:00
2017-06-10 12:56:28 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2019-11-13 19:35:39 +01:00
$hookmanager -> initHooks ( array ( 'mailingcard' , 'globalcard' ));
2012-03-23 20:03:57 +01:00
2014-05-17 19:02:47 +02:00
// Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
2019-11-13 19:35:39 +01:00
$object -> substitutionarray = FormMail :: getAvailableSubstitKey ( 'emailing' );
2017-09-22 14:34:31 +02:00
// Set $object->substitutionarrayfortest
2019-11-13 19:35:39 +01:00
$signature = (( ! empty ( $user -> signature ) && empty ( $conf -> global -> MAIN_MAIL_DO_NOT_USE_SIGN )) ? $user -> signature : '' );
2017-09-22 14:34:31 +02:00
2019-11-13 19:35:39 +01:00
$targetobject = null ; // Not defined with mass emailing
2017-09-22 14:34:31 +02:00
2019-11-13 19:35:39 +01:00
$parameters = array ( 'mode' => 'emailing' );
$substitutionarray = FormMail :: getAvailableSubstitKey ( 'emailing' , $targetobject );
2017-09-22 14:34:31 +02:00
$object -> substitutionarrayfortest = $substitutionarray ;
2013-11-16 13:00:21 +01:00
2014-11-29 13:50:41 +01:00
// List of sending methods
2019-11-13 19:35:39 +01:00
$listofmethods = array ();
$listofmethods [ 'mail' ] = 'PHP mail function' ;
$listofmethods [ 'smtps' ] = 'SMTP/SMTPS socket library' ;
2014-11-29 13:50:41 +01:00
2021-03-29 22:43:39 +02:00
// Security check
2021-06-04 11:53:12 +02:00
if ( empty ( $user -> rights -> mailing -> lire ) || ( empty ( $conf -> global -> EXTERNAL_USERS_ARE_AUTHORIZED ) && $user -> socid > 0 )) {
2021-03-29 22:43:39 +02:00
accessforbidden ();
}
2014-11-29 13:50:41 +01:00
2005-01-14 20:24:00 +01:00
2012-06-15 11:20:09 +02:00
/*
* Actions
2012-06-13 09:26:29 +02:00
*/
2019-11-13 19:35:39 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2020-11-27 20:20:04 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2012-06-13 09:26:29 +02:00
2020-11-27 20:20:04 +01:00
if ( empty ( $reshook )) {
2015-01-17 19:28:27 +01:00
// Action clone object
2020-11-27 20:20:04 +01:00
if ( $action == 'confirm_clone' && $confirm == 'yes' ) {
if ( ! GETPOST ( " clone_content " , 'alpha' ) && ! GETPOST ( " clone_receivers " , 'alpha' )) {
2015-11-06 09:36:16 +01:00
setEventMessages ( $langs -> trans ( " NoCloneOptionsSpecified " ), null , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2020-04-03 02:29:10 +02:00
$result = $object -> createFromClone ( $user , $object -> id , GETPOST ( " clone_content " , 'alpha' ), GETPOST ( " clone_receivers " , 'alpha' ));
2020-11-27 20:20:04 +01:00
if ( $result > 0 ) {
2015-01-17 19:28:27 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . '?id=' . $result );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2015-11-06 09:36:16 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-01-17 19:28:27 +01:00
}
2008-11-20 22:30:23 +01:00
}
2020-10-31 14:32:18 +01:00
$action = '' ;
2008-11-10 15:20:02 +01:00
}
2015-01-17 19:28:27 +01:00
// Action send emailing for everybody
2020-11-27 20:20:04 +01:00
if ( $action == 'sendallconfirmed' && $confirm == 'yes' ) {
if ( empty ( $conf -> global -> MAILING_LIMIT_SENDBYWEB )) {
2015-02-15 15:01:28 +01:00
// As security measure, we don't allow send from the GUI
2015-11-06 09:36:16 +01:00
setEventMessages ( $langs -> trans ( " MailingNeedCommand " ), null , 'warnings' );
setEventMessages ( '<textarea cols="70" rows="' . ROWS_2 . '" wrap="soft">php ./scripts/emailings/mailing-send.php ' . $object -> id . '</textarea>' , null , 'warnings' );
setEventMessages ( $langs -> trans ( " MailingNeedCommand2 " ), null , 'warnings' );
2019-11-13 19:35:39 +01:00
$action = '' ;
2020-11-27 20:20:04 +01:00
} elseif ( $conf -> global -> MAILING_LIMIT_SENDBYWEB < 0 ) {
2015-11-06 09:36:16 +01:00
setEventMessages ( $langs -> trans ( " NotEnoughPermissions " ), null , 'warnings' );
2019-11-13 19:35:39 +01:00
$action = '' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$upload_dir = $conf -> mailing -> dir_output . " / " . get_exdir ( $object -> id , 2 , 0 , 1 , $object , 'mailing' );
2008-02-29 17:26:38 +01:00
2020-11-27 20:20:04 +01:00
if ( $object -> statut == 0 ) {
2019-01-27 11:55:16 +01:00
dol_print_error ( '' , 'ErrorMailIsNotValidated' );
2015-01-17 19:28:27 +01:00
exit ;
}
2012-04-05 21:02:00 +02:00
2015-01-17 19:28:27 +01:00
$id = $object -> id ;
$subject = $object -> sujet ;
$message = $object -> body ;
$from = $object -> email_from ;
2021-02-23 18:59:19 +01:00
$replyto = $object -> email_replyto ;
2015-01-17 19:28:27 +01:00
$errorsto = $object -> email_errorsto ;
2020-10-14 18:26:05 +02:00
// Is the message in html
2019-11-13 19:35:39 +01:00
$msgishtml = - 1 ; // Unknown by default
2020-11-27 20:20:04 +01:00
if ( preg_match ( '/[\s\t]*<html>/i' , $message )) {
$msgishtml = 1 ;
}
2015-01-17 19:28:27 +01:00
// Warning, we must not use begin-commit transaction here
// because we want to save update for each mail sent.
2019-11-13 19:35:39 +01:00
$nbok = 0 ; $nbko = 0 ;
2015-01-17 19:28:27 +01:00
2020-10-14 18:26:05 +02:00
// We choose mails not already sent for this mailing (statut=0)
// or sent in error (statut=-1)
2017-11-21 11:15:33 +01:00
$sql = " SELECT mc.rowid, mc.fk_mailing, mc.lastname, mc.firstname, mc.email, mc.other, mc.source_url, mc.source_id, mc.source_type, mc.tag " ;
2015-01-17 19:28:27 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " mailing_cibles as mc " ;
2021-03-30 17:53:25 +02:00
$sql .= " WHERE mc.statut < 1 AND mc.fk_mailing = " . (( int ) $object -> id );
2019-11-13 19:35:39 +01:00
$sql .= " ORDER BY mc.statut DESC " ; // first status 0, then status -1
2015-01-17 19:28:27 +01:00
2015-01-18 17:13:42 +01:00
dol_syslog ( " card.php: select targets " , LOG_DEBUG );
2019-11-13 19:35:39 +01:00
$resql = $db -> query ( $sql );
2020-11-27 20:20:04 +01:00
if ( $resql ) {
2020-10-14 18:26:05 +02:00
$num = $db -> num_rows ( $resql ); // Number of possible recipients
2008-08-04 01:45:53 +02:00
2020-11-27 20:20:04 +01:00
if ( $num ) {
2015-01-18 17:13:42 +01:00
dol_syslog ( " comm/mailing/card.php: nb of targets = " . $num , LOG_DEBUG );
2009-01-25 23:04:55 +01:00
2019-11-13 19:35:39 +01:00
$now = dol_now ();
2009-01-25 23:04:55 +01:00
2020-10-14 18:26:05 +02:00
// Positioning date of start sending
2021-08-27 16:33:03 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " mailing SET date_envoi=' " . $db -> idate ( $now ) . " ' WHERE rowid= " . (( int ) $object -> id );
2019-11-13 19:35:39 +01:00
$resql2 = $db -> query ( $sql );
2020-11-27 20:20:04 +01:00
if ( ! $resql2 ) {
2015-01-17 19:28:27 +01:00
dol_print_error ( $db );
2010-04-17 15:23:50 +02:00
}
2021-05-11 20:30:57 +02:00
$thirdpartystatic = new Societe ( $db );
2015-01-17 19:28:27 +01:00
// Loop on each email and send it
$i = 0 ;
2009-01-25 23:04:55 +01:00
2020-11-27 20:20:04 +01:00
while ( $i < $num && $i < $conf -> global -> MAILING_LIMIT_SENDBYWEB ) {
2017-09-15 13:43:16 +02:00
// Here code is common with same loop ino mailing-send.php
2019-11-13 19:35:39 +01:00
$res = 1 ;
$now = dol_now ();
2015-01-17 19:28:27 +01:00
$obj = $db -> fetch_object ( $resql );
// sendto en RFC2822
2019-01-27 11:55:16 +01:00
$sendto = str_replace ( ',' , ' ' , dolGetFirstLastname ( $obj -> firstname , $obj -> lastname )) . " < " . $obj -> email . " > " ;
2015-01-17 19:28:27 +01:00
// Make substitutions on topic and body. From (AA=YY;BB=CC;...) we keep YY, CC, ...
2019-11-13 19:35:39 +01:00
$other = explode ( ';' , $obj -> other );
$tmpfield = explode ( '=' , $other [ 0 ], 2 ); $other1 = ( isset ( $tmpfield [ 1 ]) ? $tmpfield [ 1 ] : $tmpfield [ 0 ]);
2020-10-31 14:32:18 +01:00
$tmpfield = explode ( '=' , $other [ 1 ], 2 ); $other2 = ( isset ( $tmpfield [ 1 ]) ? $tmpfield [ 1 ] : $tmpfield [ 0 ]);
$tmpfield = explode ( '=' , $other [ 2 ], 2 ); $other3 = ( isset ( $tmpfield [ 1 ]) ? $tmpfield [ 1 ] : $tmpfield [ 0 ]);
$tmpfield = explode ( '=' , $other [ 3 ], 2 ); $other4 = ( isset ( $tmpfield [ 1 ]) ? $tmpfield [ 1 ] : $tmpfield [ 0 ]);
$tmpfield = explode ( '=' , $other [ 4 ], 2 ); $other5 = ( isset ( $tmpfield [ 1 ]) ? $tmpfield [ 1 ] : $tmpfield [ 0 ]);
2017-09-22 14:34:31 +02:00
2020-10-31 14:32:18 +01:00
$signature = (( ! empty ( $user -> signature ) && empty ( $conf -> global -> MAIN_MAIL_DO_NOT_USE_SIGN )) ? $user -> signature : '' );
2016-02-08 12:20:40 +01:00
2020-10-31 14:32:18 +01:00
$targetobject = null ; // Not defined with mass emailing
$parameters = array ( 'mode' => 'emailing' );
$substitutionarray = getCommonSubstitutionArray ( $langs , 0 , array ( 'object' , 'objectamount' ), $targetobject ); // Note: On mass emailing, this is null because be don't know object
2017-09-22 14:34:31 +02:00
2020-10-31 14:32:18 +01:00
// Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
2017-09-22 14:34:31 +02:00
$substitutionarray [ '__ID__' ] = $obj -> source_id ;
2021-05-11 12:33:35 +02:00
if ( $obj -> source_type == " thirdparty " ) {
2021-05-11 20:30:57 +02:00
$result = $thirdpartystatic -> fetch ( $obj -> source_id );
2021-05-11 12:33:35 +02:00
2021-05-11 20:30:57 +02:00
if ( $result > 0 ) {
$substitutionarray [ '__THIRDPARTY_CUSTOMER_CODE__' ] = $thirdpartystatic -> code_client ;
2022-01-11 13:31:16 +01:00
} else {
$substitutionarray [ '__THIRDPARTY_CUSTOMER_CODE__' ] = '' ;
2021-05-11 20:30:57 +02:00
}
2021-05-11 12:33:35 +02:00
}
2017-09-22 14:34:31 +02:00
$substitutionarray [ '__EMAIL__' ] = $obj -> email ;
$substitutionarray [ '__LASTNAME__' ] = $obj -> lastname ;
$substitutionarray [ '__FIRSTNAME__' ] = $obj -> firstname ;
$substitutionarray [ '__MAILTOEMAIL__' ] = '<a href="mailto:' . $obj -> email . '">' . $obj -> email . '</a>' ;
$substitutionarray [ '__OTHER1__' ] = $other1 ;
$substitutionarray [ '__OTHER2__' ] = $other2 ;
$substitutionarray [ '__OTHER3__' ] = $other3 ;
$substitutionarray [ '__OTHER4__' ] = $other4 ;
$substitutionarray [ '__OTHER5__' ] = $other5 ;
2019-11-13 19:35:39 +01:00
$substitutionarray [ '__USER_SIGNATURE__' ] = $signature ; // Signature is empty when ran from command line or taken from user in parameter)
2021-03-05 17:48:55 +01:00
$substitutionarray [ '__CHECK_READ__' ] = '<img src="' . DOL_MAIN_URL_ROOT . '/public/emailing/mailing-read.php?tag=' . urlencode ( $obj -> tag ) . '&securitykey=' . urlencode ( $conf -> global -> MAILING_EMAIL_UNSUBSCRIBE_KEY ) . '&email=' . urlencode ( $obj -> email ) . '&mtid=' . $obj -> rowid . '" width="1" height="1" style="width:1px;height:1px" border="0"/>' ;
2021-11-22 02:35:55 +01:00
$substitutionarray [ '__UNSUBSCRIBE__' ] = '<a href="' . DOL_MAIN_URL_ROOT . '/public/emailing/mailing-unsubscribe.php?tag=' . urlencode ( $obj -> tag ) . '&unsuscrib=1&securitykey=' . urlencode ( $conf -> global -> MAILING_EMAIL_UNSUBSCRIBE_KEY ) . '&email=' . urlencode ( $obj -> email ) . '&mtid=' . $obj -> rowid . '" target="_blank" rel="noopener noreferrer">' . $langs -> trans ( " MailUnsubcribe " ) . '</a>' ;
2021-05-11 21:02:27 +02:00
$substitutionarray [ '__UNSUBSCRIBE_URL__' ] = DOL_MAIN_URL_ROOT . '/public/emailing/mailing-unsubscribe.php?tag=' . urlencode ( $obj -> tag ) . '&unsuscrib=1&securitykey=' . urlencode ( $conf -> global -> MAILING_EMAIL_UNSUBSCRIBE_KEY ) . '&email=' . urlencode ( $obj -> email ) . '&mtid=' . $obj -> rowid ;
2017-09-22 14:34:31 +02:00
2017-09-15 13:43:16 +02:00
$onlinepaymentenabled = 0 ;
2020-11-27 20:20:04 +01:00
if ( ! empty ( $conf -> paypal -> enabled )) {
$onlinepaymentenabled ++ ;
}
if ( ! empty ( $conf -> paybox -> enabled )) {
$onlinepaymentenabled ++ ;
}
if ( ! empty ( $conf -> stripe -> enabled )) {
$onlinepaymentenabled ++ ;
}
if ( $onlinepaymentenabled && ! empty ( $conf -> global -> PAYMENT_SECURITY_TOKEN )) {
2021-05-04 00:58:29 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/payments.lib.php' ;
2021-05-04 21:57:59 +02:00
$substitutionarray [ '__ONLINEPAYMENTLINK_MEMBER__' ] = getHtmlOnlinePaymentLink ( 'member' , $obj -> source_id );
$substitutionarray [ '__ONLINEPAYMENTLINK_DONATION__' ] = getHtmlOnlinePaymentLink ( 'donation' , $obj -> source_id );
$substitutionarray [ '__ONLINEPAYMENTLINK_ORDER__' ] = getHtmlOnlinePaymentLink ( 'order' , $obj -> source_id );
$substitutionarray [ '__ONLINEPAYMENTLINK_INVOICE__' ] = getHtmlOnlinePaymentLink ( 'invoice' , $obj -> source_id );
$substitutionarray [ '__ONLINEPAYMENTLINK_CONTRACTLINE__' ] = getHtmlOnlinePaymentLink ( 'contractline' , $obj -> source_id );
2021-05-04 00:58:29 +02:00
2019-11-13 19:35:39 +01:00
$substitutionarray [ '__SECUREKEYPAYMENT__' ] = dol_hash ( $conf -> global -> PAYMENT_SECURITY_TOKEN , 2 );
2020-11-27 20:20:04 +01:00
if ( empty ( $conf -> global -> PAYMENT_SECURITY_TOKEN_UNIQUE )) {
2019-11-13 19:35:39 +01:00
$substitutionarray [ '__SECUREKEYPAYMENT_MEMBER__' ] = dol_hash ( $conf -> global -> PAYMENT_SECURITY_TOKEN , 2 );
2021-05-04 00:58:29 +02:00
$substitutionarray [ '__SECUREKEYPAYMENT_DONATION__' ] = dol_hash ( $conf -> global -> PAYMENT_SECURITY_TOKEN , 2 );
2019-11-13 19:35:39 +01:00
$substitutionarray [ '__SECUREKEYPAYMENT_ORDER__' ] = dol_hash ( $conf -> global -> PAYMENT_SECURITY_TOKEN , 2 );
$substitutionarray [ '__SECUREKEYPAYMENT_INVOICE__' ] = dol_hash ( $conf -> global -> PAYMENT_SECURITY_TOKEN , 2 );
$substitutionarray [ '__SECUREKEYPAYMENT_CONTRACTLINE__' ] = dol_hash ( $conf -> global -> PAYMENT_SECURITY_TOKEN , 2 );
2020-05-21 15:05:19 +02:00
} else {
2021-05-04 00:58:29 +02:00
$substitutionarray [ '__SECUREKEYPAYMENT_MEMBER__' ] = dol_hash ( $conf -> global -> PAYMENT_SECURITY_TOKEN . 'member' . $obj -> source_id , 2 );
$substitutionarray [ '__SECUREKEYPAYMENT_DONATION__' ] = dol_hash ( $conf -> global -> PAYMENT_SECURITY_TOKEN . 'donation' . $obj -> source_id , 2 );
2019-11-13 19:35:39 +01:00
$substitutionarray [ '__SECUREKEYPAYMENT_ORDER__' ] = dol_hash ( $conf -> global -> PAYMENT_SECURITY_TOKEN . 'order' . $obj -> source_id , 2 );
$substitutionarray [ '__SECUREKEYPAYMENT_INVOICE__' ] = dol_hash ( $conf -> global -> PAYMENT_SECURITY_TOKEN . 'invoice' . $obj -> source_id , 2 );
$substitutionarray [ '__SECUREKEYPAYMENT_CONTRACTLINE__' ] = dol_hash ( $conf -> global -> PAYMENT_SECURITY_TOKEN . 'contractline' . $obj -> source_id , 2 );
2017-09-22 14:34:31 +02:00
}
2017-09-15 13:43:16 +02:00
}
2021-05-07 17:09:59 +02:00
if ( ! empty ( $conf -> global -> MEMBER_ENABLE_PUBLIC )) {
2021-11-22 02:35:55 +01:00
$substitutionarray [ '__PUBLICLINK_NEWMEMBERFORM__' ] = '<a target="_blank" rel="noopener noreferrer" href="' . DOL_MAIN_URL_ROOT . '/public/members/new.php' . (( ! empty ( $conf -> multicompany -> enabled )) ? '?entity=' . $conf -> entity : '' ) . '">' . $langs -> trans ( 'BlankSubscriptionForm' ) . '</a>' ;
2021-05-07 17:09:59 +02:00
}
2018-05-12 11:23:40 +02:00
/* For backward compatibility, deprecated */
2020-11-27 20:20:04 +01:00
if ( ! empty ( $conf -> paypal -> enabled ) && ! empty ( $conf -> global -> PAYPAL_SECURITY_TOKEN )) {
2019-11-13 19:35:39 +01:00
$substitutionarray [ '__SECUREKEYPAYPAL__' ] = dol_hash ( $conf -> global -> PAYPAL_SECURITY_TOKEN , 2 );
2016-03-05 12:20:58 +01:00
2020-11-27 20:20:04 +01:00
if ( empty ( $conf -> global -> PAYPAL_SECURITY_TOKEN_UNIQUE )) {
$substitutionarray [ '__SECUREKEYPAYPAL_MEMBER__' ] = dol_hash ( $conf -> global -> PAYPAL_SECURITY_TOKEN , 2 );
} else {
$substitutionarray [ '__SECUREKEYPAYPAL_MEMBER__' ] = dol_hash ( $conf -> global -> PAYPAL_SECURITY_TOKEN . 'membersubscription' . $obj -> source_id , 2 );
}
2016-03-05 12:20:58 +01:00
2020-11-27 20:20:04 +01:00
if ( empty ( $conf -> global -> PAYPAL_SECURITY_TOKEN_UNIQUE )) {
$substitutionarray [ '__SECUREKEYPAYPAL_ORDER__' ] = dol_hash ( $conf -> global -> PAYPAL_SECURITY_TOKEN , 2 );
} else {
$substitutionarray [ '__SECUREKEYPAYPAL_ORDER__' ] = dol_hash ( $conf -> global -> PAYPAL_SECURITY_TOKEN . 'order' . $obj -> source_id , 2 );
}
2017-06-07 16:44:04 +02:00
2020-11-27 20:20:04 +01:00
if ( empty ( $conf -> global -> PAYPAL_SECURITY_TOKEN_UNIQUE )) {
$substitutionarray [ '__SECUREKEYPAYPAL_INVOICE__' ] = dol_hash ( $conf -> global -> PAYPAL_SECURITY_TOKEN , 2 );
} else {
$substitutionarray [ '__SECUREKEYPAYPAL_INVOICE__' ] = dol_hash ( $conf -> global -> PAYPAL_SECURITY_TOKEN . 'invoice' . $obj -> source_id , 2 );
}
2017-06-07 16:44:04 +02:00
2020-11-27 20:20:04 +01:00
if ( empty ( $conf -> global -> PAYPAL_SECURITY_TOKEN_UNIQUE )) {
$substitutionarray [ '__SECUREKEYPAYPAL_CONTRACTLINE__' ] = dol_hash ( $conf -> global -> PAYPAL_SECURITY_TOKEN , 2 );
} else {
$substitutionarray [ '__SECUREKEYPAYPAL_CONTRACTLINE__' ] = dol_hash ( $conf -> global -> PAYPAL_SECURITY_TOKEN . 'contractline' . $obj -> source_id , 2 );
}
2015-01-17 19:28:27 +01:00
}
2017-04-17 13:02:40 +02:00
//$substitutionisok=true;
2017-09-22 14:34:31 +02:00
2020-10-31 14:32:18 +01:00
complete_substitutions_array ( $substitutionarray , $langs );
2019-11-13 19:35:39 +01:00
$newsubject = make_substitutions ( $subject , $substitutionarray );
2021-05-07 09:19:44 +02:00
$newmessage = make_substitutions ( $message , $substitutionarray , null , 0 );
$moreinheader = '' ;
if ( preg_match ( '/__UNSUBSCRIBE__/' , $message )) {
2021-05-12 09:21:28 +02:00
$moreinheader = " List-Unsubscribe: <__UNSUBSCRIBE_URL__> \n " ;
$moreinheader = make_substitutions ( $moreinheader , $substitutionarray );
2021-05-07 09:19:44 +02:00
}
2015-01-17 19:28:27 +01:00
$arr_file = array ();
$arr_mime = array ();
$arr_name = array ();
$arr_css = array ();
2019-11-13 19:35:39 +01:00
$listofpaths = dol_dir_list ( $upload_dir , 'all' , 0 , '' , '' , 'name' , SORT_ASC , 0 );
2020-11-27 20:20:04 +01:00
if ( count ( $listofpaths )) {
foreach ( $listofpaths as $key => $val ) {
2019-11-13 19:35:39 +01:00
$arr_file [] = $listofpaths [ $key ][ 'fullname' ];
$arr_mime [] = dol_mimetype ( $listofpaths [ $key ][ 'name' ]);
$arr_name [] = $listofpaths [ $key ][ 'name' ];
2015-01-17 19:28:27 +01:00
}
}
2009-01-25 23:04:55 +01:00
2020-10-14 18:26:05 +02:00
// Mail making
2019-11-13 19:35:39 +01:00
$trackid = 'emailing-' . $obj -> fk_mailing . '-' . $obj -> rowid ;
2021-05-04 15:11:30 +02:00
$mail = new CMailFile ( $newsubject , $sendto , $from , $newmessage , $arr_file , $arr_mime , $arr_name , '' , '' , 0 , $msgishtml , $errorsto , $arr_css , $trackid , $moreinheader , 'emailing' );
2009-01-25 23:04:55 +01:00
2020-11-27 20:20:04 +01:00
if ( $mail -> error ) {
2019-11-13 19:35:39 +01:00
$res = 0 ;
2015-01-17 19:28:27 +01:00
}
2017-04-17 13:02:40 +02:00
/* if ( ! $substitutionisok )
2015-01-17 19:28:27 +01:00
{
$mail -> error = 'Some substitution failed' ;
$res = 0 ;
2017-04-17 13:02:40 +02:00
} */
2008-02-29 17:26:38 +01:00
2015-01-17 19:28:27 +01:00
// Send mail
2020-11-27 20:20:04 +01:00
if ( $res ) {
2019-11-13 19:35:39 +01:00
$res = $mail -> sendfile ();
2009-05-06 15:39:43 +02:00
}
2015-01-17 19:28:27 +01:00
2020-11-27 20:20:04 +01:00
if ( $res ) {
2015-01-17 19:28:27 +01:00
// Mail successful
$nbok ++ ;
2012-04-05 21:02:00 +02:00
2019-11-13 19:35:39 +01:00
dol_syslog ( " comm/mailing/card.php: ok for # " . $i . ( $mail -> error ? ' - ' . $mail -> error : '' ), LOG_DEBUG );
2012-04-05 21:02:00 +02:00
2019-11-13 19:35:39 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " mailing_cibles " ;
2021-04-25 15:55:36 +02:00
$sql .= " SET statut=1, date_envoi = ' " . $db -> idate ( $now ) . " ' WHERE rowid= " . (( int ) $obj -> rowid );
2019-11-13 19:35:39 +01:00
$resql2 = $db -> query ( $sql );
2020-11-27 20:20:04 +01:00
if ( ! $resql2 ) {
2015-01-17 19:28:27 +01:00
dol_print_error ( $db );
2020-05-21 15:05:19 +02:00
} else {
2015-01-17 19:28:27 +01:00
//if cheack read is use then update prospect contact status
2020-11-27 20:20:04 +01:00
if ( strpos ( $message , '__CHECK_READ__' ) !== false ) {
2015-01-17 19:28:27 +01:00
//Update status communication of thirdparty prospect
2021-05-11 21:13:52 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " societe SET fk_stcomm=2 WHERE rowid IN (SELECT source_id FROM " . MAIN_DB_PREFIX . " mailing_cibles WHERE rowid= " . (( int ) $obj -> rowid ) . " ) " ;
2015-01-18 17:13:42 +01:00
dol_syslog ( " card.php: set prospect thirdparty status " , LOG_DEBUG );
2019-11-13 19:35:39 +01:00
$resql2 = $db -> query ( $sql );
2020-11-27 20:20:04 +01:00
if ( ! $resql2 ) {
2015-01-17 19:28:27 +01:00
dol_print_error ( $db );
}
2020-10-31 14:32:18 +01:00
//Update status communication of contact prospect
2021-05-11 21:13:52 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " societe SET fk_stcomm=2 WHERE rowid IN (SELECT sc.fk_soc FROM " . MAIN_DB_PREFIX . " socpeople AS sc INNER JOIN " . MAIN_DB_PREFIX . " mailing_cibles AS mc ON mc.rowid= " . (( int ) $obj -> rowid ) . " AND mc.source_type = 'contact' AND mc.source_id = sc.rowid) " ;
2015-01-18 17:13:42 +01:00
dol_syslog ( " card.php: set prospect contact status " , LOG_DEBUG );
2015-01-17 19:28:27 +01:00
2019-11-13 19:35:39 +01:00
$resql2 = $db -> query ( $sql );
2020-11-27 20:20:04 +01:00
if ( ! $resql2 ) {
2015-01-17 19:28:27 +01:00
dol_print_error ( $db );
}
2012-04-04 14:45:48 +02:00
}
}
2012-04-05 21:02:00 +02:00
2020-11-27 20:20:04 +01:00
if ( ! empty ( $conf -> global -> MAILING_DELAY )) {
2020-10-31 14:32:18 +01:00
dol_syslog ( " Wait a delay of MAILING_DELAY= " . $conf -> global -> MAILING_DELAY );
2020-12-27 14:04:04 +01:00
usleep (( float ) $conf -> global -> MAILING_DELAY * 1000000 );
2020-10-31 14:32:18 +01:00
}
2012-04-05 21:02:00 +02:00
2020-10-31 14:32:18 +01:00
//test if CHECK READ change statut prospect contact
2020-05-21 15:05:19 +02:00
} else {
2015-01-17 19:28:27 +01:00
// Mail failed
$nbko ++ ;
2009-05-06 15:39:43 +02:00
2019-11-13 19:35:39 +01:00
dol_syslog ( " comm/mailing/card.php: error for # " . $i . ( $mail -> error ? ' - ' . $mail -> error : '' ), LOG_WARNING );
2009-05-06 15:39:43 +02:00
2019-11-13 19:35:39 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " mailing_cibles " ;
2021-08-27 16:33:03 +02:00
$sql .= " SET statut=-1, error_text=' " . $db -> escape ( $mail -> error ) . " ', date_envoi=' " . $db -> idate ( $now ) . " ' WHERE rowid= " . (( int ) $obj -> rowid );
2019-11-13 19:35:39 +01:00
$resql2 = $db -> query ( $sql );
2020-11-27 20:20:04 +01:00
if ( ! $resql2 ) {
2015-01-17 19:28:27 +01:00
dol_print_error ( $db );
}
2009-05-06 15:39:43 +02:00
}
2015-01-17 19:28:27 +01:00
$i ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2015-11-06 09:36:16 +01:00
setEventMessages ( $langs -> transnoentitiesnoconv ( " NoMoreRecipientToSendTo " ), null , 'mesgs' );
2009-05-06 15:39:43 +02:00
}
2015-01-17 19:28:27 +01:00
// Loop finished, set global statut of mail
2020-11-27 20:20:04 +01:00
if ( $nbko > 0 ) {
2019-11-13 19:35:39 +01:00
$statut = 2 ; // Status 'sent partially' (because at least one error)
2020-11-27 20:20:04 +01:00
if ( $nbok > 0 ) {
setEventMessages ( $langs -> transnoentitiesnoconv ( " EMailSentToNRecipients " , $nbok ), null , 'mesgs' );
} else {
setEventMessages ( $langs -> transnoentitiesnoconv ( " EMailSentToNRecipients " , $nbok ), null , 'mesgs' );
}
2020-05-21 15:05:19 +02:00
} else {
2020-11-27 20:20:04 +01:00
if ( $nbok >= $num ) {
2019-11-13 19:35:39 +01:00
$statut = 3 ; // Send to everybody
2019-01-27 11:55:16 +01:00
setEventMessages ( $langs -> transnoentitiesnoconv ( " EMailSentToNRecipients " , $nbok ), null , 'mesgs' );
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$statut = 2 ; // Status 'sent partially' (because not send to everybody)
2019-01-27 11:55:16 +01:00
setEventMessages ( $langs -> transnoentitiesnoconv ( " EMailSentToNRecipients " , $nbok ), null , 'mesgs' );
2015-01-17 19:28:27 +01:00
}
2012-11-14 18:58:55 +01:00
}
2009-05-06 15:39:43 +02:00
2021-04-25 15:55:36 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " mailing SET statut= " . (( int ) $statut ) . " WHERE rowid = " . (( int ) $object -> id );
2015-01-18 17:13:42 +01:00
dol_syslog ( " comm/mailing/card.php: update global status " , LOG_DEBUG );
2019-11-13 19:35:39 +01:00
$resql2 = $db -> query ( $sql );
2020-11-27 20:20:04 +01:00
if ( ! $resql2 ) {
2015-01-17 19:28:27 +01:00
dol_print_error ( $db );
}
2020-05-21 15:05:19 +02:00
} else {
2015-01-17 19:28:27 +01:00
dol_syslog ( $db -> error ());
2009-05-06 15:39:43 +02:00
dol_print_error ( $db );
2008-08-04 01:45:53 +02:00
}
2021-06-04 12:27:50 +02:00
$object -> fetch ( $id );
2015-01-17 19:28:27 +01:00
$action = '' ;
}
2008-02-29 17:26:38 +01:00
}
2010-04-17 15:23:50 +02:00
2015-01-17 19:28:27 +01:00
// Action send test emailing
2021-03-25 16:59:47 +01:00
if ( $action == 'send' && ! $cancel ) {
2019-11-13 19:35:39 +01:00
$error = 0 ;
2011-03-23 20:30:37 +01:00
2019-11-13 19:35:39 +01:00
$upload_dir = $conf -> mailing -> dir_output . " / " . get_exdir ( $object -> id , 2 , 0 , 1 , $object , 'mailing' );
2005-09-10 17:56:12 +02:00
2021-03-25 16:59:47 +01:00
$object -> sendto = GETPOST ( " sendto " , 'alphawithlgt' );
2020-11-27 20:20:04 +01:00
if ( ! $object -> sendto ) {
2019-05-29 09:51:45 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " MailTo " )), null , 'errors' );
2015-01-17 19:28:27 +01:00
$error ++ ;
2009-05-06 15:39:43 +02:00
}
2020-11-27 20:20:04 +01:00
if ( ! $error ) {
2020-10-14 18:26:05 +02:00
// Is the message in html
$msgishtml = - 1 ; // Unknow by default
2020-11-27 20:20:04 +01:00
if ( preg_match ( '/[\s\t]*<html>/i' , $object -> body )) {
$msgishtml = 1 ;
}
2015-01-17 19:28:27 +01:00
2017-09-22 14:34:31 +02:00
// other are set at begin of page
$object -> substitutionarrayfortest [ '__EMAIL__' ] = $object -> sendto ;
$object -> substitutionarrayfortest [ '__MAILTOEMAIL__' ] = '<a href="mailto:' . $object -> sendto . '">' . $object -> sendto . '</a>' ;
2017-08-28 12:49:57 +02:00
2020-10-14 18:26:05 +02:00
// Subject and message substitutions
2020-10-31 14:32:18 +01:00
complete_substitutions_array ( $object -> substitutionarrayfortest , $langs );
2019-11-13 19:35:39 +01:00
$tmpsujet = make_substitutions ( $object -> sujet , $object -> substitutionarrayfortest );
$tmpbody = make_substitutions ( $object -> body , $object -> substitutionarrayfortest );
2015-01-17 19:28:27 +01:00
$arr_file = array ();
$arr_mime = array ();
$arr_name = array ();
$arr_css = array ();
2020-10-31 14:32:18 +01:00
// Add CSS
2020-11-27 20:20:04 +01:00
if ( ! empty ( $object -> bgcolor )) {
$arr_css [ 'bgcolor' ] = ( preg_match ( '/^#/' , $object -> bgcolor ) ? '' : '#' ) . $object -> bgcolor ;
}
if ( ! empty ( $object -> bgimage )) {
$arr_css [ 'bgimage' ] = $object -> bgimage ;
}
2015-01-17 19:28:27 +01:00
2020-10-31 14:32:18 +01:00
// Attached files
2019-11-13 19:35:39 +01:00
$listofpaths = dol_dir_list ( $upload_dir , 'all' , 0 , '' , '' , 'name' , SORT_ASC , 0 );
2020-11-27 20:20:04 +01:00
if ( count ( $listofpaths )) {
foreach ( $listofpaths as $key => $val ) {
2019-11-13 19:35:39 +01:00
$arr_file [] = $listofpaths [ $key ][ 'fullname' ];
$arr_mime [] = dol_mimetype ( $listofpaths [ $key ][ 'name' ]);
$arr_name [] = $listofpaths [ $key ][ 'name' ];
2015-01-17 19:28:27 +01:00
}
}
2009-05-06 15:39:43 +02:00
2022-09-12 10:26:20 +02:00
$trackid = 'emailing-test' ;
2017-04-11 10:57:17 +02:00
$mailfile = new CMailFile ( $tmpsujet , $object -> sendto , $object -> email_from , $tmpbody , $arr_file , $arr_mime , $arr_name , '' , '' , 0 , $msgishtml , $object -> email_errorsto , $arr_css , $trackid , '' , 'emailing' );
2005-01-05 16:26:05 +01:00
2019-11-13 19:35:39 +01:00
$result = $mailfile -> sendfile ();
2020-11-27 20:20:04 +01:00
if ( $result ) {
2019-01-27 11:55:16 +01:00
setEventMessages ( $langs -> trans ( " MailSuccessfulySent " , $mailfile -> getValidAddress ( $object -> email_from , 2 ), $mailfile -> getValidAddress ( $object -> sendto , 2 )), null , 'mesgs' );
2019-05-21 21:16:06 +02:00
$action = '' ;
2020-05-21 15:05:19 +02:00
} else {
2015-11-06 09:36:16 +01:00
setEventMessages ( $langs -> trans ( " ResultKo " ) . '<br>' . $mailfile -> error . ' ' . $result , null , 'errors' );
2019-05-21 21:16:06 +02:00
$action = 'test' ;
2015-01-17 19:28:27 +01:00
}
2010-04-17 11:47:25 +02:00
}
}
2015-01-17 19:28:27 +01:00
// Action add emailing
2020-11-27 20:20:04 +01:00
if ( $action == 'add' ) {
2014-07-20 02:32:13 +02:00
$mesgs = array ();
2022-01-19 15:20:10 +01:00
$object -> email_from = ( string ) GETPOST ( " from " , 'alphawithlgt' ); // Must allow 'name <email>'
$object -> email_replyto = ( string ) GETPOST ( " replyto " , 'alphawithlgt' ); // Must allow 'name <email>'
$object -> email_errorsto = ( string ) GETPOST ( " errorsto " , 'alphawithlgt' ); // Must allow 'name <email>'
2020-11-27 20:20:04 +01:00
$object -> title = ( string ) GETPOST ( " title " );
$object -> sujet = ( string ) GETPOST ( " sujet " );
$object -> body = ( string ) GETPOST ( " bodyemail " , 'restricthtml' );
$object -> bgcolor = ( string ) GETPOST ( " bgcolor " );
$object -> bgimage = ( string ) GETPOST ( " bgimage " );
2010-04-17 15:23:50 +02:00
2020-10-07 17:41:36 +02:00
if ( ! $object -> title ) {
2019-01-27 11:55:16 +01:00
$mesgs [] = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " MailTitle " ));
2015-01-18 17:13:42 +01:00
}
2019-11-13 19:35:39 +01:00
if ( ! $object -> sujet ) {
2019-01-27 11:55:16 +01:00
$mesgs [] = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " MailTopic " ));
2014-07-20 02:32:13 +02:00
}
2019-11-13 19:35:39 +01:00
if ( ! $object -> body ) {
2019-01-27 11:55:16 +01:00
$mesgs [] = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " MailMessage " ));
2014-07-20 02:32:13 +02:00
}
2010-04-17 15:23:50 +02:00
2020-11-27 20:20:04 +01:00
if ( ! count ( $mesgs )) {
if ( $object -> create ( $user ) >= 0 ) {
2012-08-31 05:58:38 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
2010-04-17 15:23:50 +02:00
exit ;
}
2015-01-18 17:13:42 +01:00
$mesgs [] = $object -> error ;
2022-11-16 10:48:25 +01:00
$mesgs = array_merge ( $mesgs , $object -> errors );
2010-04-17 15:23:50 +02:00
}
2022-11-16 11:05:39 +01:00
setEventMessages ( '' , $mesgs , 'errors' );
2019-11-13 19:35:39 +01:00
$action = " create " ;
2010-04-17 15:23:50 +02:00
}
2015-01-17 19:28:27 +01:00
// Action update description of emailing
2020-11-27 20:20:04 +01:00
if ( $action == 'settitle' || $action == 'setemail_from' || $action == 'setreplyto' || $action == 'setemail_errorsto' ) {
2019-11-13 19:35:39 +01:00
$upload_dir = $conf -> mailing -> dir_output . " / " . get_exdir ( $object -> id , 2 , 0 , 1 , $object , 'mailing' );
2015-01-17 19:28:27 +01:00
2020-11-27 20:20:04 +01:00
if ( $action == 'settitle' ) {
$object -> title = trim ( GETPOST ( 'title' , 'alpha' ));
} elseif ( $action == 'setemail_from' ) {
2022-01-19 15:20:10 +01:00
$object -> email_from = trim ( GETPOST ( 'email_from' , 'alphawithlgt' )); // Must allow 'name <email>'
2020-11-27 20:20:04 +01:00
} elseif ( $action == 'setemail_replyto' ) {
2022-01-19 15:20:10 +01:00
$object -> email_replyto = trim ( GETPOST ( 'email_replyto' , 'alphawithlgt' )); // Must allow 'name <email>'
2020-11-27 20:20:04 +01:00
} elseif ( $action == 'setemail_errorsto' ) {
2022-01-19 15:20:10 +01:00
$object -> email_errorsto = trim ( GETPOST ( 'email_errorsto' , 'alphawithlgt' )); // Must allow 'name <email>'
2020-11-27 20:20:04 +01:00
} elseif ( $action == 'settitle' && empty ( $object -> title )) {
2019-01-27 23:31:37 +01:00
$mesg = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " MailTitle " ));
2019-01-27 23:23:38 +01:00
} elseif ( $action == 'setfrom' && empty ( $object -> email_from )) {
2019-01-27 23:31:37 +01:00
$mesg = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " MailFrom " ));
2015-01-18 17:13:42 +01:00
}
2015-01-17 19:28:27 +01:00
2020-11-27 20:20:04 +01:00
if ( ! $mesg ) {
if ( $object -> update ( $user ) >= 0 ) {
2015-01-17 19:28:27 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
}
2015-01-18 17:13:42 +01:00
$mesg = $object -> error ;
2015-01-17 19:28:27 +01:00
}
2015-11-06 09:36:16 +01:00
setEventMessages ( $mesg , $mesgs , 'errors' );
2019-11-13 19:35:39 +01:00
$action = " " ;
2010-04-17 15:23:50 +02:00
}
2015-01-17 19:28:27 +01:00
/*
2021-04-04 17:05:01 +02:00
* Action of adding a file in email form
2015-01-17 19:28:27 +01:00
*/
2021-04-04 17:05:01 +02:00
if ( GETPOST ( 'addfile' )) {
2019-11-13 19:35:39 +01:00
$upload_dir = $conf -> mailing -> dir_output . " / " . get_exdir ( $object -> id , 2 , 0 , 1 , $object , 'mailing' );
2015-01-17 19:28:27 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2020-10-31 14:32:18 +01:00
// Set tmp user directory
2021-04-04 17:05:01 +02:00
dol_add_file_process ( $upload_dir , 0 , 0 , 'addedfile' , '' , null , '' , 0 );
2015-01-17 19:28:27 +01:00
2019-11-13 19:35:39 +01:00
$action = " edit " ;
2012-06-15 11:20:09 +02:00
}
2015-01-17 19:28:27 +01:00
2020-10-14 18:26:05 +02:00
// Action of file remove
2021-03-25 16:59:47 +01:00
if ( GETPOST ( " removedfile " )) {
2019-11-13 19:35:39 +01:00
$upload_dir = $conf -> mailing -> dir_output . " / " . get_exdir ( $object -> id , 2 , 0 , 1 , $object , 'mailing' );
2015-01-17 19:28:27 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2021-04-04 17:05:01 +02:00
dol_remove_file_process ( GETPOST ( 'removedfile' ), 0 , 0 ); // We really delete file linked to mailing
2015-01-17 19:28:27 +01:00
2019-11-13 19:35:39 +01:00
$action = " edit " ;
2005-01-05 16:26:05 +01:00
}
2020-10-14 18:26:05 +02:00
// Action of emailing update
2021-03-25 16:59:47 +01:00
if ( $action == 'update' && ! GETPOST ( " removedfile " ) && ! $cancel ) {
2015-01-17 19:28:27 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2019-11-13 19:35:39 +01:00
$isupload = 0 ;
2012-06-15 11:20:09 +02:00
2020-11-27 20:20:04 +01:00
if ( ! $isupload ) {
2015-01-18 17:13:42 +01:00
$mesgs = array ();
2020-11-27 20:20:04 +01:00
$object -> sujet = ( string ) GETPOST ( " sujet " );
$object -> body = ( string ) GETPOST ( " bodyemail " , 'restricthtml' );
$object -> bgcolor = ( string ) GETPOST ( " bgcolor " );
$object -> bgimage = ( string ) GETPOST ( " bgimage " );
2015-01-17 19:28:27 +01:00
2019-11-13 19:35:39 +01:00
if ( ! $object -> sujet ) {
2019-01-27 11:55:16 +01:00
$mesgs [] = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " MailTopic " ));
2015-01-18 17:13:42 +01:00
}
2019-11-13 19:35:39 +01:00
if ( ! $object -> body ) {
2019-01-27 11:55:16 +01:00
$mesgs [] = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " MailMessage " ));
2015-01-18 17:13:42 +01:00
}
2015-01-17 19:28:27 +01:00
2020-11-27 20:20:04 +01:00
if ( ! count ( $mesgs )) {
if ( $object -> update ( $user ) >= 0 ) {
2015-01-17 19:28:27 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
}
2019-11-13 19:35:39 +01:00
$mesgs [] = $object -> error ;
2022-11-16 10:48:25 +01:00
$mesgs = array_merge ( $mesgs , $object -> errors );
2015-01-17 19:28:27 +01:00
}
2022-11-16 11:05:39 +01:00
setEventMessages ( '' , $mesgs , 'errors' );
2019-11-13 19:35:39 +01:00
$action = " edit " ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$action = " edit " ;
2012-06-15 11:20:09 +02:00
}
2015-01-17 19:28:27 +01:00
}
2012-06-15 11:20:09 +02:00
2020-10-14 18:26:05 +02:00
// Action of validation confirmation
2020-11-27 20:20:04 +01:00
if ( $action == 'confirm_valid' && $confirm == 'yes' ) {
if ( $object -> id > 0 ) {
2015-01-17 19:28:27 +01:00
$object -> valid ( $user );
2015-11-06 09:36:16 +01:00
setEventMessages ( $langs -> trans ( " MailingSuccessfullyValidated " ), null , 'mesgs' );
2012-08-31 05:58:38 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
2012-06-15 11:20:09 +02:00
exit ;
2020-05-21 15:05:19 +02:00
} else {
2015-01-17 19:28:27 +01:00
dol_print_error ( $db );
2012-06-15 11:20:09 +02:00
}
}
2015-01-17 19:28:27 +01:00
2020-10-14 18:26:05 +02:00
// Action of validation confirmation
2020-11-27 20:20:04 +01:00
if ( $action == 'confirm_settodraft' && $confirm == 'yes' ) {
if ( $object -> id > 0 ) {
2017-01-29 15:31:22 +01:00
$result = $object -> setStatut ( 0 );
2020-11-27 20:20:04 +01:00
if ( $result > 0 ) {
2020-10-31 14:32:18 +01:00
//setEventMessages($langs->trans("MailingSuccessfullyValidated"), null, 'mesgs');
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
} else {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2020-05-21 15:05:19 +02:00
} else {
2017-01-29 15:31:22 +01:00
dol_print_error ( $db );
}
}
2015-01-17 19:28:27 +01:00
// Resend
2020-11-27 20:20:04 +01:00
if ( $action == 'confirm_reset' && $confirm == 'yes' ) {
if ( $object -> id > 0 ) {
2015-01-17 19:28:27 +01:00
$db -> begin ();
2019-11-13 19:35:39 +01:00
$result = $object -> valid ( $user );
2020-11-27 20:20:04 +01:00
if ( $result > 0 ) {
2019-11-13 19:35:39 +01:00
$result = $object -> reset_targets_status ( $user );
2015-01-17 19:28:27 +01:00
}
2020-11-27 20:20:04 +01:00
if ( $result > 0 ) {
2015-01-17 19:28:27 +01:00
$db -> commit ();
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2015-11-06 09:36:16 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-01-17 19:28:27 +01:00
$db -> rollback ();
}
2020-05-21 15:05:19 +02:00
} else {
2015-01-17 19:28:27 +01:00
dol_print_error ( $db );
}
2005-01-05 16:26:05 +01:00
}
2020-10-14 18:26:05 +02:00
// Action of delete confirmation
2020-11-27 20:20:04 +01:00
if ( $action == 'confirm_delete' && $confirm == 'yes' ) {
if ( $object -> delete ( $object -> id )) {
2019-11-13 19:35:39 +01:00
$url = ( ! empty ( $urlfrom ) ? $urlfrom : 'list.php' );
2015-01-17 19:28:27 +01:00
header ( " Location: " . $url );
exit ;
}
2009-05-06 15:39:43 +02:00
}
2005-01-05 16:26:05 +01:00
2021-03-25 16:59:47 +01:00
if ( $cancel ) {
2015-01-17 19:28:27 +01:00
$action = '' ;
}
2005-01-05 16:26:05 +01:00
}
2005-02-12 00:41:42 +01:00
2005-01-05 16:26:05 +01:00
/*
2008-05-28 00:30:52 +02:00
* View
2005-01-05 16:26:05 +01:00
*/
2015-01-18 17:13:42 +01:00
$form = new Form ( $db );
$htmlother = new FormOther ( $db );
2012-06-13 09:26:29 +02:00
2019-11-13 19:35:39 +01:00
$help_url = 'EN:Module_EMailing|FR:Module_Mailing|ES:Módulo_Mailing' ;
2020-11-27 20:20:04 +01:00
llxHeader (
'' ,
$langs -> trans ( " Mailing " ),
$help_url ,
'' ,
0 ,
0 ,
2017-09-01 13:09:13 +02:00
array (
2020-11-27 20:20:04 +01:00
'/includes/ace/src/ace.js' ,
'/includes/ace/src/ext-statusbar.js' ,
'/includes/ace/src/ext-language_tools.js' ,
//'/includes/ace/src/ext-chromevox.js'
),
array ()
);
2022-07-11 00:05:50 +02:00
if ( $action == 'create' ) {
2008-11-10 15:20:02 +01:00
// EMailing in creation mode
2012-03-23 20:03:57 +01:00
print '<form name="new_mailing" action="' . $_SERVER [ 'PHP_SELF' ] . '" method="POST">' . " \n " ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2009-05-06 15:39:43 +02:00
print '<input type="hidden" name="action" value="add">' ;
2005-02-12 00:41:42 +01:00
2016-11-11 02:18:48 +01:00
$htmltext = '<i>' . $langs -> trans ( " FollowingConstantsWillBeSubstituted " ) . ':<br>' ;
2020-11-27 20:20:04 +01:00
foreach ( $object -> substitutionarray as $key => $val ) {
2019-11-13 19:35:39 +01:00
$htmltext .= $key . ' = ' . $langs -> trans ( $val ) . '<br>' ;
2016-11-11 02:18:48 +01:00
}
2019-11-13 19:35:39 +01:00
$htmltext .= '</i>' ;
2017-02-17 17:11:14 +01:00
2017-06-07 16:44:04 +02:00
2019-11-13 19:35:39 +01:00
$availablelink = $form -> textwithpicto ( $langs -> trans ( " AvailableVariables " ), $htmltext , 1 , 'help' , '' , 0 , 2 , 'availvar' );
2017-02-17 17:11:14 +01:00
//print '<a href="javascript:document_preview(\''.DOL_URL_ROOT.'/admin/modulehelp.php?id='.$objMod->numero.'\',\'text/html\',\''.dol_escape_js($langs->trans("Module")).'\')">'.img_picto($langs->trans("ClickToShowDescription"), $imginfo).'</a>';
2017-06-07 16:44:04 +02:00
2016-11-11 02:18:48 +01:00
// Print mail form
2020-05-11 19:00:27 +02:00
print load_fiche_titre ( $langs -> trans ( " NewMailing " ), $availablelink , 'object_email' );
2005-01-05 16:26:05 +01:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ();
2015-05-22 15:29:19 +02:00
2019-05-21 21:36:48 +02:00
print '<table class="border centpercent">' ;
2020-10-22 20:01:59 +02:00
print '<tr><td class="fieldrequired titlefieldcreate">' . $langs -> trans ( " MailTitle " ) . '</td><td><input class="flat minwidth300" name="title" value="' . dol_escape_htmltag ( GETPOST ( 'title' )) . '" autofocus="autofocus"></td></tr>' ;
2016-12-18 13:04:24 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( " MailFrom " ) . '</td><td><input class="flat minwidth200" name="from" value="' . $conf -> global -> MAILING_EMAIL_FROM . '"></td></tr>' ;
2019-11-13 19:35:39 +01:00
print '<tr><td>' . $langs -> trans ( " MailErrorsTo " ) . '</td><td><input class="flat minwidth200" name="errorsto" value="' . ( ! empty ( $conf -> global -> MAILING_EMAIL_ERRORSTO ) ? $conf -> global -> MAILING_EMAIL_ERRORSTO : $conf -> global -> MAIN_MAIL_ERRORS_TO ) . '"></td></tr>' ;
2012-06-17 18:40:45 +02:00
2012-06-15 11:20:09 +02:00
// Other attributes
2019-11-13 19:35:39 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2020-10-31 14:32:18 +01:00
print $hookmanager -> resPrint ;
2020-11-27 20:20:04 +01:00
if ( empty ( $reshook )) {
2021-10-08 15:58:08 +02:00
print $object -> showOptionals ( $extrafields , 'create' );
2012-06-13 09:26:29 +02:00
}
2012-06-17 18:40:45 +02:00
2010-04-17 11:47:25 +02:00
print '</table>' ;
print '</br><br>' ;
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">' ;
2019-12-13 15:52:08 +01:00
print '<tr><td class="fieldrequired titlefieldcreate">' . $langs -> trans ( " MailTopic " ) . '</td><td><input class="flat minwidth200 quatrevingtpercent" name="sujet" value="' . dol_escape_htmltag ( GETPOST ( 'sujet' , 'alphanohtml' )) . '"></td></tr>' ;
2016-07-06 22:28:13 +02:00
print '<tr><td>' . $langs -> trans ( " BackgroundColorByDefault " ) . '</td><td colspan="3">' ;
2022-02-22 23:44:56 +01:00
print $htmlother -> selectColor ( GETPOST ( 'bgcolor' ), 'bgcolor' , '' , 0 );
2009-05-19 15:27:44 +02:00
print '</td></tr>' ;
2016-11-11 02:18:48 +01:00
print '</table>' ;
2017-06-07 16:44:04 +02:00
2016-11-11 02:18:48 +01:00
print '<div style="padding-top: 10px">' ;
2020-10-14 18:26:05 +02:00
// wysiwyg editor
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2022-06-22 08:36:24 +02:00
$doleditor = new DolEditor ( 'bodyemail' , GETPOST ( 'bodyemail' , 'restricthtmlallowunvalid' ), '' , 600 , 'dolibarr_mailings' , '' , true , true , getDolGlobalInt ( 'FCKEDITOR_ENABLE_MAILING' ), 20 , '90%' );
2010-09-02 20:51:47 +02:00
$doleditor -> Create ();
2016-11-11 02:18:48 +01:00
print '</div>' ;
2017-06-07 16:44:04 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2015-05-22 15:29:19 +02:00
2021-09-22 08:43:30 +02:00
print $form -> buttonsSaveCancel ( " CreateMailing " , '' );
2010-02-21 20:35:58 +01:00
2009-05-06 15:39:43 +02:00
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2020-11-27 20:20:04 +01:00
if ( $object -> id > 0 ) {
2019-11-13 19:35:39 +01:00
$upload_dir = $conf -> mailing -> dir_output . " / " . get_exdir ( $object -> id , 2 , 0 , 1 , $object , 'mailing' );
2010-04-17 15:23:50 +02:00
2012-03-23 20:03:57 +01:00
$head = emailing_prepare_head ( $object );
2009-07-29 20:41:39 +02:00
2020-11-27 20:20:04 +01:00
if ( $action == 'settodraft' ) {
// Confirmation back to draft
2019-01-27 11:55:16 +01:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id , $langs -> trans ( " SetToDraft " ), $langs -> trans ( " ConfirmUnvalidateEmailing " ), " confirm_settodraft " , '' , '' , 1 );
2020-11-27 20:20:04 +01:00
} elseif ( $action == 'valid' ) {
// Confirmation of mailing validation
2019-01-27 11:55:16 +01:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id , $langs -> trans ( " ValidMailing " ), $langs -> trans ( " ConfirmValidMailing " ), " confirm_valid " , '' , '' , 1 );
2020-11-27 20:20:04 +01:00
} elseif ( $action == 'reset' ) {
// Confirm reset
2019-01-27 11:55:16 +01:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id , $langs -> trans ( " ResetMailing " ), $langs -> trans ( " ConfirmResetMailing " , $object -> ref ), " confirm_reset " , '' , '' , 2 );
2020-11-27 20:20:04 +01:00
} elseif ( $action == 'delete' ) {
// Confirm delete
2019-11-13 19:35:39 +01:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id . ( ! empty ( $urlfrom ) ? '&urlfrom=' . urlencode ( $urlfrom ) : '' ), $langs -> trans ( " DeleteAMailing " ), $langs -> trans ( " ConfirmDeleteMailing " ), " confirm_delete " , '' , '' , 1 );
2009-05-06 15:39:43 +02:00
}
2020-11-27 20:20:04 +01:00
if ( $action != 'edit' && $action != 'edithtml' ) {
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'card' , $langs -> trans ( " Mailing " ), - 1 , 'email' );
2017-04-17 13:02:40 +02:00
2009-05-06 15:39:43 +02:00
/*
2020-10-14 18:26:05 +02:00
* View mode mailing
2009-05-06 15:39:43 +02:00
*/
2020-11-27 20:20:04 +01:00
if ( $action == 'sendall' ) {
2020-10-31 14:32:18 +01:00
// Define message to recommand from command line
2020-04-10 10:59:32 +02:00
$sendingmode = $conf -> global -> EMAILING_MAIL_SENDMODE ;
2020-11-27 20:20:04 +01:00
if ( empty ( $sendingmode )) {
$sendingmode = $conf -> global -> MAIN_MAIL_SENDMODE ;
}
if ( empty ( $sendingmode )) {
$sendingmode = 'mail' ; // If not defined, we use php mail function
}
2010-12-13 19:40:04 +01:00
2016-12-26 12:30:59 +01:00
// MAILING_NO_USING_PHPMAIL may be defined or not.
// MAILING_LIMIT_SENDBYWEB is always defined to something != 0 (-1=forbidden).
2017-01-13 15:32:20 +01:00
// MAILING_LIMIT_SENDBYCLI may be defined ot not (-1=forbidden, 0 or undefined=no limit).
2022-07-13 01:01:44 +02:00
// MAILING_LIMIT_SENDBYDAY may be defined ot not (0 or undefined=no limit).
2020-11-27 20:20:04 +01:00
if ( ! empty ( $conf -> global -> MAILING_NO_USING_PHPMAIL ) && $sendingmode == 'mail' ) {
2014-11-29 13:50:41 +01:00
// EMailing feature may be a spam problem, so when you host several users/instance, having this option may force each user to use their own SMTP agent.
2016-12-17 14:47:06 +01:00
// You ensure that every user is using its own SMTP server when using the mass emailing module.
2020-04-10 10:59:32 +02:00
$linktoadminemailbefore = '<a href="' . DOL_URL_ROOT . '/admin/mails_emailing.php">' ;
$linktoadminemailend = '</a>' ;
2015-11-06 09:36:16 +01:00
setEventMessages ( $langs -> trans ( " MailSendSetupIs " , $listofmethods [ $sendingmode ]), null , 'warnings' );
2022-07-13 14:00:19 +02:00
$messagetoshow = $langs -> trans ( " MailSendSetupIs2 " , '{s1}' , '{s2}' , '{s3}' , '{s4}' );
$messagetoshow = str_replace ( '{s1}' , $linktoadminemailbefore , $messagetoshow );
$messagetoshow = str_replace ( '{s2}' , $linktoadminemailend , $messagetoshow );
$messagetoshow = str_replace ( '{s3}' , $langs -> transnoentitiesnoconv ( " MAIN_MAIL_SENDMODE " ), $messagetoshow );
$messagetoshow = str_replace ( '{s4}' , $listofmethods [ 'smtps' ], $messagetoshow );
setEventMessages ( $messagetoshow , null , 'warnings' );
2020-11-27 20:20:04 +01:00
if ( ! empty ( $conf -> global -> MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS )) {
setEventMessages ( $langs -> trans ( " MailSendSetupIs3 " , $conf -> global -> MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS ), null , 'warnings' );
}
2020-04-10 10:59:32 +02:00
$_GET [ " action " ] = '' ;
2020-11-27 20:20:04 +01:00
} elseif ( $conf -> global -> MAILING_LIMIT_SENDBYWEB < 0 ) {
if ( ! empty ( $conf -> global -> MAILING_LIMIT_WARNING_PHPMAIL ) && $sendingmode == 'mail' ) {
setEventMessages ( $langs -> transnoentitiesnoconv ( $conf -> global -> MAILING_LIMIT_WARNING_PHPMAIL ), null , 'warnings' );
}
if ( ! empty ( $conf -> global -> MAILING_LIMIT_WARNING_NOPHPMAIL ) && $sendingmode != 'mail' ) {
setEventMessages ( $langs -> transnoentitiesnoconv ( $conf -> global -> MAILING_LIMIT_WARNING_NOPHPMAIL ), null , 'warnings' );
}
2017-06-07 16:44:04 +02:00
2016-12-17 14:47:06 +01:00
// The feature is forbidden from GUI, we show just message to use from command line.
2020-10-31 14:32:18 +01:00
setEventMessages ( $langs -> trans ( " MailingNeedCommand " ), null , 'warnings' );
2015-11-06 09:36:16 +01:00
setEventMessages ( '<textarea cols="60" rows="' . ROWS_1 . '" wrap="soft">php ./scripts/emailings/mailing-send.php ' . $object -> id . '</textarea>' , null , 'warnings' );
2020-11-27 20:20:04 +01:00
if ( $conf -> file -> mailing_limit_sendbyweb != '-1' ) { // MAILING_LIMIT_SENDBYWEB was set to -1 in database, but it is allowed ot increase it.
2020-10-31 14:32:18 +01:00
setEventMessages ( $langs -> trans ( " MailingNeedCommand2 " ), null , 'warnings' ); // You can send online with constant...
2016-12-16 13:46:39 +01:00
}
2020-04-10 10:59:32 +02:00
$_GET [ " action " ] = '' ;
2020-05-21 15:05:19 +02:00
} else {
2020-11-27 20:20:04 +01:00
if ( ! empty ( $conf -> global -> MAILING_LIMIT_WARNING_PHPMAIL ) && $sendingmode == 'mail' ) {
setEventMessages ( $langs -> transnoentitiesnoconv ( $conf -> global -> MAILING_LIMIT_WARNING_PHPMAIL ), null , 'warnings' );
}
if ( ! empty ( $conf -> global -> MAILING_LIMIT_WARNING_NOPHPMAIL ) && $sendingmode != 'mail' ) {
setEventMessages ( $langs -> transnoentitiesnoconv ( $conf -> global -> MAILING_LIMIT_WARNING_NOPHPMAIL ), null , 'warnings' );
}
2020-10-31 14:32:18 +01:00
$text = '' ;
2022-07-13 01:01:44 +02:00
if ( isset ( $conf -> global -> MAILING_LIMIT_SENDBYDAY ) && $conf -> global -> MAILING_LIMIT_SENDBYDAY >= 0 ) {
$text .= $langs -> trans ( 'WarningLimitSendByDay' , $conf -> global -> MAILING_LIMIT_SENDBYDAY );
2020-10-31 14:32:18 +01:00
$text .= '<br><br>' ;
}
$text .= $langs -> trans ( 'ConfirmSendingEmailing' ) . '<br>' ;
2020-04-10 10:59:32 +02:00
$text .= $langs -> trans ( 'LimitSendingEmailing' , $conf -> global -> MAILING_LIMIT_SENDBYWEB );
2022-07-13 01:01:44 +02:00
if ( ! isset ( $conf -> global -> MAILING_LIMIT_SENDBYCLI ) || $conf -> global -> MAILING_LIMIT_SENDBYCLI >= 0 ) {
$text .= '<br><br>' ;
$text .= $langs -> trans ( " MailingNeedCommand " );
$text .= '<br><textarea cols="60" rows="' . ROWS_2 . '" wrap="soft" disabled>php ./scripts/emailings/mailing-send.php ' . $object -> id . ' ' . $user -> login . '</textarea>' ;
}
print $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $langs -> trans ( 'SendMailing' ), $text , 'sendallconfirmed' , '' , '' , 1 , 330 , 600 , 0 , $langs -> trans ( " Confirm " ), $langs -> trans ( " Cancel " ));
2008-02-29 17:26:38 +01:00
}
}
2005-02-12 00:41:42 +01:00
2018-09-23 16:09:25 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/comm/mailing/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2012-07-28 21:49:47 +02:00
2020-04-10 10:59:32 +02:00
$morehtmlright = '' ;
2018-01-29 12:46:07 +01:00
$nbtry = $nbok = 0 ;
2020-11-27 20:20:04 +01:00
if ( $object -> statut == 2 || $object -> statut == 3 ) {
2018-01-29 12:46:07 +01:00
$nbtry = $object -> countNbOfTargets ( 'alreadysent' );
$nbko = $object -> countNbOfTargets ( 'alreadysentko' );
2020-04-10 10:59:32 +02:00
$morehtmlright .= ' (' . $nbtry . '/' . $object -> nbemail ;
2020-11-27 20:20:04 +01:00
if ( $nbko ) {
$morehtmlright .= ' - ' . $nbko . ' ' . $langs -> trans ( " Error " );
}
2020-04-10 10:59:32 +02:00
$morehtmlright .= ') ' ;
2018-01-29 12:46:07 +01:00
}
2017-06-07 16:44:04 +02:00
2016-11-11 01:55:53 +01:00
dol_banner_tab ( $object , 'id' , $linkback , 1 , 'rowid' , 'ref' , '' , '' , 0 , '' , $morehtmlright );
2017-04-17 13:02:40 +02:00
print '<div class="fichecenter">' ;
2016-11-11 01:55:53 +01:00
print '<div class="underbanner clearboth"></div>' ;
2017-06-07 16:44:04 +02:00
2019-05-21 21:36:48 +02:00
print '<table class="border centpercent tableforfield">' ;
2016-11-11 01:15:41 +01:00
2010-04-17 11:47:25 +02:00
// Description
2019-10-02 14:44:38 +02:00
print '<tr><td class="titlefield">' ;
2020-10-07 17:41:36 +02:00
print $form -> editfieldkey ( " MailTitle " , 'title' , $object -> title , $object , $user -> rights -> mailing -> creer && $object -> statut < 3 , 'string' );
2019-10-02 14:44:38 +02:00
print '</td><td>' ;
2020-10-07 17:41:36 +02:00
print $form -> editfieldval ( " MailTitle " , 'title' , $object -> title , $object , $user -> rights -> mailing -> creer && $object -> statut < 3 , 'string' );
2010-04-17 11:47:25 +02:00
print '</td></tr>' ;
// From
2019-10-02 14:44:38 +02:00
print '<tr><td>' ;
print $form -> editfieldkey ( " MailFrom " , 'email_from' , $object -> email_from , $object , $user -> rights -> mailing -> creer && $object -> statut < 3 , 'string' );
print '</td><td>' ;
2019-01-27 11:55:16 +01:00
print $form -> editfieldval ( " MailFrom " , 'email_from' , $object -> email_from , $object , $user -> rights -> mailing -> creer && $object -> statut < 3 , 'string' );
2019-12-13 15:52:08 +01:00
$email = CMailFile :: getValidAddress ( $object -> email_from , 2 );
2019-12-13 16:29:58 +01:00
if ( $email && ! isValidEmail ( $email )) {
2019-12-13 15:52:08 +01:00
$langs -> load ( " errors " );
print img_warning ( $langs -> trans ( " ErrorBadEMail " , $email ));
2020-10-22 20:01:59 +02:00
} elseif ( $email && ! isValidMailDomain ( $email )) {
$langs -> load ( " errors " );
print img_warning ( $langs -> trans ( " ErrorBadMXDomain " , $email ));
2019-12-13 15:52:08 +01:00
}
2020-10-22 20:01:59 +02:00
2009-05-25 00:01:19 +02:00
print '</td></tr>' ;
2009-07-29 20:41:39 +02:00
// Errors to
2019-10-02 14:44:38 +02:00
print '<tr><td>' ;
print $form -> editfieldkey ( " MailErrorsTo " , 'email_errorsto' , $object -> email_errorsto , $object , $user -> rights -> mailing -> creer && $object -> statut < 3 , 'string' );
print '</td><td>' ;
2019-01-27 11:55:16 +01:00
print $form -> editfieldval ( " MailErrorsTo " , 'email_errorsto' , $object -> email_errorsto , $object , $user -> rights -> mailing -> creer && $object -> statut < 3 , 'string' );
2019-12-13 15:52:08 +01:00
$email = CMailFile :: getValidAddress ( $object -> email_errorsto , 2 );
2019-12-13 16:29:58 +01:00
if ( $email && ! isValidEmail ( $email )) {
2019-12-13 15:52:08 +01:00
$langs -> load ( " errors " );
print img_warning ( $langs -> trans ( " ErrorBadEMail " , $email ));
2020-10-22 20:01:59 +02:00
} elseif ( $email && ! isValidMailDomain ( $email )) {
$langs -> load ( " errors " );
print img_warning ( $langs -> trans ( " ErrorBadMXDomain " , $email ));
2019-12-13 15:52:08 +01:00
}
2009-05-25 00:01:19 +02:00
print '</td></tr>' ;
2017-06-07 16:44:04 +02:00
2020-10-14 18:26:05 +02:00
// Number of distinct emails
2013-03-24 19:00:58 +01:00
print '<tr><td>' ;
2009-08-26 11:50:00 +02:00
print $langs -> trans ( " TotalNbOfDistinctRecipients " );
print '</td><td colspan="3">' ;
2019-11-13 19:35:39 +01:00
$nbemail = ( $object -> nbemail ? $object -> nbemail : 0 );
2020-11-27 20:20:04 +01:00
if ( is_numeric ( $nbemail )) {
2020-10-31 14:32:18 +01:00
$text = '' ;
2020-11-27 20:20:04 +01:00
if (( ! empty ( $conf -> global -> MAILING_LIMIT_SENDBYWEB ) && $conf -> global -> MAILING_LIMIT_SENDBYWEB < $nbemail ) && ( $object -> statut == 1 || ( $object -> statut == 2 && $nbtry < $nbemail ))) {
if ( $conf -> global -> MAILING_LIMIT_SENDBYWEB > 0 ) {
2020-10-31 14:32:18 +01:00
$text .= $langs -> trans ( 'LimitSendingEmailing' , $conf -> global -> MAILING_LIMIT_SENDBYWEB );
} else {
$text .= $langs -> trans ( 'SendingFromWebInterfaceIsNotAllowed' );
}
}
2020-11-27 20:20:04 +01:00
if ( empty ( $nbemail )) {
2021-10-05 09:10:37 +02:00
$nbemail .= ' ' . img_warning ( '' ) . ' <span class="warning">' . $langs -> trans ( " NoTargetYet " ) . '</span>' ;
2020-11-27 20:20:04 +01:00
}
if ( $text ) {
2020-10-31 14:32:18 +01:00
print $form -> textwithpicto ( $nbemail , $text , 1 , 'warning' );
} else {
print $nbemail ;
}
2009-08-26 11:50:00 +02:00
}
print '</td></tr>' ;
2012-06-17 18:40:45 +02:00
2012-06-15 11:20:09 +02:00
// Other attributes
2019-11-13 19:35:39 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php' ;
2009-05-06 15:39:43 +02:00
print '</table>' ;
2005-02-12 00:41:42 +01:00
2009-05-06 15:39:43 +02:00
print " </div> " ;
2017-06-07 16:44:04 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2009-01-25 23:04:55 +01:00
2017-06-07 16:44:04 +02:00
2009-05-06 15:39:43 +02:00
// Clone confirmation
2020-11-27 20:20:04 +01:00
if ( $action == 'clone' ) {
2008-11-20 22:30:23 +01:00
// Create an array for form
2019-11-13 19:35:39 +01:00
$formquestion = array (
2008-11-20 22:30:23 +01:00
'text' => $langs -> trans ( " ConfirmClone " ),
2019-11-13 19:35:39 +01:00
array ( 'type' => 'checkbox' , 'name' => 'clone_content' , 'label' => $langs -> trans ( " CloneContent " ), 'value' => 1 ),
2014-04-28 17:18:11 +02:00
array ( 'type' => 'checkbox' , 'name' => 'clone_receivers' , 'label' => $langs -> trans ( " CloneReceivers " ), 'value' => 0 )
2008-11-10 15:20:02 +01:00
);
2020-10-14 18:26:05 +02:00
// Incomplete payment. On demande si motif = escompte ou autre
2019-03-12 19:44:59 +01:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $langs -> trans ( 'ToClone' ), $langs -> trans ( 'ConfirmCloneEMailing' , $object -> ref ), 'confirm_clone' , $formquestion , 'yes' , 2 , 240 );
2008-11-10 15:20:02 +01:00
}
2009-01-25 23:04:55 +01:00
2009-05-06 15:39:43 +02:00
/*
2020-10-14 18:26:05 +02:00
* Actions Buttons
2009-05-06 15:39:43 +02:00
*/
2010-04-17 11:47:25 +02:00
2020-11-27 20:20:04 +01:00
if ( GETPOST ( 'cancel' , 'alpha' ) || $confirm == 'no' || $action == '' || in_array ( $action , array ( 'settodraft' , 'valid' , 'delete' , 'sendall' , 'clone' , 'test' ))) {
2009-05-06 15:39:43 +02:00
print " \n \n <div class= \" tabsAction \" > \n " ;
2005-02-12 00:41:42 +01:00
2022-05-19 13:08:00 +02:00
if (( $object -> statut == 1 ) && ( $user -> rights -> mailing -> valider || $object -> user_validation == $user -> id )) {
2021-09-19 18:03:38 +02:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=settodraft&token=' . newToken () . '&id=' . $object -> id . '">' . $langs -> trans ( " SetToDraft " ) . '</a>' ;
2017-01-29 15:31:22 +01:00
}
2020-11-27 20:20:04 +01:00
if (( $object -> statut == 0 || $object -> statut == 1 || $object -> statut == 2 ) && $user -> rights -> mailing -> creer ) {
if ( ! empty ( $conf -> fckeditor -> enabled ) && ! empty ( $conf -> global -> FCKEDITOR_ENABLE_MAILING )) {
2021-09-19 18:03:38 +02:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=edit&token=' . newToken () . '&id=' . $object -> id . '">' . $langs -> trans ( " EditWithEditor " ) . '</a>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-09-19 18:03:38 +02:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=edit&token=' . newToken () . '&id=' . $object -> id . '">' . $langs -> trans ( " EditWithTextEditor " ) . '</a>' ;
2017-09-15 11:19:56 +02:00
}
2017-09-01 13:09:13 +02:00
2020-11-27 20:20:04 +01:00
if ( ! empty ( $conf -> use_javascript_ajax )) {
2021-09-19 18:03:38 +02:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=edithtml&token=' . newToken () . '&id=' . $object -> id . '">' . $langs -> trans ( " EditHTMLSource " ) . '</a>' ;
2020-11-27 20:20:04 +01:00
}
2009-05-06 15:39:43 +02:00
}
2005-02-12 00:41:42 +01:00
2014-09-18 21:18:25 +02:00
//print '<a class="butAction" href="card.php?action=test&id='.$object->id.'">'.$langs->trans("PreviewMailing").'</a>';
2012-06-17 18:40:45 +02:00
2020-11-27 20:20:04 +01:00
if ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! $user -> rights -> mailing -> mailing_advance -> send ) {
2018-11-13 21:40:17 +01:00
print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> transnoentitiesnoconv ( " NotEnoughPermissions " )) . '">' . $langs -> trans ( " TestMailing " ) . '</a>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-09-19 18:03:38 +02:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=test&token=' . newToken () . '&id=' . $object -> id . '">' . $langs -> trans ( " TestMailing " ) . '</a>' ;
2012-06-13 21:45:47 +02:00
}
2005-02-12 00:41:42 +01:00
2020-11-27 20:20:04 +01:00
if ( $object -> statut == 0 ) {
if ( $object -> nbemail <= 0 ) {
2018-11-13 21:40:17 +01:00
print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> transnoentitiesnoconv ( " NoTargetYet " )) . '">' . $langs -> trans ( " ValidMailing " ) . '</a>' ;
2020-11-27 20:20:04 +01:00
} elseif ( empty ( $user -> rights -> mailing -> valider )) {
2018-11-13 21:40:17 +01:00
print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> transnoentitiesnoconv ( " NotEnoughPermissions " )) . '">' . $langs -> trans ( " ValidMailing " ) . '</a>' ;
2020-05-21 15:05:19 +02:00
} else {
2012-03-23 20:03:57 +01:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=valid&id=' . $object -> id . '">' . $langs -> trans ( " ValidMailing " ) . '</a>' ;
2010-07-11 13:36:35 +02:00
}
2009-05-06 15:39:43 +02:00
}
2005-02-12 00:41:42 +01:00
2020-11-27 20:20:04 +01:00
if (( $object -> statut == 1 || $object -> statut == 2 ) && $object -> nbemail > 0 && $user -> rights -> mailing -> valider ) {
if ( $conf -> global -> MAILING_LIMIT_SENDBYWEB < 0 ) {
2018-11-13 21:40:17 +01:00
print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> transnoentitiesnoconv ( " SendingFromWebInterfaceIsNotAllowed " )) . '">' . $langs -> trans ( " SendMailing " ) . '</a>' ;
2020-11-27 20:20:04 +01:00
} elseif ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! $user -> rights -> mailing -> mailing_advance -> send ) {
2018-11-13 21:40:17 +01:00
print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> transnoentitiesnoconv ( " NotEnoughPermissions " )) . '">' . $langs -> trans ( " SendMailing " ) . '</a>' ;
2020-05-21 15:05:19 +02:00
} else {
2012-03-23 20:03:57 +01:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=sendall&id=' . $object -> id . '">' . $langs -> trans ( " SendMailing " ) . '</a>' ;
2011-01-21 11:58:05 +01:00
}
2009-05-06 15:39:43 +02:00
}
2005-02-15 22:17:36 +01:00
2020-11-27 20:20:04 +01:00
if ( $user -> rights -> mailing -> creer ) {
2012-03-23 20:03:57 +01:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=clone&object=emailing&id=' . $object -> id . '">' . $langs -> trans ( " ToClone " ) . '</a>' ;
2009-05-06 15:39:43 +02:00
}
2008-11-10 15:20:02 +01:00
2020-11-27 20:20:04 +01:00
if (( $object -> statut == 2 || $object -> statut == 3 ) && $user -> rights -> mailing -> valider ) {
if ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! $user -> rights -> mailing -> mailing_advance -> send ) {
2018-11-13 21:40:17 +01:00
print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> transnoentitiesnoconv ( " NotEnoughPermissions " )) . '">' . $langs -> trans ( " ResetMailing " ) . '</a>' ;
2020-05-21 15:05:19 +02:00
} else {
2012-06-13 21:45:47 +02:00
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=reset&id=' . $object -> id . '">' . $langs -> trans ( " ResetMailing " ) . '</a>' ;
}
2009-05-06 15:39:43 +02:00
}
2009-02-18 22:48:07 +01:00
2020-11-27 20:20:04 +01:00
if (( $object -> statut <= 1 && $user -> rights -> mailing -> creer ) || $user -> rights -> mailing -> supprimer ) {
if ( $object -> statut > 0 && ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! $user -> rights -> mailing -> mailing_advance -> delete )) {
2018-11-13 21:40:17 +01:00
print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> transnoentitiesnoconv ( " NotEnoughPermissions " )) . '">' . $langs -> trans ( " DeleteMailing " ) . '</a>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-09-18 22:04:41 +02:00
print '<a class="butActionDelete" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=delete&token=' . newToken () . '&id=' . $object -> id . ( ! empty ( $urlfrom ) ? '&urlfrom=' . $urlfrom : '' ) . '">' . $langs -> trans ( " DeleteMailing " ) . '</a>' ;
2012-06-14 20:08:46 +02:00
}
2009-05-06 15:39:43 +02:00
}
2005-02-12 00:41:42 +01:00
2016-05-06 12:15:44 +02:00
print '</div>' ;
2009-05-06 15:39:43 +02:00
}
2005-02-12 00:41:42 +01:00
2020-10-14 18:26:05 +02:00
// Display of the TEST form
2020-11-27 20:20:04 +01:00
if ( $action == 'test' ) {
2020-10-31 14:32:18 +01:00
print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>' ;
print load_fiche_titre ( $langs -> trans ( " TestMailing " ));
2009-05-06 15:39:43 +02:00
2020-10-31 14:32:18 +01:00
print dol_get_fiche_head ( null , '' , '' , - 1 );
2018-03-02 11:18:29 +01:00
2020-10-31 14:32:18 +01:00
// Create mail form object
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' ;
2009-05-06 15:39:43 +02:00
$formmail = new FormMail ( $db );
2012-03-23 20:03:57 +01:00
$formmail -> fromname = $object -> email_from ;
$formmail -> frommail = $object -> email_from ;
2019-11-13 19:35:39 +01:00
$formmail -> withsubstit = 1 ;
$formmail -> withfrom = 0 ;
$formmail -> withto = $user -> email ? $user -> email : 1 ;
$formmail -> withtocc = 0 ;
$formmail -> withtoccc = $conf -> global -> MAIN_EMAIL_USECCC ;
$formmail -> withtopic = 0 ;
$formmail -> withtopicreadonly = 1 ;
$formmail -> withfile = 0 ;
$formmail -> withbody = 0 ;
$formmail -> withbodyreadonly = 1 ;
$formmail -> withcancel = 1 ;
$formmail -> withdeliveryreceipt = 0 ;
2020-10-14 18:26:05 +02:00
// Table of substitutions
2019-11-13 19:35:39 +01:00
$formmail -> substit = $object -> substitutionarrayfortest ;
2020-10-14 18:26:05 +02:00
// Table of post's complementary params
2019-11-13 19:35:39 +01:00
$formmail -> param [ " action " ] = " send " ;
$formmail -> param [ " models " ] = 'none' ;
$formmail -> param [ " mailid " ] = $object -> id ;
$formmail -> param [ " returnurl " ] = $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id ;
2009-05-06 15:39:43 +02:00
2014-02-19 20:23:02 +01:00
print $formmail -> get_form ();
2009-01-25 23:04:55 +01:00
2009-05-06 15:39:43 +02:00
print '<br>' ;
2018-03-02 11:18:29 +01:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2018-03-02 11:18:29 +01:00
2022-05-19 13:08:00 +02:00
dol_set_focus ( '#sendto' );
2009-05-06 15:39:43 +02:00
}
2015-07-04 03:28:52 +02:00
2016-11-11 01:55:53 +01:00
$htmltext = '<i>' . $langs -> trans ( " FollowingConstantsWillBeSubstituted " ) . ':<br>' ;
2020-11-27 20:20:04 +01:00
foreach ( $object -> substitutionarray as $key => $val ) {
2019-11-13 19:35:39 +01:00
$htmltext .= $key . ' = ' . $langs -> trans ( $val ) . '<br>' ;
2016-11-11 01:15:41 +01:00
}
2019-11-13 19:35:39 +01:00
$htmltext .= '</i>' ;
2017-06-07 16:44:04 +02:00
2016-11-11 01:15:41 +01:00
// Print mail content
2019-10-02 15:54:42 +02:00
print load_fiche_titre ( $langs -> trans ( " EMail " ), $form -> textwithpicto ( '<span class="opacitymedium hideonsmartphone">' . $langs -> trans ( " AvailableVariables " ) . '</span>' , $htmltext , 1 , 'helpclickable' , '' , 0 , 2 , 'emailsubstitionhelp' ), 'generic' );
2017-06-07 16:44:04 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( '' , '' , '' , - 1 );
2017-06-07 16:44:04 +02:00
2018-03-02 11:18:29 +01:00
print '<table class="bordernooddeven" width="100%">' ;
2010-04-17 11:47:25 +02:00
// Subject
2016-07-06 22:28:13 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " MailTopic " ) . '</td><td colspan="3">' . $object -> sujet . '</td></tr>' ;
2010-04-17 11:47:25 +02:00
2011-06-11 04:25:05 +02:00
// Joined files
2011-11-21 13:17:14 +01:00
print '<tr><td>' . $langs -> trans ( " MailFile " ) . '</td><td colspan="3">' ;
// List of files
2019-11-13 19:35:39 +01:00
$listofpaths = dol_dir_list ( $upload_dir , 'all' , 0 , '' , '' , 'name' , SORT_ASC , 0 );
2020-11-27 20:20:04 +01:00
if ( count ( $listofpaths )) {
foreach ( $listofpaths as $key => $val ) {
2011-11-21 13:17:14 +01:00
print img_mime ( $listofpaths [ $key ][ 'name' ]) . ' ' . $listofpaths [ $key ][ 'name' ];
print '<br>' ;
2010-04-17 15:23:50 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2017-03-11 02:36:22 +01:00
print '<span class="opacitymedium">' . $langs -> trans ( " NoAttachedFiles " ) . '</span><br>' ;
2011-11-21 13:17:14 +01:00
}
print '</td></tr>' ;
2010-04-17 11:47:25 +02:00
2020-10-31 14:32:18 +01:00
// Background color
/* print '<tr><td width="15%">' . $langs -> trans ( " BackgroundColorByDefault " ) . '</td><td colspan="3">' ;
2020-11-27 20:20:04 +01:00
print $htmlother -> selectColor ( $object -> bgcolor , 'bgcolor' , '' , 0 );
print '</td></tr>' ; */
2017-06-07 16:44:04 +02:00
2016-11-11 01:15:41 +01:00
print '</table>' ;
2017-06-07 16:44:04 +02:00
2020-10-31 14:32:18 +01:00
// Message
2019-11-13 19:35:39 +01:00
print '<div style="padding-top: 10px; background: ' . ( $object -> bgcolor ? ( preg_match ( '/^#/' , $object -> bgcolor ) ? '' : '#' ) . $object -> bgcolor : 'white' ) . '">' ;
2020-11-27 20:20:04 +01:00
if ( empty ( $object -> bgcolor ) || strtolower ( $object -> bgcolor ) == 'ffffff' ) { // CKEditor does not apply the color of the div into its content area
2019-11-13 19:35:39 +01:00
$readonly = 1 ;
2020-10-14 18:26:05 +02:00
// wysiwyg editor
2013-03-30 14:27:13 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2019-11-13 19:35:39 +01:00
$doleditor = new DolEditor ( 'bodyemail' , $object -> body , '' , 600 , 'dolibarr_mailings' , '' , false , true , empty ( $conf -> global -> FCKEDITOR_ENABLE_MAILING ) ? 0 : 1 , 20 , '90%' , $readonly );
2013-03-24 19:00:58 +01:00
$doleditor -> Create ();
2020-11-27 20:20:04 +01:00
} else {
print dol_htmlentitiesbr ( $object -> body );
}
2016-11-11 01:15:41 +01:00
print '</div>' ;
2015-07-04 03:28:52 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2020-05-21 15:05:19 +02:00
} else {
2009-05-06 15:39:43 +02:00
/*
2020-10-14 18:26:05 +02:00
* Edition mode mailing ( CKeditor or HTML source )
2009-05-06 15:39:43 +02:00
*/
2017-06-07 16:44:04 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'card' , $langs -> trans ( " Mailing " ), - 1 , 'email' );
2017-06-07 16:44:04 +02:00
2019-12-05 15:22:06 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/comm/mailing/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2016-05-06 12:15:44 +02:00
2019-11-13 19:35:39 +01:00
$morehtmlright = '' ;
2020-11-27 20:20:04 +01:00
if ( $object -> statut == 2 ) {
$morehtmlright .= ' (' . $object -> countNbOfTargets ( 'alreadysent' ) . '/' . $object -> nbemail . ') ' ;
}
2017-06-07 16:44:04 +02:00
2016-11-11 01:55:53 +01:00
dol_banner_tab ( $object , 'id' , $linkback , 1 , 'rowid' , 'ref' , '' , '' , 0 , '' , $morehtmlright );
2017-06-07 16:44:04 +02:00
2017-04-17 13:02:40 +02:00
print '<div class="fichecenter">' ;
2016-11-11 01:55:53 +01:00
print '<div class="underbanner clearboth"></div>' ;
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">' ;
2016-11-11 01:15:41 +01:00
2016-11-11 01:55:53 +01:00
/*
2016-07-06 22:28:13 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " Ref " ) . '</td>' ;
2016-05-06 12:15:44 +02:00
print '<td colspan="3">' ;
print $form -> showrefnav ( $object , 'id' , $linkback );
print '</td></tr>' ;
2016-11-11 01:55:53 +01:00
*/
2017-06-07 16:44:04 +02:00
2012-05-09 17:15:44 +02:00
// Topic
2020-10-07 17:41:36 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " MailTitle " ) . '</td><td colspan="3">' . $object -> title . '</td></tr>' ;
2012-05-09 17:15:44 +02:00
// From
2019-01-27 11:55:16 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( " MailFrom " ) . '</td><td colspan="3">' . dol_print_email ( $object -> email_from , 0 , 0 , 0 , 0 , 1 ) . '</td></tr>' ;
2012-05-09 17:15:44 +02:00
// To
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $langs -> trans ( " MailErrorsTo " ) . '</td><td colspan="3">' . dol_print_email ( $object -> email_errorsto , 0 , 0 , 0 , 0 , 1 ) . '</td></tr>' ;
2010-04-17 11:47:25 +02:00
2020-10-14 18:26:05 +02:00
// Number of distinct emails
2016-05-06 12:15:44 +02:00
print '<tr><td>' ;
2010-04-17 11:47:25 +02:00
print $langs -> trans ( " TotalNbOfDistinctRecipients " );
print '</td><td colspan="3">' ;
2019-11-13 19:35:39 +01:00
$nbemail = ( $object -> nbemail ? $object -> nbemail : 0 );
2020-11-27 20:20:04 +01:00
if ( is_numeric ( $nbemail )) {
2019-11-13 19:35:39 +01:00
$text = '' ;
2020-11-27 20:20:04 +01:00
if (( ! empty ( $conf -> global -> MAILING_LIMIT_SENDBYWEB ) && $conf -> global -> MAILING_LIMIT_SENDBYWEB < $nbemail ) && ( $object -> statut == 1 || $object -> statut == 2 )) {
if ( $conf -> global -> MAILING_LIMIT_SENDBYWEB > 0 ) {
2019-11-13 19:35:39 +01:00
$text .= $langs -> trans ( 'LimitSendingEmailing' , $conf -> global -> MAILING_LIMIT_SENDBYWEB );
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$text .= $langs -> trans ( 'SendingFromWebInterfaceIsNotAllowed' );
2018-01-26 15:12:40 +01:00
}
}
2020-11-27 20:20:04 +01:00
if ( empty ( $nbemail )) {
2021-10-05 09:10:37 +02:00
$nbemail .= ' ' . img_warning ( '' ) . ' <span class="warning">' . $langs -> trans ( " NoTargetYet " ) . '</span>' ;
2020-11-27 20:20:04 +01:00
}
if ( $text ) {
2019-01-27 11:55:16 +01:00
print $form -> textwithpicto ( $nbemail , $text , 1 , 'warning' );
2020-05-21 15:05:19 +02:00
} else {
2018-01-26 15:12:40 +01:00
print $nbemail ;
}
2010-04-17 11:47:25 +02:00
}
print '</td></tr>' ;
2012-06-17 18:40:45 +02:00
2012-06-15 11:20:09 +02:00
// Other attributes
2019-11-13 19:35:39 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2020-10-31 14:32:18 +01:00
print $hookmanager -> resPrint ;
2020-11-27 20:20:04 +01:00
if ( empty ( $reshook )) {
2019-11-16 14:38:05 +01:00
print $object -> showOptionals ( $extrafields , 'edit' , $parameters );
2012-06-13 09:26:29 +02:00
}
2010-04-17 11:47:25 +02:00
print '</table>' ;
2017-04-17 13:02:40 +02:00
print '</div>' ;
2016-02-08 12:20:40 +01:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2016-02-08 12:20:40 +01:00
2010-04-17 11:47:25 +02:00
2016-11-11 01:15:41 +01:00
print " <br> \n " ;
2017-06-07 16:44:04 +02:00
2014-09-18 21:18:25 +02:00
print '<form name="edit_mailing" action="card.php" method="post" enctype="multipart/form-data">' . " \n " ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2009-05-06 15:39:43 +02:00
print '<input type="hidden" name="action" value="update">' ;
2012-03-23 20:03:57 +01:00
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
2017-06-07 16:44:04 +02:00
2016-11-11 01:55:53 +01:00
$htmltext = '<i>' . $langs -> trans ( " FollowingConstantsWillBeSubstituted " ) . ':<br>' ;
2020-11-27 20:20:04 +01:00
foreach ( $object -> substitutionarray as $key => $val ) {
2019-11-13 19:35:39 +01:00
$htmltext .= $key . ' = ' . $langs -> trans ( $val ) . '<br>' ;
2016-11-11 01:15:41 +01:00
}
2019-11-13 19:35:39 +01:00
$htmltext .= '</i>' ;
2017-06-07 16:44:04 +02:00
2010-04-17 11:47:25 +02:00
// Print mail content
2019-09-30 10:14:55 +02:00
print load_fiche_titre ( $langs -> trans ( " EMail " ), $form -> textwithpicto ( $langs -> trans ( " AvailableVariables " ), $htmltext , 1 , 'help' , '' , 0 , 2 , 'emailsubstitionhelp' ), 'generic' );
2015-11-05 03:02:31 +01:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( null , '' , '' , - 1 );
2017-06-07 16:44:04 +02:00
2018-03-02 11:18:29 +01:00
print '<table class="bordernooddeven" width="100%">' ;
2009-05-06 15:39:43 +02:00
2011-06-11 04:25:05 +02:00
// Subject
2016-11-11 01:15:41 +01:00
print '<tr><td class="fieldrequired titlefield">' . $langs -> trans ( " MailTopic " ) . '</td><td colspan="3"><input class="flat quatrevingtpercent" type="text" name="sujet" value="' . $object -> sujet . '"></td></tr>' ;
2010-04-17 11:47:25 +02:00
2019-11-13 19:35:39 +01:00
$trackid = '' ; // TODO To avoid conflicts with 2 mass emailing, we should set a trackid here, even if we use another one into email header.
2016-06-24 16:10:52 +02:00
dol_init_file_process ( $upload_dir , $trackid );
2011-12-17 13:51:31 +01:00
2011-06-11 04:25:05 +02:00
// Joined files
2019-11-13 19:35:39 +01:00
$addfileaction = 'addfile' ;
2011-11-21 13:17:14 +01:00
print '<tr><td>' . $langs -> trans ( " MailFile " ) . '</td>' ;
print '<td colspan="3">' ;
// List of files
2019-11-13 19:35:39 +01:00
$listofpaths = dol_dir_list ( $upload_dir , 'all' , 0 , '' , '' , 'name' , SORT_ASC , 0 );
2017-09-01 13:09:13 +02:00
2011-11-21 13:17:14 +01:00
// TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
2019-11-13 19:35:39 +01:00
$out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">' . " \n " ;
2021-11-29 15:09:18 +01:00
$out .= '<script type="text/javascript">' ;
2019-11-13 19:35:39 +01:00
$out .= 'jQuery(document).ready(function () {' ;
$out .= ' jQuery(".removedfile").click(function() {' ;
$out .= ' jQuery(".removedfilehidden").val(jQuery(this).val());' ;
$out .= ' });' ;
$out .= '})' ;
$out .= '</script>' . " \n " ;
2020-11-27 20:20:04 +01:00
if ( count ( $listofpaths )) {
foreach ( $listofpaths as $key => $val ) {
2019-11-13 19:35:39 +01:00
$out .= '<div id="attachfile_' . $key . '">' ;
$out .= img_mime ( $listofpaths [ $key ][ 'name' ]) . ' ' . $listofpaths [ $key ][ 'name' ];
$out .= ' <input type="image" style="border: 0px;" src="' . img_picto ( $langs -> trans ( " Search " ), 'delete.png' , '' , '' , 1 ) . '" value="' . ( $key + 1 ) . '" class="removedfile" id="removedfile_' . $key . '" name="removedfile_' . $key . '" />' ;
$out .= '<br></div>' ;
2010-04-17 15:23:50 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2021-04-04 17:05:01 +02:00
$out .= '<span class="opacitymedium">' . $langs -> trans ( " NoAttachedFiles " ) . '</span><br>' ;
2011-11-21 13:17:14 +01:00
}
// Add link to add file
2022-06-19 19:02:16 +02:00
$maxfilesizearray = getMaxFileSizeArray ();
$maxmin = $maxfilesizearray [ 'maxmin' ];
if ( $maxmin > 0 ) {
2022-06-20 02:23:37 +02:00
$out .= '<input type="hidden" name="MAX_FILE_SIZE" value="' . ( $maxmin * 1024 ) . '">' ; // MAX_FILE_SIZE must precede the field type=file
2022-06-19 19:02:16 +02:00
}
2019-11-13 19:35:39 +01:00
$out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="' . $langs -> trans ( " Upload " ) . '" />' ;
$out .= ' ' ;
$out .= '<input type="submit" class="button" id="' . $addfileaction . '" name="' . $addfileaction . '" value="' . $langs -> trans ( " MailingAddFile " ) . '" />' ;
2011-11-21 13:17:14 +01:00
print $out ;
print '</td></tr>' ;
2010-04-17 11:47:25 +02:00
2020-10-31 14:32:18 +01:00
// Background color
2016-07-06 22:28:13 +02:00
print '<tr><td>' . $langs -> trans ( " BackgroundColorByDefault " ) . '</td><td colspan="3">' ;
2019-01-27 11:55:16 +01:00
print $htmlother -> selectColor ( $object -> bgcolor , 'bgcolor' , '' , 0 );
2009-05-19 15:27:44 +02:00
print '</td></tr>' ;
2017-06-07 16:44:04 +02:00
2016-11-11 01:15:41 +01:00
print '</table>' ;
2017-06-07 16:44:04 +02:00
2011-06-11 04:25:05 +02:00
// Message
2016-11-11 01:15:41 +01:00
print '<div style="padding-top: 10px">' ;
2017-09-01 13:09:13 +02:00
2020-11-27 20:20:04 +01:00
if ( $action == 'edit' ) {
2020-10-14 18:26:05 +02:00
// wysiwyg editor
2017-09-01 13:09:13 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2022-06-22 08:36:24 +02:00
$doleditor = new DolEditor ( 'bodyemail' , $object -> body , '' , 600 , 'dolibarr_mailings' , '' , true , true , getDolGlobalInt ( 'FCKEDITOR_ENABLE_MAILING' ), 20 , '90%' );
2017-09-01 13:09:13 +02:00
$doleditor -> Create ();
}
2020-11-27 20:20:04 +01:00
if ( $action == 'edithtml' ) {
2020-10-14 18:26:05 +02:00
// HTML source editor
2017-09-01 13:09:13 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2019-11-13 19:35:39 +01:00
$doleditor = new DolEditor ( 'bodyemail' , $object -> body , '' , 600 , 'dolibarr_mailings' , '' , true , true , 'ace' , 20 , '90%' );
2017-09-01 13:09:13 +02:00
$doleditor -> Create ( 0 , '' , false , 'HTML Source' , 'php' );
}
2016-11-11 01:15:41 +01:00
print '</div>' ;
2009-05-06 15:39:43 +02:00
2013-03-24 19:00:58 +01:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2016-02-08 12:20:40 +01:00
2015-11-05 03:02:31 +01:00
print '<div class="center">' ;
2020-11-19 20:23:38 +01:00
print '<input type="submit" class="button buttonforacesave button-save" value="' . $langs -> trans ( " Save " ) . '" name="save">' ;
2014-11-25 20:13:43 +01:00
print ' ' ;
2020-11-23 15:12:52 +01:00
print '<input type="submit" class="button button-cancel" value="' . $langs -> trans ( " Cancel " ) . '" name="cancel">' ;
2014-11-25 20:13:43 +01:00
print '</div>' ;
2009-05-06 15:39:43 +02:00
2010-04-17 11:47:25 +02:00
print '</form>' ;
print '<br>' ;
2009-05-06 15:39:43 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2019-01-27 11:55:16 +01:00
dol_print_error ( $db , $object -> error );
2009-05-20 13:20:49 +02:00
}
2005-02-12 00:41:42 +01:00
}
2005-01-05 16:26:05 +01:00
2018-07-29 17:17:29 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-03-23 20:03:57 +01:00
$db -> close ();