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