PageRenderTime 47ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/class/html.formmail.class.php

https://github.com/asterix14/dolibarr
PHP | 637 lines | 494 code | 56 blank | 87 comment | 89 complexity | 1f10842b32c49a093de119f9a2ea5dee MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?PHP
  2. /* Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  4. * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/core/class/html.formmail.class.php
  21. * \ingroup core
  22. * \brief Fichier de la classe permettant la generation du formulaire html d'envoi de mail unitaire
  23. */
  24. require_once(DOL_DOCUMENT_ROOT ."/core/class/html.form.class.php");
  25. /** \class FormMail
  26. * \brief Classe permettant la generation du formulaire html d'envoi de mail unitaire
  27. * \remarks Utilisation: $formail = new FormMail($db)
  28. * \remarks $formmail->proprietes=1 ou chaine ou tableau de valeurs
  29. * \remarks $formmail->show_form() affiche le formulaire
  30. */
  31. class FormMail
  32. {
  33. var $db;
  34. var $withform;
  35. var $fromname;
  36. var $frommail;
  37. var $replytoname;
  38. var $replytomail;
  39. var $toname;
  40. var $tomail;
  41. var $withsubstit; // Show substitution array
  42. var $withfrom;
  43. var $withto;
  44. var $withtofree;
  45. var $withtocc;
  46. var $withtopic;
  47. var $withfile; // 0=No attaches files, 1=Show attached files, 2=Can add new attached files
  48. var $withbody;
  49. var $withfromreadonly;
  50. var $withreplytoreadonly;
  51. var $withtoreadonly;
  52. var $withtoccreadonly;
  53. var $withtopicreadonly;
  54. var $withfilereadonly;
  55. var $withdeliveryreceipt;
  56. var $withcancel;
  57. var $substit=array();
  58. var $param=array();
  59. var $error;
  60. /**
  61. * \brief Constructeur
  62. * \param DB handler d'acces base de donnee
  63. */
  64. function FormMail($DB)
  65. {
  66. $this->db = $DB;
  67. $this->withform=1;
  68. $this->withfrom=1;
  69. $this->withto=1;
  70. $this->withtofree=1;
  71. $this->withtocc=1;
  72. $this->withtoccc=0;
  73. $this->witherrorsto=0;
  74. $this->withtopic=1;
  75. $this->withfile=0;
  76. $this->withbody=1;
  77. $this->withfromreadonly=1;
  78. $this->withreplytoreadonly=1;
  79. $this->withtoreadonly=0;
  80. $this->withtoccreadonly=0;
  81. $this->witherrorstoreadonly=0;
  82. $this->withtopicreadonly=0;
  83. $this->withfilereadonly=0;
  84. $this->withbodyreadonly=0;
  85. $this->withdeliveryreceiptreadonly=0;
  86. return 1;
  87. }
  88. /**
  89. * Clear list of attached files in send mail form (stored in session)
  90. */
  91. function clear_attached_files()
  92. {
  93. global $conf,$user;
  94. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  95. // Set tmp user directory
  96. $vardir=$conf->user->dir_output."/".$user->id;
  97. $upload_dir = $vardir.'/temp/';
  98. if (is_dir($upload_dir)) dol_delete_dir_recursive($upload_dir);
  99. unset($_SESSION["listofpaths"]);
  100. unset($_SESSION["listofnames"]);
  101. unset($_SESSION["listofmimes"]);
  102. }
  103. /**
  104. * Add a file into the list of attached files (stored in SECTION array)
  105. *
  106. * @param string $path Full absolute path on filesystem of file, including file name
  107. * @param string $file Only filename
  108. * @param string $type Mime type
  109. */
  110. function add_attached_files($path,$file,$type)
  111. {
  112. $listofpaths=array();
  113. $listofnames=array();
  114. $listofmimes=array();
  115. if (! empty($_SESSION["listofpaths"])) $listofpaths=explode(';',$_SESSION["listofpaths"]);
  116. if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
  117. if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
  118. if (! in_array($file,$listofnames))
  119. {
  120. $listofpaths[]=$path;
  121. $listofnames[]=$file;
  122. $listofmimes[]=$type;
  123. $_SESSION["listofpaths"]=join(';',$listofpaths);
  124. $_SESSION["listofnames"]=join(';',$listofnames);
  125. $_SESSION["listofmimes"]=join(';',$listofmimes);
  126. }
  127. }
  128. /**
  129. * Remove a file from the list of attached files (stored in SECTION array)
  130. *
  131. * @param $keytodelete Key in file array
  132. */
  133. function remove_attached_files($keytodelete)
  134. {
  135. $listofpaths=array();
  136. $listofnames=array();
  137. $listofmimes=array();
  138. if (! empty($_SESSION["listofpaths"])) $listofpaths=explode(';',$_SESSION["listofpaths"]);
  139. if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
  140. if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
  141. if ($keytodelete >= 0)
  142. {
  143. unset ($listofpaths[$keytodelete]);
  144. unset ($listofnames[$keytodelete]);
  145. unset ($listofmimes[$keytodelete]);
  146. $_SESSION["listofpaths"]=join(';',$listofpaths);
  147. $_SESSION["listofnames"]=join(';',$listofnames);
  148. $_SESSION["listofmimes"]=join(';',$listofmimes);
  149. //var_dump($_SESSION['listofpaths']);
  150. }
  151. }
  152. /**
  153. * Return list of attached files (stored in SECTION array)
  154. *
  155. * @return array array('paths'=> ,'names'=>, 'mimes'=> )
  156. */
  157. function get_attached_files()
  158. {
  159. $listofpaths=array();
  160. $listofnames=array();
  161. $listofmimes=array();
  162. if (! empty($_SESSION["listofpaths"])) $listofpaths=explode(';',$_SESSION["listofpaths"]);
  163. if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
  164. if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
  165. return array('paths'=>$listofpaths, 'names'=>$listofnames, 'mimes'=>$listofmimes);
  166. }
  167. /**
  168. * Show the form to input an email
  169. * this->withfile: 0=No attaches files, 1=Show attached files, 2=Can add new attached files
  170. *
  171. * @param addfileaction Name of action when posting file attachments
  172. * @param removefileaction Name of action when removing file attachments
  173. */
  174. function show_form($addfileaction='addfile',$removefileaction='removefile')
  175. {
  176. print $this->get_form($addfileaction,$removefileaction);
  177. }
  178. /**
  179. * Get the form to input an email
  180. * this->withfile: 0=No attaches files, 1=Show attached files, 2=Can add new attached files
  181. *
  182. * @param addfileaction Name of action when posting file attachments
  183. * @param removefileaction Name of action when removing file attachments
  184. */
  185. function get_form($addfileaction='addfile',$removefileaction='removefile')
  186. {
  187. global $conf, $langs, $user;
  188. $langs->load("other");
  189. $langs->load("mails");
  190. $out='';
  191. // Define list of attached files
  192. $listofpaths=array();
  193. $listofnames=array();
  194. $listofmimes=array();
  195. if (! empty($_SESSION["listofpaths"])) $listofpaths=explode(';',$_SESSION["listofpaths"]);
  196. if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
  197. if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
  198. $form=new Form($DB);
  199. $out.= "\n<!-- Debut form mail -->\n";
  200. if ($this->withform)
  201. {
  202. $out.= '<form method="POST" name="mailform" enctype="multipart/form-data" action="'.$this->param["returnurl"].'">'."\n";
  203. $out.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
  204. }
  205. foreach ($this->param as $key=>$value)
  206. {
  207. $out.= '<input type="hidden" id="'.$key.'" name="'.$key.'" value="'.$value.'" />'."\n";
  208. }
  209. $out.= '<table class="border" width="100%">'."\n";
  210. // Substitution array
  211. if ($this->withsubstit)
  212. {
  213. $out.= '<tr><td colspan="2">';
  214. $help="";
  215. foreach($this->substit as $key => $val)
  216. {
  217. $help.=$key.' -> '.$langs->trans($val).'<br>';
  218. }
  219. $out.= $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"),$help);
  220. $out.= "</td></tr>\n";
  221. }
  222. // From
  223. if ($this->withfrom)
  224. {
  225. if ($this->withfromreadonly)
  226. {
  227. $out.= '<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.'" />';
  228. $out.= '<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.'" />';
  229. $out.= '<tr><td width="180">'.$langs->trans("MailFrom").'</td><td>';
  230. if ($this->fromtype == 'user' && $this->fromid > 0)
  231. {
  232. $langs->load("users");
  233. $fuser=new User($this->db);
  234. $fuser->fetch($this->fromid);
  235. $out.= $fuser->getNomUrl(1);
  236. }
  237. else
  238. {
  239. $out.= $this->fromname;
  240. }
  241. if ($this->frommail)
  242. {
  243. $out.= " &lt;".$this->frommail."&gt;";
  244. }
  245. else
  246. {
  247. if ($this->fromtype)
  248. {
  249. $langs->load("errors");
  250. $out.= '<font class="warning"> &lt;'.$langs->trans("ErrorNoMailDefinedForThisUser").'&gt; </font>';
  251. }
  252. }
  253. $out.= "</td></tr>\n";
  254. $out.= "</td></tr>\n";
  255. }
  256. else
  257. {
  258. $out.= "<tr><td>".$langs->trans("MailFrom")."</td><td>";
  259. $out.= $langs->trans("Name").':<input type="text" id="fromname" name="fromname" size="32" value="'.$this->fromname.'" />';
  260. $out.= '&nbsp; &nbsp; ';
  261. $out.= $langs->trans("EMail").':&lt;<input type="text" id="frommail" name="frommail" size="32" value="'.$this->frommail.'" />&gt;';
  262. $out.= "</td></tr>\n";
  263. }
  264. }
  265. // Replyto
  266. if ($this->withreplyto)
  267. {
  268. if ($this->withreplytoreadonly)
  269. {
  270. $out.= '<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.'" />';
  271. $out.= '<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.'" />';
  272. $out.= "<tr><td>".$langs->trans("MailReply")."</td><td>".$this->replytoname.($this->replytomail?(" &lt;".$this->replytomail."&gt;"):"");
  273. $out.= "</td></tr>\n";
  274. }
  275. }
  276. // Errorsto
  277. if ($this->witherrorsto)
  278. {
  279. //if (! $this->errorstomail) $this->errorstomail=$this->frommail;
  280. $errorstomail = (! empty($conf->global->MAIN_MAIL_ERRORS_TO) ? $conf->global->MAIN_MAIL_ERRORS_TO : $this->errorstomail);
  281. if ($this->witherrorstoreadonly)
  282. {
  283. $out.= '<input type="hidden" id="errorstomail" name="errorstomail" value="'.$errorstomail.'" />';
  284. $out.= '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td>';
  285. $out.= $errorstomail;
  286. $out.= "</td></tr>\n";
  287. }
  288. else
  289. {
  290. $out.= '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td>';
  291. $out.= '<input size="30" id="errorstomail" name="errorstomail" value="'.$errorstomail.'" />';
  292. $out.= "</td></tr>\n";
  293. }
  294. }
  295. // To
  296. if ($this->withto || is_array($this->withto))
  297. {
  298. $out.= '<tr><td width="180">';
  299. if ($this->withtofree) $out.= $form->textwithpicto($langs->trans("MailTo"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
  300. else $out.= $langs->trans("MailTo");
  301. $out.= '</td><td>';
  302. if ($this->withtoreadonly)
  303. {
  304. if (! empty($this->toname) && ! empty($this->tomail))
  305. {
  306. $out.= '<input type="hidden" id="toname" name="toname" value="'.$this->toname.'" />';
  307. $out.= '<input type="hidden" id="tomail" name="tomail" value="'.$this->tomail.'" />';
  308. if ($this->totype == 'thirdparty')
  309. {
  310. $soc=new Societe($this->db);
  311. $soc->fetch($this->toid);
  312. $out.= $soc->getNomUrl(1);
  313. }
  314. else if ($this->totype == 'contact')
  315. {
  316. $contact=new Contact($this->db);
  317. $contact->fetch($this->toid);
  318. $out.= $contact->getNomUrl(1);
  319. }
  320. else
  321. {
  322. $out.= $this->toname;
  323. }
  324. $out.= ' &lt;'.$this->tomail.'&gt;';
  325. if ($this->withtofree)
  326. {
  327. $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) :"").'" />';
  328. }
  329. }
  330. else
  331. {
  332. $out.= (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:"";
  333. }
  334. }
  335. else
  336. {
  337. if ($this->withtofree)
  338. {
  339. $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) :"").'" />';
  340. }
  341. if (is_array($this->withto))
  342. {
  343. if ($this->withtofree) $out.= " ".$langs->trans("or")." ";
  344. $out.= $form->selectarray("receiver", $this->withto, GETPOST("receiver"), 1);
  345. }
  346. if ($this->withtosocid > 0) // deprecated. TODO Remove this. Instead, fill withto with array before calling method.
  347. {
  348. $liste=array();
  349. $soc=new Societe($this->db);
  350. $soc->fetch($this->withtosocid);
  351. foreach ($soc->thirdparty_and_contact_email_array(1) as $key=>$value)
  352. {
  353. $liste[$key]=$value;
  354. }
  355. if ($this->withtofree) $out.= " ".$langs->trans("or")." ";
  356. $out.= $form->selectarray("receiver", $liste, GETPOST("receiver"), 1);
  357. }
  358. }
  359. $out.= "</td></tr>\n";
  360. }
  361. // CC
  362. if ($this->withtocc || is_array($this->withtocc))
  363. {
  364. $out.= '<tr><td width="180">';
  365. $out.= $form->textwithpicto($langs->trans("MailCC"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
  366. $out.= '</td><td>';
  367. if ($this->withtoccreadonly)
  368. {
  369. $out.= (! is_array($this->withtocc) && ! is_numeric($this->withtocc))?$this->withtocc:"";
  370. }
  371. else
  372. {
  373. $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"]:"") ).'" />';
  374. if (is_array($this->withto))
  375. {
  376. $out.= " ".$langs->trans("or")." ";
  377. $out.= $form->selectarray("receivercc", $this->withto, GETPOST("receivercc"), 1);
  378. }
  379. if ($this->withtoccsocid > 0) // deprecated. TODO Remove this. Instead, fill withto with array before calling method.
  380. {
  381. $liste=array();
  382. $soc=new Societe($this->db);
  383. $soc->fetch($this->withtoccsocid);
  384. foreach ($soc->thirdparty_and_contact_email_array(1) as $key=>$value)
  385. {
  386. $liste[$key]=$value;
  387. }
  388. $out.= " ".$langs->trans("or")." ";
  389. $out.= $form->selectarray("receivercc", $liste, GETPOST("receivercc"), 1);
  390. }
  391. }
  392. $out.= "</td></tr>\n";
  393. }
  394. // CCC
  395. if ($this->withtoccc || is_array($this->withtoccc))
  396. {
  397. $out.= '<tr><td width="180">';
  398. $out.= $form->textwithpicto($langs->trans("MailCCC"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
  399. $out.= '</td><td>';
  400. if ($this->withtocccreadonly)
  401. {
  402. $out.= (! is_array($this->withtoccc) && ! is_numeric($this->withtoccc))?$this->withtoccc:"";
  403. }
  404. else
  405. {
  406. $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"]:"") ).'" />';
  407. if (is_array($this->withto))
  408. {
  409. $out.= " ".$langs->trans("or")." ";
  410. $out.= $form->selectarray("receiverccc", $this->withto, GETPOST("receiverccc"), 1);
  411. }
  412. if ($this->withtocccsocid > 0) // deprecated. TODO Remove this. Instead, fill withto with array before calling method.
  413. {
  414. $liste=array();
  415. $soc=new Societe($this->db);
  416. $soc->fetch($this->withtosocid);
  417. foreach ($soc->thirdparty_and_contact_email_array(1) as $key=>$value)
  418. {
  419. $liste[$key]=$value;
  420. }
  421. $out.= " ".$langs->trans("or")." ";
  422. $out.= $form->selectarray("receiverccc", $liste, GETPOST("receiverccc"), 1);
  423. }
  424. }
  425. //if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) print ' '.info_admin("+ ".$conf->global->MAIN_MAIL_AUTOCOPY_TO,1);
  426. $out.= "</td></tr>\n";
  427. }
  428. // Ask delivery receipt
  429. if ($this->withdeliveryreceipt)
  430. {
  431. $out.= '<tr><td width="180">'.$langs->trans("DeliveryReceipt").'</td><td>';
  432. if ($this->withdeliveryreceiptreadonly)
  433. {
  434. $out.= yn($this->withdeliveryreceipt);
  435. }
  436. else
  437. {
  438. $out.= $form->selectyesno('deliveryreceipt', (isset($_POST["deliveryreceipt"])?$_POST["deliveryreceipt"]:0), 1);
  439. }
  440. $out.= "</td></tr>\n";
  441. }
  442. // Topic
  443. if ($this->withtopic)
  444. {
  445. $this->withtopic=make_substitutions($this->withtopic,$this->substit);
  446. $out.= '<tr>';
  447. $out.= '<td width="180">'.$langs->trans("MailTopic").'</td>';
  448. $out.= '<td>';
  449. if ($this->withtopicreadonly)
  450. {
  451. $out.= $this->withtopic;
  452. $out.= '<input type="hidden" size="60" id="subject" name="subject" value="'.$this->withtopic.'" />';
  453. }
  454. else
  455. {
  456. $out.= '<input type="text" size="60" id="subject" name="subject" value="'. (isset($_POST["subject"])?$_POST["subject"]:$this->withtopic) .'" />';
  457. }
  458. $out.= "</td></tr>\n";
  459. }
  460. // Attached files
  461. if ($this->withfile)
  462. {
  463. $out.= '<tr>';
  464. $out.= '<td width="180">'.$langs->trans("MailFile").'</td>';
  465. $out.= '<td>';
  466. // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
  467. $out.= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n";
  468. $out.= '<script type="text/javascript" language="javascript">';
  469. $out.= 'jQuery(document).ready(function () {';
  470. $out.= ' jQuery(".removedfile").click(function() {';
  471. $out.= ' jQuery(".removedfilehidden").val(jQuery(this).val());';
  472. $out.= ' });';
  473. $out.= '})';
  474. $out.= '</script>'."\n";
  475. if (count($listofpaths))
  476. {
  477. foreach($listofpaths as $key => $val)
  478. {
  479. $out.= '<div id="attachfile_'.$key.'">';
  480. $out.= img_mime($listofnames[$key]).' '.$listofnames[$key];
  481. if (! $this->withfilereadonly)
  482. {
  483. $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.'" />';
  484. //$out.= ' <a href="'.$_SERVER["PHP_SELF"].'?removedfile='.($key+1).' id="removedfile_'.$key.'">'.img_delete($langs->trans("Delete").'</a>';
  485. }
  486. $out.= '<br></div>';
  487. }
  488. }
  489. else
  490. {
  491. $out.= $langs->trans("NoAttachedFiles").'<br>';
  492. }
  493. if ($this->withfile == 2) // Can add other files
  494. {
  495. $out.= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
  496. $out.= ' ';
  497. $out.= '<input type="submit" class="button" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />';
  498. }
  499. $out.= "</td></tr>\n";
  500. }
  501. // Message
  502. if ($this->withbody)
  503. {
  504. $defaultmessage="";
  505. // TODO A partir du type, proposer liste de messages dans table llx_models
  506. if ($this->param["models"]=='facture_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendInvoice"); }
  507. elseif ($this->param["models"]=='facture_relance') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendInvoiceReminder"); }
  508. elseif ($this->param["models"]=='propal_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendProposal"); }
  509. elseif ($this->param["models"]=='order_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendOrder"); }
  510. elseif ($this->param["models"]=='order_supplier_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendSupplierOrder"); }
  511. elseif ($this->param["models"]=='invoice_supplier_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendSupplierInvoice"); }
  512. elseif ($this->param["models"]=='shipping_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendShipping"); }
  513. elseif ($this->param["models"]=='fichinter_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendFichInter"); }
  514. elseif (! is_numeric($this->withbody)) { $defaultmessage=$this->withbody; }
  515. if ($conf->paypal->enabled && $conf->global->PAYPAL_ADD_PAYMENT_URL)
  516. {
  517. require_once(DOL_DOCUMENT_ROOT."/paypal/lib/paypal.lib.php");
  518. $langs->load('paypal');
  519. if ($this->param["models"]=='order_send')
  520. {
  521. $url=getPaypalPaymentUrl(0,'order',$this->substit['__ORDERREF__']);
  522. $defaultmessage=$langs->transnoentities("PredefinedMailContentSendOrderWithPaypalLink",$url);
  523. }
  524. if ($this->param["models"]=='facture_send')
  525. {
  526. $url=getPaypalPaymentUrl(0,'invoice',$this->substit['__FACREF__']);
  527. $defaultmessage=$langs->transnoentities("PredefinedMailContentSendInvoiceWithPaypalLink",$url);
  528. }
  529. }
  530. $defaultmessage=make_substitutions($defaultmessage,$this->substit);
  531. if (isset($_POST["message"])) $defaultmessage=$_POST["message"];
  532. $defaultmessage=str_replace('\n',"\n",$defaultmessage);
  533. $out.= '<tr>';
  534. $out.= '<td width="180" valign="top">'.$langs->trans("MailText").'</td>';
  535. $out.= '<td>';
  536. if ($this->withbodyreadonly)
  537. {
  538. $out.= nl2br($defaultmessage);
  539. $out.= '<input type="hidden" id="message" name="message" value="'.$defaultmessage.'" />';
  540. }
  541. else
  542. {
  543. if(! empty($conf->global->MAIL_USE_SIGN) && $this->fromid > 0)
  544. {
  545. $fuser=new User($this->db);
  546. $fuser->fetch($this->fromid);
  547. if(!empty($fuser->signature)) {
  548. $defaultmessage.=dol_htmlentitiesbr_decode($fuser->signature);
  549. }
  550. }
  551. // Editor wysiwyg
  552. require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php");
  553. $doleditor=new DolEditor('message',$defaultmessage,'',280,'dolibarr_notes','In',true,false,$this->withfckeditor,8,72);
  554. $out.= $doleditor->Create(1);
  555. }
  556. $out.= "</td></tr>\n";
  557. }
  558. if ($this->withform)
  559. {
  560. $out.= '<tr><td align="center" colspan="2"><center>';
  561. $out.= '<input class="button" type="submit" id="sendmail" name="sendmail" value="'.$langs->trans("SendMail").'"';
  562. // Add a javascript test to avoid to forget to submit file before sending email
  563. if ($this->withfile == 2 && $conf->use_javascript_ajax)
  564. {
  565. $out.= ' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans("FileWasNotUploaded")).'\'); return false; } else { return true; }"';
  566. }
  567. $out.= ' />';
  568. if ($this->withcancel)
  569. {
  570. $out.= ' &nbsp; &nbsp; ';
  571. $out.= '<input class="button" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'" />';
  572. }
  573. $out.= '</center></td></tr>'."\n";
  574. }
  575. $out.= '</table>'."\n";
  576. if ($this->withform) $out.= '</form>'."\n";
  577. $out.= "<!-- Fin form mail -->\n";
  578. return $out;
  579. }
  580. }
  581. ?>