dolibarr  19.0.0-dev
html.formmail.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
5  * Copyright (C) 2015-2017 Marcos García <marcosgdf@gmail.com>
6  * Copyright (C) 2015-2017 Nicolas ZABOURI <info@inovea-conseil.com>
7  * Copyright (C) 2018-2022 Frédéric France <frederic.france@netlogic.fr>
8  * Copyright (C) 2022 Charlene Benke <charlene@patas-monkey.com>
9  * Copyright (C) 2023 Anthony Berton <anthony.berton@bb2a.fr>
10  *
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>.
24  */
25 
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
32 
33 
40 class FormMail extends Form
41 {
45  public $db;
46 
52  public $withform;
53 
57  public $fromname;
58 
62  public $frommail;
63 
67  public $fromtype;
68 
72  public $fromid;
73 
77  public $fromalsorobot;
78 
82  public $totype;
83 
87  public $toid;
88 
92  public $replytoname;
93 
97  public $replytomail;
98 
102  public $toname;
103 
107  public $tomail;
108 
112  public $trackid;
113 
117  public $inreplyto;
118 
119  public $withsubstit; // Show substitution array
120  public $withfrom;
121 
125  public $withto; // Show recipient emails
126  public $withreplyto;
127 
133  public $withtofree;
134  public $withtocc;
135  public $withtoccc;
136  public $withtopic;
137 
141  public $withfile;
142 
146  public $withmaindocfile;
147  public $withbody;
148 
149  public $withfromreadonly;
150  public $withreplytoreadonly;
151  public $withtoreadonly;
152  public $withtoccreadonly;
153  public $withtocccreadonly;
154  public $withtopicreadonly;
155  public $withfilereadonly;
156  public $withdeliveryreceipt;
157  public $withcancel;
158  public $withfckeditor;
159 
160  public $substit = array();
161  public $substit_lines = array();
162  public $param = array();
163 
164  public $withtouser = array();
165  public $withtoccuser = array();
166 
167  public $lines_model;
168 
169  // -1 suggest the checkbox 'one email per recipient' not checked, 0 = no suggestion, 1 = suggest and checked
170  public $withoptiononeemailperrecipient;
171 
172 
178  public function __construct($db)
179  {
180  $this->db = $db;
181 
182  $this->withform = 1;
183 
184  $this->withfrom = 1;
185  $this->withto = 1;
186  $this->withtofree = 1;
187  $this->withtocc = 1;
188  $this->withtoccc = 0;
189  $this->witherrorsto = 0;
190  $this->withtopic = 1;
191  $this->withfile = 0; // 1=Add section "Attached files". 2=Can add files.
192  $this->withmaindocfile = 0; // 1=Add a checkbox "Attach also main document" for mass actions (checked by default), -1=Add checkbox (not checked by default)
193  $this->withbody = 1;
194 
195  $this->withfromreadonly = 1;
196  $this->withreplytoreadonly = 1;
197  $this->withtoreadonly = 0;
198  $this->withtoccreadonly = 0;
199  $this->withtocccreadonly = 0;
200  $this->witherrorstoreadonly = 0;
201  $this->withtopicreadonly = 0;
202  $this->withfilereadonly = 0;
203  $this->withbodyreadonly = 0;
204  $this->withdeliveryreceiptreadonly = 0;
205  $this->withfckeditor = -1; // -1 = Auto
206  }
207 
208  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
214  public function clear_attached_files()
215  {
216  // phpcs:enable
217  global $conf, $user;
218  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
219 
220  // Set tmp user directory
221  $vardir = $conf->user->dir_output."/".$user->id;
222  $upload_dir = $vardir.'/temp/'; // TODO Add $keytoavoidconflict in upload_dir path
223  if (is_dir($upload_dir)) {
224  dol_delete_dir_recursive($upload_dir);
225  }
226 
227  $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
228  unset($_SESSION["listofpaths".$keytoavoidconflict]);
229  unset($_SESSION["listofnames".$keytoavoidconflict]);
230  unset($_SESSION["listofmimes".$keytoavoidconflict]);
231  }
232 
233  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
242  public function add_attached_files($path, $file = '', $type = '')
243  {
244  // phpcs:enable
245  $listofpaths = array();
246  $listofnames = array();
247  $listofmimes = array();
248 
249  if (empty($file)) {
250  $file = basename($path);
251  }
252  if (empty($type)) {
253  $type = dol_mimetype($file);
254  }
255 
256  $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
257  if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) {
258  $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
259  }
260  if (!empty($_SESSION["listofnames".$keytoavoidconflict])) {
261  $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
262  }
263  if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) {
264  $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
265  }
266  if (!in_array($file, $listofnames)) {
267  $listofpaths[] = $path;
268  $listofnames[] = $file;
269  $listofmimes[] = $type;
270  $_SESSION["listofpaths".$keytoavoidconflict] = join(';', $listofpaths);
271  $_SESSION["listofnames".$keytoavoidconflict] = join(';', $listofnames);
272  $_SESSION["listofmimes".$keytoavoidconflict] = join(';', $listofmimes);
273  }
274  }
275 
276  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
283  public function remove_attached_files($keytodelete)
284  {
285  // phpcs:enable
286  $listofpaths = array();
287  $listofnames = array();
288  $listofmimes = array();
289 
290  $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
291  if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) {
292  $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
293  }
294  if (!empty($_SESSION["listofnames".$keytoavoidconflict])) {
295  $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
296  }
297  if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) {
298  $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
299  }
300  if ($keytodelete >= 0) {
301  unset($listofpaths[$keytodelete]);
302  unset($listofnames[$keytodelete]);
303  unset($listofmimes[$keytodelete]);
304  $_SESSION["listofpaths".$keytoavoidconflict] = join(';', $listofpaths);
305  $_SESSION["listofnames".$keytoavoidconflict] = join(';', $listofnames);
306  $_SESSION["listofmimes".$keytoavoidconflict] = join(';', $listofmimes);
307  //var_dump($_SESSION['listofpaths']);
308  }
309  }
310 
311  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
317  public function get_attached_files()
318  {
319  // phpcs:enable
320  $listofpaths = array();
321  $listofnames = array();
322  $listofmimes = array();
323 
324  $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
325  if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) {
326  $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
327  }
328  if (!empty($_SESSION["listofnames".$keytoavoidconflict])) {
329  $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
330  }
331  if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) {
332  $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
333  }
334  return array('paths'=>$listofpaths, 'names'=>$listofnames, 'mimes'=>$listofmimes);
335  }
336 
337  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
348  public function show_form($addfileaction = 'addfile', $removefileaction = 'removefile')
349  {
350  // phpcs:enable
351  print $this->get_form($addfileaction, $removefileaction);
352  }
353 
354  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
365  public function get_form($addfileaction = 'addfile', $removefileaction = 'removefile')
366  {
367  // phpcs:enable
368  global $conf, $langs, $user, $hookmanager, $form;
369 
370  // Required to show preview wof mail attachments
371  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
372  $formfile = new FormFile($this->db);
373 
374  if (!is_object($form)) {
375  $form = new Form($this->db);
376  }
377 
378  // Load translation files required by the page
379  $langs->loadLangs(array('other', 'mails', 'members'));
380 
381  // Clear temp files. Must be done before call of triggers, at beginning (mode = init), or when we select a new template
382  if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelselected') && GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) {
383  $this->clear_attached_files();
384  }
385 
386  // Call hook getFormMail
387  $hookmanager->initHooks(array('formmail'));
388 
389  $parameters = array(
390  'addfileaction' => $addfileaction,
391  'removefileaction'=> $removefileaction,
392  'trackid'=> $this->trackid
393  );
394  $reshook = $hookmanager->executeHooks('getFormMail', $parameters, $this);
395 
396  if (!empty($reshook)) {
397  return $hookmanager->resPrint;
398  } else {
399  $out = '';
400 
401  $disablebademails = 1;
402 
403  // Define output language
404  $outputlangs = $langs;
405  $newlang = '';
406  if (getDolGlobalInt('MAIN_MULTILANGS') && !empty($this->param['langsmodels'])) {
407  $newlang = $this->param['langsmodels'];
408  }
409  if (!empty($newlang)) {
410  $outputlangs = new Translate("", $conf);
411  $outputlangs->setDefaultLang($newlang);
412  $outputlangs->load('other');
413  }
414 
415  // Get message template for $this->param["models"] into c_email_templates
416  $arraydefaultmessage = -1;
417  if ($this->param['models'] != 'none') {
418  $model_id = 0;
419  if (array_key_exists('models_id', $this->param)) {
420  $model_id = $this->param["models_id"];
421  }
422 
423  $arraydefaultmessage = $this->getEMailTemplate($this->db, $this->param["models"], $user, $outputlangs, $model_id, 1, '', ($model_id > 0 ? -1 : 1)); // If $model_id is empty, preselect the first one
424  }
425 
426  // Define list of attached files
427  $listofpaths = array();
428  $listofnames = array();
429  $listofmimes = array();
430  $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
431 
432  if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelselected') && GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) {
433  if (!empty($arraydefaultmessage->joinfiles) && !empty($this->param['fileinit']) && is_array($this->param['fileinit'])) {
434  foreach ($this->param['fileinit'] as $file) {
435  if (!empty($file)) {
436  $this->add_attached_files($file, basename($file), dol_mimetype($file));
437  }
438  }
439  }
440  }
441 
442  if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) {
443  $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
444  }
445  if (!empty($_SESSION["listofnames".$keytoavoidconflict])) {
446  $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
447  }
448  if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) {
449  $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
450  }
451 
452 
453  $out .= "\n".'<!-- Begin form mail type='.$this->param["models"].' --><div id="mailformdiv"></div>'."\n";
454  if ($this->withform == 1) {
455  $out .= '<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param["returnurl"].'#formmail">'."\n";
456 
457  $out .= '<a id="formmail" name="formmail"></a>';
458  $out .= '<input style="display:none" type="submit" id="sendmailhidden" name="sendmail">';
459  $out .= '<input type="hidden" name="token" value="'.newToken().'" />';
460  $out .= '<input type="hidden" name="trackid" value="'.$this->trackid.'" />';
461  $out .= '<input type="hidden" name="inreplyto" value="'.$this->inreplyto.'" />';
462  }
463  if (!empty($this->withfrom)) {
464  if (!empty($this->withfromreadonly)) {
465  $out .= '<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.'" />';
466  $out .= '<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.'" />';
467  }
468  }
469  foreach ($this->param as $key => $value) {
470  if (is_array($value)) {
471  $out .= "<!-- param key=".$key." is array, we do not output input field for it -->\n";
472  } else {
473  $out .= '<input type="hidden" id="'.$key.'" name="'.$key.'" value="'.$value.'" />'."\n";
474  }
475  }
476 
477  $modelmail_array = array();
478  if ($this->param['models'] != 'none') {
479  $result = $this->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs);
480  if ($result < 0) {
481  setEventMessages($this->error, $this->errors, 'errors');
482  }
483 
484  foreach ($this->lines_model as $line) {
485  $reg = array();
486  if (preg_match('/\‍((.*)\‍)/', $line->label, $reg)) {
487  $labeltouse = $langs->trans($reg[1]); // langs->trans when label is __(xxx)__
488  } else {
489  $labeltouse = $line->label;
490  }
491 
492  // We escape the $labeltouse to store it into $modelmail_array.
493  $modelmail_array[$line->id] = dol_escape_htmltag($labeltouse);
494  if ($line->lang) {
495  $modelmail_array[$line->id] .= ' '.picto_from_langcode($line->lang);
496  }
497  if ($line->private) {
498  $modelmail_array[$line->id] .= ' - <span class="opacitymedium">'.dol_escape_htmltag($langs->trans("Private")).'</span>';
499  }
500  }
501  }
502 
503  // Zone to select email template
504  if (count($modelmail_array) > 0) {
505  $model_mail_selected_id = GETPOSTISSET('modelmailselected') ? GETPOST('modelmailselected', 'int') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0);
506 
507  // If list of template is filled
508  $out .= '<div class="center" style="padding: 0px 0 12px 0">'."\n";
509 
510  $out .= '<span class="opacitymedium">'.$langs->trans('SelectMailModel').':</span> ';
511 
512  $out .= $this->selectarray('modelmailselected', $modelmail_array, $model_mail_selected_id, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1, '', 0, 1);
513  if ($user->admin) {
514  $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')), 1);
515  }
516 
517  $out .= ' &nbsp; ';
518  $out .= '<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans('Apply').'" name="modelselected" id="modelselected">';
519  $out .= ' &nbsp; ';
520  $out .= '</div>';
521  } elseif (!empty($this->param['models']) && in_array($this->param['models'], array(
522  'propal_send', 'order_send', 'facture_send',
523  'shipping_send', 'fichinter_send', 'supplier_proposal_send', 'order_supplier_send',
524  'invoice_supplier_send', 'thirdparty', 'contract', 'user', 'recruitmentcandidature_send', 'all'
525  ))) {
526  // If list of template is empty
527  $out .= '<div class="center" style="padding: 0px 0 12px 0">'."\n";
528  $out .= '<span class="opacitymedium">'.$langs->trans('SelectMailModel').':</span> ';
529  $out .= '<select name="modelmailselected" disabled="disabled"><option value="none">'.$langs->trans("NoTemplateDefined").'</option></select>'; // Do not put 'disabled' on 'option' tag, it is already on 'select' and it makes chrome crazy.
530  if ($user->admin) {
531  $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')), 1);
532  }
533  $out .= ' &nbsp; ';
534  $out .= '<input type="submit" class="button" value="'.$langs->trans('Apply').'" name="modelselected" disabled="disabled" id="modelselected">';
535  $out .= ' &nbsp; ';
536  $out .= '</div>';
537  } else {
538  $out .= '<!-- No template available for $this->param["models"] = '.$this->param['models'].' -->';
539  }
540 
541 
542  $out .= '<table class="tableforemailform boxtablenotop centpercent">'."\n";
543 
544  // Substitution array/string
545  $helpforsubstitution = '';
546  if (is_array($this->substit) && count($this->substit)) {
547  $helpforsubstitution .= $langs->trans('AvailableVariables').' :<br><br><span class="small">'."\n";
548  }
549  foreach ($this->substit as $key => $val) {
550  // Do not show deprecated variables into the tooltip help of substitution variables
551  if (in_array($key, array('__NEWREF__', '__REFCLIENT__', '__REFSUPPLIER__', '__SUPPLIER_ORDER_DATE_DELIVERY__', '__SUPPLIER_ORDER_DELAY_DELIVERY__'))) {
552  continue;
553  }
554  $helpforsubstitution .= $key.' -> '.$langs->trans(dol_string_nohtmltag(dolGetFirstLineOfText($val))).'<br>';
555  }
556  if (is_array($this->substit) && count($this->substit)) {
557  $helpforsubstitution .= '</span>';
558  }
559 
560  if (!empty($this->withsubstit)) { // Unset or set ->withsubstit=0 to disable this.
561  $out .= '<tr><td colspan="2" class="right">';
562  if (is_numeric($this->withsubstit)) {
563  $out .= $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip'); // Old usage
564  } else {
565  $out .= $form->textwithpicto($langs->trans('AvailableVariables'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip'); // New usage
566  }
567  $out .= "</td></tr>\n";
568  }
569 
570  // From
571  if (!empty($this->withfrom)) {
572  if (!empty($this->withfromreadonly)) {
573  $out .= '<tr><td class="fieldrequired minwidth200">'.$langs->trans("MailFrom").'</td><td>';
574 
575  // $this->fromtype is the default value to use to select sender
576  if (!($this->fromtype === 'user' && $this->fromid > 0)
577  && !($this->fromtype === 'company')
578  && !($this->fromtype === 'robot')
579  && !preg_match('/user_aliases/', $this->fromtype)
580  && !preg_match('/global_aliases/', $this->fromtype)
581  && !preg_match('/senderprofile/', $this->fromtype)
582  ) {
583  // Use this->fromname and this->frommail or error if not defined
584  $out .= $this->fromname;
585  if ($this->frommail) {
586  $out .= ' &lt;'.$this->frommail.'&gt;';
587  } else {
588  if ($this->fromtype) {
589  $langs->load('errors');
590  $out .= '<span class="warning"> &lt;'.$langs->trans('ErrorNoMailDefinedForThisUser').'&gt; </span>';
591  }
592  }
593  } else {
594  $liste = array();
595 
596  // Add user email
597  if (empty($user->email)) {
598  $langs->load('errors');
599  $s = $user->getFullName($langs).' &lt;'.$langs->trans('ErrorNoMailDefinedForThisUser').'&gt;';
600  } else {
601  $s = $user->getFullName($langs).' &lt;'.$user->email.'&gt;';
602  }
603  $liste['user'] = array('label' => $s, 'data-html' => $s);
604 
605  // Add also company main email
606  if (!empty($conf->global->MAIN_INFO_SOCIETE_MAIL)) {
607  $s = (empty($conf->global->MAIN_INFO_SOCIETE_NOM)?$conf->global->MAIN_INFO_SOCIETE_EMAIL:$conf->global->MAIN_INFO_SOCIETE_NOM).' &lt;'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'&gt;';
608  $liste['company'] = array('label' => $s, 'data-html' => $s);
609  }
610 
611  // Add also email aliases if there is some
612  $listaliases = array(
613  'user_aliases' => (empty($user->email_aliases) ? '' : $user->email_aliases),
614  'global_aliases' => getDolGlobalString('MAIN_INFO_SOCIETE_MAIL_ALIASES'),
615  );
616 
617  if (!empty($arraydefaultmessage->email_from)) {
618  $templatemailfrom = ' &lt;'.$arraydefaultmessage->email_from.'&gt;';
619  $liste['from_template_'.GETPOST('modelmailselected')] = array('label' => $templatemailfrom, 'data-html' => $templatemailfrom);
620  }
621 
622  // Also add robot email
623  if (!empty($this->fromalsorobot)) {
624  if (!empty($conf->global->MAIN_MAIL_EMAIL_FROM) && getDolGlobalString('MAIN_MAIL_EMAIL_FROM') != getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')) {
625  $s = $conf->global->MAIN_MAIL_EMAIL_FROM;
626  if ($this->frommail) {
627  $s .= ' &lt;'.$conf->global->MAIN_MAIL_EMAIL_FROM.'&gt;';
628  }
629  array('label' => $s, 'data-html' => $s);
630  }
631  }
632 
633  // Add also email aliases from the c_email_senderprofile table
634  $sql = "SELECT rowid, label, email FROM ".$this->db->prefix()."c_email_senderprofile";
635  $sql .= " WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).")";
636  $sql .= " ORDER BY position";
637  $resql = $this->db->query($sql);
638  if ($resql) {
639  $num = $this->db->num_rows($resql);
640  $i = 0;
641  while ($i < $num) {
642  $obj = $this->db->fetch_object($resql);
643  if ($obj) {
644  $listaliases['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>';
645  }
646  $i++;
647  }
648  } else {
649  dol_print_error($this->db);
650  }
651 
652  foreach ($listaliases as $typealias => $listalias) {
653  $posalias = 0;
654  $listaliasarray = explode(',', $listalias);
655  foreach ($listaliasarray as $listaliasval) {
656  $posalias++;
657  $listaliasval = trim($listaliasval);
658  if ($listaliasval) {
659  $listaliasval = preg_replace('/</', '&lt;', $listaliasval);
660  $listaliasval = preg_replace('/>/', '&gt;', $listaliasval);
661  if (!preg_match('/&lt;/', $listaliasval)) {
662  $listaliasval = '&lt;'.$listaliasval.'&gt;';
663  }
664  $liste[$typealias.'_'.$posalias] = array('label' => $listaliasval, 'data-html' => $listaliasval);
665  }
666  }
667  }
668 
669  // Using combo here make the '<email>' no more visible on list.
670  //$out.= ' '.$form->selectarray('fromtype', $liste, $this->fromtype, 0, 0, 0, '', 0, 0, 0, '', 'fromforsendingprofile maxwidth200onsmartphone', 1, '', $disablebademails);
671  $out .= ' '.$form->selectarray('fromtype', $liste, !empty($arraydefaultmessage->email_from) ? 'from_template_'.GETPOST('modelmailselected') : $this->fromtype, 0, 0, 0, '', 0, 0, 0, '', 'fromforsendingprofile maxwidth200onsmartphone', 0, '', $disablebademails);
672  }
673 
674  $out .= "</td></tr>\n";
675  } else {
676  $out .= '<tr><td class="fieldrequired width200">'.$langs->trans("MailFrom")."</td><td>";
677  $out .= $langs->trans("Name").':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.'" />';
678  $out .= '&nbsp; &nbsp; ';
679  $out .= $langs->trans("EMail").':&lt;<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.'" />&gt;';
680  $out .= "</td></tr>\n";
681  }
682  }
683 
684  // To
685  if (!empty($this->withto) || is_array($this->withto)) {
686  $out .= $this->getHtmlForTo();
687  }
688 
689  // To User
690  if (!empty($this->withtouser) && is_array($this->withtouser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
691  $out .= '<tr><td>';
692  $out .= $langs->trans("MailToUsers");
693  $out .= '</td><td>';
694 
695  // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
696  $tmparray = $this->withtouser;
697  foreach ($tmparray as $key => $val) {
698  $tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
699  }
700  $withtoselected = GETPOST("receiveruser", 'array'); // Array of selected value
701  if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') {
702  $withtoselected = array_keys($tmparray);
703  }
704  $out .= $form->multiselectarray("receiveruser", $tmparray, $withtoselected, null, null, 'inline-block minwidth500', null, "");
705  $out .= "</td></tr>\n";
706  }
707 
708  // With option for one email per recipient
709  if (!empty($this->withoptiononeemailperrecipient)) {
710  if (abs($this->withoptiononeemailperrecipient) == 1) {
711  $out .= '<tr><td class="minwidth200">';
712  $out .= $langs->trans("GroupEmails");
713  $out .= '</td><td>';
714  $out .= ' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ? ' checked="checked"' : '').'> ';
715  $out .= '<label for="oneemailperrecipient">';
716  $out .= $form->textwithpicto($langs->trans("OneEmailPerRecipient"), $langs->trans("WarningIfYouCheckOneRecipientPerEmail"), 1, 'help');
717  $out .= '</label>';
718  //$out .= '<span class="hideonsmartphone opacitymedium">';
719  //$out .= ' - ';
720  //$out .= $langs->trans("WarningIfYouCheckOneRecipientPerEmail");
721  //$out .= '</span>';
722  if (getDolGlobalString('MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL')) {
723  if (!empty($this->withto) && !is_array($this->withto)) {
724  $out .= ' '.$langs->trans("or").' <input type="email" name="emailto" value="">';
725  }
726  }
727  $out .= '</td></tr>';
728  } else {
729  $out .= '<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>';
730  }
731  }
732 
733  // CC
734  if (!empty($this->withtocc) || is_array($this->withtocc)) {
735  $out .= $this->getHtmlForCc();
736  }
737 
738  // To User cc
739  if (!empty($this->withtoccuser) && is_array($this->withtoccuser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
740  $out .= '<tr><td>';
741  $out .= $langs->trans("MailToCCUsers");
742  $out .= '</td><td>';
743 
744  // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
745  $tmparray = $this->withtoccuser;
746  foreach ($tmparray as $key => $val) {
747  $tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
748  }
749  $withtoselected = GETPOST("receiverccuser", 'array'); // Array of selected value
750  if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') {
751  $withtoselected = array_keys($tmparray);
752  }
753  $out .= $form->multiselectarray("receiverccuser", $tmparray, $withtoselected, null, null, 'inline-block minwidth500', null, "");
754  $out .= "</td></tr>\n";
755  }
756 
757  // CCC
758  if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
759  $out .= $this->getHtmlForWithCcc();
760  }
761 
762  // Replyto
763  if (!empty($this->withreplyto)) {
764  if ($this->withreplytoreadonly) {
765  $out .= '<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.'" />';
766  $out .= '<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.'" />';
767  $out .= "<tr><td>".$langs->trans("MailReply")."</td><td>".$this->replytoname.($this->replytomail ? (" &lt;".$this->replytomail."&gt;") : "");
768  $out .= "</td></tr>\n";
769  }
770  }
771 
772  // Errorsto
773  if (!empty($this->witherrorsto)) {
774  $out .= $this->getHtmlForWithErrorsTo();
775  }
776 
777  // Ask delivery receipt
778  if (!empty($this->withdeliveryreceipt) && getDolGlobalInt('MAIN_EMAIL_SUPPORT_ACK')) {
779  $out .= $this->getHtmlForDeliveryReceipt();
780  }
781 
782  // Topic
783  if (!empty($this->withtopic)) {
784  $out .= $this->getHtmlForTopic($arraydefaultmessage, $helpforsubstitution);
785  }
786 
787  // Attached files
788  if (!empty($this->withfile)) {
789  $out .= '<tr>';
790  $out .= '<td>'.$langs->trans("MailFile").'</td>';
791 
792  $out .= '<td>';
793 
794  if ($this->withmaindocfile) {
795  // withmaindocfile is set to 1 or -1 to show the checkbox (-1 = checked or 1 = not checked)
796  if (GETPOSTISSET('sendmail')) {
797  $this->withmaindocfile = (GETPOST('addmaindocfile', 'alpha') ? -1 : 1);
798  } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
799  // If a template was selected, we use setup of template to define if join file checkbox is selected or not.
800  $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
801  }
802  }
803 
804  if (!empty($this->withmaindocfile)) {
805  if ($this->withmaindocfile == 1) {
806  $out .= '<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />';
807  } elseif ($this->withmaindocfile == -1) {
808  $out .= '<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />';
809  }
810  if (!empty($conf->global->MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND)) {
811  $out .= ' <label for="addmaindocfile">'.$langs->trans("JoinMainDocOrLastGenerated").'.</label><br>';
812  } else {
813  $out .= ' <label for="addmaindocfile">'.$langs->trans("JoinMainDoc").'.</label><br>';
814  }
815  }
816 
817  if (is_numeric($this->withfile)) {
818  // TODO Trick to have param removedfile containing nb of file to delete. But this does not works without javascript
819  $out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n";
820  $out .= '<script nonce="'.getNonce().'" type="text/javascript">';
821  $out .= 'jQuery(document).ready(function () {';
822  $out .= ' jQuery(".removedfile").click(function() {';
823  $out .= ' jQuery(".removedfilehidden").val(jQuery(this).val());';
824  $out .= ' });';
825  $out .= '})';
826  $out .= '</script>'."\n";
827  if (count($listofpaths)) {
828  foreach ($listofpaths as $key => $val) {
829  $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
830 
831  if ($conf->entity > 1) {
832  $relativepathtofile = str_replace('/'.$conf->entity.'/', '/', $relativepathtofile);
833  }
834  // Try to extract data from full path
835  $formfile_params = array();
836  preg_match('#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params);
837 
838  $out .= '<div id="attachfile_'.$key.'">';
839  // Preview of attachment
840  $out .= img_mime($listofnames[$key]).' '.$listofnames[$key];
841 
842  $out .= $formfile->showPreview(array(), $formfile_params[2], $formfile_params[4]);
843  if (!$this->withfilereadonly) {
844  $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.'" />';
845  //$out.= ' <a href="'.$_SERVER["PHP_SELF"].'?removedfile='.($key+1).' id="removedfile_'.$key.'">'.img_delete($langs->trans("Delete").'</a>';
846  }
847  $out .= '<br></div>';
848  }
849  } elseif (empty($this->withmaindocfile)) {
850  //$out .= '<span class="opacitymedium">'.$langs->trans("NoAttachedFiles").'</span><br>';
851  }
852  if ($this->withfile == 2) {
853  $maxfilesizearray = getMaxFileSizeArray();
854  $maxmin = $maxfilesizearray['maxmin'];
855  if ($maxmin > 0) {
856  $out .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
857  }
858  // Can add other files
859  if (empty($conf->global->FROM_MAIL_DONT_USE_INPUT_FILE_MULTIPLE)) {
860  $out .= '<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans("Upload").'" multiple />';
861  } else {
862  $out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
863  }
864  $out .= ' ';
865  $out .= '<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />';
866  }
867  } else {
868  $out .= $this->withfile;
869  }
870 
871  $out .= "</td></tr>\n";
872  }
873 
874  // Message
875  if (!empty($this->withbody)) {
876  $defaultmessage = GETPOST('message', 'restricthtml');
877  if (!GETPOST('modelselected', 'alpha') || GETPOST('modelmailselected') != '-1') {
878  if ($arraydefaultmessage && $arraydefaultmessage->content) {
879  $defaultmessage = $arraydefaultmessage->content;
880  } elseif (!is_numeric($this->withbody)) {
881  $defaultmessage = $this->withbody;
882  }
883  }
884 
885  // Complete substitution array with the url to make online payment
886  $paymenturl = '';
887  $validpaymentmethod = array();
888  if (empty($this->substit['__REF__'])) {
889  $paymenturl = '';
890  } else {
891  // Set the online payment url link into __ONLINE_PAYMENT_URL__ key
892  require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
893  $langs->loadLangs(array('paypal', 'other'));
894  $typeforonlinepayment = 'free';
895  if ($this->param["models"] == 'order' || $this->param["models"] == 'order_send') {
896  $typeforonlinepayment = 'order'; // TODO use detection on something else than template
897  }
898  if ($this->param["models"] == 'invoice' || $this->param["models"] == 'facture_send') {
899  $typeforonlinepayment = 'invoice'; // TODO use detection on something else than template
900  }
901  if ($this->param["models"] == 'member') {
902  $typeforonlinepayment = 'member'; // TODO use detection on something else than template
903  }
904  $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit['__REF__']);
905  $paymenturl = $url;
906 
907  $validpaymentmethod = getValidOnlinePaymentMethods('');
908  }
909 
910  if (count($validpaymentmethod) > 0 && $paymenturl) {
911  $langs->load('other');
912  $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace('\n', "\n", $langs->transnoentities("PredefinedMailContentLink", $paymenturl));
913  $this->substit['__ONLINE_PAYMENT_URL__'] = $paymenturl;
914  } else {
915  $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = '';
916  $this->substit['__ONLINE_PAYMENT_URL__'] = '';
917  }
918 
919  $this->substit['__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] = '';
920 
921  // Add lines substitution key from each line
922  $lines = '';
923  $defaultlines = $arraydefaultmessage->content_lines;
924  if (isset($defaultlines)) {
925  foreach ($this->substit_lines as $substit_line) {
926  $lines .= make_substitutions($defaultlines, $substit_line)."\n";
927  }
928  }
929  $this->substit['__LINES__'] = $lines;
930 
931  $defaultmessage = str_replace('\n', "\n", $defaultmessage);
932 
933  // Deal with format differences between message and some substitution variables (text / HTML)
934  $atleastonecomponentishtml = 0;
935  if (strpos($defaultmessage, '__USER_SIGNATURE__') !== false && dol_textishtml($this->substit['__USER_SIGNATURE__'])) {
936  $atleastonecomponentishtml++;
937  }
938  if (strpos($defaultmessage, '__SENDEREMAIL_SIGNATURE__') !== false && dol_textishtml($this->substit['__SENDEREMAIL_SIGNATURE__'])) {
939  $atleastonecomponentishtml++;
940  }
941  if (strpos($defaultmessage, '__ONLINE_PAYMENT_TEXT_AND_URL__') !== false && dol_textishtml($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
942  $atleastonecomponentishtml++;
943  }
944  if (strpos($defaultmessage, '__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !== false && dol_textishtml($this->substit['__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
945  $atleastonecomponentishtml++;
946  }
947  if (dol_textishtml($defaultmessage)) {
948  $atleastonecomponentishtml++;
949  }
950  if ($atleastonecomponentishtml) {
951  if (!dol_textishtml($this->substit['__USER_SIGNATURE__'])) {
952  $this->substit['__USER_SIGNATURE__'] = dol_nl2br($this->substit['__USER_SIGNATURE__']);
953  }
954  if (!dol_textishtml($this->substit['__SENDEREMAIL_SIGNATURE__'])) {
955  $this->substit['__SENDEREMAIL_SIGNATURE__'] = dol_nl2br($this->substit['__SENDEREMAIL_SIGNATURE__']);
956  }
957  if (!dol_textishtml($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
958  $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = dol_nl2br($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__']);
959  }
960  if (!dol_textishtml($defaultmessage)) {
961  $defaultmessage = dol_nl2br($defaultmessage);
962  }
963  }
964 
965  if (GETPOSTISSET("message") && !GETPOST('modelselected')) {
966  $defaultmessage = GETPOST("message", "restricthtml");
967  } else {
968  $defaultmessage = make_substitutions($defaultmessage, $this->substit);
969  // Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty)
970  $defaultmessage = preg_replace("/^(<br>)+/", "", $defaultmessage);
971  $defaultmessage = preg_replace("/^\n+/", "", $defaultmessage);
972  }
973 
974  $out .= '<tr>';
975  $out .= '<td colspan="2">';
976  $out .= $form->textwithpicto($langs->trans('MailText'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltipfrombody');
977  $out .= '</td>';
978  $out .= '</tr>';
979 
980  $out .= '<tr>';
981  $out .= '<td colspan="2">';
982  if ($this->withbodyreadonly) {
983  $out .= nl2br($defaultmessage);
984  $out .= '<input type="hidden" id="message" name="message" value="'.$defaultmessage.'" />';
985  } else {
986  if (!isset($this->ckeditortoolbar)) {
987  $this->ckeditortoolbar = 'dolibarr_mailings';
988  }
989 
990  // Editor wysiwyg
991  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
992  if ($this->withfckeditor == -1) {
993  if (!empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
994  $this->withfckeditor = 1;
995  } else {
996  $this->withfckeditor = 0;
997  }
998  }
999 
1000  $doleditor = new DolEditor('message', $defaultmessage, '', 280, $this->ckeditortoolbar, 'In', true, true, $this->withfckeditor, 8, '95%');
1001  $out .= $doleditor->Create(1);
1002  }
1003  $out .= "</td></tr>\n";
1004  }
1005 
1006  $out .= '</table>'."\n";
1007 
1008  if ($this->withform == 1 || $this->withform == -1) {
1009  $out .= '<div class="center">';
1010  $out .= '<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans("SendMail").'"';
1011  // Add a javascript test to avoid to forget to submit file before sending email
1012  if ($this->withfile == 2 && $conf->use_javascript_ajax) {
1013  $out .= ' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans("FileWasNotUploaded")).'\'); return false; } else { return true; }"';
1014  }
1015  $out .= ' />';
1016  if ($this->withcancel) {
1017  $out .= '<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'" />';
1018  }
1019  $out .= '</div>'."\n";
1020  }
1021 
1022  if ($this->withform == 1) {
1023  $out .= '</form>'."\n";
1024  }
1025 
1026  // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1027  if (!empty($conf->global->MAIN_MAILFORM_DISABLE_ENTERKEY)) {
1028  $out .= '<script nonce="'.getNonce().'" type="text/javascript">';
1029  $out .= 'jQuery(document).ready(function () {';
1030  $out .= ' $(document).on("keypress", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1031  var code = e.keyCode || e.which;
1032  if (code == 13) {
1033  console.log("Enter was intercepted and blocked");
1034  e.preventDefault();
1035  return false;
1036  }
1037  });';
1038  $out .= ' })';
1039  $out .= '</script>';
1040  }
1041 
1042  $out .= "<!-- End form mail -->\n";
1043 
1044  return $out;
1045  }
1046  }
1047 
1053  public function getHtmlForTo()
1054  {
1055  global $langs, $form;
1056  $out = '<tr><td class="fieldrequired">';
1057  if ($this->withtofree) {
1058  $out .= $form->textwithpicto($langs->trans("MailTo"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
1059  } else {
1060  $out .= $langs->trans("MailTo");
1061  }
1062  $out .= '</td><td>';
1063  if ($this->withtoreadonly) {
1064  if (!empty($this->toname) && !empty($this->tomail)) {
1065  $out .= '<input type="hidden" id="toname" name="toname" value="'.$this->toname.'" />';
1066  $out .= '<input type="hidden" id="tomail" name="tomail" value="'.$this->tomail.'" />';
1067  if ($this->totype == 'thirdparty') {
1068  $soc = new Societe($this->db);
1069  $soc->fetch($this->toid);
1070  $out .= $soc->getNomUrl(1);
1071  } elseif ($this->totype == 'contact') {
1072  $contact = new Contact($this->db);
1073  $contact->fetch($this->toid);
1074  $out .= $contact->getNomUrl(1);
1075  } else {
1076  $out .= $this->toname;
1077  }
1078  $out .= ' &lt;'.$this->tomail.'&gt;';
1079  if ($this->withtofree) {
1080  $out .= '<br>'.$langs->trans("and").' <input class="minwidth200" id="sendto" name="sendto" value="'.(!is_array($this->withto) && !is_numeric($this->withto) ? (GETPOSTISSET("sendto") ? GETPOST("sendto") : $this->withto) : "").'" />';
1081  }
1082  } else {
1083  // Note withto may be a text like 'AllRecipientSelected'
1084  $out .= (!is_array($this->withto) && !is_numeric($this->withto)) ? $this->withto : "";
1085  }
1086  } else {
1087  // The free input of email
1088  if (!empty($this->withtofree)) {
1089  $out .= '<input class="minwidth200" id="sendto" name="sendto" value="'.(($this->withtofree && !is_numeric($this->withtofree)) ? $this->withtofree : (!is_array($this->withto) && !is_numeric($this->withto) ? (GETPOSTISSET("sendto") ? GETPOST("sendto") : $this->withto) : "")).'" />';
1090  }
1091  // The select combo
1092  if (!empty($this->withto) && is_array($this->withto)) {
1093  if (!empty($this->withtofree)) {
1094  $out .= " ".$langs->trans("and")."/".$langs->trans("or")." ";
1095  }
1096  // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
1097  $tmparray = $this->withto;
1098  foreach ($tmparray as $key => $val) {
1099  $tmparray[$key] = str_replace(array('<', '>'), array('(', ')'), $tmparray[$key]);
1100  $tmparray[$key] = dol_htmlentities($tmparray[$key], ENT_QUOTES|ENT_SUBSTITUTE, 'UTF-8', true);
1101  }
1102 
1103  $withtoselected = GETPOST("receiver", 'array'); // Array of selected value
1104  if (!getDolGlobalInt('MAIN_MAIL_NO_WITH_TO_SELECTED')) {
1105  if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') {
1106  $withtoselected = array_keys($tmparray);
1107  }
1108  }
1109 
1110  $out .= $form->multiselectarray("receiver", $tmparray, $withtoselected, null, null, 'inline-block minwidth500', null, "");
1111  }
1112  }
1113  $out .= "</td></tr>\n";
1114  return $out;
1115  }
1116 
1122  public function getHtmlForCc()
1123  {
1124  global $langs, $form;
1125  $out = '<tr><td>';
1126  $out .= $form->textwithpicto($langs->trans("MailCC"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
1127  $out .= '</td><td>';
1128  if ($this->withtoccreadonly) {
1129  $out .= (!is_array($this->withtocc) && !is_numeric($this->withtocc)) ? $this->withtocc : "";
1130  } else {
1131  $out .= '<input class="minwidth200" id="sendtocc" name="sendtocc" value="'.(GETPOST("sendtocc", "alpha") ? GETPOST("sendtocc", "alpha") : ((!is_array($this->withtocc) && !is_numeric($this->withtocc)) ? $this->withtocc : '')).'" />';
1132  if (!empty($this->withtocc) && is_array($this->withtocc)) {
1133  $out .= " ".$langs->trans("and")."/".$langs->trans("or")." ";
1134  // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
1135  $tmparray = $this->withtocc;
1136  foreach ($tmparray as $key => $val) {
1137  $tmparray[$key] = str_replace(array('<', '>'), array('(', ')'), $tmparray[$key]);
1138  $tmparray[$key] = dol_htmlentities($tmparray[$key], ENT_QUOTES|ENT_SUBSTITUTE, 'UTF-8', true);
1139  }
1140  $withtoccselected = GETPOST("receivercc", 'array'); // Array of selected value
1141  $out .= $form->multiselectarray("receivercc", $tmparray, $withtoccselected, null, null, 'inline-block minwidth500', null, "");
1142  }
1143  }
1144  $out .= "</td></tr>\n";
1145  return $out;
1146  }
1147 
1153  public function getHtmlForWithCcc()
1154  {
1155  global $conf, $langs, $form;
1156  $out = '<tr><td>';
1157  $out .= $form->textwithpicto($langs->trans("MailCCC"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
1158  $out .= '</td><td>';
1159  if (!empty($this->withtocccreadonly)) {
1160  $out .= (!is_array($this->withtoccc) && !is_numeric($this->withtoccc)) ? $this->withtoccc : "";
1161  } else {
1162  $out .= '<input class="minwidth200" id="sendtoccc" name="sendtoccc" value="'.(GETPOSTISSET("sendtoccc") ? GETPOST("sendtoccc", "alpha") : ((!is_array($this->withtoccc) && !is_numeric($this->withtoccc)) ? $this->withtoccc : '')).'" />';
1163  if (!empty($this->withtoccc) && is_array($this->withtoccc)) {
1164  $out .= " ".$langs->trans("and")."/".$langs->trans("or")." ";
1165  // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
1166  $tmparray = $this->withtoccc;
1167  foreach ($tmparray as $key => $val) {
1168  $tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
1169  }
1170  $withtocccselected = GETPOST("receiverccc", 'array'); // Array of selected value
1171  $out .= $form->multiselectarray("receiverccc", $tmparray, $withtocccselected, null, null, null, null, "90%");
1172  }
1173  }
1174 
1175  $showinfobcc = '';
1176  if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) && !empty($this->param['models']) && $this->param['models'] == 'propal_send') {
1177  $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO;
1178  }
1179  if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) && !empty($this->param['models']) && $this->param['models'] == 'order_send') {
1180  $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO;
1181  }
1182  if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) && !empty($this->param['models']) && $this->param['models'] == 'facture_send') {
1183  $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO;
1184  }
1185  if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) && !empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') {
1186  $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO;
1187  }
1188  if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO) && !empty($this->param['models']) && $this->param['models'] == 'order_supplier_send') {
1189  $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO;
1190  }
1191  if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO) && !empty($this->param['models']) && $this->param['models'] == 'invoice_supplier_send') {
1192  $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO;
1193  }
1194  if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_PROJECT_TO) && !empty($this->param['models']) && $this->param['models'] == 'project') {
1195  $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_PROJECT_TO;
1196  }
1197  if ($showinfobcc) {
1198  $out .= ' + '.$showinfobcc;
1199  }
1200  $out .= "</td></tr>\n";
1201  return $out;
1202  }
1203 
1209  public function getHtmlForWithErrorsTo()
1210  {
1211  global $conf, $langs;
1212  //if (! $this->errorstomail) $this->errorstomail=$this->frommail;
1213  $errorstomail = getDolGlobalString('MAIN_MAIL_ERRORS_TO', (!empty($this->errorstomail) ? $this->errorstomail : ''));
1214  if ($this->witherrorstoreadonly) {
1215  $out = '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td>';
1216  $out .= '<input type="hidden" id="errorstomail" name="errorstomail" value="'.$errorstomail.'" />';
1217  $out .= $errorstomail;
1218  $out .= "</td></tr>\n";
1219  } else {
1220  $out = '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td>';
1221  $out .= '<input class="minwidth200" id="errorstomail" name="errorstomail" value="'.$errorstomail.'" />';
1222  $out .= "</td></tr>\n";
1223  }
1224  return $out;
1225  }
1226 
1232  public function getHtmlForDeliveryreceipt()
1233  {
1234  global $conf, $langs;
1235  $out = '<tr><td><label for="deliveryreceipt">'.$langs->trans("DeliveryReceipt").'</label></td><td>';
1236 
1237  if (!empty($this->withdeliveryreceiptreadonly)) {
1238  $out .= yn($this->withdeliveryreceipt);
1239  } else {
1240  $defaultvaluefordeliveryreceipt = 0;
1241  if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_PROPAL) && !empty($this->param['models']) && $this->param['models'] == 'propal_send') {
1242  $defaultvaluefordeliveryreceipt = 1;
1243  }
1244  if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_PROPOSAL) && !empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') {
1245  $defaultvaluefordeliveryreceipt = 1;
1246  }
1247  if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_ORDER) && !empty($this->param['models']) && $this->param['models'] == 'order_send') {
1248  $defaultvaluefordeliveryreceipt = 1;
1249  }
1250  if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_INVOICE) && !empty($this->param['models']) && $this->param['models'] == 'facture_send') {
1251  $defaultvaluefordeliveryreceipt = 1;
1252  }
1253  if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_ORDER) && !empty($this->param['models']) && $this->param['models'] == 'order_supplier_send') {
1254  $defaultvaluefordeliveryreceipt = 1;
1255  }
1256  //$out .= $form->selectyesno('deliveryreceipt', (GETPOSTISSET("deliveryreceipt") ? GETPOST("deliveryreceipt") : $defaultvaluefordeliveryreceipt), 1);
1257  $out .= '<input type="checkbox" id="deliveryreceipt" name="deliveryreceipt" value="1"'.((GETPOSTISSET("deliveryreceipt") ? GETPOST("deliveryreceipt") : $defaultvaluefordeliveryreceipt) ? ' checked="checked"' : '').'>';
1258  }
1259  $out .= "</td></tr>\n";
1260  return $out;
1261  }
1262 
1270  public function getHtmlForTopic($arraydefaultmessage, $helpforsubstitution)
1271  {
1272  global $conf, $langs, $form;
1273 
1274  $defaulttopic = GETPOST('subject', 'restricthtml');
1275 
1276  if (!GETPOST('modelselected', 'alpha') || GETPOST('modelmailselected') != '-1') {
1277  if ($arraydefaultmessage && $arraydefaultmessage->topic) {
1278  $defaulttopic = $arraydefaultmessage->topic;
1279  } elseif (!is_numeric($this->withtopic)) {
1280  $defaulttopic = $this->withtopic;
1281  }
1282  }
1283 
1284  $defaulttopic = make_substitutions($defaulttopic, $this->substit);
1285 
1286  $out = '<tr>';
1287  $out .= '<td class="fieldrequired">';
1288  $out .= $form->textwithpicto($langs->trans('MailTopic'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltipfromtopic');
1289  $out .= '</td>';
1290  $out .= '<td>';
1291  if ($this->withtopicreadonly) {
1292  $out .= $defaulttopic;
1293  $out .= '<input type="hidden" class="quatrevingtpercent" id="subject" name="subject" value="'.$defaulttopic.'" />';
1294  } else {
1295  $out .= '<input type="text" class="quatrevingtpercent" id="subject" name="subject" value="'.((GETPOSTISSET("subject") && !GETPOST('modelselected')) ? GETPOST("subject") : ($defaulttopic ? $defaulttopic : '')).'" />';
1296  }
1297  $out .= "</td></tr>\n";
1298  return $out;
1299  }
1300 
1318  public function getEMailTemplate($dbs, $type_template, $user, $outputlangs, $id = 0, $active = 1, $label = '', $defaultfortype = -1)
1319  {
1320  global $conf;
1321 
1322  if ($id == -2 && empty($label)) {
1323  $this->error = 'LabelIsMandatoryWhenIdIs-2or-3';
1324  return -1;
1325  }
1326 
1327  $ret = new ModelMail();
1328 
1329  $languagetosearch = (is_object($outputlangs) ? $outputlangs->defaultlang : '');
1330  // Define $languagetosearchmain to fall back on main language (for example to get 'es_ES' for 'es_MX')
1331  $tmparray = explode('_', $languagetosearch);
1332  $languagetosearchmain = $tmparray[0].'_'.strtoupper($tmparray[0]);
1333  if ($languagetosearchmain == $languagetosearch) {
1334  $languagetosearchmain = '';
1335  }
1336 
1337  $sql = "SELECT rowid, module, label, type_template, topic, email_from, joinfiles, content, content_lines, lang, email_from, email_to, email_tocc, email_tobcc";
1338  $sql .= " FROM ".$dbs->prefix().'c_email_templates';
1339  $sql .= " WHERE (type_template = '".$dbs->escape($type_template)."' OR type_template = 'all')";
1340  $sql .= " AND entity IN (".getEntity('c_email_templates').")";
1341  $sql .= " AND (private = 0 OR fk_user = ".((int) $user->id).")"; // Get all public or private owned
1342  if ($active >= 0) {
1343  $sql .= " AND active = ".((int) $active);
1344  }
1345  if ($defaultfortype >= 0) {
1346  $sql .= " AND defaultfortype = ".((int) $defaultfortype);
1347  }
1348  if ($label) {
1349  $sql .= " AND label = '".$dbs->escape($label)."'";
1350  }
1351  if (!($id > 0) && $languagetosearch) {
1352  $sql .= " AND (lang = '".$dbs->escape($languagetosearch)."'".($languagetosearchmain ? " OR lang = '".$dbs->escape($languagetosearchmain)."'" : "")." OR lang IS NULL OR lang = '')";
1353  }
1354  if ($id > 0) {
1355  $sql .= " AND rowid = ".(int) $id;
1356  }
1357  if ($id == -1) {
1358  $sql .= " AND position = 0";
1359  }
1360  if ($languagetosearch) {
1361  $sql .= $dbs->order("position,lang,label", "ASC,DESC,ASC"); // We want line with lang set first, then with lang null or ''
1362  } else {
1363  $sql .= $dbs->order("position,lang,label", "ASC,ASC,ASC"); // If no language provided, we give priority to lang not defined
1364  }
1365  //$sql .= $dbs->plimit(1);
1366  //print $sql;
1367 
1368  $resql = $dbs->query($sql);
1369  if (!$resql) {
1370  dol_print_error($dbs);
1371  return -1;
1372  }
1373 
1374  // Get first found
1375  while (1) {
1376  $obj = $dbs->fetch_object($resql);
1377 
1378  if ($obj) {
1379  // If template is for a module, check module is enabled; if not, take next template
1380  if ($obj->module) {
1381  $tempmodulekey = $obj->module;
1382  if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1383  continue;
1384  }
1385  }
1386 
1387  // If a record was found
1388  $ret->id = $obj->rowid;
1389  $ret->module = $obj->module;
1390  $ret->label = $obj->label;
1391  $ret->lang = $obj->lang;
1392  $ret->topic = $obj->topic;
1393  $ret->content = $obj->content;
1394  $ret->content_lines = $obj->content_lines;
1395  $ret->joinfiles = $obj->joinfiles;
1396  $ret->email_from = $obj->email_from;
1397 
1398  break;
1399  } else {
1400  // If no record found
1401  if ($id == -2) {
1402  // Not found with the provided label
1403  return -1;
1404  } else {
1405  // If there is no template at all
1406  $defaultmessage = '';
1407 
1408  if ($type_template == 'body') {
1409  // Special case to use this->withbody as content
1410  $defaultmessage = $this->withbody;
1411  } elseif ($type_template == 'facture_send') {
1412  $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoice");
1413  } elseif ($type_template == 'facture_relance') {
1414  $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoiceReminder");
1415  } elseif ($type_template == 'propal_send') {
1416  $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendProposal");
1417  } elseif ($type_template == 'supplier_proposal_send') {
1418  $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierProposal");
1419  } elseif ($type_template == 'order_send') {
1420  $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendOrder");
1421  } elseif ($type_template == 'order_supplier_send') {
1422  $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder");
1423  } elseif ($type_template == 'invoice_supplier_send') {
1424  $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice");
1425  } elseif ($type_template == 'shipping_send') {
1426  $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendShipping");
1427  } elseif ($type_template == 'fichinter_send') {
1428  $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendFichInter");
1429  } elseif ($type_template == 'actioncomm_send') {
1430  $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendActionComm");
1431  } elseif (!empty($type_template)) {
1432  $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentGeneric");
1433  }
1434 
1435  $ret->label = 'default';
1436  $ret->lang = $outputlangs->defaultlang;
1437  $ret->topic = '';
1438  $ret->joinfiles = 1;
1439  $ret->content = $defaultmessage;
1440  $ret->content_lines = '';
1441 
1442  break;
1443  }
1444  }
1445  }
1446 
1447  $dbs->free($resql);
1448 
1449  return $ret;
1450  }
1451 
1461  public function isEMailTemplate($type_template, $user, $outputlangs)
1462  {
1463  $sql = "SELECT label, topic, content, lang";
1464  $sql .= " FROM ".$this->db->prefix().'c_email_templates';
1465  $sql .= " WHERE type_template='".$this->db->escape($type_template)."'";
1466  $sql .= " AND entity IN (".getEntity('c_email_templates').")";
1467  $sql .= " AND (fk_user is NULL or fk_user = 0 or fk_user = ".((int) $user->id).")";
1468  if (is_object($outputlangs)) {
1469  $sql .= " AND (lang = '".$this->db->escape($outputlangs->defaultlang)."' OR lang IS NULL OR lang = '')";
1470  }
1471  $sql .= $this->db->order("lang,label", "ASC");
1472  //print $sql;
1473 
1474  $resql = $this->db->query($sql);
1475  if ($resql) {
1476  $num = $this->db->num_rows($resql);
1477  $this->db->free($resql);
1478  return $num;
1479  } else {
1480  $this->error = get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1481  return -1;
1482  }
1483  }
1484 
1495  public function fetchAllEMailTemplate($type_template, $user, $outputlangs, $active = 1)
1496  {
1497  global $conf;
1498 
1499  $sql = "SELECT rowid, module, label, topic, content, content_lines, lang, fk_user, private, position";
1500  $sql .= " FROM ".$this->db->prefix().'c_email_templates';
1501  $sql .= " WHERE type_template IN ('".$this->db->escape($type_template)."', 'all')";
1502  $sql .= " AND entity IN (".getEntity('c_email_templates').")";
1503  $sql .= " AND (private = 0 OR fk_user = ".((int) $user->id).")"; // See all public templates or templates I own.
1504  if ($active >= 0) {
1505  $sql .= " AND active = ".((int) $active);
1506  }
1507  //if (is_object($outputlangs)) $sql.= " AND (lang = '".$this->db->escape($outputlangs->defaultlang)."' OR lang IS NULL OR lang = '')"; // Return all languages
1508  $sql .= $this->db->order("position,lang,label", "ASC");
1509  //print $sql;
1510 
1511  $resql = $this->db->query($sql);
1512  if ($resql) {
1513  $num = $this->db->num_rows($resql);
1514  $this->lines_model = array();
1515  while ($obj = $this->db->fetch_object($resql)) {
1516  // If template is for a module, check module is enabled.
1517  if ($obj->module) {
1518  $tempmodulekey = $obj->module;
1519  if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1520  continue;
1521  }
1522  }
1523 
1524  $line = new ModelMail();
1525  $line->id = $obj->rowid;
1526  $line->label = $obj->label;
1527  $line->lang = $obj->lang;
1528  $line->fk_user = $obj->fk_user;
1529  $line->private = $obj->private;
1530  $line->position = $obj->position;
1531  $line->topic = $obj->topic;
1532  $line->content = $obj->content;
1533  $line->content_lines = $obj->content_lines;
1534 
1535  $this->lines_model[] = $line;
1536  }
1537  $this->db->free($resql);
1538  return $num;
1539  } else {
1540  $this->error = get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1541  return -1;
1542  }
1543  }
1544 
1545 
1546 
1555  public function setSubstitFromObject($object, $outputlangs)
1556  {
1557  global $conf, $user, $extrafields;
1558 
1559  $parameters = array();
1560  $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1561  complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
1562 
1563  $this->substit = $tmparray;
1564 
1565  // Fill substit_lines with each object lines content
1566  if (is_array($object->lines)) {
1567  foreach ($object->lines as $line) {
1568  $substit_line = array(
1569  '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
1570  '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
1571  '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
1572  '__LABEL__' => isset($line->label) ? $line->label : '',
1573  '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
1574  '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', 0, $outputlangs),
1575  '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', 0, $outputlangs),
1576  '__QUANTITY__' => $line->qty,
1577  '__SUBPRICE__' => price($line->subprice),
1578  '__AMOUNT__' => price($line->total_ttc),
1579  '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
1580  );
1581 
1582  // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
1583  if (!empty($line->fk_product)) {
1584  if (!is_object($extrafields)) {
1585  $extrafields = new ExtraFields($this->db);
1586  }
1587  $product = new Product($this->db);
1588  $product->fetch($line->fk_product, '', '', 1);
1589  $product->fetch_optionals();
1590 
1591  $extrafields->fetch_name_optionals_label($product->table_element, true);
1592 
1593  if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
1594  foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
1595  $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
1596  }
1597  }
1598  }
1599  $this->substit_lines[] = $substit_line;
1600  }
1601  }
1602  }
1603 
1612  public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
1613  {
1614  global $conf, $langs;
1615 
1616  $tmparray = array();
1617  if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
1618  $parameters = array('mode'=>$mode);
1619  $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
1620  complete_substitutions_array($tmparray, $langs, null, $parameters);
1621 
1622  if ($mode == 'formwithlines') {
1623  $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
1624  }
1625  if ($mode == 'formforlines') {
1626  $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
1627  }
1628  }
1629 
1630  if ($mode == 'emailing') {
1631  $parameters = array('mode'=>$mode);
1632  $tmparray = getCommonSubstitutionArray($langs, 2, array('object', 'objectamount'), $object); // Note: On email templated edition, this is null because it is related to all type of objects
1633  complete_substitutions_array($tmparray, $langs, null, $parameters);
1634 
1635  // For mass emailing, we have different keys specific to the data into tagerts list
1636  $tmparray['__ID__'] = 'IdRecord';
1637  $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode';
1638  $tmparray['__EMAIL__'] = 'EMailRecipient';
1639  $tmparray['__LASTNAME__'] = 'Lastname';
1640  $tmparray['__FIRSTNAME__'] = 'Firstname';
1641  $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
1642  $tmparray['__OTHER1__'] = 'Other1';
1643  $tmparray['__OTHER2__'] = 'Other2';
1644  $tmparray['__OTHER3__'] = 'Other3';
1645  $tmparray['__OTHER4__'] = 'Other4';
1646  $tmparray['__OTHER5__'] = 'Other5';
1647  //,'__PERSONALIZED__' => 'Personalized' // Hidden because not used yet in mass emailing
1648 
1649  $onlinepaymentenabled = 0;
1650  if (isModEnabled('paypal')) {
1651  $onlinepaymentenabled++;
1652  }
1653  if (isModEnabled('paybox')) {
1654  $onlinepaymentenabled++;
1655  }
1656  if (isModEnabled('stripe')) {
1657  $onlinepaymentenabled++;
1658  }
1659  if ($onlinepaymentenabled && !empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
1660  $tmparray['__SECUREKEYPAYMENT__'] = $conf->global->PAYMENT_SECURITY_TOKEN;
1661  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
1662  if (isModEnabled('adherent')) {
1663  $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
1664  }
1665  if (isModEnabled('don')) {
1666  $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
1667  }
1668  if (isModEnabled('facture')) {
1669  $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
1670  }
1671  if (isModEnabled('commande')) {
1672  $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
1673  }
1674  if (isModEnabled('contrat')) {
1675  $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
1676  }
1677 
1678  //Online payment link
1679  if (isModEnabled('adherent')) {
1680  $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
1681  }
1682  if (isModEnabled('don')) {
1683  $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
1684  }
1685  if (isModEnabled('facture')) {
1686  $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
1687  }
1688  if (isModEnabled('commande')) {
1689  $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
1690  }
1691  if (isModEnabled('contrat')) {
1692  $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
1693  }
1694  }
1695  } else {
1696  /* No need to show into tooltip help, option is not enabled
1697  $vars['__SECUREKEYPAYMENT__']='';
1698  $vars['__SECUREKEYPAYMENT_MEMBER__']='';
1699  $vars['__SECUREKEYPAYMENT_INVOICE__']='';
1700  $vars['__SECUREKEYPAYMENT_ORDER__']='';
1701  $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
1702  */
1703  }
1704  if (!empty($conf->global->MEMBER_ENABLE_PUBLIC)) {
1705  $substitutionarray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
1706  }
1707  }
1708 
1709  foreach ($tmparray as $key => $val) {
1710  if (empty($val)) {
1711  $tmparray[$key] = $key;
1712  }
1713  }
1714 
1715  return $tmparray;
1716  }
1717 }
1718 
1719 
1725 class ModelMail
1726 {
1730  public $id;
1731 
1735  public $label;
1736 
1740  public $fk_user;
1741 
1745  public $private;
1746 
1750  public $topic;
1751 
1755  public $content;
1756  public $content_lines;
1757  public $lang;
1758  public $joinfiles;
1759 
1760  public $email_from;
1761  public $email_to;
1762  public $email_tocc;
1763  public $email_tobcc;
1764 
1768  public $module;
1769 
1773  public $position;
1774 }
Class to manage a WYSIWYG editor.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
static selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='minwidth75', $addjscombo=1, $moreparamonempty='', $disablebademail=0, $nohtmlescape=0)
Return a HTML select string, built from an array of key+value.
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
get_attached_files()
Return list of attached files (stored in SECTION array)
getHtmlForWithErrorsTo()
get Html For WithErrorsTo
getHtmlForTopic($arraydefaultmessage, $helpforsubstitution)
get Html For Topic of message
clear_attached_files()
Clear list of attached files in send mail form (also stored in session)
fetchAllEMailTemplate($type_template, $user, $outputlangs, $active=1)
Find if template exists and are available for current user, then set them into $this->lines_module.
getHtmlForCc()
get html For CC
getHtmlForTo()
get html For To
add_attached_files($path, $file='', $type='')
Add a file into the list of attached files (stored in SECTION array)
getHtmlForWithCcc()
get html For WithCCC
remove_attached_files($keytodelete)
Remove a file from the list of attached files (stored in SECTION array)
__construct($db)
Constructor.
getEMailTemplate($dbs, $type_template, $user, $outputlangs, $id=0, $active=1, $label='', $defaultfortype=-1)
Return templates of email with type = $type_template or type = 'all'.
show_form($addfileaction='addfile', $removefileaction='removefile')
Show the form to input an email this->withfile: 0=No attaches files, 1=Show attached files,...
get_form($addfileaction='addfile', $removefileaction='removefile')
Get the form to input an email this->withfile: 0=No attaches files, 1=Show attached files,...
Class to manage translations.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
Definition: files.lib.php:1485
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_textishtml($msg, $option=0)
Return if a text is a html content.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
rtl background position
table tableforfield button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
Definition: style.css.php:848
getMaxFileSizeArray()
Return the max allowed for file upload.