40require
'../main.inc.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
53require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
54require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
55require_once DOL_DOCUMENT_ROOT.
'/core/class/cemailtemplate.class.php';
58$langsArray = array(
"errors",
"admin",
"mails",
"languages");
61 $langsArray[] =
'members';
64 $langsArray[] =
'eventorganization';
67$langs->loadLangs($langsArray);
69$toselect =
GETPOST(
'toselect',
'array:int');
70$action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'view';
71$massaction =
GETPOST(
'massaction',
'alpha');
72$confirm =
GETPOST(
'confirm',
'alpha');
74$optioncss =
GETPOST(
'optioncss',
'alpha');
75$backtopage =
GETPOST(
'backtopage');
76$contextpage =
GETPOST(
'contextpage',
'aZ09');
79$search_label =
GETPOST(
'search_label',
'alphanohtml');
80$search_type_template =
GETPOST(
'search_type_template',
'alpha');
81$search_lang =
GETPOST(
'search_lang',
'alpha');
82$defaulttemplatelang = $langs->defaultlang;
87 $defaulttemplatelang = $templatelangs->defaultlang;
89$search_fk_user =
GETPOST(
'search_fk_user',
'intcomma');
90$search_topic =
GETPOST(
'search_topic',
'alpha');
91$search_module =
GETPOST(
'search_module',
'alpha');
93$search_position =
GETPOST(
'search_position',
'int');
101$actl[0] = img_picto($langs->trans(
"Disabled"),
'switch_off',
'class="size15x"');
102$actl[1] = img_picto($langs->trans(
"Activated"),
'switch_on',
'class="size15x"');
105$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
106$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
108if (empty($page) || $page == -1) {
111$offset = $limit * $page;
112$pageprev = $page - 1;
113$pagenext = $page + 1;
115if (empty($sortfield)) {
116 $sortfield =
'type_template,lang,position,label';
118if (empty($sortorder)) {
123$hookmanager->initHooks(array(
'emailtemplates'));
129$arrayfields = array();
130foreach (
$object->fields as $key => $val) {
132 if (!empty($val[
'visible'])) {
133 $visible = (int)
dol_eval((
string) $val[
'visible'], 1);
134 $arrayfields[$tableprefix.
'.'.$key] = array(
135 'label' => $val[
'label'],
136 'checked' => (($visible < 0) ?
'0' :
'1'),
137 'enabled' => (string) (int) (abs($visible) != 3 && (bool)
dol_eval((string) $val[
'enabled'], 1)),
138 'position' => $val[
'position'],
139 'help' => isset($val[
'help']) ? $val[
'help'] :
''
144$arrayfields[
't.lang'][
'enabled'] = (string)
getDolGlobalInt(
'MAIN_MULTILANGS');
146 $arrayfields[
't.lang'][
'checked'] =
'0';
150if (!empty($user->socid)) {
155$permissiontoedit = ($user->admin ? 1 : 0);
156$permissiontodelete = ($user->admin ? 1 : 0);
160 $result = $tmpmailtemplate->fetch($rowid);
161 if ($tmpmailtemplate->fk_user == $user->id) {
162 $permissiontoedit = 1;
163 $permissiontodelete = 1;
171$tabname[25] = MAIN_DB_PREFIX.
"c_email_templates";
176$tabfield[25] =
"label,lang,type_template,fk_user,private,position,module,topic,joinfiles,defaultfortype,content";
178 $tabfield[25] .=
',content_lines';
183$tabfieldvalue = array();
184$tabfieldvalue[25] =
"label,lang,type_template,fk_user,private,position,topic,email_from,joinfiles,defaultfortype,content";
186 $tabfieldvalue[25] .=
',email_to';
189 $tabfieldvalue[25] .=
',email_tocc';
192 $tabfieldvalue[25] .=
',email_tobcc';
195 $tabfieldvalue[25] .=
',content_lines';
200$tabfieldinsert = array();
201$tabfieldinsert[25] =
"label,lang,type_template,fk_user,private,position,topic,email_from,joinfiles,defaultfortype,content,datec";
203 $tabfieldvalue[25] .=
',email_to';
206 $tabfieldvalue[25] .=
',email_tocc';
209 $tabfieldvalue[25] .=
',email_tobcc';
212 $tabfieldinsert[25] .=
',content_lines';
214$tabfieldinsert[25] .=
',entity';
218require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
220 $targetobject = fetchObjectByElement(0, $tmpmailtemplate->type_template);
224 $tmp[
'__(AnyTranslationKey)__'] =
'Translation';
225 $helpsubstit = $langs->trans(
"AvailableVariables").
':<br>';
226 $helpsubstitforlines = $langs->trans(
"AvailableVariables").
':<br>';
227 foreach ($tmp as $key => $val) {
228 $helpsubstit .= $key.
' -> '.$val.
'<br>';
229 $helpsubstitforlines .= $key.
' -> '.$val.
'<br>';
232 $targetobject = fetchObjectByElement(0, $tmpmailtemplate->type_template);
236 $tmp[
'__(AnyTranslationKey)__'] =
'Translation';
237 $helpsubstit = $langs->trans(
"AvailableVariables").
':<br>';
238 $helpsubstitforlines = $langs->trans(
"AvailableVariables").
':<br>';
239 foreach ($tmp as $key => $val) {
240 $helpsubstit .= $key.
' -> '.$val.
'<br>';
243 foreach ($tmp as $key => $val) {
244 $helpsubstitforlines .= $key.
' -> '.$val.
'<br>';
251 'label' => $langs->trans(
'EnterAnyCode'),
252 'type_template' => $langs->trans(
"TemplateForElement"),
253 'private' => $langs->trans(
"TemplateIsVisibleByOwnerOnly"),
254 'position' => $langs->trans(
"PositionIntoComboList"),
255 'topic' =>
'<span class="small">'.$helpsubstit.
'</span>',
256 'email_from' => $langs->trans(
'ForceEmailFrom'),
257 'email_to' => $langs->trans(
'MailTo'),
258 'email_tocc' => $langs->trans(
'MailCC'),
259 'email_tobcc' => $langs->trans(
'MailCCC'),
260 'joinfiles' => $langs->trans(
'AttachMainDocByDefault'),
261 'defaultfortype' => $langs->trans(
"DefaultForTypeDesc"),
262 'content' =>
'<span class="small">'.$helpsubstit.
'</span>',
263 'content_lines' =>
'<span class="small">'.$helpsubstitforlines.
'</span>'
268$elementList = array();
271$elementList[
'all'] =
'-- '.dol_escape_htmltag($langs->trans(
"All")).
' --';
272$elementList[
'none'] =
'-- '.dol_escape_htmltag($langs->trans(
"None")).
' --';
273$elementList[
'user'] = img_picto(
'',
'user',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToUser'));
274if (
isModEnabled(
'member') && $user->hasRight(
'adherent',
'lire')) {
275 $elementList[
'member'] = img_picto(
'',
'object_member',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToMember'));
277if (
isModEnabled(
'recruitment') && $user->hasRight(
'recruitment',
'recruitmentjobposition',
'read')) {
278 $elementList[
'recruitmentcandidature_send'] = img_picto(
'',
'recruitmentcandidature',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'RecruitmentCandidatures'));
280if (
isModEnabled(
'expensereport') && $user->hasRight(
'expensereport',
'lire')) {
281 $elementList[
'expensereport_send'] = img_picto(
'',
'trip',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendExpenseReport'));
283if (
isModEnabled(
'holiday') && $user->hasRight(
'holiday',
'read')) {
284 $elementList[
'holiday'] = img_picto(
'',
'holiday',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendLeaves'));
286if (
isModEnabled(
"societe") && $user->hasRight(
'societe',
'lire')) {
287 $elementList[
'thirdparty'] = img_picto(
'',
'company',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToThirdparty'));
289if (
isModEnabled(
"societe") && $user->hasRight(
'societe',
'contact',
'lire')) {
290 $elementList[
'contact'] = img_picto(
'',
'contact',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToContact'));
293 $elementList[
'project'] = img_picto(
'',
'project',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToProject'));
295if (
isModEnabled(
"propal") && $user->hasRight(
'propal',
'lire')) {
296 $elementList[
'propal_send'] = img_picto(
'',
'propal',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendProposal'));
298if (
isModEnabled(
'order') && $user->hasRight(
'commande',
'lire')) {
299 $elementList[
'order_send'] = img_picto(
'',
'order',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendOrder'));
301if (
isModEnabled(
'invoice') && $user->hasRight(
'facture',
'lire')) {
302 $elementList[
'facture_send'] = img_picto(
'',
'bill',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendInvoice'));
305 $elementList[
'shipping_send'] = img_picto(
'',
'dolly',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendShipment'));
306 $elementList[
'delivery_send'] = img_picto(
'',
'dolly',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendDelivery'));
309 $elementList[
'reception_send'] = img_picto(
'',
'dollyrevert',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendReception'));
312 $elementList[
'fichinter_send'] = img_picto(
'',
'intervention',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendIntervention'));
315 $elementList[
'supplier_proposal_send'] = img_picto(
'',
'propal',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendSupplierRequestForQuotation'));
317if (
isModEnabled(
"supplier_order") && ($user->hasRight(
'fournisseur',
'commande',
'lire') || $user->hasRight(
'supplier_order',
'read'))) {
318 $elementList[
'order_supplier_send'] = img_picto(
'',
'order',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendSupplierOrder'));
320if (
isModEnabled(
"supplier_invoice") && ($user->hasRight(
'fournisseur',
'facture',
'lire') || $user->hasRight(
'supplier_invoice',
'read'))) {
321 $elementList[
'invoice_supplier_send'] = img_picto(
'',
'bill',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendSupplierInvoice'));
323if (
isModEnabled(
"supplier_invoice") && ($user->hasRight(
'fournisseur',
'facture',
'creer') || $user->hasRight(
"supplier_invoice",
"write"))) {
324 $elementList[
'supplier_payment_send'] = img_picto(
'',
'bill',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'SuppliersPayment'));
326if (
isModEnabled(
'contract') && $user->hasRight(
'contrat',
'lire')) {
327 $elementList[
'contract'] = img_picto(
'',
'contract',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendContract'));
329if (
isModEnabled(
'ticket') && $user->hasRight(
'ticket',
'read')) {
330 $elementList[
'ticket_send'] = img_picto(
'',
'ticket',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToTicket'));
333 $elementList[
'actioncomm_send'] = img_picto(
'',
'action',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendEventPush'));
335if (
isModEnabled(
'eventorganization') && $user->hasRight(
'project',
'read')) {
336 $elementList[
'conferenceorbooth'] = img_picto(
'',
'action',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendEventOrganization'));
338if (
isModEnabled(
'partnership') && $user->hasRight(
'partnership',
'read')) {
339 $elementList[
'partnership_send'] = img_picto(
'',
'partnership',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToPartnership'));
341if (
isModEnabled(
'product') && $user->hasRight(
'produit',
'lire')) {
342 $elementList[
'product_send'] = img_picto(
'',
'product',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'Product'));
345 $elementList[
'stocktransfer_send'] =
'<span class="fas fa-box-open em080 valignmiddle pictomodule paddingrightonly" style="color: #a69944;"></span>'.dol_escape_htmltag($langs->trans(
'MailToSendStockTransfer'));
348$parameters = array(
'elementList' => $elementList);
349$reshook = $hookmanager->executeHooks(
'emailElementlist', $parameters);
351 foreach ($hookmanager->resArray as $item => $value) {
352 $elementList[$item] = $value;
365if (
GETPOST(
'cancel',
'alpha') ||
GETPOST(
'actioncancel',
'alpha')) {
369 if (!empty($backtopage)) {
370 header(
"Location: ".$backtopage);
374if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') {
378$parameters = array();
380$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
382 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
385if (empty($reshook)) {
387 include DOL_DOCUMENT_ROOT.
'/core/actions_changeselectedfields.inc.php';
390 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
393 $search_type_template =
'';
395 $search_fk_user =
'';
398 $search_private = -1;
399 $search_position =
'';
400 $search_joinfiles = -1;
401 $search_defaultfortype = -1;
403 $search_array_options = array();
407 if ((
GETPOST(
'actionadd',
'alpha') && $permissiontoadd) || (
GETPOST(
'actionmodify',
'alpha') && $permissiontoedit)) {
408 $listfield = explode(
',', str_replace(
' ',
'', $tabfield[25]));
409 $listfieldinsert = explode(
',', $tabfieldinsert[25]);
410 $listfieldmodify = explode(
',', $tabfieldvalue[25]);
411 $listfieldvalue = explode(
',', $tabfieldvalue[25]);
415 foreach ($listfield as $f => $value) {
417 if (in_array($value, [
'joinfiles',
'defaultfortype',
'content',
'content_lines',
'module',
'tms',
'datec',
'email_to',
'email_tocc',
'email_tobcc'])) {
422 if (
GETPOST(
'actionmodify',
'alpha') && $value ==
'topic') {
423 $_POST[
'topic'] =
GETPOST(
'topic-'.$rowid);
426 if ((!
GETPOSTISSET($value) ||
GETPOST($value) ==
'' ||
GETPOST($value) ==
'-1') && $value !=
'lang' && $value !=
'fk_user' && $value !=
'position') {
428 $fieldnamekey = $listfield[$f];
430 if ($fieldnamekey ==
'libelle' || ($fieldnamekey ==
'label')) {
431 $fieldnamekey =
'Code';
433 if ($fieldnamekey ==
'code') {
434 $fieldnamekey =
'Code';
436 if ($fieldnamekey ==
'note') {
437 $fieldnamekey =
'Note';
439 if ($fieldnamekey ==
'type_template') {
440 $fieldnamekey =
'TypeOfTemplate';
442 if ($fieldnamekey ==
'fk_user') {
443 $fieldnamekey =
'Owner';
445 if ($fieldnamekey ==
'private') {
446 $fieldnamekey =
'Private';
448 if ($fieldnamekey ==
'position') {
449 $fieldnamekey =
'Position';
451 if ($fieldnamekey ==
'topic') {
452 $fieldnamekey =
'Topic';
455 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->transnoentities($fieldnamekey)),
null,
'errors');
461 if ($ok &&
GETPOST(
'actionadd')) {
463 $sql =
"INSERT INTO ".$db->sanitize($tabname[25]).
" (";
465 $sql .= $tabfieldinsert[25];
466 $sql .=
", active, enabled)";
472 foreach ($listfieldinsert as $f => $value) {
473 $keycode = isset($listfieldvalue[$i]) ? $listfieldvalue[$i] :
"";
474 if ($value ==
'lang') {
475 $keycode =
'langcode';
477 if (empty($keycode)) {
482 if ($value ==
'entity') {
483 $_POST[$keycode] =
$conf->entity;
485 if ($value ==
'fk_user' && !($_POST[$keycode] > 0)) {
486 $_POST[$keycode] =
'';
488 if ($value ==
'private' && !is_numeric($_POST[$keycode])) {
489 $_POST[$keycode] =
'0';
491 if ($value ==
'position' && !is_numeric($_POST[$keycode])) {
492 $_POST[$keycode] =
'1';
494 if ($value ==
'defaultfortype' && !is_numeric($_POST[$keycode])) {
495 $_POST[$keycode] =
'0';
503 $sql .=
"'".$db->escape($defaulttemplatelang).
"'";
504 } elseif ($keycode ==
'datec') {
505 $sql .=
"'".$db->idate($now).
"'";
506 } elseif (
GETPOST($keycode) ==
'' && $keycode !=
'langcode') {
508 } elseif ($keycode ==
'langcode' && (
GETPOST($keycode) ==
'0' ||
GETPOST($keycode) ==
'-1')) {
510 } elseif ($keycode ==
'fk_user') {
512 $sql .=
" ".((int) $user->id);
514 $sql .=
" ".(GETPOSTINT($keycode));
516 } elseif ($keycode ==
'content') {
517 $sql .=
"'".$db->escape(
GETPOST($keycode,
'restricthtml')).
"'";
518 } elseif (in_array($keycode, array(
'joinfiles',
'defaultfortype',
'private',
'position',
'entity'))) {
521 $sql .=
"'".$db->escape(
GETPOST($keycode,
'alphanohtml')).
"'";
528 $result = $db->query($sql);
530 setEventMessages($langs->transnoentities(
"RecordSaved"),
null,
'mesgs');
531 $_POST = array(
'id' => 25);
533 if (!empty($backtopage)) {
534 header(
"Location: ".$backtopage);
538 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
539 setEventMessages($langs->transnoentities(
"ErrorRecordAlreadyExists"),
null,
'errors');
541 dol_print_error($db);
548 if ($ok &&
GETPOST(
'actionmodify')) {
552 setEventMessages($langs->trans(
"AnOwnerMustBeSetIfEmailTemplateIsPrivate"),
null,
'errors');
559 $sql =
"UPDATE ".$db->sanitize($tabname[25]).
" SET ";
562 foreach ($listfieldmodify as $field) {
563 if ($field ==
'entity') {
566 $_POST[$keycode] =
$conf->entity;
568 $keycode = $listfieldvalue[$i];
571 if ($field ==
'lang') {
572 $keycode =
'langcode';
574 if (empty($keycode)) {
579 if ($field ==
'topic') {
580 $_POST[
'topic'] =
GETPOST(
'topic-'.$rowid);
582 if ($field ==
'joinfiles') {
583 $_POST[
'joinfiles'] =
GETPOST(
'joinfiles-'.$rowid);
585 if ($field ==
'content') {
586 $_POST[
'content'] =
GETPOST(
'content-'.$rowid,
'restricthtml');
588 if ($field ==
'content_lines') {
589 $_POST[
'content_lines'] =
GETPOST(
'content_lines-'.$rowid,
'restricthtml');
591 if ($field ==
'email_from') {
592 $_POST[
'email_from'] =
GETPOST(
'email_from-'.$rowid,
'email');
594 if ($field ==
'email_to') {
595 $_POST[
'email_to'] =
GETPOST(
'email_to-'.$rowid,
'email');
597 if ($field ==
'email_tocc') {
598 $_POST[
'email_tocc'] =
GETPOST(
'email_tocc-'.$rowid,
'email');
600 if ($field ==
'email_tobcc') {
601 $_POST[
'email_tobcc'] =
GETPOST(
'email_tobcc-'.$rowid,
'email');
607 $sql .= $field.
" = ";
610 $sql .=
"'".$db->escape($defaulttemplatelang).
"'";
611 } elseif ((
GETPOST($keycode) ==
'' && in_array($keycode, array(
'langcode'))) || (!in_array($keycode, array(
'langcode',
'position',
'private',
'defaultfortype')) && !
GETPOST($keycode))) {
613 } elseif ($keycode ==
'langcode' && (
GETPOST($keycode) ==
'0' ||
GETPOST($keycode) ==
'-1')) {
615 } elseif ($keycode ==
'fk_user') {
617 $sql .= ((int) $user->id);
621 } elseif ($keycode ==
'content') {
622 $sql .=
"'".$db->escape(
GETPOST($keycode,
'restricthtml')).
"'";
623 } elseif ($keycode ==
'position') {
625 } elseif (in_array($keycode, array(
'joinfiles',
'defaultfortype',
'private'))) {
628 $sql .=
"'".$db->escape(
GETPOST($keycode,
'alphanohtml')).
"'";
633 $sql .=
" WHERE ".$db->sanitize($rowidcol).
" = ".((int) $rowid);
635 $sql .=
" AND fk_user = ".((int) $user->id);
641 $resql = $db->query($sql);
644 setEventMessages($db->error(),
null,
'errors');
650 setEventMessages($langs->transnoentities(
"RecordSaved"),
null,
'mesgs');
655 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $permissiontodelete) {
658 $sql =
"DELETE from ".$db->sanitize($tabname[25]).
" WHERE rowid = ".((int) $rowid);
660 $sql .=
" AND fk_user = ".((int) $user->id);
663 $result = $db->query($sql);
665 if ($db->errno() ==
'DB_ERROR_CHILD_EXISTS') {
666 setEventMessages($langs->transnoentities(
"ErrorRecordIsUsedByChild"),
null,
'errors');
668 dol_print_error($db);
674 if ($action == $acts[0] && $permissiontoedit) {
677 $sql =
"UPDATE ".$db->sanitize($tabname[25]).
" SET active = 1 WHERE rowid = ".((int) $rowid);
679 $result = $db->query($sql);
681 dol_print_error($db);
686 if ($action == $acts[1] && $permissiontoedit) {
689 $sql =
"UPDATE ".$db->sanitize($tabname[25]).
" SET active = 0 WHERE rowid = ".((int) $rowid);
691 $result = $db->query($sql);
693 dol_print_error($db);
703$form =
new Form($db);
710if (!empty($user->admin) && (empty($_SESSION[
'leftmenu']) || $_SESSION[
'leftmenu'] !=
'email_templates')) {
711 $title = $langs->trans(
"EMailsSetup");
713 $title = $langs->trans(
"EMailTemplates");
718$sql =
"SELECT rowid as rowid, module, label, type_template, lang, fk_user, private, position, topic, email_from, email_to, email_tocc, email_tobcc, joinfiles, defaultfortype,";
719$sql .=
" content_lines, content, enabled, active, tms, datec";
720$sql .=
" FROM ".MAIN_DB_PREFIX.
"c_email_templates";
721$sql .=
" WHERE entity IN (".getEntity(
'email_template').
")";
723 $sql .=
" AND (private = 0 OR (private = 1 AND fk_user = ".((int) $user->id).
"))";
724 $sql .=
" AND (active = 1 OR fk_user = ".((int) $user->id).
")";
729if ($search_type_template !=
'' && $search_type_template !=
'-1') {
735if ($search_fk_user !=
'' && $search_fk_user !=
'-1') {
742$listofmodules = implode(
",", array_keys(
$conf->modules));
743$sql .=
"AND (".natural_search(
'module', $listofmodules, 3, 1).
" OR module IS NULL)";
747if (in_array($search_private, array(0, 1),
true)) {
748 $sql .=
" AND private = ".((int) $search_private);
750if ($search_position !==
'') {
751 $sql .=
" AND position = ".((int) $search_position);
753if ($search_joinfiles === 1) {
754 $sql .=
" AND (joinfiles IS NOT NULL AND joinfiles <> '' AND joinfiles <> '0')";
755} elseif ($search_joinfiles === 0) {
756 $sql .=
" AND (joinfiles IS NULL OR joinfiles = '' OR joinfiles = '0')";
758if (in_array($search_defaultfortype, array(0, 1),
true)) {
759 $sql .=
" AND COALESCE(defaultfortype, 0) = ".((int) $search_defaultfortype);
762if ($sortfield ==
'country') {
763 $sortfield =
'country_code';
765$sql .= $db->order($sortfield, $sortorder);
771llxHeader(
'', $title, $help_url,
'', 0, 0, $morejs, $morecss,
'',
'mod-admin page-mails_templates');
773$arrayofselected = is_array($toselect) ? $toselect : array();
777 $param .=
'&mode='.urlencode($mode);
779if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
780 $param .=
'&contextpage='.urlencode($contextpage);
782if ($limit > 0 && $limit !=
$conf->liste_limit) {
783 $param .=
'&limit='.((int) $limit);
785if ($optioncss !=
'') {
786 $param .=
'&optioncss='.urlencode($optioncss);
789include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_param.tpl.php';
791$parameters = array();
792$reshook = $hookmanager->executeHooks(
'printFieldListSearchParam', $parameters, $object);
793$param .= $hookmanager->resPrint;
796$titlepicto =
'title_setup';
799$url = DOL_URL_ROOT.
'/admin/mails_templates.php?action=create';
801$newcardbutton .=
dolGetButtonTitle($langs->trans(
'NewEMailTemplate'),
'',
'fa fa-plus-circle', $url,
'', (
int) $permissiontoadd);
806 $param .=
'&search_label='.urlencode($search_label);
808if (!empty($search_lang) && $search_lang !=
'-1') {
809 $param .=
'&search_lang='.urlencode($search_lang);
811if ($search_type_template !=
'-1') {
812 $param .=
'&search_type_template='.urlencode($search_type_template);
814if ($search_fk_user > 0) {
815 $param .=
'&search_fk_user='.urlencode($search_fk_user);
818 $param .=
'&search_module='.urlencode($search_module);
821 $param .=
'&search_topic='.urlencode($search_topic);
824if (in_array($search_private, array(0, 1),
true)) {
825 $param .=
'&search_private='.((int) $search_private);
827if ($search_position !==
'') {
828 $param .=
'&search_position='.((int) $search_position);
830if (in_array($search_joinfiles, array(0, 1),
true)) {
831 $param .=
'&search_joinfiles='.((int) $search_joinfiles);
833if (in_array($search_defaultfortype, array(0, 1),
true)) {
834 $param .=
'&search_defaultfortype='.((int) $search_defaultfortype);
837$paramwithsearch = $param;
839 $paramwithsearch .=
'&sortorder='.urlencode($sortorder);
842 $paramwithsearch .=
'&sortfield='.urlencode($sortfield);
845 $paramwithsearch .=
'&limit='.((int) $limit);
848 $paramwithsearch .=
'&from='.urlencode(
GETPOST(
'from',
'alpha'));
851$massactionbutton =
'';
855dol_syslog(
"htdocs/admin/mails_templates.php", LOG_DEBUG);
857$resql = $db->query($sql);
859 dol_print_error($db);
863$nbtotalofrecords = $db->num_rows($resql);
865$sql .= $db->plimit($limit + 1, $offset);
867$resql = $db->query($sql);
869 dol_print_error($db);
873$num = $db->num_rows($resql);
875if ($action !=
'create') {
876 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'" method="POST" id="list_of_c_email_templates" spellcheck="false">';
877 print
'<input type="hidden" name="token" value="'.newToken().
'">';
878 print
'<input type="hidden" name="from" value="'.dol_escape_htmltag(
GETPOST(
'from',
'alpha')).
'">';
881 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'" method="POST" id="create_c_email_template" spellcheck="false">';
882 print
'<input type="hidden" name="token" value="'.newToken().
'">';
883 print
'<input type="hidden" name="action" value="add">';
884 print
'<input type="hidden" name="from" value="'.dol_escape_htmltag(
GETPOST(
'from',
'alpha')).
'">';
885 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
888if (!empty($user->admin) && (empty($_SESSION[
'leftmenu']) || $_SESSION[
'leftmenu'] !=
'email_templates')) {
891 print_barre_liste($title, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords,
'tools', 0, $newcardbutton,
'', $limit,
'limit', 0, 1);
894if (!empty($user->admin) && (empty($_SESSION[
'leftmenu']) || $_SESSION[
'leftmenu'] !=
'email_templates')) {
899 if (!empty($user->admin) && (empty($_SESSION[
'leftmenu']) || $_SESSION[
'leftmenu'] !=
'email_templates')) {
906if ($action ==
'delete') {
907 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?'.($page ?
'page='.$page.
'&' :
'').
'sortfield='.$sortfield.
'&sortorder='.$sortorder.
'&rowid='.((int) $rowid), $langs->trans(
'DeleteLine'), $langs->trans(
'ConfirmDeleteLine'),
'confirm_delete',
'', 0, 1);
911$fieldlist = explode(
',', $tabfield[25]);
913if ($action ==
'create') {
916 $obj->label =
GETPOST(
'label');
918 $obj->type_template =
GETPOST(
'type_template');
921 $obj->position =
GETPOST(
'position');
922 $obj->topic =
GETPOST(
'topic');
923 $obj->joinfiles =
GETPOST(
'joinfiles');
924 $obj->defaultfortype =
GETPOST(
'defaultfortype') ? 1 : 0;
925 $obj->content =
GETPOST(
'content',
'restricthtml');
927 print
'<div class="div-table-responsive-no-min">';
928 print
'<table class="noborder centpercent" id="table_create_c_email_template">';
931 print
'<tr class="liste_titre">';
932 foreach ($fieldlist as $field => $value) {
938 $valuetoshow = ucfirst($fieldlist[$field]);
939 $valuetoshow = $langs->trans($valuetoshow);
941 if ($fieldlist[$field] ==
'module') {
942 $valuetoshow =
' ';
944 if ($fieldlist[$field] ==
'fk_user') {
945 $valuetoshow = $langs->trans(
"Owner");
947 if ($fieldlist[$field] ==
'lang') {
948 $valuetoshow = $langs->trans(
"Language");
950 if ($fieldlist[$field] ==
'type') {
951 $valuetoshow = $langs->trans(
"Type");
953 if ($fieldlist[$field] ==
'position') {
956 if ($fieldlist[$field] ==
'code') {
957 $valuetoshow = $langs->trans(
"Code");
959 if ($fieldlist[$field] ==
'label') {
960 $valuetoshow = $langs->trans(
"Label");
962 if ($fieldlist[$field] ==
'type_template') {
963 $valuetoshow = $langs->trans(
"TypeOfTemplate");
966 if (in_array($fieldlist[$field], array(
'private',
'private',
'defaultfortype'))) {
970 if ($fieldlist[$field] ==
'topic') {
973 if ($fieldlist[$field] ==
'joinfiles') {
976 if ($fieldlist[$field] ==
'content') {
979 if ($fieldlist[$field] ==
'content_lines') {
982 if ($valuetoshow !=
'') {
983 print
'<th class="'.$css.
'">';
984 if (!empty($tabhelp[25][$value]) && preg_match(
'/^http(s*):/i', $tabhelp[25][$value])) {
985 print
'<a href="'.$tabhelp[25][$value].
'" target="_blank" rel="noopener noreferrer">'.$valuetoshow.
' '.img_help(1, $valuetoshow).
'</a>';
986 } elseif (!empty($tabhelp[25][$value])) {
987 if (in_array($value, array(
'topic'))) {
988 print $form->textwithpicto($valuetoshow, $tabhelp[25][$value], 1,
'help',
'', 0, 2, $value);
990 print $form->textwithpicto($valuetoshow, $tabhelp[25][$value], 1,
'help',
'', 0, 2);
1002 $tmpaction =
'create';
1003 $parameters = array(
1004 'fieldlist' => $fieldlist,
1005 'tabname' => $tabname[25]
1007 $reshook = $hookmanager->executeHooks(
'createEmailTemplateFieldlist', $parameters, $obj, $tmpaction);
1008 $error = $hookmanager->error;
1009 $errors = $hookmanager->errors;
1013 print
'<tr class="oddeven">';
1015 if (empty($reshook)) {
1016 if ($action ==
'edit') {
1017 fieldList($fieldlist, $obj, $tabname[25],
'hide');
1019 fieldList($fieldlist, $obj, $tabname[25],
'add');
1023 print
'<td class="right">';
1027 print
'<tr class="oddeven nodrag nodrop nohover"><td colspan="9" style="padding-left: 20px; padding-right: 20px;">';
1030 $fieldsforcontent = array(
'topic',
'email_from',
'joinfiles',
'content');
1032 $fieldsforcontent[] =
'email_to';
1035 $fieldsforcontent[] =
'email_tocc';
1038 $fieldsforcontent[] =
'email_tobcc';
1041 $fieldsforcontent[] =
'content_lines';
1043 foreach ($fieldsforcontent as $tmpfieldlist) {
1044 print
'<div class="inline-block lineformailtemplatefield paddingtop paddingbottom centpercent">';
1046 if ($tmpfieldlist ==
'topic') {
1047 print
'<span class="bold minwidth150 inline-block">'.$form->textwithpicto($langs->trans(
"Topic"), $tabhelp[25][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'</span>';
1049 if ($tmpfieldlist ==
'email_from') {
1050 print
'<span class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans(
"MailFrom"), $tabhelp[25][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'</span>';
1052 if ($tmpfieldlist ==
'email_to') {
1053 print
'<span class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans(
"MailTo"), $tabhelp[25][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'</span>';
1055 if ($tmpfieldlist ==
'email_tocc') {
1056 print
'<span class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans(
"MailCC"), $tabhelp[25][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'</span>';
1058 if ($tmpfieldlist ==
'email_tobcc') {
1059 print
'<span class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans(
"MailCCC"), $tabhelp[25][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'</span>';
1061 if ($tmpfieldlist ==
'joinfiles') {
1062 print
'<span class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans(
"FilesAttachedToEmail"), $tabhelp[25][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'</span>';
1064 if ($tmpfieldlist ==
'content') {
1065 print
'<span class="minwidth150 inline-block margintoponly">'.$form->textwithpicto($langs->trans(
"Content"), $tabhelp[25][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'</span>';
1070 $formmail->withlayout =
'email';
1071 $formmail->withaiprompt =
'html';
1072 $formmail->withfckeditor = 1;
1074 $showlinktolayout = (
getDolGlobalInt(
'MAIN_EMAIL_USE_LAYOUT') ? $formmail->withlayout :
'');
1075 $showlinktolayoutlabel = $langs->trans(
"FillMessageWithALayout");
1076 $showlinktoai = (
isModEnabled(
'ai') ?
'textgenerationemail' :
'');
1077 $showlinktoailabel = $langs->trans(
"FillMessageWithAIContent");
1078 $htmlname =
'content';
1079 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
1083 if ($tmpfieldlist ==
'content_lines') {
1084 print
'<span class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans(
"ContentForLines"), $tabhelp[25][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'</span><br>';
1088 if ($tmpfieldlist ==
'topic') {
1089 print
'<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.
'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist :
'').
'">';
1090 } elseif ($tmpfieldlist ==
'email_from') {
1091 print
'<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.
'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist :
'').
'" spellcheck="false">';
1092 } elseif ($tmpfieldlist ==
'email_to') {
1093 print
'<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.
'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist :
'').
'" spellcheck="false">';
1094 } elseif ($tmpfieldlist ==
'email_tocc') {
1095 print
'<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.
'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist :
'').
'" spellcheck="false">';
1096 } elseif ($tmpfieldlist ==
'email_tobcc') {
1097 print
'<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.
'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist :
'').
'" spellcheck="false">';
1098 } elseif ($tmpfieldlist ==
'joinfiles') {
1099 print $form->selectyesno($tmpfieldlist, (isset($obj->$tmpfieldlist) ? $obj->$tmpfieldlist :
'0'), 1, false, 0, 1);
1101 $okforextended =
true;
1103 $okforextended =
false;
1105 $doleditor =
new DolEditor($tmpfieldlist, (!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist :
''),
'', 400,
'dolibarr_mailings',
'In', false, $acceptlocallinktomedia, $okforextended, ROWS_6,
'90%');
1106 print $doleditor->Create(1);
1116 if ($action !=
'edit') {
1118 print
'<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans(
"Add").
'"> ';
1119 print
'<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans(
"Cancel").
'">';
1126 print
'<br><br><br>';
1129if ($action !=
'create') {
1130 print
'<div class="div-table-responsive-no-min">';
1131 print
'<table class="noborder centpercent" id="table_list_of_c_email_templates">';
1145 print
'<tr class="liste_titre" id="Title line with search boxes">';
1147 if (
$conf->main_checkbox_left_column) {
1148 print
'<td class="liste_titre center" width="64">';
1149 $searchpicto = $form->showFilterButtons();
1153 foreach ($fieldlist as $field => $value) {
1157 if ($value ==
'module') {
1158 print
'<td class="liste_titre"><input type="text" name="search_module" class="maxwidth75" value="'.dol_escape_htmltag($search_module).
'" spellcheck="false"></td>';
1159 } elseif ($value ==
'label') {
1160 print
'<td class="liste_titre"><input type="text" name="search_label" class="maxwidth75" value="'.dol_escape_htmltag($search_label).
'" spellcheck="false"></td>';
1161 } elseif ($value ==
'lang') {
1162 print
'<td class="liste_titre">';
1163 print $formadmin->select_language($search_lang,
'search_lang', 0, array(), 1, 0, 0,
'maxwidth100');
1165 } elseif ($value ==
'fk_user') {
1166 print
'<td class="liste_titre">';
1167 print $form->select_dolusers($search_fk_user,
'search_fk_user', 1,
null, 0, ($user->admin ?
'' :
'hierarchyme'), array(),
'0', 0, 0,
'', 0,
'',
'maxwidth100', 1);
1169 } elseif ($value ==
'topic') {
1170 print
'<td class="liste_titre"><input type="text" class="maxwidth150" name="search_topic" value="'.dol_escape_htmltag($search_topic).
'" spellcheck="false"></td>';
1171 } elseif ($value ==
'type_template') {
1172 print
'<td class="liste_titre center">';
1174 print $form->selectarray(
'search_type_template', $elementList, $search_type_template, 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth100 maxwidth125', 1,
'', 0, 1);
1176 } elseif (in_array($value, array(
'private',
'joinfiles',
'defaultfortype'))) {
1177 print
'<td class="liste_titre center">';
1178 $searchvalue = ($value ==
'private' ? $search_private : ($value ==
'joinfiles' ? $search_joinfiles : $search_defaultfortype));
1179 print $form->selectyesno(
'search_'.$value, $searchvalue, 1,
false, 1, 1,
'maxwidth75');
1181 } elseif ($value ==
'position') {
1182 print
'<td class="liste_titre center"><input type="text" class="width50 center" name="search_position" value="'.dol_escape_htmltag($search_position).
'" spellcheck="false"></td>';
1183 } elseif (!in_array($value, array(
'content',
'content_lines'))) {
1184 print
'<td class="liste_titre"></td>';
1191 if (!empty($arrayfields[
't.tms'][
'checked'])) {
1192 print
'<td class="liste_titre"></td>';
1194 if (!empty($arrayfields[
't.datec'][
'checked'])) {
1195 print
'<td class="liste_titre"></td>';
1198 print
'<td class="liste_titre center"></td>';
1201 if (!
$conf->main_checkbox_left_column) {
1202 print
'<td class="liste_titre center" width="64">';
1203 $searchpicto = $form->showFilterButtons();
1210 print
'<tr class="liste_titre" id="Title of lines">';
1212 if (
$conf->main_checkbox_left_column) {
1215 array_push($fieldlist,
"tms",
"datec");
1216 foreach ($fieldlist as $field => $value) {
1232 $valuetoshow = ucfirst($fieldlist[$field]);
1233 $valuetoshow = $langs->trans($valuetoshow);
1234 if ($fieldlist[$field] ==
'module') {
1235 $css =
'tdoverflowmax100';
1237 if ($fieldlist[$field] ==
'fk_user') {
1238 $valuetoshow = $langs->trans(
"Owner");
1240 if ($fieldlist[$field] ==
'lang') {
1241 $valuetoshow = $langs->trans(
"Language");
1243 if ($fieldlist[$field] ==
'type') {
1244 $valuetoshow = $langs->trans(
"Type");
1246 if ($fieldlist[$field] ==
'libelle' || $fieldlist[$field] ==
'label') {
1247 $valuetoshow = $langs->trans(
"Label");
1249 if ($fieldlist[$field] ==
'type_template') {
1251 $valuetoshow = $langs->trans(
"TypeOfTemplate");
1253 if ($fieldlist[$field] ==
'private') {
1256 if ($fieldlist[$field] ==
'position') {
1259 if ($fieldlist[$field] ==
'tms') {
1260 $valuetoshow =
'Modif. date';
1262 if ($fieldlist[$field] ==
'datec') {
1263 $valuetoshow =
'Date creation';
1266 if ($fieldlist[$field] ==
'joinfiles') {
1267 $valuetoshow = $langs->trans(
"FilesAttachedToEmail");
1271 if ($fieldlist[$field] ==
'content') {
1272 $valuetoshow = $langs->trans(
"Content");
1275 if ($fieldlist[$field] ==
'content_lines') {
1276 $valuetoshow = $langs->trans(
"ContentForLines");
1279 if ($value ==
'tms' && empty($arrayfields[
't.'.$value][
'checked'])) {
1282 if ($value ==
'datec' && empty($arrayfields[
't.'.$value][
'checked'])) {
1288 if (!empty($tabhelp[25][$value])) {
1289 if (in_array($value, array(
'topic'))) {
1290 $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[25][$value], 1,
'help',
'', 0, 2,
'tooltip'.$value, $forcenowrap);
1292 $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[25][$value], 1,
'help',
'', 0, 2,
'', $forcenowrap);
1295 $sortfieldtouse = ($sortable ? $fieldlist[$field] :
'');
1296 if ($sortfieldtouse ==
'type_template') {
1297 $sortfieldtouse .=
',lang,position,label';
1299 print
getTitleFieldOfList($valuetoshow, 0, $_SERVER[
"PHP_SELF"], $sortfieldtouse, ($page ?
'page='.$page.
'&' :
''), $paramwithsearch,
'', $sortfield, $sortorder, $css.
' ');
1303 print
getTitleFieldOfList($langs->trans(
"Status"), 0, $_SERVER[
"PHP_SELF"],
"active", ($page ?
'page='.$page.
'&' :
''), $paramwithsearch,
'', $sortfield, $sortorder,
'center ');
1305 if (!
$conf->main_checkbox_left_column) {
1314 $obj = $db->fetch_object($resql);
1317 if (($action ==
'edit' || $action ==
'preview') && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
1319 print
'<tr class="nohover oddeven noborderbottom" id="rowid-'.$obj->rowid.
'" name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).
'">';
1321 $tmpaction =
'edit';
1322 if ($action ==
'edit') {
1324 $fieldlist = explode(
',', $tabfield[25]);
1325 $parameters = array(
'fieldlist' => $fieldlist,
'tabname' => $tabname[25]);
1327 $parameters = array(
'fieldlist' => $fieldlist,
'tabname' => $tabname[25]);
1329 $reshook = $hookmanager->executeHooks(
'editEmailTemplateFieldlist', $parameters, $obj, $tmpaction);
1330 $error = $hookmanager->error;
1331 $errors = $hookmanager->errors;
1336 if (
$conf->main_checkbox_left_column) {
1337 print
'<td class="center">';
1342 if (empty($reshook)) {
1343 $colspan +=
fieldList($fieldlist, $obj, $tabname[25], $action);
1346 if (!
$conf->main_checkbox_left_column) {
1347 print
'<td class="center">';
1353 print
'<tr class="oddeven nohover" id="tr-aaa-'.$rowid.
'">';
1354 if (
$conf->main_checkbox_left_column) {
1355 print
'<td class="center"></td>';
1357 print
'<td colspan="'.($colspan - 1).
'" class="" style="padding-left: 20px; padding-right: 20px;">';
1359 $fieldsforcontent = array(
'topic',
'email_from',
'joinfiles',
'content');
1361 $fieldsforcontent[] =
'email_to';
1364 $fieldsforcontent[] =
'email_tocc';
1367 $fieldsforcontent[] =
'email_tobcc';
1370 $fieldsforcontent[] =
'content_lines';
1373 $parameters = array(
'fieldsforcontent' => &$fieldsforcontent,
'tabname' => $tabname[25]);
1374 $hookmanager->executeHooks(
'editEmailTemplateFieldsForContent', $parameters, $obj, $tmpaction);
1376 print
'<div class="lineformailtemplatefield centpercent">';
1377 foreach ($fieldsforcontent as $tmpfieldlist) {
1380 $valuetoshow = $obj->$tmpfieldlist;
1385 print
'<div class="inline-block lineformailtemplatefield paddingtop paddingbottom centpercent">';
1387 if ($tmpfieldlist ==
'topic') {
1388 print
'<div class="minwidth150 inline-block bold">'.$form->textwithpicto($langs->trans(
"Topic"), $tabhelp[25][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'</div> ';
1389 print
'<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.
'-'.$rowid.
'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} :
'').
'"'.($action !=
'edit' ?
' disabled' :
'').
'>';
1392 if ($tmpfieldlist ==
'email_from') {
1393 print
'<div class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans(
"MailFrom"), $tabhelp[25][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'</div> ';
1394 print
'<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.
'-'.$rowid.
'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} :
'').
'"'.($action !=
'edit' ?
' disabled' :
'').
' spellcheck="false">';
1397 if ($tmpfieldlist ==
'email_to') {
1398 print
'<div class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans(
"MailTo"), $tabhelp[25][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'</div> ';
1399 print
'<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.
'-'.$rowid.
'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} :
'').
'"'.($action !=
'edit' ?
' disabled' :
'').
' spellcheck="false">';
1402 if ($tmpfieldlist ==
'email_tocc') {
1403 print
'<div class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans(
"MailCC"), $tabhelp[25][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'</div> ';
1404 print
'<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.
'-'.$rowid.
'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} :
'').
'"'.($action !=
'edit' ?
' disabled' :
'').
' spellcheck="false">';
1407 if ($tmpfieldlist ==
'email_tobcc') {
1408 print
'<div class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans(
"MailCCC"), $tabhelp[25][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'</div> ';
1409 print
'<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.
'-'.$rowid.
'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} :
'').
'"'.($action !=
'edit' ?
' disabled' :
'').
' spellcheck="false">';
1412 if ($tmpfieldlist ==
'joinfiles') {
1413 print
'<div class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans(
"FilesAttachedToEmail"), $tabhelp[25][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'</div> ';
1414 print $form->selectyesno($tmpfieldlist.
'-'.$rowid, (isset($obj->$tmpfieldlist) ? $obj->$tmpfieldlist :
'0'), 1, ($action !=
'edit'), 0, 1);
1418 if ($tmpfieldlist ==
'content') {
1419 print
'<div class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans(
"Content"), $tabhelp[25][$tmpfieldlist], 1,
'help',
'margintoponly', 0, 2, $tmpfieldlist).
'</div>';
1425 $formmail->withlayout =
'email';
1426 $formmail->withaiprompt =
'html';
1427 $formmail->withfckeditor = 1;
1429 $showlinktolayout = (
getDolGlobalInt(
'MAIN_EMAIL_USE_LAYOUT') ? $formmail->withlayout :
'');
1430 $showlinktolayoutlabel = $langs->trans(
"FillMessageWithALayout");
1431 $showlinktoai = (
isModEnabled(
'ai') ?
'textgenerationemail' :
'');
1432 $showlinktoailabel = $langs->trans(
"FillMessageWithAIContent");
1433 $htmlname =
'content_'.$rowid;
1434 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
1437 $okforextended =
true;
1439 $okforextended =
false;
1441 $doleditor =
new DolEditor($tmpfieldlist.
'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} :
''),
'', 450,
'dolibarr_mailings',
'In',
false, $acceptlocallinktomedia, $okforextended, ROWS_6,
'80%', ($action !=
'edit' ? 1 : 0));
1442 print $doleditor->Create(1);
1444 if ($tmpfieldlist ==
'content_lines') {
1446 print $form->textwithpicto($langs->trans(
"ContentForLines"), $tabhelp[25][$tmpfieldlist], 1,
'help',
'margintoponly', 0, 2, $tmpfieldlist).
'<br>';
1447 $okforextended =
true;
1449 $okforextended =
false;
1451 $doleditor =
new DolEditor($tmpfieldlist.
'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} :
''),
'', 140,
'dolibarr_mailings',
'In',
false, $acceptlocallinktomedia, $okforextended, ROWS_6,
'80%');
1452 print $doleditor->Create(1);
1458 print
'<center><input type="hidden" name="page" value="'.$page.
'">';
1459 print
'<input type="hidden" name="rowid" value="'.$rowid.
'">';
1460 if ($action ==
'edit') {
1461 print
'<input type="submit" class="button buttongen button-save" name="actionmodify" value="'.$langs->trans(
"Save").
'">';
1463 print
'<input type="submit" class="button buttongen button-cancel" name="actioncancel" value="'.$langs->trans(
"Cancel").
'">';
1467 if (!
$conf->main_checkbox_left_column) {
1468 print
'<td class="center"></td>';
1477 $tempmodulekey = $obj->module;
1484 $keyforobj =
'type_template';
1485 if (!in_array($obj->$keyforobj, array_keys($elementList))) {
1490 if (! (
int)
dol_eval((
string) $obj->enabled, 1, 1,
'1')) {
1501 if (!$user->admin && $obj->fk_user != $user->id) {
1507 $url = $_SERVER[
"PHP_SELF"].
'?'.($page ?
'page='.$page.
'&' :
'').
'sortfield='.$sortfield.
'&sortorder='.$sortorder.
'&rowid='.(!empty($obj->rowid) ? $obj->rowid : (!empty($obj->code) ? $obj->code :
'')).(!empty($obj->code) ?
'&code='.urlencode($obj->code) :
'');
1512 print
'<tr class="oddeven" id="rowid-'.$obj->rowid.
'">';
1515 if (
$conf->main_checkbox_left_column) {
1516 print
'<td class="center nowraponall" width="64">';
1517 if ($canbemodified) {
1518 print
'<a class="reposition editfielda" href="'.$url.
'&action=edit&token='.
newToken().
'">'.img_edit().
'</a>';
1520 print
'<a class="reposition editfielda" href="'.$url.
'&action=preview&token='.
newToken().
'">'.img_view().
'</a>';
1523 print
'<a class="reposition marginleftonly" href="'.$url.
'&action=delete&token='.
newToken().$param.
'">'.img_delete().
'</a>';
1528 $tmpaction =
'view';
1529 $parameters = array(
'fieldlist' => $fieldlist,
'tabname' => $tabname[25]);
1530 $reshook = $hookmanager->executeHooks(
'viewEmailTemplateFieldlist', $parameters, $obj, $tmpaction);
1532 $error = $hookmanager->error;
1533 $errors = $hookmanager->errors;
1535 if (empty($reshook)) {
1536 foreach ($fieldlist as $field => $value) {
1540 if (in_array($fieldlist[$field], array(
'content',
'content_lines'))) {
1547 $tmpvar = $fieldlist[$field];
1548 $valuetoshow = $obj->$tmpvar;
1549 if ($value ==
'label' || $value ==
'topic') {
1550 if ($langs->trans($valuetoshow) != $valuetoshow) {
1551 $valuetoshow = $langs->trans($valuetoshow);
1555 if ($value ==
'label') {
1556 $class .=
' tdoverflowmax200';
1558 if ($value ==
'topic') {
1559 $class .=
' tdoverflowmax200 small';
1561 if ($value ==
'type_template') {
1562 $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
1563 $css =
"center tdoverflowmax150";
1565 if ($value ==
'lang' && $valuetoshow) {
1566 $valuetoshow = $valuetoshow.
' - '.$langs->trans(
"Language_".$valuetoshow);
1567 $class .=
' tdoverflowmax100';
1569 if ($value ==
'fk_user') {
1570 if ($valuetoshow > 0) {
1571 $fuser =
new User($db);
1572 $fuser->fetch($valuetoshow);
1573 $valuetoshow = $fuser->getNomUrl(-1);
1575 if ($obj->private) {
1576 $valuetoshow = img_picto($langs->transnoentitiesnoconv(
"Private"),
'lock',
'class="pictofixedwidth"').$valuetoshow;
1579 $class .=
' tdoverflowmax100';
1582 if ($value ==
'private') {
1585 $valuetoshow = yn($valuetoshow);
1590 if ($value ==
'position') {
1593 if (in_array($value, array(
'joinfiles',
'defaultfortype'))) {
1597 $valuetoshow =
'<input type="checkbox" checked="checked" disabled>';
1606 if ($value ==
'tms' && empty($arrayfields[
't.'.$value][
'checked'])) {
1609 if ($value ==
'datec' && empty($arrayfields[
't.'.$value][
'checked'])) {
1615 print
'<!-- '.$fieldlist[$field].
' -->';
1616 print
'<td class="'.$class.
'"';
1617 if (in_array($value, array(
'code',
'label',
'topic'))) {
1618 print
' title="'.dol_escape_htmltag($valuetoshow).
'"';
1628 print
'<td class="center nowrap">';
1629 if ($canbedisabled) {
1630 print
'<a class="reposition" href="'.$url.
'&action='.$acts[$obj->active].
'&token='.
newToken().
'">'.$actl[$obj->active].
'</a>';
1632 print
'<span class="opacitymedium">'.$actl[$obj->active].
'</span>';
1637 if (!
$conf->main_checkbox_left_column) {
1638 print
'<td class="center nowraponall" width="64">';
1639 if ($canbemodified) {
1640 print
'<a class="reposition editfielda" href="'.$url.
'&action=edit&token='.
newToken().
'">'.img_edit().
'</a>';
1643 print
'<a class="reposition marginleftonly" href="'.$url.
'&action=delete&token='.
newToken().
'">'.img_delete().
'</a>';
1658 if ($nbqualified == 0) {
1660 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
1669if (!empty($user->admin) && (empty($_SESSION[
'leftmenu']) || $_SESSION[
'leftmenu'] !=
'email_templates')) {
1690 global $langs, $user, $db;
1692 global $elementList;
1695 $nboffieldsprinted = 0;
1697 foreach ($fieldlist as $value) {
1702 if ($value ==
'module') {
1704 $nboffieldsprinted++;
1705 } elseif ($value ==
'fk_user') {
1707 if ($user->admin &&
$context !=
'preview') {
1708 print $form->select_dolusers(
GETPOSTISSET(
'fk_user') ?
GETPOSTINT(
'fk_user') : (empty($obj->$value) ?
'' : $obj->$value),
'fk_user', $langs->trans(
"Owner"), array(), 0, ($user->admin ?
'' :
'hierarchyme'), array(),
'0', 0, 0,
'', 0,
'',
'minwidth75 maxwidth100');
1711 print $user->getNomUrl(-1);
1712 $forcedvalue = $user->id;
1714 if ($obj && !empty($obj->$value) && $obj->$value > 0) {
1715 $fuser =
new User($db);
1716 $fuser->fetch($obj->$value);
1717 print $fuser->getNomUrl(-1);
1718 $forcedvalue = $fuser->id;
1720 $forcedvalue = $obj->$value;
1724 print
'<input type="hidden" value="'.$forcedvalue.
'" name="'.$keyname.
'">';
1727 $nboffieldsprinted++;
1728 } elseif ($value ==
'lang') {
1731 $selectedlang =
GETPOSTISSET(
'langcode') ?
GETPOST(
'langcode',
'aZ09') : $langs->defaultlang;
1733 $selectedlang = $obj->lang;
1735 print $formadmin->select_language($selectedlang,
'langcode', 0, array(), $langs->trans(
"Language"), 0, 0,
'maxwidth100');
1737 if (!empty($obj->lang)) {
1738 print $obj->lang.
' - '.$langs->trans(
'Language_'.$obj->lang);
1741 if ($keyname ==
'lang') {
1742 $keyname =
'langcode';
1744 print
'<input type="hidden" value="'.(empty($obj->lang) ?
'' : $obj->lang).
'" name="'.$keyname.
'">';
1747 $nboffieldsprinted++;
1748 } elseif ($value ==
'type_template') {
1750 print
'<td class="center">';
1751 if ((
$context ==
'edit' && !empty($obj->type_template) && !in_array($obj->type_template, array_keys($elementList))) ||
$context ==
'preview') {
1753 print
'<input type="hidden" name="type_template" value="'.$obj->type_template.
'">';
1754 print $obj->type_template;
1756 print $form->selectarray(
'type_template', $elementList, (!empty($obj->type_template) ? $obj->type_template :
''), 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth75 maxwidth125', 1,
'', 0, 1);
1759 $nboffieldsprinted++;
1760 } elseif (
$context ==
'add' && in_array($value, array(
'topic',
'joinfiles',
'content',
'content_lines'))) {
1762 } elseif (
$context ==
'edit' && in_array($value, array(
'topic',
'joinfiles',
'content',
'content_lines'))) {
1764 $nboffieldsprinted++;
1765 } elseif (
$context ==
'preview' && in_array($value, array(
'topic',
'joinfiles',
'content',
'content_lines'))) {
1767 $nboffieldsprinted++;
1768 } elseif (
$context ==
'hide' && in_array($value, array(
'topic',
'joinfiles',
'content',
'content_lines'))) {
1774 if ($value ==
'code') {
1775 $class =
'maxwidth100';
1777 if ($value ==
'label') {
1778 $class =
'maxwidth200';
1780 if ($value ==
'private') {
1781 $class =
'maxwidth50';
1782 $classtd =
'center';
1784 if ($value ==
'position') {
1785 $class =
'maxwidth50 center';
1786 $classtd =
'center';
1788 if ($value ==
'topic') {
1789 $class =
'quatrevingtpercent';
1791 if ($value ==
'defaultfortype') {
1792 $class =
'width25 center';
1793 $classtd =
'center';
1796 print
'<td'.($classtd ?
' class="'.$classtd.
'"' :
'').
'>';
1797 if (in_array($value, array(
'defaultfortype',
'private')) &&
$context !=
'preview') {
1798 if (empty($user->admin)) {
1800 print $form->selectyesno($value,
GETPOSTISSET($value) ?
GETPOSTINT($value) : ((
$context !=
'add' && isset($obj->$value)) ? $obj->$value :
'1'), 1,
false, 0, 1);
1803 print $form->selectyesno($value, (isset($obj->$value) ? $obj->$value :
''), 1,
false, 0, 1);
1806 print
'<input type="text" '.$size.
'class="flat'.($class ?
' '.$class :
'').
'" value="'.(isset($obj->$value) ? $obj->$value :
'').
'" name="'. $value .
'"'.(
$context ==
'preview' ?
' disabled' :
'').
' spellcheck="false">';
1809 $nboffieldsprinted++;
1813 return $nboffieldsprinted;
if(! $sortfield) if(! $sortorder) $object
email_admin_prepare_head()
Return array head with list of tabs to view object information.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Object of table llx_c_email_templates.
Class to manage a WYSIWYG editor.
Class to manage translations.
Class to manage Dolibarr users.
$context
@method int call_trigger(string $triggerName, ?User $user)
acceptLocalLinktoMedia()
Check the syntax of some PHP code.
dol_now($mode='gmt')
Return date for now.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
fieldList($fieldlist, $obj=null, $tabname='', $context='')
Show fields in insert/edit mode.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.