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