2012-08-22 23:27:53 +02:00
< ? php
2023-01-26 10:46:59 +01:00
/* Copyright ( C ) 2005 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
* Copyright ( C ) 2010 - 2011 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2015 - 2017 Marcos García < marcosgdf @ gmail . com >
* Copyright ( C ) 2015 - 2017 Nicolas ZABOURI < info @ inovea - conseil . com >
* Copyright ( C ) 2018 - 2022 Frédéric France < frederic . france @ netlogic . fr >
* Copyright ( C ) 2022 Charlene Benke < charlene @ patas - monkey . com >
* Copyright ( C ) 2023 Anthony Berton < anthony . berton @ bb2a . fr >
*
2010-05-03 10:43:32 +02: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
2010-05-03 10:43:32 +02: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 />.
2010-05-03 10:43:32 +02:00
*/
/**
2010-06-08 01:52:43 +02:00
* \file htdocs / core / class / html . formmail . class . php
2010-11-22 10:18:53 +01:00
* \ingroup core
2010-05-03 10:43:32 +02:00
* \brief Fichier de la classe permettant la generation du formulaire html d ' envoi de mail unitaire
*/
2019-12-03 11:17:29 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php' ;
2010-05-03 10:43:32 +02:00
2012-01-27 15:17:36 +01:00
/**
* Classe permettant la generation du formulaire html d ' envoi de mail unitaire
* Usage : $formail = new FormMail ( $db )
* $formmail -> proprietes = 1 ou chaine ou tableau de valeurs
* $formmail -> show_form () affiche le formulaire
2010-05-03 10:43:32 +02:00
*/
2015-04-18 11:06:53 +02:00
class FormMail extends Form
2010-05-03 10:43:32 +02:00
{
2018-08-22 11:06:34 +02:00
/**
2020-09-07 10:18:17 +02:00
* @ var DoliDB Database handler .
*/
public $db ;
/**
* @ var int 1 = Include HTML form tag and show submit button
* 0 = Do not include form tag and submit button
* - 1 = Do not include form tag but include submit button
*/
2019-10-27 18:08:21 +01:00
public $withform ;
2011-06-29 12:23:32 +02:00
2020-09-07 10:18:17 +02:00
/**
* @ var string name from
*/
2018-08-29 12:35:56 +02:00
public $fromname ;
2019-10-27 18:08:21 +01:00
2020-09-07 10:18:17 +02:00
/**
* @ var string email from
*/
2018-08-29 12:35:56 +02:00
public $frommail ;
2018-10-16 22:27:34 +02:00
2020-09-07 10:18:17 +02:00
/**
* @ var string user , company , robot
*/
public $fromtype ;
/**
* @ var int from ID
*/
public $fromid ;
/**
* @ var int also from robot
*/
public $fromalsorobot ;
/**
* @ var string thirdparty etc
*/
public $totype ;
/**
* @ var int ID
*/
public $toid ;
/**
2022-08-02 20:22:10 +02:00
* @ var string Reply - to name
2020-09-07 10:18:17 +02:00
*/
public $replytoname ;
/**
* @ var string replyto email
*/
2018-08-29 12:35:56 +02:00
public $replytomail ;
2019-10-27 18:08:21 +01:00
2020-09-07 10:18:17 +02:00
/**
2022-08-02 20:22:10 +02:00
* @ var string To name
2020-09-07 10:18:17 +02:00
*/
2018-08-29 12:35:56 +02:00
public $toname ;
2019-10-27 18:08:21 +01:00
2020-09-07 10:18:17 +02:00
/**
2022-08-02 20:22:10 +02:00
* @ var string To email
2020-09-07 10:18:17 +02:00
*/
2018-08-29 12:35:56 +02:00
public $tomail ;
2019-10-27 18:08:21 +01:00
2020-09-07 10:18:17 +02:00
/**
2022-08-02 20:22:10 +02:00
* @ var string Track id
2020-09-07 10:18:17 +02:00
*/
2018-08-29 12:35:56 +02:00
public $trackid ;
2022-08-02 20:22:10 +02:00
/**
* @ var string If you know a MSGID of an email and want to send the email in reply to it . Will be added into header as In - Reply - To : <...>
*/
public $inreplyto ;
2019-12-03 11:17:29 +01:00
public $withsubstit ; // Show substitution array
2018-08-29 12:35:56 +02:00
public $withfrom ;
2014-04-30 15:17:39 +02:00
2015-04-23 23:21:06 +02:00
/**
2020-02-20 01:34:33 +01:00
* @ var int | string | array
2015-04-23 23:21:06 +02:00
*/
2019-12-03 11:17:29 +01:00
public $withto ; // Show recipient emails
2022-06-12 11:17:11 +02:00
public $withreplyto ;
2018-08-29 12:35:56 +02:00
2021-01-04 23:41:20 +01:00
/**
* @ var int | string 0 = Do not Show free text for recipient emails
* 1 = Show free text for recipient emails
* or a free email
*/
public $withtofree ;
2018-08-29 12:35:56 +02:00
public $withtocc ;
public $withtoccc ;
public $withtopic ;
2023-09-02 10:14:25 +02:00
public $witherrorsto ;
2021-01-02 09:47:29 +01:00
/**
* @ var int 0 = No attaches files , 1 = Show attached files , 2 = Can add new attached files
*/
public $withfile ;
/**
* @ var int 1 = Add a checkbox " Attach also main document " for mass actions ( checked by default ), - 1 = Add checkbox ( not checked by default )
*/
public $withmaindocfile ;
2018-08-29 12:35:56 +02:00
public $withbody ;
public $withfromreadonly ;
public $withreplytoreadonly ;
public $withtoreadonly ;
public $withtoccreadonly ;
2023-09-02 10:14:25 +02:00
public $witherrorstoreadonly ;
2018-08-29 12:35:56 +02:00
public $withtocccreadonly ;
public $withtopicreadonly ;
2023-09-02 10:14:25 +02:00
public $withbodyreadonly ;
2018-08-29 12:35:56 +02:00
public $withfilereadonly ;
public $withdeliveryreceipt ;
public $withcancel ;
2023-09-02 10:14:25 +02:00
public $withdeliveryreceiptreadonly ;
2018-08-29 12:35:56 +02:00
public $withfckeditor ;
2023-09-02 10:14:25 +02:00
/**
* @ var string ckeditortoolbar
*/
public $ckeditortoolbar ;
2019-12-03 11:17:29 +01:00
public $substit = array ();
public $substit_lines = array ();
public $param = array ();
2017-10-13 13:28:26 +02:00
2019-12-03 11:17:29 +01:00
public $withtouser = array ();
public $withtoccuser = array ();
2018-03-21 11:48:30 +01:00
2017-10-13 13:28:26 +02:00
public $lines_model ;
2022-01-21 13:44:40 +01:00
// -1 suggest the checkbox 'one email per recipient' not checked, 0 = no suggestion, 1 = suggest and checked
2021-10-21 18:15:15 +02:00
public $withoptiononeemailperrecipient ;
2017-10-13 13:28:26 +02:00
/**
* Constructor
*
* @ param DoliDB $db Database handler
*/
2019-02-27 20:45:07 +01:00
public function __construct ( $db )
2017-10-13 13:28:26 +02:00
{
$this -> db = $db ;
2019-12-03 11:17:29 +01:00
$this -> withform = 1 ;
$this -> withfrom = 1 ;
$this -> withto = 1 ;
$this -> withtofree = 1 ;
$this -> withtocc = 1 ;
$this -> withtoccc = 0 ;
$this -> witherrorsto = 0 ;
$this -> withtopic = 1 ;
$this -> withfile = 0 ; // 1=Add section "Attached files". 2=Can add files.
$this -> withmaindocfile = 0 ; // 1=Add a checkbox "Attach also main document" for mass actions (checked by default), -1=Add checkbox (not checked by default)
$this -> withbody = 1 ;
$this -> withfromreadonly = 1 ;
$this -> withreplytoreadonly = 1 ;
$this -> withtoreadonly = 0 ;
$this -> withtoccreadonly = 0 ;
$this -> withtocccreadonly = 0 ;
$this -> witherrorstoreadonly = 0 ;
$this -> withtopicreadonly = 0 ;
$this -> withfilereadonly = 0 ;
$this -> withbodyreadonly = 0 ;
$this -> withdeliveryreceiptreadonly = 0 ;
$this -> withfckeditor = - 1 ; // -1 = Auto
2017-10-13 13:28:26 +02:00
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Clear list of attached files in send mail form ( also stored in session )
*
* @ return void
*/
2019-02-27 20:45:07 +01:00
public function clear_attached_files ()
2017-10-13 13:28:26 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-12-03 11:17:29 +01:00
global $conf , $user ;
2017-10-13 13:28:26 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
// Set tmp user directory
2019-12-03 11:17:29 +01:00
$vardir = $conf -> user -> dir_output . " / " . $user -> id ;
$upload_dir = $vardir . '/temp/' ; // TODO Add $keytoavoidconflict in upload_dir path
2021-01-02 09:47:29 +01:00
if ( is_dir ( $upload_dir )) {
dol_delete_dir_recursive ( $upload_dir );
}
2017-10-13 13:28:26 +02:00
2019-12-03 11:17:29 +01:00
$keytoavoidconflict = empty ( $this -> trackid ) ? '' : '-' . $this -> trackid ; // this->trackid must be defined
2017-10-13 13:28:26 +02:00
unset ( $_SESSION [ " listofpaths " . $keytoavoidconflict ]);
unset ( $_SESSION [ " listofnames " . $keytoavoidconflict ]);
unset ( $_SESSION [ " listofmimes " . $keytoavoidconflict ]);
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Add a file into the list of attached files ( stored in SECTION array )
*
* @ param string $path Full absolute path on filesystem of file , including file name
2018-03-08 15:01:34 +01:00
* @ param string $file Only filename ( can be basename ( $path ))
* @ param string $type Mime type ( can be dol_mimetype ( $file ))
2017-10-13 13:28:26 +02:00
* @ return void
*/
2019-02-27 20:45:07 +01:00
public function add_attached_files ( $path , $file = '' , $type = '' )
2017-10-13 13:28:26 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-12-03 11:17:29 +01:00
$listofpaths = array ();
$listofnames = array ();
$listofmimes = array ();
2021-01-02 09:47:29 +01:00
if ( empty ( $file )) {
$file = basename ( $path );
}
if ( empty ( $type )) {
$type = dol_mimetype ( $file );
}
2019-12-03 11:17:29 +01:00
$keytoavoidconflict = empty ( $this -> trackid ) ? '' : '-' . $this -> trackid ; // this->trackid must be defined
2021-01-02 09:47:29 +01:00
if ( ! empty ( $_SESSION [ " listofpaths " . $keytoavoidconflict ])) {
$listofpaths = explode ( ';' , $_SESSION [ " listofpaths " . $keytoavoidconflict ]);
}
if ( ! empty ( $_SESSION [ " listofnames " . $keytoavoidconflict ])) {
$listofnames = explode ( ';' , $_SESSION [ " listofnames " . $keytoavoidconflict ]);
}
if ( ! empty ( $_SESSION [ " listofmimes " . $keytoavoidconflict ])) {
$listofmimes = explode ( ';' , $_SESSION [ " listofmimes " . $keytoavoidconflict ]);
}
if ( ! in_array ( $file , $listofnames )) {
2019-12-03 11:17:29 +01:00
$listofpaths [] = $path ;
$listofnames [] = $file ;
$listofmimes [] = $type ;
$_SESSION [ " listofpaths " . $keytoavoidconflict ] = join ( ';' , $listofpaths );
$_SESSION [ " listofnames " . $keytoavoidconflict ] = join ( ';' , $listofnames );
$_SESSION [ " listofmimes " . $keytoavoidconflict ] = join ( ';' , $listofmimes );
2017-10-13 13:28:26 +02:00
}
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Remove a file from the list of attached files ( stored in SECTION array )
*
2023-09-16 16:37:56 +02:00
* @ param int $keytodelete Key index in file array ( 0 , 1 , 2 , ... )
2017-10-13 13:28:26 +02:00
* @ return void
*/
2019-02-27 20:45:07 +01:00
public function remove_attached_files ( $keytodelete )
2017-10-13 13:28:26 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-12-03 11:17:29 +01:00
$listofpaths = array ();
$listofnames = array ();
$listofmimes = array ();
$keytoavoidconflict = empty ( $this -> trackid ) ? '' : '-' . $this -> trackid ; // this->trackid must be defined
2021-01-02 09:47:29 +01:00
if ( ! empty ( $_SESSION [ " listofpaths " . $keytoavoidconflict ])) {
$listofpaths = explode ( ';' , $_SESSION [ " listofpaths " . $keytoavoidconflict ]);
}
if ( ! empty ( $_SESSION [ " listofnames " . $keytoavoidconflict ])) {
$listofnames = explode ( ';' , $_SESSION [ " listofnames " . $keytoavoidconflict ]);
}
if ( ! empty ( $_SESSION [ " listofmimes " . $keytoavoidconflict ])) {
$listofmimes = explode ( ';' , $_SESSION [ " listofmimes " . $keytoavoidconflict ]);
}
if ( $keytodelete >= 0 ) {
2019-02-24 20:06:55 +01:00
unset ( $listofpaths [ $keytodelete ]);
unset ( $listofnames [ $keytodelete ]);
unset ( $listofmimes [ $keytodelete ]);
2019-12-03 11:17:29 +01:00
$_SESSION [ " listofpaths " . $keytoavoidconflict ] = join ( ';' , $listofpaths );
$_SESSION [ " listofnames " . $keytoavoidconflict ] = join ( ';' , $listofnames );
$_SESSION [ " listofmimes " . $keytoavoidconflict ] = join ( ';' , $listofmimes );
2017-10-13 13:28:26 +02:00
//var_dump($_SESSION['listofpaths']);
}
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Return list of attached files ( stored in SECTION array )
*
* @ return array array ( 'paths' => , 'names' => , 'mimes' => )
*/
2019-02-27 20:45:07 +01:00
public function get_attached_files ()
2017-10-13 13:28:26 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-12-03 11:17:29 +01:00
$listofpaths = array ();
$listofnames = array ();
$listofmimes = array ();
$keytoavoidconflict = empty ( $this -> trackid ) ? '' : '-' . $this -> trackid ; // this->trackid must be defined
2021-01-02 09:47:29 +01:00
if ( ! empty ( $_SESSION [ " listofpaths " . $keytoavoidconflict ])) {
$listofpaths = explode ( ';' , $_SESSION [ " listofpaths " . $keytoavoidconflict ]);
}
if ( ! empty ( $_SESSION [ " listofnames " . $keytoavoidconflict ])) {
$listofnames = explode ( ';' , $_SESSION [ " listofnames " . $keytoavoidconflict ]);
}
if ( ! empty ( $_SESSION [ " listofmimes " . $keytoavoidconflict ])) {
$listofmimes = explode ( ';' , $_SESSION [ " listofmimes " . $keytoavoidconflict ]);
}
2017-10-13 13:28:26 +02:00
return array ( 'paths' => $listofpaths , 'names' => $listofnames , 'mimes' => $listofmimes );
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Show the form to input an email
* this -> withfile : 0 = No attaches files , 1 = Show attached files , 2 = Can add new attached files
* this -> withmaindocfile
*
* @ param string $addfileaction Name of action when posting file attachments
* @ param string $removefileaction Name of action when removing file attachments
* @ return void
2020-10-17 12:59:22 +02:00
* @ deprecated
2017-10-13 13:28:26 +02:00
*/
2019-02-27 20:45:07 +01:00
public function show_form ( $addfileaction = 'addfile' , $removefileaction = 'removefile' )
2017-10-13 13:28:26 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2019-01-27 11:55:16 +01:00
print $this -> get_form ( $addfileaction , $removefileaction );
2017-10-13 13:28:26 +02:00
}
2020-09-07 10:18:17 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-13 13:28:26 +02:00
/**
* Get the form to input an email
* this -> withfile : 0 = No attaches files , 1 = Show attached files , 2 = Can add new attached files
2018-04-06 16:16:08 +02:00
* this -> param : Contains more parameters like email templates info
2020-05-28 11:41:48 +02:00
* this -> withfckeditor : 1 = We use an advanced editor , so we switch content into HTML
2017-10-13 13:28:26 +02:00
*
* @ param string $addfileaction Name of action when posting file attachments
* @ param string $removefileaction Name of action when removing file attachments
* @ return string Form to show
*/
2019-02-27 20:45:07 +01:00
public function get_form ( $addfileaction = 'addfile' , $removefileaction = 'removefile' )
2017-10-13 13:28:26 +02:00
{
2020-09-07 10:18:17 +02:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
global $conf , $langs , $user , $hookmanager , $form ;
2022-01-21 13:44:40 +01:00
// Required to show preview wof mail attachments
2020-09-07 10:18:17 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
2023-08-05 14:11:44 +02:00
$formfile = new FormFile ( $this -> db );
2020-06-09 11:32:34 +02:00
2021-01-04 23:41:20 +01:00
if ( ! is_object ( $form )) {
$form = new Form ( $this -> db );
}
2017-10-13 13:28:26 +02:00
2018-09-11 10:36:39 +02:00
// Load translation files required by the page
2022-01-21 13:44:40 +01:00
$langs -> loadLangs ( array ( 'other' , 'mails' , 'members' ));
2018-02-27 10:59:26 +01:00
2021-02-28 12:47:24 +01:00
// Clear temp files. Must be done before call of triggers, at beginning (mode = init), or when we select a new template
if ( GETPOST ( 'mode' , 'alpha' ) == 'init' || ( GETPOST ( 'modelselected' ) && GETPOST ( 'modelmailselected' , 'alpha' ) && GETPOST ( 'modelmailselected' , 'alpha' ) != '-1' )) {
2018-02-27 10:59:26 +01:00
$this -> clear_attached_files ();
}
// Call hook getFormMail
2017-10-13 13:28:26 +02:00
$hookmanager -> initHooks ( array ( 'formmail' ));
2019-12-03 11:17:29 +01:00
$parameters = array (
2017-10-13 13:28:26 +02:00
'addfileaction' => $addfileaction ,
'removefileaction' => $removefileaction ,
'trackid' => $this -> trackid
);
2019-12-03 11:17:29 +01:00
$reshook = $hookmanager -> executeHooks ( 'getFormMail' , $parameters , $this );
2017-10-13 13:28:26 +02:00
2021-01-04 23:41:20 +01:00
if ( ! empty ( $reshook )) {
2017-10-13 13:28:26 +02:00
return $hookmanager -> resPrint ;
2020-05-21 15:05:19 +02:00
} else {
2019-12-03 11:17:29 +01:00
$out = '' ;
2015-05-04 22:02:54 +02:00
2019-12-03 11:17:29 +01:00
$disablebademails = 1 ;
2017-06-01 01:53:55 +02:00
2018-08-22 13:37:18 +02:00
// Define output language
2014-09-17 01:12:59 +02:00
$outputlangs = $langs ;
$newlang = '' ;
2022-09-24 14:43:29 +02:00
if ( getDolGlobalInt ( 'MAIN_MULTILANGS' ) && ! empty ( $this -> param [ 'langsmodels' ])) {
2021-01-12 23:46:29 +01:00
$newlang = $this -> param [ 'langsmodels' ];
}
2021-01-04 23:41:20 +01:00
if ( ! empty ( $newlang )) {
2014-09-17 01:12:59 +02:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
$outputlangs -> load ( 'other' );
}
2017-10-16 08:47:05 +02:00
// Get message template for $this->param["models"] into c_email_templates
2017-12-17 23:42:50 +01:00
$arraydefaultmessage = - 1 ;
2021-01-04 23:41:20 +01:00
if ( $this -> param [ 'models' ] != 'none' ) {
2019-12-03 11:17:29 +01:00
$model_id = 0 ;
2021-01-04 23:41:20 +01:00
if ( array_key_exists ( 'models_id' , $this -> param )) {
2019-12-03 11:17:29 +01:00
$model_id = $this -> param [ " models_id " ];
2017-10-16 08:47:05 +02:00
}
2023-04-25 21:30:00 +02:00
$arraydefaultmessage = $this -> getEMailTemplate ( $this -> db , $this -> param [ " models " ], $user , $outputlangs , $model_id , 1 , '' , ( $model_id > 0 ? - 1 : 1 )); // If $model_id is empty, preselect the first one
2017-12-17 23:42:50 +01:00
}
2017-10-16 08:47:05 +02:00
// Define list of attached files
2019-12-03 11:17:29 +01:00
$listofpaths = array ();
$listofnames = array ();
$listofmimes = array ();
$keytoavoidconflict = empty ( $this -> trackid ) ? '' : '-' . $this -> trackid ; // this->trackid must be defined
2017-10-16 08:47:05 +02:00
2021-03-20 14:10:56 +01:00
if ( GETPOST ( 'mode' , 'alpha' ) == 'init' || ( GETPOST ( 'modelselected' ) && GETPOST ( 'modelmailselected' , 'alpha' ) && GETPOST ( 'modelmailselected' , 'alpha' ) != '-1' )) {
2022-08-10 14:38:38 +02:00
if ( ! empty ( $arraydefaultmessage -> joinfiles ) && ! empty ( $this -> param [ 'fileinit' ]) && is_array ( $this -> param [ 'fileinit' ])) {
2021-01-04 23:41:20 +01:00
foreach ( $this -> param [ 'fileinit' ] as $file ) {
2023-06-13 16:01:52 +02:00
if ( ! empty ( $file )) {
$this -> add_attached_files ( $file , basename ( $file ), dol_mimetype ( $file ));
}
2017-10-16 08:47:05 +02:00
}
}
}
2021-01-12 23:46:29 +01:00
if ( ! empty ( $_SESSION [ " listofpaths " . $keytoavoidconflict ])) {
2021-01-04 23:41:20 +01:00
$listofpaths = explode ( ';' , $_SESSION [ " listofpaths " . $keytoavoidconflict ]);
}
2021-01-12 23:46:29 +01:00
if ( ! empty ( $_SESSION [ " listofnames " . $keytoavoidconflict ])) {
2021-01-04 23:41:20 +01:00
$listofnames = explode ( ';' , $_SESSION [ " listofnames " . $keytoavoidconflict ]);
}
2021-01-12 23:46:29 +01:00
if ( ! empty ( $_SESSION [ " listofmimes " . $keytoavoidconflict ])) {
2021-01-04 23:41:20 +01:00
$listofmimes = explode ( ';' , $_SESSION [ " listofmimes " . $keytoavoidconflict ]);
}
2017-10-16 08:47:05 +02:00
2019-12-03 11:17:29 +01:00
$out .= " \n " . '<!-- Begin form mail type=' . $this -> param [ " models " ] . ' --><div id="mailformdiv"></div>' . " \n " ;
2021-01-04 23:41:20 +01:00
if ( $this -> withform == 1 ) {
2019-12-03 11:17:29 +01:00
$out .= '<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="' . $this -> param [ " returnurl " ] . '#formmail">' . " \n " ;
2017-11-25 17:21:53 +01:00
2019-12-03 11:17:29 +01:00
$out .= '<a id="formmail" name="formmail"></a>' ;
2021-03-02 12:33:55 +01:00
$out .= '<input style="display:none" type="submit" id="sendmailhidden" name="sendmail">' ;
2019-12-03 11:17:29 +01:00
$out .= '<input type="hidden" name="token" value="' . newToken () . '" />' ;
$out .= '<input type="hidden" name="trackid" value="' . $this -> trackid . '" />' ;
2022-08-02 20:22:10 +02:00
$out .= '<input type="hidden" name="inreplyto" value="' . $this -> inreplyto . '" />' ;
2017-10-16 08:47:05 +02:00
}
2021-01-04 23:41:20 +01:00
if ( ! empty ( $this -> withfrom )) {
if ( ! empty ( $this -> withfromreadonly )) {
2019-12-03 11:17:29 +01:00
$out .= '<input type="hidden" id="fromname" name="fromname" value="' . $this -> fromname . '" />' ;
$out .= '<input type="hidden" id="frommail" name="frommail" value="' . $this -> frommail . '" />' ;
2017-10-16 08:47:05 +02:00
}
}
2021-01-12 23:46:29 +01:00
foreach ( $this -> param as $key => $value ) {
2020-08-21 13:00:12 +02:00
if ( is_array ( $value )) {
2022-08-02 20:22:10 +02:00
$out .= " <!-- param key= " . $key . " is array, we do not output input field for it --> \n " ;
2020-08-21 13:00:12 +02:00
} else {
$out .= '<input type="hidden" id="' . $key . '" name="' . $key . '" value="' . $value . '" />' . " \n " ;
}
2017-10-16 08:47:05 +02:00
}
2019-12-03 11:17:29 +01:00
$modelmail_array = array ();
2021-01-04 23:41:20 +01:00
if ( $this -> param [ 'models' ] != 'none' ) {
2017-10-16 08:47:05 +02:00
$result = $this -> fetchAllEMailTemplate ( $this -> param [ " models " ], $user , $outputlangs );
2021-01-04 23:41:20 +01:00
if ( $result < 0 ) {
2017-10-16 08:47:05 +02:00
setEventMessages ( $this -> error , $this -> errors , 'errors' );
}
2022-01-21 13:44:40 +01:00
2021-01-04 23:41:20 +01:00
foreach ( $this -> lines_model as $line ) {
2020-10-17 12:59:22 +02:00
$reg = array ();
if ( preg_match ( '/\((.*)\)/' , $line -> label , $reg )) {
$labeltouse = $langs -> trans ( $reg [ 1 ]); // langs->trans when label is __(xxx)__
2020-05-21 15:05:19 +02:00
} else {
2020-10-17 12:59:22 +02:00
$labeltouse = $line -> label ;
2017-10-16 08:47:05 +02:00
}
2020-10-17 12:59:22 +02:00
// We escape the $labeltouse to store it into $modelmail_array.
$modelmail_array [ $line -> id ] = dol_escape_htmltag ( $labeltouse );
2021-01-12 23:46:29 +01:00
if ( $line -> lang ) {
$modelmail_array [ $line -> id ] .= ' ' . picto_from_langcode ( $line -> lang );
}
if ( $line -> private ) {
$modelmail_array [ $line -> id ] .= ' - <span class="opacitymedium">' . dol_escape_htmltag ( $langs -> trans ( " Private " )) . '</span>' ;
}
2017-10-16 08:47:05 +02:00
}
}
// Zone to select email template
2021-01-04 23:41:20 +01:00
if ( count ( $modelmail_array ) > 0 ) {
2021-02-26 10:31:02 +01:00
$model_mail_selected_id = GETPOSTISSET ( 'modelmailselected' ) ? GETPOST ( 'modelmailselected' , 'int' ) : ( $arraydefaultmessage -> id > 0 ? $arraydefaultmessage -> id : 0 );
2021-02-02 10:34:33 +01:00
2017-10-16 08:47:05 +02:00
// If list of template is filled
2019-12-03 11:17:29 +01:00
$out .= '<div class="center" style="padding: 0px 0 12px 0">' . " \n " ;
2021-02-03 20:46:22 +01:00
2020-10-17 12:59:22 +02:00
$out .= '<span class="opacitymedium">' . $langs -> trans ( 'SelectMailModel' ) . ':</span> ' ;
2021-02-03 21:02:32 +01:00
2021-02-03 20:46:22 +01:00
$out .= $this -> selectarray ( 'modelmailselected' , $modelmail_array , $model_mail_selected_id , 1 , 0 , 0 , '' , 0 , 0 , 0 , '' , 'minwidth100' , 1 , '' , 0 , 1 );
2021-01-12 23:46:29 +01:00
if ( $user -> admin ) {
$out .= info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFrom " , $langs -> transnoentitiesnoconv ( 'Setup' ) . ' - ' . $langs -> transnoentitiesnoconv ( 'EMails' )), 1 );
}
2021-02-03 21:02:32 +01:00
2019-12-03 11:17:29 +01:00
$out .= ' ' ;
2022-09-10 09:19:01 +02:00
$out .= '<input type="submit" class="button reposition smallpaddingimp" value="' . $langs -> trans ( 'Apply' ) . '" name="modelselected" id="modelselected">' ;
2019-12-03 11:17:29 +01:00
$out .= ' ' ;
$out .= '</div>' ;
} elseif ( ! empty ( $this -> param [ 'models' ]) && in_array ( $this -> param [ 'models' ], array (
'propal_send' , 'order_send' , 'facture_send' ,
'shipping_send' , 'fichinter_send' , 'supplier_proposal_send' , 'order_supplier_send' ,
2020-08-23 22:11:16 +02:00
'invoice_supplier_send' , 'thirdparty' , 'contract' , 'user' , 'recruitmentcandidature_send' , 'all'
2021-01-04 23:41:20 +01:00
))) {
2017-10-16 08:47:05 +02:00
// If list of template is empty
2019-12-03 11:17:29 +01:00
$out .= '<div class="center" style="padding: 0px 0 12px 0">' . " \n " ;
2022-10-01 13:26:11 +02:00
$out .= '<span class="opacitymedium">' . $langs -> trans ( 'SelectMailModel' ) . ':</span> ' ;
$out .= '<select name="modelmailselected" disabled="disabled"><option value="none">' . $langs -> trans ( " NoTemplateDefined " ) . '</option></select>' ; // Do not put 'disabled' on 'option' tag, it is already on 'select' and it makes chrome crazy.
2021-01-12 23:46:29 +01:00
if ( $user -> admin ) {
$out .= info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFrom " , $langs -> transnoentitiesnoconv ( 'Setup' ) . ' - ' . $langs -> transnoentitiesnoconv ( 'EMails' )), 1 );
}
2019-12-03 11:17:29 +01:00
$out .= ' ' ;
2021-08-24 17:04:17 +02:00
$out .= '<input type="submit" class="button" value="' . $langs -> trans ( 'Apply' ) . '" name="modelselected" disabled="disabled" id="modelselected">' ;
2019-12-03 11:17:29 +01:00
$out .= ' ' ;
$out .= '</div>' ;
2020-08-23 22:11:16 +02:00
} else {
$out .= '<!-- No template available for $this->param["models"] = ' . $this -> param [ 'models' ] . ' -->' ;
2017-10-16 08:47:05 +02:00
}
2022-01-21 13:44:40 +01:00
$out .= '<table class="tableforemailform boxtablenotop centpercent">' . " \n " ;
2017-10-16 08:47:05 +02:00
2018-04-06 16:16:08 +02:00
// Substitution array/string
2019-12-03 11:17:29 +01:00
$helpforsubstitution = '' ;
2021-01-12 23:46:29 +01:00
if ( is_array ( $this -> substit ) && count ( $this -> substit )) {
2023-02-23 13:50:25 +01:00
$helpforsubstitution .= $langs -> trans ( 'AvailableVariables' ) . ' :<br><br><span class="small">' . " \n " ;
2021-01-12 23:46:29 +01:00
}
2021-01-04 23:41:20 +01:00
foreach ( $this -> substit as $key => $val ) {
2023-05-11 18:42:56 +02:00
// Do not show deprecated variables into the tooltip help of substitution variables
if ( in_array ( $key , array ( '__NEWREF__' , '__REFCLIENT__' , '__REFSUPPLIER__' , '__SUPPLIER_ORDER_DATE_DELIVERY__' , '__SUPPLIER_ORDER_DELAY_DELIVERY__' ))) {
continue ;
}
2020-09-06 19:19:55 +02:00
$helpforsubstitution .= $key . ' -> ' . $langs -> trans ( dol_string_nohtmltag ( dolGetFirstLineOfText ( $val ))) . '<br>' ;
2018-04-06 16:16:08 +02:00
}
2023-02-23 13:50:25 +01:00
if ( is_array ( $this -> substit ) && count ( $this -> substit )) {
$helpforsubstitution .= '</span>' ;
}
2021-01-12 23:46:29 +01:00
if ( ! empty ( $this -> withsubstit )) { // Unset or set ->withsubstit=0 to disable this.
2019-12-03 11:17:29 +01:00
$out .= '<tr><td colspan="2" class="right">' ;
2021-01-12 23:46:29 +01:00
if ( is_numeric ( $this -> withsubstit )) {
$out .= $form -> textwithpicto ( $langs -> trans ( " EMailTestSubstitutionReplacedByGenericValues " ), $helpforsubstitution , 1 , 'help' , '' , 0 , 2 , 'substittooltip' ); // Old usage
} else {
$out .= $form -> textwithpicto ( $langs -> trans ( 'AvailableVariables' ), $helpforsubstitution , 1 , 'help' , '' , 0 , 2 , 'substittooltip' ); // New usage
}
2019-12-03 11:17:29 +01:00
$out .= " </td></tr> \n " ;
2017-10-16 08:47:05 +02:00
}
// From
2021-01-04 23:41:20 +01:00
if ( ! empty ( $this -> withfrom )) {
if ( ! empty ( $this -> withfromreadonly )) {
2019-12-03 11:17:29 +01:00
$out .= '<tr><td class="fieldrequired minwidth200">' . $langs -> trans ( " MailFrom " ) . '</td><td>' ;
2017-10-16 08:47:05 +02:00
2017-11-25 19:16:15 +01:00
// $this->fromtype is the default value to use to select sender
2019-12-03 11:17:29 +01:00
if ( ! ( $this -> fromtype === 'user' && $this -> fromid > 0 )
&& ! ( $this -> fromtype === 'company' )
&& ! ( $this -> fromtype === 'robot' )
&& ! preg_match ( '/user_aliases/' , $this -> fromtype )
&& ! preg_match ( '/global_aliases/' , $this -> fromtype )
&& ! preg_match ( '/senderprofile/' , $this -> fromtype )
2021-01-04 23:41:20 +01:00
) {
2017-10-16 08:47:05 +02:00
// Use this->fromname and this->frommail or error if not defined
2019-12-03 11:17:29 +01:00
$out .= $this -> fromname ;
2021-01-04 23:41:20 +01:00
if ( $this -> frommail ) {
2019-12-03 11:17:29 +01:00
$out .= ' <' . $this -> frommail . '>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-01-04 23:41:20 +01:00
if ( $this -> fromtype ) {
2017-10-16 08:47:05 +02:00
$langs -> load ( 'errors' );
2019-12-03 11:17:29 +01:00
$out .= '<span class="warning"> <' . $langs -> trans ( 'ErrorNoMailDefinedForThisUser' ) . '> </span>' ;
2017-10-16 08:47:05 +02:00
}
}
} else {
$liste = array ();
// Add user email
2021-01-04 23:41:20 +01:00
if ( empty ( $user -> email )) {
2017-10-16 08:47:05 +02:00
$langs -> load ( 'errors' );
2023-04-25 18:57:17 +02:00
$s = $user -> getFullName ( $langs ) . ' <' . $langs -> trans ( 'ErrorNoMailDefinedForThisUser' ) . '>' ;
2020-05-21 15:05:19 +02:00
} else {
2023-04-25 18:57:17 +02:00
$s = $user -> getFullName ( $langs ) . ' <' . $user -> email . '>' ;
2017-10-16 08:47:05 +02:00
}
2023-04-25 18:57:17 +02:00
$liste [ 'user' ] = array ( 'label' => $s , 'data-html' => $s );
2017-10-16 08:47:05 +02:00
// Add also company main email
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MAIN_INFO_SOCIETE_MAIL' )) {
2023-12-04 12:04:36 +01:00
$s = ( ! getDolGlobalString ( 'MAIN_INFO_SOCIETE_NOM' ) ? $conf -> global -> MAIN_INFO_SOCIETE_EMAIL : $conf -> global -> MAIN_INFO_SOCIETE_NOM ) . ' <' . getDolGlobalString ( 'MAIN_INFO_SOCIETE_MAIL' ) . '>' ;
2023-04-25 18:57:17 +02:00
$liste [ 'company' ] = array ( 'label' => $s , 'data-html' => $s );
2022-06-09 15:13:29 +02:00
}
2017-10-16 08:47:05 +02:00
// Add also email aliases if there is some
2021-06-10 22:26:58 +02:00
$listaliases = array (
'user_aliases' => ( empty ( $user -> email_aliases ) ? '' : $user -> email_aliases ),
2021-06-10 22:28:19 +02:00
'global_aliases' => getDolGlobalString ( 'MAIN_INFO_SOCIETE_MAIL_ALIASES' ),
2021-06-10 22:26:58 +02:00
);
2017-10-16 08:47:05 +02:00
2023-08-02 12:05:44 +02:00
if ( ! empty ( $arraydefaultmessage -> email_from )) {
$templatemailfrom = ' <' . $arraydefaultmessage -> email_from . '>' ;
$liste [ 'from_template_' . GETPOST ( 'modelmailselected' )] = array ( 'label' => $templatemailfrom , 'data-html' => $templatemailfrom );
}
2017-11-25 19:23:27 +01:00
// Also add robot email
2021-01-04 23:41:20 +01:00
if ( ! empty ( $this -> fromalsorobot )) {
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MAIN_MAIL_EMAIL_FROM' ) && getDolGlobalString ( 'MAIN_MAIL_EMAIL_FROM' ) != getDolGlobalString ( 'MAIN_INFO_SOCIETE_MAIL' )) {
2023-04-25 18:57:17 +02:00
$s = $conf -> global -> MAIN_MAIL_EMAIL_FROM ;
2021-01-04 23:41:20 +01:00
if ( $this -> frommail ) {
2023-10-15 15:32:35 +02:00
$s .= ' <' . getDolGlobalString ( 'MAIN_MAIL_EMAIL_FROM' ) . '>' ;
2017-11-25 19:23:27 +01:00
}
2023-04-25 18:57:17 +02:00
array ( 'label' => $s , 'data-html' => $s );
2017-11-25 19:23:27 +01:00
}
}
2017-10-16 08:47:05 +02:00
// Add also email aliases from the c_email_senderprofile table
2022-01-27 12:52:13 +01:00
$sql = " SELECT rowid, label, email FROM " . $this -> db -> prefix () . " c_email_senderprofile " ;
$sql .= " WHERE active = 1 AND (private = 0 OR private = " . (( int ) $user -> id ) . " ) " ;
$sql .= " ORDER BY position " ;
2017-10-16 08:47:05 +02:00
$resql = $this -> db -> query ( $sql );
2021-01-04 23:41:20 +01:00
if ( $resql ) {
2017-10-16 08:47:05 +02:00
$num = $this -> db -> num_rows ( $resql );
2019-12-03 11:17:29 +01:00
$i = 0 ;
2021-01-04 23:41:20 +01:00
while ( $i < $num ) {
2017-10-16 08:47:05 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2021-01-04 23:41:20 +01:00
if ( $obj ) {
2017-10-16 08:47:05 +02:00
$listaliases [ 'senderprofile_' . $obj -> rowid ] = $obj -> label . ' <' . $obj -> email . '>' ;
}
$i ++ ;
}
2021-01-04 23:41:20 +01:00
} else {
dol_print_error ( $this -> db );
}
2017-10-16 08:47:05 +02:00
2021-01-04 23:41:20 +01:00
foreach ( $listaliases as $typealias => $listalias ) {
2019-12-03 11:17:29 +01:00
$posalias = 0 ;
$listaliasarray = explode ( ',' , $listalias );
2021-01-04 23:41:20 +01:00
foreach ( $listaliasarray as $listaliasval ) {
2017-10-16 08:47:05 +02:00
$posalias ++ ;
2019-12-03 11:17:29 +01:00
$listaliasval = trim ( $listaliasval );
2021-01-04 23:41:20 +01:00
if ( $listaliasval ) {
2019-12-03 11:17:29 +01:00
$listaliasval = preg_replace ( '/</' , '<' , $listaliasval );
$listaliasval = preg_replace ( '/>/' , '>' , $listaliasval );
2021-01-12 23:46:29 +01:00
if ( ! preg_match ( '/</' , $listaliasval )) {
$listaliasval = '<' . $listaliasval . '>' ;
}
2023-04-25 18:57:17 +02:00
$liste [ $typealias . '_' . $posalias ] = array ( 'label' => $listaliasval , 'data-html' => $listaliasval );
2017-10-16 08:47:05 +02:00
}
}
}
2017-12-10 02:01:36 +01:00
2023-08-16 17:55:44 +02:00
// Using ajaxcombo here make the '<email>' no more visible on list because <emailofuser> is not a valid html tag,
// so we transform before each record into $liste to be printable with ajaxcombo by replacing <> into ()
// $liste['senderprofile_0_0'] = array('label'=>'rrr', 'data-html'=>'rrr <aaaa>');
foreach ( $liste as $key => $val ) {
if ( ! empty ( $liste [ $key ][ 'data-html' ])) {
$liste [ $key ][ 'data-html' ] = str_replace ( array ( '<' , '<' , '>' , '>' ), array ( '__LTCHAR__' , '__LTCHAR__' , '__GTCHAR__' , '__GTCHAR__' ), $liste [ $key ][ 'data-html' ]);
$liste [ $key ][ 'data-html' ] = str_replace ( array ( '__LTCHAR__' , '__GTCHAR__' ), array ( '<span class="opacitymedium">(' , ')</span>' ), $liste [ $key ][ 'data-html' ]);
}
}
$out .= ' ' . $form -> selectarray ( 'fromtype' , $liste , empty ( $arraydefaultmessage -> email_from ) ? $this -> fromtype : 'from_template_' . GETPOST ( 'modelmailselected' ), 0 , 0 , 0 , '' , 0 , 0 , 0 , '' , 'fromforsendingprofile maxwidth200onsmartphone' , 1 , '' , $disablebademails );
2017-10-16 08:47:05 +02:00
}
2019-12-03 11:17:29 +01:00
$out .= " </td></tr> \n " ;
2020-05-21 15:05:19 +02:00
} else {
2019-12-03 11:17:29 +01:00
$out .= '<tr><td class="fieldrequired width200">' . $langs -> trans ( " MailFrom " ) . " </td><td> " ;
$out .= $langs -> trans ( " Name " ) . ':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="' . $this -> fromname . '" />' ;
$out .= ' ' ;
$out .= $langs -> trans ( " EMail " ) . ':<<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="' . $this -> frommail . '" />>' ;
$out .= " </td></tr> \n " ;
2017-10-16 08:47:05 +02:00
}
}
// To
2021-01-12 23:46:29 +01:00
if ( ! empty ( $this -> withto ) || is_array ( $this -> withto )) {
2021-03-15 20:17:01 +01:00
$out .= $this -> getHtmlForTo ();
2017-10-16 08:47:05 +02:00
}
2018-03-21 11:48:30 +01:00
// To User
2023-11-27 11:24:19 +01:00
if ( ! empty ( $this -> withtouser ) && is_array ( $this -> withtouser ) && getDolGlobalString ( 'MAIN_MAIL_ENABLED_USER_DEST_SELECT' )) {
2019-12-03 11:17:29 +01:00
$out .= '<tr><td>' ;
$out .= $langs -> trans ( " MailToUsers " );
$out .= '</td><td>' ;
2018-03-21 11:48:30 +01:00
// multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
$tmparray = $this -> withtouser ;
2021-01-04 23:41:20 +01:00
foreach ( $tmparray as $key => $val ) {
2019-12-03 11:17:29 +01:00
$tmparray [ $key ] = dol_htmlentities ( $tmparray [ $key ], null , 'UTF-8' , true );
2018-03-21 11:48:30 +01:00
}
2020-09-29 21:28:07 +02:00
$withtoselected = GETPOST ( " receiveruser " , 'array' ); // Array of selected value
2021-01-04 23:41:20 +01:00
if ( empty ( $withtoselected ) && count ( $tmparray ) == 1 && GETPOST ( 'action' , 'aZ09' ) == 'presend' ) {
2018-03-21 11:48:30 +01:00
$withtoselected = array_keys ( $tmparray );
}
2019-12-03 11:17:29 +01:00
$out .= $form -> multiselectarray ( " receiveruser " , $tmparray , $withtoselected , null , null , 'inline-block minwidth500' , null , " " );
$out .= " </td></tr> \n " ;
2018-03-21 11:48:30 +01:00
}
2023-06-13 19:35:18 +02:00
// With option for one email per recipient
2021-01-04 23:41:20 +01:00
if ( ! empty ( $this -> withoptiononeemailperrecipient )) {
2022-01-21 13:44:40 +01:00
if ( abs ( $this -> withoptiononeemailperrecipient ) == 1 ) {
$out .= '<tr><td class="minwidth200">' ;
$out .= $langs -> trans ( " GroupEmails " );
$out .= '</td><td>' ;
$out .= ' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"' . ( $this -> withoptiononeemailperrecipient > 0 ? ' checked="checked"' : '' ) . '> ' ;
2023-06-13 19:35:18 +02:00
$out .= '<label for="oneemailperrecipient">' ;
$out .= $form -> textwithpicto ( $langs -> trans ( " OneEmailPerRecipient " ), $langs -> trans ( " WarningIfYouCheckOneRecipientPerEmail " ), 1 , 'help' );
$out .= '</label>' ;
//$out .= '<span class="hideonsmartphone opacitymedium">';
//$out .= ' - ';
//$out .= $langs->trans("WarningIfYouCheckOneRecipientPerEmail");
//$out .= '</span>';
if ( getDolGlobalString ( 'MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL' )) {
if ( ! empty ( $this -> withto ) && ! is_array ( $this -> withto )) {
$out .= ' ' . $langs -> trans ( " or " ) . ' <input type="email" name="emailto" value="">' ;
}
}
2022-01-21 13:44:40 +01:00
$out .= '</td></tr>' ;
} else {
$out .= '<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>' ;
}
2017-10-16 08:47:05 +02:00
}
// CC
2021-01-04 23:41:20 +01:00
if ( ! empty ( $this -> withtocc ) || is_array ( $this -> withtocc )) {
2021-03-15 20:17:01 +01:00
$out .= $this -> getHtmlForCc ();
2017-10-16 08:47:05 +02:00
}
2018-03-21 11:48:30 +01:00
// To User cc
2023-11-27 11:24:19 +01:00
if ( ! empty ( $this -> withtoccuser ) && is_array ( $this -> withtoccuser ) && getDolGlobalString ( 'MAIN_MAIL_ENABLED_USER_DEST_SELECT' )) {
2019-12-03 11:17:29 +01:00
$out .= '<tr><td>' ;
$out .= $langs -> trans ( " MailToCCUsers " );
$out .= '</td><td>' ;
2018-03-21 11:48:30 +01:00
// multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
$tmparray = $this -> withtoccuser ;
2021-01-04 23:41:20 +01:00
foreach ( $tmparray as $key => $val ) {
2019-12-03 11:17:29 +01:00
$tmparray [ $key ] = dol_htmlentities ( $tmparray [ $key ], null , 'UTF-8' , true );
2018-03-21 11:48:30 +01:00
}
2020-09-29 21:28:07 +02:00
$withtoselected = GETPOST ( " receiverccuser " , 'array' ); // Array of selected value
2021-01-04 23:41:20 +01:00
if ( empty ( $withtoselected ) && count ( $tmparray ) == 1 && GETPOST ( 'action' , 'aZ09' ) == 'presend' ) {
2018-03-21 11:48:30 +01:00
$withtoselected = array_keys ( $tmparray );
}
2019-12-03 11:17:29 +01:00
$out .= $form -> multiselectarray ( " receiverccuser " , $tmparray , $withtoselected , null , null , 'inline-block minwidth500' , null , " " );
$out .= " </td></tr> \n " ;
2018-03-21 11:48:30 +01:00
}
2017-10-16 08:47:05 +02:00
// CCC
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withtoccc ) || is_array ( $this -> withtoccc )) {
2018-11-19 21:19:39 +01:00
$out .= $this -> getHtmlForWithCcc ();
2017-10-16 08:47:05 +02:00
}
// Replyto
2021-01-04 23:41:20 +01:00
if ( ! empty ( $this -> withreplyto )) {
if ( $this -> withreplytoreadonly ) {
2019-12-03 11:17:29 +01:00
$out .= '<input type="hidden" id="replyname" name="replyname" value="' . $this -> replytoname . '" />' ;
$out .= '<input type="hidden" id="replymail" name="replymail" value="' . $this -> replytomail . '" />' ;
$out .= " <tr><td> " . $langs -> trans ( " MailReply " ) . " </td><td> " . $this -> replytoname . ( $this -> replytomail ? ( " < " . $this -> replytomail . " > " ) : " " );
$out .= " </td></tr> \n " ;
2017-10-16 08:47:05 +02:00
}
}
// Errorsto
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> witherrorsto )) {
2018-11-19 21:19:39 +01:00
$out .= $this -> getHtmlForWithErrorsTo ();
2017-10-16 08:47:05 +02:00
}
// Ask delivery receipt
2022-10-01 13:26:11 +02:00
if ( ! empty ( $this -> withdeliveryreceipt ) && getDolGlobalInt ( 'MAIN_EMAIL_SUPPORT_ACK' )) {
2018-11-19 21:19:39 +01:00
$out .= $this -> getHtmlForDeliveryReceipt ();
2017-10-16 08:47:05 +02:00
}
// Topic
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withtopic )) {
2018-12-27 05:18:16 +01:00
$out .= $this -> getHtmlForTopic ( $arraydefaultmessage , $helpforsubstitution );
2017-10-16 08:47:05 +02:00
}
// Attached files
2021-01-04 23:41:20 +01:00
if ( ! empty ( $this -> withfile )) {
2019-12-03 11:17:29 +01:00
$out .= '<tr>' ;
$out .= '<td>' . $langs -> trans ( " MailFile " ) . '</td>' ;
2017-10-16 08:47:05 +02:00
2019-12-03 11:17:29 +01:00
$out .= '<td>' ;
2018-10-29 00:55:55 +01:00
2021-03-15 18:22:50 +01:00
if ( $this -> withmaindocfile ) {
2021-01-12 23:46:29 +01:00
// withmaindocfile is set to 1 or -1 to show the checkbox (-1 = checked or 1 = not checked)
2021-01-04 23:41:20 +01:00
if ( GETPOSTISSET ( 'sendmail' )) {
2018-10-29 02:27:51 +01:00
$this -> withmaindocfile = ( GETPOST ( 'addmaindocfile' , 'alpha' ) ? - 1 : 1 );
2021-01-04 23:41:20 +01:00
} elseif ( is_object ( $arraydefaultmessage ) && $arraydefaultmessage -> id > 0 ) {
// If a template was selected, we use setup of template to define if join file checkbox is selected or not.
2018-10-29 02:27:51 +01:00
$this -> withmaindocfile = ( $arraydefaultmessage -> joinfiles ? - 1 : 1 );
}
2018-10-29 00:55:55 +01:00
}
2021-01-04 23:41:20 +01:00
if ( ! empty ( $this -> withmaindocfile )) {
if ( $this -> withmaindocfile == 1 ) {
2021-10-27 03:06:50 +02:00
$out .= '<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />' ;
} elseif ( $this -> withmaindocfile == - 1 ) {
$out .= '<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />' ;
2017-10-16 08:47:05 +02:00
}
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND' )) {
2022-05-02 11:35:12 +02:00
$out .= ' <label for="addmaindocfile">' . $langs -> trans ( " JoinMainDocOrLastGenerated " ) . '.</label><br>' ;
} else {
$out .= ' <label for="addmaindocfile">' . $langs -> trans ( " JoinMainDoc " ) . '.</label><br>' ;
}
2017-09-16 18:24:58 +02:00
}
2014-09-17 01:12:59 +02:00
2021-01-04 23:41:20 +01:00
if ( is_numeric ( $this -> withfile )) {
2017-11-25 17:21:53 +01:00
// TODO Trick to have param removedfile containing nb of file to delete. But this does not works without javascript
2019-12-03 11:17:29 +01:00
$out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">' . " \n " ;
2023-02-18 15:10:05 +01:00
$out .= '<script nonce="' . getNonce () . '" type="text/javascript">' ;
2019-12-03 11:17:29 +01:00
$out .= 'jQuery(document).ready(function () {' ;
$out .= ' jQuery(".removedfile").click(function() {' ;
$out .= ' jQuery(".removedfilehidden").val(jQuery(this).val());' ;
$out .= ' });' ;
$out .= '})' ;
$out .= '</script>' . " \n " ;
2021-01-04 23:41:20 +01:00
if ( count ( $listofpaths )) {
foreach ( $listofpaths as $key => $val ) {
2021-01-16 13:41:27 +01:00
$relativepathtofile = substr ( $val , ( strlen ( DOL_DATA_ROOT ) - strlen ( $val )));
2021-10-11 20:04:45 +02:00
2021-01-16 13:41:27 +01:00
if ( $conf -> entity > 1 ) {
2023-07-12 16:30:34 +02:00
$relativepathtofile = str_replace ( '/' . $conf -> entity . '/' , '/' , $relativepathtofile );
2021-01-16 13:41:27 +01:00
}
// Try to extract data from full path
$formfile_params = array ();
preg_match ( '#^(/)(\w+)(/)(.+)$#' , $relativepathtofile , $formfile_params );
2019-12-03 11:17:29 +01:00
$out .= '<div id="attachfile_' . $key . '">' ;
2020-09-07 10:18:17 +02:00
// Preview of attachment
2019-12-03 11:17:29 +01:00
$out .= img_mime ( $listofnames [ $key ]) . ' ' . $listofnames [ $key ];
2021-10-11 20:04:45 +02:00
2020-09-07 10:18:17 +02:00
$out .= $formfile -> showPreview ( array (), $formfile_params [ 2 ], $formfile_params [ 4 ]);
2021-01-04 23:41:20 +01:00
if ( ! $this -> withfilereadonly ) {
2019-12-03 11:17:29 +01:00
$out .= ' <input type="image" style="border: 0px;" src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/delete.png" value="' . ( $key + 1 ) . '" class="removedfile" id="removedfile_' . $key . '" name="removedfile_' . $key . '" />' ;
2017-10-16 08:47:05 +02:00
//$out.= ' <a href="'.$_SERVER["PHP_SELF"].'?removedfile='.($key+1).' id="removedfile_'.$key.'">'.img_delete($langs->trans("Delete").'</a>';
}
2019-12-03 11:17:29 +01:00
$out .= '<br></div>' ;
2017-10-16 08:47:05 +02:00
}
2021-01-12 23:46:29 +01:00
} elseif ( empty ( $this -> withmaindocfile )) {
2022-09-19 21:02:06 +02:00
//$out .= '<span class="opacitymedium">'.$langs->trans("NoAttachedFiles").'</span><br>';
2017-10-16 08:47:05 +02:00
}
2021-01-12 23:46:29 +01:00
if ( $this -> withfile == 2 ) {
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
}
2021-01-12 23:46:29 +01:00
// Can add other files
2023-11-27 11:24:19 +01:00
if ( ! getDolGlobalString ( 'FROM_MAIL_DONT_USE_INPUT_FILE_MULTIPLE' )) {
2021-01-12 23:46:29 +01:00
$out .= '<input type="file" class="flat" id="addedfile" name="addedfile[]" value="' . $langs -> trans ( " Upload " ) . '" multiple />' ;
} else {
$out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="' . $langs -> trans ( " Upload " ) . '" />' ;
}
2019-12-03 11:17:29 +01:00
$out .= ' ' ;
2022-09-19 21:02:06 +02:00
$out .= '<input type="submit" class="button smallpaddingimp" id="' . $addfileaction . '" name="' . $addfileaction . '" value="' . $langs -> trans ( " MailingAddFile " ) . '" />' ;
2017-10-16 08:47:05 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2019-12-03 11:17:29 +01:00
$out .= $this -> withfile ;
2017-10-16 08:47:05 +02:00
}
2019-12-03 11:17:29 +01:00
$out .= " </td></tr> \n " ;
2017-10-16 08:47:05 +02:00
}
// Message
2021-01-04 23:41:20 +01:00
if ( ! empty ( $this -> withbody )) {
2020-09-18 01:29:17 +02:00
$defaultmessage = GETPOST ( 'message' , 'restricthtml' );
2021-01-04 23:41:20 +01:00
if ( ! GETPOST ( 'modelselected' , 'alpha' ) || GETPOST ( 'modelmailselected' ) != '-1' ) {
2017-12-17 23:42:50 +01:00
if ( $arraydefaultmessage && $arraydefaultmessage -> content ) {
2018-03-11 15:09:25 +01:00
$defaultmessage = $arraydefaultmessage -> content ;
2019-12-03 11:17:29 +01:00
} elseif ( ! is_numeric ( $this -> withbody )) {
2017-12-17 23:42:50 +01:00
$defaultmessage = $this -> withbody ;
}
2017-10-16 08:47:05 +02:00
}
2018-03-21 20:06:22 +01:00
// Complete substitution array with the url to make online payment
2021-03-01 20:37:16 +01:00
$paymenturl = '' ;
$validpaymentmethod = array ();
2021-01-04 23:41:20 +01:00
if ( empty ( $this -> substit [ '__REF__' ])) {
2019-12-03 11:17:29 +01:00
$paymenturl = '' ;
2020-05-21 15:05:19 +02:00
} else {
2017-12-17 22:03:42 +01:00
// Set the online payment url link into __ONLINE_PAYMENT_URL__ key
require_once DOL_DOCUMENT_ROOT . '/core/lib/payments.lib.php' ;
2019-12-03 11:17:29 +01:00
$langs -> loadLangs ( array ( 'paypal' , 'other' ));
$typeforonlinepayment = 'free' ;
2021-01-04 23:41:20 +01:00
if ( $this -> param [ " models " ] == 'order' || $this -> param [ " models " ] == 'order_send' ) {
$typeforonlinepayment = 'order' ; // TODO use detection on something else than template
}
if ( $this -> param [ " models " ] == 'invoice' || $this -> param [ " models " ] == 'facture_send' ) {
$typeforonlinepayment = 'invoice' ; // TODO use detection on something else than template
}
if ( $this -> param [ " models " ] == 'member' ) {
$typeforonlinepayment = 'member' ; // TODO use detection on something else than template
}
2019-12-03 11:17:29 +01:00
$url = getOnlinePaymentUrl ( 0 , $typeforonlinepayment , $this -> substit [ '__REF__' ]);
$paymenturl = $url ;
2018-06-27 11:34:40 +02:00
2018-07-16 11:25:21 +02:00
$validpaymentmethod = getValidOnlinePaymentMethods ( '' );
2018-06-27 11:34:40 +02:00
}
2018-06-27 12:11:49 +02:00
2021-01-04 23:41:20 +01:00
if ( count ( $validpaymentmethod ) > 0 && $paymenturl ) {
2018-09-12 12:55:10 +02:00
$langs -> load ( 'other' );
2019-12-03 11:17:29 +01:00
$this -> substit [ '__ONLINE_PAYMENT_TEXT_AND_URL__' ] = str_replace ( '\n' , " \n " , $langs -> transnoentities ( " PredefinedMailContentLink " , $paymenturl ));
$this -> substit [ '__ONLINE_PAYMENT_URL__' ] = $paymenturl ;
2020-05-21 15:05:19 +02:00
} else {
2019-12-03 11:17:29 +01:00
$this -> substit [ '__ONLINE_PAYMENT_TEXT_AND_URL__' ] = '' ;
$this -> substit [ '__ONLINE_PAYMENT_URL__' ] = '' ;
2017-12-17 22:03:42 +01:00
}
2013-01-24 17:29:11 +01:00
2020-08-23 22:11:16 +02:00
$this -> substit [ '__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__' ] = '' ;
2020-05-28 11:41:48 +02:00
// Add lines substitution key from each line
2017-10-16 08:47:05 +02:00
$lines = '' ;
2017-12-17 23:42:50 +01:00
$defaultlines = $arraydefaultmessage -> content_lines ;
2021-01-04 23:41:20 +01:00
if ( isset ( $defaultlines )) {
foreach ( $this -> substit_lines as $substit_line ) {
2019-01-27 11:55:16 +01:00
$lines .= make_substitutions ( $defaultlines , $substit_line ) . " \n " ;
2017-10-16 08:47:05 +02:00
}
}
2019-12-03 11:17:29 +01:00
$this -> substit [ '__LINES__' ] = $lines ;
2013-01-24 17:29:11 +01:00
2019-12-03 11:17:29 +01:00
$defaultmessage = str_replace ( '\n' , " \n " , $defaultmessage );
2014-02-19 15:33:04 +01:00
2020-05-28 11:41:48 +02:00
// Deal with format differences between message and some substitution variables (text / HTML)
$atleastonecomponentishtml = 0 ;
if ( strpos ( $defaultmessage , '__USER_SIGNATURE__' ) !== false && dol_textishtml ( $this -> substit [ '__USER_SIGNATURE__' ])) {
$atleastonecomponentishtml ++ ;
}
2022-09-10 15:55:36 +02:00
if ( strpos ( $defaultmessage , '__SENDEREMAIL_SIGNATURE__' ) !== false && dol_textishtml ( $this -> substit [ '__SENDEREMAIL_SIGNATURE__' ])) {
$atleastonecomponentishtml ++ ;
}
2020-05-28 11:41:48 +02:00
if ( strpos ( $defaultmessage , '__ONLINE_PAYMENT_TEXT_AND_URL__' ) !== false && dol_textishtml ( $this -> substit [ '__ONLINE_PAYMENT_TEXT_AND_URL__' ])) {
$atleastonecomponentishtml ++ ;
}
2020-08-23 22:11:16 +02:00
if ( strpos ( $defaultmessage , '__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__' ) !== false && dol_textishtml ( $this -> substit [ '__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__' ])) {
$atleastonecomponentishtml ++ ;
}
2020-05-28 11:41:48 +02:00
if ( dol_textishtml ( $defaultmessage )) {
$atleastonecomponentishtml ++ ;
}
if ( $atleastonecomponentishtml ) {
2020-09-08 21:27:28 +02:00
if ( ! dol_textishtml ( $this -> substit [ '__USER_SIGNATURE__' ])) {
2020-05-28 11:41:48 +02:00
$this -> substit [ '__USER_SIGNATURE__' ] = dol_nl2br ( $this -> substit [ '__USER_SIGNATURE__' ]);
}
2022-09-10 15:55:36 +02:00
if ( ! dol_textishtml ( $this -> substit [ '__SENDEREMAIL_SIGNATURE__' ])) {
$this -> substit [ '__SENDEREMAIL_SIGNATURE__' ] = dol_nl2br ( $this -> substit [ '__SENDEREMAIL_SIGNATURE__' ]);
}
2020-09-08 21:27:28 +02:00
if ( ! dol_textishtml ( $this -> substit [ '__ONLINE_PAYMENT_TEXT_AND_URL__' ])) {
2020-05-28 11:41:48 +02:00
$this -> substit [ '__ONLINE_PAYMENT_TEXT_AND_URL__' ] = dol_nl2br ( $this -> substit [ '__ONLINE_PAYMENT_TEXT_AND_URL__' ]);
}
2020-09-08 21:27:28 +02:00
if ( ! dol_textishtml ( $defaultmessage )) {
2020-05-28 11:41:48 +02:00
$defaultmessage = dol_nl2br ( $defaultmessage );
}
2013-08-02 10:24:09 +02:00
}
2014-02-19 15:33:04 +01:00
2021-03-25 16:59:47 +01:00
if ( GETPOSTISSET ( " message " ) && ! GETPOST ( 'modelselected' )) {
$defaultmessage = GETPOST ( " message " , " restricthtml " );
2021-01-04 23:41:20 +01:00
} else {
2019-12-03 11:17:29 +01:00
$defaultmessage = make_substitutions ( $defaultmessage , $this -> substit );
2014-04-30 15:17:39 +02:00
// Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty)
2019-12-03 11:17:29 +01:00
$defaultmessage = preg_replace ( " /^(<br>)+/ " , " " , $defaultmessage );
$defaultmessage = preg_replace ( " /^ \n +/ " , " " , $defaultmessage );
2014-04-30 15:17:39 +02:00
}
2020-05-28 11:41:48 +02:00
2019-12-03 11:17:29 +01:00
$out .= '<tr>' ;
2022-09-19 21:02:06 +02:00
$out .= '<td colspan="2">' ;
2019-12-03 11:17:29 +01:00
$out .= $form -> textwithpicto ( $langs -> trans ( 'MailText' ), $helpforsubstitution , 1 , 'help' , '' , 0 , 2 , 'substittooltipfrombody' );
$out .= '</td>' ;
2022-09-19 21:02:06 +02:00
$out .= '</tr>' ;
$out .= '<tr>' ;
$out .= '<td colspan="2">' ;
2021-01-04 23:41:20 +01:00
if ( $this -> withbodyreadonly ) {
2019-12-03 11:17:29 +01:00
$out .= nl2br ( $defaultmessage );
$out .= '<input type="hidden" id="message" name="message" value="' . $defaultmessage . '" />' ;
2020-05-21 15:05:19 +02:00
} else {
2021-01-04 23:41:20 +01:00
if ( ! isset ( $this -> ckeditortoolbar )) {
2022-07-18 09:21:51 +02:00
$this -> ckeditortoolbar = 'dolibarr_mailings' ;
2021-01-04 23:41:20 +01:00
}
2013-01-24 17:29:11 +01:00
2017-10-13 13:28:26 +02:00
// Editor wysiwyg
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2021-01-04 23:41:20 +01:00
if ( $this -> withfckeditor == - 1 ) {
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'FCKEDITOR_ENABLE_MAIL' )) {
2021-01-12 23:46:29 +01:00
$this -> withfckeditor = 1 ;
} else {
$this -> withfckeditor = 0 ;
}
2017-10-13 13:28:26 +02:00
}
2014-06-21 01:26:41 +02:00
2019-12-03 11:17:29 +01:00
$doleditor = new DolEditor ( 'message' , $defaultmessage , '' , 280 , $this -> ckeditortoolbar , 'In' , true , true , $this -> withfckeditor , 8 , '95%' );
$out .= $doleditor -> Create ( 1 );
2017-10-13 13:28:26 +02:00
}
2019-12-03 11:17:29 +01:00
$out .= " </td></tr> \n " ;
2017-10-13 13:28:26 +02:00
}
2013-01-24 17:29:11 +01:00
2019-12-03 11:17:29 +01:00
$out .= '</table>' . " \n " ;
2016-06-10 18:41:18 +02:00
2021-01-04 23:41:20 +01:00
if ( $this -> withform == 1 || $this -> withform == - 1 ) {
2021-09-22 08:43:30 +02:00
$out .= '<div class="center">' ;
$out .= '<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="' . $langs -> trans ( " SendMail " ) . '"' ;
2017-10-13 13:28:26 +02:00
// Add a javascript test to avoid to forget to submit file before sending email
2021-01-04 23:41:20 +01:00
if ( $this -> withfile == 2 && $conf -> use_javascript_ajax ) {
2019-12-03 11:17:29 +01:00
$out .= ' onClick="if (document.mailform.addedfile.value != \'\') { alert(\'' . dol_escape_js ( $langs -> trans ( " FileWasNotUploaded " )) . '\'); return false; } else { return true; }"' ;
2017-10-13 13:28:26 +02:00
}
2019-12-03 11:17:29 +01:00
$out .= ' />' ;
2021-01-04 23:41:20 +01:00
if ( $this -> withcancel ) {
2020-11-23 15:12:52 +01:00
$out .= '<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '" />' ;
2017-10-13 13:28:26 +02:00
}
2019-12-03 11:17:29 +01:00
$out .= '</div>' . " \n " ;
2017-10-13 13:28:26 +02:00
}
2013-01-24 17:29:11 +01:00
2021-01-04 23:41:20 +01:00
if ( $this -> withform == 1 ) {
$out .= '</form>' . " \n " ;
}
2015-06-04 12:57:49 +02:00
2017-10-13 13:28:26 +02:00
// Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MAIN_MAILFORM_DISABLE_ENTERKEY' )) {
2023-02-18 15:10:05 +01:00
$out .= '<script nonce="' . getNonce () . '" type="text/javascript">' ;
2019-12-03 11:17:29 +01:00
$out .= 'jQuery(document).ready(function () {' ;
$out .= ' $ ( document ) . on ( " keypress " , \ ' #mailform\', function (e) { /* Note this is called at every key pressed ! */
2015-06-04 12:57:49 +02:00
var code = e . keyCode || e . which ;
if ( code == 13 ) {
2020-03-06 11:02:40 +01:00
console . log ( " Enter was intercepted and blocked " );
2015-06-04 12:57:49 +02:00
e . preventDefault ();
return false ;
}
}); ' ;
2019-12-03 11:17:29 +01:00
$out .= ' })' ;
$out .= '</script>' ;
2017-10-13 13:28:26 +02:00
}
2015-06-04 12:57:49 +02:00
2019-12-03 11:17:29 +01:00
$out .= " <!-- End form mail --> \n " ;
2013-01-24 17:29:11 +01:00
2017-10-13 13:28:26 +02:00
return $out ;
}
}
2014-09-17 01:12:59 +02:00
2021-03-15 20:17:01 +01:00
/**
* get html For To
*
* @ return string html
*/
public function getHtmlForTo ()
{
global $langs , $form ;
$out = '<tr><td class="fieldrequired">' ;
if ( $this -> withtofree ) {
$out .= $form -> textwithpicto ( $langs -> trans ( " MailTo " ), $langs -> trans ( " YouCanUseCommaSeparatorForSeveralRecipients " ));
} else {
$out .= $langs -> trans ( " MailTo " );
}
$out .= '</td><td>' ;
if ( $this -> withtoreadonly ) {
if ( ! empty ( $this -> toname ) && ! empty ( $this -> tomail )) {
$out .= '<input type="hidden" id="toname" name="toname" value="' . $this -> toname . '" />' ;
$out .= '<input type="hidden" id="tomail" name="tomail" value="' . $this -> tomail . '" />' ;
if ( $this -> totype == 'thirdparty' ) {
$soc = new Societe ( $this -> db );
$soc -> fetch ( $this -> toid );
$out .= $soc -> getNomUrl ( 1 );
} elseif ( $this -> totype == 'contact' ) {
$contact = new Contact ( $this -> db );
$contact -> fetch ( $this -> toid );
$out .= $contact -> getNomUrl ( 1 );
} else {
$out .= $this -> toname ;
}
$out .= ' <' . $this -> tomail . '>' ;
if ( $this -> withtofree ) {
$out .= '<br>' . $langs -> trans ( " and " ) . ' <input class="minwidth200" id="sendto" name="sendto" value="' . ( ! is_array ( $this -> withto ) && ! is_numeric ( $this -> withto ) ? ( GETPOSTISSET ( " sendto " ) ? GETPOST ( " sendto " ) : $this -> withto ) : " " ) . '" />' ;
}
} else {
// Note withto may be a text like 'AllRecipientSelected'
$out .= ( ! is_array ( $this -> withto ) && ! is_numeric ( $this -> withto )) ? $this -> withto : " " ;
}
} else {
// The free input of email
if ( ! empty ( $this -> withtofree )) {
$out .= '<input class="minwidth200" id="sendto" name="sendto" value="' . (( $this -> withtofree && ! is_numeric ( $this -> withtofree )) ? $this -> withtofree : ( ! is_array ( $this -> withto ) && ! is_numeric ( $this -> withto ) ? ( GETPOSTISSET ( " sendto " ) ? GETPOST ( " sendto " ) : $this -> withto ) : " " )) . '" />' ;
}
// The select combo
if ( ! empty ( $this -> withto ) && is_array ( $this -> withto )) {
if ( ! empty ( $this -> withtofree )) {
$out .= " " . $langs -> trans ( " and " ) . " / " . $langs -> trans ( " or " ) . " " ;
}
2023-08-16 17:55:44 +02:00
2021-03-15 20:17:01 +01:00
$tmparray = $this -> withto ;
foreach ( $tmparray as $key => $val ) {
2023-08-16 17:55:44 +02:00
if ( is_array ( $val )) {
$label = $val [ 'label' ];
} else {
$label = $val ;
}
$tmparray [ $key ] = array ();
$tmparray [ $key ][ 'id' ] = $key ;
$tmparray [ $key ][ 'label' ] = $label ;
$tmparray [ $key ][ 'label' ] = str_replace ( array ( '<' , '>' ), array ( '(' , ')' ), $tmparray [ $key ][ 'label' ]);
// multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
$tmparray [ $key ][ 'label' ] = dol_htmlentities ( $tmparray [ $key ][ 'label' ], ENT_QUOTES | ENT_SUBSTITUTE , 'UTF-8' , true );
$tmparray [ $key ][ 'labelhtml' ] = $label ;
$tmparray [ $key ][ 'labelhtml' ] = str_replace ( array ( '<' , '<' , '>' , '>' ), array ( '__LTCHAR__' , '__LTCHAR__' , '__GTCHAR__' , '__GTCHAR__' ), $tmparray [ $key ][ 'labelhtml' ]);
$tmparray [ $key ][ 'labelhtml' ] = str_replace ( array ( '__LTCHAR__' , '__GTCHAR__' ), array ( '<span class="opacitymedium">(' , ')</span>' ), $tmparray [ $key ][ 'labelhtml' ]);
2021-03-15 20:17:01 +01:00
}
2023-02-01 01:04:29 +01:00
$withtoselected = GETPOST ( " receiver " , 'array' ); // Array of selected value
if ( ! getDolGlobalInt ( 'MAIN_MAIL_NO_WITH_TO_SELECTED' )) {
2023-01-25 23:56:57 +01:00
if ( empty ( $withtoselected ) && count ( $tmparray ) == 1 && GETPOST ( 'action' , 'aZ09' ) == 'presend' ) {
$withtoselected = array_keys ( $tmparray );
}
2021-03-15 20:17:01 +01:00
}
2022-08-29 19:40:47 +02:00
2023-08-16 17:55:44 +02:00
$out .= $form -> multiselectarray ( " receiver " , $tmparray , $withtoselected , null , null , 'inline-block minwidth500' , 0 , 0 );
2021-03-15 20:17:01 +01:00
}
}
$out .= " </td></tr> \n " ;
return $out ;
}
/**
* get html For CC
*
* @ return string html
*/
public function getHtmlForCc ()
{
global $langs , $form ;
$out = '<tr><td>' ;
$out .= $form -> textwithpicto ( $langs -> trans ( " MailCC " ), $langs -> trans ( " YouCanUseCommaSeparatorForSeveralRecipients " ));
$out .= '</td><td>' ;
if ( $this -> withtoccreadonly ) {
$out .= ( ! is_array ( $this -> withtocc ) && ! is_numeric ( $this -> withtocc )) ? $this -> withtocc : " " ;
} else {
$out .= '<input class="minwidth200" id="sendtocc" name="sendtocc" value="' . ( GETPOST ( " sendtocc " , " alpha " ) ? GETPOST ( " sendtocc " , " alpha " ) : (( ! is_array ( $this -> withtocc ) && ! is_numeric ( $this -> withtocc )) ? $this -> withtocc : '' )) . '" />' ;
if ( ! empty ( $this -> withtocc ) && is_array ( $this -> withtocc )) {
$out .= " " . $langs -> trans ( " and " ) . " / " . $langs -> trans ( " or " ) . " " ;
2023-08-16 17:55:44 +02:00
2021-03-15 20:17:01 +01:00
$tmparray = $this -> withtocc ;
foreach ( $tmparray as $key => $val ) {
2023-08-16 17:55:44 +02:00
if ( is_array ( $val )) {
$label = $val [ 'label' ];
} else {
$label = $val ;
}
$tmparray [ $key ] = array ();
$tmparray [ $key ][ 'id' ] = $key ;
$tmparray [ $key ][ 'label' ] = $label ;
$tmparray [ $key ][ 'label' ] = str_replace ( array ( '<' , '>' ), array ( '(' , ')' ), $tmparray [ $key ][ 'label' ]);
// multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
$tmparray [ $key ][ 'label' ] = dol_htmlentities ( $tmparray [ $key ][ 'label' ], ENT_QUOTES | ENT_SUBSTITUTE , 'UTF-8' , true );
$tmparray [ $key ][ 'labelhtml' ] = $label ;
$tmparray [ $key ][ 'labelhtml' ] = str_replace ( array ( '<' , '<' , '>' , '>' ), array ( '__LTCHAR__' , '__LTCHAR__' , '__GTCHAR__' , '__GTCHAR__' ), $tmparray [ $key ][ 'labelhtml' ]);
$tmparray [ $key ][ 'labelhtml' ] = str_replace ( array ( '__LTCHAR__' , '__GTCHAR__' ), array ( '<span class="opacitymedium">(' , ')</span>' ), $tmparray [ $key ][ 'labelhtml' ]);
2021-03-15 20:17:01 +01:00
}
2023-08-16 17:55:44 +02:00
2021-03-15 20:17:01 +01:00
$withtoccselected = GETPOST ( " receivercc " , 'array' ); // Array of selected value
2023-08-16 17:55:44 +02:00
$out .= $form -> multiselectarray ( " receivercc " , $tmparray , $withtoccselected , null , null , 'inline-block minwidth500' , 0 , 0 );
2021-03-15 20:17:01 +01:00
}
}
$out .= " </td></tr> \n " ;
return $out ;
}
2018-11-19 21:19:39 +01:00
/**
* get html For WithCCC
*
* @ return string html
*/
public function getHtmlForWithCcc ()
{
global $conf , $langs , $form ;
$out = '<tr><td>' ;
2019-12-03 11:17:29 +01:00
$out .= $form -> textwithpicto ( $langs -> trans ( " MailCCC " ), $langs -> trans ( " YouCanUseCommaSeparatorForSeveralRecipients " ));
$out .= '</td><td>' ;
if ( ! empty ( $this -> withtocccreadonly )) {
$out .= ( ! is_array ( $this -> withtoccc ) && ! is_numeric ( $this -> withtoccc )) ? $this -> withtoccc : " " ;
2018-11-19 21:19:39 +01:00
} else {
2020-09-29 21:28:07 +02:00
$out .= '<input class="minwidth200" id="sendtoccc" name="sendtoccc" value="' . ( GETPOSTISSET ( " sendtoccc " ) ? GETPOST ( " sendtoccc " , " alpha " ) : (( ! is_array ( $this -> withtoccc ) && ! is_numeric ( $this -> withtoccc )) ? $this -> withtoccc : '' )) . '" />' ;
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withtoccc ) && is_array ( $this -> withtoccc )) {
$out .= " " . $langs -> trans ( " and " ) . " / " . $langs -> trans ( " or " ) . " " ;
2023-08-16 17:55:44 +02:00
2018-11-19 21:19:39 +01:00
$tmparray = $this -> withtoccc ;
foreach ( $tmparray as $key => $val ) {
2023-08-16 17:55:44 +02:00
if ( is_array ( $val )) {
$label = $val [ 'label' ];
} else {
$label = $val ;
}
$tmparray [ $key ] = array ();
$tmparray [ $key ][ 'id' ] = $key ;
$tmparray [ $key ][ 'label' ] = $label ;
$tmparray [ $key ][ 'label' ] = str_replace ( array ( '<' , '>' ), array ( '(' , ')' ), $tmparray [ $key ][ 'label' ]);
// multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
$tmparray [ $key ][ 'label' ] = dol_htmlentities ( $tmparray [ $key ][ 'label' ], ENT_QUOTES | ENT_SUBSTITUTE , 'UTF-8' , true );
$tmparray [ $key ][ 'labelhtml' ] = $label ;
$tmparray [ $key ][ 'labelhtml' ] = str_replace ( array ( '<' , '<' , '>' , '>' ), array ( '__LTCHAR__' , '__LTCHAR__' , '__GTCHAR__' , '__GTCHAR__' ), $tmparray [ $key ][ 'labelhtml' ]);
$tmparray [ $key ][ 'labelhtml' ] = str_replace ( array ( '__LTCHAR__' , '__GTCHAR__' ), array ( '<span class="opacitymedium">(' , ')</span>' ), $tmparray [ $key ][ 'labelhtml' ]);
2018-11-19 21:19:39 +01:00
}
2023-08-16 17:55:44 +02:00
2020-09-29 21:28:07 +02:00
$withtocccselected = GETPOST ( " receiverccc " , 'array' ); // Array of selected value
2023-08-16 17:55:44 +02:00
$out .= $form -> multiselectarray ( " receiverccc " , $tmparray , $withtocccselected , null , null , 'inline-block minwidth500' , 0 , 0 );
2018-11-19 21:19:39 +01:00
}
}
2019-12-03 11:17:29 +01:00
$showinfobcc = '' ;
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MAIN_MAIL_AUTOCOPY_PROPOSAL_TO' ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'propal_send' ) {
2021-01-02 16:58:05 +01:00
$showinfobcc = $conf -> global -> MAIN_MAIL_AUTOCOPY_PROPOSAL_TO ;
}
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MAIN_MAIL_AUTOCOPY_ORDER_TO' ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'order_send' ) {
2021-01-02 16:58:05 +01:00
$showinfobcc = $conf -> global -> MAIN_MAIL_AUTOCOPY_ORDER_TO ;
}
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MAIN_MAIL_AUTOCOPY_INVOICE_TO' ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'facture_send' ) {
2021-01-02 16:58:05 +01:00
$showinfobcc = $conf -> global -> MAIN_MAIL_AUTOCOPY_INVOICE_TO ;
}
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO' ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'supplier_proposal_send' ) {
2021-01-02 16:58:05 +01:00
$showinfobcc = $conf -> global -> MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO ;
}
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO' ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'order_supplier_send' ) {
2021-01-02 16:58:05 +01:00
$showinfobcc = $conf -> global -> MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO ;
}
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO' ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'invoice_supplier_send' ) {
2021-01-02 16:58:05 +01:00
$showinfobcc = $conf -> global -> MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO ;
}
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MAIN_MAIL_AUTOCOPY_PROJECT_TO' ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'project' ) {
2021-01-02 16:58:05 +01:00
$showinfobcc = $conf -> global -> MAIN_MAIL_AUTOCOPY_PROJECT_TO ;
}
if ( $showinfobcc ) {
$out .= ' + ' . $showinfobcc ;
}
2019-12-03 11:17:29 +01:00
$out .= " </td></tr> \n " ;
2018-11-19 21:19:39 +01:00
return $out ;
}
/**
* get Html For WithErrorsTo
*
* @ return string html
*/
public function getHtmlForWithErrorsTo ()
{
global $conf , $langs ;
//if (! $this->errorstomail) $this->errorstomail=$this->frommail;
2022-08-10 14:42:07 +02:00
$errorstomail = getDolGlobalString ( 'MAIN_MAIL_ERRORS_TO' , ( ! empty ( $this -> errorstomail ) ? $this -> errorstomail : '' ));
2018-11-19 21:19:39 +01:00
if ( $this -> witherrorstoreadonly ) {
2019-12-03 11:17:29 +01:00
$out = '<tr><td>' . $langs -> trans ( " MailErrorsTo " ) . '</td><td>' ;
$out .= '<input type="hidden" id="errorstomail" name="errorstomail" value="' . $errorstomail . '" />' ;
$out .= $errorstomail ;
$out .= " </td></tr> \n " ;
2018-11-19 21:19:39 +01:00
} else {
2019-12-03 11:17:29 +01:00
$out = '<tr><td>' . $langs -> trans ( " MailErrorsTo " ) . '</td><td>' ;
2022-10-23 17:14:23 +02:00
$out .= '<input class="minwidth200" id="errorstomail" name="errorstomail" value="' . $errorstomail . '" />' ;
2019-12-03 11:17:29 +01:00
$out .= " </td></tr> \n " ;
2018-11-19 21:19:39 +01:00
}
return $out ;
}
/**
2021-01-16 14:12:09 +01:00
* get Html For Asking for Delivery Receipt
2018-11-19 21:19:39 +01:00
*
* @ return string html
*/
public function getHtmlForDeliveryreceipt ()
{
2022-09-19 21:10:07 +02:00
global $conf , $langs ;
$out = '<tr><td><label for="deliveryreceipt">' . $langs -> trans ( " DeliveryReceipt " ) . '</label></td><td>' ;
2018-11-19 21:19:39 +01:00
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withdeliveryreceiptreadonly )) {
$out .= yn ( $this -> withdeliveryreceipt );
2018-11-19 21:19:39 +01:00
} else {
2019-12-03 11:17:29 +01:00
$defaultvaluefordeliveryreceipt = 0 ;
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MAIL_FORCE_DELIVERY_RECEIPT_PROPAL' ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'propal_send' ) {
2021-01-12 23:46:29 +01:00
$defaultvaluefordeliveryreceipt = 1 ;
}
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_PROPOSAL' ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'supplier_proposal_send' ) {
2021-01-12 23:46:29 +01:00
$defaultvaluefordeliveryreceipt = 1 ;
}
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MAIL_FORCE_DELIVERY_RECEIPT_ORDER' ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'order_send' ) {
2021-01-12 23:46:29 +01:00
$defaultvaluefordeliveryreceipt = 1 ;
}
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MAIL_FORCE_DELIVERY_RECEIPT_INVOICE' ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'facture_send' ) {
2021-01-12 23:46:29 +01:00
$defaultvaluefordeliveryreceipt = 1 ;
}
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_ORDER' ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'order_supplier_send' ) {
2022-04-27 09:25:38 +02:00
$defaultvaluefordeliveryreceipt = 1 ;
}
2022-09-19 21:10:07 +02:00
//$out .= $form->selectyesno('deliveryreceipt', (GETPOSTISSET("deliveryreceipt") ? GETPOST("deliveryreceipt") : $defaultvaluefordeliveryreceipt), 1);
$out .= '<input type="checkbox" id="deliveryreceipt" name="deliveryreceipt" value="1"' . (( GETPOSTISSET ( " deliveryreceipt " ) ? GETPOST ( " deliveryreceipt " ) : $defaultvaluefordeliveryreceipt ) ? ' checked="checked"' : '' ) . '>' ;
2018-11-19 21:19:39 +01:00
}
2019-12-03 11:17:29 +01:00
$out .= " </td></tr> \n " ;
2018-11-19 21:19:39 +01:00
return $out ;
}
/**
* get Html For Topic of message
*
2018-12-27 05:18:16 +01:00
* @ param array $arraydefaultmessage Array with message template content
* @ param string $helpforsubstitution Help string for substitution
* @ return string Text for topic
2018-11-19 21:19:39 +01:00
*/
2018-12-27 05:18:16 +01:00
public function getHtmlForTopic ( $arraydefaultmessage , $helpforsubstitution )
2018-11-19 21:19:39 +01:00
{
global $conf , $langs , $form ;
2018-12-27 05:18:16 +01:00
2020-09-18 01:29:17 +02:00
$defaulttopic = GETPOST ( 'subject' , 'restricthtml' );
2022-01-21 13:44:40 +01:00
2019-12-03 11:17:29 +01:00
if ( ! GETPOST ( 'modelselected' , 'alpha' ) || GETPOST ( 'modelmailselected' ) != '-1' ) {
2018-11-19 21:19:39 +01:00
if ( $arraydefaultmessage && $arraydefaultmessage -> topic ) {
$defaulttopic = $arraydefaultmessage -> topic ;
2019-12-03 11:17:29 +01:00
} elseif ( ! is_numeric ( $this -> withtopic )) {
2018-11-19 21:19:39 +01:00
$defaulttopic = $this -> withtopic ;
}
}
2014-09-17 01:12:59 +02:00
2019-12-03 11:17:29 +01:00
$defaulttopic = make_substitutions ( $defaulttopic , $this -> substit );
2018-11-19 21:19:39 +01:00
$out = '<tr>' ;
2019-12-03 11:17:29 +01:00
$out .= '<td class="fieldrequired">' ;
$out .= $form -> textwithpicto ( $langs -> trans ( 'MailTopic' ), $helpforsubstitution , 1 , 'help' , '' , 0 , 2 , 'substittooltipfromtopic' );
$out .= '</td>' ;
$out .= '<td>' ;
2018-11-19 21:19:39 +01:00
if ( $this -> withtopicreadonly ) {
2019-12-03 11:17:29 +01:00
$out .= $defaulttopic ;
$out .= '<input type="hidden" class="quatrevingtpercent" id="subject" name="subject" value="' . $defaulttopic . '" />' ;
2018-11-19 21:19:39 +01:00
} else {
2020-11-30 14:47:07 +01:00
$out .= '<input type="text" class="quatrevingtpercent" id="subject" name="subject" value="' . (( GETPOSTISSET ( " subject " ) && ! GETPOST ( 'modelselected' )) ? GETPOST ( " subject " ) : ( $defaulttopic ? $defaulttopic : '' )) . '" />' ;
2018-11-19 21:19:39 +01:00
}
2019-12-03 11:17:29 +01:00
$out .= " </td></tr> \n " ;
2018-11-19 21:19:39 +01:00
return $out ;
}
2014-09-17 01:12:59 +02:00
/**
2019-02-27 20:45:07 +01:00
* Return templates of email with type = $type_template or type = 'all' .
* This search into table c_email_templates . Used by the get_form function .
2014-09-17 01:12:59 +02:00
*
2022-03-07 19:37:53 +01:00
* @ param DoliDB $dbs Database handler
2019-02-27 20:45:07 +01:00
* @ param string $type_template Get message for model / type = $type_template , type = 'all' also included .
2022-11-23 18:49:59 +01:00
* @ param User $user Get templates public + limited to this user
2019-02-27 20:45:07 +01:00
* @ param Translate $outputlangs Output lang object
2023-04-25 16:57:31 +02:00
* @ param int $id Id of template to get , or
* - 1 for first found with position 0 , or
* 0 for first found whatever is position ( priority order depends on lang provided or not ) or
* - 2 for exact match with label ( no answer if not found )
2019-02-27 20:45:07 +01:00
* @ param int $active 1 = Only active template , 0 = Only disabled , - 1 = All
2022-05-03 20:07:21 +02:00
* @ param string $label Label of template to get
2023-04-25 16:57:31 +02:00
* @ param int $defaultfortype 1 = Only default templates , 0 = Only not default , - 1 = All
2022-10-18 23:12:15 +02:00
* @ return ModelMail | integer One instance of ModelMail or < 0 if error
2014-09-17 01:12:59 +02:00
*/
2023-04-25 16:57:31 +02:00
public function getEMailTemplate ( $dbs , $type_template , $user , $outputlangs , $id = 0 , $active = 1 , $label = '' , $defaultfortype = - 1 )
2014-09-17 01:12:59 +02:00
{
2023-04-25 16:57:31 +02:00
global $conf ;
2014-09-17 01:12:59 +02:00
2019-02-27 20:45:07 +01:00
if ( $id == - 2 && empty ( $label )) {
2023-04-25 16:57:31 +02:00
$this -> error = 'LabelIsMandatoryWhenIdIs-2or-3' ;
2018-03-16 19:03:16 +01:00
return - 1 ;
}
2023-04-25 16:57:31 +02:00
$ret = new ModelMail ();
2019-06-25 14:02:58 +02:00
$languagetosearch = ( is_object ( $outputlangs ) ? $outputlangs -> defaultlang : '' );
// Define $languagetosearchmain to fall back on main language (for example to get 'es_ES' for 'es_MX')
$tmparray = explode ( '_' , $languagetosearch );
$languagetosearchmain = $tmparray [ 0 ] . '_' . strtoupper ( $tmparray [ 0 ]);
2021-01-02 16:58:05 +01:00
if ( $languagetosearchmain == $languagetosearch ) {
$languagetosearchmain = '' ;
}
2019-06-25 14:02:58 +02:00
2023-08-02 12:05:44 +02:00
$sql = " SELECT rowid, module, label, type_template, topic, email_from, joinfiles, content, content_lines, lang, email_from, email_to, email_tocc, email_tobcc " ;
2022-03-07 19:37:53 +01:00
$sql .= " FROM " . $dbs -> prefix () . 'c_email_templates' ;
2022-11-07 14:16:04 +01:00
$sql .= " WHERE (type_template = ' " . $dbs -> escape ( $type_template ) . " ' OR type_template = 'all') " ;
2019-12-03 11:17:29 +01:00
$sql .= " AND entity IN ( " . getEntity ( 'c_email_templates' ) . " ) " ;
2021-08-23 17:41:11 +02:00
$sql .= " AND (private = 0 OR fk_user = " . (( int ) $user -> id ) . " ) " ; // Get all public or private owned
2021-01-12 23:46:29 +01:00
if ( $active >= 0 ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND active = " . (( int ) $active );
2021-01-12 23:46:29 +01:00
}
2023-04-25 16:57:31 +02:00
if ( $defaultfortype >= 0 ) {
$sql .= " AND defaultfortype = " . (( int ) $defaultfortype );
}
2021-01-12 23:46:29 +01:00
if ( $label ) {
2022-03-07 19:37:53 +01:00
$sql .= " AND label = ' " . $dbs -> escape ( $label ) . " ' " ;
2021-01-12 23:46:29 +01:00
}
if ( ! ( $id > 0 ) && $languagetosearch ) {
2022-03-07 19:37:53 +01:00
$sql .= " AND (lang = ' " . $dbs -> escape ( $languagetosearch ) . " ' " . ( $languagetosearchmain ? " OR lang = ' " . $dbs -> escape ( $languagetosearchmain ) . " ' " : " " ) . " OR lang IS NULL OR lang = '') " ;
2021-01-12 23:46:29 +01:00
}
if ( $id > 0 ) {
2023-03-26 18:48:29 +02:00
$sql .= " AND rowid = " . ( int ) $id ;
2021-01-12 23:46:29 +01:00
}
if ( $id == - 1 ) {
2023-03-26 18:48:29 +02:00
$sql .= " AND position = 0 " ;
2021-01-12 23:46:29 +01:00
}
2021-01-02 16:58:05 +01:00
if ( $languagetosearch ) {
2022-03-07 19:37:53 +01:00
$sql .= $dbs -> order ( " position,lang,label " , " ASC,DESC,ASC " ); // We want line with lang set first, then with lang null or ''
2021-01-02 16:58:05 +01:00
} else {
2022-03-07 19:37:53 +01:00
$sql .= $dbs -> order ( " position,lang,label " , " ASC,ASC,ASC " ); // If no language provided, we give priority to lang not defined
2021-01-02 16:58:05 +01:00
}
2022-03-07 19:37:53 +01:00
//$sql .= $dbs->plimit(1);
2014-10-20 11:35:34 +02:00
//print $sql;
2014-09-17 01:12:59 +02:00
2022-03-07 19:37:53 +01:00
$resql = $dbs -> query ( $sql );
2021-03-01 00:19:52 +01:00
if ( ! $resql ) {
2022-03-07 19:37:53 +01:00
dol_print_error ( $dbs );
2021-02-28 12:47:24 +01:00
return - 1 ;
}
// Get first found
while ( 1 ) {
2022-03-07 19:37:53 +01:00
$obj = $dbs -> fetch_object ( $resql );
2017-12-17 23:42:50 +01:00
if ( $obj ) {
2021-02-28 12:47:24 +01:00
// If template is for a module, check module is enabled; if not, take next template
if ( $obj -> module ) {
$tempmodulekey = $obj -> module ;
2023-06-12 20:43:28 +02:00
if ( empty ( $conf -> $tempmodulekey ) || ! isModEnabled ( $tempmodulekey )) {
2021-02-28 12:47:24 +01:00
continue ;
}
}
// If a record was found
2018-03-21 16:40:09 +01:00
$ret -> id = $obj -> rowid ;
2021-02-28 12:47:24 +01:00
$ret -> module = $obj -> module ;
2017-12-17 23:42:50 +01:00
$ret -> label = $obj -> label ;
$ret -> lang = $obj -> lang ;
$ret -> topic = $obj -> topic ;
$ret -> content = $obj -> content ;
$ret -> content_lines = $obj -> content_lines ;
$ret -> joinfiles = $obj -> joinfiles ;
2023-08-02 12:05:44 +02:00
$ret -> email_from = $obj -> email_from ;
2018-05-22 20:17:31 +02:00
2021-02-28 12:47:24 +01:00
break ;
2021-01-12 23:46:29 +01:00
} else {
2021-02-28 12:47:24 +01:00
// If no record found
if ( $id == - 2 ) {
// Not found with the provided label
return - 1 ;
} else {
// If there is no template at all
$defaultmessage = '' ;
2018-05-22 20:17:31 +02:00
2021-02-28 12:47:24 +01:00
if ( $type_template == 'body' ) {
// Special case to use this->withbody as content
$defaultmessage = $this -> withbody ;
} elseif ( $type_template == 'facture_send' ) {
$defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentSendInvoice " );
} elseif ( $type_template == 'facture_relance' ) {
$defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentSendInvoiceReminder " );
} elseif ( $type_template == 'propal_send' ) {
$defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentSendProposal " );
} elseif ( $type_template == 'supplier_proposal_send' ) {
$defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentSendSupplierProposal " );
} elseif ( $type_template == 'order_send' ) {
$defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentSendOrder " );
} elseif ( $type_template == 'order_supplier_send' ) {
$defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentSendSupplierOrder " );
} elseif ( $type_template == 'invoice_supplier_send' ) {
$defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentSendSupplierInvoice " );
} elseif ( $type_template == 'shipping_send' ) {
$defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentSendShipping " );
} elseif ( $type_template == 'fichinter_send' ) {
$defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentSendFichInter " );
} elseif ( $type_template == 'actioncomm_send' ) {
$defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentSendActionComm " );
} elseif ( ! empty ( $type_template )) {
$defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentGeneric " );
}
2014-09-17 01:12:59 +02:00
2021-02-28 12:47:24 +01:00
$ret -> label = 'default' ;
$ret -> lang = $outputlangs -> defaultlang ;
$ret -> topic = '' ;
$ret -> joinfiles = 1 ;
$ret -> content = $defaultmessage ;
$ret -> content_lines = '' ;
break ;
}
}
2014-09-17 01:12:59 +02:00
}
2021-02-28 12:47:24 +01:00
2022-03-07 19:37:53 +01:00
$dbs -> free ( $resql );
2021-02-28 12:47:24 +01:00
return $ret ;
2014-09-17 01:12:59 +02:00
}
2015-05-04 22:02:54 +02:00
2015-04-18 11:06:53 +02:00
/**
* Find if template exists
* Search into table c_email_templates
*
* @ param string $type_template Get message for key module
2021-01-02 16:58:05 +01:00
* @ param User $user Use template public or limited to this user
2015-04-18 11:06:53 +02:00
* @ param Translate $outputlangs Output lang object
2023-12-06 15:46:39 +01:00
* @ return int Return integer < 0 if KO ,
2015-04-18 11:06:53 +02:00
*/
public function isEMailTemplate ( $type_template , $user , $outputlangs )
{
$sql = " SELECT label, topic, content, lang " ;
2022-01-27 10:19:35 +01:00
$sql .= " FROM " . $this -> db -> prefix () . 'c_email_templates' ;
2019-12-03 11:17:29 +01:00
$sql .= " WHERE type_template=' " . $this -> db -> escape ( $type_template ) . " ' " ;
$sql .= " AND entity IN ( " . getEntity ( 'c_email_templates' ) . " ) " ;
2021-08-23 17:41:11 +02:00
$sql .= " AND (fk_user is NULL or fk_user = 0 or fk_user = " . (( int ) $user -> id ) . " ) " ;
2021-01-02 16:58:05 +01:00
if ( is_object ( $outputlangs )) {
$sql .= " AND (lang = ' " . $this -> db -> escape ( $outputlangs -> defaultlang ) . " ' OR lang IS NULL OR lang = '') " ;
}
2019-12-03 11:17:29 +01:00
$sql .= $this -> db -> order ( " lang,label " , " ASC " );
2015-04-18 11:06:53 +02:00
//print $sql;
2015-05-04 22:02:54 +02:00
2015-04-18 11:06:53 +02:00
$resql = $this -> db -> query ( $sql );
2021-01-02 16:58:05 +01:00
if ( $resql ) {
2019-12-03 11:17:29 +01:00
$num = $this -> db -> num_rows ( $resql );
2015-04-18 11:06:53 +02:00
$this -> db -> free ( $resql );
return $num ;
2020-05-21 15:05:19 +02:00
} else {
2019-12-03 11:17:29 +01:00
$this -> error = get_class ( $this ) . ' ' . __METHOD__ . ' ERROR:' . $this -> db -> lasterror ();
2015-04-18 11:06:53 +02:00
return - 1 ;
}
}
2015-05-04 22:02:54 +02:00
2015-04-18 11:06:53 +02:00
/**
2017-09-08 14:40:39 +02:00
* Find if template exists and are available for current user , then set them into $this -> lines_module .
2015-04-18 11:06:53 +02:00
* Search into table c_email_templates
*
2023-04-25 16:57:31 +02:00
* @ param string $type_template Get message for key module
* @ param User $user Use template public or limited to this user
* @ param Translate $outputlangs Output lang object
* @ param int $active 1 = Only active template , 0 = Only disabled , - 1 = All
2023-12-06 15:46:39 +01:00
* @ return int Return integer < 0 if KO , nb of records found if OK
2015-04-18 11:06:53 +02:00
*/
2019-01-27 15:20:16 +01:00
public function fetchAllEMailTemplate ( $type_template , $user , $outputlangs , $active = 1 )
2015-04-18 11:06:53 +02:00
{
2021-02-28 12:47:24 +01:00
global $conf ;
$sql = " SELECT rowid, module, label, topic, content, content_lines, lang, fk_user, private, position " ;
2022-01-27 10:19:35 +01:00
$sql .= " FROM " . $this -> db -> prefix () . 'c_email_templates' ;
2019-12-03 11:17:29 +01:00
$sql .= " WHERE type_template IN (' " . $this -> db -> escape ( $type_template ) . " ', 'all') " ;
$sql .= " AND entity IN ( " . getEntity ( 'c_email_templates' ) . " ) " ;
2021-08-23 17:41:11 +02:00
$sql .= " AND (private = 0 OR fk_user = " . (( int ) $user -> id ) . " ) " ; // See all public templates or templates I own.
2021-01-02 16:58:05 +01:00
if ( $active >= 0 ) {
2021-06-09 15:36:47 +02:00
$sql .= " AND active = " . (( int ) $active );
2021-01-02 16:58:05 +01:00
}
2020-09-19 21:19:04 +02:00
//if (is_object($outputlangs)) $sql.= " AND (lang = '".$this->db->escape($outputlangs->defaultlang)."' OR lang IS NULL OR lang = '')"; // Return all languages
2019-12-03 11:17:29 +01:00
$sql .= $this -> db -> order ( " position,lang,label " , " ASC " );
2015-04-18 11:06:53 +02:00
//print $sql;
2015-05-04 22:02:54 +02:00
2015-04-18 11:06:53 +02:00
$resql = $this -> db -> query ( $sql );
2021-01-02 16:58:05 +01:00
if ( $resql ) {
2019-12-03 11:17:29 +01:00
$num = $this -> db -> num_rows ( $resql );
$this -> lines_model = array ();
2021-01-02 16:58:05 +01:00
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2021-02-28 12:47:24 +01:00
// If template is for a module, check module is enabled.
if ( $obj -> module ) {
$tempmodulekey = $obj -> module ;
2023-06-12 20:43:28 +02:00
if ( empty ( $conf -> $tempmodulekey ) || ! isModEnabled ( $tempmodulekey )) {
2021-02-28 12:47:24 +01:00
continue ;
}
}
2015-04-18 18:07:36 +02:00
$line = new ModelMail ();
2019-12-03 11:17:29 +01:00
$line -> id = $obj -> rowid ;
$line -> label = $obj -> label ;
$line -> lang = $obj -> lang ;
$line -> fk_user = $obj -> fk_user ;
$line -> private = $obj -> private ;
$line -> position = $obj -> position ;
$line -> topic = $obj -> topic ;
$line -> content = $obj -> content ;
$line -> content_lines = $obj -> content_lines ;
$this -> lines_model [] = $line ;
2015-04-18 11:06:53 +02:00
}
$this -> db -> free ( $resql );
return $num ;
2020-05-21 15:05:19 +02:00
} else {
2019-12-03 11:17:29 +01:00
$this -> error = get_class ( $this ) . ' ' . __METHOD__ . ' ERROR:' . $this -> db -> lasterror ();
2015-04-18 11:06:53 +02:00
return - 1 ;
}
}
2017-06-01 01:53:55 +02:00
2016-03-05 12:20:58 +01:00
/**
2022-08-29 19:40:47 +02:00
* Set -> substit ( and -> substit_line ) array from object . This is call when suggesting the email template into forms before sending email .
2017-06-01 01:53:55 +02:00
*
2017-09-16 03:13:44 +02:00
* @ param CommonObject $object Object to use
* @ param Translate $outputlangs Object lang
2016-03-05 12:20:58 +01:00
* @ return void
2019-03-14 08:19:22 +01:00
* @ see getCommonSubstitutionArray ()
2016-03-05 12:20:58 +01:00
*/
2019-02-27 20:45:07 +01:00
public function setSubstitFromObject ( $object , $outputlangs )
2016-03-05 12:20:58 +01:00
{
2020-05-28 11:44:58 +02:00
global $conf , $user , $extrafields ;
2017-09-22 14:34:31 +02:00
2019-12-03 11:17:29 +01:00
$parameters = array ();
$tmparray = getCommonSubstitutionArray ( $outputlangs , 0 , null , $object );
2017-09-22 14:34:31 +02:00
complete_substitutions_array ( $tmparray , $outputlangs , null , $parameters );
2019-12-03 11:17:29 +01:00
$this -> substit = $tmparray ;
2017-06-01 01:53:55 +02:00
2017-10-13 13:28:26 +02:00
// Fill substit_lines with each object lines content
2021-01-02 16:58:05 +01:00
if ( is_array ( $object -> lines )) {
foreach ( $object -> lines as $line ) {
2017-10-13 13:28:26 +02:00
$substit_line = array (
'__PRODUCT_REF__' => isset ( $line -> product_ref ) ? $line -> product_ref : '' ,
'__PRODUCT_LABEL__' => isset ( $line -> product_label ) ? $line -> product_label : '' ,
'__PRODUCT_DESCRIPTION__' => isset ( $line -> product_desc ) ? $line -> product_desc : '' ,
'__LABEL__' => isset ( $line -> label ) ? $line -> label : '' ,
'__DESCRIPTION__' => isset ( $line -> desc ) ? $line -> desc : '' ,
'__DATE_START_YMD__' => dol_print_date ( $line -> date_start , 'day' , 0 , $outputlangs ),
'__DATE_END_YMD__' => dol_print_date ( $line -> date_end , 'day' , 0 , $outputlangs ),
'__QUANTITY__' => $line -> qty ,
'__SUBPRICE__' => price ( $line -> subprice ),
'__AMOUNT__' => price ( $line -> total_ttc ),
2018-04-11 17:14:34 +02:00
'__AMOUNT_EXCL_TAX__' => price ( $line -> total_ht )
2017-10-13 13:28:26 +02:00
);
// Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
2021-01-02 16:58:05 +01:00
if ( ! empty ( $line -> fk_product )) {
2021-01-16 14:12:09 +01:00
if ( ! is_object ( $extrafields )) {
$extrafields = new ExtraFields ( $this -> db );
}
2017-10-13 13:28:26 +02:00
$product = new Product ( $this -> db );
$product -> fetch ( $line -> fk_product , '' , '' , 1 );
2018-02-21 14:48:25 +01:00
$product -> fetch_optionals ();
2022-05-16 13:05:17 +02:00
$extrafields -> fetch_name_optionals_label ( $product -> table_element , true );
2022-06-09 15:13:29 +02:00
if ( ! empty ( $extrafields -> attributes [ $product -> table_element ][ 'label' ]) && is_array ( $extrafields -> attributes [ $product -> table_element ][ 'label' ]) && count ( $extrafields -> attributes [ $product -> table_element ][ 'label' ]) > 0 ) {
2018-04-13 16:18:33 +02:00
foreach ( $extrafields -> attributes [ $product -> table_element ][ 'label' ] as $key => $label ) {
2022-07-04 15:50:41 +02:00
$substit_line [ '__PRODUCT_EXTRAFIELD_' . strtoupper ( $key ) . '__' ] = isset ( $product -> array_options [ 'options_' . $key ]) ? $product -> array_options [ 'options_' . $key ] : '' ;
2018-04-13 16:18:33 +02:00
}
2017-10-13 13:28:26 +02:00
}
}
$this -> substit_lines [] = $substit_line ;
}
}
2016-03-05 12:20:58 +01:00
}
2017-06-01 01:53:55 +02:00
2016-03-05 12:20:58 +01:00
/**
2017-09-16 09:15:10 +02:00
* Get list of substitution keys available for emails . This is used for tooltips help .
2017-09-16 03:13:44 +02:00
* This include the complete_substitutions_array .
2017-06-01 01:53:55 +02:00
*
2017-05-04 12:35:45 +02:00
* @ param string $mode 'formemail' , 'formemailwithlines' , 'formemailforlines' , 'emailing' , ...
2017-09-16 03:13:44 +02:00
* @ param Object $object Object if applicable
2017-06-01 01:53:55 +02:00
* @ return array Array of substitution values for emails .
2016-03-05 12:20:58 +01:00
*/
2019-02-27 20:45:07 +01:00
public static function getAvailableSubstitKey ( $mode = 'formemail' , $object = null )
2016-03-05 12:20:58 +01:00
{
2017-05-04 12:35:45 +02:00
global $conf , $langs ;
2017-06-01 01:53:55 +02:00
2019-12-03 11:17:29 +01:00
$tmparray = array ();
2021-01-02 16:58:05 +01:00
if ( $mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines' ) {
2019-12-03 11:17:29 +01:00
$parameters = array ( 'mode' => $mode );
$tmparray = getCommonSubstitutionArray ( $langs , 2 , null , $object ); // Note: On email templated edition, this is null because it is related to all type of objects
2017-09-22 14:34:31 +02:00
complete_substitutions_array ( $tmparray , $langs , null , $parameters );
2021-01-02 16:58:05 +01:00
if ( $mode == 'formwithlines' ) {
2019-12-03 11:17:29 +01:00
$tmparray [ '__LINES__' ] = '__LINES__' ; // Will be set by the get_form function
2017-02-12 18:13:49 +01:00
}
2021-01-02 16:58:05 +01:00
if ( $mode == 'formforlines' ) {
2019-12-03 11:17:29 +01:00
$tmparray [ '__QUANTITY__' ] = '__QUANTITY__' ; // Will be set by the get_form function
2017-02-12 18:13:49 +01:00
}
2016-03-05 12:20:58 +01:00
}
2017-09-22 14:34:31 +02:00
2021-01-02 16:58:05 +01:00
if ( $mode == 'emailing' ) {
2019-12-03 11:17:29 +01:00
$parameters = array ( 'mode' => $mode );
$tmparray = getCommonSubstitutionArray ( $langs , 2 , array ( 'object' , 'objectamount' ), $object ); // Note: On email templated edition, this is null because it is related to all type of objects
2017-09-22 14:34:31 +02:00
complete_substitutions_array ( $tmparray , $langs , null , $parameters );
2023-02-23 13:50:25 +01:00
// For mass emailing, we have different keys specific to the data into tagerts list
2017-09-22 14:34:31 +02:00
$tmparray [ '__ID__' ] = 'IdRecord' ;
2021-05-11 12:33:35 +02:00
$tmparray [ '__THIRDPARTY_CUSTOMER_CODE__' ] = 'CustomerCode' ;
2017-09-22 14:34:31 +02:00
$tmparray [ '__EMAIL__' ] = 'EMailRecipient' ;
$tmparray [ '__LASTNAME__' ] = 'Lastname' ;
$tmparray [ '__FIRSTNAME__' ] = 'Firstname' ;
$tmparray [ '__MAILTOEMAIL__' ] = 'TagMailtoEmail' ;
$tmparray [ '__OTHER1__' ] = 'Other1' ;
$tmparray [ '__OTHER2__' ] = 'Other2' ;
$tmparray [ '__OTHER3__' ] = 'Other3' ;
$tmparray [ '__OTHER4__' ] = 'Other4' ;
$tmparray [ '__OTHER5__' ] = 'Other5' ;
2017-09-15 13:43:16 +02:00
$onlinepaymentenabled = 0 ;
2022-09-25 21:58:40 +02:00
if ( isModEnabled ( 'paypal' )) {
2021-01-16 14:12:09 +01:00
$onlinepaymentenabled ++ ;
}
2022-09-25 21:58:40 +02:00
if ( isModEnabled ( 'paybox' )) {
2021-01-16 14:12:09 +01:00
$onlinepaymentenabled ++ ;
}
2022-09-25 21:58:40 +02:00
if ( isModEnabled ( 'stripe' )) {
2021-01-16 14:12:09 +01:00
$onlinepaymentenabled ++ ;
}
2023-11-27 11:24:19 +01:00
if ( $onlinepaymentenabled && getDolGlobalString ( 'PAYMENT_SECURITY_TOKEN' )) {
2019-12-03 11:17:29 +01:00
$tmparray [ '__SECUREKEYPAYMENT__' ] = $conf -> global -> PAYMENT_SECURITY_TOKEN ;
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'PAYMENT_SECURITY_TOKEN_UNIQUE' )) {
2022-08-31 21:55:55 +02:00
if ( isModEnabled ( 'adherent' )) {
2021-01-12 23:46:29 +01:00
$tmparray [ '__SECUREKEYPAYMENT_MEMBER__' ] = 'SecureKeyPAYMENTUniquePerMember' ;
}
2022-09-25 06:18:33 +02:00
if ( isModEnabled ( 'don' )) {
2021-05-04 01:41:32 +02:00
$tmparray [ '__SECUREKEYPAYMENT_DONATION__' ] = 'SecureKeyPAYMENTUniquePerDonation' ;
}
2022-06-11 09:46:28 +02:00
if ( isModEnabled ( 'facture' )) {
2021-01-12 23:46:29 +01:00
$tmparray [ '__SECUREKEYPAYMENT_INVOICE__' ] = 'SecureKeyPAYMENTUniquePerInvoice' ;
}
2022-08-31 21:55:55 +02:00
if ( isModEnabled ( 'commande' )) {
2021-01-12 23:46:29 +01:00
$tmparray [ '__SECUREKEYPAYMENT_ORDER__' ] = 'SecureKeyPAYMENTUniquePerOrder' ;
}
2022-08-31 22:02:31 +02:00
if ( isModEnabled ( 'contrat' )) {
2021-01-12 23:46:29 +01:00
$tmparray [ '__SECUREKEYPAYMENT_CONTRACTLINE__' ] = 'SecureKeyPAYMENTUniquePerContractLine' ;
}
2021-05-04 01:53:46 +02:00
2023-02-20 13:59:46 +01:00
//Online payment link
2022-08-31 21:55:55 +02:00
if ( isModEnabled ( 'adherent' )) {
2021-05-04 01:53:46 +02:00
$tmparray [ '__ONLINEPAYMENTLINK_MEMBER__' ] = 'OnlinePaymentLinkUniquePerMember' ;
}
2022-09-25 06:18:33 +02:00
if ( isModEnabled ( 'don' )) {
2021-05-04 01:53:46 +02:00
$tmparray [ '__ONLINEPAYMENTLINK_DONATION__' ] = 'OnlinePaymentLinkUniquePerDonation' ;
}
2022-06-11 09:46:28 +02:00
if ( isModEnabled ( 'facture' )) {
2021-05-04 01:53:46 +02:00
$tmparray [ '__ONLINEPAYMENTLINK_INVOICE__' ] = 'OnlinePaymentLinkUniquePerInvoice' ;
}
2022-08-31 21:55:55 +02:00
if ( isModEnabled ( 'commande' )) {
2021-05-04 01:53:46 +02:00
$tmparray [ '__ONLINEPAYMENTLINK_ORDER__' ] = 'OnlinePaymentLinkUniquePerOrder' ;
}
2022-08-31 22:02:31 +02:00
if ( isModEnabled ( 'contrat' )) {
2021-05-04 01:53:46 +02:00
$tmparray [ '__ONLINEPAYMENTLINK_CONTRACTLINE__' ] = 'OnlinePaymentLinkUniquePerContractLine' ;
}
2017-09-15 13:43:16 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2017-09-15 13:43:16 +02:00
/* No need to show into tooltip help , option is not enabled
$vars [ '__SECUREKEYPAYMENT__' ] = '' ;
$vars [ '__SECUREKEYPAYMENT_MEMBER__' ] = '' ;
$vars [ '__SECUREKEYPAYMENT_INVOICE__' ] = '' ;
$vars [ '__SECUREKEYPAYMENT_ORDER__' ] = '' ;
$vars [ '__SECUREKEYPAYMENT_CONTRACTLINE__' ] = '' ;
*/
}
2023-11-27 11:24:19 +01:00
if ( getDolGlobalString ( 'MEMBER_ENABLE_PUBLIC' )) {
2021-05-07 17:16:58 +02:00
$substitutionarray [ '__PUBLICLINK_NEWMEMBERFORM__' ] = 'BlankSubscriptionForm' ;
2021-05-07 17:14:33 +02:00
}
2016-03-05 12:20:58 +01:00
}
2017-06-01 01:53:55 +02:00
2021-01-02 16:58:05 +01:00
foreach ( $tmparray as $key => $val ) {
2021-01-16 14:12:09 +01:00
if ( empty ( $val )) {
$tmparray [ $key ] = $key ;
}
2017-05-04 12:35:45 +02:00
}
2017-06-01 01:53:55 +02:00
2017-09-22 14:34:31 +02:00
return $tmparray ;
2016-03-05 12:20:58 +01:00
}
2015-04-18 11:06:53 +02:00
}
2016-03-05 12:20:58 +01:00
2015-04-18 18:07:36 +02:00
/**
* ModelMail
2022-06-12 11:17:11 +02:00
*
* Object of table llx_c_email_templates
2015-04-18 18:07:36 +02:00
*/
class ModelMail
2015-04-18 13:09:35 +02:00
{
2018-09-01 23:04:46 +02:00
/**
* @ var int ID
*/
2015-04-18 11:06:53 +02:00
public $id ;
2018-08-29 12:35:56 +02:00
2018-08-28 09:44:54 +02:00
/**
2020-09-07 10:18:17 +02:00
* @ var string Model mail label
*/
public $label ;
2018-08-29 12:35:56 +02:00
2022-06-12 11:17:11 +02:00
/**
* @ var int Owner of email template
*/
public $fk_user ;
/**
* @ var int Is template private
*/
public $private ;
2021-03-15 18:58:35 +01:00
/**
* @ var string Model mail topic
*/
2015-04-18 11:06:53 +02:00
public $topic ;
2021-03-15 18:58:35 +01:00
/**
* @ var string Model mail content
*/
2015-04-18 11:06:53 +02:00
public $content ;
2016-12-26 05:18:40 +01:00
public $content_lines ;
2015-04-18 11:06:53 +02:00
public $lang ;
2017-12-17 23:42:50 +01:00
public $joinfiles ;
2022-06-09 03:21:31 +02:00
2022-11-07 14:16:04 +01:00
public $email_from ;
public $email_to ;
public $email_tocc ;
public $email_tobcc ;
2022-06-09 03:21:31 +02:00
/**
* @ var string Module the template is dedicated for
*/
public $module ;
2022-06-12 11:17:11 +02:00
/**
* @ var int Position of template in a combo list
*/
public $position ;
2010-05-03 10:43:32 +02:00
}