2012-08-22 23:27:53 +02:00
< ? php
2012-01-27 15:17:36 +01:00
/* Copyright ( C ) 2005 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2018-08-29 12:35:56 +02:00
* Copyright ( C ) 2010 - 2011 Juanjo Menent < jmenent @ 2 byte . es >
2017-12-17 23:42:50 +01:00
* Copyright ( C ) 2015 - 2017 Marcos García < marcosgdf @ gmail . com >
2018-08-28 10:43:13 +02:00
* Copyright ( C ) 2015 - 2017 Nicolas ZABOURI < info @ inovea - conseil . com >
2019-02-23 11:25:49 +01:00
* Copyright ( C ) 2018 - 2019 Frédéric France < frederic . france @ netlogic . 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
/**
* @ var DoliDB Database handler .
*/
public $db ;
2011-06-29 12:23:32 +02:00
2019-10-27 18:08:21 +01:00
/**
* @ 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
*/
public $withform ;
2011-06-29 12:23:32 +02:00
2019-10-27 18:08:21 +01:00
/**
* @ var string name from
*/
2018-08-29 12:35:56 +02:00
public $fromname ;
2019-10-27 18:08:21 +01:00
/**
* @ var string email from
*/
2018-08-29 12:35:56 +02:00
public $frommail ;
2018-10-16 22:27:34 +02:00
2018-10-16 22:22:57 +02:00
/**
* @ var string user , company , robot
*/
public $fromtype ;
2018-10-16 22:27:34 +02:00
2018-10-16 22:22:57 +02:00
/**
2019-10-27 18:08:21 +01:00
* @ var int from ID
2018-10-16 22:22:57 +02:00
*/
public $fromid ;
2018-10-16 22:27:34 +02:00
2019-10-27 18:08:21 +01:00
/**
* @ var int also from robot
*/
public $fromalsorobot ;
2018-10-16 22:27:34 +02:00
/**
* @ var string thirdparty etc
*/
public $totype ;
/**
* @ var int ID
*/
public $toid ;
2019-10-27 18:08:21 +01:00
/**
* @ var string replyto name
*/
2018-10-16 22:27:34 +02:00
public $replytoname ;
2019-10-27 18:08:21 +01:00
/**
* @ var string replyto email
*/
2018-08-29 12:35:56 +02:00
public $replytomail ;
2019-10-27 18:08:21 +01:00
/**
* @ var string to name
*/
2018-08-29 12:35:56 +02:00
public $toname ;
2019-10-27 18:08:21 +01:00
/**
* @ var string to email
*/
2018-08-29 12:35:56 +02:00
public $tomail ;
2019-10-27 18:08:21 +01:00
/**
* @ var string trackid
*/
2018-08-29 12:35:56 +02:00
public $trackid ;
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
2018-08-29 12:35:56 +02:00
2019-12-03 11:17:29 +01:00
public $withtofree ; // Show free text for recipient emails
2018-08-29 12:35:56 +02:00
public $withtocc ;
public $withtoccc ;
public $withtopic ;
2019-12-03 11:17:29 +01:00
public $withfile ; // 0=No attaches files, 1=Show attached files, 2=Can add new attached files
public $withmaindocfile ; // 1=Add a checkbox "Attach also main document" for mass actions (checked by default), -1=Add checkbox (not checked by default)
2018-08-29 12:35:56 +02:00
public $withbody ;
public $withfromreadonly ;
public $withreplytoreadonly ;
public $withtoreadonly ;
public $withtoccreadonly ;
public $withtocccreadonly ;
public $withtopicreadonly ;
public $withfilereadonly ;
public $withdeliveryreceipt ;
public $withcancel ;
public $withfckeditor ;
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 ;
/**
* 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
}
2019-02-27 20:45:07 +01: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
{
2018-09-06 18:29:01 +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
2017-10-13 13:28:26 +02:00
if ( is_dir ( $upload_dir )) dol_delete_dir_recursive ( $upload_dir );
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 ]);
}
2019-02-27 20:45:07 +01: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
{
2018-09-06 18:29:01 +02:00
// phpcs:enable
2019-12-03 11:17:29 +01:00
$listofpaths = array ();
$listofnames = array ();
$listofmimes = array ();
if ( empty ( $file )) $file = basename ( $path );
if ( empty ( $type )) $type = dol_mimetype ( $file );
$keytoavoidconflict = empty ( $this -> trackid ) ? '' : '-' . $this -> trackid ; // this->trackid must be defined
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 ))
2017-10-13 13:28:26 +02:00
{
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
}
}
2019-02-27 20:45:07 +01: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 )
*
2019-10-04 19:41:35 +02:00
* @ param string $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
{
2018-09-06 18:29:01 +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
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
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']);
}
}
2019-02-27 20:45:07 +01: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
{
2018-09-06 18:29:01 +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
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 );
}
2019-02-27 20:45:07 +01: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
*/
2019-02-27 20:45:07 +01:00
public function show_form ( $addfileaction = 'addfile' , $removefileaction = 'removefile' )
2017-10-13 13:28:26 +02:00
{
2018-09-06 18:29:01 +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
}
2019-02-27 20:45:07 +01: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
{
2018-09-06 18:29:01 +02:00
// phpcs:enable
2017-10-13 13:28:26 +02:00
global $conf , $langs , $user , $hookmanager , $form ;
2019-12-03 11:17:29 +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
$langs -> loadLangs ( array ( 'other' , 'mails' ));
2018-02-27 10:59:26 +01:00
// Clear temp files. Must be done at beginning, before call of triggers
2019-01-27 11:55:16 +01:00
if ( GETPOST ( 'mode' , 'alpha' ) == 'init' || ( 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
if ( ! empty ( $reshook ))
{
return $hookmanager -> resPrint ;
}
else
2015-08-13 05:09:26 +02:00
{
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 = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $this -> param [ 'langsmodels' ];
2019-12-03 11:17:29 +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 ;
2017-09-22 14:34:31 +02:00
if ( $this -> param [ 'models' ] != 'none' )
{
2019-12-03 11:17:29 +01:00
$model_id = 0 ;
2019-01-27 11:55:16 +01:00
if ( array_key_exists ( 'models_id' , $this -> param ))
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
$model_id = $this -> param [ " models_id " ];
2017-10-16 08:47:05 +02:00
}
2019-12-03 11:17:29 +01:00
$arraydefaultmessage = $this -> getEMailTemplate ( $this -> db , $this -> param [ " models " ], $user , $outputlangs , $model_id ); // 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
2019-01-27 11:55:16 +01:00
if ( GETPOST ( 'mode' , 'alpha' ) == 'init' || ( GETPOST ( 'modelmailselected' , 'alpha' ) && GETPOST ( 'modelmailselected' , 'alpha' ) != '-1' ))
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
if ( ! empty ( $arraydefaultmessage -> joinfiles ) && is_array ( $this -> param [ 'fileinit' ]))
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
foreach ( $this -> param [ 'fileinit' ] as $file )
2017-10-16 08:47:05 +02:00
{
2017-10-08 16:34:42 +02:00
$this -> add_attached_files ( $file , basename ( $file ), dol_mimetype ( $file ));
2017-10-16 08:47:05 +02:00
}
}
}
2019-12-03 11:17: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-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 " ;
2017-10-16 08:47:05 +02: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>' ;
$out .= '<input style="display:none" type="submit" id="sendmail" name="sendmail">' ;
$out .= '<input type="hidden" name="token" value="' . newToken () . '" />' ;
$out .= '<input type="hidden" name="trackid" value="' . $this -> trackid . '" />' ;
2017-10-16 08:47:05 +02:00
}
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withfrom ))
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withfromreadonly ))
2017-10-16 08:47:05 +02:00
{
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
}
}
foreach ( $this -> param as $key => $value )
{
2019-12-03 11:17:29 +01:00
$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 ();
2017-10-16 08:47:05 +02:00
if ( $this -> param [ 'models' ] != 'none' )
{
$result = $this -> fetchAllEMailTemplate ( $this -> param [ " models " ], $user , $outputlangs );
2019-06-12 12:30:49 +02:00
2017-10-16 08:47:05 +02:00
if ( $result < 0 )
{
setEventMessages ( $this -> error , $this -> errors , 'errors' );
}
2019-12-03 11:17:29 +01:00
foreach ( $this -> lines_model as $line )
2017-10-16 08:47:05 +02:00
{
$langs -> trans ( " members " );
if ( preg_match ( '/\((.*)\)/' , $line -> label , $reg ))
{
2019-12-03 11:17:29 +01:00
$modelmail_array [ $line -> id ] = $langs -> trans ( $reg [ 1 ]); // langs->trans when label is __(xxx)__
2017-10-16 08:47:05 +02:00
}
else
{
2019-12-03 11:17:29 +01:00
$modelmail_array [ $line -> id ] = $line -> label ;
2017-10-16 08:47:05 +02:00
}
2019-12-03 11:17:29 +01:00
if ( $line -> lang ) $modelmail_array [ $line -> id ] .= ' (' . $line -> lang . ')' ;
if ( $line -> private ) $modelmail_array [ $line -> id ] .= ' - ' . $langs -> trans ( " Private " );
2017-10-16 08:47:05 +02:00
//if ($line->fk_user != $user->id) $modelmail_array[$line->id].=' - '.$langs->trans("By").' ';
}
}
// Zone to select email template
2019-12-03 11:17:29 +01:00
if ( count ( $modelmail_array ) > 0 )
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 " ;
$out .= '<span class="opacitymedium">' . $langs -> trans ( 'SelectMailModel' ) . ':</span> ' . $this -> selectarray ( 'modelmailselected' , $modelmail_array , 0 , 1 , 0 , 0 , '' , 0 , 0 , 0 , '' , 'minwidth100' );
if ( $user -> admin ) $out .= info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFrom " , $langs -> transnoentitiesnoconv ( 'Setup' ) . ' - ' . $langs -> transnoentitiesnoconv ( 'EMails' )), 1 );
$out .= ' ' ;
$out .= '<input class="button" type="submit" value="' . $langs -> trans ( 'Apply' ) . '" name="modelselected" id="modelselected">' ;
$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' ,
'invoice_supplier_send' , 'thirdparty' , 'contract' , 'user' , 'all'
2019-02-10 10:45:49 +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 " ;
$out .= $langs -> trans ( 'SelectMailModel' ) . ': <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.
if ( $user -> admin ) $out .= info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFrom " , $langs -> transnoentitiesnoconv ( 'Setup' ) . ' - ' . $langs -> transnoentitiesnoconv ( 'EMails' )), 1 );
$out .= ' ' ;
$out .= '<input class="button" type="submit" value="' . $langs -> trans ( 'Apply' ) . '" name="modelselected" disabled="disabled" id="modelselected">' ;
$out .= ' ' ;
$out .= '</div>' ;
2017-10-16 08:47:05 +02:00
}
2019-12-03 11:17:29 +01:00
$out .= '<table class="tableforemailform boxtablenotop" width="100%">' . " \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 = '' ;
if ( is_array ( $this -> substit ) && count ( $this -> substit )) $helpforsubstitution .= $langs -> trans ( 'AvailableVariables' ) . ' :<br>' . " \n " ;
foreach ( $this -> substit as $key => $val )
2018-04-06 16:16:08 +02:00
{
2019-12-03 11:17:29 +01:00
$helpforsubstitution .= $key . ' -> ' . $langs -> trans ( dol_string_nohtmltag ( $val )) . '<br>' ;
2018-04-06 16:16:08 +02:00
}
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withsubstit )) // Unset or set ->withsubstit=0 to disable this.
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
$out .= '<tr><td colspan="2" class="right">' ;
2017-10-16 08:47:05 +02:00
//$out.='<div class="floatright">';
2019-12-03 11:17: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
$out .= " </td></tr> \n " ;
2017-10-16 08:47:05 +02:00
//$out.='</div>';
}
2017-11-25 18:52:47 +01:00
/* var_dump ( ! empty ( $this -> withfromreadonly ));
var_dump ( $this -> withfrom );
var_dump ( $this -> fromtype );
var_dump ( $this -> fromname ); */
2017-10-16 08:47:05 +02:00
// From
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withfrom ))
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withfromreadonly ))
2017-10-16 08:47:05 +02:00
{
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 )
2017-11-25 19:16:15 +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 ;
2017-10-16 08:47:05 +02:00
if ( $this -> frommail )
{
2019-12-03 11:17:29 +01:00
$out .= ' <' . $this -> frommail . '>' ;
2017-10-16 08:47:05 +02:00
}
else
{
if ( $this -> fromtype )
{
$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
if ( empty ( $user -> email ))
{
$langs -> load ( 'errors' );
2019-12-03 11:17:29 +01:00
$liste [ 'user' ] = $user -> getFullName ( $langs ) . ' <' . $langs -> trans ( 'ErrorNoMailDefinedForThisUser' ) . '>' ;
2017-10-16 08:47:05 +02:00
}
else
{
2019-12-03 11:17:29 +01:00
$liste [ 'user' ] = $user -> getFullName ( $langs ) . ' <' . $user -> email . '>' ;
2017-10-16 08:47:05 +02:00
}
// Add also company main email
2019-12-03 11:17:29 +01:00
$liste [ 'company' ] = $conf -> global -> MAIN_INFO_SOCIETE_NOM . ' <' . $conf -> global -> MAIN_INFO_SOCIETE_MAIL . '>' ;
2017-10-16 08:47:05 +02:00
// Add also email aliases if there is some
2019-12-03 11:17:29 +01:00
$listaliases = array ( 'user_aliases' => $user -> email_aliases , 'global_aliases' => $conf -> global -> MAIN_INFO_SOCIETE_MAIL_ALIASES );
2017-10-16 08:47:05 +02:00
2017-11-25 19:23:27 +01:00
// Also add robot email
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> fromalsorobot ))
2017-11-25 19:23:27 +01:00
{
2019-12-03 11:17:29 +01:00
if ( ! empty ( $conf -> global -> MAIN_MAIL_EMAIL_FROM ) && $conf -> global -> MAIN_MAIL_EMAIL_FROM != $conf -> global -> MAIN_INFO_SOCIETE_MAIL )
2017-11-25 19:23:27 +01:00
{
$liste [ 'robot' ] = $conf -> global -> MAIN_MAIL_EMAIL_FROM ;
if ( $this -> frommail )
{
$liste [ 'robot' ] .= ' <' . $conf -> global -> MAIN_MAIL_EMAIL_FROM . '>' ;
}
}
}
2017-10-16 08:47:05 +02:00
// Add also email aliases from the c_email_senderprofile table
2020-01-20 18:38:53 +01:00
$sql = 'SELECT rowid, label, email FROM ' . MAIN_DB_PREFIX . 'c_email_senderprofile' ;
$sql .= ' WHERE active = 1 AND (private = 0 OR private = ' . $user -> id . ')' ;
$sql .= ' ORDER BY position' ;
2017-10-16 08:47:05 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$num = $this -> db -> num_rows ( $resql );
2019-12-03 11:17:29 +01:00
$i = 0 ;
while ( $i < $num )
2017-10-16 08:47:05 +02:00
{
$obj = $this -> db -> fetch_object ( $resql );
if ( $obj )
{
$listaliases [ 'senderprofile_' . $obj -> rowid ] = $obj -> label . ' <' . $obj -> email . '>' ;
}
$i ++ ;
}
}
else dol_print_error ( $this -> db );
2019-12-03 11:17:29 +01:00
foreach ( $listaliases as $typealias => $listalias )
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
$posalias = 0 ;
$listaliasarray = explode ( ',' , $listalias );
2017-10-16 08:47:05 +02:00
foreach ( $listaliasarray as $listaliasval )
{
$posalias ++ ;
2019-12-03 11:17:29 +01:00
$listaliasval = trim ( $listaliasval );
2017-10-16 08:47:05 +02:00
if ( $listaliasval )
{
2019-12-03 11:17:29 +01:00
$listaliasval = preg_replace ( '/</' , '<' , $listaliasval );
$listaliasval = preg_replace ( '/>/' , '>' , $listaliasval );
if ( ! preg_match ( '/</' , $listaliasval )) $listaliasval = '<' . $listaliasval . '>' ;
$liste [ $typealias . '_' . $posalias ] = $listaliasval ;
2017-10-16 08:47:05 +02:00
}
}
}
2017-12-10 02:01:36 +01:00
// Set the default "From"
2019-12-03 11:17:29 +01:00
$defaultfrom = '' ;
$reshook = $hookmanager -> executeHooks ( 'getDefaultFromEmail' , $parameters , $this );
2017-12-10 02:01:36 +01:00
if ( empty ( $reshook ))
{
$defaultfrom = $this -> fromtype ;
}
2019-12-03 11:17:29 +01:00
if ( ! empty ( $hookmanager -> resArray [ 'defaultfrom' ])) $defaultfrom = $hookmanager -> resArray [ 'defaultfrom' ];
2017-12-10 02:01:36 +01:00
2017-11-25 18:52:47 +01:00
// Using combo here make the '<email>' no more visible on list.
2017-12-10 02:01:36 +01:00
//$out.= ' '.$form->selectarray('fromtype', $liste, $this->fromtype, 0, 0, 0, '', 0, 0, 0, '', 'fromforsendingprofile maxwidth200onsmartphone', 1, '', $disablebademails);
2019-12-03 11:17:29 +01:00
$out .= ' ' . $form -> selectarray ( 'fromtype' , $liste , $defaultfrom , 0 , 0 , 0 , '' , 0 , 0 , 0 , '' , 'fromforsendingprofile maxwidth200onsmartphone' , 0 , '' , $disablebademails );
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
}
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
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withto ) || is_array ( $this -> withto ))
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
$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>' ;
2017-10-16 08:47:05 +02:00
if ( $this -> withtoreadonly )
{
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> toname ) && ! empty ( $this -> tomail ))
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
$out .= '<input type="hidden" id="toname" name="toname" value="' . $this -> toname . '" />' ;
$out .= '<input type="hidden" id="tomail" name="tomail" value="' . $this -> tomail . '" />' ;
2017-10-16 08:47:05 +02:00
if ( $this -> totype == 'thirdparty' )
{
2019-12-03 11:17:29 +01:00
$soc = new Societe ( $this -> db );
2017-10-16 08:47:05 +02:00
$soc -> fetch ( $this -> toid );
2019-12-03 11:17:29 +01:00
$out .= $soc -> getNomUrl ( 1 );
2017-10-16 08:47:05 +02:00
}
2019-01-27 10:49:34 +01:00
elseif ( $this -> totype == 'contact' )
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
$contact = new Contact ( $this -> db );
2017-10-16 08:47:05 +02:00
$contact -> fetch ( $this -> toid );
2019-12-03 11:17:29 +01:00
$out .= $contact -> getNomUrl ( 1 );
2017-10-16 08:47:05 +02:00
}
else
{
2019-12-03 11:17:29 +01:00
$out .= $this -> toname ;
2017-10-16 08:47:05 +02:00
}
2019-12-03 11:17:29 +01:00
$out .= ' <' . $this -> tomail . '>' ;
2017-10-16 08:47:05 +02:00
if ( $this -> withtofree )
{
2019-12-03 11:17:29 +01:00
$out .= '<br>' . $langs -> trans ( " and " ) . ' <input class="minwidth200" id="sendto" name="sendto" value="' . ( ! is_array ( $this -> withto ) && ! is_numeric ( $this -> withto ) ? ( isset ( $_REQUEST [ " sendto " ]) ? $_REQUEST [ " sendto " ] : $this -> withto ) : " " ) . '" />' ;
2017-10-16 08:47:05 +02:00
}
}
else
{
// Note withto may be a text like 'AllRecipientSelected'
2019-12-03 11:17:29 +01:00
$out .= ( ! is_array ( $this -> withto ) && ! is_numeric ( $this -> withto )) ? $this -> withto : " " ;
2017-10-16 08:47:05 +02:00
}
}
else
{
2020-02-08 15:59:08 +01:00
// The free input of email
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withtofree ))
2017-10-16 08:47:05 +02:00
{
2020-02-08 15:59:08 +01:00
$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 ) ? ( isset ( $_REQUEST [ " sendto " ]) ? $_REQUEST [ " sendto " ] : $this -> withto ) : " " )) . '" />' ;
2017-10-16 08:47:05 +02:00
}
2020-02-08 15:59:08 +01:00
// The select combo
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withto ) && is_array ( $this -> withto ))
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withtofree )) $out .= " " . $langs -> trans ( " and " ) . " / " . $langs -> trans ( " or " ) . " " ;
2017-10-16 08:47:05 +02:00
// multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
$tmparray = $this -> withto ;
2019-12-03 11:17:29 +01:00
foreach ( $tmparray as $key => $val )
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
$tmparray [ $key ] = dol_htmlentities ( $tmparray [ $key ], null , 'UTF-8' , true );
2017-10-16 08:47:05 +02:00
}
2019-12-03 11:17:29 +01:00
$withtoselected = GETPOST ( " receiver " , 'none' ); // Array of selected value
2019-01-27 11:55:16 +01:00
if ( empty ( $withtoselected ) && count ( $tmparray ) == 1 && GETPOST ( 'action' , 'aZ09' ) == 'presend' )
2017-10-16 08:47:05 +02:00
{
$withtoselected = array_keys ( $tmparray );
}
2019-12-03 11:17:29 +01:00
$out .= $form -> multiselectarray ( " receiver " , $tmparray , $withtoselected , null , null , 'inline-block minwidth500' , null , " " );
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
}
2018-03-21 11:48:30 +01:00
// To User
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withtouser ) && is_array ( $this -> withtouser ) && ! empty ( $conf -> global -> MAIN_MAIL_ENABLED_USER_DEST_SELECT ))
2018-03-21 11:48:30 +01:00
{
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 ;
2019-12-03 11:17:29 +01:00
foreach ( $tmparray as $key => $val )
2018-03-21 11:48:30 +01:00
{
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
}
2019-12-03 11:17:29 +01:00
$withtoselected = GETPOST ( " receiveruser " , 'none' ); // Array of selected value
2019-01-27 11:55:16 +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
}
2018-12-27 05:18:16 +01:00
// With option one email per recipient
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withoptiononeemailperrecipient ))
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
$out .= '<tr><td class="minwidth200">' ;
$out .= $langs -> trans ( " GroupEmails " );
$out .= '</td><td>' ;
$out .= ' <input type="checkbox" name="oneemailperrecipient"' . ( $this -> withoptiononeemailperrecipient > 0 ? ' checked="checked"' : '' ) . '> ' ;
$out .= $langs -> trans ( " OneEmailPerRecipient " );
$out .= '<span class="hideonsmartphone">' ;
$out .= ' - ' ;
$out .= $langs -> trans ( " WarningIfYouCheckOneRecipientPerEmail " );
$out .= '</span>' ;
$out .= '</td></tr>' ;
2017-10-16 08:47:05 +02:00
}
// CC
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withtocc ) || is_array ( $this -> withtocc ))
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
$out .= '<tr><td>' ;
$out .= $form -> textwithpicto ( $langs -> trans ( " MailCC " ), $langs -> trans ( " YouCanUseCommaSeparatorForSeveralRecipients " ));
$out .= '</td><td>' ;
2017-10-16 08:47:05 +02:00
if ( $this -> withtoccreadonly )
{
2019-12-03 11:17:29 +01:00
$out .= ( ! is_array ( $this -> withtocc ) && ! is_numeric ( $this -> withtocc )) ? $this -> withtocc : " " ;
2017-10-16 08:47:05 +02:00
}
else
{
2019-12-03 11:17:29 +01:00
$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 ))
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
$out .= " " . $langs -> trans ( " and " ) . " / " . $langs -> trans ( " or " ) . " " ;
2017-10-16 08:47:05 +02:00
// multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
$tmparray = $this -> withtocc ;
2019-12-03 11:17:29 +01:00
foreach ( $tmparray as $key => $val )
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
$tmparray [ $key ] = dol_htmlentities ( $tmparray [ $key ], null , 'UTF-8' , true );
2017-10-16 08:47:05 +02:00
}
2019-12-03 11:17:29 +01:00
$withtoccselected = GETPOST ( " receivercc " ); // Array of selected value
$out .= $form -> multiselectarray ( " receivercc " , $tmparray , $withtoccselected , null , null , 'inline-block minwidth500' , null , " " );
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
}
2018-03-21 11:48:30 +01:00
// To User cc
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withtoccuser ) && is_array ( $this -> withtoccuser ) && ! empty ( $conf -> global -> MAIN_MAIL_ENABLED_USER_DEST_SELECT ))
2018-03-21 11:48:30 +01:00
{
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 ;
2019-12-03 11:17:29 +01:00
foreach ( $tmparray as $key => $val )
2018-03-21 11:48:30 +01:00
{
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
}
2019-12-03 11:17:29 +01:00
$withtoselected = GETPOST ( " receiverccuser " , 'none' ); // Array of selected value
2019-01-27 11:55:16 +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
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withreplyto ))
2017-10-16 08:47:05 +02:00
{
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
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withdeliveryreceipt )) {
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
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withfile ))
2017-10-16 08:47:05 +02:00
{
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
2018-10-29 02:27:51 +01:00
if ( $this -> withmaindocfile ) // withmaindocfile is set to 1 or -1 to show the checkbox (-1 = checked or 1 = not checked)
2018-10-29 02:11:33 +01:00
{
2018-10-29 02:27:51 +01:00
if ( GETPOSTISSET ( 'sendmail' ))
{
$this -> withmaindocfile = ( GETPOST ( 'addmaindocfile' , 'alpha' ) ? - 1 : 1 );
}
// If a template was selected, we use setup of template to define if join file checkbox is selected or not.
elseif ( is_object ( $arraydefaultmessage ) && $arraydefaultmessage -> id > 0 )
{
$this -> withmaindocfile = ( $arraydefaultmessage -> joinfiles ? - 1 : 1 );
}
2018-10-29 00:55:55 +01:00
}
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withmaindocfile ))
2017-10-16 08:47:05 +02:00
{
if ( $this -> withmaindocfile == 1 )
{
2019-12-03 11:17:29 +01:00
$out .= '<input type="checkbox" name="addmaindocfile" value="1" />' ;
2017-10-16 08:47:05 +02:00
}
if ( $this -> withmaindocfile == - 1 )
{
2019-12-03 11:17:29 +01:00
$out .= '<input type="checkbox" name="addmaindocfile" value="1" checked="checked" />' ;
2017-10-16 08:47:05 +02:00
}
2019-12-03 11:17:29 +01:00
$out .= ' ' . $langs -> trans ( " JoinMainDoc " ) . '.<br>' ;
2017-09-16 18:24:58 +02:00
}
2014-09-17 01:12:59 +02:00
2017-10-16 08:47:05 +02: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 " ;
$out .= '<script type="text/javascript" language="javascript">' ;
$out .= 'jQuery(document).ready(function () {' ;
$out .= ' jQuery(".removedfile").click(function() {' ;
$out .= ' jQuery(".removedfilehidden").val(jQuery(this).val());' ;
$out .= ' });' ;
$out .= '})' ;
$out .= '</script>' . " \n " ;
2017-10-16 08:47:05 +02:00
if ( count ( $listofpaths ))
{
2019-12-03 11:17:29 +01:00
foreach ( $listofpaths as $key => $val )
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
$out .= '<div id="attachfile_' . $key . '">' ;
$out .= img_mime ( $listofnames [ $key ]) . ' ' . $listofnames [ $key ];
if ( ! $this -> withfilereadonly )
2017-10-16 08:47:05 +02:00
{
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
}
}
2019-01-27 10:49:34 +01:00
elseif ( empty ( $this -> withmaindocfile )) // Do not show message if we asked to show the checkbox
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
$out .= $langs -> trans ( " NoAttachedFiles " ) . '<br>' ;
2017-10-16 08:47:05 +02:00
}
if ( $this -> withfile == 2 ) // Can add other files
{
2019-12-03 11:17:29 +01:00
if ( ! empty ( $conf -> global -> FROM_MAIL_USE_INPUT_FILE_MULTIPLE )) $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 " ) . '" />' ;
$out .= ' ' ;
$out .= '<input class="button" type="submit" id="' . $addfileaction . '" name="' . $addfileaction . '" value="' . $langs -> trans ( " MailingAddFile " ) . '" />' ;
2017-10-16 08:47:05 +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
2019-12-03 11:17:29 +01:00
if ( ! empty ( $this -> withbody ))
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
$defaultmessage = GETPOST ( 'message' , 'none' );
if ( ! GETPOST ( 'modelselected' , 'alpha' ) || GETPOST ( 'modelmailselected' ) != '-1' )
2017-09-16 18:24:58 +02:00
{
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
2019-12-03 11:17:29 +01:00
$paymenturl = '' ; $validpaymentmethod = array ();
2017-12-17 22:03:42 +01:00
if ( empty ( $this -> substit [ '__REF__' ]))
2017-10-16 08:47:05 +02:00
{
2019-12-03 11:17:29 +01:00
$paymenturl = '' ;
2017-09-16 18:24:58 +02:00
}
2017-12-17 22:03:42 +01:00
else
{
// 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' ;
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
$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
if ( count ( $validpaymentmethod ) > 0 && $paymenturl )
2018-06-27 11:34:40 +02:00
{
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 ;
2018-06-27 11:34:40 +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-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 ;
2017-10-16 08:47:05 +02: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 ++ ;
}
if ( strpos ( $defaultmessage , '__ONLINE_PAYMENT_TEXT_AND_URL__' ) !== false && dol_textishtml ( $this -> substit [ '__ONLINE_PAYMENT_TEXT_AND_URL__' ])) {
$atleastonecomponentishtml ++ ;
}
if ( dol_textishtml ( $defaultmessage )) {
$atleastonecomponentishtml ++ ;
}
if ( $atleastonecomponentishtml ) {
if ( ! dol_textishtml ( $this -> substit [ '__USER_SIGNATURE__' ])) {
$this -> substit [ '__USER_SIGNATURE__' ] = dol_nl2br ( $this -> substit [ '__USER_SIGNATURE__' ]);
}
if ( ! dol_textishtml ( $this -> substit [ '__ONLINE_PAYMENT_TEXT_AND_URL__' ])) {
$this -> substit [ '__ONLINE_PAYMENT_TEXT_AND_URL__' ] = dol_nl2br ( $this -> substit [ '__ONLINE_PAYMENT_TEXT_AND_URL__' ]);
}
if ( ! dol_textishtml ( $defaultmessage )) {
$defaultmessage = dol_nl2br ( $defaultmessage );
}
2013-08-02 10:24:09 +02:00
}
2014-02-19 15:33:04 +01:00
2020-05-28 11:41:48 +02:00
if ( GETPOSTISSET ( " message " ) && ! $_POST [ 'modelselected' ]) $defaultmessage = $_POST [ " message " ];
2014-04-30 15:17:39 +02: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>' ;
2019-12-12 11:11:08 +01:00
$out .= '<td class="tdtop">' ;
2019-12-03 11:17:29 +01:00
$out .= $form -> textwithpicto ( $langs -> trans ( 'MailText' ), $helpforsubstitution , 1 , 'help' , '' , 0 , 2 , 'substittooltipfrombody' );
$out .= '</td>' ;
$out .= '<td>' ;
2017-10-13 13:28:26 +02: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 . '" />' ;
2017-10-13 13:28:26 +02:00
}
else
{
2019-12-03 11:17:29 +01:00
if ( ! isset ( $this -> ckeditortoolbar )) $this -> ckeditortoolbar = 'dolibarr_notes' ;
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' ;
if ( $this -> withfckeditor == - 1 )
{
2019-12-03 11:17:29 +01:00
if ( ! empty ( $conf -> global -> FCKEDITOR_ENABLE_MAIL )) $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
2017-10-13 13:28:26 +02:00
if ( $this -> withform == 1 || $this -> withform == - 1 )
{
2019-12-03 11:17:29 +01:00
$out .= '<br><div class="center">' ;
$out .= '<input class="button" type="submit" 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
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 .= ' />' ;
2017-10-13 13:28:26 +02:00
if ( $this -> withcancel )
{
2019-12-03 11:17:29 +01:00
$out .= ' ' ;
$out .= '<input class="button" 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
2019-12-03 11:17:29 +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
2019-12-03 11:17:29 +01:00
if ( ! empty ( $conf -> global -> MAIN_MAILFORM_DISABLE_ENTERKEY ))
2017-10-13 13:28:26 +02:00
{
2019-12-03 11:17:29 +01:00
$out .= '<script type="text/javascript" language="javascript">' ;
$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
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 {
2019-12-03 11:17:29 +01:00
$out .= '<input class="minwidth200" id="sendtoccc" name="sendtoccc" value="' . ( GETPOST ( " sendtoccc " , " alpha " ) ? GETPOST ( " sendtoccc " , " alpha " ) : (( ! is_array ( $this -> withtoccc ) && ! is_numeric ( $this -> withtoccc )) ? $this -> withtoccc : '' )) . '" />' ;
if ( ! empty ( $this -> withtoccc ) && is_array ( $this -> withtoccc )) {
$out .= " " . $langs -> trans ( " and " ) . " / " . $langs -> trans ( " or " ) . " " ;
2018-11-19 21:19:39 +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 -> withtoccc ;
foreach ( $tmparray as $key => $val ) {
2019-12-03 11:17:29 +01:00
$tmparray [ $key ] = dol_htmlentities ( $tmparray [ $key ], null , 'UTF-8' , true );
2018-11-19 21:19:39 +01:00
}
2019-12-03 11:17:29 +01:00
$withtocccselected = GETPOST ( " receiverccc " ); // Array of selected value
$out .= $form -> multiselectarray ( " receiverccc " , $tmparray , $withtocccselected , null , null , null , null , " 90% " );
2018-11-19 21:19:39 +01:00
}
}
2019-12-03 11:17:29 +01:00
$showinfobcc = '' ;
if ( ! empty ( $conf -> global -> MAIN_MAIL_AUTOCOPY_PROPOSAL_TO ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'propal_send' ) $showinfobcc = $conf -> global -> MAIN_MAIL_AUTOCOPY_PROPOSAL_TO ;
if ( ! empty ( $conf -> global -> MAIN_MAIL_AUTOCOPY_ORDER_TO ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'order_send' ) $showinfobcc = $conf -> global -> MAIN_MAIL_AUTOCOPY_ORDER_TO ;
if ( ! empty ( $conf -> global -> MAIN_MAIL_AUTOCOPY_INVOICE_TO ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'facture_send' ) $showinfobcc = $conf -> global -> MAIN_MAIL_AUTOCOPY_INVOICE_TO ;
if ( ! empty ( $conf -> global -> MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'supplier_proposal_send' ) $showinfobcc = $conf -> global -> MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO ;
if ( ! empty ( $conf -> global -> MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'order_supplier_send' ) $showinfobcc = $conf -> global -> MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO ;
if ( ! empty ( $conf -> global -> MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'invoice_supplier_send' ) $showinfobcc = $conf -> global -> MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO ;
if ( ! empty ( $conf -> global -> MAIN_MAIL_AUTOCOPY_PROJECT_TO ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'project' ) $showinfobcc = $conf -> global -> MAIN_MAIL_AUTOCOPY_PROJECT_TO ;
if ( $showinfobcc ) $out .= ' + ' . $showinfobcc ;
$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;
2019-12-03 11:17:29 +01:00
$errorstomail = ( ! empty ( $conf -> global -> MAIN_MAIL_ERRORS_TO ) ? $conf -> global -> MAIN_MAIL_ERRORS_TO : $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>' ;
$out .= '<input size="30" id="errorstomail" name="errorstomail" value="' . $errorstomail . '" />' ;
$out .= " </td></tr> \n " ;
2018-11-19 21:19:39 +01:00
}
return $out ;
}
/**
* get Html For Asking for Deliveriy Receipt
*
* @ return string html
*/
public function getHtmlForDeliveryreceipt ()
{
global $conf , $langs , $form ;
$out = '<tr><td>' . $langs -> trans ( " DeliveryReceipt " ) . '</td><td>' ;
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 ;
if ( ! empty ( $conf -> global -> MAIL_FORCE_DELIVERY_RECEIPT_PROPAL ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'propal_send' ) $defaultvaluefordeliveryreceipt = 1 ;
if ( ! empty ( $conf -> global -> MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_PROPOSAL ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'supplier_proposal_send' ) $defaultvaluefordeliveryreceipt = 1 ;
if ( ! empty ( $conf -> global -> MAIL_FORCE_DELIVERY_RECEIPT_ORDER ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'order_send' ) $defaultvaluefordeliveryreceipt = 1 ;
if ( ! empty ( $conf -> global -> MAIL_FORCE_DELIVERY_RECEIPT_INVOICE ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'facture_send' ) $defaultvaluefordeliveryreceipt = 1 ;
$out .= $form -> selectyesno ( 'deliveryreceipt' , ( isset ( $_POST [ " deliveryreceipt " ]) ? $_POST [ " deliveryreceipt " ] : $defaultvaluefordeliveryreceipt ), 1 );
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
2019-01-27 11:55:16 +01:00
$defaulttopic = GETPOST ( 'subject' , 'none' );
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 {
2019-12-03 11:17:29 +01:00
$out .= '<input type="text" class="quatrevingtpercent" id="subject" name="subject" value="' . (( isset ( $_POST [ " subject " ]) && ! $_POST [ 'modelselected' ]) ? $_POST [ " 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
*
2019-02-27 20:45:07 +01:00
* @ param DoliDB $db Database handler
* @ param string $type_template Get message for model / type = $type_template , type = 'all' also included .
* @ param string $user Get template public or limited to this user
* @ param Translate $outputlangs Output lang object
* @ param int $id Id of template to find , 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 )
* @ param int $active 1 = Only active template , 0 = Only disabled , - 1 = All
* @ param string $label Label of template
* @ return ModelMail | integer One instance of ModelMail or - 1 if error
2014-09-17 01:12:59 +02:00
*/
2019-01-27 15:20:16 +01:00
public function getEMailTemplate ( $db , $type_template , $user , $outputlangs , $id = 0 , $active = 1 , $label = '' )
2014-09-17 01:12:59 +02:00
{
2019-02-27 20:45:07 +01:00
$ret = new ModelMail ();
2014-09-17 01:12:59 +02:00
2019-02-27 20:45:07 +01:00
if ( $id == - 2 && empty ( $label )) {
2018-03-16 19:03:16 +01:00
$this -> error = 'LabelIsMandatoryWhenIdIs-2' ;
return - 1 ;
}
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 ]);
if ( $languagetosearchmain == $languagetosearch ) $languagetosearchmain = '' ;
2018-03-21 16:40:09 +01:00
$sql = " SELECT rowid, label, topic, joinfiles, content, content_lines, lang " ;
2019-12-03 11:17:29 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . 'c_email_templates' ;
$sql .= " WHERE (type_template=' " . $db -> escape ( $type_template ) . " ' OR type_template='all') " ;
$sql .= " AND entity IN ( " . getEntity ( 'c_email_templates' ) . " ) " ;
$sql .= " AND (private = 0 OR fk_user = " . $user -> id . " ) " ; // Get all public or private owned
if ( $active >= 0 ) $sql .= " AND active = " . $active ;
if ( $label ) $sql .= " AND label =' " . $db -> escape ( $label ) . " ' " ;
if ( ! ( $id > 0 ) && $languagetosearch ) $sql .= " AND (lang = ' " . $db -> escape ( $languagetosearch ) . " ' " . ( $languagetosearchmain ? " OR lang = ' " . $db -> escape ( $languagetosearchmain ) . " ' " : " " ) . " OR lang IS NULL OR lang = '') " ;
if ( $id > 0 ) $sql .= " AND rowid= " . $id ;
if ( $id == - 1 ) $sql .= " AND position=0 " ;
if ( $languagetosearch ) $sql .= $db -> order ( " position,lang,label " , " ASC,DESC,ASC " ); // We want line with lang set first, then with lang null or ''
else $sql .= $db -> order ( " position,lang,label " , " ASC,ASC,ASC " ); // If no language provided, we give priority to lang not defined
$sql .= $db -> plimit ( 1 );
2014-10-20 11:35:34 +02:00
//print $sql;
2014-09-17 01:12:59 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
2017-12-17 23:42:50 +01:00
// Get first found
$obj = $db -> fetch_object ( $resql );
if ( $obj ) {
2018-03-21 16:40:09 +01:00
$ret -> id = $obj -> rowid ;
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 ;
2014-09-17 01:12:59 +02:00
}
2019-12-03 11:17:29 +01:00
elseif ( $id == - 2 ) {
2018-03-16 19:03:16 +01:00
// Not found with the provided label
return - 1 ;
}
else { // If there is no template at all
2019-12-03 11:17:29 +01:00
$defaultmessage = '' ;
if ( $type_template == 'body' ) { $defaultmessage = $this -> withbody ; } // Special case to use this->withbody as content
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 == 'thirdparty' ) { $defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentThirdparty " ); }
elseif ( $type_template == 'user' ) { $defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentUser " ); }
elseif ( ! empty ( $type_template )) { $defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContent " . ucfirst ( $type_template )); }
2018-05-22 20:17:31 +02:00
2017-12-17 23:42:50 +01:00
$ret -> label = 'default' ;
$ret -> lang = $outputlangs -> defaultlang ;
$ret -> topic = '' ;
$ret -> joinfiles = 1 ;
$ret -> content = $defaultmessage ;
2019-12-03 11:17:29 +01:00
$ret -> content_lines = '' ;
2014-09-17 01:12:59 +02:00
}
$db -> free ( $resql );
return $ret ;
}
else
{
dol_print_error ( $db );
return - 1 ;
}
}
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
* @ param string $user Use template public or limited to this user
* @ param Translate $outputlangs Output lang object
* @ return int < 0 if KO ,
*/
public function isEMailTemplate ( $type_template , $user , $outputlangs )
{
2019-12-03 11:17:29 +01:00
$ret = array ();
2015-05-04 22:02:54 +02:00
2015-04-18 11:06:53 +02:00
$sql = " SELECT label, topic, content, lang " ;
2019-12-03 11:17:29 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . 'c_email_templates' ;
$sql .= " WHERE type_template=' " . $this -> db -> escape ( $type_template ) . " ' " ;
$sql .= " AND entity IN ( " . getEntity ( 'c_email_templates' ) . " ) " ;
$sql .= " AND (fk_user is NULL or fk_user = 0 or fk_user = " . $user -> id . " ) " ;
if ( is_object ( $outputlangs )) $sql .= " AND (lang = ' " . $outputlangs -> defaultlang . " ' OR lang IS NULL OR lang = '') " ;
$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 );
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 ;
}
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
*
* @ param string $type_template Get message for key module
* @ param string $user Use template public or limited to this user
* @ param Translate $outputlangs Output lang object
2016-06-24 13:08:34 +02:00
* @ param int $active 1 = Only active template , 0 = Only disabled , - 1 = All
* @ return int < 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
{
2019-12-03 11:17:29 +01:00
$ret = array ();
2015-05-04 22:02:54 +02:00
2017-09-08 14:40:39 +02:00
$sql = " SELECT rowid, label, topic, content, content_lines, lang, fk_user, private, position " ;
2019-12-03 11:17:29 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . 'c_email_templates' ;
$sql .= " WHERE type_template IN (' " . $this -> db -> escape ( $type_template ) . " ', 'all') " ;
$sql .= " AND entity IN ( " . getEntity ( 'c_email_templates' ) . " ) " ;
$sql .= " AND (private = 0 OR fk_user = " . $user -> id . " ) " ; // See all public templates or templates I own.
if ( $active >= 0 ) $sql .= " AND active = " . $active ;
2017-09-08 14:40:39 +02:00
//if (is_object($outputlangs)) $sql.= " AND (lang = '".$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 );
if ( $resql )
{
2019-12-03 11:17:29 +01:00
$num = $this -> db -> num_rows ( $resql );
$this -> lines_model = array ();
2015-05-04 22:02:54 +02:00
while ( $obj = $this -> db -> fetch_object ( $resql ))
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 ;
}
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
/**
2017-09-22 14:34:31 +02:00
* Set substit 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
{
2017-02-12 18:13:49 +01:00
global $conf , $user ;
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
if ( is_array ( $object -> lines ))
{
foreach ( $object -> lines as $line )
{
$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__
if ( ! empty ( $line -> fk_product ))
{
2019-12-03 11:17:29 +01:00
if ( ! is_object ( $extrafields )) $extrafields = new ExtraFields ( $this -> db );
2018-04-13 23:11:19 +02:00
$extrafields -> fetch_name_optionals_label ( 'product' , true );
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 ();
2018-04-13 23:11:19 +02:00
if ( is_array ( $extrafields -> attributes [ $object -> table_element ][ 'label' ]) && count ( $extrafields -> attributes [ $object -> table_element ][ 'label' ]) > 0 )
2018-04-13 16:18:33 +02:00
{
foreach ( $extrafields -> attributes [ $product -> table_element ][ 'label' ] as $key => $label ) {
2019-12-03 11:17:29 +01:00
$substit_line [ '__PRODUCT_EXTRAFIELD_' . strtoupper ( $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 ();
2017-05-04 12:35:45 +02:00
if ( $mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines' )
2016-03-05 12:20:58 +01:00
{
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 );
2017-02-12 18:13:49 +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
}
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
2016-03-05 12:20:58 +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 );
2016-03-05 12:20:58 +01:00
// For mass emailing, we have different keys
2017-09-22 14:34:31 +02:00
$tmparray [ '__ID__' ] = 'IdRecord' ;
$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-10-13 10:35:21 +02:00
$tmparray [ '__USER_SIGNATURE__' ] = 'TagSignature' ;
2017-09-22 14:34:31 +02:00
$tmparray [ '__CHECK_READ__' ] = 'TagCheckMail' ;
$tmparray [ '__UNSUBSCRIBE__' ] = 'TagUnsubscribe' ;
2016-03-05 12:20:58 +01:00
//,'__PERSONALIZED__' => 'Personalized' // Hidden because not used yet in mass emailing
2017-09-15 13:43:16 +02:00
$onlinepaymentenabled = 0 ;
2019-12-03 11:17:29 +01:00
if ( ! empty ( $conf -> paypal -> enabled )) $onlinepaymentenabled ++ ;
if ( ! empty ( $conf -> paybox -> enabled )) $onlinepaymentenabled ++ ;
if ( ! empty ( $conf -> stripe -> enabled )) $onlinepaymentenabled ++ ;
if ( $onlinepaymentenabled && ! empty ( $conf -> global -> PAYMENT_SECURITY_TOKEN ))
2017-09-15 13:43:16 +02:00
{
2019-12-03 11:17:29 +01:00
$tmparray [ '__SECUREKEYPAYMENT__' ] = $conf -> global -> PAYMENT_SECURITY_TOKEN ;
if ( ! empty ( $conf -> global -> PAYMENT_SECURITY_TOKEN_UNIQUE ))
2017-09-15 13:43:16 +02:00
{
2019-12-03 11:17:29 +01:00
if ( $conf -> adherent -> enabled ) $tmparray [ '__SECUREKEYPAYMENT_MEMBER__' ] = 'SecureKeyPAYMENTUniquePerMember' ;
if ( $conf -> facture -> enabled ) $tmparray [ '__SECUREKEYPAYMENT_INVOICE__' ] = 'SecureKeyPAYMENTUniquePerInvoice' ;
if ( $conf -> commande -> enabled ) $tmparray [ '__SECUREKEYPAYMENT_ORDER__' ] = 'SecureKeyPAYMENTUniquePerOrder' ;
if ( $conf -> contrat -> enabled ) $tmparray [ '__SECUREKEYPAYMENT_CONTRACTLINE__' ] = 'SecureKeyPAYMENTUniquePerContractLine' ;
2017-09-15 13:43:16 +02:00
}
}
else
{
/* 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__' ] = '' ;
*/
}
2016-03-05 12:20:58 +01:00
}
2017-06-01 01:53:55 +02:00
2019-12-03 11:17:29 +01:00
foreach ( $tmparray as $key => $val )
2017-05-04 12:35:45 +02:00
{
2019-12-03 11:17:29 +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
*/
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
/**
2018-09-01 14:06:58 +02:00
* @ var string Model mail label
2018-08-29 12:35:56 +02:00
*/
public $label ;
2015-04-18 11:06:53 +02:00
public $topic ;
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 ;
2010-05-03 10:43:32 +02:00
}