dolibarr 20.0.2
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).")";
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['__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
993 $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = dol_nl2br($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__']);
994 }
995 if (!dol_textishtml($defaultmessage)) {
996 $defaultmessage = dol_nl2br($defaultmessage);
997 }
998 }
999
1000 if (GETPOSTISSET("message") && !GETPOST('modelselected')) {
1001 $defaultmessage = GETPOST("message", "restricthtml");
1002 } else {
1003 $defaultmessage = make_substitutions($defaultmessage, $this->substit);
1004 // Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty)
1005 $defaultmessage = preg_replace("/^(<br>)+/", "", $defaultmessage);
1006 $defaultmessage = preg_replace("/^\n+/", "", $defaultmessage);
1007 }
1008
1009 $out .= '<tr>';
1010 $out .= '<td class="tdtop">';
1011 $out .= $form->textwithpicto($langs->trans('MailText'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltipfrombody');
1012 $out .= '</td>';
1013 $out .= '<td class="tdtop">';
1014
1015 $formmail = $this;
1016 $showlinktolayout = $formmail->withlayout && $formmail->withfckeditor && getDolGlobalInt('MAIN_EMAIL_USE_LAYOUT');
1017 $showlinktolayoutlabel = $langs->trans("FillMessageWithALayout");
1018 $showlinktoai = ($formmail->withaiprompt && isModEnabled('ai')) ? 'textgenerationemail' : '';
1019 $showlinktoailabel = $langs->trans("FillMessageWithAIContent");
1020 $formatforouput = '';
1021 $htmlname = 'message';
1022
1023 // Fill $out
1024 include DOL_DOCUMENT_ROOT.'/core/tpl/formlayoutai.tpl.php';
1025
1026 $out .= '</td>';
1027 $out .= '</tr>';
1028
1029 $out .= '<tr>';
1030 $out .= '<td colspan="2">';
1031 if ($this->withbodyreadonly) {
1032 $out .= nl2br($defaultmessage);
1033 $out .= '<input type="hidden" id="message" name="message" disabled value="'.$defaultmessage.'" />';
1034 } else {
1035 if (!isset($this->ckeditortoolbar)) {
1036 $this->ckeditortoolbar = 'dolibarr_mailings';
1037 }
1038
1039 // Editor wysiwyg
1040 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1041 if ($this->withfckeditor == -1) {
1042 if (getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) {
1043 $this->withfckeditor = 1;
1044 } else {
1045 $this->withfckeditor = 0;
1046 }
1047 }
1048
1049 $doleditor = new DolEditor('message', $defaultmessage, '', 280, $this->ckeditortoolbar, 'In', true, true, $this->withfckeditor, 8, '95%');
1050 $out .= $doleditor->Create(1);
1051 }
1052 $out .= "</td></tr>\n";
1053 }
1054
1055 $out .= '</table>'."\n";
1056
1057 if ($this->withform == 1 || $this->withform == -1) {
1058 $out .= '<div class="center">';
1059 $out .= '<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans("SendMail").'"';
1060 // Add a javascript test to avoid to forget to submit file before sending email
1061 if ($this->withfile == 2 && $conf->use_javascript_ajax) {
1062 $out .= ' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans("FileWasNotUploaded")).'\'); return false; } else { return true; }"';
1063 }
1064 $out .= ' />';
1065 if ($this->withcancel) {
1066 $out .= '<input class="button button-cancel" type="submit" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'" />';
1067 }
1068 $out .= '</div>'."\n";
1069 }
1070
1071 if ($this->withform == 1) {
1072 $out .= '</form>'."\n";
1073 }
1074
1075 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1076 if (getDolGlobalString('MAIN_MAILFORM_DISABLE_ENTERKEY')) {
1077 $out .= '<script nonce="'.getNonce().'" type="text/javascript">';
1078 $out .= 'jQuery(document).ready(function () {';
1079 $out .= ' $(document).on("keypress", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1080 var code = e.keyCode || e.which;
1081 if (code == 13) {
1082 console.log("Enter was intercepted and blocked");
1083 e.preventDefault();
1084 return false;
1085 }
1086 });';
1087 $out .= ' })';
1088 $out .= '</script>';
1089 }
1090
1091 $out .= "<!-- End form mail -->\n";
1092
1093 return $out;
1094 }
1095 }
1096
1102 public function getHtmlForTo()
1103 {
1104 global $langs, $form;
1105 $out = '<tr><td class="fieldrequired">';
1106 if ($this->withtofree) {
1107 $out .= $form->textwithpicto($langs->trans("MailTo"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
1108 } else {
1109 $out .= $langs->trans("MailTo");
1110 }
1111 $out .= '</td><td>';
1112 if ($this->withtoreadonly) {
1113 if (!empty($this->toname) && !empty($this->tomail)) {
1114 $out .= '<input type="hidden" id="toname" name="toname" value="'.$this->toname.'" />';
1115 $out .= '<input type="hidden" id="tomail" name="tomail" value="'.$this->tomail.'" />';
1116 if ($this->totype == 'thirdparty') {
1117 $soc = new Societe($this->db);
1118 $soc->fetch($this->toid);
1119 $out .= $soc->getNomUrl(1);
1120 } elseif ($this->totype == 'contact') {
1121 $contact = new Contact($this->db);
1122 $contact->fetch($this->toid);
1123 $out .= $contact->getNomUrl(1);
1124 } else {
1125 $out .= $this->toname;
1126 }
1127 $out .= ' &lt;'.$this->tomail.'&gt;';
1128 if ($this->withtofree) {
1129 $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) : "").'" />';
1130 }
1131 } else {
1132 // Note withto may be a text like 'AllRecipientSelected'
1133 $out .= (!is_array($this->withto) && !is_numeric($this->withto)) ? $this->withto : "";
1134 }
1135 } else {
1136 // The free input of email
1137 if (!empty($this->withtofree)) {
1138 $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) : "")).'" />';
1139 }
1140 // The select combo
1141 if (!empty($this->withto) && is_array($this->withto)) {
1142 if (!empty($this->withtofree)) {
1143 $out .= " ".$langs->trans("and")."/".$langs->trans("or")." ";
1144 }
1145
1146 $tmparray = $this->withto;
1147 foreach ($tmparray as $key => $val) {
1148 if (is_array($val)) {
1149 $label = $val['label'];
1150 } else {
1151 $label = $val;
1152 }
1153
1154 $tmparray[$key] = array();
1155 $tmparray[$key]['id'] = $key;
1156
1157 $tmparray[$key]['label'] = $label;
1158 $tmparray[$key]['label'] = str_replace(array('<', '>'), array('(', ')'), $tmparray[$key]['label']);
1159 // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time
1160 $tmparray[$key]['label'] = dol_htmlentities($tmparray[$key]['label'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', true);
1161
1162 $tmparray[$key]['labelhtml'] = $label;
1163 $tmparray[$key]['labelhtml'] = str_replace(array('&lt;', '<', '&gt;', '>'), array('__LTCHAR__', '__LTCHAR__', '__GTCHAR__', '__GTCHAR__'), $tmparray[$key]['labelhtml']);
1164 $tmparray[$key]['labelhtml'] = str_replace(array('__LTCHAR__', '__GTCHAR__'), array('<span class="opacitymedium">(', ')</span>'), $tmparray[$key]['labelhtml']);
1165 }
1166
1167 $withtoselected = GETPOST("receiver", 'array'); // Array of selected value
1168 if (!getDolGlobalInt('MAIN_MAIL_NO_WITH_TO_SELECTED')) {
1169 if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') {
1170 $withtoselected = array_keys($tmparray);
1171 }
1172 }
1173
1174 $out .= $form->multiselectarray("receiver", $tmparray, $withtoselected, null, null, 'inline-block minwidth500', 0, 0);
1175 }
1176 }
1177 $out .= "</td></tr>\n";
1178 return $out;
1179 }
1180
1186 public function getHtmlForCc()
1187 {
1188 global $langs, $form;
1189 $out = '<tr><td>';
1190 $out .= $form->textwithpicto($langs->trans("MailCC"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
1191 $out .= '</td><td>';
1192 if ($this->withtoccreadonly) {
1193 $out .= (!is_array($this->withtocc) && !is_numeric($this->withtocc)) ? $this->withtocc : "";
1194 } else {
1195 $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 : '')).'" />';
1196 if (!empty($this->withtocc) && is_array($this->withtocc)) {
1197 $out .= " ".$langs->trans("and")."/".$langs->trans("or")." ";
1198
1199 $tmparray = $this->withtocc;
1200 foreach ($tmparray as $key => $val) {
1201 if (is_array($val)) {
1202 $label = $val['label'];
1203 } else {
1204 $label = $val;
1205 }
1206
1207 $tmparray[$key] = array();
1208 $tmparray[$key]['id'] = $key;
1209
1210 $tmparray[$key]['label'] = $label;
1211 $tmparray[$key]['label'] = str_replace(array('<', '>'), array('(', ')'), $tmparray[$key]['label']);
1212 // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time
1213 $tmparray[$key]['label'] = dol_htmlentities($tmparray[$key]['label'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', true);
1214
1215 $tmparray[$key]['labelhtml'] = $label;
1216 $tmparray[$key]['labelhtml'] = str_replace(array('&lt;', '<', '&gt;', '>'), array('__LTCHAR__', '__LTCHAR__', '__GTCHAR__', '__GTCHAR__'), $tmparray[$key]['labelhtml']);
1217 $tmparray[$key]['labelhtml'] = str_replace(array('__LTCHAR__', '__GTCHAR__'), array('<span class="opacitymedium">(', ')</span>'), $tmparray[$key]['labelhtml']);
1218 }
1219
1220 $withtoccselected = GETPOST("receivercc", 'array'); // Array of selected value
1221
1222 $out .= $form->multiselectarray("receivercc", $tmparray, $withtoccselected, null, null, 'inline-block minwidth500', 0, 0);
1223 }
1224 }
1225 $out .= "</td></tr>\n";
1226 return $out;
1227 }
1228
1235 public function getHtmlForWithCcc()
1236 {
1237 global $langs, $form;
1238
1239 $out = '<tr><td>';
1240 $out .= $form->textwithpicto($langs->trans("MailCCC"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
1241 $out .= '</td><td>';
1242 if (!empty($this->withtocccreadonly)) {
1243 $out .= (!is_array($this->withtoccc) && !is_numeric($this->withtoccc)) ? $this->withtoccc : "";
1244 } else {
1245 $out .= '<input class="minwidth200" id="sendtoccc" name="sendtoccc" value="'.(GETPOSTISSET("sendtoccc") ? GETPOST("sendtoccc", "alpha") : ((!is_array($this->withtoccc) && !is_numeric($this->withtoccc)) ? $this->withtoccc : '')).'" />';
1246 if (!empty($this->withtoccc) && is_array($this->withtoccc)) {
1247 $out .= " ".$langs->trans("and")."/".$langs->trans("or")." ";
1248
1249 $tmparray = $this->withtoccc;
1250 foreach ($tmparray as $key => $val) {
1251 if (is_array($val)) {
1252 $label = $val['label'];
1253 } else {
1254 $label = $val;
1255 }
1256 $tmparray[$key] = array();
1257 $tmparray[$key]['id'] = $key;
1258
1259 $tmparray[$key]['label'] = $label;
1260 $tmparray[$key]['label'] = str_replace(array('<', '>'), array('(', ')'), $tmparray[$key]['label']);
1261 // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time
1262 $tmparray[$key]['label'] = dol_htmlentities($tmparray[$key]['label'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', true);
1263
1264 $tmparray[$key]['labelhtml'] = $label;
1265 $tmparray[$key]['labelhtml'] = str_replace(array('&lt;', '<', '&gt;', '>'), array('__LTCHAR__', '__LTCHAR__', '__GTCHAR__', '__GTCHAR__'), $tmparray[$key]['labelhtml']);
1266 $tmparray[$key]['labelhtml'] = str_replace(array('__LTCHAR__', '__GTCHAR__'), array('<span class="opacitymedium">(', ')</span>'), $tmparray[$key]['labelhtml']);
1267 }
1268
1269 $withtocccselected = GETPOST("receiverccc", 'array'); // Array of selected value
1270
1271 $out .= $form->multiselectarray("receiverccc", $tmparray, $withtocccselected, null, null, 'inline-block minwidth500', 0, 0);
1272 }
1273 }
1274
1275 $showinfobcc = '';
1276 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_PROPOSAL_TO') && !empty($this->param['models']) && $this->param['models'] == 'propal_send') {
1277 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_PROPOSAL_TO');
1278 }
1279 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_ORDER_TO') && !empty($this->param['models']) && $this->param['models'] == 'order_send') {
1280 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_ORDER_TO');
1281 }
1282 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_INVOICE_TO') && !empty($this->param['models']) && $this->param['models'] == 'facture_send') {
1283 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_INVOICE_TO');
1284 }
1285 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO') && !empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') {
1286 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO');
1287 }
1288 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO') && !empty($this->param['models']) && $this->param['models'] == 'order_supplier_send') {
1289 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO');
1290 }
1291 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO') && !empty($this->param['models']) && $this->param['models'] == 'invoice_supplier_send') {
1292 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO');
1293 }
1294 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.
1295 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_PROJECT_TO');
1296 }
1297 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_SHIPMENT_TO') && !empty($this->param['models']) && $this->param['models'] == 'shipping_send') {
1298 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_SHIPMENT_TO');
1299 }
1300 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_RECEPTION_TO') && !empty($this->param['models']) && $this->param['models'] == 'reception_send') {
1301 $showinfobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_RECEPTION_TO');
1302 }
1303 if ($showinfobcc) {
1304 $out .= ' + '.$showinfobcc;
1305 }
1306 $out .= "</td></tr>\n";
1307 return $out;
1308 }
1309
1315 public function getHtmlForWithErrorsTo()
1316 {
1317 global $langs;
1318
1319 //if (! $this->errorstomail) $this->errorstomail=$this->frommail;
1320 $errorstomail = getDolGlobalString('MAIN_MAIL_ERRORS_TO', (!empty($this->errorstomail) ? $this->errorstomail : ''));
1321 if ($this->witherrorstoreadonly) {
1322 $out = '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td>';
1323 $out .= '<input type="hidden" id="errorstomail" name="errorstomail" value="'.$errorstomail.'" />';
1324 $out .= $errorstomail;
1325 $out .= "</td></tr>\n";
1326 } else {
1327 $out = '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td>';
1328 $out .= '<input class="minwidth200" id="errorstomail" name="errorstomail" value="'.$errorstomail.'" />';
1329 $out .= "</td></tr>\n";
1330 }
1331 return $out;
1332 }
1333
1339 public function getHtmlForDeliveryreceipt()
1340 {
1341 global $langs;
1342
1343 $out = '<tr><td><label for="deliveryreceipt">'.$langs->trans("DeliveryReceipt").'</label></td><td>';
1344
1345 if (!empty($this->withdeliveryreceiptreadonly)) {
1346 $out .= yn($this->withdeliveryreceipt);
1347 } else {
1348 $defaultvaluefordeliveryreceipt = 0;
1349 if (getDolGlobalString('MAIL_FORCE_DELIVERY_RECEIPT_PROPAL') && !empty($this->param['models']) && $this->param['models'] == 'propal_send') {
1350 $defaultvaluefordeliveryreceipt = 1;
1351 }
1352 if (getDolGlobalString('MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_PROPOSAL') && !empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') {
1353 $defaultvaluefordeliveryreceipt = 1;
1354 }
1355 if (getDolGlobalString('MAIL_FORCE_DELIVERY_RECEIPT_ORDER') && !empty($this->param['models']) && $this->param['models'] == 'order_send') {
1356 $defaultvaluefordeliveryreceipt = 1;
1357 }
1358 if (getDolGlobalString('MAIL_FORCE_DELIVERY_RECEIPT_INVOICE') && !empty($this->param['models']) && $this->param['models'] == 'facture_send') {
1359 $defaultvaluefordeliveryreceipt = 1;
1360 }
1361 if (getDolGlobalString('MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_ORDER') && !empty($this->param['models']) && $this->param['models'] == 'order_supplier_send') {
1362 $defaultvaluefordeliveryreceipt = 1;
1363 }
1364 //$out .= $form->selectyesno('deliveryreceipt', (GETPOSTISSET("deliveryreceipt") ? GETPOST("deliveryreceipt") : $defaultvaluefordeliveryreceipt), 1);
1365 $out .= '<input type="checkbox" id="deliveryreceipt" name="deliveryreceipt" value="1"'.((GETPOSTISSET("deliveryreceipt") ? GETPOST("deliveryreceipt") : $defaultvaluefordeliveryreceipt) ? ' checked="checked"' : '').'>';
1366 }
1367 $out .= "</td></tr>\n";
1368 return $out;
1369 }
1370
1378 public function getHtmlForTopic($arraydefaultmessage, $helpforsubstitution)
1379 {
1380 global $langs, $form;
1381
1382 $defaulttopic = GETPOST('subject', 'restricthtml');
1383
1384 if (!GETPOST('modelselected', 'alpha') || GETPOST('modelmailselected') != '-1') {
1385 if ($arraydefaultmessage && $arraydefaultmessage->topic) {
1386 $defaulttopic = $arraydefaultmessage->topic;
1387 } elseif (!is_numeric($this->withtopic)) {
1388 $defaulttopic = $this->withtopic;
1389 }
1390 }
1391
1392 $defaulttopic = make_substitutions($defaulttopic, $this->substit);
1393
1394 $out = '<tr>';
1395 $out .= '<td class="fieldrequired">';
1396 $out .= $form->textwithpicto($langs->trans('MailTopic'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltipfromtopic');
1397 $out .= '</td>';
1398 $out .= '<td>';
1399 if ($this->withtopicreadonly) {
1400 $out .= $defaulttopic;
1401 $out .= '<input type="hidden" class="quatrevingtpercent" id="subject" name="subject" value="'.$defaulttopic.'" />';
1402 } else {
1403 $out .= '<input type="text" class="quatrevingtpercent" id="subject" name="subject" value="'.((GETPOSTISSET("subject") && !GETPOST('modelselected')) ? GETPOST("subject") : ($defaulttopic ? $defaulttopic : '')).'" />';
1404 }
1405 $out .= "</td></tr>\n";
1406 return $out;
1407 }
1408
1417 public function getSectionForAIPrompt($function = 'textgeneration', $format = '', $htmlContent = 'message')
1418 {
1419 global $langs;
1420
1421 $langs->load("other");
1422
1423 $htmlContent = preg_replace('/[^a-z0-9_]/', '', $htmlContent);
1424
1425 $out = '<tr id="ai_input" class="hidden">';
1426 $out .= '<td>';
1427 //$out .= $form->textwithpicto($langs->trans('HelpWithAI'), $langs->trans("YouCanMakeSomeInstructionForEmail"));
1428 $out .= '</td>';
1429
1430 $out .= '<td>';
1431 $out .= '<input type="text" class="quatrevingtpercent" id="ai_instructions" name="instruction" placeholder="'.$langs->trans("EnterYourAIPromptHere").'..." />';
1432 $out .= '<input id="generate_button" type="button" class="button smallpaddingimp" value="'.$langs->trans('Generate').'"/>';
1433 $out .= '<div id="ai_status_message" class="fieldrequired hideobject marginrightonly margintoponly">';
1434 $out .= '<i class="fa fa-spinner fa-spin fa-2x fa-fw valignmiddle marginrightonly"></i>'.$langs->trans("AIProcessingPleaseWait", getDolGlobalString('AI_API_SERVICE', 'chatgpt'));
1435 $out .= '</div>';
1436 $out .= "</td></tr>\n";
1437
1438 $out .= "<script type='text/javascript'>
1439 $(document).ready(function() {
1440 // for keydown
1441 $('#ai_instructions').keydown(function(event) {
1442 if (event.keyCode === 13) {
1443 event.preventDefault();
1444 $('#generate_button').click();
1445 }
1446 });
1447
1448 $('#generate_button').click(function() {
1449 console.log('We click on generate ai button');
1450
1451 var instructions = $('#ai_instructions').val();
1452 var timeoutfinished = 0;
1453 var apicallfinished = 0;
1454
1455 $('#ai_status_message').show();
1456 $('.icon-container .loader').show();
1457 setTimeout(function() {
1458 timeoutfinished = 1;
1459 if (apicallfinished) {
1460 $('#ai_status_message').hide();
1461 }
1462 }, 2000);
1463
1464 // set editor in readonly
1465 if (CKEDITOR.instances.".$htmlContent.") {
1466 CKEDITOR.instances.".$htmlContent.".setReadOnly(1);
1467 }
1468
1469
1470 $.ajax({
1471 url: '". DOL_URL_ROOT."/ai/ajax/generate_content.php?token=".currentToken()."',
1472 type: 'POST',
1473 contentType: 'application/json',
1474 data: JSON.stringify({
1475 'format': '".dol_escape_js($format)."', /* the format for output */
1476 'function': '".dol_escape_js($function)."', /* the AI feature to call */
1477 'instructions': instructions, /* the prompt string */
1478 }),
1479 success: function(response) {
1480 console.log('Add response into field \'".$htmlContent."\': '+response);
1481
1482 jQuery('#".$htmlContent."').val(response);
1483 //jQuery('#".$htmlContent."preview').val(response);
1484
1485 if (CKEDITOR.instances) {
1486 var editorInstance = CKEDITOR.instances.".$htmlContent.";
1487 if (editorInstance) {
1488 editorInstance.setReadOnly(0);
1489 editorInstance.setData(response);
1490 }
1491 //var editorInstancepreview = CKEDITOR.instances.".$htmlContent."preview;
1492 //if (editorInstancepreview) {
1493 // editorInstancepreview.setData(response);
1494 //}
1495 }
1496
1497 // remove readonly
1498 $('#ai_instructions').val('');
1499
1500 apicallfinished = 1;
1501 if (timeoutfinished) {
1502 $('#ai_status_message').hide();
1503 }
1504 },
1505 error: function(xhr, status, error) {
1506 alert(error);
1507 console.error('error ajax', status, error);
1508 $('#ai_status_message').hide();
1509 }
1510
1511 });
1512 });
1513 });
1514 </script>
1515 ";
1516 return $out;
1517 }
1518
1525 public function getModelEmailTemplate($htmlContent = 'message')
1526 {
1527 require_once DOL_DOCUMENT_ROOT.'/core/lib/emaillayout.lib.php';
1528
1529 $out = '<div id="template-selector" class="template-container hidden">';
1530 $templates = array(
1531 'empty' => 'empty',
1532 'basic' => 'basic',
1533 );
1534 //if (getDolGlobalInt('MAIN_FEATURES_LEVEL') > 1) {
1535 $templates['news'] = 'news';
1536 $templates['commerce'] = 'commerce';
1537 //$templates['text'] = 'text';
1538 //}
1539
1540 foreach ($templates as $template => $templateFunction) {
1541 $contentHtml = getHtmlOfLayout($template);
1542
1543 $out .= '<div class="template-option" data-template="'.$template.'" data-content="'.htmlentities($contentHtml).'">';
1544 $out .= '<img class="maillayout" alt="'.$template.'" src="'.DOL_URL_ROOT.'/theme/common/maillayout/'.$template.'.png" />';
1545 $out .= '<span class="template-option-text">'.ucfirst($template).'</span>';
1546 $out .= '</div>';
1547 }
1548 $out .= '</div>';
1549
1550 $out .= '<script type="text/javascript">
1551 $(document).ready(function() {
1552 $(".template-option").click(function() {
1553 var template = $(this).data("template");
1554
1555 console.log("We choose a layout for email template "+template);
1556
1557 $(".template-option").removeClass("selected");
1558 $(this).addClass("selected");
1559
1560 var contentHtml = $(this).data("content");
1561
1562 jQuery("#'.$htmlContent.'").val(contentHtml);
1563 var editorInstance = CKEDITOR.instances.'.$htmlContent.';
1564 if (editorInstance) {
1565 editorInstance.setData(contentHtml);
1566 }
1567 });
1568 });
1569 </script>';
1570
1571 return $out;
1572 }
1573
1591 public function getEMailTemplate($dbs, $type_template, $user, $outputlangs, $id = 0, $active = 1, $label = '', $defaultfortype = -1)
1592 {
1593 global $conf;
1594
1595 if ($id == -2 && empty($label)) {
1596 $this->error = 'LabelIsMandatoryWhenIdIs-2or-3';
1597 return -1;
1598 }
1599
1600 $ret = new ModelMail($dbs);
1601
1602 $languagetosearch = (is_object($outputlangs) ? $outputlangs->defaultlang : '');
1603 // Define $languagetosearchmain to fall back on main language (for example to get 'es_ES' for 'es_MX')
1604 $tmparray = explode('_', $languagetosearch);
1605 $languagetosearchmain = $tmparray[0].'_'.strtoupper($tmparray[0]);
1606 if ($languagetosearchmain == $languagetosearch) {
1607 $languagetosearchmain = '';
1608 }
1609
1610 $sql = "SELECT rowid, entity, module, label, type_template, topic, email_from, joinfiles, content, content_lines, lang, email_from, email_to, email_tocc, email_tobcc";
1611 $sql .= " FROM ".$dbs->prefix().'c_email_templates';
1612 $sql .= " WHERE (type_template = '".$dbs->escape($type_template)."' OR type_template = 'all')";
1613 $sql .= " AND entity IN (".getEntity('c_email_templates').")";
1614 $sql .= " AND (private = 0 OR fk_user = ".((int) $user->id).")"; // Get all public or private owned
1615 if ($active >= 0) {
1616 $sql .= " AND active = ".((int) $active);
1617 }
1618 if ($defaultfortype >= 0) {
1619 $sql .= " AND defaultfortype = ".((int) $defaultfortype);
1620 }
1621 if ($label) {
1622 $sql .= " AND label = '".$dbs->escape($label)."'";
1623 }
1624 if (!($id > 0) && $languagetosearch) {
1625 $sql .= " AND (lang = '".$dbs->escape($languagetosearch)."'".($languagetosearchmain ? " OR lang = '".$dbs->escape($languagetosearchmain)."'" : "")." OR lang IS NULL OR lang = '')";
1626 }
1627 if ($id > 0) {
1628 $sql .= " AND rowid = ".(int) $id;
1629 }
1630 if ($id == -1) {
1631 $sql .= " AND position = 0";
1632 }
1633 $sql .= " AND entity IN(".getEntity('c_email_templates', 1).")";
1634 if ($languagetosearch) {
1635 $sql .= $dbs->order("position,lang,label", "ASC,DESC,ASC"); // We want line with lang set first, then with lang null or ''
1636 } else {
1637 $sql .= $dbs->order("position,lang,label", "ASC,ASC,ASC"); // If no language provided, we give priority to lang not defined
1638 }
1639 //$sql .= $dbs->plimit(1);
1640 //print $sql;
1641
1642 $resql = $dbs->query($sql);
1643 if (!$resql) {
1644 dol_print_error($dbs);
1645 return -1;
1646 }
1647
1648 // Get first found
1649 while (1) {
1650 $obj = $dbs->fetch_object($resql);
1651
1652 if ($obj) {
1653 // If template is for a module, check module is enabled; if not, take next template
1654 if ($obj->module) {
1655 $tempmodulekey = $obj->module;
1656 if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1657 continue;
1658 }
1659 }
1660
1661 // If a record was found
1662 $ret->id = $obj->rowid;
1663 $ret->module = $obj->module;
1664 $ret->label = $obj->label;
1665 $ret->lang = $obj->lang;
1666 $ret->topic = $obj->topic;
1667 $ret->content = $obj->content;
1668 $ret->content_lines = $obj->content_lines;
1669 $ret->joinfiles = $obj->joinfiles;
1670 $ret->email_from = $obj->email_from;
1671
1672 break;
1673 } else {
1674 // If no record found
1675 if ($id == -2) {
1676 // Not found with the provided label
1677 return -1;
1678 } else {
1679 // If there is no template at all
1680 $defaultmessage = '';
1681
1682 if ($type_template == 'body') {
1683 // Special case to use this->withbody as content
1684 $defaultmessage = $this->withbody;
1685 } elseif ($type_template == 'facture_send') {
1686 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoice");
1687 } elseif ($type_template == 'facture_relance') {
1688 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoiceReminder");
1689 } elseif ($type_template == 'propal_send') {
1690 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendProposal");
1691 } elseif ($type_template == 'supplier_proposal_send') {
1692 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierProposal");
1693 } elseif ($type_template == 'order_send') {
1694 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendOrder");
1695 } elseif ($type_template == 'order_supplier_send') {
1696 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder");
1697 } elseif ($type_template == 'invoice_supplier_send') {
1698 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice");
1699 } elseif ($type_template == 'shipping_send') {
1700 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendShipping");
1701 } elseif ($type_template == 'fichinter_send') {
1702 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendFichInter");
1703 } elseif ($type_template == 'actioncomm_send') {
1704 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendActionComm");
1705 } elseif (!empty($type_template)) {
1706 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentGeneric");
1707 }
1708
1709 $ret->label = 'default';
1710 $ret->lang = $outputlangs->defaultlang;
1711 $ret->topic = '';
1712 $ret->joinfiles = 1;
1713 $ret->content = $defaultmessage;
1714 $ret->content_lines = '';
1715
1716 break;
1717 }
1718 }
1719 }
1720
1721 $dbs->free($resql);
1722
1723 return $ret;
1724 }
1725
1735 public function isEMailTemplate($type_template, $user, $outputlangs)
1736 {
1737 $sql = "SELECT label, topic, content, lang";
1738 $sql .= " FROM ".$this->db->prefix().'c_email_templates';
1739 $sql .= " WHERE type_template='".$this->db->escape($type_template)."'";
1740 $sql .= " AND entity IN (".getEntity('c_email_templates').")";
1741 $sql .= " AND (fk_user is NULL or fk_user = 0 or fk_user = ".((int) $user->id).")";
1742 if (is_object($outputlangs)) {
1743 $sql .= " AND (lang = '".$this->db->escape($outputlangs->defaultlang)."' OR lang IS NULL OR lang = '')";
1744 }
1745 $sql .= $this->db->order("lang,label", "ASC");
1746 //print $sql;
1747
1748 $resql = $this->db->query($sql);
1749 if ($resql) {
1750 $num = $this->db->num_rows($resql);
1751 $this->db->free($resql);
1752 return $num;
1753 } else {
1754 $this->error = get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1755 return -1;
1756 }
1757 }
1758
1769 public function fetchAllEMailTemplate($type_template, $user, $outputlangs, $active = 1)
1770 {
1771 global $db, $conf;
1772
1773 $sql = "SELECT rowid, module, label, topic, content, content_lines, lang, fk_user, private, position";
1774 $sql .= " FROM ".$this->db->prefix().'c_email_templates';
1775 $sql .= " WHERE type_template IN ('".$this->db->escape($type_template)."', 'all')";
1776 $sql .= " AND entity IN (".getEntity('c_email_templates').")";
1777 $sql .= " AND (private = 0 OR fk_user = ".((int) $user->id).")"; // See all public templates or templates I own.
1778 if ($active >= 0) {
1779 $sql .= " AND active = ".((int) $active);
1780 }
1781 //if (is_object($outputlangs)) $sql.= " AND (lang = '".$this->db->escape($outputlangs->defaultlang)."' OR lang IS NULL OR lang = '')"; // Return all languages
1782 $sql .= $this->db->order("position,lang,label", "ASC");
1783 //print $sql;
1784
1785 $resql = $this->db->query($sql);
1786 if ($resql) {
1787 $num = $this->db->num_rows($resql);
1788 $this->lines_model = array();
1789 while ($obj = $this->db->fetch_object($resql)) {
1790 // If template is for a module, check module is enabled.
1791 if ($obj->module) {
1792 $tempmodulekey = $obj->module;
1793 if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1794 continue;
1795 }
1796 }
1797
1798 $line = new ModelMail($db);
1799 $line->id = $obj->rowid;
1800 $line->label = $obj->label;
1801 $line->lang = $obj->lang;
1802 $line->fk_user = $obj->fk_user;
1803 $line->private = $obj->private;
1804 $line->position = $obj->position;
1805 $line->topic = $obj->topic;
1806 $line->content = $obj->content;
1807 $line->content_lines = $obj->content_lines;
1808
1809 $this->lines_model[] = $line;
1810 }
1811 $this->db->free($resql);
1812 return $num;
1813 } else {
1814 $this->error = get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1815 return -1;
1816 }
1817 }
1818
1819
1820
1829 public function setSubstitFromObject($object, $outputlangs)
1830 {
1831 global $extrafields;
1832
1833 $parameters = array();
1834 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1835 complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
1836
1837 $this->substit = $tmparray;
1838
1839 // Fill substit_lines with each object lines content
1840 if (is_array($object->lines)) {
1841 foreach ($object->lines as $line) {
1842 $substit_line = array(
1843 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
1844 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
1845 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
1846 '__LABEL__' => isset($line->label) ? $line->label : '',
1847 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
1848 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', 0, $outputlangs),
1849 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', 0, $outputlangs),
1850 '__QUANTITY__' => $line->qty,
1851 '__SUBPRICE__' => price($line->subprice),
1852 '__AMOUNT__' => price($line->total_ttc),
1853 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
1854 );
1855
1856 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
1857 if (!empty($line->fk_product)) {
1858 if (!is_object($extrafields)) {
1859 $extrafields = new ExtraFields($this->db);
1860 }
1861 $product = new Product($this->db);
1862 $product->fetch($line->fk_product, '', '', 1);
1863 $product->fetch_optionals();
1864
1865 $extrafields->fetch_name_optionals_label($product->table_element, true);
1866
1867 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
1868 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
1869 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
1870 }
1871 }
1872 }
1873 $this->substit_lines[] = $substit_line;
1874 }
1875 }
1876 }
1877
1886 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
1887 {
1888 global $langs;
1889
1890 $tmparray = array();
1891 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
1892 $parameters = array('mode' => $mode);
1893 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
1894 complete_substitutions_array($tmparray, $langs, null, $parameters);
1895
1896 if ($mode == 'formwithlines') {
1897 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
1898 }
1899 if ($mode == 'formforlines') {
1900 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
1901 }
1902 }
1903
1904 if ($mode == 'emailing') {
1905 $parameters = array('mode' => $mode);
1906 $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
1907 complete_substitutions_array($tmparray, $langs, null, $parameters);
1908
1909 // For mass emailing, we have different keys specific to the data into tagerts list
1910 $tmparray['__ID__'] = 'IdRecord';
1911 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode';
1912 $tmparray['__EMAIL__'] = 'EMailRecipient';
1913 $tmparray['__LASTNAME__'] = 'Lastname';
1914 $tmparray['__FIRSTNAME__'] = 'Firstname';
1915 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
1916 $tmparray['__OTHER1__'] = 'Other1';
1917 $tmparray['__OTHER2__'] = 'Other2';
1918 $tmparray['__OTHER3__'] = 'Other3';
1919 $tmparray['__OTHER4__'] = 'Other4';
1920 $tmparray['__OTHER5__'] = 'Other5';
1921 $tmparray['__CHECK_READ__'] = $langs->trans('TagCheckMail');
1922 $tmparray['__UNSUBSCRIBE__'] = $langs->trans('TagUnsubscribe');
1923 $tmparray['__UNSUBSCRIBE_URL__'] = $langs->trans('TagUnsubscribe').' (URL)';
1924
1925 $onlinepaymentenabled = 0;
1926 if (isModEnabled('paypal')) {
1927 $onlinepaymentenabled++;
1928 }
1929 if (isModEnabled('paybox')) {
1930 $onlinepaymentenabled++;
1931 }
1932 if (isModEnabled('stripe')) {
1933 $onlinepaymentenabled++;
1934 }
1935 if ($onlinepaymentenabled && getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
1936 $tmparray['__SECUREKEYPAYMENT__'] = getDolGlobalString('PAYMENT_SECURITY_TOKEN');
1937 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
1938 if (isModEnabled('member')) {
1939 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
1940 }
1941 if (isModEnabled('don')) {
1942 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
1943 }
1944 if (isModEnabled('invoice')) {
1945 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
1946 }
1947 if (isModEnabled('order')) {
1948 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
1949 }
1950 if (isModEnabled('contract')) {
1951 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
1952 }
1953
1954 //Online payment link
1955 if (isModEnabled('member')) {
1956 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
1957 }
1958 if (isModEnabled('don')) {
1959 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
1960 }
1961 if (isModEnabled('invoice')) {
1962 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
1963 }
1964 if (isModEnabled('order')) {
1965 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
1966 }
1967 if (isModEnabled('contract')) {
1968 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
1969 }
1970 }
1971 } else {
1972 /* No need to show into tooltip help, option is not enabled
1973 $vars['__SECUREKEYPAYMENT__']='';
1974 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
1975 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
1976 $vars['__SECUREKEYPAYMENT_ORDER__']='';
1977 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
1978 */
1979 }
1980 if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) {
1981 $tmparray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
1982 }
1983 }
1984
1985 foreach ($tmparray as $key => $val) {
1986 if (empty($val)) {
1987 $tmparray[$key] = $key;
1988 }
1989 }
1990
1991 return $tmparray;
1992 }
1993}
1994
1995
1996require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
1997
2003class ModelMail extends CommonObject
2004{
2008 public $element = 'email_template';
2009
2013 public $table_element = 'c_email_templates';
2014
2015
2016 // BEGIN MODULEBUILDER PROPERTIES
2020 public $fields=array(
2021 "rowid" => array("type"=>"integer", "label"=>"TechnicalID", "enabled"=>"1", 'position'=>10, 'notnull'=>1, "visible"=>"-1",),
2022 "module" => array("type"=>"varchar(32)", "label"=>"Module", "enabled"=>"1", 'position'=>20, 'notnull'=>0, "visible"=>"-1",),
2023 "type_template" => array("type"=>"varchar(32)", "label"=>"Typetemplate", "enabled"=>"1", 'position'=>25, 'notnull'=>0, "visible"=>"-1",),
2024 "lang" => array("type"=>"varchar(6)", "label"=>"Lang", "enabled"=>"1", 'position'=>30, 'notnull'=>0, "visible"=>"-1",),
2025 "private" => array("type"=>"smallint(6)", "label"=>"Private", "enabled"=>"1", 'position'=>35, 'notnull'=>1, "visible"=>"-1",),
2026 "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",),
2027 "datec" => array("type"=>"datetime", "label"=>"DateCreation", "enabled"=>"1", 'position'=>45, 'notnull'=>0, "visible"=>"-1",),
2028 "tms" => array("type"=>"timestamp", "label"=>"DateModification", "enabled"=>"1", 'position'=>50, 'notnull'=>1, "visible"=>"-1",),
2029 "label" => array("type"=>"varchar(255)", "label"=>"Label", "enabled"=>"1", 'position'=>55, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1", "css"=>"minwidth300", "cssview"=>"wordbreak", "csslist"=>"tdoverflowmax150",),
2030 "position" => array("type"=>"smallint(6)", "label"=>"Position", "enabled"=>"1", 'position'=>60, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2031 "active" => array("type"=>"integer", "label"=>"Active", "enabled"=>"1", 'position'=>65, 'notnull'=>1, "visible"=>"-1", "alwayseditable"=>"1",),
2032 "topic" => array("type"=>"text", "label"=>"Topic", "enabled"=>"1", 'position'=>70, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2033 "content" => array("type"=>"mediumtext", "label"=>"Content", "enabled"=>"1", 'position'=>75, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2034 "content_lines" => array("type"=>"text", "label"=>"Contentlines", "enabled"=>"1", 'position'=>80, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2035 "enabled" => array("type"=>"varchar(255)", "label"=>"Enabled", "enabled"=>"1", 'position'=>85, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2036 "joinfiles" => array("type"=>"varchar(255)", "label"=>"Joinfiles", "enabled"=>"1", 'position'=>90, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2037 "email_from" => array("type"=>"varchar(255)", "label"=>"Emailfrom", "enabled"=>"1", 'position'=>95, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2038 "email_to" => array("type"=>"varchar(255)", "label"=>"Emailto", "enabled"=>"1", 'position'=>100, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2039 "email_tocc" => array("type"=>"varchar(255)", "label"=>"Emailtocc", "enabled"=>"1", 'position'=>105, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2040 "email_tobcc" => array("type"=>"varchar(255)", "label"=>"Emailtobcc", "enabled"=>"1", 'position'=>110, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2041 "defaultfortype" => array("type"=>"smallint(6)", "label"=>"Defaultfortype", "enabled"=>"1", 'position'=>115, 'notnull'=>0, "visible"=>"-1", "alwayseditable"=>"1",),
2042 );
2043 public $rowid;
2044 public $type_template;
2045 public $datec;
2046 public $tms;
2047 public $active;
2048 public $enabled;
2049 public $defaultfortype;
2050
2054 public $id;
2055
2059 public $label;
2060
2064 public $fk_user;
2065
2069 public $private;
2070
2074 public $topic;
2075
2079 public $content;
2080 public $content_lines;
2081 public $lang;
2082 public $joinfiles;
2083
2084 public $email_from;
2085 public $email_to;
2086 public $email_tocc;
2087 public $email_tobcc;
2088
2092 public $module;
2093
2097 public $position;
2098 // END MODULEBUILDER PROPERTIES
2099
2100
2101
2107 public function __construct(DoliDB $db)
2108 {
2109 global $langs;
2110
2111 $this->db = $db;
2112 $this->ismultientitymanaged = 0;
2113 $this->isextrafieldmanaged = 1;
2114
2115 if (!getDolGlobalInt('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid']) && !empty($this->fields['ref'])) {
2116 $this->fields['rowid']['visible'] = 0;
2117 }
2118 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
2119 $this->fields['entity']['enabled'] = 0;
2120 }
2121
2122 // Example to show how to set values of fields definition dynamically
2123 /*if ($user->hasRight('test', 'mailtemplate', 'read')) {
2124 $this->fields['myfield']['visible'] = 1;
2125 $this->fields['myfield']['noteditable'] = 0;
2126 }*/
2127
2128 // Unset fields that are disabled
2129 foreach ($this->fields as $key => $val) {
2130 if (isset($val['enabled']) && empty($val['enabled'])) {
2131 unset($this->fields[$key]);
2132 }
2133 }
2134
2135 // Translate some data of arrayofkeyval
2136 if (is_object($langs)) {
2137 foreach ($this->fields as $key => $val) {
2138 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
2139 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
2140 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
2141 }
2142 }
2143 }
2144 }
2145 }
2146
2147
2157 public function fetch($id, $ref = null, $noextrafields = 0, $nolines = 0)
2158 {
2159 $result = $this->fetchCommon($id, $ref, '', $noextrafields);
2160 if ($result > 0 && !empty($this->table_element_line) && empty($nolines)) {
2161 $this->fetchLines($noextrafields);
2162 }
2163 return $result;
2164 }
2165}
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.
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:2010