dolibarr 20.0.5
html.formmail.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2015-2017 Marcos García <marcosgdf@gmail.com>
6 * Copyright (C) 2015-2017 Nicolas ZABOURI <info@inovea-conseil.com>
7 * Copyright (C) 2018-2022 Frédéric France <frederic.france@netlogic.fr>
8 * Copyright (C) 2022 Charlene Benke <charlene@patas-monkey.com>
9 * Copyright (C) 2023 Anthony Berton <anthony.berton@bb2a.fr>
10 * Copyright (C) 2024 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';
33
34
41class FormMail extends Form
42{
46 public $db;
47
53 public $withform;
54
58 public $fromname;
59
63 public $frommail;
64
68 public $fromtype;
69
73 public $fromid;
74
78 public $fromalsorobot;
79
83 public $totype;
84
88 public $toid;
89
93 public $replytoname;
94
98 public $replytomail;
99
103 public $toname;
104
108 public $tomail;
109
113 public $trackid;
114
118 public $inreplyto;
119
120 public $withsubstit; // Show substitution array
121 public $withfrom;
122
126 public $withto; // Show recipient emails
127 public $withreplyto;
128
134 public $withtofree;
135 public $withtocc;
136 public $withtoccc;
137 public $withtopic;
138 public $witherrorsto;
139
143 public $withfile;
144
148 public $withlayout;
149
153 public $withaiprompt;
154
158 public $withmaindocfile;
159 public $withbody;
160
161 public $withfromreadonly;
162 public $withreplytoreadonly;
163 public $withtoreadonly;
164 public $withtoccreadonly;
165 public $witherrorstoreadonly;
166 public $withtocccreadonly;
167 public $withtopicreadonly;
168 public $withbodyreadonly;
169 public $withfilereadonly;
170 public $withdeliveryreceipt;
171 public $withcancel;
172 public $withdeliveryreceiptreadonly;
173 public $withfckeditor;
174
178 public $ckeditortoolbar;
179
180 public $substit = array();
181 public $substit_lines = array();
185 public $param = array();
186
187 public $withtouser = array();
188 public $withtoccuser = array();
189
190 public $lines_model;
191
192 // -1 suggest the checkbox 'one email per recipient' not checked, 0 = no suggestion, 1 = suggest and checked
193 public $withoptiononeemailperrecipient;
194
195
201 public function __construct($db)
202 {
203 $this->db = $db;
204
205 $this->withform = 1;
206
207 $this->withfrom = 1;
208 $this->withto = 1;
209 $this->withtofree = 1;
210 $this->withtocc = 1;
211 $this->withtoccc = 0;
212 $this->witherrorsto = 0;
213 $this->withtopic = 1;
214 $this->withfile = 0; // 1=Add section "Attached files". 2=Can add files.
215 $this->withmaindocfile = 0; // 1=Add a checkbox "Attach also main document" for mass actions (checked by default), -1=Add checkbox (not checked by default)
216 $this->withbody = 1;
217
218 $this->withfromreadonly = 1;
219 $this->withreplytoreadonly = 1;
220 $this->withtoreadonly = 0;
221 $this->withtoccreadonly = 0;
222 $this->withtocccreadonly = 0;
223 $this->witherrorstoreadonly = 0;
224 $this->withtopicreadonly = 0;
225 $this->withfilereadonly = 0;
226 $this->withbodyreadonly = 0;
227 $this->withdeliveryreceiptreadonly = 0;
228 $this->withfckeditor = -1; // -1 = Auto
229 }
230
231 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
237 public function clear_attached_files()
238 {
239 // phpcs:enable
240 global $conf, $user;
241 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
242
243 // Set tmp user directory
244 $vardir = $conf->user->dir_output."/".$user->id;
245 $upload_dir = $vardir.'/temp/'; // TODO Add $keytoavoidconflict in upload_dir path
246 if (is_dir($upload_dir)) {
247 dol_delete_dir_recursive($upload_dir);
248 }
249
250 $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
251 unset($_SESSION["listofpaths".$keytoavoidconflict]);
252 unset($_SESSION["listofnames".$keytoavoidconflict]);
253 unset($_SESSION["listofmimes".$keytoavoidconflict]);
254 }
255
256 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
265 public function add_attached_files($path, $file = '', $type = '')
266 {
267 // phpcs:enable
268 $listofpaths = array();
269 $listofnames = array();
270 $listofmimes = array();
271
272 if (empty($file)) {
273 $file = basename($path);
274 }
275 if (empty($type)) {
276 $type = dol_mimetype($file);
277 }
278
279 $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
280 if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) {
281 $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
282 }
283 if (!empty($_SESSION["listofnames".$keytoavoidconflict])) {
284 $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
285 }
286 if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) {
287 $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
288 }
289 if (!in_array($file, $listofnames)) {
290 $listofpaths[] = $path;
291 $listofnames[] = $file;
292 $listofmimes[] = $type;
293 $_SESSION["listofpaths".$keytoavoidconflict] = implode(';', $listofpaths);
294 $_SESSION["listofnames".$keytoavoidconflict] = implode(';', $listofnames);
295 $_SESSION["listofmimes".$keytoavoidconflict] = implode(';', $listofmimes);
296 }
297 }
298
299 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
306 public function remove_attached_files($keytodelete)
307 {
308 // phpcs:enable
309 $listofpaths = array();
310 $listofnames = array();
311 $listofmimes = array();
312
313 $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
314 if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) {
315 $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
316 }
317 if (!empty($_SESSION["listofnames".$keytoavoidconflict])) {
318 $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
319 }
320 if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) {
321 $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
322 }
323 if ($keytodelete >= 0) {
324 unset($listofpaths[$keytodelete]);
325 unset($listofnames[$keytodelete]);
326 unset($listofmimes[$keytodelete]);
327 $_SESSION["listofpaths".$keytoavoidconflict] = implode(';', $listofpaths);
328 $_SESSION["listofnames".$keytoavoidconflict] = implode(';', $listofnames);
329 $_SESSION["listofmimes".$keytoavoidconflict] = implode(';', $listofmimes);
330 //var_dump($_SESSION['listofpaths']);
331 }
332 }
333
334 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
340 public function get_attached_files()
341 {
342 // phpcs:enable
343 $listofpaths = array();
344 $listofnames = array();
345 $listofmimes = array();
346
347 $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
348 if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) {
349 $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
350 }
351 if (!empty($_SESSION["listofnames".$keytoavoidconflict])) {
352 $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
353 }
354 if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) {
355 $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
356 }
357 return array('paths' => $listofpaths, 'names' => $listofnames, 'mimes' => $listofmimes);
358 }
359
360 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
371 public function show_form($addfileaction = 'addfile', $removefileaction = 'removefile')
372 {
373 // phpcs:enable
374 print $this->get_form($addfileaction, $removefileaction);
375 }
376
377 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
388 public function get_form($addfileaction = 'addfile', $removefileaction = 'removefile')
389 {
390 // phpcs:enable
391 global $conf, $langs, $user, $hookmanager, $form;
392
393 // Required to show preview wof mail attachments
394 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
395 $formfile = new FormFile($this->db);
396
397 if (!is_object($form)) {
398 $form = new Form($this->db);
399 }
400
401 // Load translation files required by the page
402 $langs->loadLangs(array('other', 'mails', 'members'));
403
404 // Clear temp files. Must be done before call of triggers, at beginning (mode = init), or when we select a new template
405 if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelselected') && GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) {
406 $this->clear_attached_files();
407 }
408
409 // Call hook getFormMail
410 $hookmanager->initHooks(array('formmail'));
411
412 $parameters = array(
413 'addfileaction' => $addfileaction,
414 'removefileaction' => $removefileaction,
415 'trackid' => $this->trackid
416 );
417 $reshook = $hookmanager->executeHooks('getFormMail', $parameters, $this);
418
419 if (!empty($reshook)) {
420 return $hookmanager->resPrint;
421 } else {
422 $out = '';
423
424 $disablebademails = 1;
425
426 // Define output language
427 $outputlangs = $langs;
428 $newlang = '';
429 if (getDolGlobalInt('MAIN_MULTILANGS') && !empty($this->param['langsmodels'])) {
430 $newlang = $this->param['langsmodels'];
431 }
432 if (!empty($newlang)) {
433 $outputlangs = new Translate("", $conf);
434 $outputlangs->setDefaultLang($newlang);
435 $outputlangs->load('other');
436 }
437
438 // Get message template for $this->param["models"] into c_email_templates
439 $arraydefaultmessage = -1;
440 if ($this->param['models'] != 'none') {
441 $model_id = 0;
442 if (array_key_exists('models_id', $this->param)) {
443 $model_id = $this->param["models_id"];
444 }
445
446 $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
447 }
448
449 // Define list of attached files
450 $listofpaths = array();
451 $listofnames = array();
452 $listofmimes = array();
453 $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined
454
455 if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelselected') && GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) {
456 if (!empty($arraydefaultmessage->joinfiles) && !empty($this->param['fileinit']) && is_array($this->param['fileinit'])) {
457 foreach ($this->param['fileinit'] as $path) {
458 if (!empty($path)) {
459 $this->add_attached_files($path);
460 }
461 }
462 }
463 }
464
465 if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) {
466 $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
467 }
468 if (!empty($_SESSION["listofnames".$keytoavoidconflict])) {
469 $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
470 }
471 if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) {
472 $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
473 }
474
475
476 $out .= "\n".'<!-- Begin form mail type='.$this->param["models"].' --><div id="mailformdiv"></div>'."\n";
477 if ($this->withform == 1) {
478 $out .= '<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param["returnurl"].'#formmail">'."\n";
479
480 $out .= '<a id="formmail" name="formmail"></a>';
481 $out .= '<input style="display:none" type="submit" id="sendmailhidden" name="sendmail">';
482 $out .= '<input type="hidden" name="token" value="'.newToken().'" />';
483 $out .= '<input type="hidden" name="trackid" value="'.$this->trackid.'" />';
484 $out .= '<input type="hidden" name="inreplyto" value="'.$this->inreplyto.'" />';
485 }
486 if (!empty($this->withfrom)) {
487 if (!empty($this->withfromreadonly)) {
488 $out .= '<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.'" />';
489 $out .= '<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.'" />';
490 }
491 }
492 foreach ($this->param as $key => $value) {
493 if (is_array($value)) {
494 $out .= "<!-- param key=".$key." is array, we do not output input field for it -->\n";
495 } else {
496 $out .= '<input type="hidden" id="'.$key.'" name="'.$key.'" value="'.$value.'" />'."\n";
497 }
498 }
499
500 $modelmail_array = array();
501 if ($this->param['models'] != 'none') {
502 $result = $this->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs); // Fill $this->lines_model
503 if ($result < 0) {
504 setEventMessages($this->error, $this->errors, 'errors');
505 }
506
507 foreach ($this->lines_model as $line) {
508 $reg = array();
509 if (preg_match('/\‍((.*)\‍)/', $line->label, $reg)) {
510 $labeltouse = $langs->trans($reg[1]); // langs->trans when label is __(xxx)__
511 } else {
512 $labeltouse = $line->label;
513 }
514
515 // We escape the $labeltouse to store it into $modelmail_array.
516 $modelmail_array[$line->id] = dol_escape_htmltag($labeltouse);
517 if ($line->lang) {
518 $modelmail_array[$line->id] .= ' '.picto_from_langcode($line->lang);
519 }
520 if ($line->private) {
521 $modelmail_array[$line->id] .= ' - <span class="opacitymedium">'.dol_escape_htmltag($langs->trans("Private")).'</span>';
522 }
523 }
524 }
525
526 // Zone to select email template
527 if (count($modelmail_array) > 0) {
528 $model_mail_selected_id = GETPOSTISSET('modelmailselected') ? GETPOSTINT('modelmailselected') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0);
529
530 // If list of template is filled
531 $out .= '<div class="center" style="padding: 0px 0 12px 0">'."\n";
532
533 $out .= '<span class="opacitymedium">'.$langs->trans('SelectMailModel').':</span> ';
534
535 $out .= $this->selectarray('modelmailselected', $modelmail_array, $model_mail_selected_id, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1, '', 0, 1);
536 if ($user->admin) {
537 $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')), 1);
538 }
539
540 $out .= ' &nbsp; ';
541 $out .= '<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans('Apply').'" name="modelselected" id="modelselected">';
542 $out .= ' &nbsp; ';
543 $out .= '</div>';
544 } elseif (!empty($this->param['models']) && in_array($this->param['models'], array(
545 'propal_send', 'order_send', 'facture_send',
546 'shipping_send', 'fichinter_send', 'supplier_proposal_send', 'order_supplier_send',
547 'invoice_supplier_send', 'thirdparty', 'contract', 'user', 'recruitmentcandidature_send', 'all'
548 ))) {
549 // If list of template is empty
550 $out .= '<div class="center" style="padding: 0px 0 12px 0">'."\n";
551 $out .= '<span class="opacitymedium">'.$langs->trans('SelectMailModel').':</span> ';
552 $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.
553 if ($user->admin) {
554 $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')), 1);
555 }
556 $out .= ' &nbsp; ';
557 $out .= '<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans('Apply').'" name="modelselected" disabled="disabled" id="modelselected">';
558 $out .= ' &nbsp; ';
559 $out .= '</div>';
560 } else {
561 $out .= '<!-- No template available for $this->param["models"] = '.$this->param['models'].' -->';
562 }
563
564
565 $out .= '<table class="tableforemailform boxtablenotop centpercent">'."\n";
566
567 // Substitution array/string
568 $helpforsubstitution = '';
569 if (is_array($this->substit) && count($this->substit)) {
570 $helpforsubstitution .= $langs->trans('AvailableVariables').' :<br><br><span class="small">'."\n";
571 }
572 foreach ($this->substit as $key => $val) {
573 // Do not show deprecated variables into the tooltip help of substitution variables
574 if (in_array($key, array('__NEWREF__', '__REFCLIENT__', '__REFSUPPLIER__', '__SUPPLIER_ORDER_DATE_DELIVERY__', '__SUPPLIER_ORDER_DELAY_DELIVERY__'))) {
575 continue;
576 }
577 $helpforsubstitution .= $key.' -> '.$langs->trans(dol_string_nohtmltag(dolGetFirstLineOfText($val))).'<br>';
578 }
579 if (is_array($this->substit) && count($this->substit)) {
580 $helpforsubstitution .= '</span>';
581 }
582
583 /*
584 if (!empty($this->withsubstit)) { // Unset or set ->withsubstit=0 to disable this.
585 $out .= '<tr><td colspan="2" class="right">';
586 if (is_numeric($this->withsubstit)) {
587 $out .= $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip'); // Old usage
588 } else {
589 $out .= $form->textwithpicto($langs->trans('AvailableVariables'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip'); // New usage
590 }
591 $out .= "</td></tr>\n";
592 }*/
593
594 // From
595 if (!empty($this->withfrom)) {
596 if (!empty($this->withfromreadonly)) {
597 $out .= '<tr><td class="fieldrequired minwidth200">'.$langs->trans("MailFrom").'</td><td>';
598
599 // $this->fromtype is the default value to use to select sender
600 if (!($this->fromtype === 'user' && $this->fromid > 0)
601 && !($this->fromtype === 'company')
602 && !($this->fromtype === 'robot')
603 && !preg_match('/user_aliases/', $this->fromtype)
604 && !preg_match('/global_aliases/', $this->fromtype)
605 && !preg_match('/senderprofile/', $this->fromtype)
606 ) {
607 // Use this->fromname and this->frommail or error if not defined
608 $out .= $this->fromname;
609 if ($this->frommail) {
610 $out .= ' &lt;'.$this->frommail.'&gt;';
611 } else {
612 if ($this->fromtype) {
613 $langs->load('errors');
614 $out .= '<span class="warning"> &lt;'.$langs->trans('ErrorNoMailDefinedForThisUser').'&gt; </span>';
615 }
616 }
617 } else {
618 $liste = array();
619
620 // Add user email
621 if (empty($user->email)) {
622 $langs->load('errors');
623 $s = $user->getFullName($langs).' &lt;'.$langs->trans('ErrorNoMailDefinedForThisUser').'&gt;';
624 } else {
625 $s = $user->getFullName($langs).' &lt;'.$user->email.'&gt;';
626 }
627 $liste['user'] = array('label' => $s, 'data-html' => $s);
628
629 // Add also company main email
630 if (getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')) {
631 $s = (!getDolGlobalString('MAIN_INFO_SOCIETE_NOM') ? $conf->global->MAIN_INFO_SOCIETE_EMAIL : $conf->global->MAIN_INFO_SOCIETE_NOM).' &lt;' . getDolGlobalString('MAIN_INFO_SOCIETE_MAIL').'&gt;';
632 $liste['company'] = array('label' => $s, 'data-html' => $s);
633 }
634
635 // Add also email aliases if there is some
636 $listaliases = array(
637 'user_aliases' => (empty($user->email_aliases) ? '' : $user->email_aliases),
638 'global_aliases' => getDolGlobalString('MAIN_INFO_SOCIETE_MAIL_ALIASES'),
639 );
640
641 if (!empty($arraydefaultmessage->email_from)) {
642 $templatemailfrom = ' &lt;'.$arraydefaultmessage->email_from.'&gt;';
643 $liste['from_template_'.GETPOST('modelmailselected')] = array('label' => $templatemailfrom, 'data-html' => $templatemailfrom);
644 }
645
646 // Also add robot email
647 if (!empty($this->fromalsorobot)) {
648 if (getDolGlobalString('MAIN_MAIL_EMAIL_FROM') && getDolGlobalString('MAIN_MAIL_EMAIL_FROM') != getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')) {
649 $s = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
650 if ($this->frommail) {
651 $s .= ' &lt;' . getDolGlobalString('MAIN_MAIL_EMAIL_FROM').'&gt;';
652 }
653 $liste['main_from'] = array('label' => $s, 'data-html' => $s);
654 }
655 }
656
657 // Add also email aliases from the c_email_senderprofile table
658 $sql = "SELECT rowid, label, email FROM ".$this->db->prefix()."c_email_senderprofile";
659 $sql .= " WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).") AND entity IN (".getEntity('c_email_senderprofile').")";
660 $sql .= " ORDER BY position";
661 $resql = $this->db->query($sql);
662 if ($resql) {
663 $num = $this->db->num_rows($resql);
664 $i = 0;
665 while ($i < $num) {
666 $obj = $this->db->fetch_object($resql);
667 if ($obj) {
668 $listaliases['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>';
669 }
670 $i++;
671 }
672 } else {
673 dol_print_error($this->db);
674 }
675
676 foreach ($listaliases as $typealias => $listalias) {
677 $posalias = 0;
678 $listaliasarray = explode(',', $listalias);
679 foreach ($listaliasarray as $listaliasval) {
680 $posalias++;
681 $listaliasval = trim($listaliasval);
682 if ($listaliasval) {
683 $listaliasval = preg_replace('/</', '&lt;', $listaliasval);
684 $listaliasval = preg_replace('/>/', '&gt;', $listaliasval);
685 if (!preg_match('/&lt;/', $listaliasval)) {
686 $listaliasval = '&lt;'.$listaliasval.'&gt;';
687 }
688 $liste[$typealias.'_'.$posalias] = array('label' => $listaliasval, 'data-html' => $listaliasval);
689 }
690 }
691 }
692
693 // Using ajaxcombo here make the '<email>' no more visible on list because <emailofuser> is not a valid html tag,
694 // so we transform before each record into $liste to be printable with ajaxcombo by replacing <> into ()
695 // $liste['senderprofile_0_0'] = array('label'=>'rrr', 'data-html'=>'rrr &lt;aaaa&gt;');
696 foreach ($liste as $key => $val) {
697 if (!empty($liste[$key]['data-html'])) {
698 $liste[$key]['data-html'] = str_replace(array('&lt;', '<', '&gt;', '>'), array('__LTCHAR__', '__LTCHAR__', '__GTCHAR__', '__GTCHAR__'), $liste[$key]['data-html']);
699 $liste[$key]['data-html'] = str_replace(array('__LTCHAR__', '__GTCHAR__'), array('<span class="opacitymedium">(', ')</span>'), $liste[$key]['data-html']);
700 }
701 }
702 $out .= ' '.$form->selectarray('fromtype', $liste, empty($arraydefaultmessage->email_from) ? $this->fromtype : 'from_template_'.GETPOST('modelmailselected'), 0, 0, 0, '', 0, 0, 0, '', 'fromforsendingprofile maxwidth200onsmartphone', 1, '', $disablebademails);
703 }
704
705 $out .= "</td></tr>\n";
706 } else {
707 $out .= '<tr><td class="fieldrequired width200">'.$langs->trans("MailFrom")."</td><td>";
708 $out .= $langs->trans("Name").':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.'" />';
709 $out .= '&nbsp; &nbsp; ';
710 $out .= $langs->trans("EMail").':&lt;<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.'" />&gt;';
711 $out .= "</td></tr>\n";
712 }
713 }
714
715 // To
716 if (!empty($this->withto) || is_array($this->withto)) {
717 $out .= $this->getHtmlForTo();
718 }
719
720 // To User
721 if (!empty($this->withtouser) && is_array($this->withtouser) && getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
722 $out .= '<tr><td>';
723 $out .= $langs->trans("MailToUsers");
724 $out .= '</td><td>';
725
726 // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time
727 $tmparray = $this->withtouser;
728 foreach ($tmparray as $key => $val) {
729 $tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
730 }
731 $withtoselected = GETPOST("receiveruser", 'array'); // Array of selected value
732 if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') {
733 $withtoselected = array_keys($tmparray);
734 }
735 $out .= $form->multiselectarray("receiveruser", $tmparray, $withtoselected, null, null, 'inline-block minwidth500', null, "");
736 $out .= "</td></tr>\n";
737 }
738
739 // With option for one email per recipient
740 if (!empty($this->withoptiononeemailperrecipient)) {
741 if (abs($this->withoptiononeemailperrecipient) == 1) {
742 $out .= '<tr><td class="minwidth200">';
743 $out .= $langs->trans("GroupEmails");
744 $out .= '</td><td>';
745 $out .= ' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ? ' checked="checked"' : '').'> ';
746 $out .= '<label for="oneemailperrecipient">';
747 $out .= $form->textwithpicto($langs->trans("OneEmailPerRecipient"), $langs->trans("WarningIfYouCheckOneRecipientPerEmail"), 1, 'help');
748 $out .= '</label>';
749 //$out .= '<span class="hideonsmartphone opacitymedium">';
750 //$out .= ' - ';
751 //$out .= $langs->trans("WarningIfYouCheckOneRecipientPerEmail");
752 //$out .= '</span>';
753 if (getDolGlobalString('MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL')) {
754 if (!empty($this->withto) && !is_array($this->withto)) {
755 $out .= ' '.$langs->trans("or").' <input type="email" name="emailto" value="">';
756 }
757 }
758 $out .= '</td></tr>';
759 } else {
760 $out .= '<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>';
761 }
762 }
763
764 // CC
765 if (!empty($this->withtocc) || is_array($this->withtocc)) {
766 $out .= $this->getHtmlForCc();
767 }
768
769 // To User cc
770 if (!empty($this->withtoccuser) && is_array($this->withtoccuser) && getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
771 $out .= '<tr><td>';
772 $out .= $langs->trans("MailToCCUsers");
773 $out .= '</td><td>';
774
775 // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time
776 $tmparray = $this->withtoccuser;
777 foreach ($tmparray as $key => $val) {
778 $tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
779 }
780 $withtoselected = GETPOST("receiverccuser", 'array'); // Array of selected value
781 if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') {
782 $withtoselected = array_keys($tmparray);
783 }
784 $out .= $form->multiselectarray("receiverccuser", $tmparray, $withtoselected, null, null, 'inline-block minwidth500', null, "");
785 $out .= "</td></tr>\n";
786 }
787
788 // CCC
789 if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
790 $out .= $this->getHtmlForWithCcc();
791 }
792
793 // Replyto
794 if (!empty($this->withreplyto)) {
795 if ($this->withreplytoreadonly) {
796 $out .= '<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.'" />';
797 $out .= '<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.'" />';
798 $out .= "<tr><td>".$langs->trans("MailReply")."</td><td>".$this->replytoname.($this->replytomail ? (" &lt;".$this->replytomail."&gt;") : "");
799 $out .= "</td></tr>\n";
800 }
801 }
802
803 // Errorsto
804 if (!empty($this->witherrorsto)) {
805 $out .= $this->getHtmlForWithErrorsTo();
806 }
807
808 // Ask delivery receipt
809 if (!empty($this->withdeliveryreceipt) && getDolGlobalInt('MAIN_EMAIL_SUPPORT_ACK')) {
810 $out .= $this->getHtmlForDeliveryreceipt();
811 }
812
813 // Topic
814 if (!empty($this->withtopic)) {
815 $out .= $this->getHtmlForTopic($arraydefaultmessage, $helpforsubstitution);
816 }
817
818 // Attached files
819 if (!empty($this->withfile)) {
820 $out .= '<tr>';
821 $out .= '<td class="tdtop">'.$langs->trans("MailFile").'</td>';
822
823 $out .= '<td>';
824
825 if ($this->withmaindocfile) {
826 // withmaindocfile is set to 1 or -1 to show the checkbox (-1 = checked or 1 = not checked)
827 if (GETPOSTISSET('sendmail')) {
828 $this->withmaindocfile = (GETPOST('addmaindocfile', 'alpha') ? -1 : 1);
829 } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
830 // If a template was selected, we use setup of template to define if join file checkbox is selected or not.
831 $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
832 }
833 }
834
835 if (!empty($this->withmaindocfile)) {
836 if ($this->withmaindocfile == 1) {
837 $out .= '<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />';
838 } elseif ($this->withmaindocfile == -1) {
839 $out .= '<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />';
840 }
841 if (getDolGlobalString('MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND')) {
842 $out .= ' <label for="addmaindocfile">'.$langs->trans("JoinMainDocOrLastGenerated").'.</label><br>';
843 } else {
844 $out .= ' <label for="addmaindocfile">'.$langs->trans("JoinMainDoc").'.</label><br>';
845 }
846 }
847
848 if (is_numeric($this->withfile)) {
849 // TODO Trick to have param removedfile containing nb of file to delete. But this does not works without javascript
850 $out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n";
851 $out .= '<script nonce="'.getNonce().'" type="text/javascript">';
852 $out .= 'jQuery(document).ready(function () {';
853 $out .= ' jQuery(".removedfile").click(function() {';
854 $out .= ' jQuery(".removedfilehidden").val(jQuery(this).val());';
855 $out .= ' });';
856 $out .= '})';
857 $out .= '</script>'."\n";
858 if (count($listofpaths)) {
859 foreach ($listofpaths as $key => $val) {
860 $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
861
862 $entity = (isset($this->param['object_entity']) ? $this->param['object_entity'] : $conf->entity);
863 if ($entity > 1) {
864 $relativepathtofile = str_replace('/'.$entity.'/', '/', $relativepathtofile);
865 }
866 // Try to extract data from full path
867 $formfile_params = array();
868 preg_match('#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params);
869
870 $out .= '<div id="attachfile_'.$key.'">';
871 // Preview of attachment
872 $out .= img_mime($listofnames[$key]).$listofnames[$key];
873
874 $out .= ' '.$formfile->showPreview(array(), $formfile_params[2], $formfile_params[4], 0, ($entity == 1 ? '' : 'entity='.((int) $entity)));
875
876 if (!$this->withfilereadonly) {
877 $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.'" />';
878 //$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>';
879 }
880 $out .= '<br></div>';
881 }
882 } elseif (empty($this->withmaindocfile)) {
883 //$out .= '<span class="opacitymedium">'.$langs->trans("NoAttachedFiles").'</span><br>';
884 }
885 if ($this->withfile == 2) {
886 $maxfilesizearray = getMaxFileSizeArray();
887 $maxmin = $maxfilesizearray['maxmin'];
888 if ($maxmin > 0) {
889 $out .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
890 }
891 // Can add other files
892 if (!getDolGlobalString('FROM_MAIL_DONT_USE_INPUT_FILE_MULTIPLE')) {
893 $out .= '<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans("Upload").'" multiple />';
894 } else {
895 $out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
896 }
897 $out .= ' ';
898 $out .= '<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />';
899 }
900 } else {
901 $out .= $this->withfile;
902 }
903
904 $out .= "</td></tr>\n";
905 }
906
907 // Message (+ Links to choose layout or ai prompt)
908 if (!empty($this->withbody)) {
909 $defaultmessage = GETPOST('message', 'restricthtml');
910 if (!GETPOST('modelselected', 'alpha') || GETPOST('modelmailselected') != '-1') {
911 if ($arraydefaultmessage && $arraydefaultmessage->content) {
912 $defaultmessage = $arraydefaultmessage->content;
913 } elseif (!is_numeric($this->withbody)) {
914 $defaultmessage = $this->withbody;
915 }
916 }
917
918 // Complete substitution array with the url to make online payment
919 $paymenturl = '';
920 // Set the online payment url link into __ONLINE_PAYMENT_URL__ key
921 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
922 $validpaymentmethod = getValidOnlinePaymentMethods('');
923
924 if (empty($this->substit['__REF__'])) {
925 $paymenturl = '';
926 } else {
927 $langs->loadLangs(array('paypal', 'other'));
928 $typeforonlinepayment = 'free';
929 if ($this->param["models"] == 'order' || $this->param["models"] == 'order_send') {
930 $typeforonlinepayment = 'order'; // TODO use detection on something else than template
931 }
932 if ($this->param["models"] == 'invoice' || $this->param["models"] == 'facture_send') {
933 $typeforonlinepayment = 'invoice'; // TODO use detection on something else than template
934 }
935 if ($this->param["models"] == 'member') {
936 $typeforonlinepayment = 'member'; // TODO use detection on something else than template
937 }
938 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit['__REF__']);
939 $paymenturl = $url;
940 }
941
942 if (count($validpaymentmethod) > 0 && $paymenturl) {
943 $langs->load('other');
944 $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace('\n', "\n", $langs->transnoentities("PredefinedMailContentLink", $paymenturl));
945 $this->substit['__ONLINE_PAYMENT_URL__'] = $paymenturl;
946 } elseif (count($validpaymentmethod) > 0) {
947 $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = '__ONLINE_PAYMENT_TEXT_AND_URL__';
948 $this->substit['__ONLINE_PAYMENT_URL__'] = '__ONLINE_PAYMENT_URL__';
949 } else {
950 $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = '';
951 $this->substit['__ONLINE_PAYMENT_URL__'] = '';
952 }
953
954 $this->substit['__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] = '';
955
956 // Add lines substitution key from each line
957 $lines = '';
958 $defaultlines = $arraydefaultmessage->content_lines;
959 if (isset($defaultlines)) {
960 foreach ($this->substit_lines as $substit_line) {
961 $lines .= make_substitutions($defaultlines, $substit_line)."\n";
962 }
963 }
964 $this->substit['__LINES__'] = $lines;
965
966 $defaultmessage = str_replace('\n', "\n", $defaultmessage);
967
968 // Deal with format differences between message and some substitution variables (text / HTML)
969 $atleastonecomponentishtml = 0;
970 if (strpos($defaultmessage, '__USER_SIGNATURE__') !== false && dol_textishtml($this->substit['__USER_SIGNATURE__'])) {
971 $atleastonecomponentishtml++;
972 }
973 if (strpos($defaultmessage, '__SENDEREMAIL_SIGNATURE__') !== false && dol_textishtml($this->substit['__SENDEREMAIL_SIGNATURE__'])) {
974 $atleastonecomponentishtml++;
975 }
976 if (strpos($defaultmessage, '__ONLINE_PAYMENT_TEXT_AND_URL__') !== false && dol_textishtml($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
977 $atleastonecomponentishtml++;
978 }
979 if (strpos($defaultmessage, '__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !== false && dol_textishtml($this->substit['__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
980 $atleastonecomponentishtml++;
981 }
982 if (dol_textishtml($defaultmessage)) {
983 $atleastonecomponentishtml++;
984 }
985 if ($atleastonecomponentishtml) {
986 if (!dol_textishtml($this->substit['__USER_SIGNATURE__'])) {
987 $this->substit['__USER_SIGNATURE__'] = dol_nl2br($this->substit['__USER_SIGNATURE__']);
988 }
989 if (!dol_textishtml($this->substit['__SENDEREMAIL_SIGNATURE__'])) {
990 $this->substit['__SENDEREMAIL_SIGNATURE__'] = dol_nl2br($this->substit['__SENDEREMAIL_SIGNATURE__']);
991 }
992 if (!dol_textishtml($this->substit['__LINES__'])) {
993 $this->substit['__LINES__'] = dol_nl2br($this->substit['__LINES__']);
994 }
995 if (!dol_textishtml($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
996 $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = dol_nl2br($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__']);
997 }
998 if (!dol_textishtml($defaultmessage)) {
999 $defaultmessage = dol_nl2br($defaultmessage);
1000 }
1001 }
1002
1003 if (GETPOSTISSET("message") && !GETPOST('modelselected')) {
1004 $defaultmessage = GETPOST("message", "restricthtml");
1005 } else {
1006 $defaultmessage = make_substitutions($defaultmessage, $this->substit);
1007 // Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty)
1008 $defaultmessage = preg_replace("/^(<br>)+/", "", $defaultmessage);
1009 $defaultmessage = preg_replace("/^\n+/", "", $defaultmessage);
1010 }
1011
1012 $out .= '<tr>';
1013 $out .= '<td class="tdtop">';
1014 $out .= $form->textwithpicto($langs->trans('MailText'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltipfrombody');
1015 $out .= '</td>';
1016 $out .= '<td class="tdtop">';
1017
1018 $formmail = $this;
1019 $showlinktolayout = $formmail->withlayout && $formmail->withfckeditor && getDolGlobalInt('MAIN_EMAIL_USE_LAYOUT');
1020 $showlinktolayoutlabel = $langs->trans("FillMessageWithALayout");
1021 $showlinktoai = ($formmail->withaiprompt && isModEnabled('ai')) ? 'textgenerationemail' : '';
1022 $showlinktoailabel = $langs->trans("FillMessageWithAIContent");
1023 $formatforouput = '';
1024 $htmlname = 'message';
1025
1026 // Fill $out
1027 include DOL_DOCUMENT_ROOT.'/core/tpl/formlayoutai.tpl.php';
1028
1029 $out .= '</td>';
1030 $out .= '</tr>';
1031
1032 $out .= '<tr>';
1033 $out .= '<td colspan="2">';
1034 if ($this->withbodyreadonly) {
1035 $out .= nl2br($defaultmessage);
1036 $out .= '<input type="hidden" id="message" name="message" disabled value="'.$defaultmessage.'" />';
1037 } else {
1038 if (!isset($this->ckeditortoolbar)) {
1039 $this->ckeditortoolbar = 'dolibarr_mailings';
1040 }
1041
1042 // Editor wysiwyg
1043 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1044 if ($this->withfckeditor == -1) {
1045 if (getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) {
1046 $this->withfckeditor = 1;
1047 } else {
1048 $this->withfckeditor = 0;
1049 }
1050 }
1051
1052 $doleditor = new DolEditor('message', $defaultmessage, '', 280, $this->ckeditortoolbar, 'In', true, true, $this->withfckeditor, 8, '95%');
1053 $out .= $doleditor->Create(1);
1054 }
1055 $out .= "</td></tr>\n";
1056 }
1057
1058 $out .= '</table>'."\n";
1059
1060 if ($this->withform == 1 || $this->withform == -1) {
1061 $out .= '<div class="center">';
1062 $out .= '<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans("SendMail").'"';
1063 // Add a javascript test to avoid to forget to submit file before sending email
1064 if ($this->withfile == 2 && $conf->use_javascript_ajax) {
1065 $out .= ' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans("FileWasNotUploaded")).'\'); return false; } else { return true; }"';
1066 }
1067 $out .= ' />';
1068 if ($this->withcancel) {
1069 $out .= '<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'" />';
1070 }
1071 $out .= '</div>'."\n";
1072 }
1073
1074 if ($this->withform == 1) {
1075 $out .= '</form>'."\n";
1076 }
1077
1078 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1079 if (getDolGlobalString('MAIN_MAILFORM_DISABLE_ENTERKEY')) {
1080 $out .= '<script nonce="'.getNonce().'" type="text/javascript">';
1081 $out .= 'jQuery(document).ready(function () {';
1082 $out .= ' $(document).on("keypress", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1083 var code = e.keyCode || e.which;
1084 if (code == 13) {
1085 console.log("Enter was intercepted and blocked");
1086 e.preventDefault();
1087 return false;
1088 }
1089 });';
1090 $out .= ' })';
1091 $out .= '</script>';
1092 }
1093
1094 $out .= "<!-- End form mail -->\n";
1095
1096 return $out;
1097 }
1098 }
1099
1105 public function getHtmlForTo()
1106 {
1107 global $langs, $form;
1108 $out = '<tr><td class="fieldrequired">';
1109 if ($this->withtofree) {
1110 $out .= $form->textwithpicto($langs->trans("MailTo"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
1111 } else {
1112 $out .= $langs->trans("MailTo");
1113 }
1114 $out .= '</td><td>';
1115 if ($this->withtoreadonly) {
1116 if (!empty($this->toname) && !empty($this->tomail)) {
1117 $out .= '<input type="hidden" id="toname" name="toname" value="'.$this->toname.'" />';
1118 $out .= '<input type="hidden" id="tomail" name="tomail" value="'.$this->tomail.'" />';
1119 if ($this->totype == 'thirdparty') {
1120 $soc = new Societe($this->db);
1121 $soc->fetch($this->toid);
1122 $out .= $soc->getNomUrl(1);
1123 } elseif ($this->totype == 'contact') {
1124 $contact = new Contact($this->db);
1125 $contact->fetch($this->toid);
1126 $out .= $contact->getNomUrl(1);
1127 } else {
1128 $out .= $this->toname;
1129 }
1130 $out .= ' &lt;'.$this->tomail.'&gt;';
1131 if ($this->withtofree) {
1132 $out .= '<br>'.$langs->trans("and").' <input class="minwidth200" id="sendto" name="sendto" value="'.(!is_array($this->withto) && !is_numeric($this->withto) ? (GETPOSTISSET("sendto") ? GETPOST("sendto") : $this->withto) : "").'" />';
1133 }
1134 } else {
1135 // Note withto may be a text like 'AllRecipientSelected'
1136 $out .= (!is_array($this->withto) && !is_numeric($this->withto)) ? $this->withto : "";
1137 }
1138 } else {
1139 // The free input of email
1140 if (!empty($this->withtofree)) {
1141 $out .= '<input class="minwidth200" id="sendto" name="sendto" value="'.(($this->withtofree && !is_numeric($this->withtofree)) ? $this->withtofree : (!is_array($this->withto) && !is_numeric($this->withto) ? (GETPOSTISSET("sendto") ? GETPOST("sendto") : $this->withto) : "")).'" />';
1142 }
1143 // The select combo
1144 if (!empty($this->withto) && is_array($this->withto)) {
1145 if (!empty($this->withtofree)) {
1146 $out .= " ".$langs->trans("and")."/".$langs->trans("or")." ";
1147 }
1148
1149 $tmparray = $this->withto;
1150 foreach ($tmparray as $key => $val) {
1151 if (is_array($val)) {
1152 $label = $val['label'];
1153 } else {
1154 $label = $val;
1155 }
1156
1157 $tmparray[$key] = array();
1158 $tmparray[$key]['id'] = $key;
1159
1160 $tmparray[$key]['label'] = $label;
1161 $tmparray[$key]['label'] = str_replace(array('<', '>'), array('(', ')'), $tmparray[$key]['label']);
1162 // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time
1163 $tmparray[$key]['label'] = dol_htmlentities($tmparray[$key]['label'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', true);
1164
1165 $tmparray[$key]['labelhtml'] = $label;
1166 $tmparray[$key]['labelhtml'] = str_replace(array('&lt;', '<', '&gt;', '>'), array('__LTCHAR__', '__LTCHAR__', '__GTCHAR__', '__GTCHAR__'), $tmparray[$key]['labelhtml']);
1167 $tmparray[$key]['labelhtml'] = str_replace(array('__LTCHAR__', '__GTCHAR__'), array('<span class="opacitymedium">(', ')</span>'), $tmparray[$key]['labelhtml']);
1168 }
1169
1170 $withtoselected = GETPOST("receiver", 'array'); // Array of selected value
1171 if (!getDolGlobalInt('MAIN_MAIL_NO_WITH_TO_SELECTED')) {
1172 if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') {
1173 $withtoselected = array_keys($tmparray);
1174 }
1175 }
1176
1177 $out .= $form->multiselectarray("receiver", $tmparray, $withtoselected, null, null, 'inline-block minwidth500', 0, 0);
1178 }
1179 }
1180 $out .= "</td></tr>\n";
1181 return $out;
1182 }
1183
1189 public function getHtmlForCc()
1190 {
1191 global $langs, $form;
1192 $out = '<tr><td>';
1193 $out .= $form->textwithpicto($langs->trans("MailCC"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
1194 $out .= '</td><td>';
1195 if ($this->withtoccreadonly) {
1196 $out .= (!is_array($this->withtocc) && !is_numeric($this->withtocc)) ? $this->withtocc : "";
1197 } else {
1198 $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 : '')).'" />';
1199 if (!empty($this->withtocc) && is_array($this->withtocc)) {
1200 $out .= " ".$langs->trans("and")."/".$langs->trans("or")." ";
1201
1202 $tmparray = $this->withtocc;
1203 foreach ($tmparray as $key => $val) {
1204 if (is_array($val)) {
1205 $label = $val['label'];
1206 } else {
1207 $label = $val;
1208 }
1209
1210 $tmparray[$key] = array();
1211 $tmparray[$key]['id'] = $key;
1212
1213 $tmparray[$key]['label'] = $label;
1214 $tmparray[$key]['label'] = str_replace(array('<', '>'), array('(', ')'), $tmparray[$key]['label']);
1215 // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time
1216 $tmparray[$key]['label'] = dol_htmlentities($tmparray[$key]['label'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', true);
1217
1218 $tmparray[$key]['labelhtml'] = $label;
1219 $tmparray[$key]['labelhtml'] = str_replace(array('&lt;', '<', '&gt;', '>'), array('__LTCHAR__', '__LTCHAR__', '__GTCHAR__', '__GTCHAR__'), $tmparray[$key]['labelhtml']);
1220 $tmparray[$key]['labelhtml'] = str_replace(array('__LTCHAR__', '__GTCHAR__'), array('<span class="opacitymedium">(', ')</span>'), $tmparray[$key]['labelhtml']);
1221 }
1222
1223 $withtoccselected = GETPOST("receivercc", 'array'); // Array of selected value
1224
1225 $out .= $form->multiselectarray("receivercc", $tmparray, $withtoccselected, null, null, 'inline-block minwidth500', 0, 0);
1226 }
1227 }
1228 $out .= "</td></tr>\n";
1229 return $out;
1230 }
1231
1238 public function getHtmlForWithCcc()
1239 {
1240 global $langs, $form;
1241
1242 $out = '<tr><td>';
1243 $out .= $form->textwithpicto($langs->trans("MailCCC"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
1244 $out .= '</td><td>';
1245 if (!empty($this->withtocccreadonly)) {
1246 $out .= (!is_array($this->withtoccc) && !is_numeric($this->withtoccc)) ? $this->withtoccc : "";
1247 } else {
1248 $out .= '<input class="minwidth200" id="sendtoccc" name="sendtoccc" value="'.(GETPOSTISSET("sendtoccc") ? GETPOST("sendtoccc", "alpha") : ((!is_array($this->withtoccc) && !is_numeric($this->withtoccc)) ? $this->withtoccc : '')).'" />';
1249 if (!empty($this->withtoccc) && is_array($this->withtoccc)) {
1250 $out .= " ".$langs->trans("and")."/".$langs->trans("or")." ";
1251
1252 $tmparray = $this->withtoccc;
1253 foreach ($tmparray as $key => $val) {
1254 if (is_array($val)) {
1255 $label = $val['label'];
1256 } else {
1257 $label = $val;
1258 }
1259 $tmparray[$key] = array();
1260 $tmparray[$key]['id'] = $key;
1261
1262 $tmparray[$key]['label'] = $label;
1263 $tmparray[$key]['label'] = str_replace(array('<', '>'), array('(', ')'), $tmparray[$key]['label']);
1264 // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time
1265 $tmparray[$key]['label'] = dol_htmlentities($tmparray[$key]['label'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', true);
1266
1267 $tmparray[$key]['labelhtml'] = $label;
1268 $tmparray[$key]['labelhtml'] = str_replace(array('&lt;', '<', '&gt;', '>'), array('__LTCHAR__', '__LTCHAR__', '__GTCHAR__', '__GTCHAR__'), $tmparray[$key]['labelhtml']);
1269 $tmparray[$key]['labelhtml'] = str_replace(array('__LTCHAR__', '__GTCHAR__'), array('<span class="opacitymedium">(', ')</span>'), $tmparray[$key]['labelhtml']);
1270 }
1271
1272 $withtocccselected = GETPOST("receiverccc", 'array'); // Array of selected value
1273
1274 $out .= $form->multiselectarray("receiverccc", $tmparray, $withtocccselected, null, null, 'inline-block minwidth500', 0, 0);
1275 }
1276 }
1277
1278 $showinfobcc = '';
1279 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_PROPOSAL_TO') && !empty($this->param['models']) && $this->param['models'] == 'propal_send') {
1280 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_PROPOSAL_TO');
1281 }
1282 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_ORDER_TO') && !empty($this->param['models']) && $this->param['models'] == 'order_send') {
1283 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_ORDER_TO');
1284 }
1285 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_INVOICE_TO') && !empty($this->param['models']) && $this->param['models'] == 'facture_send') {
1286 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_INVOICE_TO');
1287 }
1288 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO') && !empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') {
1289 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO');
1290 }
1291 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO') && !empty($this->param['models']) && $this->param['models'] == 'order_supplier_send') {
1292 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO');
1293 }
1294 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO') && !empty($this->param['models']) && $this->param['models'] == 'invoice_supplier_send') {
1295 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO');
1296 }
1297 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.
1298 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_PROJECT_TO');
1299 }
1300 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_SHIPMENT_TO') && !empty($this->param['models']) && $this->param['models'] == 'shipping_send') {
1301 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_SHIPMENT_TO');
1302 }
1303 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_RECEPTION_TO') && !empty($this->param['models']) && $this->param['models'] == 'reception_send') {
1304 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_RECEPTION_TO');
1305 }
1306 if ($showinfobcc) {
1307 $out .= ' + '.$showinfobcc;
1308 }
1309 $out .= "</td></tr>\n";
1310 return $out;
1311 }
1312
1318 public function getHtmlForWithErrorsTo()
1319 {
1320 global $langs;
1321
1322 //if (! $this->errorstomail) $this->errorstomail=$this->frommail;
1323 $errorstomail = getDolGlobalString('MAIN_MAIL_ERRORS_TO', (!empty($this->errorstomail) ? $this->errorstomail : ''));
1324 if ($this->witherrorstoreadonly) {
1325 $out = '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td>';
1326 $out .= '<input type="hidden" id="errorstomail" name="errorstomail" value="'.$errorstomail.'" />';
1327 $out .= $errorstomail;
1328 $out .= "</td></tr>\n";
1329 } else {
1330 $out = '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td>';
1331 $out .= '<input class="minwidth200" id="errorstomail" name="errorstomail" value="'.$errorstomail.'" />';
1332 $out .= "</td></tr>\n";
1333 }
1334 return $out;
1335 }
1336
1342 public function getHtmlForDeliveryreceipt()
1343 {
1344 global $langs;
1345
1346 $out = '<tr><td><label for="deliveryreceipt">'.$langs->trans("DeliveryReceipt").'</label></td><td>';
1347
1348 if (!empty($this->withdeliveryreceiptreadonly)) {
1349 $out .= yn($this->withdeliveryreceipt);
1350 } else {
1351 $defaultvaluefordeliveryreceipt = 0;
1352 if (getDolGlobalString('MAIL_FORCE_DELIVERY_RECEIPT_PROPAL') && !empty($this->param['models']) && $this->param['models'] == 'propal_send') {
1353 $defaultvaluefordeliveryreceipt = 1;
1354 }
1355 if (getDolGlobalString('MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_PROPOSAL') && !empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') {
1356 $defaultvaluefordeliveryreceipt = 1;
1357 }
1358 if (getDolGlobalString('MAIL_FORCE_DELIVERY_RECEIPT_ORDER') && !empty($this->param['models']) && $this->param['models'] == 'order_send') {
1359 $defaultvaluefordeliveryreceipt = 1;
1360 }
1361 if (getDolGlobalString('MAIL_FORCE_DELIVERY_RECEIPT_INVOICE') && !empty($this->param['models']) && $this->param['models'] == 'facture_send') {
1362 $defaultvaluefordeliveryreceipt = 1;
1363 }
1364 if (getDolGlobalString('MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_ORDER') && !empty($this->param['models']) && $this->param['models'] == 'order_supplier_send') {
1365 $defaultvaluefordeliveryreceipt = 1;
1366 }
1367 //$out .= $form->selectyesno('deliveryreceipt', (GETPOSTISSET("deliveryreceipt") ? GETPOST("deliveryreceipt") : $defaultvaluefordeliveryreceipt), 1);
1368 $out .= '<input type="checkbox" id="deliveryreceipt" name="deliveryreceipt" value="1"'.((GETPOSTISSET("deliveryreceipt") ? GETPOST("deliveryreceipt") : $defaultvaluefordeliveryreceipt) ? ' checked="checked"' : '').'>';
1369 }
1370 $out .= "</td></tr>\n";
1371 return $out;
1372 }
1373
1381 public function getHtmlForTopic($arraydefaultmessage, $helpforsubstitution)
1382 {
1383 global $langs, $form;
1384
1385 $defaulttopic = GETPOST('subject', 'restricthtml');
1386
1387 if (!GETPOST('modelselected', 'alpha') || GETPOST('modelmailselected') != '-1') {
1388 if ($arraydefaultmessage && $arraydefaultmessage->topic) {
1389 $defaulttopic = $arraydefaultmessage->topic;
1390 } elseif (!is_numeric($this->withtopic)) {
1391 $defaulttopic = $this->withtopic;
1392 }
1393 }
1394
1395 $defaulttopic = make_substitutions($defaulttopic, $this->substit);
1396
1397 $out = '<tr>';
1398 $out .= '<td class="fieldrequired">';
1399 $out .= $form->textwithpicto($langs->trans('MailTopic'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltipfromtopic');
1400 $out .= '</td>';
1401 $out .= '<td>';
1402 if ($this->withtopicreadonly) {
1403 $out .= $defaulttopic;
1404 $out .= '<input type="hidden" class="quatrevingtpercent" id="subject" name="subject" value="'.$defaulttopic.'" />';
1405 } else {
1406 $out .= '<input type="text" class="quatrevingtpercent" id="subject" name="subject" value="'.((GETPOSTISSET("subject") && !GETPOST('modelselected')) ? GETPOST("subject") : ($defaulttopic ? $defaulttopic : '')).'" />';
1407 }
1408 $out .= "</td></tr>\n";
1409 return $out;
1410 }
1411
1420 public function getSectionForAIPrompt($function = 'textgeneration', $format = '', $htmlContent = 'message')
1421 {
1422 global $langs;
1423
1424 $langs->load("other");
1425
1426 $htmlContent = preg_replace('/[^a-z0-9_]/', '', $htmlContent);
1427
1428 $out = '<tr id="ai_input" class="hidden">';
1429 $out .= '<td>';
1430 //$out .= $form->textwithpicto($langs->trans('HelpWithAI'), $langs->trans("YouCanMakeSomeInstructionForEmail"));
1431 $out .= '</td>';
1432
1433 $out .= '<td>';
1434 $out .= '<input type="text" class="quatrevingtpercent" id="ai_instructions" name="instruction" placeholder="'.$langs->trans("EnterYourAIPromptHere").'..." />';
1435 $out .= '<input id="generate_button" type="button" class="button smallpaddingimp" value="'.$langs->trans('Generate').'"/>';
1436 $out .= '<div id="ai_status_message" class="fieldrequired hideobject marginrightonly margintoponly">';
1437 $out .= '<i class="fa fa-spinner fa-spin fa-2x fa-fw valignmiddle marginrightonly"></i>'.$langs->trans("AIProcessingPleaseWait", getDolGlobalString('AI_API_SERVICE', 'chatgpt'));
1438 $out .= '</div>';
1439 $out .= "</td></tr>\n";
1440
1441 $out .= "<script type='text/javascript'>
1442 $(document).ready(function() {
1443 // for keydown
1444 $('#ai_instructions').keydown(function(event) {
1445 if (event.keyCode === 13) {
1446 event.preventDefault();
1447 $('#generate_button').click();
1448 }
1449 });
1450
1451 $('#generate_button').click(function() {
1452 console.log('We click on generate ai button');
1453
1454 var instructions = $('#ai_instructions').val();
1455 var timeoutfinished = 0;
1456 var apicallfinished = 0;
1457
1458 $('#ai_status_message').show();
1459 $('.icon-container .loader').show();
1460 setTimeout(function() {
1461 timeoutfinished = 1;
1462 if (apicallfinished) {
1463 $('#ai_status_message').hide();
1464 }
1465 }, 2000);
1466
1467 // set editor in readonly
1468 if (CKEDITOR.instances.".$htmlContent.") {
1469 CKEDITOR.instances.".$htmlContent.".setReadOnly(1);
1470 }
1471
1472
1473 $.ajax({
1474 url: '". DOL_URL_ROOT."/ai/ajax/generate_content.php?token=".currentToken()."',
1475 type: 'POST',
1476 contentType: 'application/json',
1477 data: JSON.stringify({
1478 'format': '".dol_escape_js($format)."', /* the format for output */
1479 'function': '".dol_escape_js($function)."', /* the AI feature to call */
1480 'instructions': instructions, /* the prompt string */
1481 }),
1482 success: function(response) {
1483 console.log('Add response into field \'".$htmlContent."\': '+response);
1484
1485 jQuery('#".$htmlContent."').val(response);
1486 //jQuery('#".$htmlContent."preview').val(response);
1487
1488 if (CKEDITOR.instances) {
1489 var editorInstance = CKEDITOR.instances.".$htmlContent.";
1490 if (editorInstance) {
1491 editorInstance.setReadOnly(0);
1492 editorInstance.setData(response);
1493 }
1494 //var editorInstancepreview = CKEDITOR.instances.".$htmlContent."preview;
1495 //if (editorInstancepreview) {
1496 // editorInstancepreview.setData(response);
1497 //}
1498 }
1499
1500 // remove readonly
1501 $('#ai_instructions').val('');
1502
1503 apicallfinished = 1;
1504 if (timeoutfinished) {
1505 $('#ai_status_message').hide();
1506 }
1507 },
1508 error: function(xhr, status, error) {
1509 alert(error);
1510 console.error('error ajax', status, error);
1511 $('#ai_status_message').hide();
1512 }
1513
1514 });
1515 });
1516 });
1517 </script>
1518 ";
1519 return $out;
1520 }
1521
1528 public function getModelEmailTemplate($htmlContent = 'message')
1529 {
1530 require_once DOL_DOCUMENT_ROOT.'/core/lib/emaillayout.lib.php';
1531
1532 $out = '<div id="template-selector" class="template-container hidden">';
1533 $templates = array(
1534 'empty' => 'empty',
1535 'basic' => 'basic',
1536 );
1537 //if (getDolGlobalInt('MAIN_FEATURES_LEVEL') > 1) {
1538 $templates['news'] = 'news';
1539 $templates['commerce'] = 'commerce';
1540 //$templates['text'] = 'text';
1541 //}
1542
1543 foreach ($templates as $template => $templateFunction) {
1544 $contentHtml = getHtmlOfLayout($template);
1545
1546 $out .= '<div class="template-option" data-template="'.$template.'" data-content="'.htmlentities($contentHtml).'">';
1547 $out .= '<img class="maillayout" alt="'.$template.'" src="'.DOL_URL_ROOT.'/theme/common/maillayout/'.$template.'.png" />';
1548 $out .= '<span class="template-option-text">'.ucfirst($template).'</span>';
1549 $out .= '</div>';
1550 }
1551 $out .= '</div>';
1552
1553 $out .= '<script type="text/javascript">
1554 $(document).ready(function() {
1555 $(".template-option").click(function() {
1556 var template = $(this).data("template");
1557
1558 console.log("We choose a layout for email template "+template);
1559
1560 $(".template-option").removeClass("selected");
1561 $(this).addClass("selected");
1562
1563 var contentHtml = $(this).data("content");
1564
1565 jQuery("#'.$htmlContent.'").val(contentHtml);
1566 var editorInstance = CKEDITOR.instances.'.$htmlContent.';
1567 if (editorInstance) {
1568 editorInstance.setData(contentHtml);
1569 }
1570 });
1571 });
1572 </script>';
1573
1574 return $out;
1575 }
1576
1594 public function getEMailTemplate($dbs, $type_template, $user, $outputlangs, $id = 0, $active = 1, $label = '', $defaultfortype = -1)
1595 {
1596 global $conf;
1597
1598 if ($id == -2 && empty($label)) {
1599 $this->error = 'LabelIsMandatoryWhenIdIs-2or-3';
1600 return -1;
1601 }
1602
1603 $ret = new ModelMail($dbs);
1604
1605 $languagetosearch = (is_object($outputlangs) ? $outputlangs->defaultlang : '');
1606 // Define $languagetosearchmain to fall back on main language (for example to get 'es_ES' for 'es_MX')
1607 $tmparray = explode('_', $languagetosearch);
1608 $languagetosearchmain = $tmparray[0].'_'.strtoupper($tmparray[0]);
1609 if ($languagetosearchmain == $languagetosearch) {
1610 $languagetosearchmain = '';
1611 }
1612
1613 $sql = "SELECT rowid, entity, module, label, type_template, topic, email_from, joinfiles, content, content_lines, lang, email_from, email_to, email_tocc, email_tobcc";
1614 $sql .= " FROM ".$dbs->prefix().'c_email_templates';
1615 $sql .= " WHERE (type_template = '".$dbs->escape($type_template)."' OR type_template = 'all')";
1616 $sql .= " AND entity IN (".getEntity('c_email_templates').")";
1617 $sql .= " AND (private = 0 OR fk_user = ".((int) $user->id).")"; // Get all public or private owned
1618 if ($active >= 0) {
1619 $sql .= " AND active = ".((int) $active);
1620 }
1621 if ($defaultfortype >= 0) {
1622 $sql .= " AND defaultfortype = ".((int) $defaultfortype);
1623 }
1624 if ($label) {
1625 $sql .= " AND label = '".$dbs->escape($label)."'";
1626 }
1627 if (!($id > 0) && $languagetosearch) {
1628 $sql .= " AND (lang = '".$dbs->escape($languagetosearch)."'".($languagetosearchmain ? " OR lang = '".$dbs->escape($languagetosearchmain)."'" : "")." OR lang IS NULL OR lang = '')";
1629 }
1630 if ($id > 0) {
1631 $sql .= " AND rowid = ".(int) $id;
1632 }
1633 if ($id == -1) {
1634 $sql .= " AND position = 0";
1635 }
1636 $sql .= " AND entity IN(".getEntity('c_email_templates', 1).")";
1637 if ($languagetosearch) {
1638 $sql .= $dbs->order("position,lang,label", "ASC,DESC,ASC"); // We want line with lang set first, then with lang null or ''
1639 } else {
1640 $sql .= $dbs->order("position,lang,label", "ASC,ASC,ASC"); // If no language provided, we give priority to lang not defined
1641 }
1642 //$sql .= $dbs->plimit(1);
1643 //print $sql;
1644
1645 $resql = $dbs->query($sql);
1646 if (!$resql) {
1647 dol_print_error($dbs);
1648 return -1;
1649 }
1650
1651 // Get first found
1652 while (1) {
1653 $obj = $dbs->fetch_object($resql);
1654
1655 if ($obj) {
1656 // If template is for a module, check module is enabled; if not, take next template
1657 if ($obj->module) {
1658 $tempmodulekey = $obj->module;
1659 if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1660 continue;
1661 }
1662 }
1663
1664 // If a record was found
1665 $ret->id = $obj->rowid;
1666 $ret->module = $obj->module;
1667 $ret->label = $obj->label;
1668 $ret->lang = $obj->lang;
1669 $ret->topic = $obj->topic;
1670 $ret->content = $obj->content;
1671 $ret->content_lines = $obj->content_lines;
1672 $ret->joinfiles = $obj->joinfiles;
1673 $ret->email_from = $obj->email_from;
1674
1675 break;
1676 } else {
1677 // If no record found
1678 if ($id == -2) {
1679 // Not found with the provided label
1680 return -1;
1681 } else {
1682 // If there is no template at all
1683 $defaultmessage = '';
1684
1685 if ($type_template == 'body') {
1686 // Special case to use this->withbody as content
1687 $defaultmessage = $this->withbody;
1688 } elseif ($type_template == 'facture_send') {
1689 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoice");
1690 } elseif ($type_template == 'facture_relance') {
1691 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoiceReminder");
1692 } elseif ($type_template == 'propal_send') {
1693 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendProposal");
1694 } elseif ($type_template == 'supplier_proposal_send') {
1695 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierProposal");
1696 } elseif ($type_template == 'order_send') {
1697 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendOrder");
1698 } elseif ($type_template == 'order_supplier_send') {
1699 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder");
1700 } elseif ($type_template == 'invoice_supplier_send') {
1701 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice");
1702 } elseif ($type_template == 'shipping_send') {
1703 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendShipping");
1704 } elseif ($type_template == 'fichinter_send') {
1705 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendFichInter");
1706 } elseif ($type_template == 'actioncomm_send') {
1707 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendActionComm");
1708 } elseif (!empty($type_template)) {
1709 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentGeneric");
1710 }
1711
1712 $ret->label = 'default';
1713 $ret->lang = $outputlangs->defaultlang;
1714 $ret->topic = '';
1715 $ret->joinfiles = 1;
1716 $ret->content = $defaultmessage;
1717 $ret->content_lines = '';
1718
1719 break;
1720 }
1721 }
1722 }
1723
1724 $dbs->free($resql);
1725
1726 return $ret;
1727 }
1728
1738 public function isEMailTemplate($type_template, $user, $outputlangs)
1739 {
1740 $sql = "SELECT label, topic, content, lang";
1741 $sql .= " FROM ".$this->db->prefix().'c_email_templates';
1742 $sql .= " WHERE type_template='".$this->db->escape($type_template)."'";
1743 $sql .= " AND entity IN (".getEntity('c_email_templates').")";
1744 $sql .= " AND (fk_user is NULL or fk_user = 0 or fk_user = ".((int) $user->id).")";
1745 if (is_object($outputlangs)) {
1746 $sql .= " AND (lang = '".$this->db->escape($outputlangs->defaultlang)."' OR lang IS NULL OR lang = '')";
1747 }
1748 $sql .= $this->db->order("lang,label", "ASC");
1749 //print $sql;
1750
1751 $resql = $this->db->query($sql);
1752 if ($resql) {
1753 $num = $this->db->num_rows($resql);
1754 $this->db->free($resql);
1755 return $num;
1756 } else {
1757 $this->error = get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1758 return -1;
1759 }
1760 }
1761
1772 public function fetchAllEMailTemplate($type_template, $user, $outputlangs, $active = 1)
1773 {
1774 global $db, $conf;
1775
1776 $sql = "SELECT rowid, module, label, topic, content, content_lines, lang, fk_user, private, position";
1777 $sql .= " FROM ".$this->db->prefix().'c_email_templates';
1778 $sql .= " WHERE type_template IN ('".$this->db->escape($type_template)."', 'all')";
1779 $sql .= " AND entity IN (".getEntity('c_email_templates').")";
1780 $sql .= " AND (private = 0 OR fk_user = ".((int) $user->id).")"; // See all public templates or templates I own.
1781 if ($active >= 0) {
1782 $sql .= " AND active = ".((int) $active);
1783 }
1784 //if (is_object($outputlangs)) $sql.= " AND (lang = '".$this->db->escape($outputlangs->defaultlang)."' OR lang IS NULL OR lang = '')"; // Return all languages
1785 $sql .= $this->db->order("position,lang,label", "ASC");
1786 //print $sql;
1787
1788 $resql = $this->db->query($sql);
1789 if ($resql) {
1790 $num = $this->db->num_rows($resql);
1791 $this->lines_model = array();
1792 while ($obj = $this->db->fetch_object($resql)) {
1793 // If template is for a module, check module is enabled.
1794 if ($obj->module) {
1795 $tempmodulekey = $obj->module;
1796 if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1797 continue;
1798 }
1799 }
1800
1801 $line = new ModelMail($db);
1802 $line->id = $obj->rowid;
1803 $line->label = $obj->label;
1804 $line->lang = $obj->lang;
1805 $line->fk_user = $obj->fk_user;
1806 $line->private = $obj->private;
1807 $line->position = $obj->position;
1808 $line->topic = $obj->topic;
1809 $line->content = $obj->content;
1810 $line->content_lines = $obj->content_lines;
1811
1812 $this->lines_model[] = $line;
1813 }
1814 $this->db->free($resql);
1815 return $num;
1816 } else {
1817 $this->error = get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1818 return -1;
1819 }
1820 }
1821
1822
1823
1832 public function setSubstitFromObject($object, $outputlangs)
1833 {
1834 global $extrafields;
1835
1836 $parameters = array();
1837 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1838 complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
1839
1840 $this->substit = $tmparray;
1841
1842 // Fill substit_lines with each object lines content
1843 if (is_array($object->lines)) {
1844 foreach ($object->lines as $line) {
1845 $substit_line = array(
1846 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
1847 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
1848 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
1849 '__LABEL__' => isset($line->label) ? $line->label : '',
1850 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
1851 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', 0, $outputlangs),
1852 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', 0, $outputlangs),
1853 '__QUANTITY__' => $line->qty,
1854 '__SUBPRICE__' => price($line->subprice),
1855 '__AMOUNT__' => price($line->total_ttc),
1856 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
1857 );
1858
1859 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
1860 if (!empty($line->fk_product)) {
1861 if (!is_object($extrafields)) {
1862 $extrafields = new ExtraFields($this->db);
1863 }
1864 $product = new Product($this->db);
1865 $product->fetch($line->fk_product, '', '', 1);
1866 $product->fetch_optionals();
1867
1868 $extrafields->fetch_name_optionals_label($product->table_element, true);
1869
1870 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
1871 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
1872 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
1873 }
1874 }
1875 }
1876 $this->substit_lines[] = $substit_line;
1877 }
1878 }
1879 }
1880
1889 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
1890 {
1891 global $langs;
1892
1893 $tmparray = array();
1894 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
1895 $parameters = array('mode' => $mode);
1896 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
1897 complete_substitutions_array($tmparray, $langs, null, $parameters);
1898
1899 if ($mode == 'formwithlines') {
1900 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
1901 }
1902 if ($mode == 'formforlines') {
1903 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
1904 }
1905 }
1906
1907 if ($mode == 'emailing') {
1908 $parameters = array('mode' => $mode);
1909 $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
1910 complete_substitutions_array($tmparray, $langs, null, $parameters);
1911
1912 // For mass emailing, we have different keys specific to the data into tagerts list
1913 $tmparray['__ID__'] = 'IdRecord';
1914 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode';
1915 $tmparray['__EMAIL__'] = 'EMailRecipient';
1916 $tmparray['__LASTNAME__'] = 'Lastname';
1917 $tmparray['__FIRSTNAME__'] = 'Firstname';
1918 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
1919 $tmparray['__OTHER1__'] = 'Other1';
1920 $tmparray['__OTHER2__'] = 'Other2';
1921 $tmparray['__OTHER3__'] = 'Other3';
1922 $tmparray['__OTHER4__'] = 'Other4';
1923 $tmparray['__OTHER5__'] = 'Other5';
1924 $tmparray['__CHECK_READ__'] = $langs->trans('TagCheckMail');
1925 $tmparray['__UNSUBSCRIBE__'] = $langs->trans('TagUnsubscribe');
1926 $tmparray['__UNSUBSCRIBE_URL__'] = $langs->trans('TagUnsubscribe').' (URL)';
1927
1928 $onlinepaymentenabled = 0;
1929 if (isModEnabled('paypal')) {
1930 $onlinepaymentenabled++;
1931 }
1932 if (isModEnabled('paybox')) {
1933 $onlinepaymentenabled++;
1934 }
1935 if (isModEnabled('stripe')) {
1936 $onlinepaymentenabled++;
1937 }
1938 if ($onlinepaymentenabled && getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
1939 $tmparray['__SECUREKEYPAYMENT__'] = getDolGlobalString('PAYMENT_SECURITY_TOKEN');
1940 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
1941 if (isModEnabled('member')) {
1942 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
1943 }
1944 if (isModEnabled('don')) {
1945 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
1946 }
1947 if (isModEnabled('invoice')) {
1948 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
1949 }
1950 if (isModEnabled('order')) {
1951 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
1952 }
1953 if (isModEnabled('contract')) {
1954 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
1955 }
1956
1957 //Online payment link
1958 if (isModEnabled('member')) {
1959 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
1960 }
1961 if (isModEnabled('don')) {
1962 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
1963 }
1964 if (isModEnabled('invoice')) {
1965 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
1966 }
1967 if (isModEnabled('order')) {
1968 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
1969 }
1970 if (isModEnabled('contract')) {
1971 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
1972 }
1973 }
1974 } else {
1975 /* No need to show into tooltip help, option is not enabled
1976 $vars['__SECUREKEYPAYMENT__']='';
1977 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
1978 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
1979 $vars['__SECUREKEYPAYMENT_ORDER__']='';
1980 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
1981 */
1982 }
1983 if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) {
1984 $tmparray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
1985 }
1986 }
1987
1988 foreach ($tmparray as $key => $val) {
1989 if (empty($val)) {
1990 $tmparray[$key] = $key;
1991 }
1992 }
1993
1994 return $tmparray;
1995 }
1996}
1997
1998
1999require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
2000
2006class ModelMail extends CommonObject
2007{
2011 public $element = 'email_template';
2012
2016 public $table_element = 'c_email_templates';
2017
2018
2019 // BEGIN MODULEBUILDER PROPERTIES
2023 public $fields=array(
2024 "rowid" => array("type"=>"integer", "label"=>"TechnicalID", "enabled"=>"1", 'position'=>10, 'notnull'=>1, "visible"=>"-1",),
2025 "module" => array("type"=>"varchar(32)", "label"=>"Module", "enabled"=>"1", 'position'=>20, 'notnull'=>0, "visible"=>"-1",),
2026 "type_template" => array("type"=>"varchar(32)", "label"=>"Typetemplate", "enabled"=>"1", 'position'=>25, 'notnull'=>0, "visible"=>"-1",),
2027 "lang" => array("type"=>"varchar(6)", "label"=>"Lang", "enabled"=>"1", 'position'=>30, 'notnull'=>0, "visible"=>"-1",),
2028 "private" => array("type"=>"smallint(6)", "label"=>"Private", "enabled"=>"1", 'position'=>35, 'notnull'=>1, "visible"=>"-1",),
2029 "fk_user" => array("type"=>"integer:User:user/class/user.class.php", "label"=>"Fkuser", "enabled"=>"1", 'position'=>40, 'notnull'=>0, "visible"=>"-1", "css"=>"maxwidth500 widthcentpercentminusxx", "csslist"=>"tdoverflowmax150",),
2030 "datec" => array("type"=>"datetime", "label"=>"DateCreation", "enabled"=>"1", 'position'=>45, 'notnull'=>0, "visible"=>"-1",),
2031 "tms" => array("type"=>"timestamp", "label"=>"DateModification", "enabled"=>"1", 'position'=>50, 'notnull'=>1, "visible"=>"-1",),
2032 "label" => array("type"=>"varchar(255)", "label"=>"Label", "enabled"=>"1", 'position'=>55, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1", "css"=>"minwidth300", "cssview"=>"wordbreak", "csslist"=>"tdoverflowmax150",),
2033 "position" => array("type"=>"smallint(6)", "label"=>"Position", "enabled"=>"1", 'position'=>60, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2034 "active" => array("type"=>"integer", "label"=>"Active", "enabled"=>"1", 'position'=>65, 'notnull'=>1, "visible"=>"-1", "alwayseditable"=>"1",),
2035 "topic" => array("type"=>"text", "label"=>"Topic", "enabled"=>"1", 'position'=>70, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2036 "content" => array("type"=>"mediumtext", "label"=>"Content", "enabled"=>"1", 'position'=>75, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2037 "content_lines" => array("type"=>"text", "label"=>"Contentlines", "enabled"=>"1", 'position'=>80, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2038 "enabled" => array("type"=>"varchar(255)", "label"=>"Enabled", "enabled"=>"1", 'position'=>85, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2039 "joinfiles" => array("type"=>"varchar(255)", "label"=>"Joinfiles", "enabled"=>"1", 'position'=>90, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2040 "email_from" => array("type"=>"varchar(255)", "label"=>"Emailfrom", "enabled"=>"1", 'position'=>95, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2041 "email_to" => array("type"=>"varchar(255)", "label"=>"Emailto", "enabled"=>"1", 'position'=>100, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2042 "email_tocc" => array("type"=>"varchar(255)", "label"=>"Emailtocc", "enabled"=>"1", 'position'=>105, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2043 "email_tobcc" => array("type"=>"varchar(255)", "label"=>"Emailtobcc", "enabled"=>"1", 'position'=>110, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2044 "defaultfortype" => array("type"=>"smallint(6)", "label"=>"Defaultfortype", "enabled"=>"1", 'position'=>115, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2045 );
2046 public $rowid;
2047 public $type_template;
2048 public $datec;
2049 public $tms;
2050 public $active;
2051 public $enabled;
2052 public $defaultfortype;
2053
2057 public $id;
2058
2062 public $label;
2063
2067 public $fk_user;
2068
2072 public $private;
2073
2077 public $topic;
2078
2082 public $content;
2083 public $content_lines;
2084 public $lang;
2085 public $joinfiles;
2086
2087 public $email_from;
2088 public $email_to;
2089 public $email_tocc;
2090 public $email_tobcc;
2091
2095 public $module;
2096
2100 public $position;
2101 // END MODULEBUILDER PROPERTIES
2102
2103
2104
2110 public function __construct(DoliDB $db)
2111 {
2112 global $langs;
2113
2114 $this->db = $db;
2115 $this->ismultientitymanaged = 0;
2116 $this->isextrafieldmanaged = 1;
2117
2118 if (!getDolGlobalInt('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid']) && !empty($this->fields['ref'])) {
2119 $this->fields['rowid']['visible'] = 0;
2120 }
2121 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
2122 $this->fields['entity']['enabled'] = 0;
2123 }
2124
2125 // Example to show how to set values of fields definition dynamically
2126 /*if ($user->hasRight('test', 'mailtemplate', 'read')) {
2127 $this->fields['myfield']['visible'] = 1;
2128 $this->fields['myfield']['noteditable'] = 0;
2129 }*/
2130
2131 // Unset fields that are disabled
2132 foreach ($this->fields as $key => $val) {
2133 if (isset($val['enabled']) && empty($val['enabled'])) {
2134 unset($this->fields[$key]);
2135 }
2136 }
2137
2138 // Translate some data of arrayofkeyval
2139 if (is_object($langs)) {
2140 foreach ($this->fields as $key => $val) {
2141 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
2142 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
2143 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
2144 }
2145 }
2146 }
2147 }
2148 }
2149
2150
2160 public function fetch($id, $ref = null, $noextrafields = 0, $nolines = 0)
2161 {
2162 $result = $this->fetchCommon($id, $ref, '', $noextrafields);
2163 if ($result > 0 && !empty($this->table_element_line) && empty($nolines)) {
2164 $this->fetchLines($noextrafields);
2165 }
2166 return $result;
2167 }
2168}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:637
print $object position
Definition edit.php:195
Class to manage a WYSIWYG editor.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
static selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='minwidth75', $addjscombo=1, $moreparamonempty='', $disablebademail=0, $nohtmlescape=0)
Return a HTML select string, built from an array of key+value.
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 for Position.
Class to manage translations.
Class to manage Dolibarr users.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 dolibarr global constant string value.
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...
ui state ui widget content ui state ui widget header ui state a ui button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
$conf db user
Active Directory does not allow anonymous connections.
Definition repair.php:141
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:137
getMaxFileSizeArray()
Return the max allowed for file upload.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e rowid
Definition invoice.php:2043