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 >
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
*/
class FormMail
{
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 ;
2014-04-30 15:17:39 +02:00
2011-06-29 12:23:32 +02:00
var $withsubstit ; // Show substitution array
var $withfrom ;
2013-09-23 14:35:22 +02:00
var $withto ; // Show recipient emails
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 ;
/**
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 ;
}
/**
* Clear list of attached files in send mail form ( 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 ;
$upload_dir = $vardir . '/temp/' ;
if ( is_dir ( $upload_dir )) dol_delete_dir_recursive ( $upload_dir );
unset ( $_SESSION [ " listofpaths " ]);
unset ( $_SESSION [ " listofnames " ]);
unset ( $_SESSION [ " listofmimes " ]);
}
/**
* 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 ();
if ( ! empty ( $_SESSION [ " listofpaths " ])) $listofpaths = explode ( ';' , $_SESSION [ " listofpaths " ]);
if ( ! empty ( $_SESSION [ " listofnames " ])) $listofnames = explode ( ';' , $_SESSION [ " listofnames " ]);
if ( ! empty ( $_SESSION [ " listofmimes " ])) $listofmimes = explode ( ';' , $_SESSION [ " listofmimes " ]);
if ( ! in_array ( $file , $listofnames ))
{
$listofpaths [] = $path ;
$listofnames [] = $file ;
$listofmimes [] = $type ;
$_SESSION [ " listofpaths " ] = join ( ';' , $listofpaths );
$_SESSION [ " listofnames " ] = join ( ';' , $listofnames );
$_SESSION [ " listofmimes " ] = join ( ';' , $listofmimes );
}
}
/**
* Remove a file from the list of attached files ( stored in SECTION array )
*
2012-01-27 15:17:36 +01:00
* @ param string $keytodelete Key in file array
* @ return void
2011-06-29 12:23:32 +02:00
*/
function remove_attached_files ( $keytodelete )
{
$listofpaths = array ();
$listofnames = array ();
$listofmimes = array ();
if ( ! empty ( $_SESSION [ " listofpaths " ])) $listofpaths = explode ( ';' , $_SESSION [ " listofpaths " ]);
if ( ! empty ( $_SESSION [ " listofnames " ])) $listofnames = explode ( ';' , $_SESSION [ " listofnames " ]);
if ( ! empty ( $_SESSION [ " listofmimes " ])) $listofmimes = explode ( ';' , $_SESSION [ " listofmimes " ]);
if ( $keytodelete >= 0 )
{
unset ( $listofpaths [ $keytodelete ]);
unset ( $listofnames [ $keytodelete ]);
unset ( $listofmimes [ $keytodelete ]);
$_SESSION [ " listofpaths " ] = join ( ';' , $listofpaths );
$_SESSION [ " listofnames " ] = join ( ';' , $listofnames );
$_SESSION [ " listofmimes " ] = join ( ';' , $listofmimes );
//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 ();
if ( ! empty ( $_SESSION [ " listofpaths " ])) $listofpaths = explode ( ';' , $_SESSION [ " listofpaths " ]);
if ( ! empty ( $_SESSION [ " listofnames " ])) $listofnames = explode ( ';' , $_SESSION [ " listofnames " ]);
if ( ! empty ( $_SESSION [ " listofmimes " ])) $listofmimes = explode ( ';' , $_SESSION [ " listofmimes " ]);
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
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 (
'addfileaction' => $addfileaction ,
'removefileaction' => $removefileaction
);
$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
2011-06-29 12:23:32 +02:00
{
2013-01-24 17:29:11 +01:00
$out = '' ;
// Define list of attached files
$listofpaths = array ();
$listofnames = array ();
$listofmimes = array ();
if ( ! empty ( $_SESSION [ " listofpaths " ])) $listofpaths = explode ( ';' , $_SESSION [ " listofpaths " ]);
if ( ! empty ( $_SESSION [ " listofnames " ])) $listofnames = explode ( ';' , $_SESSION [ " listofnames " ]);
if ( ! empty ( $_SESSION [ " listofmimes " ])) $listofmimes = explode ( ';' , $_SESSION [ " listofmimes " ]);
$out .= " \n <!-- Debut form mail --> \n " ;
2014-02-24 16:50:36 +01:00
if ( $this -> withform == 1 )
2013-01-24 17:29:11 +01:00
{
$out .= '<form method="POST" name="mailform" enctype="multipart/form-data" action="' . $this -> param [ " returnurl " ] . '">' . " \n " ;
$out .= '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '" />' ;
}
foreach ( $this -> param as $key => $value )
{
$out .= '<input type="hidden" id="' . $key . '" name="' . $key . '" value="' . $value . '" />' . " \n " ;
}
$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>' ;
}
$out .= $form -> textwithpicto ( $langs -> trans ( " EMailTestSubstitutionReplacedByGenericValues " ), $help );
$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">' ;
if ( $this -> withtofree ) $out .= $form -> textwithpicto ( $langs -> trans ( " MailTo " ), $langs -> trans ( " YouCanUseCommaSeparatorForSeveralRecipients " ));
else $out .= $langs -> trans ( " MailTo " );
$out .= '</td><td>' ;
if ( $this -> withtoreadonly )
{
if ( ! empty ( $this -> toname ) && ! empty ( $this -> tomail ))
{
$out .= '<input type="hidden" id="toname" name="toname" value="' . $this -> toname . '" />' ;
$out .= '<input type="hidden" id="tomail" name="tomail" value="' . $this -> tomail . '" />' ;
if ( $this -> totype == 'thirdparty' )
{
$soc = new Societe ( $this -> db );
$soc -> fetch ( $this -> toid );
$out .= $soc -> getNomUrl ( 1 );
}
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 " ) . " " ;
$out .= $form -> selectarray ( " receiver " , $this -> withto , GETPOST ( " receiver " ), 1 );
}
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 " ) . " " ;
$out .= $form -> selectarray ( " receiver " , $liste , GETPOST ( " receiver " ), 1 );
}
}
$out .= " </td></tr> \n " ;
}
// CC
if ( ! empty ( $this -> withtocc ) || is_array ( $this -> withtocc ))
{
$out .= '<tr><td width="180">' ;
$out .= $form -> textwithpicto ( $langs -> trans ( " MailCC " ), $langs -> trans ( " YouCanUseCommaSeparatorForSeveralRecipients " ));
$out .= '</td><td>' ;
if ( $this -> withtoccreadonly )
{
$out .= ( ! is_array ( $this -> withtocc ) && ! is_numeric ( $this -> withtocc )) ? $this -> withtocc : " " ;
}
else
{
$out .= '<input 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 " ) . " " ;
2013-09-18 13:36:22 +02:00
$out .= $form -> selectarray ( " receivercc " , $this -> withtocc , GETPOST ( " receivercc " ), 1 );
2013-01-24 17:29:11 +01:00
}
}
$out .= " </td></tr> \n " ;
}
2014-08-05 19:32:24 +02:00
2013-01-24 17:29:11 +01:00
// CCC
if ( ! empty ( $this -> withtoccc ) || is_array ( $this -> withtoccc ))
{
$out .= '<tr><td width="180">' ;
$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 : " " ;
}
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 " ) . " " ;
2013-09-18 13:36:22 +02: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 ;
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 ;
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 ;
2014-08-04 19:03:15 +02: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 ))
{
$this -> withtopic = make_substitutions ( $this -> withtopic , $this -> substit );
$out .= '<tr>' ;
$out .= '<td width="180">' . $langs -> trans ( " MailTopic " ) . '</td>' ;
$out .= '<td>' ;
if ( $this -> withtopicreadonly )
{
$out .= $this -> withtopic ;
$out .= '<input type="hidden" size="60" id="subject" name="subject" value="' . $this -> withtopic . '" />' ;
}
else
{
2013-09-23 13:17:31 +02:00
$out .= '<input type="text" size="60" id="subject" name="subject" value="' . ( isset ( $_POST [ " subject " ]) ? $_POST [ " subject " ] : ( is_numeric ( $this -> withtopic ) ? '' : $this -> withtopic )) . '" />' ;
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
{
$out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="' . $langs -> trans ( " Upload " ) . '" />' ;
$out .= ' ' ;
$out .= '<input type="submit" class="button" id="' . $addfileaction . '" name="' . $addfileaction . '" value="' . $langs -> trans ( " MailingAddFile " ) . '" />' ;
}
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-06-18 09:59:15 +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 );
2014-07-28 02:45:58 +02:00
$outputlangs -> load ( 'other' );
2014-06-18 09:59:15 +02:00
}
2013-01-24 17:29:11 +01:00
2014-04-30 15:17:39 +02:00
// TODO A partir du type, proposer liste de messages dans table llx_c_email_template
2014-06-18 09:59:15 +02:00
if ( $this -> param [ " models " ] == 'facture_send' ) { $defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentSendInvoice " ); }
elseif ( $this -> param [ " models " ] == 'facture_relance' ) { $defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentSendInvoiceReminder " ); }
elseif ( $this -> param [ " models " ] == 'propal_send' ) { $defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentSendProposal " ); }
elseif ( $this -> param [ " models " ] == 'order_send' ) { $defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentSendOrder " ); }
elseif ( $this -> param [ " models " ] == 'order_supplier_send' ) { $defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentSendSupplierOrder " ); }
elseif ( $this -> param [ " models " ] == 'invoice_supplier_send' ) { $defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentSendSupplierInvoice " ); }
elseif ( $this -> param [ " models " ] == 'shipping_send' ) { $defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentSendShipping " ); }
elseif ( $this -> param [ " models " ] == 'fichinter_send' ) { $defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentSendFichInter " ); }
elseif ( $this -> param [ " models " ] == 'thirdparty' ) { $defaultmessage = $outputlangs -> transnoentities ( " PredefinedMailContentThirdparty " ); }
2014-02-19 15:33:04 +01:00
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' );
if ( $this -> param [ " models " ] == 'order_send' )
{
$url = getPaypalPaymentUrl ( 0 , 'order' , $this -> substit [ '__ORDERREF__' ]);
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' )
{
$url = getPaypalPaymentUrl ( 0 , 'invoice' , $this -> substit [ '__FACREF__' ]);
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
2014-04-30 15:17:39 +02:00
2013-01-24 17:29:11 +01:00
if ( isset ( $_POST [ " message " ])) $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
2013-06-03 19:52:34 +02:00
$doleditor = new DolEditor ( 'message' , $defaultmessage , '' , 280 , $this -> ckeditortoolbar , 'In' , true , true , $this -> withfckeditor , 8 , 72 );
2013-01-24 17:29:11 +01:00
$out .= $doleditor -> Create ( 1 );
}
$out .= " </td></tr> \n " ;
}
2014-02-24 16:50:36 +01:00
if ( $this -> withform == 1 || $this -> withform == - 1 )
2013-01-24 17:29:11 +01:00
{
$out .= '<tr><td align="center" colspan="2"><center>' ;
$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 " ) . '" />' ;
}
$out .= '</center></td></tr>' . " \n " ;
}
$out .= '</table>' . " \n " ;
2014-02-24 16:50:36 +01:00
if ( $this -> withform == 1 ) $out .= '</form>' . " \n " ;
2013-01-24 17:29:11 +01:00
$out .= " <!-- Fin form mail --> \n " ;
return $out ;
2011-06-29 12:23:32 +02:00
}
}
2010-05-03 10:43:32 +02:00
}