PageRenderTime 55ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

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

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