dolibarr 23.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-2025 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2022 Charlene Benke <charlene@patas-monkey.com>
9 * Copyright (C) 2023 Anthony Berton <anthony.berton@bb2a.fr>
10 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
11 * Copyright (C) 2026 Nathan Pixodeo <nathan@pixodeo.net>
12 *
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/cemailtemplate.class.php'; // So the class ModelMail that was defined into this file in old version is still available when including this file
35
36
43class FormMail extends Form
44{
48 public $db;
49
55 public $withform;
56
60 public $fromname;
61
65 public $frommail;
66
70 public $fromtype;
71
75 public $fromid;
76
80 public $fromalsorobot;
81
85 public $totype;
86
90 public $toid;
91
95 public $replytoname;
96
100 public $replytomail;
101
105 public $toname;
106
110 public $tomail;
111
115 public $trackid;
116
120 public $inreplyto;
121
125 public $withsubstit; // Show substitution array
129 public $withfrom;
130
134 public $withto; // Show recipient emails
138 public $withreplyto;
139
145 public $withtofree;
149 public $withtocc;
153 public $withtoccc;
157 public $withtopic;
161 public $witherrorsto;
162
166 public $withfile;
167
171 public $withlayout;
172
176 public $withaiprompt;
177
181 public $withmaindocfile;
185 public $withbody;
186
190 public $withfromreadonly;
194 public $withreplytoreadonly;
198 public $withtoreadonly;
202 public $withtoccreadonly;
206 public $witherrorstoreadonly;
210 public $withtocccreadonly;
214 public $withtopicreadonly;
218 public $withbodyreadonly;
222 public $withfilereadonly;
226 public $withdeliveryreceipt;
230 public $withcancel;
234 public $withdeliveryreceiptreadonly;
238 public $withfckeditor;
239
243 public $ckeditortoolbar;
244
248 public $substit = array();
249
253 public $substit_lines = array();
254
258 public $param = array();
259
263 public $withtouser = array();
267 public $withtoccuser = array();
268
272 public $lines_model;
273
277 public $withoptiononeemailperrecipient;
278
279
285 public function __construct($db)
286 {
287 $this->db = $db;
288
289 $this->withform = 1;
290
291 $this->withfrom = 1;
292 $this->withto = 1;
293 $this->withtofree = 1;
294 $this->withtocc = 1;
295 $this->withtoccc = '0';
296 $this->witherrorsto = 0;
297 $this->withtopic = 1;
298 $this->withfile = 0; // 1=Add section "Attached files". 2=Can add files.
299 $this->withmaindocfile = 0; // 1=Add a checkbox "Attach also main document" for mass actions (checked by default), -1=Add checkbox (not checked by default)
300 $this->withbody = 1;
301
302 $this->withfromreadonly = 1;
303 $this->withreplytoreadonly = 1;
304 $this->withtoreadonly = 0;
305 $this->withtoccreadonly = 0;
306 $this->withtocccreadonly = 0;
307 $this->witherrorstoreadonly = 0;
308 $this->withtopicreadonly = 0;
309 $this->withfilereadonly = 0;
310 $this->withbodyreadonly = 0;
311 $this->withdeliveryreceiptreadonly = 0;
312 $this->withfckeditor = -1; // -1 = Auto
313 }
314
315 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
321 public function clear_attached_files()
322 {
323 // phpcs:enable
324 global $conf, $user;
325 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
326
327 // Set tmp user directory
328 $vardir = $conf->user->dir_output."/".$user->id;
329 $upload_dir = $vardir.'/temp/'; // TODO Add $keytoavoidconflict in upload_dir path
330 if (is_dir($upload_dir)) {
331 dol_delete_dir_recursive($upload_dir);
332 }
333
334 $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
335 unset($_SESSION["listofpaths".$keytoavoidconflict]);
336 unset($_SESSION["listofnames".$keytoavoidconflict]);
337 unset($_SESSION["listofmimes".$keytoavoidconflict]);
338 }
339
340 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
349 public function add_attached_files($path, $file = '', $type = '')
350 {
351 // phpcs:enable
352 $listofpaths = array();
353 $listofnames = array();
354 $listofmimes = array();
355
356 if (empty($file)) {
357 $file = basename($path);
358 }
359 if (empty($type)) {
360 $type = dol_mimetype($file);
361 }
362
363 $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
364 if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) {
365 $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
366 }
367 if (!empty($_SESSION["listofnames".$keytoavoidconflict])) {
368 $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
369 }
370 if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) {
371 $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
372 }
373 if (!in_array($file, $listofnames)) {
374 $listofpaths[] = $path;
375 $listofnames[] = $file;
376 $listofmimes[] = $type;
377 $_SESSION["listofpaths".$keytoavoidconflict] = implode(';', $listofpaths);
378 $_SESSION["listofnames".$keytoavoidconflict] = implode(';', $listofnames);
379 $_SESSION["listofmimes".$keytoavoidconflict] = implode(';', $listofmimes);
380 }
381 }
382
383 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
390 public function remove_attached_files($keytodelete)
391 {
392 // phpcs:enable
393 $listofpaths = array();
394 $listofnames = array();
395 $listofmimes = array();
396
397 $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
398 if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) {
399 $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
400 }
401 if (!empty($_SESSION["listofnames".$keytoavoidconflict])) {
402 $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
403 }
404 if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) {
405 $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
406 }
407 if ($keytodelete >= 0) {
408 unset($listofpaths[$keytodelete]);
409 unset($listofnames[$keytodelete]);
410 unset($listofmimes[$keytodelete]);
411 $_SESSION["listofpaths".$keytoavoidconflict] = implode(';', $listofpaths);
412 $_SESSION["listofnames".$keytoavoidconflict] = implode(';', $listofnames);
413 $_SESSION["listofmimes".$keytoavoidconflict] = implode(';', $listofmimes);
414 //var_dump($_SESSION['listofpaths']);
415 }
416 }
417
418 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
424 public function get_attached_files()
425 {
426 // phpcs:enable
427 $listofpaths = array();
428 $listofnames = array();
429 $listofmimes = array();
430
431 $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
432 if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) {
433 $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
434 }
435 if (!empty($_SESSION["listofnames".$keytoavoidconflict])) {
436 $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
437 }
438 if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) {
439 $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
440 }
441 return array('paths' => $listofpaths, 'names' => $listofnames, 'mimes' => $listofmimes);
442 }
443
444 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
455 public function show_form($addfileaction = 'addfile', $removefileaction = 'removefile')
456 {
457 // phpcs:enable
458 print $this->get_form($addfileaction, $removefileaction);
459 }
460
461 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
472 public function get_form($addfileaction = 'addfile', $removefileaction = 'removefile')
473 {
474 // phpcs:enable
475 global $conf, $langs, $user, $hookmanager, $form;
476
477 if (!is_object($form)) {
478 $form = new Form($this->db);
479 }
480
481 // Required to show editor assistants
482 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
483 $formfile = new FormFile($this->db);
484
485 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formai.class.php';
486 $formai = new FormAI($this->db);
487
488 // Load translation files required by the page
489 $langs->loadLangs(array('other', 'mails', 'members'));
490
491 // Clear temp files. Must be done before call of triggers, at beginning (mode = init), or when we select a new template
492 if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelselected') && GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) {
493 $this->clear_attached_files();
494 }
495
496 // Call hook getFormMail
497 $hookmanager->initHooks(array('formmail'));
498
499 $parameters = array(
500 'addfileaction' => $addfileaction,
501 'removefileaction' => $removefileaction,
502 'trackid' => $this->trackid
503 );
504 $reshook = $hookmanager->executeHooks('getFormMail', $parameters, $this);
505
506 if (!empty($reshook)) {
507 return $hookmanager->resPrint;
508 } else {
509 $out = '';
510
511 $disablebademails = 1;
512
513 // Define output language
514 $outputlangs = $langs;
515 $newlang = '';
516 if (getDolGlobalInt('MAIN_MULTILANGS') && !empty($this->param['langsmodels'])) {
517 $newlang = $this->param['langsmodels'];
518 }
519 if (!empty($newlang)) {
520 $outputlangs = new Translate("", $conf);
521 $outputlangs->setDefaultLang($newlang);
522 $outputlangs->load('other');
523 }
524
525 // Get message template for $this->param["models"] into c_email_templates
526 $arraydefaultmessage = -1;
527 if ($this->param['models'] != 'none') {
528 $model_id = 0;
529 if (array_key_exists('models_id', $this->param)) {
530 $model_id = $this->param["models_id"];
531 }
532
533 $arraydefaultmessage = $this->getEMailTemplate($this->db, $this->param["models"], $user, $outputlangs, $model_id, 1, '', ($model_id > 0 ? -1 : 1)); // If $model_id is empty, preselect the first one
534 }
535
536 // Define list of attached files
537 $listofpaths = array();
538 $listofnames = array();
539 $listofmimes = array();
540 $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
541
542 if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelselected') && GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) {
543 if (!empty($arraydefaultmessage->joinfiles) && !empty($this->param['fileinit']) && is_array($this->param['fileinit'])) {
544 foreach ($this->param['fileinit'] as $path) {
545 if (!empty($path)) {
546 $this->add_attached_files($path);
547 }
548 }
549 }
550 }
551
552 if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) {
553 $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
554 }
555 if (!empty($_SESSION["listofnames".$keytoavoidconflict])) {
556 $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
557 }
558 if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) {
559 $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
560 }
561
562
563 $out .= "\n".'<!-- Begin form mail type='.$this->param["models"].' --><div id="mailformdiv"></div>'."\n";
564 if ($this->withform == 1) {
565 $out .= '<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param["returnurl"].'#formmail">'."\n";
566
567 $out .= '<a id="formmail" name="formmail"></a>';
568 $out .= '<input style="display:none" type="submit" id="sendmailhidden" name="sendmail">';
569 $out .= '<input type="hidden" name="token" value="'.newToken().'" />';
570 $out .= '<input type="hidden" name="page_y" value="" />';
571 $out .= '<input type="hidden" name="trackid" value="'.$this->trackid.'" />';
572 $out .= '<input type="hidden" name="inreplyto" value="'.$this->inreplyto.'" />';
573 }
574 if (!empty($this->withfrom)) {
575 if (!empty($this->withfromreadonly)) {
576 $out .= '<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.'" />';
577 $out .= '<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.'" />';
578 }
579 }
580 foreach ($this->param as $key => $value) {
581 if (is_array($value)) {
582 $out .= "<!-- param key=".$key." is array, we do not output input field for it -->\n";
583 } else {
584 $out .= '<input type="hidden" id="'.$key.'" name="'.$key.'" value="'.$value.'" />'."\n";
585 }
586 }
587
588 $modelmail_array = array();
589 if ($this->param['models'] != 'none') {
590 $result = $this->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs);
591 if ($result < 0) {
592 setEventMessages($this->error, $this->errors, 'errors');
593 }
594
595 foreach ($this->lines_model as $line) {
596 $reg = array();
597 if (preg_match('/\‍((.*)\‍)/', $line->label, $reg)) {
598 $labeltouse = $langs->trans($reg[1]); // langs->trans when label is __(xxx)__
599 } else {
600 $labeltouse = $line->label;
601 }
602
603 // We escape the $labeltouse to store it into $modelmail_array.
604 $modelmail_array[$line->id] = dol_escape_htmltag($labeltouse);
605 if ($line->lang) {
606 $modelmail_array[$line->id] .= ' '.picto_from_langcode($line->lang);
607 }
608 if ($line->private) {
609 $modelmail_array[$line->id] .= ' - <span class="opacitymedium">'.dol_escape_htmltag($langs->trans("Private")).'</span>';
610 }
611 }
612 }
613
614 // Zone to select email template
615 if (count($modelmail_array) > 0) {
616 $model_mail_selected_id = GETPOSTISSET('modelmailselected') ? GETPOSTINT('modelmailselected') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0);
617
618 // If list of template is filled
619 $out .= '<div class="center" style="padding: 0px 0 12px 0">'."\n";
620
621 $out .= $this->selectarray('modelmailselected', $modelmail_array, $model_mail_selected_id, $langs->trans('SelectMailModel'), 0, 0, '', 0, 0, 0, '', 'minwidth100', 1, '', 0, 1);
622 if ($user->admin) {
623 $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')), 1);
624 }
625
626 $out .= ' &nbsp; ';
627 $out .= '<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans('Apply').'" name="modelselected" id="modelselected">';
628 $out .= ' &nbsp; ';
629 $out .= '</div>';
630 } elseif (!empty($this->param['models']) && in_array($this->param['models'], array(
631 'propal_send', 'order_send', 'facture_send',
632 'shipping_send', 'reception_send', 'fichinter_send', 'supplier_proposal_send', 'order_supplier_send',
633 'invoice_supplier_send', 'thirdparty', 'contract', 'user', 'recruitmentcandidature_send', 'product_send', 'all'
634 ))) {
635 // If list of template is empty
636 $out .= '<div class="center" style="padding: 0px 0 12px 0">'."\n";
637 $out .= '<span class="opacitymedium">'.$langs->trans('SelectMailModel').':</span> ';
638 $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.
639 if ($user->admin) {
640 $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')), 1);
641 }
642 $out .= ' &nbsp; ';
643 $out .= '<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans('Apply').'" name="modelselected" disabled="disabled" id="modelselected">';
644 $out .= ' &nbsp; ';
645 $out .= '</div>';
646 } else {
647 $out .= '<!-- No template available for $this->param["models"] = '.$this->param['models'].' -->';
648 }
649
650
651 $out .= '<table class="tableforemailform boxtablenotop centpercent">'."\n";
652
653 // Substitution array/string
654 $helpforsubstitution = '';
655 if (is_array($this->substit) && count($this->substit)) {
656 $helpforsubstitution .= $langs->trans('AvailableVariables').' :<br><br><span class="small">'."\n";
657 foreach ($this->substit as $key => $val) {
658 // Do not show deprecated variables into the tooltip help of substitution variables
659 if (in_array($key, array('__NEWREF__', '__REFCLIENT__', '__REFSUPPLIER__', '__SUPPLIER_ORDER_DATE_DELIVERY__', '__SUPPLIER_ORDER_DELAY_DELIVERY__'))) {
660 continue;
661 }
662 if (is_array($val)) $val = implode(', ', $val); // key __MULTICURRENCY_CODE__ is an array and crashes dolGetFirstLineOfText function which accept only text
663 $helpforsubstitution .= $key.' -> '.$langs->trans(dol_string_nohtmltag(dolGetFirstLineOfText((string) $val))).'<br>';
664 }
665 $helpforsubstitution .= '</span>';
666 }
667
668 /*
669 if (!empty($this->withsubstit)) { // Unset or set ->withsubstit=0 to disable this.
670 $out .= '<tr><td colspan="2" class="right">';
671 if (is_numeric($this->withsubstit)) {
672 $out .= $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip'); // Old usage
673 } else {
674 $out .= $form->textwithpicto($langs->trans('AvailableVariables'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip'); // New usage
675 }
676 $out .= "</td></tr>\n";
677 }*/
678
679 // From
680 if (!empty($this->withfrom)) {
681 if (!empty($this->withfromreadonly)) {
682 $out .= '<tr><td class="fieldrequired minwidth200">'.$langs->trans("MailFrom").'</td><td>';
683
684 // $this->fromtype is the default value to use to select sender
685 if (!($this->fromtype === 'user' && $this->fromid > 0)
686 && !($this->fromtype === 'company')
687 && !($this->fromtype === 'robot')
688 && !preg_match('/user_aliases/', $this->fromtype)
689 && !preg_match('/global_aliases/', $this->fromtype)
690 && !preg_match('/senderprofile/', $this->fromtype)
691 && !preg_match('/from_template_(\d+)/', $this->fromtype)
692 ) {
693 // Use this->fromname and this->frommail or error if not defined
694 $out .= $this->fromname;
695 if ($this->frommail) {
696 $out .= ' &lt;'.$this->frommail.'&gt;';
697 } else {
698 if ($this->fromtype) {
699 $langs->load('errors');
700 $out .= '<span class="warning"> &lt;'.$langs->trans('ErrorNoMailDefinedForThisUser').'&gt; </span>';
701 }
702 }
703 } else {
704 $liste = array();
705
706 // Add user email
707 if (empty($user->email)) {
708 $langs->load('errors');
709 $s = $user->getFullName($langs).' &lt;'.$langs->trans('ErrorNoMailDefinedForThisUser').'&gt;';
710 } else {
711 $s = $user->getFullName($langs).' &lt;'.$user->email.'&gt;';
712 }
713 $liste['user'] = array('label' => $s, 'data-html' => $s);
714
715 // Add also company main email
716 if (getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')) {
717 $s = getDolGlobalString('MAIN_INFO_SOCIETE_NOM', getDolGlobalString('MAIN_INFO_SOCIETE_EMAIL')).' &lt;' . getDolGlobalString('MAIN_INFO_SOCIETE_MAIL').'&gt;';
718 $liste['company'] = array('label' => $s, 'data-html' => $s);
719 }
720
721 // Add also email aliases if there is some
722 $listaliases = array(
723 'user_aliases' => (empty($user->email_aliases) ? '' : $user->email_aliases),
724 'global_aliases' => getDolGlobalString('MAIN_INFO_SOCIETE_MAIL_ALIASES'),
725 );
726
727 if (!empty($arraydefaultmessage->email_from) && !empty($arraydefaultmessage->id)) {
728 $templatemailfrom = ' &lt;'.$arraydefaultmessage->email_from.'&gt;';
729 $liste['from_template_'.((int) $arraydefaultmessage->id)] = array('label' => $templatemailfrom, 'data-html' => $templatemailfrom);
730 }
731
732 // Also add robot email
733 if (!empty($this->fromalsorobot)) {
734 if (getDolGlobalString('MAIN_MAIL_EMAIL_FROM') && getDolGlobalString('MAIN_MAIL_EMAIL_FROM') != getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')) {
735 $s = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
736 if ($this->frommail) {
737 $s .= ' &lt;' . getDolGlobalString('MAIN_MAIL_EMAIL_FROM').'&gt;';
738 }
739 $liste['main_from'] = array('label' => $s, 'data-html' => $s);
740 }
741 }
742
743 // Add also email aliases from the c_email_senderprofile table
744 $sql = "SELECT rowid, label, email FROM ".$this->db->prefix()."c_email_senderprofile";
745 $sql .= " WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).") AND entity IN (".getEntity('c_email_senderprofile').")";
746 $sql .= " ORDER BY position";
747 $resql = $this->db->query($sql);
748 if ($resql) {
749 $num = $this->db->num_rows($resql);
750 $i = 0;
751 while ($i < $num) {
752 $obj = $this->db->fetch_object($resql);
753 if ($obj) {
754 $listaliases['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>';
755 }
756 $i++;
757 }
758 } else {
759 dol_print_error($this->db);
760 }
761
762 foreach ($listaliases as $typealias => $listalias) {
763 $posalias = 0;
764 $listaliasarray = explode(',', $listalias);
765 foreach ($listaliasarray as $listaliasval) {
766 $posalias++;
767 $listaliasval = trim($listaliasval);
768 if ($listaliasval) {
769 $listaliasval = preg_replace('/</', '&lt;', $listaliasval);
770 $listaliasval = preg_replace('/>/', '&gt;', $listaliasval);
771 if (!preg_match('/&lt;/', $listaliasval)) {
772 $listaliasval = '&lt;'.$listaliasval.'&gt;';
773 }
774 $liste[$typealias.'_'.$posalias] = array('label' => $listaliasval, 'data-html' => $listaliasval);
775 }
776 }
777 }
778
779 // Using ajaxcombo here make the '<email>' no more visible on list because <emailofuser> is not a valid html tag,
780 // so we transform before each record into $liste to be printable with ajaxcombo by replacing <> into ()
781 // $liste['senderprofile_0_0'] = array('label'=>'rrr', 'data-html'=>'rrr &lt;aaaa&gt;');
782 foreach ($liste as $key => $val) {
783 if (!empty($liste[$key]['data-html'])) {
784 $liste[$key]['data-html'] = str_replace(array('&lt;', '<', '&gt;', '>'), array('__LTCHAR__', '__LTCHAR__', '__GTCHAR__', '__GTCHAR__'), $liste[$key]['data-html']);
785 $liste[$key]['data-html'] = str_replace(array('__LTCHAR__', '__GTCHAR__'), array('<span class="opacitymedium">(', ')</span>'), $liste[$key]['data-html']);
786 }
787 }
788 $out .= ' '.$form->selectarray('fromtype', $liste, (empty($arraydefaultmessage->email_from) || empty($arraydefaultmessage->id)) ? $this->fromtype : 'from_template_'.((int) $arraydefaultmessage->id), 0, 0, 0, '', 0, 0, 0, '', 'fromforsendingprofile maxwidth200onsmartphone', 1, '', $disablebademails);
789 }
790
791 $out .= "</td></tr>\n";
792 } else {
793 $out .= '<tr><td class="fieldrequired width200">'.$langs->trans("MailFrom")."</td><td>";
794 $out .= $langs->trans("Name").':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.'" />';
795 $out .= '&nbsp; &nbsp; ';
796 $out .= $langs->trans("EMail").':&lt;<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.'" />&gt;';
797 $out .= "</td></tr>\n";
798 }
799 }
800
801 // To
802 if (!empty($this->withto) || is_array($this->withto)) {
803 $out .= $this->getHtmlForTo();
804 }
805
806 // To User
807 if (!empty($this->withtouser) && is_array($this->withtouser) && getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
808 $out .= '<tr><td>';
809 $out .= $langs->trans("MailToUsers");
810 $out .= '</td><td>';
811
812 // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time
813 $tmparray = $this->withtouser;
814 foreach ($tmparray as $key => $val) {
815 $tmparray[$key] = dol_htmlentities($tmparray[$key], 0, 'UTF-8', true);
816 }
817 $withtoselected = GETPOST("receiveruser", 'array'); // Array of selected value
818 if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') {
819 $withtoselected = array_keys($tmparray);
820 }
821 $out .= $form->multiselectarray("receiveruser", $tmparray, $withtoselected, 0, 0, 'inline-block minwidth500', 0, "");
822 $out .= "</td></tr>\n";
823 }
824
825 // With option for one email per recipient
826 if (!empty($this->withoptiononeemailperrecipient)) {
827 if (abs($this->withoptiononeemailperrecipient) == 1) {
828 $out .= '<tr><td class="minwidth200">';
829 $out .= $langs->trans("GroupEmails");
830 $out .= '</td><td>';
831 $out .= ' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ? ' checked="checked"' : '').'> ';
832 $out .= '<label for="oneemailperrecipient">';
833 $out .= $form->textwithpicto($langs->trans("OneEmailPerRecipient"), $langs->trans("WarningIfYouCheckOneRecipientPerEmail"), 1, 'help');
834 $out .= '</label>';
835 //$out .= '<span class="hideonsmartphone opacitymedium">';
836 //$out .= ' - ';
837 //$out .= $langs->trans("WarningIfYouCheckOneRecipientPerEmail");
838 //$out .= '</span>';
839 if (getDolGlobalString('MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL')) {
840 if (!empty($this->withto) && !is_array($this->withto)) {
841 $out .= ' <span class="opacitymedium">'.$langs->trans("or").'</span> <input type="email" name="emailto" value="">';
842 }
843 }
844 $out .= '</td></tr>';
845 } else {
846 $out .= '<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>';
847 }
848 }
849
850 // CC
851 if (!empty($this->withtocc) || is_array($this->withtocc)) {
852 $out .= $this->getHtmlForCc();
853 }
854
855 // To User cc
856 if (!empty($this->withtoccuser) && is_array($this->withtoccuser) && getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
857 $out .= '<tr><td>';
858 $out .= $langs->trans("MailToCCUsers");
859 $out .= '</td><td>';
860
861 // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time
862 $tmparray = $this->withtoccuser;
863 foreach ($tmparray as $key => $val) {
864 $tmparray[$key] = dol_htmlentities($tmparray[$key], 0, 'UTF-8', true);
865 }
866 $withtoselected = GETPOST("receiverccuser", 'array'); // Array of selected value
867 if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') {
868 $withtoselected = array_keys($tmparray);
869 }
870 $out .= $form->multiselectarray("receiverccuser", $tmparray, $withtoselected, 0, 0, 'inline-block minwidth500', 0, "");
871 $out .= "</td></tr>\n";
872 }
873
874 // CCC
875 if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
876 $out .= $this->getHtmlForWithCcc();
877 }
878
879 // Replyto
880 if (!empty($this->withreplyto)) {
881 if ($this->withreplytoreadonly) {
882 $out .= '<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.'" />';
883 $out .= '<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.'" />';
884 $out .= "<tr><td>".$langs->trans("MailReply")."</td><td>".$this->replytoname.($this->replytomail ? (" &lt;".$this->replytomail."&gt;") : "");
885 $out .= "</td></tr>\n";
886 }
887 }
888
889 // Errorsto
890 if (!empty($this->witherrorsto)) {
891 $out .= $this->getHtmlForWithErrorsTo();
892 }
893
894 // Ask delivery receipt
895 if (!empty($this->withdeliveryreceipt) && getDolGlobalInt('MAIN_EMAIL_SUPPORT_ACK')) {
896 $out .= $this->getHtmlForDeliveryreceipt();
897 }
898
899 // Topic
900 if (!empty($this->withtopic)) {
901 $out .= $this->getHtmlForTopic($arraydefaultmessage, $helpforsubstitution);
902 }
903
904 // Attached files
905 if (!empty($this->withfile)) {
906 $out .= '<tr>';
907 $out .= '<td class="tdtop">'.$langs->trans("MailFile").'</td>';
908
909 $out .= '<td>';
910
911 if ($this->withmaindocfile) {
912 // withmaindocfile is set to 1 or -1 to show the checkbox (-1 = checked or 1 = not checked)
913 if (GETPOSTISSET('sendmail')) {
914 $this->withmaindocfile = (GETPOST('addmaindocfile', 'alpha') ? -1 : 1);
915 } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
916 // If a template was selected, we use setup of template to define if join file checkbox is selected or not.
917 $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
918 }
919 }
920
921 if (!empty($this->withmaindocfile)) {
922 if ($this->withmaindocfile == 1) {
923 $out .= '<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />';
924 } elseif ($this->withmaindocfile == -1) {
925 $out .= '<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />';
926 }
927 if (getDolGlobalString('MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND')) {
928 $out .= ' <label for="addmaindocfile">'.$langs->trans("JoinMainDocOrLastGenerated").'.</label><br>';
929 } else {
930 $out .= ' <label for="addmaindocfile">'.$langs->trans("JoinMainDoc").'.</label><br>';
931 }
932 }
933
934 if (is_numeric($this->withfile)) {
935 // TODO Trick to have param removedfile containing nb of file to delete. But this does not works without javascript
936 $out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n";
937 $out .= '<script nonce="'.getNonce().'" type="text/javascript">';
938 $out .= 'jQuery(document).ready(function () {';
939 $out .= ' jQuery(".removedfile").click(function() {';
940 $out .= ' jQuery(".removedfilehidden").val(jQuery(this).val());';
941 $out .= ' });';
942 $out .= '})';
943 $out .= '</script>'."\n";
944 if (count($listofpaths)) {
945 foreach ($listofpaths as $key => $val) {
946 $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
947
948 $entity = (isset($this->param['object_entity']) ? $this->param['object_entity'] : $conf->entity);
949 if ($entity > 1) {
950 $relativepathtofile = str_replace('/'.$entity.'/', '/', $relativepathtofile);
951 }
952 // Try to extract data from full path
953 $formfile_params = array();
954 preg_match('#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params);
955
956 $out .= '<div id="attachfile_'.$key.'">';
957 // Preview of attachment
958 $out .= img_mime($listofnames[$key]).$listofnames[$key];
959
960 $out .= ' '.$formfile->showPreview(array(), $formfile_params[2], $formfile_params[4], 0, ($entity == 1 ? '' : 'entity='.((int) $entity)));
961
962 if (!$this->withfilereadonly) {
963 $out .= ' <input type="image" style="border: 0px;" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/delete.png" value="'.($key + 1).'" class="removedfile input-nobottom" id="removedfile_'.$key.'" name="removedfile_'.$key.'" />';
964 //$out.= ' <a href="'.$_SERVER["PHP_SELF"].'?removedfile='.($key+1).'&id=removedfile_'.$key.'">'.img_delete($langs->trans("Remove"), 'id="removedfile_'.$key.'" name="removedfile_'.$key.'"', 'removedfile input-nobottom').'</a>';
965 }
966 $out .= '<br></div>';
967 }
968 } /*elseif (empty($this->withmaindocfile)) {
969 //$out .= '<span class="opacitymedium">'.$langs->trans("NoAttachedFiles").'</span><br>';
970 }*/
971 if ($this->withfile == 2) {
972 $maxfilesizearray = getMaxFileSizeArray();
973 $maxmin = $maxfilesizearray['maxmin'];
974 if ($maxmin > 0) {
975 $out .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
976 }
977 // Can add other files
978 if (!getDolGlobalString('FROM_MAIL_DONT_USE_INPUT_FILE_MULTIPLE')) {
979 $out .= '<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans("Upload").'" multiple />';
980 } else {
981 $out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
982 }
983 $out .= ' ';
984 $out .= '<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />';
985 }
986 } else {
987 $out .= $this->withfile;
988 }
989
990 $out .= "</td></tr>\n";
991 }
992
993 // Message (+ Links to choose layout or ai prompt)
994 if (!empty($this->withbody)) {
995 $defaultmessage = GETPOST('message', 'restricthtml');
996 if (!GETPOST('modelselected', 'alpha') || GETPOST('modelmailselected') != '-1') {
997 if ($arraydefaultmessage && $arraydefaultmessage->content) {
998 $defaultmessage = (string) $arraydefaultmessage->content;
999 } elseif (!is_numeric($this->withbody)) {
1000 $defaultmessage = $this->withbody;
1001 }
1002 }
1003
1004 // Complete substitution array with the url to make online payment
1005 $paymenturl = '';
1006 // Set the online payment url link into __ONLINE_PAYMENT_URL__ key
1007 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
1008 $validpaymentmethod = getValidOnlinePaymentMethods('');
1009
1010 if (empty($this->substit['__REF__'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
1011 $paymenturl = '';
1012 } else {
1013 $langs->loadLangs(array('paypal', 'other'));
1014 $typeforonlinepayment = 'free';
1015 if ($this->param["models"] == 'order' || $this->param["models"] == 'order_send') {
1016 $typeforonlinepayment = 'order'; // TODO use detection on something else than template
1017 }
1018 if ($this->param["models"] == 'invoice' || $this->param["models"] == 'facture_send') {
1019 $typeforonlinepayment = 'invoice'; // TODO use detection on something else than template
1020 }
1021 if ($this->param["models"] == 'member') {
1022 $typeforonlinepayment = 'member'; // TODO use detection on something else than template
1023 }
1024 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit['__REF__']);
1025 $paymenturl = $url;
1026 }
1027
1028 if (count($validpaymentmethod) > 0 && $paymenturl) {
1029 $langs->load('other');
1030 $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace('\n', "\n", $langs->transnoentities("PredefinedMailContentLink", $paymenturl));
1031 $this->substit['__ONLINE_PAYMENT_URL__'] = $paymenturl;
1032 } elseif (count($validpaymentmethod) > 0) {
1033 $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = '__ONLINE_PAYMENT_TEXT_AND_URL__';
1034 $this->substit['__ONLINE_PAYMENT_URL__'] = '__ONLINE_PAYMENT_URL__';
1035 } else {
1036 $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = '';
1037 $this->substit['__ONLINE_PAYMENT_URL__'] = '';
1038 }
1039
1040 $this->substit['__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] = '';
1041
1042 // Generate the string with the template for lines repeated and filled for each line
1043 $lines = '';
1044 $defaultlines = $arraydefaultmessage->content_lines;
1045 if (isset($defaultlines)) {
1046 foreach ($this->substit_lines as $lineid => $substit_line) {
1047 $lines .= make_substitutions($defaultlines, $substit_line, $outputlangs)."\n";
1048 }
1049 }
1050 $this->substit['__LINES__'] = $lines;
1051
1052 $defaultmessage = str_replace('\n', "\n", $defaultmessage);
1053
1054 // Deal with format differences between message and some substitution variables (text / HTML)
1055 $atleastonecomponentishtml = 0;
1056 if (strpos($defaultmessage, '__USER_SIGNATURE__') !== false && dol_textishtml($this->substit['__USER_SIGNATURE__'])) {
1057 $atleastonecomponentishtml++;
1058 }
1059 if (strpos($defaultmessage, '__SENDEREMAIL_SIGNATURE__') !== false && dol_textishtml($this->substit['__SENDEREMAIL_SIGNATURE__'])) {
1060 $atleastonecomponentishtml++;
1061 }
1062 if (strpos($defaultmessage, '__ONLINE_PAYMENT_TEXT_AND_URL__') !== false && dol_textishtml($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1063 $atleastonecomponentishtml++;
1064 }
1065 if (strpos($defaultmessage, '__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !== false && dol_textishtml($this->substit['__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
1066 $atleastonecomponentishtml++;
1067 }
1068 if (dol_textishtml($defaultmessage)) {
1069 $atleastonecomponentishtml++;
1070 }
1071 if ($atleastonecomponentishtml) {
1072 if (!dol_textishtml($this->substit['__USER_SIGNATURE__'])) {
1073 $this->substit['__USER_SIGNATURE__'] = dol_nl2br($this->substit['__USER_SIGNATURE__']);
1074 }
1075 if (!dol_textishtml($this->substit['__SENDEREMAIL_SIGNATURE__'])) {
1076 $this->substit['__SENDEREMAIL_SIGNATURE__'] = dol_nl2br($this->substit['__SENDEREMAIL_SIGNATURE__']);
1077 }
1078 if (!dol_textishtml($this->substit['__LINES__'])) {
1079 $this->substit['__LINES__'] = dol_nl2br($this->substit['__LINES__']);
1080 }
1081 if (!dol_textishtml($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
1082 $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = dol_nl2br($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__']);
1083 }
1084 if (!dol_textishtml($defaultmessage)) {
1085 $defaultmessage = dol_nl2br($defaultmessage);
1086 }
1087 }
1088
1089 if (GETPOSTISSET("message") && !GETPOST('modelselected')) {
1090 $defaultmessage = GETPOST("message", "restricthtml");
1091 } else {
1092 // Pass $outputlangs so __(TranslationKey)__ in the template body is resolved
1093 // in the language of the selected email template, not the operator's language
1094 // (see issue #34540).
1095 $defaultmessage = make_substitutions($defaultmessage, $this->substit, $outputlangs);
1096 // Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty)
1097 $defaultmessage = preg_replace("/^(<br>)+/", "", $defaultmessage);
1098 $defaultmessage = preg_replace("/^\n+/", "", $defaultmessage);
1099 }
1100
1101 $out .= '<tr>';
1102 $out .= '<td class="tdtop">';
1103 $out .= $form->textwithpicto($langs->trans('MailText'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltipfrombody');
1104 $out .= '</td>';
1105 $out .= '<td class="tdtop">';
1106
1107 $formmail = $this;
1108 $showlinktolayout = ($formmail->withfckeditor && getDolGlobalInt('MAIN_EMAIL_USE_LAYOUT')) ? $formmail->withlayout : '';
1109 $showlinktolayoutlabel = $langs->trans("FillMessageWithALayout");
1110 $showlinktoai = ($formmail->withaiprompt && isModEnabled('ai')) ? 'textgenerationemail' : '';
1111 $showlinktoailabel = $langs->trans("AIEnhancements");
1112 $formatforouput = '';
1113 $htmlname = 'message';
1114
1115 $formai->substit = $this->substit;
1116 $formai->substit_lines = $this->substit_lines;
1117
1118 // Fill $out
1119 $db = $this->db;
1120 include DOL_DOCUMENT_ROOT.'/core/tpl/formlayoutai.tpl.php';
1121
1122 $out .= '</td>';
1123 $out .= '</tr>';
1124
1125 $out .= '<tr>';
1126 $out .= '<td colspan="2">';
1127 if ($this->withbodyreadonly) {
1128 $out .= nl2br($defaultmessage);
1129 $out .= '<input type="hidden" id="message" name="message" disabled value="'.$defaultmessage.'" />';
1130 } else {
1131 if (!isset($this->ckeditortoolbar)) {
1132 $this->ckeditortoolbar = 'dolibarr_mailings';
1133 }
1134
1135 // Editor wysiwyg
1136 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1137 if ($this->withfckeditor == -1) {
1138 if (getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) {
1139 $this->withfckeditor = 1;
1140 } else {
1141 $this->withfckeditor = 0;
1142 }
1143 }
1144
1145 $doleditor = new DolEditor('message', $defaultmessage, '', 280, $this->ckeditortoolbar, 'In', true, true, $this->withfckeditor, 8, '95%');
1146 $out .= $doleditor->Create(1);
1147 }
1148 $out .= "</td></tr>\n";
1149 }
1150
1151 $out .= '</table>'."\n";
1152
1153 if ($this->withform == 1 || $this->withform == -1) {
1154 $out .= '<div class="center">';
1155 $out .= '<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans("SendMail").'"';
1156 // Add a javascript test to avoid to forget to submit file before sending email
1157 if ($this->withfile == 2 && $conf->use_javascript_ajax) {
1158 $out .= ' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans("FileWasNotUploaded")).'\'); return false; } else { return true; }"';
1159 }
1160 $out .= ' />';
1161 if ($this->withcancel) {
1162 $out .= '<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'" />';
1163 }
1164 $out .= '</div>'."\n";
1165 }
1166
1167 if ($this->withform == 1) {
1168 $out .= '</form>'."\n";
1169 }
1170
1171 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1172 if (getDolGlobalString('MAIN_MAILFORM_DISABLE_ENTERKEY')) {
1173 $out .= '<script nonce="'.getNonce().'" type="text/javascript">';
1174 $out .= 'jQuery(document).ready(function () {';
1175 $out .= ' $(document).on("keypress", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1176 var code = e.keyCode || e.which;
1177 if (code == 13) {
1178 console.log("Enter was intercepted and blocked");
1179 e.preventDefault();
1180 return false;
1181 }
1182 });';
1183 $out .= ' })';
1184 $out .= '</script>';
1185 }
1186
1187 $out .= "<!-- End form mail -->\n";
1188
1189 return $out;
1190 }
1191 }
1192
1198 public function getHtmlForTo()
1199 {
1200 global $langs, $form;
1201 $out = '<tr><td class="fieldrequired">';
1202 if ($this->withtofree) {
1203 $out .= $form->textwithpicto($langs->trans("MailTo"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
1204 } else {
1205 $out .= $langs->trans("MailTo");
1206 }
1207 $out .= '</td><td>';
1208 if ($this->withtoreadonly) {
1209 if (!empty($this->toname) && !empty($this->tomail)) {
1210 $out .= '<input type="hidden" id="toname" name="toname" value="'.$this->toname.'" />';
1211 $out .= '<input type="hidden" id="tomail" name="tomail" value="'.$this->tomail.'" />';
1212 if ($this->totype == 'thirdparty') {
1213 $soc = new Societe($this->db);
1214 $soc->fetch($this->toid);
1215 $out .= $soc->getNomUrl(1);
1216 } elseif ($this->totype == 'contact') {
1217 $contact = new Contact($this->db);
1218 $contact->fetch($this->toid);
1219 $out .= $contact->getNomUrl(1);
1220 } else {
1221 $out .= $this->toname;
1222 }
1223 $out .= ' &lt;'.$this->tomail.'&gt;';
1224 if ($this->withtofree) {
1225 $out .= '<br>'.$langs->trans("and").' <input class="minwidth200" id="sendto" name="sendto" spellcheck="false" value="'.(!is_array($this->withto) && !is_numeric($this->withto) ? (GETPOSTISSET("sendto") ? GETPOST("sendto") : $this->withto) : "").'" />';
1226 }
1227 } else {
1228 // Note withto may be a text like 'AllRecipientSelected'
1229 $out .= (!is_array($this->withto) && !is_numeric($this->withto)) ? $this->withto : "";
1230 }
1231 } else {
1232 // The free input of email
1233 if (!empty($this->withtofree)) {
1234 $out .= '<input class="minwidth200" id="sendto" name="sendto" spellcheck="false" value="'.(($this->withtofree && !is_numeric($this->withtofree)) ? $this->withtofree : (!is_array($this->withto) && !is_numeric($this->withto) ? (GETPOSTISSET("sendto") ? GETPOST("sendto") : $this->withto) : "")).'" />';
1235 }
1236 // The select combo
1237 if (!empty($this->withto) && is_array($this->withto)) {
1238 if (!empty($this->withtofree)) {
1239 $out .= ' <span class="opacitymedium">'.$langs->trans("and")."/".$langs->trans("or")."</span> ";
1240 }
1241
1242 $tmparray = $this->withto;
1243 foreach ($tmparray as $key => $val) {
1244 if (is_array($val)) {
1245 $label = $val['label'];
1246 } else {
1247 $label = $val;
1248 }
1249
1250 $tmparray[$key] = array();
1251 $tmparray[$key]['id'] = $key;
1252
1253 $tmparray[$key]['label'] = $label;
1254 $tmparray[$key]['label'] = str_replace(array('<', '>'), array('(', ')'), $tmparray[$key]['label']);
1255 // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time
1256 $tmparray[$key]['label'] = dol_htmlentities($tmparray[$key]['label'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', true);
1257
1258 $tmparray[$key]['labelhtml'] = $label;
1259 $tmparray[$key]['labelhtml'] = str_replace(array('&lt;', '<', '&gt;', '>'), array('__LTCHAR__', '__LTCHAR__', '__GTCHAR__', '__GTCHAR__'), $tmparray[$key]['labelhtml']);
1260 $tmparray[$key]['labelhtml'] = str_replace(array('__LTCHAR__', '__GTCHAR__'), array('<span class="opacitymedium">(', ')</span>'), $tmparray[$key]['labelhtml']);
1261 }
1262
1263 $withtoselected = GETPOST("receiver", 'array'); // Array of selected value
1264 if (!getDolGlobalInt('MAIN_MAIL_NO_WITH_TO_SELECTED')) {
1265 if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') {
1266 $withtoselected = array_keys($tmparray);
1267 }
1268 }
1269
1270 $out .= $form->multiselectarray("receiver", $tmparray, $withtoselected, 0, 0, 'inline-block minwidth500', 0, 0);
1271 }
1272 }
1273 $out .= "</td></tr>\n";
1274 return $out;
1275 }
1276
1282 public function getHtmlForCc()
1283 {
1284 global $langs, $form;
1285 $out = '<tr><td>';
1286 $out .= $form->textwithpicto($langs->trans("MailCC"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
1287 $out .= '</td><td>';
1288 if ($this->withtoccreadonly) {
1289 $out .= (!is_array($this->withtocc) && !is_numeric($this->withtocc)) ? $this->withtocc : "";
1290 } else {
1291 $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 : '')).'" />';
1292 if (!empty($this->withtocc) && is_array($this->withtocc)) {
1293 $out .= ' <span class="opacitymedium">'.$langs->trans("and")."/".$langs->trans("or")."</span> ";
1294
1295 $tmparray = $this->withtocc;
1296 foreach ($tmparray as $key => $val) {
1297 if (is_array($val)) {
1298 $label = $val['label'];
1299 } else {
1300 $label = $val;
1301 }
1302
1303 $tmparray[$key] = array();
1304 $tmparray[$key]['id'] = $key;
1305
1306 $tmparray[$key]['label'] = $label;
1307 $tmparray[$key]['label'] = str_replace(array('<', '>'), array('(', ')'), $tmparray[$key]['label']);
1308 // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time
1309 $tmparray[$key]['label'] = dol_htmlentities($tmparray[$key]['label'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', true);
1310
1311 $tmparray[$key]['labelhtml'] = $label;
1312 $tmparray[$key]['labelhtml'] = str_replace(array('&lt;', '<', '&gt;', '>'), array('__LTCHAR__', '__LTCHAR__', '__GTCHAR__', '__GTCHAR__'), $tmparray[$key]['labelhtml']);
1313 $tmparray[$key]['labelhtml'] = str_replace(array('__LTCHAR__', '__GTCHAR__'), array('<span class="opacitymedium">(', ')</span>'), $tmparray[$key]['labelhtml']);
1314 }
1315
1316 $withtoccselected = GETPOST("receivercc", 'array'); // Array of selected value
1317
1318 $out .= $form->multiselectarray("receivercc", $tmparray, $withtoccselected, 0, 0, 'inline-block minwidth500', 0, 0);
1319 }
1320 }
1321 $out .= "</td></tr>\n";
1322 return $out;
1323 }
1324
1331 public function getHtmlForWithCcc()
1332 {
1333 global $langs, $form;
1334
1335 $out = '<tr><td>';
1336 $out .= $form->textwithpicto($langs->trans("MailCCC"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
1337 $out .= '</td><td>';
1338 if (!empty($this->withtocccreadonly)) {
1339 $out .= (!is_array($this->withtoccc) && !is_numeric($this->withtoccc)) ? $this->withtoccc : "";
1340 } else {
1341 $out .= '<input class="minwidth200" id="sendtoccc" name="sendtoccc" value="'.(GETPOSTISSET("sendtoccc") ? GETPOST("sendtoccc", "alpha") : ((!is_array($this->withtoccc) && !is_numeric($this->withtoccc)) ? $this->withtoccc : '')).'" />';
1342 if (!empty($this->withtoccc) && is_array($this->withtoccc)) {
1343 $out .= ' <span class="opacitymedium">'.$langs->trans("and")."/".$langs->trans("or")."</span> ";
1344
1345 $tmparray = $this->withtoccc;
1346 foreach ($tmparray as $key => $val) {
1347 if (is_array($val)) {
1348 $label = $val['label'];
1349 } else {
1350 $label = $val;
1351 }
1352 $tmparray[$key] = array();
1353 $tmparray[$key]['id'] = $key;
1354
1355 $tmparray[$key]['label'] = $label;
1356 $tmparray[$key]['label'] = str_replace(array('<', '>'), array('(', ')'), $tmparray[$key]['label']);
1357 // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time
1358 $tmparray[$key]['label'] = dol_htmlentities($tmparray[$key]['label'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', true);
1359
1360 $tmparray[$key]['labelhtml'] = $label;
1361 $tmparray[$key]['labelhtml'] = str_replace(array('&lt;', '<', '&gt;', '>'), array('__LTCHAR__', '__LTCHAR__', '__GTCHAR__', '__GTCHAR__'), $tmparray[$key]['labelhtml']);
1362 $tmparray[$key]['labelhtml'] = str_replace(array('__LTCHAR__', '__GTCHAR__'), array('<span class="opacitymedium">(', ')</span>'), $tmparray[$key]['labelhtml']);
1363 }
1364
1365 $withtocccselected = GETPOST("receiverccc", 'array'); // Array of selected value
1366
1367 $out .= $form->multiselectarray("receiverccc", $tmparray, $withtocccselected, 0, 0, 'inline-block minwidth500', 0, 0);
1368 }
1369 }
1370
1371 $showinfobcc = '';
1372 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_PROPOSAL_TO') && !empty($this->param['models']) && $this->param['models'] == 'propal_send') {
1373 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_PROPOSAL_TO');
1374 }
1375 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_ORDER_TO') && !empty($this->param['models']) && $this->param['models'] == 'order_send') {
1376 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_ORDER_TO');
1377 }
1378 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_INVOICE_TO') && !empty($this->param['models']) && $this->param['models'] == 'facture_send') {
1379 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_INVOICE_TO');
1380 }
1381 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO') && !empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') {
1382 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO');
1383 }
1384 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO') && !empty($this->param['models']) && $this->param['models'] == 'order_supplier_send') {
1385 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO');
1386 }
1387 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO') && !empty($this->param['models']) && $this->param['models'] == 'invoice_supplier_send') {
1388 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO');
1389 }
1390 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_PROJECT_TO') && !empty($this->param['models']) && $this->param['models'] == 'project') { // don't know why there is not '_send' at end of this models name.
1391 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_PROJECT_TO');
1392 }
1393 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_SHIPMENT_TO') && !empty($this->param['models']) && $this->param['models'] == 'shipping_send') {
1394 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_SHIPMENT_TO');
1395 }
1396 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_RECEPTION_TO') && !empty($this->param['models']) && $this->param['models'] == 'reception_send') {
1397 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_RECEPTION_TO');
1398 }
1399 if ($showinfobcc) {
1400 $out .= ' + '.$showinfobcc;
1401 }
1402 $out .= "</td></tr>\n";
1403 return $out;
1404 }
1405
1411 public function getHtmlForWithErrorsTo()
1412 {
1413 global $langs;
1414
1415 //if (! $this->errorstomail) $this->errorstomail=$this->frommail;
1416 $errorstomail = getDolGlobalString('MAIN_MAIL_ERRORS_TO', (!empty($this->errorstomail) ? $this->errorstomail : ''));
1417 if ($this->witherrorstoreadonly) {
1418 $out = '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td>';
1419 $out .= '<input type="hidden" id="errorstomail" name="errorstomail" value="'.$errorstomail.'" />';
1420 $out .= $errorstomail;
1421 $out .= "</td></tr>\n";
1422 } else {
1423 $out = '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td>';
1424 $out .= '<input class="minwidth200" id="errorstomail" name="errorstomail" value="'.$errorstomail.'" />';
1425 $out .= "</td></tr>\n";
1426 }
1427 return $out;
1428 }
1429
1435 public function getHtmlForDeliveryreceipt()
1436 {
1437 global $langs;
1438
1439 $out = '<tr><td><label for="deliveryreceipt">'.$langs->trans("DeliveryReceipt").'</label></td><td>';
1440
1441 if (!empty($this->withdeliveryreceiptreadonly)) {
1442 $out .= yn($this->withdeliveryreceipt);
1443 } else {
1444 $defaultvaluefordeliveryreceipt = 0;
1445 if (getDolGlobalString('MAIL_FORCE_DELIVERY_RECEIPT_PROPAL') && !empty($this->param['models']) && $this->param['models'] == 'propal_send') {
1446 $defaultvaluefordeliveryreceipt = 1;
1447 }
1448 if (getDolGlobalString('MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_PROPOSAL') && !empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') {
1449 $defaultvaluefordeliveryreceipt = 1;
1450 }
1451 if (getDolGlobalString('MAIL_FORCE_DELIVERY_RECEIPT_ORDER') && !empty($this->param['models']) && $this->param['models'] == 'order_send') {
1452 $defaultvaluefordeliveryreceipt = 1;
1453 }
1454 if (getDolGlobalString('MAIL_FORCE_DELIVERY_RECEIPT_INVOICE') && !empty($this->param['models']) && $this->param['models'] == 'facture_send') {
1455 $defaultvaluefordeliveryreceipt = 1;
1456 }
1457 if (getDolGlobalString('MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_ORDER') && !empty($this->param['models']) && $this->param['models'] == 'order_supplier_send') {
1458 $defaultvaluefordeliveryreceipt = 1;
1459 }
1460 //$out .= $form->selectyesno('deliveryreceipt', (GETPOSTISSET("deliveryreceipt") ? GETPOST("deliveryreceipt") : $defaultvaluefordeliveryreceipt), 1);
1461 $out .= '<input type="checkbox" id="deliveryreceipt" name="deliveryreceipt" value="1"'.((GETPOSTISSET("deliveryreceipt") ? GETPOST("deliveryreceipt") : $defaultvaluefordeliveryreceipt) ? ' checked="checked"' : '').'>';
1462 }
1463 $out .= "</td></tr>\n";
1464 return $out;
1465 }
1466
1474 public function getHtmlForTopic($arraydefaultmessage, $helpforsubstitution)
1475 {
1476 global $conf, $langs, $form;
1477
1478 $defaulttopic = GETPOST('subject', 'restricthtml');
1479
1480 if (!GETPOST('modelselected', 'alpha') || GETPOST('modelmailselected') != '-1') {
1481 if ($arraydefaultmessage && $arraydefaultmessage->topic) {
1482 $defaulttopic = $arraydefaultmessage->topic;
1483 } elseif (!is_numeric($this->withtopic)) {
1484 $defaulttopic = $this->withtopic;
1485 }
1486 }
1487
1488 // Resolve __(TranslationKey)__ in the language of the selected template
1489 // (see issue #34540). Falls back to the caller's language when the template
1490 // has no explicit language pinned.
1491 $outputlangs = $langs;
1492 if (is_object($arraydefaultmessage) && !empty($arraydefaultmessage->lang)) {
1493 $outputlangs = new Translate("", $conf);
1494 $outputlangs->setDefaultLang($arraydefaultmessage->lang);
1495 $outputlangs->load('other');
1496 }
1497
1498 $defaulttopic = make_substitutions($defaulttopic, $this->substit, $outputlangs);
1499
1500 $out = '<tr>';
1501 $out .= '<td class="fieldrequired">';
1502 $out .= $form->textwithpicto($langs->trans('MailTopicShort'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltipfromtopic');
1503 $out .= '</td>';
1504 $out .= '<td>';
1505 if ($this->withtopicreadonly) {
1506 $out .= $defaulttopic;
1507 $out .= '<input type="hidden" class="quatrevingtpercent" id="subject" name="subject" value="'.$defaulttopic.'" />';
1508 } else {
1509 $out .= '<input type="text" class="quatrevingtpercent" id="subject" name="subject" value="'.((GETPOSTISSET("subject") && !GETPOST('modelselected')) ? GETPOST("subject") : ($defaulttopic ? $defaulttopic : '')).'" />';
1510 }
1511 $out .= "</td></tr>\n";
1512 return $out;
1513 }
1514
1523 public function getEmailLayoutSelector($htmlContent = 'message', $showlinktolayout = 'email')
1524 {
1525 global $conf, $db, $websitepage, $langs;
1526
1527 require_once DOL_DOCUMENT_ROOT.'/core/lib/emaillayout.lib.php';
1528 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1529 require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
1530 require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
1531
1532 $out = '<div id="template-selector" class="template-selector email-layout-container hidden" style="display:none;">';
1533
1534 // Define list of email layouts to use
1535 $layouts = array(
1536 'none' => 'None',
1537 );
1538 // Add layouts found on disk in install/doctemplates/maillayout directory
1539 $arrayoflayoutemplates = dol_dir_list(DOL_DOCUMENT_ROOT.'/install/doctemplates/maillayout/', 'files', 0, '\.html$');
1540 foreach ($arrayoflayoutemplates as $layouttemplatefile) {
1541 $layoutname = preg_replace('/\.html$/i', '', $layouttemplatefile['name']);
1542
1543 // Exclude some layouts for some use cases
1544 if ($layoutname == 'news' && (!in_array($showlinktolayout, array('emailing', 'websitepage')) || !isModEnabled('website'))) {
1545 continue;
1546 }
1547 if ($layoutname == 'product' && (!in_array($showlinktolayout, array('emailing', 'websitepage')) || (!isModEnabled('product') && !isModEnabled('service')))) {
1548 continue;
1549 }
1550
1551 $layouts[$layoutname] = ucfirst($layoutname);
1552 }
1553 //}
1554 // TODO Add a hook to allow to complete the list
1555 foreach ($layouts as $layout => $templateFunction) {
1556 $contentHtml = getHtmlOfLayout($layout);
1557
1558 $out .= '<div class="template-option" data-template="'.$layout.'" data-content="'.htmlentities($contentHtml).'">';
1559 $out .= '<img class="maillayout" alt="'.$layout.'" src="'.DOL_URL_ROOT.'/theme/common/maillayout/'.$layout.'.png" />';
1560 $out .= '<span class="template-option-text">'.$langs->trans($templateFunction).'</span>';
1561 $out .= '</div>';
1562 }
1563 $out .= '</div>';
1564
1565 // Prepare the array for multiselect
1566
1567 // Fetch blogs
1568 $blogArray = array();
1569 if (isModEnabled('website')) {
1570 $websitepage = new WebsitePage($this->db);
1571 $arrayofblogs = $websitepage->fetchAll('', 'ASC,DESC', 'fk_website,date_creation', 0, 0, array('type_container' => 'blogpost'));
1572
1573 if (empty($conf->cache['websiteurl'])) {
1574 $conf->cache['websiteurl'] = array();
1575 }
1576
1577 if (!empty($arrayofblogs)) {
1578 foreach ($arrayofblogs as $blog) {
1579 if (!isset($conf->cache['websiteurl'][$blog->id])) {
1580 $tmpwebsite = new Website($db);
1581 $tmpwebsite->fetch($blog->fk_website);
1582 $conf->cache['websiteurl'][$blog->fk_website] = (empty($tmpwebsite->virtualhost) ? $tmpwebsite->ref : $tmpwebsite->virtualhost);
1583 }
1584
1585 $labelwebsite = $conf->cache['websiteurl'][$blog->fk_website];
1586 //$blog->fk_website
1587
1588 $blogArray[$blog->id] = array(
1589 'id' => $blog->id,
1590 'label' => '['.$labelwebsite.' '.$blog->type_container.' '.$blog->id.'] '.dol_trunc($blog->title, 40),
1591 'labelhtml' => '<span class="opacitymedium">['.$labelwebsite.' '.$blog->type_container.' '.$blog->id.']</span> '.dol_trunc($blog->title, 40),
1592 );
1593 }
1594 }
1595 }
1596
1597 // Fetch Product / Services
1598 /* to use with multiselectarray but consume too much memory so replaced
1599 if (in_array('product', array_keys($layouts))) {
1600 $productArray = array();
1601 if (isModEnabled('product') || isModEnabled('service')) {
1602 include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
1603 $form = new Form($this->db);
1604 $arrayofproduct = $form->select_produits_list(0, 'product-select', '', 0, 0, '', 1, 2, 1);
1605 if (!empty($arrayofproduct)) {
1606 foreach ($arrayofproduct as $product) {
1607 $productArray[$product["key"]] = array(
1608 'id' => $product["key"],
1609 'label' => $product["value"].' - '.dol_trunc($product["label2"], 40),
1610 'labelhtml' => $product["value"].' - '.dol_trunc($product["label2"], 40),
1611 );
1612 }
1613 }
1614 }
1615 }
1616 */
1617
1618 // Use the multiselect array function to create the dropdown
1619 if (in_array('news', array_keys($layouts)) && (isModEnabled('product') || isModEnabled('service'))) {
1620 $out .= '<div id="post-dropdown-container" class="email-layout-container hidden" style="height: 32px; display:none;">';
1621 $out .= '<label for="blogpost-select">Select Posts: </label>';
1622 $out .= '<!-- select component for selection of blog posts -->'."\n";
1623 // TODO WARNING: multiselectarray is ok only for very small list
1624 $out .= self::multiselectarray('blogpost-select', $blogArray, array(), 0, 0, 'minwidth200 select-template');
1625 $out .= ' <input type="submit" class="smallpaddingimp button reposition" name="submit" id="post-submit" value="'.dolPrintHTMLForAttribute($langs->trans("Select")).'">';
1626 $out .= '</div>';
1627 }
1628 if (in_array('product', array_keys($layouts)) && (isModEnabled('product') || isModEnabled('service'))) {
1629 include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
1630 $form = new Form($this->db);
1631 $out .= '<div id="product-dropdown-container" class="email-layout-container hidden" style="height: 32px; display:none;">';
1632 $out .= '<label for="product-select">'.img_picto('', 'product', 'class="pictofixedwidth"').$langs->trans("Product").' : </label>';
1633 $out .= '<!-- select component for selection of product -->'."\n";
1634 $out .= $form->select_produits(0, 'product-select', '', 0, 0, -1, 2, '', 0, array(), 0, '1', 0, 'inline-block valignmiddle', 0, '', null, 1);
1635 // TODO multiselectarray is ok only for very small list but is ok for multiselect. We need a multiselect ok with ajax for long list
1636 //$out .= self::multiselectarray('product-select', $productArray, array(), 0, 0, 'minwidth200 select-template');
1637 $out .= ' <input type="submit" class="smallpaddingimp button reposition" name="submit" id="product-submit" value="'.dolPrintHTMLForAttribute($langs->trans("Select")).'">';
1638 $out .= '</div>';
1639 }
1640
1641 $out .= '<!-- Js code to manage choice of an email layout -->'."\n";
1642 $out .= '<script type="text/javascript">
1643 $(document).ready(function() {
1644 $(".template-option").click(function() {
1645 var template = $(this).data("template");
1646 var subject = jQuery("#subject").val();
1647 var fromtype = jQuery("#fromtype").val();
1648 var sendto = jQuery("#sendto").val();
1649 var sendtocc = jQuery("#sendtocc").val();
1650 var sendtoccc = jQuery("#sendtoccc").val();
1651
1652 console.log("We choose a layout for email template=" + template + ", subject="+subject);
1653
1654 $(".template-option").removeClass("selected");
1655 $(this).addClass("selected");
1656 $(".select-template").val("").trigger("change");
1657
1658 if (template === "news") {
1659 $("#post-dropdown-container").show();
1660 $("#product-dropdown-container").hide();
1661 console.log("Displaying dropdown for news selection");
1662 } else if (template === "product") {
1663 $("#product-dropdown-container").show();
1664 $("#post-dropdown-container").hide();
1665 console.log("Displaying dropdown for product selection");
1666 } else {
1667 $("#post-dropdown-container").hide();
1668 $("#product-dropdown-container").hide();
1669 }
1670
1671 var csrfToken = "' .newToken().'";
1672 $.ajax({
1673 type: "POST",
1674 url: "'.DOL_URL_ROOT.'/core/ajax/mailtemplate.php",
1675 data: {
1676 token: csrfToken,
1677 template: template,
1678 subject: subject,
1679 fromtype: fromtype,
1680 sendto: sendto,
1681 sendtocc: sendtocc,
1682 sendtoccc: sendtoccc,
1683 selectedPosts: "[]"
1684 },
1685 success: function(response) {
1686 jQuery("#'.$htmlContent.'").val(response);
1687 var editorInstance = CKEDITOR.instances["'.$htmlContent.'"];
1688 if (editorInstance) {
1689 editorInstance.setData(response);
1690 }
1691 },
1692 error: function(xhr, status, error) {
1693 console.error("An error occurred: " + xhr.responseText);
1694 }
1695 });
1696 });
1697
1698 $("#blogpost-select").change(function() {
1699 var selectedIds = $(this).val();
1700 var contentHtml = $(".template-option.selected").data("content");
1701
1702 updateSelectedPostsContent(contentHtml, selectedIds);
1703 });
1704 $("#product-select").change(function() {
1705 var selectedIds = $(this).val();
1706 var contentHtml = $(".template-option.selected").data("content");
1707
1708 updateSelectedPostsContent(contentHtml, selectedIds);
1709 });
1710
1711 function updateSelectedPostsContent(contentHtml, selectedIds) {
1712 var csrfToken = "' .newToken().'";
1713 template = $(".template-option.selected").data("template");
1714 var subject = $("#subject").val();
1715 $.ajax({
1716 type: "POST",
1717 url: "'.dol_buildpath('/core/ajax/mailtemplate.php', 1).'",
1718 data: {
1719 token: csrfToken,
1720 template: template,
1721 subject: subject,
1722 selectedPosts: JSON.stringify(selectedIds)
1723 },
1724 success: function(response) {
1725 jQuery("#'.$htmlContent.'").val(response);
1726 var editorInstance = CKEDITOR.instances["'.$htmlContent.'"];
1727 if (editorInstance) {
1728 editorInstance.setData(response);
1729 }
1730 },
1731 error: function(xhr, status, error) {
1732 console.error("An error occurred: " + xhr.responseText);
1733 }
1734 });
1735
1736 }
1737 });
1738 </script>';
1739
1740 return $out;
1741 }
1742
1760 public function getEMailTemplate($dbs, $type_template, $user, $outputlangs, $id = 0, $active = 1, $label = '', $defaultfortype = -1)
1761 {
1762 global $conf;
1763
1764 if ($id == -2 && empty($label)) {
1765 $this->error = 'LabelIsMandatoryWhenIdIs-2or-3';
1766 return -1;
1767 }
1768 if ($type_template === 'societe') {
1769 $type_template = 'thirdparty';
1770 }
1771 $ret = new CEmailTemplate($dbs);
1772
1773 $languagetosearch = (is_object($outputlangs) ? $outputlangs->defaultlang : '');
1774 // Define $languagetosearchmain to fall back on main language (for example to get 'es_ES' for 'es_MX')
1775 $tmparray = explode('_', $languagetosearch);
1776 $languagetosearchmain = $tmparray[0].'_'.strtoupper($tmparray[0]);
1777 if ($languagetosearchmain == $languagetosearch) {
1778 $languagetosearchmain = '';
1779 }
1780
1781 $sql = "SELECT rowid, entity, module, label, type_template, topic, email_from, joinfiles, content, content_lines, lang, email_from, email_to, email_tocc, email_tobcc";
1782 $sql .= " FROM ".$dbs->prefix().'c_email_templates';
1783 $sql .= " WHERE (type_template = '".$dbs->escape($type_template)."' OR type_template = '".$dbs->escape($type_template)."_send' OR type_template = 'all')";
1784 $sql .= " AND entity IN (".getEntity('c_email_templates').")";
1785 $sql .= " AND (private = 0 OR fk_user = ".((int) $user->id).")"; // Get all public or private owned
1786 if ($active >= 0) {
1787 $sql .= " AND active = ".((int) $active);
1788 }
1789 if ($defaultfortype >= 0) {
1790 $sql .= " AND defaultfortype = ".((int) $defaultfortype);
1791 }
1792 if ($label) {
1793 $sql .= " AND label = '".$dbs->escape($label)."'";
1794 }
1795 if (!($id > 0) && $languagetosearch) {
1796 $sql .= " AND (lang = '".$dbs->escape($languagetosearch)."'".($languagetosearchmain ? " OR lang = '".$dbs->escape($languagetosearchmain)."'" : "")." OR lang IS NULL OR lang = '')";
1797 }
1798 if ($id > 0) {
1799 $sql .= " AND rowid = ".(int) $id;
1800 }
1801 if ($id == -1) {
1802 $sql .= " AND position = 0";
1803 }
1804 $sql .= " AND entity IN(".getEntity('c_email_templates', 1).")";
1805 if ($languagetosearch) {
1806 $sql .= $dbs->order("position,lang,label", "ASC,DESC,ASC"); // We want line with lang set first, then with lang null or ''
1807 } else {
1808 $sql .= $dbs->order("position,lang,label", "ASC,ASC,ASC"); // If no language provided, we give priority to lang not defined
1809 }
1810 //$sql .= $dbs->plimit(1);
1811 //print $sql;
1812
1813 $resql = $dbs->query($sql);
1814 if (!$resql) {
1815 dol_print_error($dbs);
1816 return -1;
1817 }
1818
1819 // Get first found
1820 while (1) {
1821 $obj = $dbs->fetch_object($resql);
1822
1823 if ($obj) {
1824 // If template is for a module, check module is enabled; if not, take next template
1825 if ($obj->module) {
1826 $tempmodulekey = $obj->module;
1827 if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1828 continue;
1829 }
1830 }
1831
1832 // If a record was found
1833 $ret->id = (int) $obj->rowid;
1834 $ret->module = (string) $obj->module;
1835 $ret->label = (string) $obj->label;
1836 $ret->lang = $obj->lang;
1837 $ret->topic = $obj->topic;
1838 $ret->content = (string) $obj->content;
1839 $ret->content_lines = (string) $obj->content_lines;
1840 $ret->joinfiles = $obj->joinfiles;
1841 $ret->email_from = (string) $obj->email_from;
1842
1843 break;
1844 } else {
1845 // If no record found
1846 if ($id == -2) {
1847 // Not found with the provided label
1848 return -1;
1849 } else {
1850 // If there is no template at all
1851 $defaultmessage = '';
1852
1853 if ($type_template == 'body') {
1854 // Special case to use this->withbody as content
1855 $defaultmessage = (string) $this->withbody;
1856 } elseif ($type_template == 'facture_send' || $type_template == 'facture' || $type_template == 'facture_relance') {
1857 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoice");
1858 } elseif ($type_template == 'propal_send' || $type_template == 'propal') {
1859 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendProposal");
1860 } elseif ($type_template == 'supplier_proposal_send' || $type_template == 'supplier_proposal') {
1861 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierProposal");
1862 } elseif ($type_template == 'order_send' || $type_template == 'order') {
1863 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendOrder");
1864 } elseif ($type_template == 'order_supplier_send' || $type_template == 'order_supplier') {
1865 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder");
1866 } elseif ($type_template == 'invoice_supplier_send' || $type_template == 'invoice_supplier') {
1867 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice");
1868 } elseif ($type_template == 'shipping_send' || $type_template == 'shipping') {
1869 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendShipping");
1870 } elseif ($type_template == 'reception_send' || $type_template == 'reception') {
1871 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendReception");
1872 } elseif ($type_template == 'fichinter_send' || $type_template == 'fichinter') {
1873 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendFichInter");
1874 } elseif ($type_template == 'actioncomm_send' || $type_template == 'actioncomm') {
1875 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendActionComm");
1876 } elseif (!empty($type_template)) {
1877 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentGeneric");
1878 }
1879
1880 $ret->label = 'default';
1881 $ret->lang = $outputlangs->defaultlang;
1882 $ret->topic = '';
1883 $ret->joinfiles = 1;
1884 $ret->content = $defaultmessage;
1885 $ret->content_lines = '';
1886
1887 break;
1888 }
1889 }
1890 }
1891
1892 $dbs->free($resql);
1893
1894 return $ret;
1895 }
1896
1906 public function isEMailTemplate($type_template, $user, $outputlangs)
1907 {
1908 $sql = "SELECT label, topic, content, lang";
1909 $sql .= " FROM ".$this->db->prefix().'c_email_templates';
1910 $sql .= " WHERE type_template='".$this->db->escape($type_template)."'";
1911 $sql .= " AND entity IN (".getEntity('c_email_templates').")";
1912 $sql .= " AND (fk_user is NULL or fk_user = 0 or fk_user = ".((int) $user->id).")";
1913 if (is_object($outputlangs)) {
1914 $sql .= " AND (lang = '".$this->db->escape($outputlangs->defaultlang)."' OR lang IS NULL OR lang = '')";
1915 }
1916 $sql .= $this->db->order("lang,label", "ASC");
1917 //print $sql;
1918
1919 $resql = $this->db->query($sql);
1920 if ($resql) {
1921 $num = $this->db->num_rows($resql);
1922 $this->db->free($resql);
1923 return $num;
1924 } else {
1925 $this->error = get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1926 return -1;
1927 }
1928 }
1929
1940 public function fetchAllEMailTemplate($type_template, $user, $outputlangs, $active = 1)
1941 {
1942 global $db, $conf;
1943
1944 $sql = "SELECT rowid, module, label, topic, content, content_lines, lang, fk_user, private, position";
1945 $sql .= " FROM ".$this->db->prefix().'c_email_templates';
1946 $sql .= " WHERE type_template IN ('".$this->db->escape($type_template)."', 'all')";
1947 $sql .= " AND entity IN (".getEntity('c_email_templates').")";
1948 $sql .= " AND (private = 0 OR fk_user = ".((int) $user->id).")"; // See all public templates or templates I own.
1949 if ($active >= 0) {
1950 $sql .= " AND active = ".((int) $active);
1951 }
1952 //if (is_object($outputlangs)) $sql.= " AND (lang = '".$this->db->escape($outputlangs->defaultlang)."' OR lang IS NULL OR lang = '')"; // Return all languages
1953 $sql .= $this->db->order("position,lang,label", "ASC");
1954 //print $sql;
1955
1956 $resql = $this->db->query($sql);
1957 if ($resql) {
1958 $num = $this->db->num_rows($resql);
1959 $this->lines_model = array();
1960 while ($obj = $this->db->fetch_object($resql)) {
1961 // If template is for a module, check module is enabled.
1962 if ($obj->module) {
1963 $tempmodulekey = $obj->module;
1964 if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1965 continue;
1966 }
1967 }
1968
1969 $line = new CEmailTemplate($db);
1970 $line->id = (int) $obj->rowid;
1971 $line->label = (string) $obj->label;
1972 $line->lang = $obj->lang;
1973 $line->fk_user = $obj->fk_user;
1974 $line->private = $obj->private;
1975 $line->position = $obj->position;
1976 $line->topic = $obj->topic;
1977 $line->content = $obj->content;
1978 $line->content_lines = $obj->content_lines;
1979
1980 $this->lines_model[] = $line;
1981 }
1982 $this->db->free($resql);
1983 return $num;
1984 } else {
1985 $this->error = get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1986 return -1;
1987 }
1988 }
1989
1990
1991
2000 public function setSubstitFromObject($object, $outputlangs)
2001 {
2002 global $extrafields;
2003
2004 $parameters = array();
2005 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
2006 complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
2007
2008 $this->substit = $tmparray;
2009
2010 // Fill substit_lines with each object lines content
2011 if (is_array($object->lines)) {
2012 foreach ($object->lines as $line) {
2013 $substit_line = array(
2014 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
2015 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
2016 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
2017 '__LABEL__' => isset($line->label) ? $line->label : '',
2018 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
2019 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', false, $outputlangs),
2020 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', false, $outputlangs),
2021 '__QUANTITY__' => $line->qty,
2022 '__SUBPRICE__' => price($line->subprice),
2023 '__AMOUNT__' => price($line->total_ttc),
2024 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
2025 );
2026
2027 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
2028 if (!empty($line->fk_product)) {
2029 if (!is_object($extrafields)) {
2030 $extrafields = new ExtraFields($this->db);
2031 }
2032 $product = new Product($this->db);
2033 $product->fetch($line->fk_product, '', '', '1');
2034 $product->fetch_optionals();
2035
2036 $extrafields->fetch_name_optionals_label($product->table_element, true);
2037
2038 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
2039 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
2040 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
2041 }
2042 }
2043 }
2044
2045 $this->substit_lines[$line->id] = $substit_line; // @phan-suppress-current-line PhanTypeMismatchProperty
2046 }
2047 }
2048 }
2049
2058 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
2059 {
2060 global $langs;
2061
2062 $tmparray = array();
2063 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
2064 $parameters = array('mode' => $mode);
2065 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
2066 complete_substitutions_array($tmparray, $langs, null, $parameters);
2067
2068 if ($mode == 'formwithlines') {
2069 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
2070 }
2071 if ($mode == 'formforlines') {
2072 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
2073 }
2074 }
2075
2076 if ($mode == 'emailing') {
2077 $parameters = array('mode' => $mode);
2078 $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
2079 complete_substitutions_array($tmparray, $langs, null, $parameters);
2080
2081 // For mass emailing, we have different keys specific to the data into tagerts list
2082 $tmparray['__ID__'] = 'IdRecord';
2083 $tmparray['__EMAIL__'] = 'EMailRecipient';
2084 $tmparray['__LASTNAME__'] = 'Lastname';
2085 $tmparray['__FIRSTNAME__'] = 'Firstname';
2086 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
2087 $tmparray['__OTHER1__'] = 'Other1';
2088 $tmparray['__OTHER2__'] = 'Other2';
2089 $tmparray['__OTHER3__'] = 'Other3';
2090 $tmparray['__OTHER4__'] = 'Other4';
2091 $tmparray['__OTHER5__'] = 'Other5';
2092
2093 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode'; // If source is a thirdparty
2094
2095 $tmparray['__CHECK_READ__'] = $langs->trans('TagCheckMail');
2096 $tmparray['__UNSUBSCRIBE__'] = $langs->trans('TagUnsubscribe');
2097 $tmparray['__UNSUBSCRIBE_URL__'] = $langs->trans('TagUnsubscribe').' (URL)';
2098
2099 $onlinepaymentenabled = 0;
2100 if (isModEnabled('paypal')) {
2101 $onlinepaymentenabled++;
2102 }
2103 if (isModEnabled('paybox')) {
2104 $onlinepaymentenabled++;
2105 }
2106 if (isModEnabled('stripe')) {
2107 $onlinepaymentenabled++;
2108 }
2109 if ($onlinepaymentenabled && getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
2110 $tmparray['__SECUREKEYPAYMENT__'] = getDolGlobalString('PAYMENT_SECURITY_TOKEN');
2111 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
2112 if (isModEnabled('member')) {
2113 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
2114 }
2115 if (isModEnabled('don')) {
2116 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
2117 }
2118 if (isModEnabled('invoice')) {
2119 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
2120 }
2121 if (isModEnabled('order')) {
2122 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
2123 }
2124 if (isModEnabled('contract')) {
2125 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
2126 }
2127
2128 //Online payment link
2129 if (isModEnabled('member')) {
2130 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
2131 }
2132 if (isModEnabled('don')) {
2133 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
2134 }
2135 if (isModEnabled('invoice')) {
2136 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
2137 }
2138 if (isModEnabled('order')) {
2139 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
2140 }
2141 if (isModEnabled('contract')) {
2142 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
2143 }
2144 }
2145 } else {
2146 /* No need to show into tooltip help, option is not enabled
2147 $vars['__SECUREKEYPAYMENT__']='';
2148 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
2149 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
2150 $vars['__SECUREKEYPAYMENT_ORDER__']='';
2151 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
2152 */
2153 }
2154 if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) {
2155 $tmparray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
2156 }
2157 }
2158
2159 foreach ($tmparray as $key => $val) {
2160 if (empty($val)) {
2161 $tmparray[$key] = $key;
2162 }
2163 }
2164
2165 return $tmparray;
2166 }
2167}
print $object position
Definition edit.php:207
Class to manage a WYSIWYG editor.
Class permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new Form...
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
static selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='minwidth75', $addjscombo=1, $moreparamonempty='', $disablebademail=0, $nohtmlescape=0)
Return a HTML select string, built from an array of key+value.
Class permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new Form...
get_attached_files()
Return list of attached files (stored in SECTION array)
getHtmlForWithErrorsTo()
get Html For WithErrorsTo
getHtmlForTopic($arraydefaultmessage, $helpforsubstitution)
Return Html section for the 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_model.
getHtmlForCc()
get html For CC
getHtmlForTo()
get html For To
add_attached_files($path, $file='', $type='')
Add a file into the list of attached files (stored in SECTION array)
getHtmlForWithCcc()
get html For WithCCC This information is show when MAIN_EMAIL_USECCC is set.
remove_attached_files($keytodelete)
Remove a file from the list of attached files (stored in SECTION array)
__construct($db)
Constructor.
getHtmlForDeliveryreceipt()
get Html For Asking for Delivery Receipt
getEMailTemplate($dbs, $type_template, $user, $outputlangs, $id=0, $active=1, $label='', $defaultfortype=-1)
Return templates of email with type = $type_template or type = 'all'.
show_form($addfileaction='addfile', $removefileaction='removefile')
Show the form to input an email this->withfile: 0=No attaches files, 1=Show attached files,...
get_form($addfileaction='addfile', $removefileaction='removefile')
Get the form to input an email this->withfile: 0=No attaches files, 1=Show attached files,...
Class to manage products or services.
Class to manage translations.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
getDolGlobalInt($key, $default=0)
Return a 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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
editval_textarea active
getMaxFileSizeArray()
Return the max allowed for file upload.