29 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
75 public $fromalsorobot;
139 public $withmaindocfile;
142 public $withfromreadonly;
143 public $withreplytoreadonly;
144 public $withtoreadonly;
145 public $withtoccreadonly;
146 public $withtocccreadonly;
147 public $withtopicreadonly;
148 public $withfilereadonly;
149 public $withdeliveryreceipt;
151 public $withfckeditor;
153 public $substit = array();
154 public $substit_lines = array();
155 public $param = array();
157 public $withtouser = array();
158 public $withtoccuser = array();
163 public $withoptiononeemailperrecipient;
179 $this->withtofree = 1;
181 $this->withtoccc = 0;
182 $this->witherrorsto = 0;
183 $this->withtopic = 1;
185 $this->withmaindocfile = 0;
188 $this->withfromreadonly = 1;
189 $this->withreplytoreadonly = 1;
190 $this->withtoreadonly = 0;
191 $this->withtoccreadonly = 0;
192 $this->withtocccreadonly = 0;
193 $this->witherrorstoreadonly = 0;
194 $this->withtopicreadonly = 0;
195 $this->withfilereadonly = 0;
196 $this->withbodyreadonly = 0;
197 $this->withdeliveryreceiptreadonly = 0;
198 $this->withfckeditor = -1;
211 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
214 $vardir = $conf->user->dir_output.
"/".$user->id;
215 $upload_dir = $vardir.
'/temp/';
216 if (is_dir($upload_dir)) {
220 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
221 unset($_SESSION[
"listofpaths".$keytoavoidconflict]);
222 unset($_SESSION[
"listofnames".$keytoavoidconflict]);
223 unset($_SESSION[
"listofmimes".$keytoavoidconflict]);
238 $listofpaths = array();
239 $listofnames = array();
240 $listofmimes = array();
243 $file = basename($path);
249 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
250 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
251 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
253 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
254 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
256 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
257 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
259 if (!in_array($file, $listofnames)) {
260 $listofpaths[] = $path;
261 $listofnames[] = $file;
262 $listofmimes[] = $type;
263 $_SESSION[
"listofpaths".$keytoavoidconflict] = join(
';', $listofpaths);
264 $_SESSION[
"listofnames".$keytoavoidconflict] = join(
';', $listofnames);
265 $_SESSION[
"listofmimes".$keytoavoidconflict] = join(
';', $listofmimes);
279 $listofpaths = array();
280 $listofnames = array();
281 $listofmimes = array();
283 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
284 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
285 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
287 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
288 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
290 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
291 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
293 if ($keytodelete >= 0) {
294 unset($listofpaths[$keytodelete]);
295 unset($listofnames[$keytodelete]);
296 unset($listofmimes[$keytodelete]);
297 $_SESSION[
"listofpaths".$keytoavoidconflict] = join(
';', $listofpaths);
298 $_SESSION[
"listofnames".$keytoavoidconflict] = join(
';', $listofnames);
299 $_SESSION[
"listofmimes".$keytoavoidconflict] = join(
';', $listofmimes);
313 $listofpaths = array();
314 $listofnames = array();
315 $listofmimes = array();
317 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
318 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
319 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
321 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
322 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
324 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
325 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
327 return array(
'paths'=>$listofpaths,
'names'=>$listofnames,
'mimes'=>$listofmimes);
341 public function show_form($addfileaction =
'addfile', $removefileaction =
'removefile')
344 print $this->
get_form($addfileaction, $removefileaction);
358 public function get_form($addfileaction =
'addfile', $removefileaction =
'removefile')
361 global $conf, $langs, $user, $hookmanager,
$form;
364 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
365 $formfile =
new Formfile($this->
db);
367 if (!is_object(
$form)) {
372 $langs->loadLangs(array(
'other',
'mails',
'members'));
375 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
380 $hookmanager->initHooks(array(
'formmail'));
383 'addfileaction' => $addfileaction,
384 'removefileaction'=> $removefileaction,
385 'trackid'=> $this->trackid
387 $reshook = $hookmanager->executeHooks(
'getFormMail', $parameters, $this);
389 if (!empty($reshook)) {
390 return $hookmanager->resPrint;
394 $disablebademails = 1;
397 $outputlangs = $langs;
399 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) {
400 $newlang = $this->param[
'langsmodels'];
402 if (!empty($newlang)) {
404 $outputlangs->setDefaultLang($newlang);
405 $outputlangs->load(
'other');
409 $arraydefaultmessage = -1;
410 if ($this->param[
'models'] !=
'none') {
412 if (array_key_exists(
'models_id', $this->param)) {
413 $model_id = $this->param[
"models_id"];
416 $arraydefaultmessage = $this->
getEMailTemplate($this->
db, $this->param[
"models"], $user, $outputlangs, $model_id);
420 $listofpaths = array();
421 $listofnames = array();
422 $listofmimes = array();
423 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
425 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
426 if (!empty($arraydefaultmessage->joinfiles) && is_array($this->param[
'fileinit'])) {
427 foreach ($this->param[
'fileinit'] as $file) {
433 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
434 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
436 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
437 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
439 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
440 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
444 $out .=
"\n".
'<!-- Begin form mail type='.$this->param[
"models"].
' --><div id="mailformdiv"></div>'.
"\n";
445 if ($this->withform == 1) {
446 $out .=
'<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param[
"returnurl"].
'#formmail">'.
"\n";
448 $out .=
'<a id="formmail" name="formmail"></a>';
449 $out .=
'<input style="display:none" type="submit" id="sendmailhidden" name="sendmail">';
450 $out .=
'<input type="hidden" name="token" value="'.newToken().
'" />';
451 $out .=
'<input type="hidden" name="trackid" value="'.$this->trackid.
'" />';
453 if (!empty($this->withfrom)) {
454 if (!empty($this->withfromreadonly)) {
455 $out .=
'<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.
'" />';
456 $out .=
'<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.
'" />';
459 foreach ($this->param as $key => $value) {
460 if (is_array($value)) {
461 $out .=
"<!-- param key=".$key.
" is array, we do not output input filed for it -->\n";
463 $out .=
'<input type="hidden" id="'.$key.
'" name="'.$key.
'" value="'.$value.
'" />'.
"\n";
467 $modelmail_array = array();
468 if ($this->param[
'models'] !=
'none') {
474 foreach ($this->lines_model as $line) {
476 if (preg_match(
'/\((.*)\)/', $line->label, $reg)) {
477 $labeltouse = $langs->trans($reg[1]);
479 $labeltouse = $line->label;
485 $modelmail_array[$line->id] .=
' '.picto_from_langcode($line->lang);
487 if ($line->private) {
488 $modelmail_array[$line->id] .=
' - <span class="opacitymedium">'.dol_escape_htmltag($langs->trans(
"Private")).
'</span>';
494 if (count($modelmail_array) > 0) {
495 $model_mail_selected_id =
GETPOSTISSET(
'modelmailselected') ?
GETPOST(
'modelmailselected',
'int') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0);
498 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
500 $out .=
'<span class="opacitymedium">'.$langs->trans(
'SelectMailModel').
':</span> ';
502 $out .= $this->
selectarray(
'modelmailselected', $modelmail_array, $model_mail_selected_id, 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth100', 1,
'', 0, 1);
504 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
508 $out .=
'<input type="submit" class="button reposition" value="'.$langs->trans(
'Apply').
'" name="modelselected" id="modelselected">';
511 } elseif (!empty($this->param[
'models']) && in_array($this->param[
'models'], array(
512 'propal_send',
'order_send',
'facture_send',
513 'shipping_send',
'fichinter_send',
'supplier_proposal_send',
'order_supplier_send',
514 'invoice_supplier_send',
'thirdparty',
'contract',
'user',
'recruitmentcandidature_send',
'all'
517 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
518 $out .= $langs->trans(
'SelectMailModel').
': <select name="modelmailselected" disabled="disabled"><option value="none">'.$langs->trans(
"NoTemplateDefined").
'</option></select>';
520 $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
523 $out .=
'<input type="submit" class="button" value="'.$langs->trans(
'Apply').
'" name="modelselected" disabled="disabled" id="modelselected">';
527 $out .=
'<!-- No template available for $this->param["models"] = '.$this->param[
'models'].
' -->';
531 $out .=
'<table class="tableforemailform boxtablenotop centpercent">'.
"\n";
534 $helpforsubstitution =
'';
535 if (is_array($this->substit) && count($this->substit)) {
536 $helpforsubstitution .= $langs->trans(
'AvailableVariables').
' :<br>'.
"\n";
538 foreach ($this->substit as $key => $val) {
541 if (!empty($this->withsubstit)) {
542 $out .=
'<tr><td colspan="2" class="right">';
544 if (is_numeric($this->withsubstit)) {
545 $out .=
$form->textwithpicto($langs->trans(
"EMailTestSubstitutionReplacedByGenericValues"), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltip');
547 $out .=
$form->textwithpicto($langs->trans(
'AvailableVariables'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltip');
549 $out .=
"</td></tr>\n";
554 if (!empty($this->withfrom)) {
555 if (!empty($this->withfromreadonly)) {
556 $out .=
'<tr><td class="fieldrequired minwidth200">'.$langs->trans(
"MailFrom").
'</td><td>';
559 if (!($this->fromtype ===
'user' && $this->fromid > 0)
560 && !($this->fromtype ===
'company')
561 && !($this->fromtype ===
'robot')
562 && !preg_match(
'/user_aliases/', $this->fromtype)
563 && !preg_match(
'/global_aliases/', $this->fromtype)
564 && !preg_match(
'/senderprofile/', $this->fromtype)
567 $out .= $this->fromname;
568 if ($this->frommail) {
569 $out .=
' <'.$this->frommail.
'>';
571 if ($this->fromtype) {
572 $langs->load(
'errors');
573 $out .=
'<span class="warning"> <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'> </span>';
580 if (empty($user->email)) {
581 $langs->load(
'errors');
582 $liste[
'user'] = $user->getFullName($langs).
' <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'>';
584 $liste[
'user'] = $user->getFullName($langs).
' <'.$user->email.
'>';
588 if (!empty($conf->global->MAIN_INFO_SOCIETE_MAIL)) {
589 $liste[
'company'] = !empty($conf->global->MAIN_INFO_SOCIETE_NOM)?$conf->global->MAIN_INFO_SOCIETE_NOM:$conf->global->MAIN_INFO_SOCIETE_MAIL;
590 $liste[
'company'].=
' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.
'>';
594 $listaliases = array(
595 'user_aliases' => (empty($user->email_aliases) ?
'' : $user->email_aliases),
600 if (!empty($this->fromalsorobot)) {
601 if (!empty($conf->global->MAIN_MAIL_EMAIL_FROM) && $conf->global->MAIN_MAIL_EMAIL_FROM != $conf->global->MAIN_INFO_SOCIETE_MAIL) {
602 $liste[
'robot'] = $conf->global->MAIN_MAIL_EMAIL_FROM;
603 if ($this->frommail) {
604 $liste[
'robot'] .=
' <'.$conf->global->MAIN_MAIL_EMAIL_FROM.
'>';
610 $sql =
"SELECT rowid, label, email FROM ".$this->db->prefix().
"c_email_senderprofile";
611 $sql .=
" WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).
")";
612 $sql .=
" ORDER BY position";
618 $obj = $this->
db->fetch_object(
$resql);
620 $listaliases[
'senderprofile_'.$obj->rowid] = $obj->label.
' <'.$obj->email.
'>';
628 foreach ($listaliases as $typealias => $listalias) {
630 $listaliasarray = explode(
',', $listalias);
631 foreach ($listaliasarray as $listaliasval) {
633 $listaliasval = trim($listaliasval);
635 $listaliasval = preg_replace(
'/</',
'<', $listaliasval);
636 $listaliasval = preg_replace(
'/>/',
'>', $listaliasval);
637 if (!preg_match(
'/</', $listaliasval)) {
638 $listaliasval =
'<'.$listaliasval.
'>';
640 $liste[$typealias.
'_'.$posalias] = $listaliasval;
647 $reshook = $hookmanager->executeHooks(
'getDefaultFromEmail', $parameters, $this);
648 if (empty($reshook)) {
649 $defaultfrom = $this->fromtype;
651 if (!empty($hookmanager->resArray[
'defaultfrom'])) {
652 $defaultfrom = $hookmanager->resArray[
'defaultfrom'];
657 $out .=
' '.$form->selectarray(
'fromtype', $liste, $defaultfrom, 0, 0, 0,
'', 0, 0, 0,
'',
'fromforsendingprofile maxwidth200onsmartphone', 0,
'', $disablebademails);
660 $out .=
"</td></tr>\n";
662 $out .=
'<tr><td class="fieldrequired width200">'.$langs->trans(
"MailFrom").
"</td><td>";
663 $out .= $langs->trans(
"Name").
':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.
'" />';
664 $out .=
' ';
665 $out .= $langs->trans(
"EMail").
':<<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.
'" />>';
666 $out .=
"</td></tr>\n";
671 if (!empty($this->withto) || is_array($this->withto)) {
676 if (!empty($this->withtouser) && is_array($this->withtouser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
678 $out .= $langs->trans(
"MailToUsers");
682 $tmparray = $this->withtouser;
683 foreach ($tmparray as $key => $val) {
686 $withtoselected =
GETPOST(
"receiveruser",
'array');
687 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
688 $withtoselected = array_keys($tmparray);
690 $out .=
$form->multiselectarray(
"receiveruser", $tmparray, $withtoselected,
null,
null,
'inline-block minwidth500',
null,
"");
691 $out .=
"</td></tr>\n";
695 if (!empty($this->withoptiononeemailperrecipient)) {
696 if (abs($this->withoptiononeemailperrecipient) == 1) {
697 $out .=
'<tr><td class="minwidth200">';
698 $out .= $langs->trans(
"GroupEmails");
700 $out .=
' <input type="checkbox" id="oneemailperrecipient" value="1" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ?
' checked="checked"' :
'').
'> ';
701 $out .=
'<label for="oneemailperrecipient">'.$langs->trans(
"OneEmailPerRecipient").
'</label>';
702 $out .=
'<span class="hideonsmartphone opacitymedium">';
704 $out .= $langs->trans(
"WarningIfYouCheckOneRecipientPerEmail");
706 $out .=
'</td></tr>';
708 $out .=
'<tr><td><input type="hidden" name="oneemailperrecipient" value="1"></td><td></td></tr>';
713 if (!empty($this->withtocc) || is_array($this->withtocc)) {
718 if (!empty($this->withtoccuser) && is_array($this->withtoccuser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
720 $out .= $langs->trans(
"MailToCCUsers");
724 $tmparray = $this->withtoccuser;
725 foreach ($tmparray as $key => $val) {
728 $withtoselected =
GETPOST(
"receiverccuser",
'array');
729 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend') {
730 $withtoselected = array_keys($tmparray);
732 $out .=
$form->multiselectarray(
"receiverccuser", $tmparray, $withtoselected,
null,
null,
'inline-block minwidth500',
null,
"");
733 $out .=
"</td></tr>\n";
737 if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
742 if (!empty($this->withreplyto)) {
743 if ($this->withreplytoreadonly) {
744 $out .=
'<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.
'" />';
745 $out .=
'<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.
'" />';
746 $out .=
"<tr><td>".$langs->trans(
"MailReply").
"</td><td>".$this->replytoname.($this->replytomail ? (
" <".$this->replytomail.
">") :
"");
747 $out .=
"</td></tr>\n";
752 if (!empty($this->witherrorsto)) {
757 if (!empty($this->withdeliveryreceipt)) {
758 $out .= $this->getHtmlForDeliveryReceipt();
762 if (!empty($this->withtopic)) {
763 $out .= $this->
getHtmlForTopic($arraydefaultmessage, $helpforsubstitution);
767 if (!empty($this->withfile)) {
769 $out .=
'<td>'.$langs->trans(
"MailFile").
'</td>';
773 if ($this->withmaindocfile) {
776 $this->withmaindocfile = (
GETPOST(
'addmaindocfile',
'alpha') ? -1 : 1);
777 } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
779 $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
783 if (!empty($this->withmaindocfile)) {
784 if ($this->withmaindocfile == 1) {
785 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" />';
786 } elseif ($this->withmaindocfile == -1) {
787 $out .=
'<input type="checkbox" id="addmaindocfile" name="addmaindocfile" value="1" checked="checked" />';
789 if (!empty($conf->global->MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND)) {
790 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDocOrLastGenerated").
'.</label><br>';
792 $out .=
' <label for="addmaindocfile">'.$langs->trans(
"JoinMainDoc").
'.</label><br>';
796 if (is_numeric($this->withfile)) {
798 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
799 $out .=
'<script type="text/javascript">';
800 $out .=
'jQuery(document).ready(function () {';
801 $out .=
' jQuery(".removedfile").click(function() {';
802 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
805 $out .=
'</script>'.
"\n";
806 if (count($listofpaths)) {
807 foreach ($listofpaths as $key => $val) {
808 $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
810 if ($conf->entity > 1) {
811 $relativepathtofile = str_replace(
'/'.$conf->entity.
'/',
'/', $relativepathtofile);
814 $formfile_params = array();
815 preg_match(
'#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params);
817 $out .=
'<div id="attachfile_'.$key.
'">';
819 $out .=
img_mime($listofnames[$key]).
' '.$listofnames[$key];
821 $out .= $formfile->showPreview(array(), $formfile_params[2], $formfile_params[4]);
822 if (!$this->withfilereadonly) {
823 $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.
'" />';
826 $out .=
'<br></div>';
828 } elseif (empty($this->withmaindocfile)) {
829 $out .=
'<span class="opacitymedium">'.$langs->trans(
"NoAttachedFiles").
'</span><br>';
831 if ($this->withfile == 2) {
833 $maxmin = $maxfilesizearray[
'maxmin'];
835 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
838 if (!empty($conf->global->FROM_MAIL_USE_INPUT_FILE_MULTIPLE)) {
839 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans(
"Upload").
'" multiple />';
841 $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
844 $out .=
'<input type="submit" class="button" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
847 $out .= $this->withfile;
850 $out .=
"</td></tr>\n";
854 if (!empty($this->withbody)) {
855 $defaultmessage =
GETPOST(
'message',
'restricthtml');
856 if (!
GETPOST(
'modelselected',
'alpha') ||
GETPOST(
'modelmailselected') !=
'-1') {
857 if ($arraydefaultmessage && $arraydefaultmessage->content) {
858 $defaultmessage = $arraydefaultmessage->content;
859 } elseif (!is_numeric($this->withbody)) {
860 $defaultmessage = $this->withbody;
866 $validpaymentmethod = array();
867 if (empty($this->substit[
'__REF__'])) {
871 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
872 $langs->loadLangs(array(
'paypal',
'other'));
873 $typeforonlinepayment =
'free';
874 if ($this->param[
"models"] ==
'order' || $this->param[
"models"] ==
'order_send') {
875 $typeforonlinepayment =
'order';
877 if ($this->param[
"models"] ==
'invoice' || $this->param[
"models"] ==
'facture_send') {
878 $typeforonlinepayment =
'invoice';
880 if ($this->param[
"models"] ==
'member') {
881 $typeforonlinepayment =
'member';
883 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit[
'__REF__']);
886 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
889 if (count($validpaymentmethod) > 0 && $paymenturl) {
890 $langs->load(
'other');
891 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace(
'\n',
"\n", $langs->transnoentities(
"PredefinedMailContentLink", $paymenturl));
892 $this->substit[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
894 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
895 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'';
898 $this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] =
'';
902 $defaultlines = $arraydefaultmessage->content_lines;
903 if (isset($defaultlines)) {
904 foreach ($this->substit_lines as $substit_line) {
908 $this->substit[
'__LINES__'] = $lines;
910 $defaultmessage = str_replace(
'\n',
"\n", $defaultmessage);
913 $atleastonecomponentishtml = 0;
914 if (strpos($defaultmessage,
'__USER_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__USER_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[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
931 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
dol_nl2br($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__']);
934 $defaultmessage =
dol_nl2br($defaultmessage);
939 $defaultmessage =
GETPOST(
"message",
"restricthtml");
943 $defaultmessage = preg_replace(
"/^(<br>)+/",
"", $defaultmessage);
944 $defaultmessage = preg_replace(
"/^\n+/",
"", $defaultmessage);
948 $out .=
'<td class="tdtop">';
949 $out .=
$form->textwithpicto($langs->trans(
'MailText'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltipfrombody');
952 if ($this->withbodyreadonly) {
953 $out .= nl2br($defaultmessage);
954 $out .=
'<input type="hidden" id="message" name="message" value="'.$defaultmessage.
'" />';
956 if (!isset($this->ckeditortoolbar)) {
957 $this->ckeditortoolbar =
'dolibarr_notes';
961 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
962 if ($this->withfckeditor == -1) {
963 if (!empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
964 $this->withfckeditor = 1;
966 $this->withfckeditor = 0;
970 $doleditor =
new DolEditor(
'message', $defaultmessage,
'', 280, $this->ckeditortoolbar,
'In',
true,
true, $this->withfckeditor, 8,
'95%');
971 $out .= $doleditor->Create(1);
973 $out .=
"</td></tr>\n";
976 $out .=
'</table>'.
"\n";
978 if ($this->withform == 1 || $this->withform == -1) {
979 $out .=
'<div class="center">';
980 $out .=
'<input type="submit" class="button button-add" id="sendmail" name="sendmail" value="'.$langs->trans(
"SendMail").
'"';
982 if ($this->withfile == 2 && $conf->use_javascript_ajax) {
983 $out .=
' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans(
"FileWasNotUploaded")).
'\');
return false; }
else {
return true; }
"';
986 if ($this->withcancel) {
987 $out .= '<input class="button button-cancel
" type="submit
" id="cancel
" name="cancel
" value="'.$langs->trans("Cancel").'" />';
989 $out .= '</div>'."\n
";
992 if ($this->withform == 1) {
993 $out .= '</form>'."\n
";
996 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
997 if (!empty($conf->global->MAIN_MAILFORM_DISABLE_ENTERKEY)) {
998 $out .= '<script type="text/javascript
">';
999 $out .= 'jQuery(document).ready(function () {';
1000 $out .= ' $(document).on("keypress
", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1001 var code = e.keyCode || e.which;
1003 console.log("Enter was intercepted and blocked
");
1009 $out .= '</script>';
1012 $out .= "<!-- End form mail -->\n
";
1023 public function getHtmlForTo()
1025 global $langs, $form;
1026 $out = '<tr><td class="fieldrequired
">';
1027 if ($this->withtofree) {
1028 $out .= $form->textwithpicto($langs->trans("MailTo
"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients
"));
1030 $out .= $langs->trans("MailTo
");
1032 $out .= '</td><td>';
1033 if ($this->withtoreadonly) {
1034 if (!empty($this->toname) && !empty($this->tomail)) {
1035 $out .= '<input type="hidden
" id="toname
" name="toname
" value="'.$this->toname.'" />';
1036 $out .= '<input type="hidden
" id="tomail
" name="tomail
" value="'.$this->tomail.'" />';
1037 if ($this->totype == 'thirdparty') {
1038 $soc = new Societe($this->db);
1039 $soc->fetch($this->toid);
1040 $out .= $soc->getNomUrl(1);
1041 } elseif ($this->totype == 'contact') {
1042 $contact = new Contact($this->db);
1043 $contact->fetch($this->toid);
1044 $out .= $contact->getNomUrl(1);
1046 $out .= $this->toname;
1048 $out .= ' <'.$this->tomail.'>';
1049 if ($this->withtofree) {
1050 $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) : "").'" />';
1053 // Note withto may be a text like 'AllRecipientSelected'
1054 $out .= (!is_array($this->withto) && !is_numeric($this->withto)) ? $this->withto : "";
1057 // The free input of email
1058 if (!empty($this->withtofree)) {
1059 $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) : "")).'" />';
1062 if (!empty($this->withto) && is_array($this->withto)) {
1063 if (!empty($this->withtofree)) {
1064 $out .= " ".$langs->trans("and
")."/
".$langs->trans("or
")." ";
1066 // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
1067 $tmparray = $this->withto;
1068 foreach ($tmparray as $key => $val) {
1069 $tmparray[$key] = str_replace(array('<', '>'), array('(', ')'), $tmparray[$key]);
1070 $tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
1073 $withtoselected = GETPOST("receiver
", 'array'); // Array of selected value
1075 if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') {
1076 $withtoselected = array_keys($tmparray);
1079 $out .= $form->multiselectarray("receiver
", $tmparray, $withtoselected, null, null, 'inline-block minwidth500', null, "");
1082 $out .= "</td></tr>\n
";
1091 public function getHtmlForCc()
1093 global $langs, $form;
1095 $out .= $form->textwithpicto($langs->trans("MailCC
"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients
"));
1096 $out .= '</td><td>';
1097 if ($this->withtoccreadonly) {
1098 $out .= (!is_array($this->withtocc) && !is_numeric($this->withtocc)) ? $this->withtocc : "";
1100 $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 : '')).'" />';
1101 if (!empty($this->withtocc) && is_array($this->withtocc)) {
1102 $out .= " ".$langs->trans("and
")."/
".$langs->trans("or
")." ";
1103 // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
1104 $tmparray = $this->withtocc;
1105 foreach ($tmparray as $key => $val) {
1106 $tmparray[$key] = str_replace(array('<', '>'), array('(', ')'), $tmparray[$key]);
1107 $tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
1109 $withtoccselected = GETPOST("receivercc
", 'array'); // Array of selected value
1110 $out .= $form->multiselectarray("receivercc
", $tmparray, $withtoccselected, null, null, 'inline-block minwidth500', null, "");
1113 $out .= "</td></tr>\n
";
1122 public function getHtmlForWithCcc()
1124 global $conf, $langs, $form;
1126 $out .= $form->textwithpicto($langs->trans("MailCCC
"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients
"));
1127 $out .= '</td><td>';
1128 if (!empty($this->withtocccreadonly)) {
1129 $out .= (!is_array($this->withtoccc) && !is_numeric($this->withtoccc)) ? $this->withtoccc : "";
1131 $out .= '<input class="minwidth200
" id="sendtoccc
" name="sendtoccc
" value="'.(GETPOSTISSET("sendtoccc") ? GETPOST("sendtoccc", "alpha") : ((!is_array($this->withtoccc) && !is_numeric($this->withtoccc)) ? $this->withtoccc : '')).'" />';
1132 if (!empty($this->withtoccc) && is_array($this->withtoccc)) {
1133 $out .= " ".$langs->trans("and
")."/
".$langs->trans("or
")." ";
1134 // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
1135 $tmparray = $this->withtoccc;
1136 foreach ($tmparray as $key => $val) {
1137 $tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
1139 $withtocccselected = GETPOST("receiverccc
", 'array'); // Array of selected value
1140 $out .= $form->multiselectarray("receiverccc
", $tmparray, $withtocccselected, null, null, null, null, "90%
");
1145 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) && !empty($this->param['models']) && $this->param['models'] == 'propal_send') {
1146 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO;
1148 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) && !empty($this->param['models']) && $this->param['models'] == 'order_send') {
1149 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO;
1151 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) && !empty($this->param['models']) && $this->param['models'] == 'facture_send') {
1152 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO;
1154 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) && !empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') {
1155 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO;
1157 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO) && !empty($this->param['models']) && $this->param['models'] == 'order_supplier_send') {
1158 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO;
1160 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO) && !empty($this->param['models']) && $this->param['models'] == 'invoice_supplier_send') {
1161 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO;
1163 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_PROJECT_TO) && !empty($this->param['models']) && $this->param['models'] == 'project') {
1164 $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_PROJECT_TO;
1167 $out .= ' + '.$showinfobcc;
1169 $out .= "</td></tr>\n
";
1178 public function getHtmlForWithErrorsTo()
1180 global $conf, $langs;
1181 //if (! $this->errorstomail) $this->errorstomail=$this->frommail;
1182 $errorstomail = (!empty($conf->global->MAIN_MAIL_ERRORS_TO) ? $conf->global->MAIN_MAIL_ERRORS_TO : $this->errorstomail);
1183 if ($this->witherrorstoreadonly) {
1184 $out = '<tr><td>'.$langs->trans("MailErrorsTo
").'</td><td>';
1185 $out .= '<input type="hidden
" id="errorstomail
" name="errorstomail
" value="'.$errorstomail.'" />';
1186 $out .= $errorstomail;
1187 $out .= "</td></tr>\n
";
1189 $out = '<tr><td>'.$langs->trans("MailErrorsTo
").'</td><td>';
1190 $out .= '<input size="30
" id="errorstomail
" name="errorstomail
" value="'.$errorstomail.'" />';
1191 $out .= "</td></tr>\n
";
1201 public function getHtmlForDeliveryreceipt()
1203 global $conf, $langs, $form;
1204 $out = '<tr><td>'.$langs->trans("DeliveryReceipt
").'</td><td>';
1206 if (!empty($this->withdeliveryreceiptreadonly)) {
1207 $out .= yn($this->withdeliveryreceipt);
1209 $defaultvaluefordeliveryreceipt = 0;
1210 if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_PROPAL) && !empty($this->param['models']) && $this->param['models'] == 'propal_send') {
1211 $defaultvaluefordeliveryreceipt = 1;
1213 if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_PROPOSAL) && !empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') {
1214 $defaultvaluefordeliveryreceipt = 1;
1216 if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_ORDER) && !empty($this->param['models']) && $this->param['models'] == 'order_send') {
1217 $defaultvaluefordeliveryreceipt = 1;
1219 if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_INVOICE) && !empty($this->param['models']) && $this->param['models'] == 'facture_send') {
1220 $defaultvaluefordeliveryreceipt = 1;
1222 if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_ORDER) && !empty($this->param['models']) && $this->param['models'] == 'order_supplier_send') {
1223 $defaultvaluefordeliveryreceipt = 1;
1225 $out .= $form->selectyesno('deliveryreceipt', (GETPOSTISSET("deliveryreceipt
") ? GETPOST("deliveryreceipt
") : $defaultvaluefordeliveryreceipt), 1);
1227 $out .= "</td></tr>\n
";
1238 public function getHtmlForTopic($arraydefaultmessage, $helpforsubstitution)
1240 global $conf, $langs, $form;
1242 $defaulttopic = GETPOST('subject', 'restricthtml');
1244 if (!GETPOST('modelselected', 'alpha') || GETPOST('modelmailselected') != '-1') {
1245 if ($arraydefaultmessage && $arraydefaultmessage->topic) {
1246 $defaulttopic = $arraydefaultmessage->topic;
1247 } elseif (!is_numeric($this->withtopic)) {
1248 $defaulttopic = $this->withtopic;
1252 $defaulttopic = make_substitutions($defaulttopic, $this->substit);
1255 $out .= '<td class="fieldrequired
">';
1256 $out .= $form->textwithpicto($langs->trans('MailTopic'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltipfromtopic');
1259 if ($this->withtopicreadonly) {
1260 $out .= $defaulttopic;
1261 $out .= '<input type="hidden
" class="quatrevingtpercent
" id="subject
" name="subject
" value="'.$defaulttopic.'" />';
1263 $out .= '<input type="text
" class="quatrevingtpercent
" id="subject
" name="subject
" value="'.((GETPOSTISSET("subject") && !GETPOST('modelselected
')) ? GETPOST("subject") : ($defaulttopic ? $defaulttopic : '')).'" />';
1265 $out .= "</td></tr>\n
";
1282 public function getEMailTemplate($dbs, $type_template, $user, $outputlangs, $id = 0, $active = 1, $label = '')
1284 global $conf, $langs;
1286 $ret = new ModelMail();
1288 if ($id == -2 && empty($label)) {
1289 $this->error = 'LabelIsMandatoryWhenIdIs-2';
1293 $languagetosearch = (is_object($outputlangs) ? $outputlangs->defaultlang : '');
1294 // Define $languagetosearchmain to fall back on main language (for example to get 'es_ES' for 'es_MX')
1295 $tmparray = explode('_', $languagetosearch);
1296 $languagetosearchmain = $tmparray[0].'_'.strtoupper($tmparray[0]);
1297 if ($languagetosearchmain == $languagetosearch) {
1298 $languagetosearchmain = '';
1301 $sql = "SELECT
rowid, module, label, type_template, topic, joinfiles, content, content_lines, lang
";
1302 $sql .= " FROM
".$dbs->prefix().'c_email_templates';
1303 $sql .= " WHERE (type_template=
'".$dbs->escape($type_template)."' OR type_template=
'all')
";
1304 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1305 $sql .= " AND (
private = 0 OR fk_user =
".((int) $user->id).")
"; // Get all public or private owned
1307 $sql .= " AND active =
".((int) $active);
1310 $sql .= " AND label =
'".$dbs->escape($label)."'";
1312 if (!($id > 0) && $languagetosearch) {
1313 $sql .= " AND (lang =
'".$dbs->escape($languagetosearch)."'".($languagetosearchmain ? " OR lang =
'".$dbs->escape($languagetosearchmain)."'" : "")." OR lang IS NULL OR lang =
'')
";
1316 $sql .= " AND
rowid=
".(int) $id;
1319 $sql .= " AND position=0
";
1321 if ($languagetosearch) {
1322 $sql .= $dbs->order("position,lang,label
", "ASC,DESC,ASC
"); // We want line with lang set first, then with lang null or ''
1324 $sql .= $dbs->order("position,lang,label
", "ASC,ASC,ASC
"); // If no language provided, we give priority to lang not defined
1326 //$sql .= $dbs->plimit(1);
1329 $resql = $dbs->query($sql);
1331 dol_print_error($dbs);
1337 $obj = $dbs->fetch_object($resql);
1340 // If template is for a module, check module is enabled; if not, take next template
1342 $tempmodulekey = $obj->module;
1343 if (empty($conf->$tempmodulekey) || empty($conf->$tempmodulekey->enabled)) {
1348 // If a record was found
1349 $ret->id = $obj->rowid;
1350 $ret->module = $obj->module;
1351 $ret->label = $obj->label;
1352 $ret->lang = $obj->lang;
1353 $ret->topic = $obj->topic;
1354 $ret->content = $obj->content;
1355 $ret->content_lines = $obj->content_lines;
1356 $ret->joinfiles = $obj->joinfiles;
1360 // If no record found
1362 // Not found with the provided label
1365 // If there is no template at all
1366 $defaultmessage = '';
1368 if ($type_template == 'body') {
1369 // Special case to use this->withbody as content
1370 $defaultmessage = $this->withbody;
1371 } elseif ($type_template == 'facture_send') {
1372 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoice
");
1373 } elseif ($type_template == 'facture_relance') {
1374 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoiceReminder
");
1375 } elseif ($type_template == 'propal_send') {
1376 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendProposal
");
1377 } elseif ($type_template == 'supplier_proposal_send') {
1378 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierProposal
");
1379 } elseif ($type_template == 'order_send') {
1380 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendOrder
");
1381 } elseif ($type_template == 'order_supplier_send') {
1382 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder
");
1383 } elseif ($type_template == 'invoice_supplier_send') {
1384 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice
");
1385 } elseif ($type_template == 'shipping_send') {
1386 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendShipping
");
1387 } elseif ($type_template == 'fichinter_send') {
1388 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendFichInter
");
1389 } elseif ($type_template == 'actioncomm_send') {
1390 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendActionComm
");
1391 } elseif ($type_template == 'thirdparty') {
1392 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentThirdparty
");
1393 } elseif (!empty($type_template)) {
1394 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentGeneric
");
1397 $ret->label = 'default';
1398 $ret->lang = $outputlangs->defaultlang;
1400 $ret->joinfiles = 1;
1401 $ret->content = $defaultmessage;
1402 $ret->content_lines = '';
1423 public function isEMailTemplate($type_template, $user, $outputlangs)
1425 $sql = "SELECT label, topic, content, lang
";
1426 $sql .= " FROM
".$this->db->prefix().'c_email_templates';
1427 $sql .= " WHERE type_template=
'".$this->db->escape($type_template)."'";
1428 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1429 $sql .= " AND (fk_user is NULL or fk_user = 0 or fk_user =
".((int) $user->id).")
";
1430 if (is_object($outputlangs)) {
1431 $sql .= " AND (lang =
'".$this->db->escape($outputlangs->defaultlang)."' OR lang IS NULL OR lang =
'')
";
1433 $sql .= $this->db->order("lang,label
", "ASC
");
1436 $resql = $this->db->query($sql);
1438 $num = $this->db->num_rows($resql);
1439 $this->db->free($resql);
1442 $this->error = get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1457 public function fetchAllEMailTemplate($type_template, $user, $outputlangs, $active = 1)
1461 $sql = "SELECT
rowid, module, label, topic, content, content_lines, lang, fk_user,
private, position
";
1462 $sql .= " FROM
".$this->db->prefix().'c_email_templates';
1463 $sql .= " WHERE type_template IN (
'".$this->db->escape($type_template)."',
'all')
";
1464 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1465 $sql .= " AND (
private = 0 OR fk_user =
".((int) $user->id).")
"; // See all public templates or templates I own.
1467 $sql .= " AND active =
".((int) $active);
1469 //if (is_object($outputlangs)) $sql.= " AND (lang =
'".$this->db->escape($outputlangs->defaultlang)."' OR lang IS NULL OR lang =
'')
"; // Return all languages
1470 $sql .= $this->db->order("position,lang,label
", "ASC
");
1473 $resql = $this->db->query($sql);
1475 $num = $this->db->num_rows($resql);
1476 $this->lines_model = array();
1477 while ($obj = $this->db->fetch_object($resql)) {
1478 // If template is for a module, check module is enabled.
1480 $tempmodulekey = $obj->module;
1481 if (empty($conf->$tempmodulekey) || empty($conf->$tempmodulekey->enabled)) {
1486 $line = new ModelMail();
1487 $line->id = $obj->rowid;
1488 $line->label = $obj->label;
1489 $line->lang = $obj->lang;
1490 $line->fk_user = $obj->fk_user;
1491 $line->private = $obj->private;
1492 $line->position = $obj->position;
1493 $line->topic = $obj->topic;
1494 $line->content = $obj->content;
1495 $line->content_lines = $obj->content_lines;
1497 $this->lines_model[] = $line;
1499 $this->db->free($resql);
1502 $this->error = get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1517 public function setSubstitFromObject($object, $outputlangs)
1519 global $conf, $user, $extrafields;
1521 $parameters = array();
1522 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1523 complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
1525 $this->substit = $tmparray;
1527 // Fill substit_lines with each object lines content
1528 if (is_array($object->lines)) {
1529 foreach ($object->lines as $line) {
1530 $substit_line = array(
1531 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
1532 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
1533 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
1534 '__LABEL__' => isset($line->label) ? $line->label : '',
1535 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
1536 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', 0, $outputlangs),
1537 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', 0, $outputlangs),
1538 '__QUANTITY__' => $line->qty,
1539 '__SUBPRICE__' => price($line->subprice),
1540 '__AMOUNT__' => price($line->total_ttc),
1541 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
1544 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
1545 if (!empty($line->fk_product)) {
1546 if (!is_object($extrafields)) {
1547 $extrafields = new ExtraFields($this->db);
1549 $product = new Product($this->db);
1550 $product->fetch($line->fk_product, '', '', 1);
1551 $product->fetch_optionals();
1553 $extrafields->fetch_name_optionals_label($product->table_element, true);
1555 if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
1556 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
1557 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = isset($product->array_options['options_'.$key]) ? $product->array_options['options_'.$key] : '';
1561 $this->substit_lines[] = $substit_line;
1574 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
1576 global $conf, $langs;
1578 $tmparray = array();
1579 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') {
1580 $parameters = array('mode'=>$mode);
1581 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
1582 complete_substitutions_array($tmparray, $langs, null, $parameters);
1584 if ($mode == 'formwithlines') {
1585 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
1587 if ($mode == 'formforlines') {
1588 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
1592 if ($mode == 'emailing') {
1593 $parameters = array('mode'=>$mode);
1594 $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
1595 complete_substitutions_array($tmparray, $langs, null, $parameters);
1597 // For mass emailing, we have different keys
1598 $tmparray['__ID__'] = 'IdRecord';
1599 $tmparray['__THIRDPARTY_CUSTOMER_CODE__'] = 'CustomerCode';
1600 $tmparray['__EMAIL__'] = 'EMailRecipient';
1601 $tmparray['__LASTNAME__'] = 'Lastname';
1602 $tmparray['__FIRSTNAME__'] = 'Firstname';
1603 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
1604 $tmparray['__OTHER1__'] = 'Other1';
1605 $tmparray['__OTHER2__'] = 'Other2';
1606 $tmparray['__OTHER3__'] = 'Other3';
1607 $tmparray['__OTHER4__'] = 'Other4';
1608 $tmparray['__OTHER5__'] = 'Other5';
1609 $tmparray['__USER_SIGNATURE__'] = 'TagSignature';
1610 $tmparray['__CHECK_READ__'] = 'TagCheckMail';
1611 $tmparray['__UNSUBSCRIBE__'] = 'TagUnsubscribe';
1612 //,'__PERSONALIZED__' => 'Personalized' // Hidden because not used yet in mass emailing
1614 $onlinepaymentenabled = 0;
1615 if (!empty($conf->paypal->enabled)) {
1616 $onlinepaymentenabled++;
1618 if (!empty($conf->paybox->enabled)) {
1619 $onlinepaymentenabled++;
1621 if (!empty($conf->stripe->enabled)) {
1622 $onlinepaymentenabled++;
1624 if ($onlinepaymentenabled && !empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
1625 $tmparray['__SECUREKEYPAYMENT__'] = $conf->global->PAYMENT_SECURITY_TOKEN;
1626 if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
1627 if (!empty($conf->adherent->enabled)) {
1628 $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
1630 if (!empty($conf->don->enabled)) {
1631 $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation';
1633 if (isModEnabled('facture')) {
1634 $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
1636 if (!empty($conf->commande->enabled)) {
1637 $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
1639 if (!empty($conf->contrat->enabled)) {
1640 $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
1643 //Online payement link
1644 if (!empty($conf->adherent->enabled)) {
1645 $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember';
1647 if (!empty($conf->don->enabled)) {
1648 $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation';
1650 if (isModEnabled('facture')) {
1651 $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice';
1653 if (!empty($conf->commande->enabled)) {
1654 $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder';
1656 if (!empty($conf->contrat->enabled)) {
1657 $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine';
1661 /* No need to show into tooltip help, option is not enabled
1662 $vars['__SECUREKEYPAYMENT__']='';
1663 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
1664 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
1665 $vars['__SECUREKEYPAYMENT_ORDER__']='';
1666 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
1669 if (!empty($conf->global->MEMBER_ENABLE_PUBLIC)) {
1670 $substitutionarray['__PUBLICLINK_NEWMEMBERFORM__'] = 'BlankSubscriptionForm';
1674 foreach ($tmparray as $key => $val) {
1676 $tmparray[$key] = $key;
1721 public $content_lines;