From 473345d839c2b639b4ac10bad9e7113ec5d7bcbb Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 12 Jan 2010 23:03:34 +0000 Subject: [PATCH] Add a warning to avoid to forget to attach file --- htdocs/html.formmail.class.php | 34 ++++++++++++++++++++-------------- htdocs/langs/en_US/main.lang | 1 + htdocs/langs/fr_FR/main.lang | 1 + htdocs/lib/CMailFile.class.php | 32 ++++++++++++++++---------------- htdocs/lib/functions.lib.php | 2 +- 5 files changed, 39 insertions(+), 31 deletions(-) diff --git a/htdocs/html.formmail.class.php b/htdocs/html.formmail.class.php index 05ffbdc345f..a865390b0c6 100644 --- a/htdocs/html.formmail.class.php +++ b/htdocs/html.formmail.class.php @@ -17,20 +17,20 @@ */ /** - \file htdocs/html.formmail.class.php - \brief Fichier de la classe permettant la generation du formulaire html d'envoi de mail unitaire - \version $Id$ -*/ + * \file htdocs/html.formmail.class.php + * \brief Fichier de la classe permettant la generation 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 generation 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 -*/ + * \brief Classe permettant la generation 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; @@ -65,9 +65,9 @@ class FormMail /** - \brief Constructeur - \param DB handler d'acces base de donnee - */ + * \brief Constructeur + * \param DB handler d'acces base de donnee + */ function FormMail($DB) { $this->db = $DB; @@ -176,7 +176,7 @@ class FormMail $form=new Form($DB); print "\n\n"; - print "
param["returnurl"]."\">\n"; + print "param["returnurl"]."\">\n"; print ''; foreach ($this->param as $key=>$value) { @@ -475,7 +475,13 @@ class FormMail } print "
"; - print "trans("SendMail")."\">"; + print "trans("SendMail")."\""; + // Add a javascript test to avoid to forget to submit file before sending email + if ($this->withfile == 2 && $conf->use_javascript_ajax) + { + print ' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans("FileWasNotUploaded")).'\'); return false; } else { return true; }"'; + } + print ">"; if ($this->withcancel) { print "     "; diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index d288a69cf72..f134e8d680c 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -47,6 +47,7 @@ ErrorFailedToSaveFile=Error, failed to save file. ErrorOnlyPngJpgSupported=Error, only .png and .jpg image format file are supported. ErrorImageFormatNotSupported=Your PHP does not support functions to convert images of this format. BackgroundColorByDefault=Default background color +FileWasNotUploaded=A file is selected for attachment but was not yet uploaded. Click on "Attach file" for this. NbOfEntries=Nb of entries GoToWikiHelpPage=Read online help (need Internet access) GoToHelpPage=Read help diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index 4b62f86d55f..78f5a00249a 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -47,6 +47,7 @@ ErrorFailedToSaveFile=Erreur, l'enregistrement du fichier a échoué. ErrorOnlyPngJpgSupported=Erreur, seuls les formats images .jpg et .png sont supportés. ErrorImageFormatNotSupported=Votre PHP ne supporte pas les fonctions de conversion de ce format d'image. BackgroundColorByDefault=Couleur de fond +FileWasNotUploaded=Un fichier a été sélectionné pour attachement mais n'a pas encore été uploadé. Cliquer sur "Joindre ce fichier" pour cela. NbOfEntries=Nb d'entrées GoToWikiHelpPage=Consulter l'aide (nécessite un accès internet) GoToHelpPage=Consulter l'aide diff --git a/htdocs/lib/CMailFile.class.php b/htdocs/lib/CMailFile.class.php index 643883c35e1..ae448357bb1 100644 --- a/htdocs/lib/CMailFile.class.php +++ b/htdocs/lib/CMailFile.class.php @@ -196,7 +196,7 @@ class CMailFile $this->css = $css; $this->buildCSS(); } - + $msg = $this->html; } @@ -397,7 +397,7 @@ class CMailFile /** * Send mail that was prepared by constructor - * + * * @return boolean True if mail sent, false otherwise */ function sendfile() @@ -597,7 +597,7 @@ class CMailFile /** * Read a file on disk and return encoded content for emails - * + * * @param sourcefile * @return <0 if KO, encoded string if OK */ @@ -650,7 +650,7 @@ class CMailFile /** * Create SMTP headers - * + * * @return smtp headers */ function write_smtpheaders() @@ -680,7 +680,7 @@ class CMailFile $out.= "Content-Type: multipart/mixed; boundary=\"".$this->mime_boundary."\"".$this->eol; $out.= "Content-Transfer-Encoding: 8bit".$this->eol; - $out.=$this->eol; + //$out.=$this->eol; // Comment this to try to solve pb of hidden attached files dol_syslog("CMailFile::write_smtpheaders smtp_header=\n".$out); return $out; } @@ -688,7 +688,7 @@ class CMailFile /** * Creation header MIME - * + * * @param filename_list * @param mimefilename_list * @return mime headers @@ -716,7 +716,7 @@ class CMailFile /** * Permet d'ecrire le corps du message (mode = 'mail') - * + * * @param msgtext */ function write_body($msgtext) @@ -813,7 +813,7 @@ class CMailFile /** * Permet d'attacher un fichier - * + * * @param filename_list Tableau * @param mimetype_list Tableau * @param mimefilename_list Tableau @@ -857,7 +857,7 @@ class CMailFile /** * Permet d'attacher une image - * + * * @param images_list Tableau * @return out Chaine images encodees */ @@ -963,7 +963,7 @@ class CMailFile /** * Recherche la presence d'images dans le message html - * + * * @param images_dir Emplacement des images * @return int >0 if OK, <0 if KO */ @@ -982,22 +982,22 @@ class CMailFile if (preg_match('/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i',$full,$regs)) { $img = $regs[1]; - + if (file_exists($images_dir.'/'.$img)) { // Image path in src $src = preg_quote($full,'/'); - + // Image full path $this->html_images[$i]["fullpath"] = $images_dir.'/'.$img; - + // Image name $this->html_images[$i]["name"] = $img; - + // Content type $ext = preg_replace('/^.*\.(\w{3,4})$/e', 'strtolower("$1")', $img); $this->html_images[$i]["content_type"] = $this->image_types[$ext]; - + // cid $this->html_images[$i]["cid"] = md5(uniqid(time())); $this->html = preg_replace("/src=\"$src\"|src='$src'/i", "src=\"cid:".$this->html_images[$i]["cid"]."\"", $this->html); @@ -1052,7 +1052,7 @@ class CMailFile /** * Return an address for SMTP protocol - * + * * @param adresses Example: 'John Doe ' or 'john@doe.com' * @param format 0=Auto, 1=emails with <>, 2=emails without <> * @param encode 1=Encode name to RFC2822 diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index c7ab9fa1adc..eb306707a7e 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -181,7 +181,7 @@ function dol_string_nospecial($str,$newstr='_') function dol_escape_js($stringtoescape) { // escape quotes and backslashes, newlines, etc. - return strtr($stringtoescape, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n',''<\/')); + return strtr($stringtoescape, array("'"=>"\\'",'\\'=>'\\\\',"'"=>"\\'",'"'=>"\\'","\r"=>'\\r',"\n"=>'\\n',''<\/')); }