28 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
74 public $fromalsorobot;
124 public $withmaindocfile;
127 public $withfromreadonly;
128 public $withreplytoreadonly;
129 public $withtoreadonly;
130 public $withtoccreadonly;
131 public $withtocccreadonly;
132 public $withtopicreadonly;
133 public $withfilereadonly;
134 public $withdeliveryreceipt;
136 public $withfckeditor;
138 public $substit = array();
139 public $substit_lines = array();
140 public $param = array();
142 public $withtouser = array();
143 public $withtoccuser = array();
161 $this->withtofree = 1;
163 $this->withtoccc = 0;
164 $this->witherrorsto = 0;
165 $this->withtopic = 1;
167 $this->withmaindocfile = 0;
170 $this->withfromreadonly = 1;
171 $this->withreplytoreadonly = 1;
172 $this->withtoreadonly = 0;
173 $this->withtoccreadonly = 0;
174 $this->withtocccreadonly = 0;
175 $this->witherrorstoreadonly = 0;
176 $this->withtopicreadonly = 0;
177 $this->withfilereadonly = 0;
178 $this->withbodyreadonly = 0;
179 $this->withdeliveryreceiptreadonly = 0;
180 $this->withfckeditor = -1;
193 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
196 $vardir = $conf->user->dir_output.
"/".$user->id;
197 $upload_dir = $vardir.
'/temp/';
200 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
201 unset($_SESSION[
"listofpaths".$keytoavoidconflict]);
202 unset($_SESSION[
"listofnames".$keytoavoidconflict]);
203 unset($_SESSION[
"listofmimes".$keytoavoidconflict]);
218 $listofpaths = array();
219 $listofnames = array();
220 $listofmimes = array();
222 if (empty($file)) $file = basename($path);
225 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
226 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
227 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
228 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
229 if (!in_array($file, $listofnames))
231 $listofpaths[] = $path;
232 $listofnames[] = $file;
233 $listofmimes[] = $type;
234 $_SESSION[
"listofpaths".$keytoavoidconflict] = join(
';', $listofpaths);
235 $_SESSION[
"listofnames".$keytoavoidconflict] = join(
';', $listofnames);
236 $_SESSION[
"listofmimes".$keytoavoidconflict] = join(
';', $listofmimes);
250 $listofpaths = array();
251 $listofnames = array();
252 $listofmimes = array();
254 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
255 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
256 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
257 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
258 if ($keytodelete >= 0)
260 unset($listofpaths[$keytodelete]);
261 unset($listofnames[$keytodelete]);
262 unset($listofmimes[$keytodelete]);
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])) $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
285 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
286 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
287 return array(
'paths'=>$listofpaths,
'names'=>$listofnames,
'mimes'=>$listofmimes);
301 public function show_form($addfileaction =
'addfile', $removefileaction =
'removefile')
318 public function get_form($addfileaction =
'addfile', $removefileaction =
'removefile')
321 global $conf, $langs, $user, $hookmanager, $form;
324 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
325 $formfile =
new Formfile($this->
db);
327 if (!is_object($form)) $form =
new Form($this->
db);
330 $langs->loadLangs(array(
'other',
'mails'));
333 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelselected') &&
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1')) {
338 $hookmanager->initHooks(array(
'formmail'));
341 'addfileaction' => $addfileaction,
342 'removefileaction'=> $removefileaction,
343 'trackid'=> $this->trackid
345 $reshook = $hookmanager->executeHooks(
'getFormMail', $parameters, $this);
347 if (!empty($reshook))
349 return $hookmanager->resPrint;
353 $disablebademails = 1;
356 $outputlangs = $langs;
358 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $this->param[
'langsmodels'];
359 if (!empty($newlang))
362 $outputlangs->setDefaultLang($newlang);
363 $outputlangs->load(
'other');
367 $arraydefaultmessage = -1;
368 if ($this->param[
'models'] !=
'none')
371 if (array_key_exists(
'models_id', $this->param))
373 $model_id = $this->param[
"models_id"];
376 $arraydefaultmessage = $this->
getEMailTemplate($this->
db, $this->param[
"models"], $user, $outputlangs, $model_id);
380 $listofpaths = array();
381 $listofnames = array();
382 $listofmimes = array();
383 $keytoavoidconflict = empty($this->trackid) ?
'' :
'-'.$this->trackid;
385 if (
GETPOST(
'mode',
'alpha') ==
'init' || (
GETPOST(
'modelmailselected',
'alpha') &&
GETPOST(
'modelmailselected',
'alpha') !=
'-1'))
387 if (!empty($arraydefaultmessage->joinfiles) && is_array($this->param[
'fileinit']))
389 foreach ($this->param[
'fileinit'] as $file)
396 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
397 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
398 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
401 $out .=
"\n".
'<!-- Begin form mail type='.$this->param[
"models"].
' --><div id="mailformdiv"></div>'.
"\n";
402 if ($this->withform == 1)
404 $out .=
'<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param[
"returnurl"].
'#formmail">'.
"\n";
406 $out .=
'<a id="formmail" name="formmail"></a>';
407 $out .=
'<input style="display:none" type="submit" id="sendmail" name="sendmail">';
408 $out .=
'<input type="hidden" name="token" value="'.newToken().
'" />';
409 $out .=
'<input type="hidden" name="trackid" value="'.$this->trackid.
'" />';
411 if (!empty($this->withfrom))
413 if (!empty($this->withfromreadonly))
415 $out .=
'<input type="hidden" id="fromname" name="fromname" value="'.$this->fromname.
'" />';
416 $out .=
'<input type="hidden" id="frommail" name="frommail" value="'.$this->frommail.
'" />';
419 foreach ($this->param as $key=>$value)
421 if (is_array($value)) {
422 $out .=
"<!-- param key=".$key.
" is array, we do not output input filed for it -->\n";
424 $out .=
'<input type="hidden" id="'.$key.
'" name="'.$key.
'" value="'.$value.
'" />'.
"\n";
428 $modelmail_array = array();
429 if ($this->param[
'models'] !=
'none')
437 $langs->trans(
"members");
438 foreach ($this->lines_model as $line)
441 if (preg_match(
'/\((.*)\)/', $line->label, $reg)) {
442 $labeltouse = $langs->trans($reg[1]);
444 $labeltouse = $line->label;
449 if ($line->lang) $modelmail_array[$line->id] .=
' '.picto_from_langcode($line->lang);
450 if ($line->private) $modelmail_array[$line->id] .=
' - <span class="opacitymedium">'.dol_escape_htmltag($langs->trans(
"Private")).
'</span>';
455 if (count($modelmail_array) > 0)
457 $model_mail_selected_id =
GETPOSTISSET(
'modelmailselected') ?
GETPOST(
'modelmailselected',
'int') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0);
460 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
462 $out .=
'<span class="opacitymedium">'.$langs->trans(
'SelectMailModel').
':</span> ';
463 $out .= $this->
selectarray(
'modelmailselected', $modelmail_array, $model_mail_selected_id, 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth100', 1,
'', 0, 1);
464 if ($user->admin) $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
466 $out .=
'<input class="button" type="submit" value="'.$langs->trans(
'Apply').
'" name="modelselected" id="modelselected">';
469 } elseif (!empty($this->param[
'models']) && in_array($this->param[
'models'], array(
470 'propal_send',
'order_send',
'facture_send',
471 'shipping_send',
'fichinter_send',
'supplier_proposal_send',
'order_supplier_send',
472 'invoice_supplier_send',
'thirdparty',
'contract',
'user',
'recruitmentcandidature_send',
'all'
476 $out .=
'<div class="center" style="padding: 0px 0 12px 0">'.
"\n";
477 $out .= $langs->trans(
'SelectMailModel').
': <select name="modelmailselected" disabled="disabled"><option value="none">'.$langs->trans(
"NoTemplateDefined").
'</option></select>';
478 if ($user->admin) $out .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv(
'Setup').
' - '.$langs->transnoentitiesnoconv(
'EMails')), 1);
480 $out .=
'<input class="button" type="submit" value="'.$langs->trans(
'Apply').
'" name="modelselected" disabled="disabled" id="modelselected">';
484 $out .=
'<!-- No template available for $this->param["models"] = '.$this->param[
'models'].
' -->';
488 $out .=
'<table class="tableforemailform boxtablenotop" width="100%">'.
"\n";
491 $helpforsubstitution =
'';
492 if (is_array($this->substit) && count($this->substit)) $helpforsubstitution .= $langs->trans(
'AvailableVariables').
' :<br>'.
"\n";
493 foreach ($this->substit as $key => $val)
497 if (!empty($this->withsubstit))
499 $out .=
'<tr><td colspan="2" class="right">';
501 if (is_numeric($this->withsubstit)) $out .= $form->textwithpicto($langs->trans(
"EMailTestSubstitutionReplacedByGenericValues"), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltip');
502 else $out .= $form->textwithpicto($langs->trans(
'AvailableVariables'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltip');
503 $out .=
"</td></tr>\n";
513 if (!empty($this->withfrom))
515 if (!empty($this->withfromreadonly))
517 $out .=
'<tr><td class="fieldrequired minwidth200">'.$langs->trans(
"MailFrom").
'</td><td>';
520 if (!($this->fromtype ===
'user' && $this->fromid > 0)
521 && !($this->fromtype ===
'company')
522 && !($this->fromtype ===
'robot')
523 && !preg_match(
'/user_aliases/', $this->fromtype)
524 && !preg_match(
'/global_aliases/', $this->fromtype)
525 && !preg_match(
'/senderprofile/', $this->fromtype)
529 $out .= $this->fromname;
532 $out .=
' <'.$this->frommail.
'>';
536 $langs->load(
'errors');
537 $out .=
'<span class="warning"> <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'> </span>';
544 if (empty($user->email))
546 $langs->load(
'errors');
547 $liste[
'user'] = $user->getFullName($langs).
' <'.$langs->trans(
'ErrorNoMailDefinedForThisUser').
'>';
549 $liste[
'user'] = $user->getFullName($langs).
' <'.$user->email.
'>';
553 $liste[
'company'] = $conf->global->MAIN_INFO_SOCIETE_NOM.
' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.
'>';
556 $listaliases = array(
'user_aliases'=>$user->email_aliases,
'global_aliases'=>$conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES);
559 if (!empty($this->fromalsorobot))
561 if (!empty($conf->global->MAIN_MAIL_EMAIL_FROM) && $conf->global->MAIN_MAIL_EMAIL_FROM != $conf->global->MAIN_INFO_SOCIETE_MAIL)
563 $liste[
'robot'] = $conf->global->MAIN_MAIL_EMAIL_FROM;
566 $liste[
'robot'] .=
' <'.$conf->global->MAIN_MAIL_EMAIL_FROM.
'>';
572 $sql =
'SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.
'c_email_senderprofile';
573 $sql .=
' WHERE active = 1 AND (private = 0 OR private = '.$user->id.
')';
574 $sql .=
' ORDER BY position';
582 $obj = $this->
db->fetch_object(
$resql);
585 $listaliases[
'senderprofile_'.$obj->rowid] = $obj->label.
' <'.$obj->email.
'>';
591 foreach ($listaliases as $typealias => $listalias)
594 $listaliasarray = explode(
',', $listalias);
595 foreach ($listaliasarray as $listaliasval)
598 $listaliasval = trim($listaliasval);
601 $listaliasval = preg_replace(
'/</',
'<', $listaliasval);
602 $listaliasval = preg_replace(
'/>/',
'>', $listaliasval);
603 if (!preg_match(
'/</', $listaliasval)) $listaliasval =
'<'.$listaliasval.
'>';
604 $liste[$typealias.
'_'.$posalias] = $listaliasval;
611 $reshook = $hookmanager->executeHooks(
'getDefaultFromEmail', $parameters, $this);
614 $defaultfrom = $this->fromtype;
616 if (!empty($hookmanager->resArray[
'defaultfrom'])) $defaultfrom = $hookmanager->resArray[
'defaultfrom'];
620 $out .=
' '.$form->selectarray(
'fromtype', $liste, $defaultfrom, 0, 0, 0,
'', 0, 0, 0,
'',
'fromforsendingprofile maxwidth200onsmartphone', 0,
'', $disablebademails);
623 $out .=
"</td></tr>\n";
625 $out .=
'<tr><td class="fieldrequired width200">'.$langs->trans(
"MailFrom").
"</td><td>";
626 $out .= $langs->trans(
"Name").
':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.
'" />';
627 $out .=
' ';
628 $out .= $langs->trans(
"EMail").
':<<input type="text" id="frommail" name="frommail" class="maxwidth200onsmartphone" value="'.$this->frommail.
'" />>';
629 $out .=
"</td></tr>\n";
634 if (!empty($this->withto) || is_array($this->withto))
636 $out .=
'<tr><td class="fieldrequired">';
637 if ($this->withtofree) $out .= $form->textwithpicto($langs->trans(
"MailTo"), $langs->trans(
"YouCanUseCommaSeparatorForSeveralRecipients"));
638 else $out .= $langs->trans(
"MailTo");
640 if ($this->withtoreadonly)
642 if (!empty($this->toname) && !empty($this->tomail))
644 $out .=
'<input type="hidden" id="toname" name="toname" value="'.$this->toname.
'" />';
645 $out .=
'<input type="hidden" id="tomail" name="tomail" value="'.$this->tomail.
'" />';
646 if ($this->totype ==
'thirdparty')
649 $soc->fetch($this->toid);
650 $out .= $soc->getNomUrl(1);
651 } elseif ($this->totype ==
'contact')
654 $contact->fetch($this->toid);
655 $out .= $contact->getNomUrl(1);
657 $out .= $this->toname;
659 $out .=
' <'.$this->tomail.
'>';
660 if ($this->withtofree)
662 $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) :
"").
'" />';
666 $out .= (!is_array($this->withto) && !is_numeric($this->withto)) ? $this->withto :
"";
670 if (!empty($this->withtofree))
672 $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) :
"")).
'" />';
675 if (!empty($this->withto) && is_array($this->withto))
677 if (!empty($this->withtofree)) $out .=
" ".$langs->trans(
"and").
"/".$langs->trans(
"or").
" ";
679 $tmparray = $this->withto;
680 foreach ($tmparray as $key => $val)
685 $withtoselected =
GETPOST(
"receiver",
'array');
687 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend')
689 $withtoselected = array_keys($tmparray);
691 $out .= $form->multiselectarray(
"receiver", $tmparray, $withtoselected, null, null,
'inline-block minwidth500', null,
"");
694 $out .=
"</td></tr>\n";
698 if (!empty($this->withtouser) && is_array($this->withtouser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT))
701 $out .= $langs->trans(
"MailToUsers");
705 $tmparray = $this->withtouser;
706 foreach ($tmparray as $key => $val)
710 $withtoselected =
GETPOST(
"receiveruser",
'array');
711 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend')
713 $withtoselected = array_keys($tmparray);
715 $out .= $form->multiselectarray(
"receiveruser", $tmparray, $withtoselected, null, null,
'inline-block minwidth500', null,
"");
716 $out .=
"</td></tr>\n";
720 if (!empty($this->withoptiononeemailperrecipient))
722 $out .=
'<tr><td class="minwidth200">';
723 $out .= $langs->trans(
"GroupEmails");
725 $out .=
' <input type="checkbox" name="oneemailperrecipient"'.($this->withoptiononeemailperrecipient > 0 ?
' checked="checked"' :
'').
'> ';
726 $out .= $langs->trans(
"OneEmailPerRecipient");
727 $out .=
'<span class="hideonsmartphone">';
729 $out .= $langs->trans(
"WarningIfYouCheckOneRecipientPerEmail");
731 $out .=
'</td></tr>';
735 if (!empty($this->withtocc) || is_array($this->withtocc))
738 $out .= $form->textwithpicto($langs->trans(
"MailCC"), $langs->trans(
"YouCanUseCommaSeparatorForSeveralRecipients"));
740 if ($this->withtoccreadonly)
742 $out .= (!is_array($this->withtocc) && !is_numeric($this->withtocc)) ? $this->withtocc :
"";
744 $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 :
'')).
'" />';
745 if (!empty($this->withtocc) && is_array($this->withtocc))
747 $out .=
" ".$langs->trans(
"and").
"/".$langs->trans(
"or").
" ";
749 $tmparray = $this->withtocc;
750 foreach ($tmparray as $key => $val)
754 $withtoccselected =
GETPOST(
"receivercc",
'array');
755 $out .= $form->multiselectarray(
"receivercc", $tmparray, $withtoccselected, null, null,
'inline-block minwidth500', null,
"");
758 $out .=
"</td></tr>\n";
762 if (!empty($this->withtoccuser) && is_array($this->withtoccuser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT))
765 $out .= $langs->trans(
"MailToCCUsers");
769 $tmparray = $this->withtoccuser;
770 foreach ($tmparray as $key => $val)
774 $withtoselected =
GETPOST(
"receiverccuser",
'array');
775 if (empty($withtoselected) && count($tmparray) == 1 &&
GETPOST(
'action',
'aZ09') ==
'presend')
777 $withtoselected = array_keys($tmparray);
779 $out .= $form->multiselectarray(
"receiverccuser", $tmparray, $withtoselected, null, null,
'inline-block minwidth500', null,
"");
780 $out .=
"</td></tr>\n";
784 if (!empty($this->withtoccc) || is_array($this->withtoccc)) {
789 if (!empty($this->withreplyto))
791 if ($this->withreplytoreadonly)
793 $out .=
'<input type="hidden" id="replyname" name="replyname" value="'.$this->replytoname.
'" />';
794 $out .=
'<input type="hidden" id="replymail" name="replymail" value="'.$this->replytomail.
'" />';
795 $out .=
"<tr><td>".$langs->trans(
"MailReply").
"</td><td>".$this->replytoname.($this->replytomail ? (
" <".$this->replytomail.
">") :
"");
796 $out .=
"</td></tr>\n";
801 if (!empty($this->witherrorsto)) {
806 if (!empty($this->withdeliveryreceipt)) {
807 $out .= $this->getHtmlForDeliveryReceipt();
811 if (!empty($this->withtopic)) {
812 $out .= $this->
getHtmlForTopic($arraydefaultmessage, $helpforsubstitution);
816 if (!empty($this->withfile))
819 $out .=
'<td>'.$langs->trans(
"MailFile").
'</td>';
823 if ($this->withmaindocfile)
827 $this->withmaindocfile = (
GETPOST(
'addmaindocfile',
'alpha') ? -1 : 1);
830 elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0)
832 $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1);
836 if (!empty($this->withmaindocfile))
838 if ($this->withmaindocfile == 1)
840 $out .=
'<input type="checkbox" name="addmaindocfile" value="1" />';
842 if ($this->withmaindocfile == -1)
844 $out .=
'<input type="checkbox" name="addmaindocfile" value="1" checked="checked" />';
846 $out .=
' '.$langs->trans(
"JoinMainDoc").
'.<br>';
849 if (is_numeric($this->withfile))
852 $out .=
'<input type="hidden" class="removedfilehidden" name="removedfile" value="">'.
"\n";
853 $out .=
'<script type="text/javascript" language="javascript">';
854 $out .=
'jQuery(document).ready(function () {';
855 $out .=
' jQuery(".removedfile").click(function() {';
856 $out .=
' jQuery(".removedfilehidden").val(jQuery(this).val());';
859 $out .=
'</script>'.
"\n";
860 if (count($listofpaths))
862 foreach ($listofpaths as $key => $val)
864 $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val)));
865 if ($conf->entity > 1) {
866 $relativepathtofile = str_replace($conf->entity.
'/',
'', $relativepathtofile);
869 $formfile_params = array();
870 preg_match(
'#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params);
872 $out .=
'<div id="attachfile_'.$key.
'">';
874 $out .=
img_mime($listofnames[$key]).
' '.$listofnames[$key];
875 $out .= $formfile->showPreview(array(), $formfile_params[2], $formfile_params[4]);
876 if (!$this->withfilereadonly)
878 $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.
'" />';
881 $out .=
'<br></div>';
883 } elseif (empty($this->withmaindocfile))
885 $out .= $langs->trans(
"NoAttachedFiles").
'<br>';
887 if ($this->withfile == 2)
889 if (!empty($conf->global->FROM_MAIL_USE_INPUT_FILE_MULTIPLE)) $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans(
"Upload").
'" multiple />';
890 else $out .=
'<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans(
"Upload").
'" />';
892 $out .=
'<input class="button" type="submit" id="'.$addfileaction.
'" name="'.$addfileaction.
'" value="'.$langs->trans(
"MailingAddFile").
'" />';
895 $out .= $this->withfile;
898 $out .=
"</td></tr>\n";
902 if (!empty($this->withbody))
904 $defaultmessage =
GETPOST(
'message',
'restricthtml');
905 if (!
GETPOST(
'modelselected',
'alpha') ||
GETPOST(
'modelmailselected') !=
'-1')
907 if ($arraydefaultmessage && $arraydefaultmessage->content) {
908 $defaultmessage = $arraydefaultmessage->content;
909 } elseif (!is_numeric($this->withbody)) {
910 $defaultmessage = $this->withbody;
915 $paymenturl =
''; $validpaymentmethod = array();
916 if (empty($this->substit[
'__REF__']))
921 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
922 $langs->loadLangs(array(
'paypal',
'other'));
923 $typeforonlinepayment =
'free';
924 if ($this->param[
"models"] ==
'order' || $this->param[
"models"] ==
'order_send') $typeforonlinepayment =
'order';
925 if ($this->param[
"models"] ==
'invoice' || $this->param[
"models"] ==
'facture_send') $typeforonlinepayment =
'invoice';
926 if ($this->param[
"models"] ==
'member') $typeforonlinepayment =
'member';
927 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit[
'__REF__']);
930 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
933 if (count($validpaymentmethod) > 0 && $paymenturl)
935 $langs->load(
'other');
936 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace(
'\n',
"\n", $langs->transnoentities(
"PredefinedMailContentLink", $paymenturl));
937 $this->substit[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
939 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
940 $this->substit[
'__ONLINE_PAYMENT_URL__'] =
'';
943 $this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] =
'';
947 $defaultlines = $arraydefaultmessage->content_lines;
948 if (isset($defaultlines))
950 foreach ($this->substit_lines as $substit_line)
955 $this->substit[
'__LINES__'] = $lines;
957 $defaultmessage = str_replace(
'\n',
"\n", $defaultmessage);
960 $atleastonecomponentishtml = 0;
961 if (strpos($defaultmessage,
'__USER_SIGNATURE__') !==
false &&
dol_textishtml($this->substit[
'__USER_SIGNATURE__'])) {
962 $atleastonecomponentishtml++;
964 if (strpos($defaultmessage,
'__ONLINE_PAYMENT_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
965 $atleastonecomponentishtml++;
967 if (strpos($defaultmessage,
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !==
false &&
dol_textishtml($this->substit[
'__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) {
968 $atleastonecomponentishtml++;
971 $atleastonecomponentishtml++;
973 if ($atleastonecomponentishtml) {
975 $this->substit[
'__USER_SIGNATURE__'] =
dol_nl2br($this->substit[
'__USER_SIGNATURE__']);
977 if (!
dol_textishtml($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'])) {
978 $this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
dol_nl2br($this->substit[
'__ONLINE_PAYMENT_TEXT_AND_URL__']);
981 $defaultmessage =
dol_nl2br($defaultmessage);
985 if (
GETPOSTISSET(
"message") && !$_POST[
'modelselected']) $defaultmessage = $_POST[
"message"];
989 $defaultmessage = preg_replace(
"/^(<br>)+/",
"", $defaultmessage);
990 $defaultmessage = preg_replace(
"/^\n+/",
"", $defaultmessage);
994 $out .=
'<td class="tdtop">';
995 $out .= $form->textwithpicto($langs->trans(
'MailText'), $helpforsubstitution, 1,
'help',
'', 0, 2,
'substittooltipfrombody');
998 if ($this->withbodyreadonly)
1000 $out .= nl2br($defaultmessage);
1001 $out .=
'<input type="hidden" id="message" name="message" value="'.$defaultmessage.
'" />';
1003 if (!isset($this->ckeditortoolbar)) $this->ckeditortoolbar =
'dolibarr_notes';
1006 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1007 if ($this->withfckeditor == -1)
1009 if (!empty($conf->global->FCKEDITOR_ENABLE_MAIL)) $this->withfckeditor = 1;
1010 else $this->withfckeditor = 0;
1013 $doleditor =
new DolEditor(
'message', $defaultmessage,
'', 280, $this->ckeditortoolbar,
'In',
true,
true, $this->withfckeditor, 8,
'95%');
1014 $out .= $doleditor->Create(1);
1016 $out .=
"</td></tr>\n";
1019 $out .=
'</table>'.
"\n";
1021 if ($this->withform == 1 || $this->withform == -1)
1023 $out .=
'<br><div class="center">';
1024 $out .=
'<input class="button" type="submit" id="sendmail" name="sendmail" value="'.$langs->trans(
"SendMail").
'"';
1026 if ($this->withfile == 2 && $conf->use_javascript_ajax)
1028 $out .=
' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans(
"FileWasNotUploaded")).
'\');
return false; }
else {
return true; }
"';
1031 if ($this->withcancel)
1033 $out .= ' ';
1034 $out .= '<input class="button button-cancel
" type="submit
" id="cancel
" name="cancel
" value="'.$langs->trans("Cancel").'" />';
1036 $out .= '</div>'."\n";
1039 if ($this->withform == 1) $out .= '</form>'."\n";
1041 // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
1042 if (!empty($conf->global->MAIN_MAILFORM_DISABLE_ENTERKEY))
1044 $out .= '<script type="text/javascript
" language="javascript
">';
1045 $out .= 'jQuery(document).ready(function () {';
1046 $out .= ' $(document).on("keypress
", \'#mailform\', function (e) { /* Note this is called at every key pressed ! */
1047 var code = e.keyCode || e.which;
1049 console.log("Enter was intercepted and blocked
");
1055 $out .= '</script>';
1058 $out .= "<!-- End form mail -->\n
";
1069 public function getHtmlForWithCcc()
1071 global $conf, $langs, $form;
1073 $out .= $form->textwithpicto($langs->trans("MailCCC
"), $langs->trans("YouCanUseCommaSeparatorForSeveralRecipients
"));
1074 $out .= '</td><td>';
1075 if (!empty($this->withtocccreadonly)) {
1076 $out .= (!is_array($this->withtoccc) && !is_numeric($this->withtoccc)) ? $this->withtoccc : "";
1078 $out .= '<input class="minwidth200
" id="sendtoccc
" name="sendtoccc
" value="'.(GETPOSTISSET("sendtoccc") ? GETPOST("sendtoccc", "alpha") : ((!is_array($this->withtoccc) && !is_numeric($this->withtoccc)) ? $this->withtoccc : '')).'" />';
1079 if (!empty($this->withtoccc) && is_array($this->withtoccc)) {
1080 $out .= " ".$langs->trans("and
")."/
".$langs->trans("or
")." ";
1081 // multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
1082 $tmparray = $this->withtoccc;
1083 foreach ($tmparray as $key => $val) {
1084 $tmparray[$key] = dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
1086 $withtocccselected = GETPOST("receiverccc
", 'array'); // Array of selected value
1087 $out .= $form->multiselectarray("receiverccc
", $tmparray, $withtocccselected, null, null, null, null, "90%
");
1092 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) && !empty($this->param['models']) && $this->param['models'] == 'propal_send') $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO;
1093 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) && !empty($this->param['models']) && $this->param['models'] == 'order_send') $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO;
1094 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) && !empty($this->param['models']) && $this->param['models'] == 'facture_send') $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO;
1095 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) && !empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO;
1096 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO) && !empty($this->param['models']) && $this->param['models'] == 'order_supplier_send') $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO;
1097 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO) && !empty($this->param['models']) && $this->param['models'] == 'invoice_supplier_send') $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO;
1098 if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_PROJECT_TO) && !empty($this->param['models']) && $this->param['models'] == 'project') $showinfobcc = $conf->global->MAIN_MAIL_AUTOCOPY_PROJECT_TO;
1099 if ($showinfobcc) $out .= ' + '.$showinfobcc;
1100 $out .= "</td></tr>
\n";
1109 public function getHtmlForWithErrorsTo()
1111 global $conf, $langs;
1112 //if (! $this->errorstomail) $this->errorstomail=$this->frommail;
1113 $errorstomail = (!empty($conf->global->MAIN_MAIL_ERRORS_TO) ? $conf->global->MAIN_MAIL_ERRORS_TO : $this->errorstomail);
1114 if ($this->witherrorstoreadonly) {
1115 $out = '<tr><td>'.$langs->trans("MailErrorsTo
").'</td><td>';
1116 $out .= '<input type="hidden
" id="errorstomail
" name="errorstomail
" value="'.$errorstomail.'" />';
1117 $out .= $errorstomail;
1118 $out .= "</td></tr>
\n";
1120 $out = '<tr><td>'.$langs->trans("MailErrorsTo
").'</td><td>';
1121 $out .= '<input size="30
" id="errorstomail
" name="errorstomail
" value="'.$errorstomail.'" />';
1122 $out .= "</td></tr>
\n";
1132 public function getHtmlForDeliveryreceipt()
1134 global $conf, $langs, $form;
1135 $out = '<tr><td>'.$langs->trans("DeliveryReceipt
").'</td><td>';
1137 if (!empty($this->withdeliveryreceiptreadonly)) {
1138 $out .= yn($this->withdeliveryreceipt);
1140 $defaultvaluefordeliveryreceipt = 0;
1141 if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_PROPAL) && !empty($this->param['models']) && $this->param['models'] == 'propal_send') $defaultvaluefordeliveryreceipt = 1;
1142 if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_PROPOSAL) && !empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') $defaultvaluefordeliveryreceipt = 1;
1143 if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_ORDER) && !empty($this->param['models']) && $this->param['models'] == 'order_send') $defaultvaluefordeliveryreceipt = 1;
1144 if (!empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_INVOICE) && !empty($this->param['models']) && $this->param['models'] == 'facture_send') $defaultvaluefordeliveryreceipt = 1;
1145 $out .= $form->selectyesno('deliveryreceipt', (GETPOSTISSET("deliveryreceipt
") ? GETPOST("deliveryreceipt
") : $defaultvaluefordeliveryreceipt), 1);
1147 $out .= "</td></tr>
\n";
1158 public function getHtmlForTopic($arraydefaultmessage, $helpforsubstitution)
1160 global $conf, $langs, $form;
1162 $defaulttopic = GETPOST('subject', 'restricthtml');
1163 if (!GETPOST('modelselected', 'alpha') || GETPOST('modelmailselected') != '-1') {
1164 if ($arraydefaultmessage && $arraydefaultmessage->topic) {
1165 $defaulttopic = $arraydefaultmessage->topic;
1166 } elseif (!is_numeric($this->withtopic)) {
1167 $defaulttopic = $this->withtopic;
1171 $defaulttopic = make_substitutions($defaulttopic, $this->substit);
1174 $out .= '<td class="fieldrequired
">';
1175 $out .= $form->textwithpicto($langs->trans('MailTopic'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltipfromtopic');
1178 if ($this->withtopicreadonly) {
1179 $out .= $defaulttopic;
1180 $out .= '<input type="hidden
" class="quatrevingtpercent
" id="subject
" name="subject
" value="'.$defaulttopic.'" />';
1182 $out .= '<input type="text
" class="quatrevingtpercent
" id="subject
" name="subject
" value="'.((GETPOSTISSET("subject") && !GETPOST('modelselected
')) ? GETPOST("subject") : ($defaulttopic ? $defaulttopic : '')).'" />';
1184 $out .= "</td></tr>
\n";
1201 public function getEMailTemplate($db, $type_template, $user, $outputlangs, $id = 0, $active = 1, $label = '')
1205 $ret = new ModelMail();
1207 if ($id == -2 && empty($label)) {
1208 $this->error = 'LabelIsMandatoryWhenIdIs-2';
1212 $languagetosearch = (is_object($outputlangs) ? $outputlangs->defaultlang : '');
1213 // Define $languagetosearchmain to fall back on main language (for example to get 'es_ES' for 'es_MX')
1214 $tmparray = explode('_', $languagetosearch);
1215 $languagetosearchmain = $tmparray[0].'_'.strtoupper($tmparray[0]);
1216 if ($languagetosearchmain == $languagetosearch) $languagetosearchmain = '';
1218 $sql = "SELECT
rowid, module, label, type_template, topic, joinfiles, content, content_lines, lang
";
1219 $sql .= " FROM
".MAIN_DB_PREFIX.'c_email_templates';
1220 $sql .= " WHERE (type_template=
'".$db->escape($type_template)."' OR type_template=
'all')
";
1221 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1222 $sql .= " AND (
private = 0 OR fk_user =
".$user->id.")
"; // Get all public or private owned
1223 if ($active >= 0) $sql .= " AND active =
".$active;
1224 if ($label) $sql .= " AND label =
'".$db->escape($label)."'";
1225 if (!($id > 0) && $languagetosearch) $sql .= " AND (lang =
'".$db->escape($languagetosearch)."'".($languagetosearchmain ? " OR lang =
'".$db->escape($languagetosearchmain)."'" : "")." OR lang IS NULL OR lang =
'')
";
1226 if ($id > 0) $sql .= " AND rowid=
".$id;
1227 if ($id == -1) $sql .= " AND position=0
";
1228 if ($languagetosearch) $sql .= $db->order("position,lang,label
", "ASC,DESC,ASC
"); // We want line with lang set first, then with lang null or ''
1229 else $sql .= $db->order("position,lang,label
", "ASC,ASC,ASC
"); // If no language provided, we give priority to lang not defined
1230 //$sql .= $db->plimit(1);
1233 $resql = $db->query($sql);
1236 dol_print_error($db);
1242 $obj = $db->fetch_object($resql);
1245 // If template is for a module, check module is enabled; if not, take next template
1247 $tempmodulekey = $obj->module;
1248 if (empty($conf->$tempmodulekey) || empty($conf->$tempmodulekey->enabled)) {
1253 // If a record was found
1254 $ret->id = $obj->rowid;
1255 $ret->module = $obj->module;
1256 $ret->label = $obj->label;
1257 $ret->lang = $obj->lang;
1258 $ret->topic = $obj->topic;
1259 $ret->content = $obj->content;
1260 $ret->content_lines = $obj->content_lines;
1261 $ret->joinfiles = $obj->joinfiles;
1265 // If no record found
1267 // Not found with the provided label
1270 // If there is no template at all
1271 $defaultmessage = '';
1273 if ($type_template == 'body') {
1274 // Special case to use this->withbody as content
1275 $defaultmessage = $this->withbody;
1276 } elseif ($type_template == 'facture_send') {
1277 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoice
");
1278 } elseif ($type_template == 'facture_relance') {
1279 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendInvoiceReminder
");
1280 } elseif ($type_template == 'propal_send') {
1281 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendProposal
");
1282 } elseif ($type_template == 'supplier_proposal_send') {
1283 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierProposal
");
1284 } elseif ($type_template == 'order_send') {
1285 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendOrder
");
1286 } elseif ($type_template == 'order_supplier_send') {
1287 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder
");
1288 } elseif ($type_template == 'invoice_supplier_send') {
1289 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice
");
1290 } elseif ($type_template == 'shipping_send') {
1291 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendShipping
");
1292 } elseif ($type_template == 'fichinter_send') {
1293 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendFichInter
");
1294 } elseif ($type_template == 'actioncomm_send') {
1295 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentSendActionComm
");
1296 } elseif ($type_template == 'thirdparty') {
1297 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentThirdparty
");
1298 } elseif (!empty($type_template)) {
1299 $defaultmessage = $outputlangs->transnoentities("PredefinedMailContentGeneric
");
1302 $ret->label = 'default';
1303 $ret->lang = $outputlangs->defaultlang;
1305 $ret->joinfiles = 1;
1306 $ret->content = $defaultmessage;
1307 $ret->content_lines = '';
1327 public function isEMailTemplate($type_template, $user, $outputlangs)
1329 $sql = "SELECT label, topic, content, lang
";
1330 $sql .= " FROM
".MAIN_DB_PREFIX.'c_email_templates';
1331 $sql .= " WHERE type_template=
'".$this->db->escape($type_template)."'";
1332 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1333 $sql .= " AND (fk_user is NULL or fk_user = 0 or fk_user =
".$user->id.")
";
1334 if (is_object($outputlangs)) $sql .= " AND (lang =
'".$this->db->escape($outputlangs->defaultlang)."' OR lang IS NULL OR lang =
'')
";
1335 $sql .= $this->db->order("lang,label
", "ASC
");
1338 $resql = $this->db->query($sql);
1341 $num = $this->db->num_rows($resql);
1342 $this->db->free($resql);
1345 $this->error = get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1360 public function fetchAllEMailTemplate($type_template, $user, $outputlangs, $active = 1)
1364 $sql = "SELECT
rowid, module, label, topic, content, content_lines, lang, fk_user,
private, position
";
1365 $sql .= " FROM
".MAIN_DB_PREFIX.'c_email_templates';
1366 $sql .= " WHERE type_template IN (
'".$this->db->escape($type_template)."',
'all')
";
1367 $sql .= " AND entity IN (
".getEntity('c_email_templates').")
";
1368 $sql .= " AND (
private = 0 OR fk_user =
".$user->id.")
"; // See all public templates or templates I own.
1369 if ($active >= 0) $sql .= " AND active =
".$active;
1370 //if (is_object($outputlangs)) $sql.= " AND (lang =
'".$this->db->escape($outputlangs->defaultlang)."' OR lang IS NULL OR lang =
'')
"; // Return all languages
1371 $sql .= $this->db->order("position,lang,label
", "ASC
");
1374 $resql = $this->db->query($sql);
1377 $num = $this->db->num_rows($resql);
1378 $this->lines_model = array();
1379 while ($obj = $this->db->fetch_object($resql))
1381 // If template is for a module, check module is enabled.
1383 $tempmodulekey = $obj->module;
1384 if (empty($conf->$tempmodulekey) || empty($conf->$tempmodulekey->enabled)) {
1389 $line = new ModelMail();
1390 $line->id = $obj->rowid;
1391 $line->label = $obj->label;
1392 $line->lang = $obj->lang;
1393 $line->fk_user = $obj->fk_user;
1394 $line->private = $obj->private;
1395 $line->position = $obj->position;
1396 $line->topic = $obj->topic;
1397 $line->content = $obj->content;
1398 $line->content_lines = $obj->content_lines;
1400 $this->lines_model[] = $line;
1402 $this->db->free($resql);
1405 $this->error = get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1420 public function setSubstitFromObject($object, $outputlangs)
1422 global $conf, $user, $extrafields;
1424 $parameters = array();
1425 $tmparray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1426 complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
1428 $this->substit = $tmparray;
1430 // Fill substit_lines with each object lines content
1431 if (is_array($object->lines))
1433 foreach ($object->lines as $line)
1435 $substit_line = array(
1436 '__PRODUCT_REF__' => isset($line->product_ref) ? $line->product_ref : '',
1437 '__PRODUCT_LABEL__' => isset($line->product_label) ? $line->product_label : '',
1438 '__PRODUCT_DESCRIPTION__' => isset($line->product_desc) ? $line->product_desc : '',
1439 '__LABEL__' => isset($line->label) ? $line->label : '',
1440 '__DESCRIPTION__' => isset($line->desc) ? $line->desc : '',
1441 '__DATE_START_YMD__' => dol_print_date($line->date_start, 'day', 0, $outputlangs),
1442 '__DATE_END_YMD__' => dol_print_date($line->date_end, 'day', 0, $outputlangs),
1443 '__QUANTITY__' => $line->qty,
1444 '__SUBPRICE__' => price($line->subprice),
1445 '__AMOUNT__' => price($line->total_ttc),
1446 '__AMOUNT_EXCL_TAX__' => price($line->total_ht)
1449 // Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
1450 if (!empty($line->fk_product))
1452 if (!is_object($extrafields)) $extrafields = new ExtraFields($this->db);
1453 $extrafields->fetch_name_optionals_label('product', true);
1454 $product = new Product($this->db);
1455 $product->fetch($line->fk_product, '', '', 1);
1456 $product->fetch_optionals();
1457 if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0)
1459 foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) {
1460 $substit_line['__PRODUCT_EXTRAFIELD_'.strtoupper($key).'__'] = $product->array_options['options_'.$key];
1464 $this->substit_lines[] = $substit_line;
1477 public static function getAvailableSubstitKey($mode = 'formemail', $object = null)
1479 global $conf, $langs;
1481 $tmparray = array();
1482 if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines')
1484 $parameters = array('mode'=>$mode);
1485 $tmparray = getCommonSubstitutionArray($langs, 2, null, $object); // Note: On email templated edition, this is null because it is related to all type of objects
1486 complete_substitutions_array($tmparray, $langs, null, $parameters);
1488 if ($mode == 'formwithlines')
1490 $tmparray['__LINES__'] = '__LINES__'; // Will be set by the get_form function
1492 if ($mode == 'formforlines')
1494 $tmparray['__QUANTITY__'] = '__QUANTITY__'; // Will be set by the get_form function
1498 if ($mode == 'emailing')
1500 $parameters = array('mode'=>$mode);
1501 $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
1502 complete_substitutions_array($tmparray, $langs, null, $parameters);
1504 // For mass emailing, we have different keys
1505 $tmparray['__ID__'] = 'IdRecord';
1506 $tmparray['__EMAIL__'] = 'EMailRecipient';
1507 $tmparray['__LASTNAME__'] = 'Lastname';
1508 $tmparray['__FIRSTNAME__'] = 'Firstname';
1509 $tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
1510 $tmparray['__OTHER1__'] = 'Other1';
1511 $tmparray['__OTHER2__'] = 'Other2';
1512 $tmparray['__OTHER3__'] = 'Other3';
1513 $tmparray['__OTHER4__'] = 'Other4';
1514 $tmparray['__OTHER5__'] = 'Other5';
1515 $tmparray['__USER_SIGNATURE__'] = 'TagSignature';
1516 $tmparray['__CHECK_READ__'] = 'TagCheckMail';
1517 $tmparray['__UNSUBSCRIBE__'] = 'TagUnsubscribe';
1518 //,'__PERSONALIZED__' => 'Personalized' // Hidden because not used yet in mass emailing
1520 $onlinepaymentenabled = 0;
1521 if (!empty($conf->paypal->enabled)) $onlinepaymentenabled++;
1522 if (!empty($conf->paybox->enabled)) $onlinepaymentenabled++;
1523 if (!empty($conf->stripe->enabled)) $onlinepaymentenabled++;
1524 if ($onlinepaymentenabled && !empty($conf->global->PAYMENT_SECURITY_TOKEN))
1526 $tmparray['__SECUREKEYPAYMENT__'] = $conf->global->PAYMENT_SECURITY_TOKEN;
1527 if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
1529 if ($conf->adherent->enabled) $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember';
1530 if ($conf->facture->enabled) $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice';
1531 if ($conf->commande->enabled) $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder';
1532 if ($conf->contrat->enabled) $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine';
1535 /* No need to show into tooltip help, option is not enabled
1536 $vars['__SECUREKEYPAYMENT__']='';
1537 $vars['__SECUREKEYPAYMENT_MEMBER__']='';
1538 $vars['__SECUREKEYPAYMENT_INVOICE__']='';
1539 $vars['__SECUREKEYPAYMENT_ORDER__']='';
1540 $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
1545 foreach ($tmparray as $key => $val)
1547 if (empty($val)) $tmparray[$key] = $key;
1572 public $content_lines;
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
</td >< tdcolspan="3">< spanclass="opacitymedium"></span ></td ></tr >< trclass="liste_total"> CREANCES DETTES< tdcolspan="3"class="right"></td >< tdcolspan="3"class="right"></td ></tr > CREANCES DETTES RECETTES DEPENSES trips CREANCES DETTES Y m expensereport p date_valid Y m expensereport pe datep $db idate($date_start)."' AND $column < p rowid
dol_htmlentities($string, $flags=null, $encoding= 'UTF-8', $double_encode=false)
Replace htmlentities functions.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
img_mime($file, $titlealt= '', $morecss= '')
Show MIME img of a file.
$conf db
API class for accounts.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_mimetype($file, $default= 'application/octet-stream', $mode=0)
Return mime type of a file.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories) ...
Class to manage translations.
dolGetFirstLineOfText($text, $nboflines=1, $charset= 'UTF-8')
Return first line of text.
print
Draft customers invoices.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
print $_SERVER["PHP_SELF"] n
Edit parameters.
Class to manage a WYSIWYG editor.
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
dol_textishtml($msg, $option=0)
Return if a text is a html content.