2005-01-11 21:26:22 +01:00
< ? PHP
2008-02-29 17:26:38 +01:00
/* Copyright ( C ) 2005 - 2008 Laurent Destailleur < eldy @ users . sourceforge . net >
2005-01-11 21:26:22 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( 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
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*/
2005-08-11 22:15:10 +02:00
/**
\file htdocs / html . formmail . class . php
2005-01-11 21:26:22 +01:00
\brief Fichier de la classe permettant la g<EFBFBD> n<EFBFBD> ration du formulaire html d ' envoi de mail unitaire
2008-02-29 17:26:38 +01:00
\version $Id $
2005-01-11 21:26:22 +01:00
*/
2005-05-11 02:15:36 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /html.form.class.php " );
2008-04-05 16:18:13 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /lib/functions.lib.php " );
2005-01-11 21:26:22 +01:00
/** \class FormMail
\brief Classe permettant la g<EFBFBD> n<EFBFBD> ration du formulaire html d ' envoi de mail unitaire
\remarks Utilisation : $formail = new FormMail ( $db )
\remarks $formmail -> proprietes = 1 ou chaine ou tableau de valeurs
\remarks $formmail -> show_form () affiche le formulaire
*/
class FormMail
{
2006-08-06 15:35:19 +02:00
var $db ;
2005-01-11 21:26:22 +01:00
2006-08-06 15:35:19 +02:00
var $fromname ;
var $frommail ;
var $replytoname ;
var $replytomail ;
var $toname ;
var $tomail ;
2007-05-26 17:05:49 +02:00
var $withsubstit ; // Show substitution array
2006-08-06 15:35:19 +02:00
var $withfrom ;
var $withto ;
var $withtocc ;
var $withtopic ;
2008-05-23 21:43:28 +02:00
var $withfile ; // 0=No attaches files, 1=Show attached files, 2=Can add new attached files
2006-08-06 15:35:19 +02:00
var $withbody ;
var $withfromreadonly ;
var $withreplytoreadonly ;
var $withtoreadonly ;
var $withtoccreadonly ;
var $withtopicreadonly ;
var $withdeliveryreceipt ;
var $withcancel ;
var $substit = array ();
var $param = array ();
2006-11-20 02:13:13 +01:00
var $error ;
2005-01-11 21:26:22 +01:00
2006-08-06 15:35:19 +02:00
/**
\brief Constructeur
\param DB handler d ' acc<EFBFBD> s base de donn<EFBFBD> e
*/
function FormMail ( $DB )
{
$this -> db = $DB ;
$this -> withfrom = 1 ;
$this -> withto = 1 ;
$this -> withtocc = 1 ;
2008-02-29 17:26:38 +01:00
$this -> withtoccc = 0 ;
2007-07-30 16:44:47 +02:00
$this -> witherrorsto = 0 ;
2006-08-06 15:35:19 +02:00
$this -> withtopic = 1 ;
$this -> withfile = 0 ;
$this -> withbody = 1 ;
$this -> withfromreadonly = 1 ;
$this -> withreplytoreadonly = 1 ;
$this -> withtoreadonly = 0 ;
$this -> withtoccreadonly = 0 ;
2007-07-30 16:44:47 +02:00
$this -> witherrorstoreadonly = 0 ;
2006-08-06 15:35:19 +02:00
$this -> withtopicreadonly = 0 ;
$this -> withbodyreadonly = 0 ;
$this -> withdeliveryreceiptreadonly = 0 ;
return 1 ;
}
2005-01-11 21:26:22 +01:00
2008-05-23 21:43:28 +02:00
/**
* Clear list of attached files ( store in SECTION array )
*/
function clear_attached_files ()
{
global $conf , $user ;
$conf -> users -> dir_tmp = DOL_DATA_ROOT . " /users/ " . $user -> id ;
$upload_dir = $conf -> users -> dir_tmp . '/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 )
*
* @ param unknown_type $path
* @ param unknown_type $file
* @ param unknown_type $type
*/
function add_attached_files ( $path , $file , $type )
{
$listofpaths = array ();
$listofnames = array ();
$listofmimes = array ();
if ( ! empty ( $_SESSION [ " listofpaths " ])) $listofpaths = split ( ';' , $_SESSION [ " listofpaths " ]);
if ( ! empty ( $_SESSION [ " listofnames " ])) $listofnames = split ( ';' , $_SESSION [ " listofnames " ]);
if ( ! empty ( $_SESSION [ " listofmimes " ])) $listofmimes = split ( ';' , $_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 );
}
}
2005-01-11 21:26:22 +01:00
2008-07-11 18:14:57 +02:00
/**
* Return list of attached files ( stored in SECTION array )
*
* @ return unknown_type $type
*/
function get_attached_files ()
{
$listofpaths = array ();
$listofnames = array ();
$listofmimes = array ();
if ( ! empty ( $_SESSION [ " listofpaths " ])) $listofpaths = split ( ';' , $_SESSION [ " listofpaths " ]);
if ( ! empty ( $_SESSION [ " listofnames " ])) $listofnames = split ( ';' , $_SESSION [ " listofnames " ]);
if ( ! empty ( $_SESSION [ " listofmimes " ])) $listofmimes = split ( ';' , $_SESSION [ " listofmimes " ]);
return array ( 'paths' => $listofpaths , 'names' => $listofnames , 'mimes' => $listofmimes );
}
2008-05-23 21:43:28 +02:00
/**
2008-07-17 01:37:34 +02:00
* \brief Affiche la partie de formulaire pour saisie d ' un mail en fonction des propri<EFBFBD> t<EFBFBD> s
* \param addfileaction Name of action when posting file attachments
* \remarks this -> withfile : 0 = No attaches files , 1 = Show attached files , 2 = Can add new attached files
2006-08-06 15:35:19 +02:00
*/
2008-07-17 01:37:34 +02:00
function show_form ( $addfileaction = 'addfile' )
2006-08-06 15:35:19 +02:00
{
global $conf , $langs , $user ;
$langs -> load ( " other " );
$langs -> load ( " mails " );
2008-05-23 21:43:28 +02:00
// Define list of attached files
$listofpaths = array ();
$listofnames = array ();
$listofmimes = array ();
if ( ! empty ( $_SESSION [ " listofpaths " ])) $listofpaths = split ( ';' , $_SESSION [ " listofpaths " ]);
if ( ! empty ( $_SESSION [ " listofnames " ])) $listofnames = split ( ';' , $_SESSION [ " listofnames " ]);
if ( ! empty ( $_SESSION [ " listofmimes " ])) $listofmimes = split ( ';' , $_SESSION [ " listofmimes " ]);
2006-08-06 15:35:19 +02:00
$form = new Form ( $DB );
print " \n <!-- Debut form mail --> \n " ;
print " <form method= \" post \" ENCTYPE= \" multipart/form-data \" action= \" " . $this -> param [ " returnurl " ] . " \" > \n " ;
foreach ( $this -> param as $key => $value )
{
print " <input type= \" hidden \" name= \" $key\ " value = \ " $value\ " > \n " ;
}
print " <table class= \" border \" width= \" 100% \" > \n " ;
2007-05-26 17:05:49 +02:00
// Substitution array
if ( $this -> withsubstit )
{
print " <tr><td colspan= \" 2 \" > " ;
$help = " " ;
foreach ( $this -> substit as $key => $val )
{
$help .= $key . ' -> ' . $langs -> trans ( $val ) . '<br>' ;
}
print $form -> textwithhelp ( $langs -> trans ( " EMailTestSubstitutionReplacedByGenericValues " ), $help );
print " </td></tr> \n " ;
}
2006-08-06 15:35:19 +02:00
// From
if ( $this -> withfrom )
{
if ( $this -> withfromreadonly )
{
print '<input type="hidden" name="fromname" value="' . $this -> fromname . '">' ;
print '<input type="hidden" name="frommail" value="' . $this -> frommail . '">' ;
2008-01-07 19:39:11 +01:00
print " <tr><td width= \" 180 \" > " . $langs -> trans ( " MailFrom " ) . " </td><td> " ;
if ( $this -> fromtype == 'user' )
{
$langs -> load ( " users " );
$fuser = new User ( $this -> db );
$fuser -> id = $this -> fromid ;
$fuser -> fetch ();
print $fuser -> getNomUrl ( 1 );
}
else
{
print $this -> fromname ;
}
if ( $this -> frommail )
{
print " < " . $this -> frommail . " > " ;
}
else
{
if ( $this -> fromtype )
{
$langs -> load ( " errors " );
print '<font class="warning"> <' . $langs -> trans ( " ErrorNoMailDefinedForThisUser " ) . '> </font>' ;
}
}
print " </td></tr> \n " ;
2006-08-06 15:35:19 +02:00
print " </td></tr> \n " ;
}
2008-06-01 18:31:51 +02:00
else
{
print " <tr><td> " . $langs -> trans ( " MailFrom " ) . " </td><td> " ;
print $langs -> trans ( " Name " ) . ':<input type="text" name="fromname" size="32" value="' . $this -> fromname . '">' ;
print ' ' ;
print $langs -> trans ( " EMail " ) . ':<<input type="text" name="frommail" size="32" value="' . $this -> frommail . '">>' ;
print " </td></tr> \n " ;
}
2006-08-06 15:35:19 +02:00
}
// Replyto
if ( $this -> withreplyto )
{
if ( $this -> withreplytoreadonly )
{
print '<input type="hidden" name="replyname" value="' . $this -> replytoname . '">' ;
print '<input type="hidden" name="replymail" value="' . $this -> replytomail . '">' ;
print " <tr><td> " . $langs -> trans ( " MailReply " ) . " </td><td> " . $this -> replytoname . ( $this -> replytomail ? ( " < " . $this -> replytomail . " > " ) : " " );
print " </td></tr> \n " ;
}
}
2007-07-30 16:44:47 +02:00
// Errorsto
if ( $this -> witherrorsto )
{
//if (! $this->errorstomail) $this->errorstomail=$this->frommail;
if ( $this -> witherrorstoreadonly )
{
print '<input type="hidden" name="errorstomail" value="' . $this -> errorstomail . '">' ;
print " <tr><td> " . $langs -> trans ( " MailErrorsTo " ) . " </td><td> " ;
print $this -> errorstomail ;
print " </td></tr> \n " ;
}
else
{
print " <tr><td> " . $langs -> trans ( " MailErrorsTo " ) . " </td><td> " ;
print " <input size= \" 30 \" name= \" errorstomail \" value= \" " . $this -> errorstomail . " \" > " ;
print " </td></tr> \n " ;
}
}
2006-08-06 15:35:19 +02:00
// To
if ( $this -> withto || is_array ( $this -> withto ))
{
print '<tr><td width="180">' . $langs -> trans ( " MailTo " ) . '</td><td>' ;
if ( $this -> withtoreadonly )
{
print ( ! is_array ( $this -> withto ) && ! is_numeric ( $this -> withto )) ? $this -> withto : " " ;
}
else
{
print " <input size= \" 30 \" name= \" sendto \" value= \" " . ( ! is_array ( $this -> withto ) && ! is_numeric ( $this -> withto ) ? $this -> withto : " " ) . " \" > " ;
if ( is_array ( $this -> withto ))
{
print " " . $langs -> trans ( " or " ) . " " ;
$form -> select_array ( " receiver " , $this -> withto );
}
}
print " </td></tr> \n " ;
}
// CC
2008-02-29 17:26:38 +01:00
if ( $this -> withtocc || is_array ( $this -> withtocc ))
2006-08-06 15:35:19 +02:00
{
print '<tr><td width="180">' . $langs -> trans ( " MailCC " ) . '</td><td>' ;
if ( $this -> withtoccreadonly )
{
print ( ! is_array ( $this -> withtocc ) && ! is_numeric ( $this -> withtocc )) ? $this -> withtocc : " " ;
}
else
{
print " <input size= \" 30 \" name= \" sendtocc \" value= \" " . (( ! is_array ( $this -> withtocc ) && ! is_numeric ( $this -> withtocc )) ? $this -> withtocc : " " ) . " \" > " ;
if ( is_array ( $this -> withtocc ))
{
print " " . $langs -> trans ( " or " ) . " " ;
$form -> select_array ( " receivercc " , $this -> withtocc );
}
}
print " </td></tr> \n " ;
}
2005-01-16 19:40:02 +01:00
2008-02-29 17:26:38 +01:00
// CC
if ( $this -> withtoccc || is_array ( $this -> withtoccc ))
{
print '<tr><td width="180">' . $langs -> trans ( " MailCCC " ) . '</td><td>' ;
if ( $this -> withtocccreadonly )
{
print ( ! is_array ( $this -> withtoccc ) && ! is_numeric ( $this -> withtoccc )) ? $this -> withtoccc : " " ;
}
else
{
print " <input size= \" 30 \" name= \" sendtocc \" value= \" " . (( ! is_array ( $this -> withtoccc ) && ! is_numeric ( $this -> withtoccc )) ? $this -> withtoccc : " " ) . " \" > " ;
if ( is_array ( $this -> withtoccc ))
{
print " " . $langs -> trans ( " or " ) . " " ;
$form -> select_array ( " receiverccc " , $this -> withtoccc );
}
}
print " </td></tr> \n " ;
}
2006-08-06 15:35:19 +02:00
// Accus<75> r<> ception
if ( $this -> withdeliveryreceipt )
{
print '<tr><td width="180">' . $langs -> trans ( " DeliveryReceipt " ) . '</td><td>' ;
2005-01-11 21:26:22 +01:00
2006-08-06 15:35:19 +02:00
if ( $this -> withdeliveryreceiptreadonly )
{
print yn ( $this -> withdeliveryreceipt );
}
else
{
2007-05-04 10:26:01 +02:00
print $form -> selectyesno ( 'deliveryreceipt' , 0 , 1 );
2006-08-06 15:35:19 +02:00
}
2005-01-11 21:26:22 +01:00
2006-08-06 15:35:19 +02:00
print " </td></tr> \n " ;
}
2005-01-11 21:26:22 +01:00
2006-08-06 15:35:19 +02:00
// Topic
if ( $this -> withtopic )
{
2007-05-26 17:05:49 +02:00
$this -> withtopic = make_substitutions ( $this -> withtopic , $this -> substit );
2005-01-11 21:26:22 +01:00
2006-08-06 15:35:19 +02:00
print " <tr> " ;
print " <td width= \" 180 \" > " . $langs -> trans ( " MailTopic " ) . " </td> " ;
print " <td> " ;
if ( $this -> withtopicreadonly )
{
print $this -> withtopic ;
print " <input type= \" hidden \" size= \" 60 \" name= \" subject \" value= \" " . $this -> withtopic . " \" > " ;
}
else
{
print " <input type= \" text \" size= \" 60 \" name= \" subject \" value= \" " . $this -> withtopic . " \" > " ;
}
print " </td></tr> \n " ;
}
2005-02-23 23:58:20 +01:00
2008-05-23 21:43:28 +02:00
// Attached files
2006-08-06 15:35:19 +02:00
if ( $this -> withfile )
{
print " <tr> " ;
2008-05-23 21:43:28 +02:00
print '<td width="180">' . $langs -> trans ( " MailFile " ) . " </td> " ;
2006-08-06 15:35:19 +02:00
print " <td> " ;
2008-05-23 21:43:28 +02:00
//print '<table class="nobordernopadding" width="100%"><tr><td>';
if ( sizeof ( $listofpaths ))
{
foreach ( $listofpaths as $key => $val )
{
print img_mime ( $listofnames [ $key ]) . ' ' . $listofnames [ $key ] . '<br>' ;
}
}
else
{
print $langs -> trans ( " NoAttachedFiles " ) . '<br>' ;
}
if ( $this -> withfile == 2 ) // Can add other files
{
//print '<td><td align="right">';
print " <input type= \" file \" class= \" flat \" name= \" addedfile \" value= \" " . $langs -> trans ( " Upload " ) . " \" /> " ;
print ' ' ;
2008-07-17 01:37:34 +02:00
print '<input type="submit" class="button" name="' . $addfileaction . '" value="' . $langs -> trans ( " MailingAddFile " ) . '">' ;
2008-05-23 21:43:28 +02:00
//print '</td></tr></table>';
}
2006-08-06 15:35:19 +02:00
print " </td></tr> \n " ;
}
2005-01-11 21:26:22 +01:00
2006-08-06 15:35:19 +02:00
// Message
if ( $this -> withbody )
{
$defaultmessage = " " ;
2005-01-11 21:26:22 +01:00
2006-08-06 15:35:19 +02:00
// \todo A partir du type, proposer liste de messages dans table llx_models
if ( $this -> param [ " models " ] == 'body' ) { $defaultmessage = $this -> withbody ; }
if ( $this -> param [ " models " ] == 'facture_send' ) { $defaultmessage = " Veuillez trouver ci-joint la facture __FACREF__ \n \n Cordialement \n \n " ; }
if ( $this -> param [ " models " ] == 'facture_relance' ) { $defaultmessage = " Nous apportons <20> votre connaissance que la facture __FACREF__ ne semble pas avoir <20> t<EFBFBD> r<> gl<67> e. La voici donc, pour rappel, en pi<70> ce jointe. \n \n Cordialement \n \n " ; }
if ( $this -> param [ " models " ] == 'propal_send' ) { $defaultmessage = " Veuillez trouver ci-joint la proposition commerciale __PROPREF__ \n \n Cordialement \n \n " ; }
if ( $this -> param [ " models " ] == 'order_send' ) { $defaultmessage = " Veuillez trouver ci-joint la commande __ORDERREF__ \n \n Cordialement \n \n " ; }
2005-01-11 21:26:22 +01:00
2007-06-01 17:33:15 +02:00
$defaultmessage = make_substitutions ( $defaultmessage , $this -> substit );
2005-01-11 21:26:22 +01:00
2006-08-06 15:35:19 +02:00
print " <tr> " ;
print " <td width= \" 180 \" valign= \" top \" > " . $langs -> trans ( " MailText " ) . " </td> " ;
print " <td> " ;
if ( $this -> withbodyreadonly )
{
print nl2br ( $defaultmessage );
print '<input type="hidden" name="message" value="' . $defaultmessage . '">' ;
}
else
{
2008-07-17 01:37:34 +02:00
if ( $this -> withfckeditor )
{
// Editeur wysiwyg
require_once ( DOL_DOCUMENT_ROOT . " /lib/doleditor.class.php " );
$doleditor = new DolEditor ( 'message' , $defaultmessage , 280 , 'dolibarr_notes' , 'In' , true );
$doleditor -> Create ();
}
else
{
print '<textarea cols="72" rows="8" name="message">' ;
print $defaultmessage ;
print '</textarea>' ;
}
2006-08-06 15:35:19 +02:00
}
print " </td></tr> \n " ;
}
print " <tr><td align=center colspan=2><center> " ;
print " <input class= \" button \" type= \" submit \" name= \" sendmail \" value= \" " . $langs -> trans ( " SendMail " ) . " \" > " ;
if ( $this -> withcancel )
{
print " " ;
print " <input class= \" button \" type= \" submit \" name= \" cancel \" value= \" " . $langs -> trans ( " Cancel " ) . " \" > " ;
}
print " </center></td></tr> \n " ;
print " </table> \n " ;
2005-01-11 21:26:22 +01:00
2006-08-06 15:35:19 +02:00
print " </form> \n " ;
print " <!-- Fin form mail --> \n " ;
}
2005-01-11 21:26:22 +01:00
/*
* \brief Affiche la partie de formulaire pour saisie d ' un mail
* \param withtopic 1 pour proposer <EFBFBD> la saisie le sujet
* \param withbody 1 pour proposer <EFBFBD> la saisie le corps du message
* \param withfile 1 pour proposer <EFBFBD> la saisie l 'ajout d' un fichier joint
* \todo Fonction a virer quand fichier / comm / mailing . php vir<EFBFBD> ( = quand ecran dans / comm / mailing prets )
*/
function mail_topicmessagefile ( $withtopic = 1 , $withbody = 1 , $withfile = 1 , $defaultbody ) {
global $langs ;
$langs -> load ( " other " );
print " <table class= \" border \" width= \" 100% \" > " ;
// Topic
if ( $withtopic )
{
print " <tr> " ;
print " <td width= \" 180 \" > " . $langs -> trans ( " MailTopic " ) . " </td> " ;
print " <td> " ;
print " <input type= \" text \" size= \" 60 \" name= \" subject \" value= \" \" > " ;
print " </td></tr> " ;
}
// Message
if ( $withbody )
{
print " <tr> " ;
print " <td width= \" 180 \" valign= \" top \" > " . $langs -> trans ( " MailText " ) . " </td> " ;
print " <td> " ;
print " <textarea rows= \" 8 \" cols= \" 72 \" name= \" message \" > " ;
print $defaultbody ;
print " </textarea> " ;
print " </td></tr> " ;
}
// Si fichier joint
if ( $withfile )
{
print " <tr> " ;
print " <td width= \" 180 \" > " . $langs -> trans ( " MailFile " ) . " </td> " ;
print " <td> " ;
print " <input type= \" file \" name= \" addedfile \" value= \" " . $langs -> trans ( " Upload " ) . " \" /> " ;
print " </td></tr> " ;
}
print " </table> " ;
}
}
?>