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