* * 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. */ /** \file htdocs/html.formmail.class.php \brief Fichier de la classe permettant la g�n�ration du formulaire html d'envoi de mail unitaire \version $Id$ */ require_once(DOL_DOCUMENT_ROOT ."/html.form.class.php"); /** \class FormMail \brief Classe permettant la g�n�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 { var $db; var $fromname; var $frommail; var $replytoname; var $replytomail; var $toname; var $tomail; var $withsubstit; // Show substitution array var $withfrom; var $withto; var $withtocc; 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; var $withtopicreadonly; var $withdeliveryreceipt; var $withcancel; var $substit=array(); var $param=array(); var $error; /** \brief Constructeur \param DB handler d'acc�s base de donn�e */ function FormMail($DB) { $this->db = $DB; $this->withfrom=1; $this->withto=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; $this->witherrorstoreadonly=0; $this->withtopicreadonly=0; $this->withbodyreadonly=0; $this->withdeliveryreceiptreadonly=0; return 1; } /** * Clear list of attached files in send mail form (stored in session) */ 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); } } /** * 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); } /** * \brief Affiche la partie de formulaire pour saisie d'un mail en fonction des propri�t�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 */ function show_form($addfileaction='addfile') { global $conf, $langs, $user; $langs->load("other"); $langs->load("mails"); // 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"]); $form=new Form($DB); print "\n\n"; print "
param["returnurl"]."\">\n"; foreach ($this->param as $key=>$value) { print "\n"; } print "\n"; // Substitution array if ($this->withsubstit) { print "\n"; } // From if ($this->withfrom) { if ($this->withfromreadonly) { print ''; print ''; print "\n"; print "\n"; } else { print "\n"; } } // Replyto if ($this->withreplyto) { if ($this->withreplytoreadonly) { print ''; print ''; print "\n"; } } // Errorsto if ($this->witherrorsto) { //if (! $this->errorstomail) $this->errorstomail=$this->frommail; if ($this->witherrorstoreadonly) { print ''; print "\n"; } else { print "\n"; } } // To if ($this->withto || is_array($this->withto)) { print '\n"; } // CC if ($this->withtocc || is_array($this->withtocc)) { print '\n"; } // CCC if ($this->withtoccc || is_array($this->withtoccc)) { print '\n"; } // Ask delivery receipt if ($this->withdeliveryreceipt) { print '\n"; } // Topic if ($this->withtopic) { $this->withtopic=make_substitutions($this->withtopic,$this->substit); print ""; print ""; print "\n"; } // Attached files if ($this->withfile) { print ""; print '"; print "\n"; } // Message if ($this->withbody) { $defaultmessage=""; // \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=$langs->transnoentities("PredefinedMailContentSendInvoice"); } if ($this->param["models"]=='facture_relance') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendInvoiceReminder"); } if ($this->param["models"]=='propal_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendProposal"); } if ($this->param["models"]=='order_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendOrder"); } $defaultmessage=make_substitutions($defaultmessage,$this->substit); print ""; print ""; print "\n"; } print "\n"; print "
"; $help=""; foreach($this->substit as $key => $val) { $help.=$key.' -> '.$langs->trans($val).'
'; } print $form->textwithhelp($langs->trans("EMailTestSubstitutionReplacedByGenericValues"),$help); print "
".$langs->trans("MailFrom").""; 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 ' <'.$langs->trans("ErrorNoMailDefinedForThisUser").'> '; } } print "
".$langs->trans("MailFrom").""; print $langs->trans("Name").':'; print '    '; print $langs->trans("EMail").':<>'; print "
".$langs->trans("MailReply")."".$this->replytoname.($this->replytomail?(" <".$this->replytomail.">"):""); print "
".$langs->trans("MailErrorsTo").""; print $this->errorstomail; print "
".$langs->trans("MailErrorsTo").""; print "errorstomail."\">"; print "
'.$langs->trans("MailTo").''; if ($this->withtoreadonly) { print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:""; } else { print "withto) && ! is_numeric($this->withto)?$this->withto:"")."\">"; if (is_array($this->withto)) { print " ".$langs->trans("or")." "; $form->select_array("receiver",$this->withto); } } print "
'.$langs->trans("MailCC").''; if ($this->withtoccreadonly) { print (! is_array($this->withtocc) && ! is_numeric($this->withtocc))?$this->withtocc:""; } else { print "withtocc) && ! is_numeric($this->withtocc))?$this->withtocc:"")."\">"; if (is_array($this->withtocc)) { print " ".$langs->trans("or")." "; $form->select_array("receivercc",$this->withtocc); } } print "
'.$langs->trans("MailCCC").''; if ($this->withtocccreadonly) { print (! is_array($this->withtoccc) && ! is_numeric($this->withtoccc))?$this->withtoccc:""; } else { print "withtoccc) && ! is_numeric($this->withtoccc))?$this->withtoccc:"")."\">"; if (is_array($this->withtoccc)) { print " ".$langs->trans("or")." "; $form->select_array("receiverccc",$this->withtoccc); } } print "
'.$langs->trans("DeliveryReceipt").''; if ($this->withdeliveryreceiptreadonly) { print yn($this->withdeliveryreceipt); } else { print $form->selectyesno('deliveryreceipt',0,1); } print "
".$langs->trans("MailTopic").""; if ($this->withtopicreadonly) { print $this->withtopic; print "withtopic."\">"; } else { print "withtopic."\">"; } print "
'.$langs->trans("MailFile").""; //print '
'; if (sizeof($listofpaths)) { foreach($listofpaths as $key => $val) { print img_mime($listofnames[$key]).' '.$listofnames[$key].'
'; } } else { print $langs->trans("NoAttachedFiles").'
'; } if ($this->withfile == 2) // Can add other files { //print '
'; print "trans("Upload")."\"/>"; print ' '; print ''; //print '
'; } print "
".$langs->trans("MailText").""; if ($this->withbodyreadonly) { print nl2br($defaultmessage); print ''; } else { 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 ''; } } print "
"; print "trans("SendMail")."\">"; if ($this->withcancel) { print "     "; print "trans("Cancel")."\">"; } print "
\n"; print "
\n"; print "\n"; } /* * \brief Affiche la partie de formulaire pour saisie d'un mail * \param withtopic 1 pour proposer � la saisie le sujet * \param withbody 1 pour proposer � la saisie le corps du message * \param withfile 1 pour proposer � la saisie l'ajout d'un fichier joint * \todo Fonction a virer quand fichier /comm/mailing.php vir� (= quand ecran dans /comm/mailing prets) */ function mail_topicmessagefile($withtopic=1,$withbody=1,$withfile=1,$defaultbody) { global $langs; $langs->load("other"); print ""; // Topic if ($withtopic) { print ""; print ""; print ""; } // Message if ($withbody) { print ""; print ""; print ""; } // Si fichier joint if ($withfile) { print ""; print ""; print ""; } print "
".$langs->trans("MailTopic").""; print ""; print "
".$langs->trans("MailText").""; print ""; print "
".$langs->trans("MailFile").""; print "trans("Upload")."\"/>"; print "
"; } } ?>