From 4edb72495d9723a49b5f4cccc04ba57f21f77ca2 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 17 Jun 2011 17:59:52 +0000 Subject: [PATCH] Fix: w3c Fix: possibility to use show_form in ajax --- htdocs/core/class/html.formmail.class.php | 232 ++++++++++++---------- htdocs/lib/doleditor.class.php | 32 +-- 2 files changed, 147 insertions(+), 117 deletions(-) diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 0ef1a7417d1..1f505734d4d 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -35,6 +35,8 @@ require_once(DOL_DOCUMENT_ROOT ."/core/class/html.form.class.php"); class FormMail { var $db; + + var $withform; var $fromname; var $frommail; @@ -72,6 +74,8 @@ class FormMail function FormMail($DB) { $this->db = $DB; + + $this->withform=1; $this->withfrom=1; $this->withto=1; @@ -178,7 +182,7 @@ class FormMail if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]); return array('paths'=>$listofpaths, 'names'=>$listofnames, 'mimes'=>$listofmimes); } - + /** * Show the form to input an email * this->withfile: 0=No attaches files, 1=Show attached files, 2=Can add new attached files @@ -186,11 +190,24 @@ class FormMail * @param removefileaction Name of action when removing file attachments */ function show_form($addfileaction='addfile',$removefileaction='removefile') + { + print $this->get_form($addfileaction,$removefileaction); + } + + /** + * Get the form to input an email + * this->withfile: 0=No attaches files, 1=Show attached files, 2=Can add new attached files + * @param addfileaction Name of action when posting file attachments + * @param removefileaction Name of action when removing file attachments + */ + function get_form($addfileaction='addfile',$removefileaction='removefile') { global $conf, $langs, $user; $langs->load("other"); $langs->load("mails"); + + $out=''; // Define list of attached files $listofpaths=array(); @@ -203,26 +220,29 @@ class FormMail $form=new Form($DB); - print "\n\n"; - print "
param["returnurl"]."\">\n"; - print ''; + $out.= "\n\n"; + if ($this->withform) + { + $out.= ''."\n"; + $out.= ''; + } foreach ($this->param as $key=>$value) { - print "\n"; + $out.= ''."\n"; } - print "\n"; + $out.= '
'."\n"; // Substitution array if ($this->withsubstit) { - print "\n"; + $out.= $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"),$help); + $out.= "\n"; } // From @@ -230,42 +250,42 @@ class FormMail { if ($this->withfromreadonly) { - print ''; - print ''; - print "\n"; - print "\n"; + $out.= "\n"; + $out.= "\n"; } else { - print "\n"; + $out.= "\n"; } } @@ -274,10 +294,10 @@ class FormMail { if ($this->withreplytoreadonly) { - print ''; - print ''; - print "\n"; + $out.= ''; + $out.= ''; + $out.= "\n"; } } @@ -287,32 +307,32 @@ class FormMail //if (! $this->errorstomail) $this->errorstomail=$this->frommail; if ($this->witherrorstoreadonly) { - print ''; - print "\n"; + $out.= ''; + $out.= '\n"; } else { - print "\n"; + $out.= '\n"; } } // To if ($this->withto || is_array($this->withto)) { - print '\n"; + $out.= "\n"; } // CC if ($this->withtocc || is_array($this->withtocc)) { - print '\n"; + $out.= "\n"; } // CCC if ($this->withtoccc || is_array($this->withtoccc)) { - print '\n"; + $out.= "\n"; } // Ask delivery receipt if ($this->withdeliveryreceipt) { - print '\n"; + $out.= "\n"; } // Topic @@ -414,50 +434,50 @@ class FormMail { $this->withtopic=make_substitutions($this->withtopic,$this->substit); - print ""; - print ""; - print "'; + $out.= ''; + $out.= '\n"; + $out.= "\n"; } // Attached files if ($this->withfile) { - print ""; - print '"; - print "'; + $out.= ''; + $out.= '\n"; + $out.= "\n"; } // Message @@ -497,42 +517,48 @@ class FormMail if (isset($_POST["message"])) $defaultmessage=$_POST["message"]; $defaultmessage=str_replace('\n',"\n",$defaultmessage); - print ""; - print ""; - print "'; + $out.= ''; + $out.= '\n"; + $out.= "\n"; } - - print "'."\n"; } - print ">"; - if ($this->withcancel) - { - print "     "; - print "trans("Cancel")."\">"; - } - print "\n"; - print "
"; + $out.= '
'; $help=""; foreach($this->substit as $key => $val) { $help.=$key.' -> '.$langs->trans($val).'
'; } - print $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"),$help); - print "
".$langs->trans("MailFrom").""; + $out.= ''; + $out.= ''; + $out.= '
'.$langs->trans("MailFrom").''; if ($this->fromtype == 'user') { $langs->load("users"); $fuser=new User($this->db); $fuser->fetch($this->fromid); - print $fuser->getNomUrl(1); + $out.= $fuser->getNomUrl(1); } else { - print $this->fromname; + $out.= $this->fromname; } if ($this->frommail) { - print " <".$this->frommail.">"; + $out.= " <".$this->frommail.">"; } else { if ($this->fromtype) { $langs->load("errors"); - print ' <'.$langs->trans("ErrorNoMailDefinedForThisUser").'> '; + $out.= ' <'.$langs->trans("ErrorNoMailDefinedForThisUser").'> '; } } - print "
".$langs->trans("MailFrom").""; - print $langs->trans("Name").':'; - print '    '; - print $langs->trans("EMail").':<>'; - print "
".$langs->trans("MailFrom").""; + $out.= $langs->trans("Name").':'; + $out.= '    '; + $out.= $langs->trans("EMail").':<>'; + $out.= "
".$langs->trans("MailReply")."".$this->replytoname.($this->replytomail?(" <".$this->replytomail.">"):""); - print "
".$langs->trans("MailReply")."".$this->replytoname.($this->replytomail?(" <".$this->replytomail.">"):""); + $out.= "
".$langs->trans("MailErrorsTo").""; - print $this->errorstomail; - print "
'.$langs->trans("MailErrorsTo").''; + $out.= $this->errorstomail; + $out.= "
".$langs->trans("MailErrorsTo").""; - print "errorstomail."\">"; - print "
'.$langs->trans("MailErrorsTo").''; + $out.= ''; + $out.= "
'; - print $form->textwithpicto($langs->trans("MailTo"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients")); - print ''; + $out.= '
'; + $out.= $form->textwithpicto($langs->trans("MailTo"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients")); + $out.= ''; if ($this->withtoreadonly) { - print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:""; + $out.= (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:""; } else { - print "withto)?"30":"60")."\" name=\"sendto\" value=\"".(! is_array($this->withto) && ! is_numeric($this->withto)? (isset($_REQUEST["sendto"])?$_REQUEST["sendto"]:$this->withto) :"")."\">"; + $out.= 'withto) :"").'" />'; if ($this->withtosocid > 0) { $liste=array(); @@ -323,27 +343,27 @@ class FormMail { $liste[$key]=$value; } - print " ".$langs->trans("or")." "; + $out.= " ".$langs->trans("or")." "; //var_dump($_REQUEST);exit; - print $form->selectarray("receiver", $liste, isset($_REQUEST["receiver"])?$_REQUEST["receiver"]:0); + $out.= $form->selectarray("receiver", $liste, isset($_REQUEST["receiver"])?$_REQUEST["receiver"]:0); } } - print "
'; - print $form->textwithpicto($langs->trans("MailCC"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients")); - print ''; + $out.= '
'; + $out.= $form->textwithpicto($langs->trans("MailCC"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients")); + $out.= ''; if ($this->withtoccreadonly) { - print (! is_array($this->withtocc) && ! is_numeric($this->withtocc))?$this->withtocc:""; + $out.= (! is_array($this->withtocc) && ! is_numeric($this->withtocc))?$this->withtocc:""; } else { - print "withtocc)?"30":"60")."\" name=\"sendtocc\" value=\"".((! is_array($this->withtocc) && ! is_numeric($this->withtocc))? (isset($_POST["sendtocc"])?$_POST["sendtocc"]:$this->withtocc) : (isset($_POST["sendtocc"])?$_POST["sendtocc"]:"") )."\">"; + $out.= 'withtocc) : (isset($_POST["sendtocc"])?$_POST["sendtocc"]:"") ).'" />'; if ($this->withtoccsocid > 0) { $liste=array(); @@ -354,26 +374,26 @@ class FormMail { $liste[$key]=$value; } - print " ".$langs->trans("or")." "; - print $form->selectarray("receivercc", $liste, isset($_REQUEST["receivercc"])?$_REQUEST["receivercc"]:0); + $out.= " ".$langs->trans("or")." "; + $out.= $form->selectarray("receivercc", $liste, isset($_REQUEST["receivercc"])?$_REQUEST["receivercc"]:0); } } - print "
'; - print $form->textwithpicto($langs->trans("MailCCC"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients")); - print ''; + $out.= '
'; + $out.= $form->textwithpicto($langs->trans("MailCCC"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients")); + $out.= ''; if ($this->withtocccreadonly) { - print (! is_array($this->withtoccc) && ! is_numeric($this->withtoccc))?$this->withtoccc:""; + $out.= (! is_array($this->withtoccc) && ! is_numeric($this->withtoccc))?$this->withtoccc:""; } else { - print "withtoccc)?"30":"60")."\" name=\"sendtoccc\" value=\"".((! is_array($this->withtoccc) && ! is_numeric($this->withtoccc))? (isset($_POST["sendtoccc"])?$_POST["sendtoccc"]:$this->withtoccc) : (isset($_POST["sendtoccc"])?$_POST["sendtoccc"]:"") )."\">"; + $out.= 'withtoccc) : (isset($_POST["sendtoccc"])?$_POST["sendtoccc"]:"") ).'" />'; if ($this->withtocccsocid > 0) { $liste=array(); @@ -384,29 +404,29 @@ class FormMail { $liste[$key]=$value; } - print " ".$langs->trans("or")." "; - print $form->selectarray("receiverccc", $liste, isset($_REQUEST["receiverccc"])?$_REQUEST["receiverccc"]:0); + $out.= " ".$langs->trans("or")." "; + $out.= $form->selectarray("receiverccc", $liste, isset($_REQUEST["receiverccc"])?$_REQUEST["receiverccc"]:0); } } //if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) print ' '.info_admin("+ ".$conf->global->MAIN_MAIL_AUTOCOPY_TO,1); - print "
'.$langs->trans("DeliveryReceipt").''; + $out.= '
'.$langs->trans("DeliveryReceipt").''; if ($this->withdeliveryreceiptreadonly) { - print yn($this->withdeliveryreceipt); + $out.= yn($this->withdeliveryreceipt); } else { - print $form->selectyesno('deliveryreceipt', (isset($_POST["deliveryreceipt"])?$_POST["deliveryreceipt"]:0) ,1); + $out.= $form->selectyesno('deliveryreceipt', (isset($_POST["deliveryreceipt"])?$_POST["deliveryreceipt"]:0) ,1); } - print "
".$langs->trans("MailTopic").""; + $out.= '
'.$langs->trans("MailTopic").''; if ($this->withtopicreadonly) { - print $this->withtopic; - print "withtopic."\">"; + $out.= $this->withtopic; + $out.= ''; } else { - print "withtopic) ."\">"; + $out.= 'withtopic) .'" />'; } - print "
'.$langs->trans("MailFile").""; + $out.= '
'.$langs->trans("MailFile").''; //print '
'; if (sizeof($listofpaths)) { foreach($listofpaths as $key => $val) { - print img_mime($listofnames[$key]).' '.$listofnames[$key]; - print ' '; - print '
'; + $out.= img_mime($listofnames[$key]).' '.$listofnames[$key]; + $out.= ' '; + $out.= '
'; } } else { - print $langs->trans("NoAttachedFiles").'
'; + $out.= $langs->trans("NoAttachedFiles").'
'; } if ($this->withfile == 2) // Can add other files { //print '
'; - print ''; - print ' '; - print ''; + $out.= ''; + $out.= ' '; + $out.= ''; //print '
'; } - print "
".$langs->trans("MailText").""; + $out.= '
'.$langs->trans("MailText").''; if ($this->withbodyreadonly) { - print nl2br($defaultmessage); - print ''; + $out.= nl2br($defaultmessage); + $out.= ''; } else { // Editeur wysiwyg require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); $doleditor=new DolEditor('message',$defaultmessage,'',280,'dolibarr_notes','In',true,false,$this->withfckeditor,8,72); - $doleditor->Create(); + $out.= $doleditor->Create(1); } - print "
"; - 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) + + if ($this->withform) { - print ' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans("FileWasNotUploaded")).'\'); return false; } else { return true; }"'; + $out.= '
'; + $out.= '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.= ''; + } + $out.= '
\n"; + + $out.= ''."\n"; - print "
\n"; - print "\n"; + if ($this->withform) $out.= ''."\n"; + $out.= "\n"; + + return $out; } diff --git a/htdocs/lib/doleditor.class.php b/htdocs/lib/doleditor.class.php index 5cac53b2bdb..e8c575dd7cf 100644 --- a/htdocs/lib/doleditor.class.php +++ b/htdocs/lib/doleditor.class.php @@ -134,11 +134,12 @@ class DolEditor /** * Output edit area inside the HTML stream */ - function Create() + function Create($noprint=0) { global $conf; $found=0; + $out=''; if ($this->tool == 'fckeditor') { @@ -148,9 +149,9 @@ class DolEditor if (in_array($this->tool,array('textarea','ckeditor'))) { $found=1; - print ''; + $out.= ''; if ($this->tool == 'ckeditor') { @@ -161,7 +162,7 @@ class DolEditor //$skin='v2'; $skin='kama'; - print '