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) {
547 if (in_array($key, array(
'__NEWREF__',
'__REFCLIENT__',
'__REFSUPPLIER__',
'__SUPPLIER_ORDER_DATE_DELIVERY__',
'__SUPPLIER_ORDER_DELAY_DELIVERY__'))) {
552 if (!empty($this->withsubstit)) {
553 $out .=
'<tr><td colspan="2" class="right">';
555 if (is_numeric($this->withsubstit)) {
556 $out .=
$form->textwithpicto($langs->trans(
"EMailTestSubstitutionReplacedByGenericValues"), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltip');
558 $out .=
$form->textwithpicto($langs->trans(
'AvailableVariables'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltip');
560 $out .=
"</td></tr>\n";
565 if (!empty($this->withfrom)) {
566 if (!empty($this->withfromreadonly)) {
567 $out .=
'<tr><td class="fieldrequired minwidth200">'.$langs->trans(
"MailFrom").
'</td><td>';
570 if (!($this->fromtype ===
'user' && $this->fromid > 0)
571 && !($this->fromtype ===
'company')
572 && !($this->fromtype ===
'robot')
573 && !preg_match(
'/user_aliases/', $this->fromtype)
574 && !preg_match(
'/global_aliases/', $this->fromtype)
575 && !preg_match(
'/senderprofile/', $this->fromtype)
578 $out .= $this->fromname;
579 if ($this->frommail) {
580 $out .=
' <'.$this->frommail.
'>';
582 if ($this->fromtype) {
583 $langs->load(
'errors');
584 $out .=
'<span class="warning"> <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'> </span>';
591 if (empty($user->email)) {
592 $langs->load(
'errors');
593 $liste[
'user'] = $user->getFullName($langs).
' <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'>';
595 $liste[
'user'] = $user->getFullName($langs).
' <'.$user->email.
'>';
599 if (!empty($conf->global->MAIN_INFO_SOCIETE_MAIL)) {
600 $liste[
'company'] = !empty($conf->global->MAIN_INFO_SOCIETE_NOM)?$conf->global->MAIN_INFO_SOCIETE_NOM:$conf->global->MAIN_INFO_SOCIETE_MAIL;
601 $liste[
'company'].=
' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.
'>';
605 $listaliases = array(
606 'user_aliases' => (empty($user->email_aliases) ?
'' : $user->email_aliases),
611 if (!empty($this->fromalsorobot)) {
613 $liste[
'robot'] = $conf->global->MAIN_MAIL_EMAIL_FROM;
614 if ($this->frommail) {
615 $liste[
'robot'] .=
' <'.$conf->global->MAIN_MAIL_EMAIL_FROM.
'>';
621 $sql =
"SELECT rowid, label, email FROM ".$this->db->prefix().
"c_email_senderprofile";
622 $sql .=
" WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).
")";
623 $sql .=
" ORDER BY position";
629 $obj = $this->
db->fetch_object(
$resql);
631 $listaliases[
'senderprofile_'.$obj->rowid] = $obj->label.
' <'.$obj->email.
'>';
639 foreach ($listaliases as $typealias => $listalias) {
641 $listaliasarray = explode(
',', $listalias);
642 foreach ($listaliasarray as $listaliasval) {
644 $listaliasval = trim($listaliasval);
646 $listaliasval = preg_replace(
'/</',
'<', $listaliasval);
647 $listaliasval = preg_replace(
'/>/',
'>', $listaliasval);
648 if (!preg_match(
'/</', $listaliasval)) {
649 $listaliasval =
'<'.$listaliasval.
'>';
651 $liste[$typealias.
'_'.$posalias] = $listaliasval;
658 $out .=
' '.$form->selectarray(
'fromtype', $liste, $this->fromtype, 0, 0, 0,
'', 0, 0, 0,
'',
'fromforsendingprofile maxwidth200onsmartphone', 0,
'', $disablebademails);
661 $out .=
"</td></tr>\n";
663 $out .=
'<tr><td class="fieldrequired width200">'.$langs->trans(
"MailFrom").
"</td><td>";
664 $out .= $langs->trans(
"Name").
':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.
'" />';
665 $out .=
' ';
666 $out .= $langs->trans(
"EMail").
':<<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.
'" />>';
667 $out .=
"</td></tr>\n";
672 if (!empty($this->withto) || is_array($this->withto)) {
677 if (!empty($this->withtouser) && is_array($this->withtouser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
679 $out .= $langs->trans(
"MailToUsers");
683 $tmparray = $this->withtouser;
684 foreach ($tmparray as $key => $val) {
687 $withtoselected =
GETPOST(
"receiveruser",
'array');
688 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
689 $withtoselected = array_keys($tmparray);
691 $out .=
$form->multiselectarray(
"receiveruser", $tmparray, $withtoselected,
null,
null,
'inline-block minwidth500',
null,
"");
692 $out .=
"</td></tr>\n";
696 if (!empty($this->withoptiononeemailperrecipient)) {
697 if (abs($this->withoptiononeemailperrecipient) == 1) {
698 $out .=
'<tr><td class="minwidth200">';
699 $out .= $langs->trans(
"GroupEmails");
701 $out .=
' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ?
' checked="checked"' :
'').
'> ';
702 $out .=
'<label for="oneemailperrecipient">'.$langs->trans(
"OneEmailPerRecipient").
'</label>';
703 $out .=
'<span class="hideonsmartphone opacitymedium">';
705 $out .= $langs->trans(
"WarningIfYouCheckOneRecipientPerEmail");
707 $out .=
'</td></tr>';
709 $out .=
'<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>';
714 if (!empty($this->withtocc) || is_array($this->withtocc)) {
719 if (!empty($this->withtoccuser) && is_array($this->withtoccuser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
721 $out .= $langs->trans(
"MailToCCUsers");
725 $tmparray = $this->withtoccuser;
726 foreach ($tmparray as $key => $val) {
729 $withtoselected =
GETPOST(
"receiverccuser",
'array');
730 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
731 $withtoselected = array_keys($tmparray);
733 $out .=
$form->multiselectarray(
"receiverccuser", $tmparray, $withtoselected,
null,
null,
'inline-block minwidth500',
null,
"");
734 $out .=
"</td></tr>\n";
738 if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
743 if (!empty($this->withreplyto)) {
744 if ($this->withreplytoreadonly) {
745 $out .=
'<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.
'" />';
746 $out .=
'<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.
'" />';
747 $out .=
"<tr><td>".$langs->trans(
"MailReply").
"</td><td>".$this->replytoname.($this->replytomail ? (
" <".$this->replytomail.
">") :
"");
748 $out .=
"</td></tr>\n";
753 if (!empty($this->witherrorsto)) {
758 if (!empty($this->withdeliveryreceipt) &&
getDolGlobalInt(
'MAIN_EMAIL_SUPPORT_ACK')) {
759 $out .= $this->getHtmlForDeliveryReceipt();
763 if (!empty($this->withtopic)) {
764 $out .= $this->
getHtmlForTopic($arraydefaultmessage, $helpforsubstitution);
768 if (!empty($this->withfile)) {
770 $out .=
'<td>'.$langs->trans(
"MailFile").
'</td>';
774 if ($this->withmaindocfile) {
777 $this->withmaindocfile = (
GETPOST(
'addmaindocfile',
'alpha') ? -1 : 1);
778 } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
780 $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
784 if (!empty($this->withmaindocfile)) {
785 if ($this->withmaindocfile == 1) {
786 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />';
787 } elseif ($this->withmaindocfile == -1) {
788 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />';
790 if (!empty($conf->global->MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND)) {
791 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDocOrLastGenerated").
'.</label><br>';
793 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDoc").
'.</label><br>';
797 if (is_numeric($this->withfile)) {
799 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
800 $out .=
'<script type="text/javascript">';
801 $out .=
'jQuery(document).ready(function () {';
802 $out .=
' jQuery(".removedfile").click(function() {';
803 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
806 $out .=
'</script>'.
"\n";
807 if (count($listofpaths)) {
808 foreach ($listofpaths as $key => $val) {
809 $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
811 if ($conf->entity > 1) {
812 $relativepathtofile = str_replace(
'/'.$conf->entity.
'/',
'/', $relativepathtofile);
815 $formfile_params = array();
816 preg_match(
'#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params);
818 $out .=
'<div id="attachfile_'.$key.
'">';
820 $out .=
img_mime($listofnames[$key]).
' '.$listofnames[$key];
822 $out .= $formfile->showPreview(array(), $formfile_params[2], $formfile_params[4]);
823 if (!$this->withfilereadonly) {
824 $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.
'" />';
827 $out .=
'<br></div>';
829 } elseif (empty($this->withmaindocfile)) {
832 if ($this->withfile == 2) {
834 $maxmin = $maxfilesizearray[
'maxmin'];
836 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
839 if (empty($conf->global->FROM_MAIL_DONT_USE_INPUT_FILE_MULTIPLE)) {
840 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans(
"Upload").
'" multiple />';
842 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
845 $out .=
'<input type="submit" class="button smallpaddingimp" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
848 $out .= $this->withfile;
851 $out .=
"</td></tr>\n";
855 if (!empty($this->withbody)) {
856 $defaultmessage =
GETPOST(
'message',
'restricthtml');
857 if (!
GETPOST(
'modelselected',
'alpha') ||
GETPOST(
'modelmailselected') !=
'-1') {
858 if ($arraydefaultmessage && $arraydefaultmessage->content) {
859 $defaultmessage = $arraydefaultmessage->content;
860 } elseif (!is_numeric($this->withbody)) {
861 $defaultmessage = $this->withbody;
867 $validpaymentmethod = array();
868 if (empty($this->substit[
'__REF__'])) {
872 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
873 $langs->loadLangs(array(
'paypal',
'other'));
874 $typeforonlinepayment =
'free';
875 if ($this->param[
"models"] ==
'order' || $this->param[
"models"] ==
'order_send') {
876 $typeforonlinepayment =
'order';
878 if ($this->param[
"models"] ==
'invoice' || $this->param[
"models"] ==
'facture_send') {
879 $typeforonlinepayment =
'invoice';
881 if ($this->param[
"models"] ==
'member') {
882 $typeforonlinepayment =
'member';
884 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit[
'__REF__']);
887 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
890 if (count($validpaymentmethod) > 0 && $paymenturl) {
891 $langs->load(
'other');
892 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace(
'\n',
"\n", $langs->transnoentities(
"PredefinedMailContentLink", $paymenturl));
893 $this->substit[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
895 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
896 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'';
899 $this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] =
'';
903 $defaultlines = $arraydefaultmessage->content_lines;
904 if (isset($defaultlines)) {
905 foreach ($this->substit_lines as $substit_line) {
909 $this->substit[
'__LINES__'] = $lines;
911 $defaultmessage = str_replace(
'\n',
"\n", $defaultmessage);
914 $atleastonecomponentishtml = 0;
915 if (strpos($defaultmessage,
'__USER_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__USER_SIGNATURE__'])) {
916 $atleastonecomponentishtml++;
918 if (strpos($defaultmessage,
'__SENDEREMAIL_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
919 $atleastonecomponentishtml++;
921 if (strpos($defaultmessage,
'__ONLINE_PAYMENT_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
922 $atleastonecomponentishtml++;
924 if (strpos($defaultmessage,
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
925 $atleastonecomponentishtml++;
928 $atleastonecomponentishtml++;
930 if ($atleastonecomponentishtml) {
932 $this->substit[
'__USER_SIGNATURE__'] =
dol_nl2br($this->substit[
'__USER_SIGNATURE__']);
934 if (!
dol_textishtml($this->substit[
'__SENDEREMAIL_SIGNATURE__'])) {
935 $this->substit[
'__SENDEREMAIL_SIGNATURE__'] =
dol_nl2br($this->substit[
'__SENDEREMAIL_SIGNATURE__']);
937 if (!
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
938 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
dol_nl2br($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__']);
941 $defaultmessage =
dol_nl2br($defaultmessage);
946 $defaultmessage =
GETPOST(
"message",
"restricthtml");
950 $defaultmessage = preg_replace(
"/^(<br>)+/",
"", $defaultmessage);
951 $defaultmessage = preg_replace(
"/^\n+/",
"", $defaultmessage);
955 $out .=
'<td colspan="2">';
956 $out .=
$form->textwithpicto($langs->trans(
'MailText'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltipfrombody');
961 $out .=
'<td colspan="2">';
962 if ($this->withbodyreadonly) {
963 $out .= nl2br($defaultmessage);
964 $out .=
'<input type="hidden" id="message" name="message" value="'.$defaultmessage.
'" />';
966 if (!isset($this->ckeditortoolbar)) {
967 $this->ckeditortoolbar =
'dolibarr_mailings';
971 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
972 if ($this->withfckeditor == -1) {
973 if (!empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
974 $this->withfckeditor = 1;
976 $this->withfckeditor = 0;
980 $doleditor =
new DolEditor(
'message', $defaultmessage,
'', 280, $this->ckeditortoolbar,
'In',
true,
true, $this->withfckeditor, 8,
'95%');
981 $out .= $doleditor->Create(1);
983 $out .=
"</td></tr>\n";
986 $out .=
'</table>'.
"\n";
988 if ($this->withform == 1 || $this->withform == -1) {
989 $out .=
'<div class="center">';
990 $out .=
'<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans(
"SendMail").
'"';
992 if ($this->withfile == 2 && $conf->use_javascript_ajax) {
993 $out .=
' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans(
"FileWasNotUploaded")).
'\');
return false; }
else {
return true; }
"';
996 if ($this->withcancel) {
997 $out .= '<input class="button button-cancel
" type="submit
" id="cancel
" name="cancel
" value="'.$langs->trans("Cancel").'" />';
999 $out .= '</div>'."\n
";
1002 if ($this->withform == 1) {
1003 $out .= '</form>'."\n
";
1006 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1007 if (!empty($conf->global->MAIN_MAILFORM_DISABLE_ENTERKEY)) {
1008 $out .= '<script type="text/javascript
">';
1009 $out .= 'jQuery(document).ready(function () {';
1010 $out .= ' $(document).on("keypress
", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1011 var code = e.keyCode || e.which;
1013 console.log("Enter was intercepted and blocked
");
1019 $out .= '</script>';
1022 $out .= "<!-- End form mail -->\n
";
1033 public function getHtmlForTo()
1035 global $langs, $form;
1036 $out = '<tr><td class="fieldrequired
">';
1037 if ($this->withtofree) {
1038 $out .= $form->textwithpicto($langs->trans("MailTo
"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients
"));
1040 $out .= $langs->trans("MailTo
");
1042 $out .= '</td><td>';
1043 if ($this->withtoreadonly) {
1044 if (!empty($this->toname) && !empty($this->tomail)) {
1045 $out .= '<input type="hidden
" id="toname
" name="toname
" value="'.$this->toname.'" />';
1046 $out .= '<input type="hidden
" id="tomail
" name="tomail
" value="'.$this->tomail.'" />';
1047 if ($this->totype == 'thirdparty') {
1048 $soc = new Societe($this->db);
1049 $soc->fetch($this->toid);
1050 $out .= $soc->getNomUrl(1);
1051 } elseif ($this->totype == 'contact') {
1052 $contact = new Contact($this->db);
1053 $contact->fetch($this->toid);
1054 $out .= $contact->getNomUrl(1);
1056 $out .= $this->toname;
1058 $out .= ' <'.$this->tomail.'>';
1059 if ($this->withtofree) {
1060 $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) : "").'" />';
1063 // Note withto may be a text like 'AllRecipientSelected'
1064 $out .= (!is_array($this->withto) && !is_numeric($this->withto)) ? $this->withto : "";
1067 // The free input of email
1068 if (!empty($this->withtofree)) {
1069 $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) : "")).'" />';
1072 if (!empty($this->withto) && is_array($this->withto)) {
1073 if (!empty($this->withtofree)) {
1074 $out .= " ".$langs->trans("and
")."/
".$langs->trans("or
")." ";
1076 // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
1077 $tmparray = $this->withto;
1078 foreach ($tmparray as $key => $val) {
1079 $tmparray[$key] = str_replace(array('<', '>'), array('(', ')'), $tmparray[$key]);
1080 $tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
1083 $withtoselected = GETPOST("receiver
", 'array'); // Array of selected value
1085 if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') {
1086 $withtoselected = array_keys($tmparray);
1089 $out .= $form->multiselectarray("receiver
", $tmparray, $withtoselected, null, null, 'inline-block minwidth500', null, "");
1092 $out .= "</td></tr>\n
";
1101 public function getHtmlForCc()
1103 global $langs, $form;
1105 $out .= $form->textwithpicto($langs->trans("MailCC
"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients
"));
1106 $out .= '</td><td>';
1107 if ($this->withtoccreadonly) {
1108 $out .= (!is_array($this->withtocc) && !is_numeric($this->withtocc)) ? $this->withtocc : "";
1110 $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 : '')).'" />';
1111 if (!empty($this->withtocc) && is_array($this->withtocc)) {
1112 $out .= " ".$langs->trans("and
")."/
".$langs->trans("or
")." ";
1113 // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
1114 $tmparray = $this->withtocc;
1115 foreach ($tmparray as $key => $val) {
1116 $tmparray[$key] = str_replace(array('<', '>'), array('(', ')'), $tmparray[$key]);
1117 $tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
1119 $withtoccselected = GETPOST("receivercc
", 'array'); // Array of selected value
1120 $out .= $form->multiselectarray("receivercc
", $tmparray, $withtoccselected, null, null, 'inline-block minwidth500', null, "");
1123 $out .= "</td></tr>\n
";
1132 public function getHtmlForWithCcc()
1134 global $conf, $langs, $form;
1136 $out .= $form->textwithpicto($langs->trans("MailCCC
"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients
"));
1137 $out .= '</td><td>';
1138 if (!empty($this->withtocccreadonly)) {
1139 $out .= (!is_array($this->withtoccc) && !is_numeric($this->withtoccc)) ? $this->withtoccc : "";
1141 $out .= '<input class="minwidth200
" id="sendtoccc
" name="sendtoccc
" value="'.(GETPOSTISSET("sendtoccc") ? GETPOST("sendtoccc", "alpha") : ((!is_array($this->withtoccc) && !is_numeric($this->withtoccc)) ? $this->withtoccc : '')).'" />';
1142 if (!empty($this->withtoccc) && is_array($this->withtoccc)) {
1143 $out .= " ".$langs->trans("and
")."/
".$langs->trans("or
")." ";
1144 // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
1145 $tmparray = $this->withtoccc;
1146 foreach ($tmparray as $key => $val) {
1147 $tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
1149 $withtocccselected = GETPOST("receiverccc
", 'array'); // Array of selected value
1150 $out .= $form->multiselectarray("receiverccc
", $tmparray, $withtocccselected, null, null, null, null, "90%
");
1155 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) && !empty($this->param['models']) && $this->param['models'] == 'propal_send') {
1156 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO;
1158 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) && !empty($this->param['models']) && $this->param['models'] == 'order_send') {
1159 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO;
1161 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) && !empty($this->param['models']) && $this->param['models'] == 'facture_send') {
1162 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO;
1164 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) && !empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') {
1165 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO;
1167 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO) && !empty($this->param['models']) && $this->param['models'] == 'order_supplier_send') {
1168 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO;
1170 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO) && !empty($this->param['models']) && $this->param['models'] == 'invoice_supplier_send') {
1171 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO;
1173 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_PROJECT_TO) && !empty($this->param['models']) && $this->param['models'] == 'project') {
1174 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_PROJECT_TO;
1177 $out .= ' + '.$showinfobcc;
1179 $out .= "</td></tr>\n
";
1188 public function getHtmlForWithErrorsTo()
1190 global $conf, $langs;
1191 //if (! $this->errorstomail) $this->errorstomail=$this->frommail;
1192 $errorstomail = getDolGlobalString('MAIN_MAIL_ERRORS_TO', (!empty($this->errorstomail) ? $this->errorstomail : ''));
1193 if ($this->witherrorstoreadonly) {
1194 $out = '<tr><td>'.$langs->trans("MailErrorsTo
").'</td><td>';
1195 $out .= '<input type="hidden
" id="errorstomail
" name="errorstomail
" value="'.$errorstomail.'" />';
1196 $out .= $errorstomail;
1197 $out .= "</td></tr>\n
";
1199 $out = '<tr><td>'.$langs->trans("MailErrorsTo
").'</td><td>';
1200 $out .= '<input class="minwidth200
" id="errorstomail
" name="errorstomail
" value="'.$errorstomail.'" />';
1201 $out .= "</td></tr>\n
";
1211 public function getHtmlForDeliveryreceipt()
1213 global $conf, $langs;
1214 $out = '<tr><td><label for="deliveryreceipt
">'.$langs->trans("DeliveryReceipt
").'</label></td><td>';
1216 if (!empty($this->withdeliveryreceiptreadonly)) {
1217 $out .= yn($this->withdeliveryreceipt);
1219 $defaultvaluefordeliveryreceipt = 0;
1220 if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_PROPAL) && !empty($this->param['models']) && $this->param['models'] == 'propal_send') {
1221 $defaultvaluefordeliveryreceipt = 1;
1223 if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_PROPOSAL) && !empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') {
1224 $defaultvaluefordeliveryreceipt = 1;
1226 if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_ORDER) && !empty($this->param['models']) && $this->param['models'] == 'order_send') {
1227 $defaultvaluefordeliveryreceipt = 1;
1229 if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_INVOICE) && !empty($this->param['models']) && $this->param['models'] == 'facture_send') {
1230 $defaultvaluefordeliveryreceipt = 1;
1232 if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_ORDER) && !empty($this->param['models']) && $this->param['models'] == 'order_supplier_send') {
1233 $defaultvaluefordeliveryreceipt = 1;
1235 //$out .= $form->selectyesno('deliveryreceipt', (GETPOSTISSET("deliveryreceipt
") ? GETPOST("deliveryreceipt
") : $defaultvaluefordeliveryreceipt), 1);
1236 $out .= '<input type="checkbox
" id="deliveryreceipt
" name="deliveryreceipt
" value="1
"'.((GETPOSTISSET("deliveryreceipt
") ? GETPOST("deliveryreceipt
") : $defaultvaluefordeliveryreceipt) ? ' checked="checked
"' : '').'>';
1238 $out .= "</td></tr>\n
";
1249 public function getHtmlForTopic($arraydefaultmessage, $helpforsubstitution)
1251 global $conf, $langs, $form;
1253 $defaulttopic = GETPOST('subject', 'restricthtml');
1255 if (!GETPOST('modelselected', 'alpha') || GETPOST('modelmailselected') != '-1') {
1256 if ($arraydefaultmessage && $arraydefaultmessage->topic) {
1257 $defaulttopic = $arraydefaultmessage->topic;
1258 } elseif (!is_numeric($this->withtopic)) {
1259 $defaulttopic = $this->withtopic;
1263 $defaulttopic = make_substitutions($defaulttopic, $this->substit);
1266 $out .= '<td class="fieldrequired
">';
1267 $out .= $form->textwithpicto($langs->trans('MailTopic'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltipfromtopic');
1270 if ($this->withtopicreadonly) {
1271 $out .= $defaulttopic;
1272 $out .= '<input type="hidden
" class="quatrevingtpercent
" id="subject
" name="subject
" value="'.$defaulttopic.'" />';
1274 $out .= '<input type="text
" class="quatrevingtpercent
" id="subject
" name="subject
" value="'.((GETPOSTISSET("subject") && !GETPOST('modelselected
')) ? GETPOST("subject") : ($defaulttopic ? $defaulttopic : '')).'" />';
1276 $out .= "</td></tr>\n
";
1293 public function getEMailTemplate($dbs, $type_template, $user, $outputlangs, $id = 0, $active = 1, $label = '')
1295 global $conf, $langs;
1297 $ret = new ModelMail();
1299 if ($id == -2 && empty($label)) {
1300 $this->error = 'LabelIsMandatoryWhenIdIs-2';
1304 $languagetosearch = (is_object($outputlangs) ? $outputlangs->defaultlang : '');
1305 // Define $languagetosearchmain to fall back on main language (for example to get 'es_ES' for 'es_MX')
1306 $tmparray = explode('_', $languagetosearch);
1307 $languagetosearchmain = $tmparray[0].'_'.strtoupper($tmparray[0]);
1308 if ($languagetosearchmain == $languagetosearch) {
1309 $languagetosearchmain = '';
1312 $sql = "SELECT
rowid, module, label, type_template, topic, joinfiles, content, content_lines, lang, email_from, email_to, email_tocc, email_tobcc
";
1313 $sql .= " FROM
".$dbs->prefix().'c_email_templates';
1314 $sql .= " WHERE (type_template =
'".$dbs->escape($type_template)."' OR type_template =
'all')
";
1315 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1316 $sql .= " AND (
private = 0 OR fk_user =
".((int) $user->id).")
"; // Get all public or private owned
1318 $sql .= " AND active =
".((int) $active);
1321 $sql .= " AND label =
'".$dbs->escape($label)."'";
1323 if (!($id > 0) && $languagetosearch) {
1324 $sql .= " AND (lang =
'".$dbs->escape($languagetosearch)."'".($languagetosearchmain ? " OR lang =
'".$dbs->escape($languagetosearchmain)."'" : "")." OR lang IS NULL OR lang =
'')
";
1327 $sql .= " AND
rowid=
".(int) $id;
1330 $sql .= " AND position=0
";
1332 if ($languagetosearch) {
1333 $sql .= $dbs->order("position,lang,label
", "ASC,DESC,ASC
"); // We want line with lang set first, then with lang null or ''
1335 $sql .= $dbs->order("position,lang,label
", "ASC,ASC,ASC
"); // If no language provided, we give priority to lang not defined
1337 //$sql .= $dbs->plimit(1);
1340 $resql = $dbs->query($sql);
1342 dol_print_error($dbs);
1348 $obj = $dbs->fetch_object($resql);
1351 // If template is for a module, check module is enabled; if not, take next template
1353 $tempmodulekey = $obj->module;
1354 if (empty($conf->$tempmodulekey) || empty($conf->$tempmodulekey->enabled)) {
1359 // If a record was found
1360 $ret->id = $obj->rowid;
1361 $ret->module = $obj->module;
1362 $ret->label = $obj->label;
1363 $ret->lang = $obj->lang;
1364 $ret->topic = $obj->topic;
1365 $ret->content = $obj->content;
1366 $ret->content_lines = $obj->content_lines;
1367 $ret->joinfiles = $obj->joinfiles;
1371 // If no record found
1373 // Not found with the provided label
1376 // If there is no template at all
1377 $defaultmessage = '';
1379 if ($type_template == 'body') {
1380 // Special case to use this->withbody as content
1381 $defaultmessage = $this->withbody;
1382 } elseif ($type_template == 'facture_send') {
1383 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoice
");
1384 } elseif ($type_template == 'facture_relance') {
1385 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoiceReminder
");
1386 } elseif ($type_template == 'propal_send') {
1387 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendProposal
");
1388 } elseif ($type_template == 'supplier_proposal_send') {
1389 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierProposal
");
1390 } elseif ($type_template == 'order_send') {
1391 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendOrder
");
1392 } elseif ($type_template == 'order_supplier_send') {
1393 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder
");
1394 } elseif ($type_template == 'invoice_supplier_send') {
1395 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice
");
1396 } elseif ($type_template == 'shipping_send') {
1397 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendShipping
");
1398 } elseif ($type_template == 'fichinter_send') {
1399 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendFichInter
");
1400 } elseif ($type_template == 'actioncomm_send') {
1401 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendActionComm
");
1402 } elseif (!empty($type_template)) {
1403 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentGeneric
");
1406 $ret->label = 'default';
1407 $ret->lang = $outputlangs->defaultlang;
1409 $ret->joinfiles = 1;
1410 $ret->content = $defaultmessage;
1411 $ret->content_lines = '';
1432 public function isEMailTemplate($type_template, $user, $outputlangs)
1434 $sql = "SELECT label, topic, content, lang
";
1435 $sql .= " FROM
".$this->db->prefix().'c_email_templates';
1436 $sql .= " WHERE type_template=
'".$this->db->escape($type_template)."'";
1437 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1438 $sql .= " AND (fk_user is NULL or fk_user = 0 or fk_user =
".((int) $user->id).")
";
1439 if (is_object($outputlangs)) {
1440 $sql .= " AND (lang =
'".$this->db->escape($outputlangs->defaultlang)."' OR lang IS NULL OR lang =
'')
";
1442 $sql .= $this->db->order("lang,label
", "ASC
");
1445 $resql = $this->db->query($sql);
1447 $num = $this->db->num_rows($resql);
1448 $this->db->free($resql);
1451 $this->error = get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1466 public function fetchAllEMailTemplate($type_template, $user, $outputlangs, $active = 1)
1470 $sql = "SELECT
rowid, module, label, topic, content, content_lines, lang, fk_user,
private, position
";
1471 $sql .= " FROM
".$this->db->prefix().'c_email_templates';
1472 $sql .= " WHERE type_template IN (
'".$this->db->escape($type_template)."',
'all')
";
1473 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1474 $sql .= " AND (
private = 0 OR fk_user =
".((int) $user->id).")
"; // See all public templates or templates I own.
1476 $sql .= " AND active =
".((int) $active);
1478 //if (is_object($outputlangs)) $sql.= " AND (lang =
'".$this->db->escape($outputlangs->defaultlang)."' OR lang IS NULL OR lang =
'')
"; // Return all languages
1479 $sql .= $this->db->order("position,lang,label
", "ASC
");
1482 $resql = $this->db->query($sql);
1484 $num = $this->db->num_rows($resql);
1485 $this->lines_model = array();
1486 while ($obj = $this->db->fetch_object($resql)) {
1487 // If template is for a module, check module is enabled.
1489 $tempmodulekey = $obj->module;
1490 if (empty($conf->$tempmodulekey) || empty($conf->$tempmodulekey->enabled)) {
1495 $line = new ModelMail();
1496 $line->id = $obj->rowid;
1497 $line->label = $obj->label;
1498 $line->lang = $obj->lang;
1499 $line->fk_user = $obj->fk_user;
1500 $line->private = $obj->private;
1501 $line->position = $obj->position;
1502 $line->topic = $obj->topic;
1503 $line->content = $obj->content;
1504 $line->content_lines = $obj->content_lines;
1506 $this->lines_model[] = $line;
1508 $this->db->free($resql);
1511 $this->error = get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1526 public function setSubstitFromObject($object, $outputlangs)
1528 global $conf, $user, $extrafields;
1530 $parameters = array();
1531 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1532 complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
1534 $this->substit = $tmparray;
1536 // Fill substit_lines with each object lines content
1537 if (is_array($object->lines)) {
1538 foreach ($object->lines as $line) {
1539 $substit_line = array(
1540 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
1541 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
1542 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
1543 '__LABEL__' => isset($line->label) ? $line->label : '',
1544 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
1545 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', 0, $outputlangs),
1546 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', 0, $outputlangs),
1547 '__QUANTITY__' => $line->qty,
1548 '__SUBPRICE__' => price($line->subprice),
1549 '__AMOUNT__' => price($line->total_ttc),
1550 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
1553 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
1554 if (!empty($line->fk_product)) {
1555 if (!is_object($extrafields)) {
1556 $extrafields = new ExtraFields($this->db);
1558 $product = new Product($this->db);
1559 $product->fetch($line->fk_product, '', '', 1);
1560 $product->fetch_optionals();
1562 $extrafields->fetch_name_optionals_label($product->table_element, true);
1564 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
1565 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
1566 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
1570 $this->substit_lines[] = $substit_line;
1583 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
1585 global $conf, $langs;
1587 $tmparray = array();
1588 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
1589 $parameters = array('mode'=>$mode);
1590 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
1591 complete_substitutions_array($tmparray, $langs, null, $parameters);
1593 if ($mode == 'formwithlines') {
1594 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
1596 if ($mode == 'formforlines') {
1597 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
1601 if ($mode == 'emailing') {
1602 $parameters = array('mode'=>$mode);
1603 $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
1604 complete_substitutions_array($tmparray, $langs, null, $parameters);
1606 // For mass emailing, we have different keys
1607 $tmparray['__ID__'] = 'IdRecord';
1608 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode';
1609 $tmparray['__EMAIL__'] = 'EMailRecipient';
1610 $tmparray['__LASTNAME__'] = 'Lastname';
1611 $tmparray['__FIRSTNAME__'] = 'Firstname';
1612 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
1613 $tmparray['__OTHER1__'] = 'Other1';
1614 $tmparray['__OTHER2__'] = 'Other2';
1615 $tmparray['__OTHER3__'] = 'Other3';
1616 $tmparray['__OTHER4__'] = 'Other4';
1617 $tmparray['__OTHER5__'] = 'Other5';
1618 $tmparray['__USER_SIGNATURE__'] = 'TagUserSignature';
1619 $tmparray['__SENDEREMAIL_SIGNATURE__'] = 'TagEmailSenderSignature';
1620 $tmparray['__CHECK_READ__'] = 'TagCheckMail';
1621 $tmparray['__UNSUBSCRIBE__'] = 'TagUnsubscribe';
1622 //,'__PERSONALIZED__' => 'Personalized' // Hidden because not used yet in mass emailing
1624 $onlinepaymentenabled = 0;
1625 if (isModEnabled('paypal')) {
1626 $onlinepaymentenabled++;
1628 if (isModEnabled('paybox')) {
1629 $onlinepaymentenabled++;
1631 if (isModEnabled('stripe')) {
1632 $onlinepaymentenabled++;
1634 if ($onlinepaymentenabled && !empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
1635 $tmparray['__SECUREKEYPAYMENT__'] = $conf->global->PAYMENT_SECURITY_TOKEN;
1636 if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
1637 if (isModEnabled('adherent')) {
1638 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
1640 if (isModEnabled('don')) {
1641 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
1643 if (isModEnabled('facture')) {
1644 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
1646 if (isModEnabled('commande')) {
1647 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
1649 if (isModEnabled('contrat')) {
1650 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
1653 //Online payment link
1654 if (isModEnabled('adherent')) {
1655 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
1657 if (isModEnabled('don')) {
1658 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
1660 if (isModEnabled('facture')) {
1661 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
1663 if (isModEnabled('commande')) {
1664 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
1666 if (isModEnabled('contrat')) {
1667 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
1671 /* No need to show into tooltip help, option is not enabled
1672 $vars['__SECUREKEYPAYMENT__']='';
1673 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
1674 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
1675 $vars['__SECUREKEYPAYMENT_ORDER__']='';
1676 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
1679 if (!empty($conf->global->MEMBER_ENABLE_PUBLIC)) {
1680 $substitutionarray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
1684 foreach ($tmparray as $key => $val) {
1686 $tmparray[$key] = $key;
1731 public $content_lines;
1738 public $email_tobcc;