29 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
75 public $fromalsorobot;
144 public $withmaindocfile;
147 public $withfromreadonly;
148 public $withreplytoreadonly;
149 public $withtoreadonly;
150 public $withtoccreadonly;
151 public $withtocccreadonly;
152 public $withtopicreadonly;
153 public $withfilereadonly;
154 public $withdeliveryreceipt;
156 public $withfckeditor;
158 public $substit = array();
159 public $substit_lines = array();
160 public $param = array();
162 public $withtouser = array();
163 public $withtoccuser = array();
168 public $withoptiononeemailperrecipient;
184 $this->withtofree = 1;
186 $this->withtoccc = 0;
187 $this->witherrorsto = 0;
188 $this->withtopic = 1;
190 $this->withmaindocfile = 0;
193 $this->withfromreadonly = 1;
194 $this->withreplytoreadonly = 1;
195 $this->withtoreadonly = 0;
196 $this->withtoccreadonly = 0;
197 $this->withtocccreadonly = 0;
198 $this->witherrorstoreadonly = 0;
199 $this->withtopicreadonly = 0;
200 $this->withfilereadonly = 0;
201 $this->withbodyreadonly = 0;
202 $this->withdeliveryreceiptreadonly = 0;
203 $this->withfckeditor = -1;
216 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
219 $vardir = $conf->user->dir_output.
"/".$user->id;
220 $upload_dir = $vardir.
'/temp/';
221 if (is_dir($upload_dir)) {
225 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
226 unset($_SESSION[
"listofpaths".$keytoavoidconflict]);
227 unset($_SESSION[
"listofnames".$keytoavoidconflict]);
228 unset($_SESSION[
"listofmimes".$keytoavoidconflict]);
243 $listofpaths = array();
244 $listofnames = array();
245 $listofmimes = array();
248 $file = basename($path);
254 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
255 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
256 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
258 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
259 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
261 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
262 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
264 if (!in_array($file, $listofnames)) {
265 $listofpaths[] = $path;
266 $listofnames[] = $file;
267 $listofmimes[] = $type;
268 $_SESSION[
"listofpaths".$keytoavoidconflict] = join(
';', $listofpaths);
269 $_SESSION[
"listofnames".$keytoavoidconflict] = join(
';', $listofnames);
270 $_SESSION[
"listofmimes".$keytoavoidconflict] = join(
';', $listofmimes);
284 $listofpaths = array();
285 $listofnames = array();
286 $listofmimes = array();
288 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
289 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
290 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
292 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
293 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
295 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
296 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
298 if ($keytodelete >= 0) {
299 unset($listofpaths[$keytodelete]);
300 unset($listofnames[$keytodelete]);
301 unset($listofmimes[$keytodelete]);
302 $_SESSION[
"listofpaths".$keytoavoidconflict] = join(
';', $listofpaths);
303 $_SESSION[
"listofnames".$keytoavoidconflict] = join(
';', $listofnames);
304 $_SESSION[
"listofmimes".$keytoavoidconflict] = join(
';', $listofmimes);
318 $listofpaths = array();
319 $listofnames = array();
320 $listofmimes = array();
322 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
323 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
324 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
326 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
327 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
329 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
330 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
332 return array(
'paths'=>$listofpaths,
'names'=>$listofnames,
'mimes'=>$listofmimes);
346 public function show_form($addfileaction =
'addfile', $removefileaction =
'removefile')
349 print $this->
get_form($addfileaction, $removefileaction);
363 public function get_form($addfileaction =
'addfile', $removefileaction =
'removefile')
366 global $conf, $langs, $user, $hookmanager,
$form;
369 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
370 $formfile =
new Formfile($this->
db);
372 if (!is_object(
$form)) {
377 $langs->loadLangs(array(
'other',
'mails',
'members'));
380 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
385 $hookmanager->initHooks(array(
'formmail'));
388 'addfileaction' => $addfileaction,
389 'removefileaction'=> $removefileaction,
390 'trackid'=> $this->trackid
392 $reshook = $hookmanager->executeHooks(
'getFormMail', $parameters, $this);
394 if (!empty($reshook)) {
395 return $hookmanager->resPrint;
399 $disablebademails = 1;
402 $outputlangs = $langs;
404 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($this->param[
'langsmodels'])) {
405 $newlang = $this->param[
'langsmodels'];
407 if (!empty($newlang)) {
409 $outputlangs->setDefaultLang($newlang);
410 $outputlangs->load(
'other');
414 $arraydefaultmessage = -1;
415 if ($this->param[
'models'] !=
'none') {
417 if (array_key_exists(
'models_id', $this->param)) {
418 $model_id = $this->param[
"models_id"];
421 $arraydefaultmessage = $this->
getEMailTemplate($this->
db, $this->param[
"models"], $user, $outputlangs, $model_id);
425 $listofpaths = array();
426 $listofnames = array();
427 $listofmimes = array();
428 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
430 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
431 if (!empty($arraydefaultmessage->joinfiles) && !empty($this->param[
'fileinit']) && is_array($this->param[
'fileinit'])) {
432 foreach ($this->param[
'fileinit'] as $file) {
438 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
439 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
441 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
442 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
444 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
445 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
449 $out .=
"\n".
'<!-- Begin form mail type='.$this->param[
"models"].
' --><div id="mailformdiv"></div>'.
"\n";
450 if ($this->withform == 1) {
451 $out .=
'<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param[
"returnurl"].
'#formmail">'.
"\n";
453 $out .=
'<a id="formmail" name="formmail"></a>';
454 $out .=
'<input style="display:none" type="submit" id="sendmailhidden" name="sendmail">';
455 $out .=
'<input type="hidden" name="token" value="'.newToken().
'" />';
456 $out .=
'<input type="hidden" name="trackid" value="'.$this->trackid.
'" />';
457 $out .=
'<input type="hidden" name="inreplyto" value="'.$this->inreplyto.
'" />';
459 if (!empty($this->withfrom)) {
460 if (!empty($this->withfromreadonly)) {
461 $out .=
'<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.
'" />';
462 $out .=
'<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.
'" />';
465 foreach ($this->param as $key => $value) {
466 if (is_array($value)) {
467 $out .=
"<!-- param key=".$key.
" is array, we do not output input field for it -->\n";
469 $out .=
'<input type="hidden" id="'.$key.
'" name="'.$key.
'" value="'.$value.
'" />'.
"\n";
473 $modelmail_array = array();
474 if ($this->param[
'models'] !=
'none') {
480 foreach ($this->lines_model as $line) {
482 if (preg_match(
'/\((.*)\)/', $line->label, $reg)) {
483 $labeltouse = $langs->trans($reg[1]);
485 $labeltouse = $line->label;
491 $modelmail_array[$line->id] .=
' '.picto_from_langcode($line->lang);
493 if ($line->private) {
494 $modelmail_array[$line->id] .=
' - <span class="opacitymedium">'.dol_escape_htmltag($langs->trans(
"Private")).
'</span>';
500 if (count($modelmail_array) > 0) {
501 $model_mail_selected_id =
GETPOSTISSET(
'modelmailselected') ?
GETPOST(
'modelmailselected',
'int') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0);
504 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
506 $out .=
'<span class="opacitymedium">'.$langs->trans(
'SelectMailModel').
':</span> ';
508 $out .= $this->
selectarray(
'modelmailselected', $modelmail_array, $model_mail_selected_id, 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth100', 1,
'', 0, 1);
510 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
514 $out .=
'<input type="submit" class="button reposition smallpaddingimp" value="'.$langs->trans(
'Apply').
'" name="modelselected" id="modelselected">';
517 } elseif (!empty($this->param[
'models']) && in_array($this->param[
'models'], array(
518 'propal_send',
'order_send',
'facture_send',
519 'shipping_send',
'fichinter_send',
'supplier_proposal_send',
'order_supplier_send',
520 'invoice_supplier_send',
'thirdparty',
'contract',
'user',
'recruitmentcandidature_send',
'all'
523 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
524 $out .=
'<span class="opacitymedium">'.$langs->trans(
'SelectMailModel').
':</span> ';
525 $out .=
'<select name="modelmailselected" disabled="disabled"><option value="none">'.$langs->trans(
"NoTemplateDefined").
'</option></select>';
527 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
530 $out .=
'<input type="submit" class="button" value="'.$langs->trans(
'Apply').
'" name="modelselected" disabled="disabled" id="modelselected">';
534 $out .=
'<!-- No template available for $this->param["models"] = '.$this->param[
'models'].
' -->';
538 $out .=
'<table class="tableforemailform boxtablenotop centpercent">'.
"\n";
541 $helpforsubstitution =
'';
542 if (is_array($this->substit) && count($this->substit)) {
543 $helpforsubstitution .= $langs->trans(
'AvailableVariables').
' :<br>'.
"\n";
545 foreach ($this->substit as $key => $val) {
548 if (!empty($this->withsubstit)) {
549 $out .=
'<tr><td colspan="2" class="right">';
551 if (is_numeric($this->withsubstit)) {
552 $out .=
$form->textwithpicto($langs->trans(
"EMailTestSubstitutionReplacedByGenericValues"), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltip');
554 $out .=
$form->textwithpicto($langs->trans(
'AvailableVariables'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltip');
556 $out .=
"</td></tr>\n";
561 if (!empty($this->withfrom)) {
562 if (!empty($this->withfromreadonly)) {
563 $out .=
'<tr><td class="fieldrequired minwidth200">'.$langs->trans(
"MailFrom").
'</td><td>';
566 if (!($this->fromtype ===
'user' && $this->fromid > 0)
567 && !($this->fromtype ===
'company')
568 && !($this->fromtype ===
'robot')
569 && !preg_match(
'/user_aliases/', $this->fromtype)
570 && !preg_match(
'/global_aliases/', $this->fromtype)
571 && !preg_match(
'/senderprofile/', $this->fromtype)
574 $out .= $this->fromname;
575 if ($this->frommail) {
576 $out .=
' <'.$this->frommail.
'>';
578 if ($this->fromtype) {
579 $langs->load(
'errors');
580 $out .=
'<span class="warning"> <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'> </span>';
587 if (empty($user->email)) {
588 $langs->load(
'errors');
589 $liste[
'user'] = $user->getFullName($langs).
' <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'>';
591 $liste[
'user'] = $user->getFullName($langs).
' <'.$user->email.
'>';
595 if (!empty($conf->global->MAIN_INFO_SOCIETE_MAIL)) {
596 $liste[
'company'] = !empty($conf->global->MAIN_INFO_SOCIETE_NOM)?$conf->global->MAIN_INFO_SOCIETE_NOM:$conf->global->MAIN_INFO_SOCIETE_MAIL;
597 $liste[
'company'].=
' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.
'>';
601 $listaliases = array(
602 'user_aliases' => (empty($user->email_aliases) ?
'' : $user->email_aliases),
607 if (!empty($this->fromalsorobot)) {
609 $liste[
'robot'] = $conf->global->MAIN_MAIL_EMAIL_FROM;
610 if ($this->frommail) {
611 $liste[
'robot'] .=
' <'.$conf->global->MAIN_MAIL_EMAIL_FROM.
'>';
617 $sql =
"SELECT rowid, label, email FROM ".$this->db->prefix().
"c_email_senderprofile";
618 $sql .=
" WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).
")";
619 $sql .=
" ORDER BY position";
625 $obj = $this->
db->fetch_object(
$resql);
627 $listaliases[
'senderprofile_'.$obj->rowid] = $obj->label.
' <'.$obj->email.
'>';
635 foreach ($listaliases as $typealias => $listalias) {
637 $listaliasarray = explode(
',', $listalias);
638 foreach ($listaliasarray as $listaliasval) {
640 $listaliasval = trim($listaliasval);
642 $listaliasval = preg_replace(
'/</',
'<', $listaliasval);
643 $listaliasval = preg_replace(
'/>/',
'>', $listaliasval);
644 if (!preg_match(
'/</', $listaliasval)) {
645 $listaliasval =
'<'.$listaliasval.
'>';
647 $liste[$typealias.
'_'.$posalias] = $listaliasval;
654 $out .=
' '.$form->selectarray(
'fromtype', $liste, $this->fromtype, 0, 0, 0,
'', 0, 0, 0,
'',
'fromforsendingprofile maxwidth200onsmartphone', 0,
'', $disablebademails);
657 $out .=
"</td></tr>\n";
659 $out .=
'<tr><td class="fieldrequired width200">'.$langs->trans(
"MailFrom").
"</td><td>";
660 $out .= $langs->trans(
"Name").
':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.
'" />';
661 $out .=
' ';
662 $out .= $langs->trans(
"EMail").
':<<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.
'" />>';
663 $out .=
"</td></tr>\n";
668 if (!empty($this->withto) || is_array($this->withto)) {
673 if (!empty($this->withtouser) && is_array($this->withtouser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
675 $out .= $langs->trans(
"MailToUsers");
679 $tmparray = $this->withtouser;
680 foreach ($tmparray as $key => $val) {
683 $withtoselected =
GETPOST(
"receiveruser",
'array');
684 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
685 $withtoselected = array_keys($tmparray);
687 $out .=
$form->multiselectarray(
"receiveruser", $tmparray, $withtoselected,
null,
null,
'inline-block minwidth500',
null,
"");
688 $out .=
"</td></tr>\n";
692 if (!empty($this->withoptiononeemailperrecipient)) {
693 if (abs($this->withoptiononeemailperrecipient) == 1) {
694 $out .=
'<tr><td class="minwidth200">';
695 $out .= $langs->trans(
"GroupEmails");
697 $out .=
' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ?
' checked="checked"' :
'').
'> ';
698 $out .=
'<label for="oneemailperrecipient">'.$langs->trans(
"OneEmailPerRecipient").
'</label>';
699 $out .=
'<span class="hideonsmartphone opacitymedium">';
701 $out .= $langs->trans(
"WarningIfYouCheckOneRecipientPerEmail");
703 $out .=
'</td></tr>';
705 $out .=
'<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>';
710 if (!empty($this->withtocc) || is_array($this->withtocc)) {
715 if (!empty($this->withtoccuser) && is_array($this->withtoccuser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
717 $out .= $langs->trans(
"MailToCCUsers");
721 $tmparray = $this->withtoccuser;
722 foreach ($tmparray as $key => $val) {
725 $withtoselected =
GETPOST(
"receiverccuser",
'array');
726 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
727 $withtoselected = array_keys($tmparray);
729 $out .=
$form->multiselectarray(
"receiverccuser", $tmparray, $withtoselected,
null,
null,
'inline-block minwidth500',
null,
"");
730 $out .=
"</td></tr>\n";
734 if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
739 if (!empty($this->withreplyto)) {
740 if ($this->withreplytoreadonly) {
741 $out .=
'<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.
'" />';
742 $out .=
'<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.
'" />';
743 $out .=
"<tr><td>".$langs->trans(
"MailReply").
"</td><td>".$this->replytoname.($this->replytomail ? (
" <".$this->replytomail.
">") :
"");
744 $out .=
"</td></tr>\n";
749 if (!empty($this->witherrorsto)) {
754 if (!empty($this->withdeliveryreceipt) &&
getDolGlobalInt(
'MAIN_EMAIL_SUPPORT_ACK')) {
755 $out .= $this->getHtmlForDeliveryReceipt();
759 if (!empty($this->withtopic)) {
760 $out .= $this->
getHtmlForTopic($arraydefaultmessage, $helpforsubstitution);
764 if (!empty($this->withfile)) {
766 $out .=
'<td>'.$langs->trans(
"MailFile").
'</td>';
770 if ($this->withmaindocfile) {
773 $this->withmaindocfile = (
GETPOST(
'addmaindocfile',
'alpha') ? -1 : 1);
774 } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
776 $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
780 if (!empty($this->withmaindocfile)) {
781 if ($this->withmaindocfile == 1) {
782 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />';
783 } elseif ($this->withmaindocfile == -1) {
784 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />';
786 if (!empty($conf->global->MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND)) {
787 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDocOrLastGenerated").
'.</label><br>';
789 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDoc").
'.</label><br>';
793 if (is_numeric($this->withfile)) {
795 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
796 $out .=
'<script type="text/javascript">';
797 $out .=
'jQuery(document).ready(function () {';
798 $out .=
' jQuery(".removedfile").click(function() {';
799 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
802 $out .=
'</script>'.
"\n";
803 if (count($listofpaths)) {
804 foreach ($listofpaths as $key => $val) {
805 $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
807 if ($conf->entity > 1) {
808 $relativepathtofile = str_replace($conf->entity.
'/',
'', $relativepathtofile);
811 $formfile_params = array();
812 preg_match(
'#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params);
814 $out .=
'<div id="attachfile_'.$key.
'">';
816 $out .=
img_mime($listofnames[$key]).
' '.$listofnames[$key];
818 $out .= $formfile->showPreview(array(), $formfile_params[2], $formfile_params[4]);
819 if (!$this->withfilereadonly) {
820 $out .=
' <input type="image" style="border: 0px;" src="'.DOL_URL_ROOT.
'/theme/'.$conf->theme.
'/img/delete.png" value="'.($key + 1).
'" class="removedfile" id="removedfile_'.$key.
'" name="removedfile_'.$key.
'" />';
823 $out .=
'<br></div>';
825 } elseif (empty($this->withmaindocfile)) {
828 if ($this->withfile == 2) {
830 $maxmin = $maxfilesizearray[
'maxmin'];
832 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
835 if (empty($conf->global->FROM_MAIL_DONT_USE_INPUT_FILE_MULTIPLE)) {
836 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans(
"Upload").
'" multiple />';
838 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
841 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
844 $out .= $this->withfile;
847 $out .=
"</td></tr>\n";
851 if (!empty($this->withbody)) {
852 $defaultmessage =
GETPOST(
'message',
'restricthtml');
853 if (!
GETPOST(
'modelselected',
'alpha') ||
GETPOST(
'modelmailselected') !=
'-1') {
854 if ($arraydefaultmessage && $arraydefaultmessage->content) {
855 $defaultmessage = $arraydefaultmessage->content;
856 } elseif (!is_numeric($this->withbody)) {
857 $defaultmessage = $this->withbody;
863 $validpaymentmethod = array();
864 if (empty($this->substit[
'__REF__'])) {
868 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
869 $langs->loadLangs(array(
'paypal',
'other'));
870 $typeforonlinepayment =
'free';
871 if ($this->param[
"models"] ==
'order' || $this->param[
"models"] ==
'order_send') {
872 $typeforonlinepayment =
'order';
874 if ($this->param[
"models"] ==
'invoice' || $this->param[
"models"] ==
'facture_send') {
875 $typeforonlinepayment =
'invoice';
877 if ($this->param[
"models"] ==
'member') {
878 $typeforonlinepayment =
'member';
880 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit[
'__REF__']);
883 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
886 if (count($validpaymentmethod) > 0 && $paymenturl) {
887 $langs->load(
'other');
888 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace(
'\n',
"\n", $langs->transnoentities(
"PredefinedMailContentLink", $paymenturl));
889 $this->substit[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
891 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
892 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'';
895 $this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] =
'';
899 $defaultlines = $arraydefaultmessage->content_lines;
900 if (isset($defaultlines)) {
901 foreach ($this->substit_lines as $substit_line) {
905 $this->substit[
'__LINES__'] = $lines;
907 $defaultmessage = str_replace(
'\n',
"\n", $defaultmessage);
910 $atleastonecomponentishtml = 0;
911 if (strpos($defaultmessage,
'__USER_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__USER_SIGNATURE__'])) {
912 $atleastonecomponentishtml++;
914 if (strpos($defaultmessage,
'__SENDEREMAIL_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
915 $atleastonecomponentishtml++;
917 if (strpos($defaultmessage,
'__ONLINE_PAYMENT_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
918 $atleastonecomponentishtml++;
920 if (strpos($defaultmessage,
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
921 $atleastonecomponentishtml++;
924 $atleastonecomponentishtml++;
926 if ($atleastonecomponentishtml) {
928 $this->substit[
'__USER_SIGNATURE__'] =
dol_nl2br($this->substit[
'__USER_SIGNATURE__']);
930 if (!
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
931 $this->substit[
'__SENDEREMAIL_SIGNATURE__'] =
dol_nl2br($this->substit[
'__SENDEREMAIL_SIGNATURE__']);
933 if (!
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
934 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
dol_nl2br($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__']);
937 $defaultmessage =
dol_nl2br($defaultmessage);
942 $defaultmessage =
GETPOST(
"message",
"restricthtml");
946 $defaultmessage = preg_replace(
"/^(<br>)+/",
"", $defaultmessage);
947 $defaultmessage = preg_replace(
"/^\n+/",
"", $defaultmessage);
951 $out .=
'<td colspan="2">';
952 $out .=
$form->textwithpicto($langs->trans(
'MailText'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltipfrombody');
957 $out .=
'<td colspan="2">';
958 if ($this->withbodyreadonly) {
959 $out .= nl2br($defaultmessage);
960 $out .=
'<input type="hidden" id="message" name="message" value="'.$defaultmessage.
'" />';
962 if (!isset($this->ckeditortoolbar)) {
963 $this->ckeditortoolbar =
'dolibarr_mailings';
967 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
968 if ($this->withfckeditor == -1) {
969 if (!empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
970 $this->withfckeditor = 1;
972 $this->withfckeditor = 0;
976 $doleditor =
new DolEditor(
'message', $defaultmessage,
'', 280, $this->ckeditortoolbar,
'In',
true,
true, $this->withfckeditor, 8,
'95%');
977 $out .= $doleditor->Create(1);
979 $out .=
"</td></tr>\n";
982 $out .=
'</table>'.
"\n";
984 if ($this->withform == 1 || $this->withform == -1) {
985 $out .=
'<div class="center">';
986 $out .=
'<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans(
"SendMail").
'"';
988 if ($this->withfile == 2 && $conf->use_javascript_ajax) {
989 $out .=
' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans(
"FileWasNotUploaded")).
'\');
return false; }
else {
return true; }
"';
992 if ($this->withcancel) {
993 $out .= '<input class="button button-cancel
" type="submit
" id="cancel
" name="cancel
" value="'.$langs->trans("Cancel").'" />';
995 $out .= '</div>'."\n
";
998 if ($this->withform == 1) {
999 $out .= '</form>'."\n
";
1002 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1003 if (!empty($conf->global->MAIN_MAILFORM_DISABLE_ENTERKEY)) {
1004 $out .= '<script type="text/javascript
">';
1005 $out .= 'jQuery(document).ready(function () {';
1006 $out .= ' $(document).on("keypress
", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1007 var code = e.keyCode || e.which;
1009 console.log("Enter was intercepted and blocked
");
1015 $out .= '</script>';
1018 $out .= "<!-- End form mail -->\n
";
1029 public function getHtmlForTo()
1031 global $langs, $form;
1032 $out = '<tr><td class="fieldrequired
">';
1033 if ($this->withtofree) {
1034 $out .= $form->textwithpicto($langs->trans("MailTo
"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients
"));
1036 $out .= $langs->trans("MailTo
");
1038 $out .= '</td><td>';
1039 if ($this->withtoreadonly) {
1040 if (!empty($this->toname) && !empty($this->tomail)) {
1041 $out .= '<input type="hidden
" id="toname
" name="toname
" value="'.$this->toname.'" />';
1042 $out .= '<input type="hidden
" id="tomail
" name="tomail
" value="'.$this->tomail.'" />';
1043 if ($this->totype == 'thirdparty') {
1044 $soc = new Societe($this->db);
1045 $soc->fetch($this->toid);
1046 $out .= $soc->getNomUrl(1);
1047 } elseif ($this->totype == 'contact') {
1048 $contact = new Contact($this->db);
1049 $contact->fetch($this->toid);
1050 $out .= $contact->getNomUrl(1);
1052 $out .= $this->toname;
1054 $out .= ' <'.$this->tomail.'>';
1055 if ($this->withtofree) {
1056 $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) : "").'" />';
1059 // Note withto may be a text like 'AllRecipientSelected'
1060 $out .= (!is_array($this->withto) && !is_numeric($this->withto)) ? $this->withto : "";
1063 // The free input of email
1064 if (!empty($this->withtofree)) {
1065 $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) : "")).'" />';
1068 if (!empty($this->withto) && is_array($this->withto)) {
1069 if (!empty($this->withtofree)) {
1070 $out .= " ".$langs->trans("and
")."/
".$langs->trans("or
")." ";
1072 // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
1073 $tmparray = $this->withto;
1074 foreach ($tmparray as $key => $val) {
1075 $tmparray[$key] = str_replace(array('<', '>'), array('(', ')'), $tmparray[$key]);
1076 $tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
1079 $withtoselected = GETPOST("receiver
", 'array'); // Array of selected value
1081 if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') {
1082 $withtoselected = array_keys($tmparray);
1085 $out .= $form->multiselectarray("receiver
", $tmparray, $withtoselected, null, null, 'inline-block minwidth500', null, "");
1088 $out .= "</td></tr>\n
";
1097 public function getHtmlForCc()
1099 global $langs, $form;
1101 $out .= $form->textwithpicto($langs->trans("MailCC
"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients
"));
1102 $out .= '</td><td>';
1103 if ($this->withtoccreadonly) {
1104 $out .= (!is_array($this->withtocc) && !is_numeric($this->withtocc)) ? $this->withtocc : "";
1106 $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 : '')).'" />';
1107 if (!empty($this->withtocc) && is_array($this->withtocc)) {
1108 $out .= " ".$langs->trans("and
")."/
".$langs->trans("or
")." ";
1109 // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
1110 $tmparray = $this->withtocc;
1111 foreach ($tmparray as $key => $val) {
1112 $tmparray[$key] = str_replace(array('<', '>'), array('(', ')'), $tmparray[$key]);
1113 $tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
1115 $withtoccselected = GETPOST("receivercc
", 'array'); // Array of selected value
1116 $out .= $form->multiselectarray("receivercc
", $tmparray, $withtoccselected, null, null, 'inline-block minwidth500', null, "");
1119 $out .= "</td></tr>\n
";
1128 public function getHtmlForWithCcc()
1130 global $conf, $langs, $form;
1132 $out .= $form->textwithpicto($langs->trans("MailCCC
"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients
"));
1133 $out .= '</td><td>';
1134 if (!empty($this->withtocccreadonly)) {
1135 $out .= (!is_array($this->withtoccc) && !is_numeric($this->withtoccc)) ? $this->withtoccc : "";
1137 $out .= '<input class="minwidth200
" id="sendtoccc
" name="sendtoccc
" value="'.(GETPOSTISSET("sendtoccc") ? GETPOST("sendtoccc", "alpha") : ((!is_array($this->withtoccc) && !is_numeric($this->withtoccc)) ? $this->withtoccc : '')).'" />';
1138 if (!empty($this->withtoccc) && is_array($this->withtoccc)) {
1139 $out .= " ".$langs->trans("and
")."/
".$langs->trans("or
")." ";
1140 // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
1141 $tmparray = $this->withtoccc;
1142 foreach ($tmparray as $key => $val) {
1143 $tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
1145 $withtocccselected = GETPOST("receiverccc
", 'array'); // Array of selected value
1146 $out .= $form->multiselectarray("receiverccc
", $tmparray, $withtocccselected, null, null, null, null, "90%
");
1151 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) && !empty($this->param['models']) && $this->param['models'] == 'propal_send') {
1152 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO;
1154 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) && !empty($this->param['models']) && $this->param['models'] == 'order_send') {
1155 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO;
1157 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) && !empty($this->param['models']) && $this->param['models'] == 'facture_send') {
1158 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO;
1160 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) && !empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') {
1161 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO;
1163 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO) && !empty($this->param['models']) && $this->param['models'] == 'order_supplier_send') {
1164 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO;
1166 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO) && !empty($this->param['models']) && $this->param['models'] == 'invoice_supplier_send') {
1167 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO;
1169 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_PROJECT_TO) && !empty($this->param['models']) && $this->param['models'] == 'project') {
1170 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_PROJECT_TO;
1173 $out .= ' + '.$showinfobcc;
1175 $out .= "</td></tr>\n
";
1184 public function getHtmlForWithErrorsTo()
1186 global $conf, $langs;
1187 //if (! $this->errorstomail) $this->errorstomail=$this->frommail;
1188 $errorstomail = getDolGlobalString('MAIN_MAIL_ERRORS_TO', (!empty($this->errorstomail) ? $this->errorstomail : ''));
1189 if ($this->witherrorstoreadonly) {
1190 $out = '<tr><td>'.$langs->trans("MailErrorsTo
").'</td><td>';
1191 $out .= '<input type="hidden
" id="errorstomail
" name="errorstomail
" value="'.$errorstomail.'" />';
1192 $out .= $errorstomail;
1193 $out .= "</td></tr>\n
";
1195 $out = '<tr><td>'.$langs->trans("MailErrorsTo
").'</td><td>';
1196 $out .= '<input class="minwidth200
" id="errorstomail
" name="errorstomail
" value="'.$errorstomail.'" />';
1197 $out .= "</td></tr>\n
";
1207 public function getHtmlForDeliveryreceipt()
1209 global $conf, $langs;
1210 $out = '<tr><td><label for="deliveryreceipt
">'.$langs->trans("DeliveryReceipt
").'</label></td><td>';
1212 if (!empty($this->withdeliveryreceiptreadonly)) {
1213 $out .= yn($this->withdeliveryreceipt);
1215 $defaultvaluefordeliveryreceipt = 0;
1216 if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_PROPAL) && !empty($this->param['models']) && $this->param['models'] == 'propal_send') {
1217 $defaultvaluefordeliveryreceipt = 1;
1219 if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_PROPOSAL) && !empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') {
1220 $defaultvaluefordeliveryreceipt = 1;
1222 if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_ORDER) && !empty($this->param['models']) && $this->param['models'] == 'order_send') {
1223 $defaultvaluefordeliveryreceipt = 1;
1225 if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_INVOICE) && !empty($this->param['models']) && $this->param['models'] == 'facture_send') {
1226 $defaultvaluefordeliveryreceipt = 1;
1228 if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_ORDER) && !empty($this->param['models']) && $this->param['models'] == 'order_supplier_send') {
1229 $defaultvaluefordeliveryreceipt = 1;
1231 //$out .= $form->selectyesno('deliveryreceipt', (GETPOSTISSET("deliveryreceipt
") ? GETPOST("deliveryreceipt
") : $defaultvaluefordeliveryreceipt), 1);
1232 $out .= '<input type="checkbox
" id="deliveryreceipt
" name="deliveryreceipt
" value="1
"'.((GETPOSTISSET("deliveryreceipt
") ? GETPOST("deliveryreceipt
") : $defaultvaluefordeliveryreceipt) ? ' checked="checked
"' : '').'>';
1234 $out .= "</td></tr>\n
";
1245 public function getHtmlForTopic($arraydefaultmessage, $helpforsubstitution)
1247 global $conf, $langs, $form;
1249 $defaulttopic = GETPOST('subject', 'restricthtml');
1251 if (!GETPOST('modelselected', 'alpha') || GETPOST('modelmailselected') != '-1') {
1252 if ($arraydefaultmessage && $arraydefaultmessage->topic) {
1253 $defaulttopic = $arraydefaultmessage->topic;
1254 } elseif (!is_numeric($this->withtopic)) {
1255 $defaulttopic = $this->withtopic;
1259 $defaulttopic = make_substitutions($defaulttopic, $this->substit);
1262 $out .= '<td class="fieldrequired
">';
1263 $out .= $form->textwithpicto($langs->trans('MailTopic'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltipfromtopic');
1266 if ($this->withtopicreadonly) {
1267 $out .= $defaulttopic;
1268 $out .= '<input type="hidden
" class="quatrevingtpercent
" id="subject
" name="subject
" value="'.$defaulttopic.'" />';
1270 $out .= '<input type="text
" class="quatrevingtpercent
" id="subject
" name="subject
" value="'.((GETPOSTISSET("subject") && !GETPOST('modelselected
')) ? GETPOST("subject") : ($defaulttopic ? $defaulttopic : '')).'" />';
1272 $out .= "</td></tr>\n
";
1289 public function getEMailTemplate($dbs, $type_template, $user, $outputlangs, $id = 0, $active = 1, $label = '')
1291 global $conf, $langs;
1293 $ret = new ModelMail();
1295 if ($id == -2 && empty($label)) {
1296 $this->error = 'LabelIsMandatoryWhenIdIs-2';
1300 $languagetosearch = (is_object($outputlangs) ? $outputlangs->defaultlang : '');
1301 // Define $languagetosearchmain to fall back on main language (for example to get 'es_ES' for 'es_MX')
1302 $tmparray = explode('_', $languagetosearch);
1303 $languagetosearchmain = $tmparray[0].'_'.strtoupper($tmparray[0]);
1304 if ($languagetosearchmain == $languagetosearch) {
1305 $languagetosearchmain = '';
1308 $sql = "SELECT
rowid, module, label, type_template, topic, joinfiles, content, content_lines, lang, email_from, email_to, email_tocc, email_tobcc
";
1309 $sql .= " FROM
".$dbs->prefix().'c_email_templates';
1310 $sql .= " WHERE (type_template =
'".$dbs->escape($type_template)."' OR type_template =
'all')
";
1311 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1312 $sql .= " AND (
private = 0 OR fk_user =
".((int) $user->id).")
"; // Get all public or private owned
1314 $sql .= " AND active =
".((int) $active);
1317 $sql .= " AND label =
'".$dbs->escape($label)."'";
1319 if (!($id > 0) && $languagetosearch) {
1320 $sql .= " AND (lang =
'".$dbs->escape($languagetosearch)."'".($languagetosearchmain ? " OR lang =
'".$dbs->escape($languagetosearchmain)."'" : "")." OR lang IS NULL OR lang =
'')
";
1323 $sql .= " AND
rowid=
".(int) $id;
1326 $sql .= " AND position=0
";
1328 if ($languagetosearch) {
1329 $sql .= $dbs->order("position,lang,label
", "ASC,DESC,ASC
"); // We want line with lang set first, then with lang null or ''
1331 $sql .= $dbs->order("position,lang,label
", "ASC,ASC,ASC
"); // If no language provided, we give priority to lang not defined
1333 //$sql .= $dbs->plimit(1);
1336 $resql = $dbs->query($sql);
1338 dol_print_error($dbs);
1344 $obj = $dbs->fetch_object($resql);
1347 // If template is for a module, check module is enabled; if not, take next template
1349 $tempmodulekey = $obj->module;
1350 if (empty($conf->$tempmodulekey) || empty($conf->$tempmodulekey->enabled)) {
1355 // If a record was found
1356 $ret->id = $obj->rowid;
1357 $ret->module = $obj->module;
1358 $ret->label = $obj->label;
1359 $ret->lang = $obj->lang;
1360 $ret->topic = $obj->topic;
1361 $ret->content = $obj->content;
1362 $ret->content_lines = $obj->content_lines;
1363 $ret->joinfiles = $obj->joinfiles;
1367 // If no record found
1369 // Not found with the provided label
1372 // If there is no template at all
1373 $defaultmessage = '';
1375 if ($type_template == 'body') {
1376 // Special case to use this->withbody as content
1377 $defaultmessage = $this->withbody;
1378 } elseif ($type_template == 'facture_send') {
1379 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoice
");
1380 } elseif ($type_template == 'facture_relance') {
1381 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoiceReminder
");
1382 } elseif ($type_template == 'propal_send') {
1383 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendProposal
");
1384 } elseif ($type_template == 'supplier_proposal_send') {
1385 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierProposal
");
1386 } elseif ($type_template == 'order_send') {
1387 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendOrder
");
1388 } elseif ($type_template == 'order_supplier_send') {
1389 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder
");
1390 } elseif ($type_template == 'invoice_supplier_send') {
1391 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice
");
1392 } elseif ($type_template == 'shipping_send') {
1393 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendShipping
");
1394 } elseif ($type_template == 'fichinter_send') {
1395 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendFichInter
");
1396 } elseif ($type_template == 'actioncomm_send') {
1397 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendActionComm
");
1398 } elseif (!empty($type_template)) {
1399 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentGeneric
");
1402 $ret->label = 'default';
1403 $ret->lang = $outputlangs->defaultlang;
1405 $ret->joinfiles = 1;
1406 $ret->content = $defaultmessage;
1407 $ret->content_lines = '';
1428 public function isEMailTemplate($type_template, $user, $outputlangs)
1430 $sql = "SELECT label, topic, content, lang
";
1431 $sql .= " FROM
".$this->db->prefix().'c_email_templates';
1432 $sql .= " WHERE type_template=
'".$this->db->escape($type_template)."'";
1433 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1434 $sql .= " AND (fk_user is NULL or fk_user = 0 or fk_user =
".((int) $user->id).")
";
1435 if (is_object($outputlangs)) {
1436 $sql .= " AND (lang =
'".$this->db->escape($outputlangs->defaultlang)."' OR lang IS NULL OR lang =
'')
";
1438 $sql .= $this->db->order("lang,label
", "ASC
");
1441 $resql = $this->db->query($sql);
1443 $num = $this->db->num_rows($resql);
1444 $this->db->free($resql);
1447 $this->error = get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1462 public function fetchAllEMailTemplate($type_template, $user, $outputlangs, $active = 1)
1466 $sql = "SELECT
rowid, module, label, topic, content, content_lines, lang, fk_user,
private, position
";
1467 $sql .= " FROM
".$this->db->prefix().'c_email_templates';
1468 $sql .= " WHERE type_template IN (
'".$this->db->escape($type_template)."',
'all')
";
1469 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1470 $sql .= " AND (
private = 0 OR fk_user =
".((int) $user->id).")
"; // See all public templates or templates I own.
1472 $sql .= " AND active =
".((int) $active);
1474 //if (is_object($outputlangs)) $sql.= " AND (lang =
'".$this->db->escape($outputlangs->defaultlang)."' OR lang IS NULL OR lang =
'')
"; // Return all languages
1475 $sql .= $this->db->order("position,lang,label
", "ASC
");
1478 $resql = $this->db->query($sql);
1480 $num = $this->db->num_rows($resql);
1481 $this->lines_model = array();
1482 while ($obj = $this->db->fetch_object($resql)) {
1483 // If template is for a module, check module is enabled.
1485 $tempmodulekey = $obj->module;
1486 if (empty($conf->$tempmodulekey) || empty($conf->$tempmodulekey->enabled)) {
1491 $line = new ModelMail();
1492 $line->id = $obj->rowid;
1493 $line->label = $obj->label;
1494 $line->lang = $obj->lang;
1495 $line->fk_user = $obj->fk_user;
1496 $line->private = $obj->private;
1497 $line->position = $obj->position;
1498 $line->topic = $obj->topic;
1499 $line->content = $obj->content;
1500 $line->content_lines = $obj->content_lines;
1502 $this->lines_model[] = $line;
1504 $this->db->free($resql);
1507 $this->error = get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1522 public function setSubstitFromObject($object, $outputlangs)
1524 global $conf, $user, $extrafields;
1526 $parameters = array();
1527 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1528 complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
1530 $this->substit = $tmparray;
1532 // Fill substit_lines with each object lines content
1533 if (is_array($object->lines)) {
1534 foreach ($object->lines as $line) {
1535 $substit_line = array(
1536 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
1537 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
1538 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
1539 '__LABEL__' => isset($line->label) ? $line->label : '',
1540 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
1541 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', 0, $outputlangs),
1542 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', 0, $outputlangs),
1543 '__QUANTITY__' => $line->qty,
1544 '__SUBPRICE__' => price($line->subprice),
1545 '__AMOUNT__' => price($line->total_ttc),
1546 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
1549 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
1550 if (!empty($line->fk_product)) {
1551 if (!is_object($extrafields)) {
1552 $extrafields = new ExtraFields($this->db);
1554 $product = new Product($this->db);
1555 $product->fetch($line->fk_product, '', '', 1);
1556 $product->fetch_optionals();
1558 $extrafields->fetch_name_optionals_label($product->table_element, true);
1560 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
1561 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
1562 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
1566 $this->substit_lines[] = $substit_line;
1579 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
1581 global $conf, $langs;
1583 $tmparray = array();
1584 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
1585 $parameters = array('mode'=>$mode);
1586 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
1587 complete_substitutions_array($tmparray, $langs, null, $parameters);
1589 if ($mode == 'formwithlines') {
1590 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
1592 if ($mode == 'formforlines') {
1593 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
1597 if ($mode == 'emailing') {
1598 $parameters = array('mode'=>$mode);
1599 $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
1600 complete_substitutions_array($tmparray, $langs, null, $parameters);
1602 // For mass emailing, we have different keys
1603 $tmparray['__ID__'] = 'IdRecord';
1604 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode';
1605 $tmparray['__EMAIL__'] = 'EMailRecipient';
1606 $tmparray['__LASTNAME__'] = 'Lastname';
1607 $tmparray['__FIRSTNAME__'] = 'Firstname';
1608 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
1609 $tmparray['__OTHER1__'] = 'Other1';
1610 $tmparray['__OTHER2__'] = 'Other2';
1611 $tmparray['__OTHER3__'] = 'Other3';
1612 $tmparray['__OTHER4__'] = 'Other4';
1613 $tmparray['__OTHER5__'] = 'Other5';
1614 $tmparray['__USER_SIGNATURE__'] = 'TagUserSignature';
1615 $tmparray['__SENDEREMAIL_SIGNATURE__'] = 'TagEmailSenderSignature';
1616 $tmparray['__CHECK_READ__'] = 'TagCheckMail';
1617 $tmparray['__UNSUBSCRIBE__'] = 'TagUnsubscribe';
1618 //,'__PERSONALIZED__' => 'Personalized' // Hidden because not used yet in mass emailing
1620 $onlinepaymentenabled = 0;
1621 if (isModEnabled('paypal')) {
1622 $onlinepaymentenabled++;
1624 if (isModEnabled('paybox')) {
1625 $onlinepaymentenabled++;
1627 if (isModEnabled('stripe')) {
1628 $onlinepaymentenabled++;
1630 if ($onlinepaymentenabled && !empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
1631 $tmparray['__SECUREKEYPAYMENT__'] = $conf->global->PAYMENT_SECURITY_TOKEN;
1632 if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
1633 if (isModEnabled('adherent')) {
1634 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
1636 if (isModEnabled('don')) {
1637 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
1639 if (isModEnabled('facture')) {
1640 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
1642 if (isModEnabled('commande')) {
1643 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
1645 if (isModEnabled('contrat')) {
1646 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
1649 //Online payement link
1650 if (isModEnabled('adherent')) {
1651 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
1653 if (isModEnabled('don')) {
1654 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
1656 if (isModEnabled('facture')) {
1657 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
1659 if (isModEnabled('commande')) {
1660 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
1662 if (isModEnabled('contrat')) {
1663 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
1667 /* No need to show into tooltip help, option is not enabled
1668 $vars['__SECUREKEYPAYMENT__']='';
1669 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
1670 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
1671 $vars['__SECUREKEYPAYMENT_ORDER__']='';
1672 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
1675 if (!empty($conf->global->MEMBER_ENABLE_PUBLIC)) {
1676 $substitutionarray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
1680 foreach ($tmparray as $key => $val) {
1682 $tmparray[$key] = $key;
1727 public $content_lines;
1734 public $email_tobcc;
Class to manage a WYSIWYG editor.
Class to manage translations.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_textishtml($msg, $option=0)
Return if a text is a html content.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
table tableforfield button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
getMaxFileSizeArray()
Return the max allowed for file upload.
$conf db
API class for accounts.