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 >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2011-07-07 17:54:01 +02:00
* Copyright ( C ) 2010 - 2011 Juanjo Menent < jmenent @ 2 byte . es >
2015-02-15 15:57:38 +01:00
* Copyright ( C ) 2015 Marcos García < marcosgdf @ gmail . com >
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
2011-08-01 01:45:11 +02:00
* along with this program . If not , see < http :// 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
*/
2012-08-22 23:11:24 +02: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
{
2011-06-29 12:23:32 +02:00
var $db ;
2014-02-24 16:50:36 +01:00
var $withform ; // 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
2011-06-29 12:23:32 +02:00
var $fromname ;
var $frommail ;
var $replytoname ;
var $replytomail ;
var $toname ;
var $tomail ;
2015-05-04 22:02:54 +02:00
var $trackid ;
2014-04-30 15:17:39 +02:00
2011-06-29 12:23:32 +02:00
var $withsubstit ; // Show substitution array
var $withfrom ;
2015-04-23 23:21:06 +02:00
/**
* @ var int
* @ deprecated Fill withto with array before calling method .
* @ see withto
*/
public $withtosocid ;
/**
* @ var int | int []
*/
public $withto ; // Show recipient emails
2013-09-23 14:35:22 +02:00
var $withtofree ; // Show free text for recipient emails
2011-06-29 12:23:32 +02:00
var $withtocc ;
2013-02-12 17:08:21 +01:00
var $withtoccc ;
2011-06-29 12:23:32 +02:00
var $withtopic ;
var $withfile ; // 0=No attaches files, 1=Show attached files, 2=Can add new attached files
var $withbody ;
var $withfromreadonly ;
var $withreplytoreadonly ;
var $withtoreadonly ;
var $withtoccreadonly ;
2014-04-23 14:41:58 +02:00
var $withtocccreadonly ;
var $withtopicreadonly ;
2011-06-29 12:23:32 +02:00
var $withfilereadonly ;
var $withdeliveryreceipt ;
var $withcancel ;
2012-07-13 10:15:47 +02:00
var $withfckeditor ;
2011-06-29 12:23:32 +02:00
var $substit = array ();
var $param = array ();
var $error ;
2015-04-18 11:06:53 +02:00
public $lines_model ;
2011-06-29 12:23:32 +02:00
/**
2012-01-27 15:17:36 +01:00
* Constructor
*
2012-03-19 17:18:11 +01:00
* @ param DoliDB $db Database handler
2011-06-29 12:23:32 +02:00
*/
2012-07-30 17:17:33 +02:00
function __construct ( $db )
2014-02-19 15:33:04 +01:00
{
2012-01-27 15:17:36 +01:00
$this -> db = $db ;
2011-06-29 12:23:32 +02: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 ;
$this -> withbody = 1 ;
$this -> withfromreadonly = 1 ;
$this -> withreplytoreadonly = 1 ;
$this -> withtoreadonly = 0 ;
$this -> withtoccreadonly = 0 ;
2014-04-23 14:41:58 +02:00
$this -> withtocccreadonly = 0 ;
2011-06-29 12:23:32 +02:00
$this -> witherrorstoreadonly = 0 ;
$this -> withtopicreadonly = 0 ;
$this -> withfilereadonly = 0 ;
$this -> withbodyreadonly = 0 ;
$this -> withdeliveryreceiptreadonly = 0 ;
2014-06-21 01:26:41 +02:00
$this -> withfckeditor =- 1 ; // -1 = Auto
2011-06-29 12:23:32 +02:00
return 1 ;
}
/**
2016-06-24 16:10:52 +02:00
* Clear list of attached files in send mail form ( also stored in session )
2012-03-16 00:34:41 +01:00
*
2012-01-27 15:17:36 +01:00
* @ return void
2011-06-29 12:23:32 +02:00
*/
function clear_attached_files ()
{
global $conf , $user ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2010-05-03 10:43:32 +02:00
2011-06-29 12:23:32 +02:00
// Set tmp user directory
$vardir = $conf -> user -> dir_output . " / " . $user -> id ;
2016-06-24 16:10:52 +02:00
$upload_dir = $vardir . '/temp/' ; // TODO Add $keytoavoidconflict in upload_dir path
2011-06-29 12:23:32 +02:00
if ( is_dir ( $upload_dir )) dol_delete_dir_recursive ( $upload_dir );
2016-06-24 16:10:52 +02:00
$keytoavoidconflict = empty ( $this -> trackid ) ? '' : '-' . $this -> trackid ; // this->trackid must be defined
unset ( $_SESSION [ " listofpaths " . $keytoavoidconflict ]);
unset ( $_SESSION [ " listofnames " . $keytoavoidconflict ]);
unset ( $_SESSION [ " listofmimes " . $keytoavoidconflict ]);
2011-06-29 12:23:32 +02:00
}
/**
* Add a file into the list of attached files ( stored in SECTION array )
*
2011-07-10 22:03:38 +02:00
* @ param string $path Full absolute path on filesystem of file , including file name
* @ param string $file Only filename
* @ param string $type Mime type
2012-01-27 15:17:36 +01:00
* @ return void
2011-06-29 12:23:32 +02:00
*/
function add_attached_files ( $path , $file , $type )
{
$listofpaths = array ();
$listofnames = array ();
$listofmimes = array ();
2016-06-24 16:10:52 +02:00
$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 ]);
2011-06-29 12:23:32 +02:00
if ( ! in_array ( $file , $listofnames ))
{
$listofpaths [] = $path ;
$listofnames [] = $file ;
$listofmimes [] = $type ;
2016-06-24 16:10:52 +02:00
$_SESSION [ " listofpaths " . $keytoavoidconflict ] = join ( ';' , $listofpaths );
$_SESSION [ " listofnames " . $keytoavoidconflict ] = join ( ';' , $listofnames );
$_SESSION [ " listofmimes " . $keytoavoidconflict ] = join ( ';' , $listofmimes );
2011-06-29 12:23:32 +02:00
}
}
/**
* Remove a file from the list of attached files ( stored in SECTION array )
*
2016-04-07 14:29:07 +02:00
* @ param string $keytodelete Key in file array ( 0 , 1 , 2 , ... )
2012-01-27 15:17:36 +01:00
* @ return void
2011-06-29 12:23:32 +02:00
*/
function remove_attached_files ( $keytodelete )
{
$listofpaths = array ();
$listofnames = array ();
$listofmimes = array ();
2016-06-24 16:10:52 +02:00
$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 ]);
2011-06-29 12:23:32 +02:00
if ( $keytodelete >= 0 )
{
unset ( $listofpaths [ $keytodelete ]);
unset ( $listofnames [ $keytodelete ]);
unset ( $listofmimes [ $keytodelete ]);
2016-06-24 16:10:52 +02:00
$_SESSION [ " listofpaths " . $keytoavoidconflict ] = join ( ';' , $listofpaths );
$_SESSION [ " listofnames " . $keytoavoidconflict ] = join ( ';' , $listofnames );
$_SESSION [ " listofmimes " . $keytoavoidconflict ] = join ( ';' , $listofmimes );
2011-06-29 12:23:32 +02:00
//var_dump($_SESSION['listofpaths']);
}
}
/**
* Return list of attached files ( stored in SECTION array )
*
* @ return array array ( 'paths' => , 'names' => , 'mimes' => )
*/
function get_attached_files ()
{
$listofpaths = array ();
$listofnames = array ();
$listofmimes = array ();
2016-06-24 16:10:52 +02:00
$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 ]);
2011-06-29 12:23:32 +02:00
return array ( 'paths' => $listofpaths , 'names' => $listofnames , 'mimes' => $listofmimes );
}
/**
* Show the form to input an email
2011-03-05 17:27:26 +01:00
* this -> withfile : 0 = No attaches files , 1 = Show attached files , 2 = Can add new attached files
2011-09-06 00:52:17 +02:00
*
2012-01-27 15:17:36 +01:00
* @ param string $addfileaction Name of action when posting file attachments
* @ param string $removefileaction Name of action when removing file attachments
* @ return void
2011-06-29 12:23:32 +02:00
*/
function show_form ( $addfileaction = 'addfile' , $removefileaction = 'removefile' )
{
print $this -> get_form ( $addfileaction , $removefileaction );
}
/**
* Get the form to input an email
2011-06-17 19:59:52 +02:00
* this -> withfile : 0 = No attaches files , 1 = Show attached files , 2 = Can add new attached files
2015-08-13 05:09:26 +02:00
* this -> param : Contains more parameteres like email templates info
2011-09-06 00:52:17 +02:00
*
2012-01-27 15:17:36 +01: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
2011-06-29 12:23:32 +02:00
*/
function get_form ( $addfileaction = 'addfile' , $removefileaction = 'removefile' )
{
2014-05-01 16:26:57 +02:00
global $conf , $langs , $user , $hookmanager , $form ;
2011-06-29 12:23:32 +02:00
2014-05-01 16:26:57 +02:00
if ( ! is_object ( $form )) $form = new Form ( $this -> db );
2014-06-21 01:26:41 +02:00
2011-06-29 12:23:32 +02:00
$langs -> load ( " other " );
$langs -> load ( " mails " );
2013-01-24 17:29:11 +01:00
$hookmanager -> initHooks ( array ( 'formmail' ));
2011-06-29 12:23:32 +02:00
2013-01-24 17:29:11 +01:00
$parameters = array (
2016-07-07 16:26:00 +02:00
'addfileaction' => $addfileaction ,
'removefileaction' => $removefileaction ,
'trackid' => $this -> trackid
2013-01-24 17:29:11 +01:00
);
$reshook = $hookmanager -> executeHooks ( 'getFormMail' , $parameters , $this );
2011-06-29 12:23:32 +02:00
2013-01-24 17:29:11 +01:00
if ( ! empty ( $reshook ))
2011-06-29 12:23:32 +02:00
{
2013-01-24 17:29:11 +01:00
return $hookmanager -> resPrint ;
2011-06-29 12:23:32 +02:00
}
2013-01-24 17:29:11 +01:00
else
2015-08-13 05:09:26 +02:00
{
2013-01-24 17:29:11 +01:00
$out = '' ;
2015-05-04 22:02:54 +02:00
2013-01-24 17:29:11 +01:00
// Define list of attached files
$listofpaths = array ();
$listofnames = array ();
$listofmimes = array ();
2016-06-24 16:10:52 +02:00
$keytoavoidconflict = empty ( $this -> trackid ) ? '' : '-' . $this -> trackid ; // this->trackid must be defined
2016-09-26 14:08:14 +02:00
2016-06-24 16:10:52 +02: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 ]);
2013-01-24 17:29:11 +01:00
2014-09-17 01:12:59 +02:00
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $this -> param [ 'langsmodels' ];
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
$outputlangs -> load ( 'other' );
}
// Get message template
2015-04-18 11:06:53 +02:00
$model_id = 0 ;
2015-07-04 03:28:52 +02:00
if ( array_key_exists ( 'models_id' , $this -> param ))
{
2015-04-18 11:06:53 +02:00
$model_id = $this -> param [ " models_id " ];
}
$arraydefaultmessage = $this -> getEMailTemplate ( $this -> db , $this -> param [ " models " ], $user , $outputlangs , $model_id );
2015-08-13 05:09:26 +02:00
//var_dump($arraydefaultmessage);
2014-09-17 01:12:59 +02:00
2015-08-13 05:09:26 +02:00
$out .= " \n <!-- Begin form mail --> \n " ;
2014-02-24 16:50:36 +01:00
if ( $this -> withform == 1 )
2013-01-24 17:29:11 +01:00
{
2015-08-13 05:09:26 +02:00
$out .= '<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="' . $this -> param [ " returnurl " ] . '#formmail">' . " \n " ;
2015-02-20 10:23:17 +01:00
$out .= '<input style="display:none" type="submit" id="sendmail" name="sendmail">' ;
2013-01-24 17:29:11 +01:00
$out .= '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '" />' ;
2015-05-04 22:02:54 +02:00
$out .= '<input type="hidden" name="trackid" value="' . $this -> trackid . '" />' ;
2015-08-13 05:09:26 +02:00
$out .= '<a id="formmail" name="formmail"></a>' ;
2013-01-24 17:29:11 +01:00
}
foreach ( $this -> param as $key => $value )
{
$out .= '<input type="hidden" id="' . $key . '" name="' . $key . '" value="' . $value . '" />' . " \n " ;
}
2015-05-04 22:02:54 +02:00
2015-04-18 11:06:53 +02:00
$result = $this -> fetchAllEMailTemplate ( $this -> param [ " models " ], $user , $outputlangs );
2015-07-04 03:28:52 +02:00
if ( $result < 0 )
{
2015-11-19 13:59:58 +01:00
setEventMessages ( $this -> error , $this -> errors , 'errors' );
2015-04-18 11:06:53 +02:00
}
$modelmail_array = array ();
2015-07-04 03:28:52 +02:00
foreach ( $this -> lines_model as $line )
{
2015-04-18 11:06:53 +02:00
$modelmail_array [ $line -> id ] = $line -> label ;
}
2015-05-04 22:02:54 +02:00
2015-07-04 03:28:52 +02:00
// Zone to select its email template
if ( count ( $modelmail_array ) > 0 )
{
$out .= '<div style="padding: 3px 0 3px 0">' . " \n " ;
2016-03-25 15:34:37 +01:00
$out .= $langs -> trans ( 'SelectMailModel' ) . ': ' . $this -> selectarray ( 'modelmailselected' , $modelmail_array , 0 , 1 );
2015-04-18 11:06:53 +02:00
if ( $user -> admin ) $out .= info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
2015-07-04 03:28:52 +02:00
$out .= ' ' ;
2015-12-18 12:45:04 +01:00
$out .= '<input class="button" type="submit" value="' . $langs -> trans ( 'Use' ) . '" name="modelselected" id="modelselected">' ;
2015-07-04 03:28:52 +02:00
$out .= ' ' ;
$out .= '</div>' ;
2015-04-18 11:06:53 +02:00
}
2015-12-18 12:45:04 +01:00
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'
)))
{
$out .= '<div style="padding: 3px 0 3px 0">' . " \n " ;
2016-06-24 13:08:34 +02:00
$out .= $langs -> trans ( 'SelectMailModel' ) . ': <select name="modelmailselected" disabled="disabled"><option value="none">' . $langs -> trans ( " NoTemplateDefined " ) . '</option></select>' ; // Do not put disabled on option, it is already on select and it makes chrome crazy.
2015-12-18 12:45:04 +01:00
if ( $user -> admin ) $out .= info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
$out .= ' ' ;
$out .= '<input class="button" type="submit" value="' . $langs -> trans ( 'Use' ) . '" name="modelselected" disabled="disabled" id="modelselected">' ;
$out .= ' ' ;
$out .= '</div>' ;
}
2016-04-11 14:52:22 +02:00
2015-05-04 22:02:54 +02:00
2013-01-24 17:29:11 +01:00
$out .= '<table class="border" width="100%">' . " \n " ;
// Substitution array
if ( ! empty ( $this -> withsubstit ))
{
$out .= '<tr><td colspan="2">' ;
$help = " " ;
foreach ( $this -> substit as $key => $val )
{
$help .= $key . ' -> ' . $langs -> trans ( $val ) . '<br>' ;
}
2016-03-25 15:24:57 +01:00
$out .= $form -> textwithpicto ( $langs -> trans ( " EMailTestSubstitutionReplacedByGenericValues " ), $help );
2013-01-24 17:29:11 +01:00
$out .= " </td></tr> \n " ;
}
// From
if ( ! empty ( $this -> withfrom ))
{
if ( ! empty ( $this -> withfromreadonly ))
{
$out .= '<input type="hidden" id="fromname" name="fromname" value="' . $this -> fromname . '" />' ;
$out .= '<input type="hidden" id="frommail" name="frommail" value="' . $this -> frommail . '" />' ;
$out .= '<tr><td width="180">' . $langs -> trans ( " MailFrom " ) . '</td><td>' ;
if ( $this -> fromtype == 'user' && $this -> fromid > 0 )
{
$langs -> load ( " users " );
$fuser = new User ( $this -> db );
$fuser -> fetch ( $this -> fromid );
$out .= $fuser -> getNomUrl ( 1 );
}
else
{
$out .= $this -> fromname ;
}
if ( $this -> frommail )
{
$out .= " < " . $this -> frommail . " > " ;
}
else
{
if ( $this -> fromtype )
{
$langs -> load ( " errors " );
$out .= '<font class="warning"> <' . $langs -> trans ( " ErrorNoMailDefinedForThisUser " ) . '> </font>' ;
}
}
$out .= " </td></tr> \n " ;
$out .= " </td></tr> \n " ;
}
else
{
$out .= " <tr><td> " . $langs -> trans ( " MailFrom " ) . " </td><td> " ;
$out .= $langs -> trans ( " Name " ) . ':<input type="text" id="fromname" name="fromname" size="32" value="' . $this -> fromname . '" />' ;
$out .= ' ' ;
$out .= $langs -> trans ( " EMail " ) . ':<<input type="text" id="frommail" name="frommail" size="32" value="' . $this -> frommail . '" />>' ;
$out .= " </td></tr> \n " ;
}
}
// Replyto
if ( ! empty ( $this -> withreplyto ))
{
if ( $this -> withreplytoreadonly )
{
$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 " ;
}
}
// Errorsto
if ( ! empty ( $this -> witherrorsto ))
{
//if (! $this->errorstomail) $this->errorstomail=$this->frommail;
$errorstomail = ( ! empty ( $conf -> global -> MAIN_MAIL_ERRORS_TO ) ? $conf -> global -> MAIN_MAIL_ERRORS_TO : $this -> errorstomail );
if ( $this -> witherrorstoreadonly )
{
$out .= '<input type="hidden" id="errorstomail" name="errorstomail" value="' . $errorstomail . '" />' ;
$out .= '<tr><td>' . $langs -> trans ( " MailErrorsTo " ) . '</td><td>' ;
$out .= $errorstomail ;
$out .= " </td></tr> \n " ;
}
else
{
$out .= '<tr><td>' . $langs -> trans ( " MailErrorsTo " ) . '</td><td>' ;
$out .= '<input size="30" id="errorstomail" name="errorstomail" value="' . $errorstomail . '" />' ;
$out .= " </td></tr> \n " ;
}
}
// To
if ( ! empty ( $this -> withto ) || is_array ( $this -> withto ))
{
$out .= '<tr><td width="180">' ;
2016-03-25 15:24:57 +01:00
if ( $this -> withtofree ) $out .= $form -> textwithpicto ( $langs -> trans ( " MailTo " ), $langs -> trans ( " YouCanUseCommaSeparatorForSeveralRecipients " ));
2013-01-24 17:29:11 +01:00
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 );
}
else if ( $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 ( " or " ) . ' <input size="' . ( is_array ( $this -> withto ) ? " 30 " : " 60 " ) . '" id="sendto" name="sendto" value="' . ( ! is_array ( $this -> withto ) && ! is_numeric ( $this -> withto ) ? ( isset ( $_REQUEST [ " sendto " ]) ? $_REQUEST [ " sendto " ] : $this -> withto ) : " " ) . '" />' ;
}
}
else
{
$out .= ( ! is_array ( $this -> withto ) && ! is_numeric ( $this -> withto )) ? $this -> withto : " " ;
}
}
else
{
if ( ! empty ( $this -> withtofree ))
{
$out .= '<input size="' . ( is_array ( $this -> withto ) ? " 30 " : " 60 " ) . '" id="sendto" name="sendto" value="' . ( ! is_array ( $this -> withto ) && ! is_numeric ( $this -> withto ) ? ( isset ( $_REQUEST [ " sendto " ]) ? $_REQUEST [ " sendto " ] : $this -> withto ) : " " ) . '" />' ;
}
if ( ! empty ( $this -> withto ) && is_array ( $this -> withto ))
{
if ( ! empty ( $this -> withtofree )) $out .= " " . $langs -> trans ( " or " ) . " " ;
2016-03-25 15:34:37 +01:00
$out .= $form -> selectarray ( " receiver " , $this -> withto , GETPOST ( " receiver " ), 1 );
2013-01-24 17:29:11 +01:00
}
if ( isset ( $this -> withtosocid ) && $this -> withtosocid > 0 ) // deprecated. TODO Remove this. Instead, fill withto with array before calling method.
{
$liste = array ();
$soc = new Societe ( $this -> db );
$soc -> fetch ( $this -> withtosocid );
foreach ( $soc -> thirdparty_and_contact_email_array ( 1 ) as $key => $value )
{
$liste [ $key ] = $value ;
}
if ( $this -> withtofree ) $out .= " " . $langs -> trans ( " or " ) . " " ;
2016-03-25 15:34:37 +01:00
$out .= $form -> selectarray ( " receiver " , $liste , GETPOST ( " receiver " ), 1 );
2013-01-24 17:29:11 +01:00
}
}
$out .= " </td></tr> \n " ;
}
// CC
if ( ! empty ( $this -> withtocc ) || is_array ( $this -> withtocc ))
{
$out .= '<tr><td width="180">' ;
2016-03-25 15:24:57 +01:00
$out .= $form -> textwithpicto ( $langs -> trans ( " MailCC " ), $langs -> trans ( " YouCanUseCommaSeparatorForSeveralRecipients " ));
2013-01-24 17:29:11 +01:00
$out .= '</td><td>' ;
if ( $this -> withtoccreadonly )
{
$out .= ( ! is_array ( $this -> withtocc ) && ! is_numeric ( $this -> withtocc )) ? $this -> withtocc : " " ;
}
else
{
$out .= '<input size="' . ( is_array ( $this -> withtocc ) ? " 30 " : " 60 " ) . '" id="sendtocc" name="sendtocc" value="' . (( ! is_array ( $this -> withtocc ) && ! is_numeric ( $this -> withtocc )) ? ( isset ( $_POST [ " sendtocc " ]) ? $_POST [ " sendtocc " ] : $this -> withtocc ) : ( isset ( $_POST [ " sendtocc " ]) ? $_POST [ " sendtocc " ] : " " ) ) . '" />' ;
2013-02-12 17:08:21 +01:00
if ( ! empty ( $this -> withtocc ) && is_array ( $this -> withtocc ))
2013-01-24 17:29:11 +01:00
{
$out .= " " . $langs -> trans ( " or " ) . " " ;
2016-03-25 15:34:37 +01:00
$out .= $form -> selectarray ( " receivercc " , $this -> withtocc , GETPOST ( " receivercc " ), 1 );
2013-01-24 17:29:11 +01:00
}
}
$out .= " </td></tr> \n " ;
}
2014-09-17 01:12:59 +02:00
2013-01-24 17:29:11 +01:00
// CCC
if ( ! empty ( $this -> withtoccc ) || is_array ( $this -> withtoccc ))
{
$out .= '<tr><td width="180">' ;
2016-03-25 15:24:57 +01:00
$out .= $form -> textwithpicto ( $langs -> trans ( " MailCCC " ), $langs -> trans ( " YouCanUseCommaSeparatorForSeveralRecipients " ));
2013-01-24 17:29:11 +01:00
$out .= '</td><td>' ;
if ( ! empty ( $this -> withtocccreadonly ))
{
$out .= ( ! is_array ( $this -> withtoccc ) && ! is_numeric ( $this -> withtoccc )) ? $this -> withtoccc : " " ;
}
else
{
$out .= '<input size="' . ( is_array ( $this -> withtoccc ) ? " 30 " : " 60 " ) . '" id="sendtoccc" name="sendtoccc" value="' . (( ! is_array ( $this -> withtoccc ) && ! is_numeric ( $this -> withtoccc )) ? ( isset ( $_POST [ " sendtoccc " ]) ? $_POST [ " sendtoccc " ] : $this -> withtoccc ) : ( isset ( $_POST [ " sendtoccc " ]) ? $_POST [ " sendtoccc " ] : " " ) ) . '" />' ;
2013-02-12 17:08:21 +01:00
if ( ! empty ( $this -> withtoccc ) && is_array ( $this -> withtoccc ))
2013-01-24 17:29:11 +01:00
{
$out .= " " . $langs -> trans ( " or " ) . " " ;
2016-03-25 15:34:37 +01:00
$out .= $form -> selectarray ( " receiverccc " , $this -> withtoccc , GETPOST ( " receiverccc " ), 1 );
2013-01-24 17:29:11 +01:00
}
}
2014-08-05 19:32:24 +02: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 ;
2015-11-15 18:23:42 +01:00
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 ;
2014-08-05 19:55:14 +02:00
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 ;
2014-08-05 19:32:24 +02:00
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 ( $showinfobcc ) $out .= ' + ' . $showinfobcc ;
2013-01-24 17:29:11 +01:00
$out .= " </td></tr> \n " ;
}
// Ask delivery receipt
if ( ! empty ( $this -> withdeliveryreceipt ))
{
$out .= '<tr><td width="180">' . $langs -> trans ( " DeliveryReceipt " ) . '</td><td>' ;
if ( ! empty ( $this -> withdeliveryreceiptreadonly ))
{
$out .= yn ( $this -> withdeliveryreceipt );
}
else
{
2014-08-04 19:03:15 +02:00
$defaultvaluefordeliveryreceipt = 0 ;
if ( ! empty ( $conf -> global -> MAIL_FORCE_DELIVERY_RECEIPT_PROPAL ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'propal_send' ) $defaultvaluefordeliveryreceipt = 1 ;
2015-11-15 18:23:42 +01:00
if ( ! empty ( $conf -> global -> MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_PROPOSAL ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'supplier_proposal_send' ) $defaultvaluefordeliveryreceipt = 1 ;
2014-08-05 19:55:14 +02:00
if ( ! empty ( $conf -> global -> MAIL_FORCE_DELIVERY_RECEIPT_ORDER ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'order_send' ) $defaultvaluefordeliveryreceipt = 1 ;
2014-08-05 19:32:24 +02:00
if ( ! empty ( $conf -> global -> MAIL_FORCE_DELIVERY_RECEIPT_INVOICE ) && ! empty ( $this -> param [ 'models' ]) && $this -> param [ 'models' ] == 'facture_send' ) $defaultvaluefordeliveryreceipt = 1 ;
2016-03-25 15:53:44 +01:00
$out .= $form -> selectyesno ( 'deliveryreceipt' , ( isset ( $_POST [ " deliveryreceipt " ]) ? $_POST [ " deliveryreceipt " ] : $defaultvaluefordeliveryreceipt ), 1 );
2013-01-24 17:29:11 +01:00
}
$out .= " </td></tr> \n " ;
}
// Topic
if ( ! empty ( $this -> withtopic ))
{
2014-09-17 01:12:59 +02:00
$defaulttopic = " " ;
if ( count ( $arraydefaultmessage ) > 0 && $arraydefaultmessage [ 'topic' ]) $defaulttopic = $arraydefaultmessage [ 'topic' ];
elseif ( ! is_numeric ( $this -> withtopic )) $defaulttopic = $this -> withtopic ;
$defaulttopic = make_substitutions ( $defaulttopic , $this -> substit );
2013-01-24 17:29:11 +01:00
$out .= '<tr>' ;
$out .= '<td width="180">' . $langs -> trans ( " MailTopic " ) . '</td>' ;
$out .= '<td>' ;
if ( $this -> withtopicreadonly )
{
2014-09-17 01:12:59 +02:00
$out .= $defaulttopic ;
$out .= '<input type="hidden" size="60" id="subject" name="subject" value="' . $defaulttopic . '" />' ;
2013-01-24 17:29:11 +01:00
}
else
{
2015-08-13 05:09:26 +02:00
$out .= '<input type="text" size="60" id="subject" name="subject" value="' . (( isset ( $_POST [ " subject " ]) && ! $_POST [ 'modelselected' ]) ? $_POST [ " subject " ] : ( $defaulttopic ? $defaulttopic : '' )) . '" />' ;
2013-01-24 17:29:11 +01:00
}
$out .= " </td></tr> \n " ;
}
// Attached files
if ( ! empty ( $this -> withfile ))
{
$out .= '<tr>' ;
$out .= '<td width="180">' . $langs -> trans ( " MailFile " ) . '</td>' ;
2014-02-19 20:23:02 +01:00
2013-01-24 17:29:11 +01:00
$out .= '<td>' ;
2014-02-19 20:23:02 +01:00
if ( is_numeric ( $this -> withfile ))
2013-01-24 17:29:11 +01:00
{
2014-02-19 20:23:02 +01:00
// TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
$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 " ;
if ( count ( $listofpaths ))
{
foreach ( $listofpaths as $key => $val )
{
$out .= '<div id="attachfile_' . $key . '">' ;
$out .= img_mime ( $listofnames [ $key ]) . ' ' . $listofnames [ $key ];
if ( ! $this -> withfilereadonly )
{
$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 . '" />' ;
//$out.= ' <a href="'.$_SERVER["PHP_SELF"].'?removedfile='.($key+1).' id="removedfile_'.$key.'">'.img_delete($langs->trans("Delete").'</a>';
}
$out .= '<br></div>' ;
}
}
else
{
$out .= $langs -> trans ( " NoAttachedFiles " ) . '<br>' ;
}
if ( $this -> withfile == 2 ) // Can add other files
{
2015-12-10 13:48:37 +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 " ) . '" />' ;
2014-02-19 20:23:02 +01:00
$out .= ' ' ;
2016-09-26 00:10:29 +02:00
$out .= '<input class="button" type="submit" id="' . $addfileaction . '" name="' . $addfileaction . '" value="' . $langs -> trans ( " MailingAddFile " ) . '" />' ;
2014-02-19 20:23:02 +01:00
}
2013-01-24 17:29:11 +01:00
}
else
{
2014-02-19 20:23:02 +01:00
$out .= $this -> withfile ;
2013-01-24 17:29:11 +01:00
}
$out .= " </td></tr> \n " ;
}
// Message
if ( ! empty ( $this -> withbody ))
{
$defaultmessage = " " ;
2014-09-17 01:12:59 +02:00
if ( count ( $arraydefaultmessage ) > 0 && $arraydefaultmessage [ 'content' ]) $defaultmessage = $arraydefaultmessage [ 'content' ];
elseif ( ! is_numeric ( $this -> withbody )) $defaultmessage = $this -> withbody ;
2013-01-24 17:29:11 +01:00
// Complete substitution array
if ( ! empty ( $conf -> paypal -> enabled ) && ! empty ( $conf -> global -> PAYPAL_ADD_PAYMENT_URL ))
{
require_once DOL_DOCUMENT_ROOT . '/paypal/lib/paypal.lib.php' ;
$langs -> load ( 'paypal' );
2016-03-05 12:20:58 +01:00
// Set the paypal message and url link into __PERSONALIZED__ key
2013-01-24 17:29:11 +01:00
if ( $this -> param [ " models " ] == 'order_send' )
{
2016-03-05 12:20:58 +01:00
$url = getPaypalPaymentUrl ( 0 , 'order' , $this -> substit [ '__ORDERREF__' ] ? $this -> substit [ '__ORDERREF__' ] : $this -> substit [ '__REF__' ]);
2014-02-06 18:19:49 +01:00
$this -> substit [ '__PERSONALIZED__' ] = str_replace ( '\n' , " \n " , $langs -> transnoentitiesnoconv ( " PredefinedMailContentLink " , $url ));
2013-01-24 17:29:11 +01:00
}
if ( $this -> param [ " models " ] == 'facture_send' )
{
2015-12-02 01:38:15 +01:00
$url = getPaypalPaymentUrl ( 0 , 'invoice' , $this -> substit [ '__REF__' ]);
2014-02-06 18:19:49 +01:00
$this -> substit [ '__PERSONALIZED__' ] = str_replace ( '\n' , " \n " , $langs -> transnoentitiesnoconv ( " PredefinedMailContentLink " , $url ));
2013-01-24 17:29:11 +01:00
}
}
2013-07-30 17:29:24 +02:00
$defaultmessage = str_replace ( '\n' , " \n " , $defaultmessage );
2014-02-19 15:33:04 +01:00
2013-08-02 10:24:09 +02:00
// Deal with format differences between message and signature (text / HTML)
if ( dol_textishtml ( $defaultmessage ) && ! dol_textishtml ( $this -> substit [ '__SIGNATURE__' ])) {
$this -> substit [ '__SIGNATURE__' ] = dol_nl2br ( $this -> substit [ '__SIGNATURE__' ]);
} else if ( ! dol_textishtml ( $defaultmessage ) && dol_textishtml ( $this -> substit [ '__SIGNATURE__' ])) {
$defaultmessage = dol_nl2br ( $defaultmessage );
}
2014-02-19 15:33:04 +01:00
2015-05-04 22:02:54 +02:00
2015-04-18 11:06:53 +02:00
if ( isset ( $_POST [ " message " ]) && ! $_POST [ 'modelselected' ]) $defaultmessage = $_POST [ " message " ];
2014-04-30 15:17:39 +02:00
else
{
$defaultmessage = make_substitutions ( $defaultmessage , $this -> substit );
// Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty)
$defaultmessage = preg_replace ( " /^(<br>)+/ " , " " , $defaultmessage );
$defaultmessage = preg_replace ( " /^ \n +/ " , " " , $defaultmessage );
}
2013-01-24 17:29:11 +01:00
$out .= '<tr>' ;
$out .= '<td width="180" valign="top">' . $langs -> trans ( " MailText " ) . '</td>' ;
$out .= '<td>' ;
if ( $this -> withbodyreadonly )
{
$out .= nl2br ( $defaultmessage );
$out .= '<input type="hidden" id="message" name="message" value="' . $defaultmessage . '" />' ;
}
else
{
if ( ! isset ( $this -> ckeditortoolbar )) $this -> ckeditortoolbar = 'dolibarr_notes' ;
// Editor wysiwyg
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2014-06-21 01:26:41 +02:00
if ( $this -> withfckeditor == - 1 )
{
if ( ! empty ( $conf -> global -> FCKEDITOR_ENABLE_MAIL )) $this -> withfckeditor = 1 ;
else $this -> withfckeditor = 0 ;
2013-03-16 09:23:34 +01:00
}
2014-06-21 01:26:41 +02:00
2015-12-02 01:38:15 +01:00
$doleditor = new DolEditor ( 'message' , $defaultmessage , '' , 280 , $this -> ckeditortoolbar , 'In' , true , true , $this -> withfckeditor , 8 , '95%' );
2013-01-24 17:29:11 +01:00
$out .= $doleditor -> Create ( 1 );
}
$out .= " </td></tr> \n " ;
}
2016-06-10 18:41:18 +02:00
$out .= '</table>' . " \n " ;
2014-02-24 16:50:36 +01:00
if ( $this -> withform == 1 || $this -> withform == - 1 )
2013-01-24 17:29:11 +01:00
{
2016-06-10 18:41:18 +02:00
$out .= '<br><div class="center">' ;
2013-01-24 17:29:11 +01:00
$out .= '<input class="button" type="submit" id="sendmail" name="sendmail" value="' . $langs -> trans ( " SendMail " ) . '"' ;
// Add a javascript test to avoid to forget to submit file before sending email
if ( $this -> withfile == 2 && $conf -> use_javascript_ajax )
{
$out .= ' onClick="if (document.mailform.addedfile.value != \'\') { alert(\'' . dol_escape_js ( $langs -> trans ( " FileWasNotUploaded " )) . '\'); return false; } else { return true; }"' ;
}
$out .= ' />' ;
if ( $this -> withcancel )
{
$out .= ' ' ;
$out .= '<input class="button" type="submit" id="cancel" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '" />' ;
}
2016-06-10 18:41:18 +02:00
$out .= '</div>' . " \n " ;
2013-01-24 17:29:11 +01:00
}
2014-02-24 16:50:36 +01:00
if ( $this -> withform == 1 ) $out .= '</form>' . " \n " ;
2015-06-04 12:57:49 +02:00
2015-08-13 05:09:26 +02:00
// Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
2015-06-04 12:57:49 +02:00
if ( ! empty ( $conf -> global -> MAIN_MAILFORM_DISABLE_ENTERKEY ))
{
$out .= '<script type="text/javascript" language="javascript">' ;
$out .= 'jQuery(document).ready(function () {' ;
$out .= ' $ ( document ) . on ( " keypress " , \ ' #mailform\', function (e) { /* Note this is calle at every key pressed ! */
var code = e . keyCode || e . which ;
if ( code == 13 ) {
e . preventDefault ();
return false ;
}
}); ' ;
$out .= ' })' ;
$out .= '</script>' ;
}
2015-08-13 05:09:26 +02:00
$out .= " <!-- End form mail --> \n " ;
2013-01-24 17:29:11 +01:00
return $out ;
2011-06-29 12:23:32 +02:00
}
}
2014-09-17 01:12:59 +02:00
/**
* Return template of email
2014-10-14 01:47:31 +02:00
* Search into table c_email_templates
2014-09-17 01:12:59 +02:00
*
* @ param DoliDB $db Database handler
* @ param string $type_template Get message for key module
* @ param string $user Use template public or limited to this user
2014-09-17 16:40:35 +02:00
* @ param Translate $outputlangs Output lang object
2015-04-18 11:06:53 +02:00
* @ param int $id Id template to find
2016-06-24 13:08:34 +02:00
* @ param int $active 1 = Only active template , 0 = Only disabled , - 1 = All
2014-09-17 01:12:59 +02:00
* @ return array array ( 'topic' => , 'content' => , .. )
*/
2016-06-24 13:08:34 +02:00
private function getEMailTemplate ( $db , $type_template , $user , $outputlangs , $id = 0 , $active = 1 )
2014-09-17 01:12:59 +02:00
{
$ret = array ();
2014-10-12 21:24:51 +02:00
$sql = " SELECT label, topic, content, lang " ;
2014-09-17 01:12:59 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . 'c_email_templates' ;
$sql .= " WHERE type_template=' " . $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 . " ) " ;
2016-06-24 13:08:34 +02:00
if ( $active >= 0 ) $sql .= " AND active = " . $active ;
2014-10-12 21:24:51 +02:00
if ( is_object ( $outputlangs )) $sql .= " AND (lang = ' " . $outputlangs -> defaultlang . " ' OR lang IS NULL OR lang = '') " ;
2015-04-18 11:06:53 +02:00
if ( ! empty ( $id )) $sql .= " AND rowid= " . $id ;
2014-10-12 21:24:51 +02:00
$sql .= $db -> order ( " lang,label " , " ASC " );
2014-10-20 11:35:34 +02:00
//print $sql;
2014-09-17 01:12:59 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
2014-10-12 21:24:51 +02:00
$obj = $db -> fetch_object ( $resql ); // Get first found
2014-09-17 01:12:59 +02:00
if ( $obj )
{
2014-10-12 21:24:51 +02:00
$ret [ 'label' ] = $obj -> label ;
2014-09-17 01:12:59 +02:00
$ret [ 'topic' ] = $obj -> topic ;
$ret [ 'content' ] = $obj -> content ;
2014-10-12 21:24:51 +02:00
$ret [ 'lang' ] = $obj -> lang ;
2014-09-17 01:12:59 +02:00
}
else
{
$defaultmessage = '' ;
if ( $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 " ); }
2015-11-15 18:23:42 +01:00
elseif ( $type_template == 'supplier_proposal_send' ) { $defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentSendSupplierProposal " ); }
2014-09-17 01:12:59 +02:00
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 " ); }
2014-10-12 21:24:51 +02:00
$ret [ 'label' ] = 'default' ;
2014-09-17 01:12:59 +02:00
$ret [ 'topic' ] = '' ;
$ret [ 'content' ] = $defaultmessage ;
2014-10-12 21:24:51 +02:00
$ret [ 'lang' ] = $outputlangs -> defaultlang ;
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 )
{
$ret = array ();
2015-05-04 22:02:54 +02:00
2015-04-18 11:06:53 +02:00
$sql = " SELECT label, topic, content, lang " ;
$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 " );
//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 )
{
$num = $this -> db -> num_rows ( $resql );
$this -> db -> free ( $resql );
return $num ;
}
else
{
$this -> error = get_class ( $this ) . ' ' . __METHOD__ . ' ERROR:' . $this -> db -> lasterror ();
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
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
*/
2016-06-24 13:08:34 +02:00
public function fetchAllEMailTemplate ( $type_template , $user , $outputlangs , $active = 1 )
2015-04-18 11:06:53 +02:00
{
$ret = array ();
2015-05-04 22:02:54 +02:00
2016-04-07 14:16:10 +02:00
$sql = " SELECT rowid, label, topic, content, lang, position " ;
2015-04-18 11:06:53 +02: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 . " ) " ;
2016-06-24 13:08:34 +02:00
if ( $active >= 0 ) $sql .= " AND active = " . $active ;
2015-04-18 11:06:53 +02:00
if ( is_object ( $outputlangs )) $sql .= " AND (lang = ' " . $outputlangs -> defaultlang . " ' OR lang IS NULL OR lang = '') " ;
2016-04-07 14:16:10 +02: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 )
{
2015-11-15 20:00:11 +01:00
$num = $this -> db -> num_rows ( $resql );
2015-04-18 11:06:53 +02:00
$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 ();
2015-04-18 11:06:53 +02:00
$line -> id = $obj -> rowid ;
$line -> label = $obj -> label ;
$line -> topic = $obj -> topic ;
2016-04-11 14:52:22 +02:00
$line -> content = $obj -> content ;
2015-04-18 11:06:53 +02:00
$line -> lang = $obj -> lang ;
$this -> lines_model [] = $line ;
}
$this -> db -> free ( $resql );
return $num ;
}
else
{
$this -> error = get_class ( $this ) . ' ' . __METHOD__ . ' ERROR:' . $this -> db -> lasterror ();
return - 1 ;
}
}
2016-03-05 12:20:58 +01:00
/**
* Set substit array from object
*
2016-07-21 20:43:23 +02:00
* @ param Object $object Object to use
* @ param Translate $outputlangs Object lang
2016-03-05 12:20:58 +01:00
* @ return void
*/
2016-07-21 20:43:23 +02:00
function setSubstitFromObject ( $object , $outputlangs = null )
2016-03-05 12:20:58 +01:00
{
2016-04-17 12:20:45 +02:00
global $user ;
2016-03-05 12:20:58 +01:00
$this -> substit [ '__REF__' ] = $object -> ref ;
$this -> substit [ '__REFCLIENT__' ] = $object -> ref_client ;
2016-07-21 13:49:10 +02:00
$this -> substit [ '__REFSUPPLIER__' ] = $object -> ref_supplier ;
2016-07-21 20:43:23 +02:00
$this -> substit [ '__DATE_YMD__' ] = dol_print_date ( $object -> date , 'day' , 0 , $outputlangs );
$this -> substit [ '__DATE_DUE_YMD__' ] = dol_print_date ( $object -> date_lim_reglement , 'day' , 0 , $outputlangs );
$this -> substit [ '__AMOUNT__' ] = price ( $object -> total_ttc );
$this -> substit [ '__AMOUNT_WO_TAX__' ] = price ( $object -> total_ht );
2016-07-21 13:49:10 +02:00
$this -> substit [ '__THIRDPARTY_ID__' ] = ( is_object ( $object -> thirdparty ) ? $object -> thirdparty -> id : '' );
$this -> substit [ '__THIRDPARTY_NAME__' ] = ( is_object ( $object -> thirdparty ) ? $object -> thirdparty -> name : '' );
$this -> substit [ '__PROJECT_ID__' ] = ( is_object ( $object -> projet ) ? $object -> projet -> id : '' );
2016-03-05 12:20:58 +01:00
$this -> substit [ '__PROJECT_REF__' ] = ( is_object ( $object -> projet ) ? $object -> projet -> ref : '' );
$this -> substit [ '__PROJECT_NAME__' ] = ( is_object ( $object -> projet ) ? $object -> projet -> title : '' );
2016-07-21 13:49:10 +02:00
$this -> substit [ '__SIGNATURE__' ] = $user -> signature ;
2016-03-05 12:20:58 +01:00
$this -> substit [ '__PERSONALIZED__' ] = '' ;
$this -> substit [ '__CONTACTCIVNAME__' ] = '' ; // Will be replace just before sending
}
/**
* Set substit array from object
*
* @ param string $mode 'form' or 'emailing'
* @ return void
*/
function getAvailableSubstitKey ( $mode = 'form' )
{
global $conf ;
$vars = array ();
if ( $mode == 'form' )
{
$vars = array (
'__REF__' ,
'__REFCLIENT__' ,
'__THIRDPARTY_NAME__' ,
'__PROJECT_REF__' ,
'__PROJECT_NAME__' ,
'__CONTACTCIVNAME__' ,
2016-03-05 12:37:09 +01:00
'__PERSONALIZED__' , // Paypal link will be added here in form mode
2016-03-05 12:20:58 +01:00
'__SIGNATURE__' ,
);
}
if ( $mode == 'emailing' )
{
// For mass emailing, we have different keys
$vars = array (
'__ID__' => 'IdRecord' ,
2016-06-23 23:22:30 +02:00
'__EMAIL__' => 'EMailRecipient' ,
2016-03-05 12:20:58 +01:00
'__LASTNAME__' => 'Lastname' ,
'__FIRSTNAME__' => 'Firstname' ,
'__MAILTOEMAIL__' => 'TagMailtoEmail' ,
'__OTHER1__' => 'Other1' ,
'__OTHER2__' => 'Other2' ,
'__OTHER3__' => 'Other3' ,
'__OTHER4__' => 'Other4' ,
'__OTHER5__' => 'Other5' ,
'__SIGNATURE__' => 'TagSignature' ,
'__CHECK_READ__' => 'TagCheckMail' ,
'__UNSUBSCRIBE__' => 'TagUnsubscribe'
//,'__PERSONALIZED__' => 'Personalized' // Hidden because not used yet in mass emailing
);
if ( ! empty ( $conf -> paypal -> enabled ) && ! empty ( $conf -> global -> PAYPAL_SECURITY_TOKEN ))
{
$vars [ '__SECUREKEYPAYPAL__' ] = 'SecureKeyPaypal' ;
if ( ! empty ( $conf -> global -> PAYPAL_SECURITY_TOKEN_UNIQUE ))
{
if ( $conf -> adherent -> enabled ) $vars [ '__SECUREKEYPAYPAL_MEMBER__' ] = 'SecureKeyPaypalUniquePerMember' ;
if ( $conf -> facture -> enabled ) $vars [ '__SECUREKEYPAYPAL_INVOICE__' ] = 'SecureKeyPaypalUniquePerInvoice' ;
if ( $conf -> commande -> enabled ) $vars [ '__SECUREKEYPAYPAL_ORDER__' ] = 'SecureKeyPaypalUniquePerOrder' ;
if ( $conf -> contrat -> enabled ) $vars [ '__SECUREKEYPAYPAL_CONTRACTLINE__' ] = 'SecureKeyPaypalUniquePerContractLine' ;
}
}
else
{
$vars [ '__SECUREKEYPAYPAL__' ] = '' ;
$vars [ '__SECUREKEYPAYPAL_MEMBER__' ] = '' ;
}
}
return $vars ;
}
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
{
2015-04-18 11:06:53 +02:00
public $id ;
public $label ;
public $topic ;
public $content ;
public $lang ;
2010-05-03 10:43:32 +02:00
}