36 require
'../main.inc.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
41 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
43 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
46 $langsArray=array(
"errors",
"admin",
"mails",
"languages");
48 if (!empty($conf->adherent->enabled)) {
49 $langsArray[]=
'members';
51 if (!empty($conf->eventorganization->enabled)) {
52 $langsArray[]=
'eventorganization';
55 $langs->loadLangs($langsArray);
57 $toselect =
GETPOST(
'toselect',
'array');
58 $action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'view';
59 $massaction =
GETPOST(
'massaction',
'alpha');
60 $confirm =
GETPOST(
'confirm',
'alpha');
61 $mode =
GETPOST(
'mode',
'aZ09');
62 $optioncss =
GETPOST(
'optioncss',
'alpha');
65 $rowid =
GETPOST(
'rowid',
'alpha');
66 $search_label =
GETPOST(
'search_label',
'alphanohtml');
67 $search_type_template =
GETPOST(
'search_type_template',
'alpha');
68 $search_lang =
GETPOST(
'search_lang',
'alpha');
69 $search_fk_user =
GETPOST(
'search_fk_user',
'intcomma');
70 $search_topic =
GETPOST(
'search_topic',
'alpha');
74 $acts[0] =
"activate";
76 $actl[0] =
img_picto($langs->trans(
"Disabled"),
'switch_off',
'class="size15x"');
77 $actl[1] =
img_picto($langs->trans(
"Activated"),
'switch_on',
'class="size15x"');
79 $listoffset =
GETPOST(
'listoffset',
'alpha');
80 $listlimit =
GETPOST(
'listlimit',
'alpha') > 0 ?
GETPOST(
'listlimit',
'alpha') : 1000;
82 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
83 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
84 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
86 if (empty($page) || $page == -1) {
89 $offset = $listlimit * $page;
90 $pageprev = $page - 1;
91 $pagenext = $page + 1;
93 if (empty($sortfield)) {
94 $sortfield =
'type_template, lang, position, label';
96 if (empty($sortorder)) {
101 $hookmanager->initHooks(array(
'emailtemplates'));
106 $tabname[25] = MAIN_DB_PREFIX.
"c_email_templates";
110 $tabfield[25] =
"label,lang,type_template,fk_user,private,position,topic,joinfiles,content";
111 if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
112 $tabfield[25] .=
',content_lines';
116 $tabfieldvalue = array();
117 $tabfieldvalue[25] =
"label,lang,type_template,fk_user,private,position,topic,joinfiles,content";
118 if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
119 $tabfieldvalue[25] .=
',content_lines';
123 $tabfieldinsert = array();
124 $tabfieldinsert[25] =
"label,lang,type_template,fk_user,private,position,topic,joinfiles,content";
125 if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
126 $tabfieldinsert[25] .=
',content_lines';
128 $tabfieldinsert[25] .=
',entity';
136 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
138 if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
140 $tmp[
'__(AnyTranslationKey)__'] =
'Translation';
141 $helpsubstit = $langs->trans(
"AvailableVariables").
':<br>';
142 $helpsubstitforlines = $langs->trans(
"AvailableVariables").
':<br>';
143 foreach ($tmp as $key => $val) {
144 $helpsubstit .= $key.
' -> '.$val.
'<br>';
145 $helpsubstitforlines .= $key.
' -> '.$val.
'<br>';
149 $tmp[
'__(AnyTranslationKey)__'] =
'Translation';
150 $helpsubstit = $langs->trans(
"AvailableVariables").
':<br>';
151 $helpsubstitforlines = $langs->trans(
"AvailableVariables").
':<br>';
152 foreach ($tmp as $key => $val) {
153 $helpsubstit .= $key.
' -> '.$val.
'<br>';
156 foreach ($tmp as $key => $val) {
157 $helpsubstitforlines .= $key.
' -> '.$val.
'<br>';
163 $tabhelp[25] = array(
164 'label'=>$langs->trans(
'EnterAnyCode'),
165 'topic'=>
'<span class="small">'.$helpsubstit.
'</span>',
166 'joinfiles'=>$langs->trans(
'AttachMainDocByDefault'),
167 'content'=>
'<span class="small">'.$helpsubstit.
'</span>',
168 'content_lines'=>
'<span class="small">'.$helpsubstitforlines.
'</span>',
169 'type_template'=>$langs->trans(
"TemplateForElement"),
170 'private'=>$langs->trans(
"TemplateIsVisibleByOwnerOnly"),
171 'position'=>$langs->trans(
"PositionIntoComboList")
176 $elementList = array();
179 $elementList[
'all'] =
'-- '.dol_escape_htmltag($langs->trans(
"All")).
' --';
180 $elementList[
'none'] =
'-- '.dol_escape_htmltag($langs->trans(
"None")).
' --';
181 $elementList[
'user'] =
img_picto(
'',
'user',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToUser'));
182 if (!empty($conf->adherent->enabled) && !empty($user->rights->adherent->lire)) {
183 $elementList[
'member'] =
img_picto(
'',
'object_member',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToMember'));
185 if (!empty($conf->recruitment->enabled) && !empty($user->rights->recruitment->recruitmentjobposition->read)) {
186 $elementList[
'recruitmentcandidature_send'] =
img_picto(
'',
'recruitmentcandidature',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'RecruitmentCandidatures'));
188 if (!empty($conf->societe->enabled) && !empty($user->rights->societe->lire)) {
189 $elementList[
'thirdparty'] =
img_picto(
'',
'company',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToThirdparty'));
191 if (!empty($conf->project->enabled)) {
192 $elementList[
'project'] =
img_picto(
'',
'project',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToProject'));
194 if (!empty($conf->propal->enabled) && !empty($user->rights->propal->lire)) {
195 $elementList[
'propal_send'] =
img_picto(
'',
'propal',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendProposal'));
197 if (!empty($conf->commande->enabled) && !empty($user->rights->commande->lire)) {
198 $elementList[
'order_send'] =
img_picto(
'',
'order',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendOrder'));
200 if (
isModEnabled(
'facture') && !empty($user->rights->facture->lire)) {
201 $elementList[
'facture_send'] =
img_picto(
'',
'bill',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendInvoice'));
203 if (!empty($conf->expedition->enabled)) {
204 $elementList[
'shipping_send'] =
img_picto(
'',
'dolly',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendShipment'));
206 if (!empty($conf->reception->enabled)) {
207 $elementList[
'reception_send'] =
img_picto(
'',
'dollyrevert',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendReception'));
209 if (!empty($conf->ficheinter->enabled)) {
210 $elementList[
'fichinter_send'] =
img_picto(
'',
'intervention',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendIntervention'));
212 if (!empty($conf->supplier_proposal->enabled)) {
213 $elementList[
'supplier_proposal_send'] =
img_picto(
'',
'propal',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendSupplierRequestForQuotation'));
215 if ((!empty($conf->fournisseur->enabled) && !empty($user->rights->fournisseur->commande->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (!empty($conf->supplier_order->enabled) && !empty($user->rights->supplier_order->lire))) {
216 $elementList[
'order_supplier_send'] =
img_picto(
'',
'order',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendSupplierOrder'));
218 if ((!empty($conf->fournisseur->enabled) && !empty($user->rights->fournisseur->facture->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (!empty($conf->supplier_invoice->enabled) && !empty($user->rights->supplier_invoice->lire))) {
219 $elementList[
'invoice_supplier_send'] =
img_picto(
'',
'bill',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendSupplierInvoice'));
221 if (!empty($conf->contrat->enabled) && !empty($user->rights->contrat->lire)) {
222 $elementList[
'contract'] =
img_picto(
'',
'contract',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendContract'));
224 if (!empty($conf->ticket->enabled) && !empty($user->rights->ticket->read)) {
225 $elementList[
'ticket_send'] =
img_picto(
'',
'ticket',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToTicket'));
227 if (!empty($conf->expensereport->enabled) && !empty($user->rights->expensereport->lire)) {
228 $elementList[
'expensereport_send'] =
img_picto(
'',
'trip',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToExpenseReport'));
231 $elementList[
'actioncomm_send'] =
img_picto(
'',
'action',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendEventPush'));
233 if (!empty($conf->eventorganization->enabled) && !empty($user->rights->eventorganization->read)) {
234 $elementList[
'conferenceorbooth'] =
img_picto(
'',
'action',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToSendEventOrganization'));
236 if (!empty($conf->partnership->enabled) && !empty($user->rights->partnership->read)) {
237 $elementList[
'partnership_send'] =
img_picto(
'',
'partnership',
'class="pictofixedwidth"').dol_escape_htmltag($langs->trans(
'MailToPartnership'));
240 $parameters = array(
'elementList'=>$elementList);
241 $reshook = $hookmanager->executeHooks(
'emailElementlist', $parameters);
243 foreach ($hookmanager->resArray as $item => $value) {
244 $elementList[$item] = $value;
250 if (!empty($user->socid)) {
254 $permissiontoadd = 1;
266 if (
GETPOST(
'cancel',
'alpha')) {
270 if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') {
274 $parameters = array();
275 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
280 if (empty($reshook)) {
282 include DOL_DOCUMENT_ROOT.
'/core/actions_changeselectedfields.inc.php';
285 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
288 $search_type_template =
'';
290 $search_fk_user =
'';
293 $search_array_options = array();
297 if (
GETPOST(
'actionadd',
'alpha') ||
GETPOST(
'actionmodify',
'alpha')) {
298 $listfield = explode(
',', str_replace(
' ',
'', $tabfield[$id]));
299 $listfieldinsert = explode(
',', $tabfieldinsert[$id]);
300 $listfieldmodify = explode(
',', $tabfieldinsert[$id]);
301 $listfieldvalue = explode(
',', $tabfieldvalue[$id]);
305 foreach ($listfield as $f => $value) {
307 if ($value ==
'joinfiles') {
310 if ($value ==
'content') {
313 if ($value ==
'content_lines') {
318 if (
GETPOST(
'actionmodify',
'alpha') && $value ==
'topic') {
319 $_POST[
'topic'] =
GETPOST(
'topic-'.$rowid);
322 if ((!
GETPOSTISSET($value) ||
GETPOST($value) ==
'' ||
GETPOST($value) ==
'-1') && $value !=
'lang' && $value !=
'fk_user' && $value !=
'position') {
324 $fieldnamekey = $listfield[$f];
326 if ($fieldnamekey ==
'libelle' || ($fieldnamekey ==
'label')) {
327 $fieldnamekey =
'Code';
329 if ($fieldnamekey ==
'code') {
330 $fieldnamekey =
'Code';
332 if ($fieldnamekey ==
'note') {
333 $fieldnamekey =
'Note';
335 if ($fieldnamekey ==
'type_template') {
336 $fieldnamekey =
'TypeOfTemplate';
338 if ($fieldnamekey ==
'fk_user') {
339 $fieldnamekey =
'Owner';
341 if ($fieldnamekey ==
'private') {
342 $fieldnamekey =
'Private';
344 if ($fieldnamekey ==
'position') {
345 $fieldnamekey =
'Position';
347 if ($fieldnamekey ==
'topic') {
348 $fieldnamekey =
'Topic';
351 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->transnoentities($fieldnamekey)),
null,
'errors');
357 if ($ok &&
GETPOST(
'actionadd')) {
359 $sql =
"INSERT INTO ".$tabname[$id].
" (";
361 $sql .= $tabfieldinsert[$id];
362 $sql .=
", active, enabled)";
367 foreach ($listfieldinsert as $f => $value) {
368 $keycode = $listfieldvalue[$i];
369 if ($value ==
'lang') {
370 $keycode =
'langcode';
372 if (empty($keycode)) {
377 if ($value ==
'entity') {
378 $_POST[$keycode] = $conf->entity;
380 if ($value ==
'fk_user' && !($_POST[$keycode] > 0)) {
381 $_POST[$keycode] =
'';
383 if ($value ==
'private' && !is_numeric($_POST[$keycode])) {
384 $_POST[$keycode] =
'0';
386 if ($value ==
'position' && !is_numeric($_POST[$keycode])) {
387 $_POST[$keycode] =
'1';
394 if (
GETPOST($keycode) ==
'' && $keycode !=
'langcode') {
396 } elseif (
GETPOST($keycode) ==
'0' && $keycode ==
'langcode') {
398 } elseif ($keycode ==
'fk_user') {
400 $sql .=
" ".((int) $user->id);
402 $sql .=
" ".((int)
GETPOST($keycode,
'int'));
404 } elseif ($keycode ==
'content') {
405 $sql .=
"'".$db->escape(
GETPOST($keycode,
'restricthtml')).
"'";
406 } elseif (in_array($keycode, array(
'joinfiles',
'private',
'position',
'entity'))) {
407 $sql .= (int)
GETPOST($keycode,
'int');
409 $sql .=
"'".$db->escape(
GETPOST($keycode,
'alphanohtml')).
"'";
416 $result = $db->query($sql);
419 $_POST = array(
'id'=>$id);
421 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
422 setEventMessages($langs->transnoentities(
"ErrorRecordAlreadyExists"),
null,
'errors');
431 if ($ok &&
GETPOST(
'actionmodify')) {
435 $sql =
"UPDATE ".$tabname[$id].
" SET ";
438 foreach ($listfieldmodify as $field) {
439 if ($field ==
'entity') {
442 $_POST[$keycode] = $conf->entity;
444 $keycode = $listfieldvalue[$i];
447 if ($field ==
'lang') {
448 $keycode =
'langcode';
450 if (empty($keycode)) {
455 if ($field ==
'fk_user' && !($_POST[
'fk_user'] > 0)) {
456 $_POST[
'fk_user'] =
'';
458 if ($field ==
'topic') {
459 $_POST[
'topic'] = $_POST[
'topic-'.$rowid];
461 if ($field ==
'joinfiles') {
462 $_POST[
'joinfiles'] = $_POST[
'joinfiles-'.$rowid];
464 if ($field ==
'content') {
465 $_POST[
'content'] = $_POST[
'content-'.$rowid];
467 if ($field ==
'content_lines') {
468 $_POST[
'content_lines'] = $_POST[
'content_lines-'.$rowid];
476 if (
GETPOST($keycode) ==
'' || ($keycode !=
'langcode' && $keycode !=
'position' && $keycode !=
'private' && !
GETPOST($keycode))) {
478 } elseif (
GETPOST($keycode) ==
'0' && $keycode ==
'langcode') {
480 } elseif ($keycode ==
'fk_user') {
482 $sql .=
" ".((int) $user->id);
484 $sql .=
" ".((int)
GETPOST($keycode,
'int'));
486 } elseif ($keycode ==
'content') {
487 $sql .=
"'".$db->escape(
GETPOST($keycode,
'restricthtml')).
"'";
488 } elseif (in_array($keycode, array(
'joinfiles',
'private',
'position'))) {
489 $sql .= (int)
GETPOST($keycode,
'int');
491 $sql .=
"'".$db->escape(
GETPOST($keycode,
'alphanohtml')).
"'";
497 $sql .=
" WHERE ".$rowidcol.
" = ".((int) $rowid);
499 $sql .=
" AND fk_user = ".((int) $user->id);
504 $resql = $db->query($sql);
514 if ($action ==
'confirm_delete' && $confirm ==
'yes') {
517 $sql =
"DELETE from ".$tabname[$id].
" WHERE ".$rowidcol.
" = ".((int) $rowid);
519 $sql .=
" AND fk_user = ".((int) $user->id);
522 $result = $db->query($sql);
524 if ($db->errno() ==
'DB_ERROR_CHILD_EXISTS') {
525 setEventMessages($langs->transnoentities(
"ErrorRecordIsUsedByChild"),
null,
'errors');
533 if ($action == $acts[0]) {
536 $sql =
"UPDATE ".$tabname[$id].
" SET active = 1 WHERE rowid = ".((int) $rowid);
538 $result = $db->query($sql);
545 if ($action == $acts[1]) {
548 $sql =
"UPDATE ".$tabname[$id].
" SET active = 0 WHERE rowid = ".((int) $rowid);
550 $result = $db->query($sql);
570 if (!empty($user->admin) && (empty($_SESSION[
'leftmenu']) || $_SESSION[
'leftmenu'] !=
'email_templates')) {
571 $title = $langs->trans(
"EMailsSetup");
573 $title = $langs->trans(
"EMailTemplates");
578 $sql =
"SELECT rowid as rowid, module, label, type_template, lang, fk_user, private, position, topic, joinfiles, content_lines, content, enabled, active";
579 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_email_templates";
580 $sql .=
" WHERE entity IN (".getEntity(
'email_template').
")";
582 $sql .=
" AND (private = 0 OR (private = 1 AND fk_user = ".((int) $user->id).
"))";
583 $sql .=
" AND (active = 1 OR fk_user = ".((int) $user->id).
")";
585 if (empty($conf->global->MAIN_MULTILANGS)) {
586 $sql .=
" AND (lang = '".$db->escape($langs->defaultlang).
"' OR lang IS NULL OR lang = '')";
591 if ($search_type_template !=
'' && $search_type_template !=
'-1') {
597 if ($search_fk_user !=
'' && $search_fk_user !=
'-1') {
604 if ($sortfield ==
'country') {
605 $sortfield =
'country_code';
607 $sql .= $db->order($sortfield, $sortorder);
608 $sql .= $db->plimit($listlimit + 1, $offset);
616 $arrayofselected = is_array($toselect) ? $toselect : array();
620 $param .=
'&mode='.urlencode($mode);
622 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
623 $param .=
'&contextpage='.urlencode($contextpage);
625 if ($limit > 0 && $limit != $conf->liste_limit) {
626 $param .=
'&limit='.urlencode($limit);
628 if (!empty($search) && is_array($search)) {
629 foreach ($search as $key => $val) {
630 if (is_array($search[$key]) && count($search[$key])) {
631 foreach ($search[$key] as $skey) {
633 $param .=
'&search_'.$key.
'[]='.urlencode($skey);
636 } elseif ($search[$key] !=
'') {
637 $param .=
'&search_'.$key.
'='.urlencode($search[$key]);
641 if ($optioncss !=
'') {
642 $param .=
'&optioncss='.urlencode($optioncss);
645 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_list_search_param.tpl.php';
647 $parameters = array();
648 $reshook = $hookmanager->executeHooks(
'printFieldListSearchParam', $parameters, $object);
649 $param .= $hookmanager->resPrint;
653 $titlepicto =
'title_setup';
656 $url = DOL_URL_ROOT.
'/admin/mails_templates.php?action=add&token='.
newToken();
657 $newcardbutton =
dolGetButtonTitle($langs->trans(
'NewEMailTemplate'),
'',
'fa fa-plus-circle', $url,
'', $permissiontoadd);
660 if (!empty($user->admin) && (empty($_SESSION[
'leftmenu']) || $_SESSION[
'leftmenu'] !=
'email_templates')) {
666 if (!empty($user->admin) && (empty($_SESSION[
'leftmenu']) || $_SESSION[
'leftmenu'] !=
'email_templates')) {
671 if (!empty($user->admin) && (empty($_SESSION[
'leftmenu']) || $_SESSION[
'leftmenu'] !=
'email_templates')) {
678 if ($action ==
'delete') {
679 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?'.($page ?
'page='.$page.
'&' :
'').
'sortfield='.$sortfield.
'&sortorder='.$sortorder.
'&rowid='.$rowid.
'&code='.$code.
'&id='.$id, $langs->trans(
'DeleteLine'), $langs->trans(
'ConfirmDeleteLine'),
'confirm_delete',
'', 0, 1);
685 $fieldlist = explode(
',', $tabfield[$id]);
687 if ($action ==
'add') {
689 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.$id.
'" method="POST">';
690 print
'<input type="hidden" name="token" value="'.newToken().
'">';
691 print
'<input type="hidden" name="from" value="'.dol_escape_htmltag(
GETPOST(
'from',
'alpha')).
'">';
693 print
'<div class="div-table-responsive-no-min">';
694 print
'<table class="noborder centpercent">';
697 print
'<tr class="liste_titre">';
698 foreach ($fieldlist as $field => $value) {
701 $valuetoshow = ucfirst($fieldlist[$field]);
702 $valuetoshow = $langs->trans($valuetoshow);
704 if ($fieldlist[$field] ==
'fk_user') {
705 $valuetoshow = $langs->trans(
"Owner");
707 if ($fieldlist[$field] ==
'lang') {
708 $valuetoshow = (empty($conf->global->MAIN_MULTILANGS) ?
' ' : $langs->trans(
"Language"));
710 if ($fieldlist[$field] ==
'type') {
711 $valuetoshow = $langs->trans(
"Type");
713 if ($fieldlist[$field] ==
'code') {
714 $valuetoshow = $langs->trans(
"Code");
716 if ($fieldlist[$field] ==
'libelle' || $fieldlist[$field] ==
'label') {
717 $valuetoshow = $langs->trans(
"Code");
719 if ($fieldlist[$field] ==
'type_template') {
720 $valuetoshow = $langs->trans(
"TypeOfTemplate"); $align =
"center";
722 if ($fieldlist[$field] ==
'private') {
725 if ($fieldlist[$field] ==
'position') {
729 if ($fieldlist[$field] ==
'topic') {
732 if ($fieldlist[$field] ==
'joinfiles') {
735 if ($fieldlist[$field] ==
'content') {
738 if ($fieldlist[$field] ==
'content_lines') {
742 if ($valuetoshow !=
'') {
743 print
'<th class="'.$align.
'">';
744 if (!empty($tabhelp[$id][$value]) && preg_match(
'/^http(s*):/i', $tabhelp[$id][$value])) {
745 print
'<a href="'.$tabhelp[$id][$value].
'" target="_blank" rel="noopener noreferrer">'.$valuetoshow.
' '.
img_help(1, $valuetoshow).
'</a>';
746 } elseif (!empty($tabhelp[$id][$value])) {
747 if (in_array($value, array(
'topic'))) {
748 print
$form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1,
'help',
'', 0, 2, $value);
750 print
$form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1,
'help',
'', 0, 2);
759 print
'<input type="hidden" name="id" value="'.$id.
'">';
763 $obj =
new stdClass();
766 foreach ($fieldlist as $key => $val) {
773 $tmpaction =
'create';
775 'fieldlist' => $fieldlist,
776 'tabname' => $tabname[$id]
778 $reshook = $hookmanager->executeHooks(
'createEmailTemplateFieldlist', $parameters, $obj, $tmpaction);
779 $error = $hookmanager->error;
780 $errors = $hookmanager->errors;
784 print
'<tr class="oddeven">';
786 if (empty($reshook)) {
787 if ($action ==
'edit') {
788 fieldList($fieldlist, $obj, $tabname[$id],
'hide');
790 fieldList($fieldlist, $obj, $tabname[$id],
'add');
794 print
'<td class="right">';
799 $fieldsforcontent = array(
'topic',
'joinfiles',
'content');
800 if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
801 $fieldsforcontent = array(
'topic',
'joinfiles',
'content',
'content_lines');
803 foreach ($fieldsforcontent as $tmpfieldlist) {
804 print
'<tr class="impair nodrag nodrop nohover"><td colspan="7" class="nobottom">';
807 if ($tmpfieldlist ==
'topic') {
808 print
'<strong>'.$form->textwithpicto($langs->trans(
"Topic"), $tabhelp[$id][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'</strong> ';
810 if ($tmpfieldlist ==
'joinfiles') {
811 print
'<strong>'.$form->textwithpicto($langs->trans(
"FilesAttachedToEmail"), $tabhelp[$id][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'</strong> ';
813 if ($tmpfieldlist ==
'content') {
814 print
$form->textwithpicto($langs->trans(
"Content"), $tabhelp[$id][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'<br>';
816 if ($tmpfieldlist ==
'content_lines') {
817 print
$form->textwithpicto($langs->trans(
"ContentForLines"), $tabhelp[$id][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'<br>';
821 if ($tmpfieldlist ==
'topic') {
822 print
'<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.
'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} :
'').
'">';
823 } elseif ($tmpfieldlist ==
'joinfiles') {
824 print
'<input type="text" class="flat maxwidth50" name="'.$tmpfieldlist.
'" value="'.(isset($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} :
'1').
'">';
827 $okforextended =
true;
828 if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
829 $okforextended =
false;
831 $doleditor =
new DolEditor($tmpfieldlist, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} :
''),
'', 180,
'dolibarr_mailings',
'In', 0,
true, $okforextended, ROWS_4,
'90%');
832 print $doleditor->Create(1);
840 if ($action !=
'edit') {
842 print
'<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans(
"Add").
'"> ';
843 print
'<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans(
"Cancel").
'">';
854 $resql = $db->query($sql);
860 $num = $db->num_rows(
$resql);
862 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.$id.
'" method="POST">';
863 print
'<input type="hidden" name="token" value="'.newToken().
'">';
864 print
'<input type="hidden" name="from" value="'.dol_escape_htmltag(
GETPOST(
'from',
'alpha')).
'">';
866 print
'<div class="div-table-responsive-no-min">';
867 print
'<table class="noborder centpercent">';
873 $param .=
'&search_label='.urlencode($search_label);
875 if ($search_lang > 0) {
876 $param .=
'&search_lang='.urlencode($search_lang);
878 if ($search_type_template !=
'-1') {
879 $param .=
'&search_type_template='.urlencode($search_type_template);
881 if ($search_fk_user > 0) {
882 $param .=
'&search_fk_user='.urlencode($search_fk_user);
885 $param .=
'&search_topic='.urlencode($search_topic);
888 $paramwithsearch = $param;
890 $paramwithsearch .=
'&sortorder='.urlencode($sortorder);
893 $paramwithsearch .=
'&sortfield='.urlencode($sortfield);
895 if (
GETPOST(
'from',
'alpha')) {
896 $paramwithsearch .=
'&from='.urlencode(
GETPOST(
'from',
'alpha'));
900 if ($num > $listlimit) {
901 print
'<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).
'">';
902 print_fleche_navigation($page, $_SERVER[
"PHP_SELF"], $paramwithsearch, ($num > $listlimit),
'<li class="pagination"><span>'.$langs->trans(
"Page").
' '.($page + 1).
'</span></li>');
908 print
'<tr class="liste_titre">';
910 foreach ($fieldlist as $field => $value) {
911 if ($value ==
'label') {
912 print
'<td class="liste_titre"><input type="text" name="search_label" class="maxwidth200" value="'.dol_escape_htmltag($search_label).
'"></td>';
913 } elseif ($value ==
'lang') {
914 print
'<td class="liste_titre">';
915 print $formadmin->select_language($search_lang,
'search_lang', 0,
null, 1, 0, 0,
'maxwidth150');
917 } elseif ($value ==
'fk_user') {
918 print
'<td class="liste_titre">';
919 print
$form->select_dolusers($search_fk_user,
'search_fk_user', 1,
null, 0, ($user->admin ?
'' :
'hierarchyme'),
null, 0, 0, 0,
'', 0,
'',
'maxwidth150');
921 } elseif ($value ==
'topic') {
922 print
'<td class="liste_titre"><input type="text" name="search_topic" value="'.dol_escape_htmltag($search_topic).
'"></td>';
923 } elseif ($value ==
'type_template') {
924 print
'<td class="liste_titre center">';
925 print
$form->selectarray(
'search_type_template', $elementList, $search_type_template, 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth150', 1,
'', 0, 1);
927 } elseif (!in_array($value, array(
'content',
'content_lines'))) {
928 print
'<td class="liste_titre"></td>';
932 if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
933 print
'<td class="liste_titre"></td>';
937 print
'<td class="liste_titre right" width="64">';
938 $searchpicto =
$form->showFilterButtons();
944 print
'<tr class="liste_titre">';
945 foreach ($fieldlist as $field => $value) {
958 $valuetoshow = ucfirst($fieldlist[$field]);
959 $valuetoshow = $langs->trans($valuetoshow);
960 if ($fieldlist[$field] ==
'fk_user') {
961 $valuetoshow = $langs->trans(
"Owner");
963 if ($fieldlist[$field] ==
'lang') {
964 $valuetoshow = $langs->trans(
"Language");
966 if ($fieldlist[$field] ==
'type') {
967 $valuetoshow = $langs->trans(
"Type");
969 if ($fieldlist[$field] ==
'libelle' || $fieldlist[$field] ==
'label') {
970 $valuetoshow = $langs->trans(
"Code");
972 if ($fieldlist[$field] ==
'type_template') {
974 $valuetoshow = $langs->trans(
"TypeOfTemplate");
976 if ($fieldlist[$field] ==
'private') {
979 if ($fieldlist[$field] ==
'position') {
983 if ($fieldlist[$field] ==
'joinfiles') {
984 $valuetoshow = $langs->trans(
"FilesAttachedToEmail"); $align =
'center'; $forcenowrap = 0;
986 if ($fieldlist[$field] ==
'content') {
987 $valuetoshow = $langs->trans(
"Content"); $showfield = 0;
989 if ($fieldlist[$field] ==
'content_lines') {
990 $valuetoshow = $langs->trans(
"ContentForLines"); $showfield = 0;
995 if (!empty($tabhelp[$id][$value])) {
996 if (in_array($value, array(
'topic'))) {
997 $valuetoshow =
$form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1,
'help',
'', 0, 2,
'tooltip'.$value, $forcenowrap);
999 $valuetoshow =
$form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1,
'help',
'', 0, 2,
'', $forcenowrap);
1002 print
getTitleFieldOfList($valuetoshow, 0, $_SERVER[
"PHP_SELF"], ($sortable ? $fieldlist[$field] :
''), ($page ?
'page='.$page.
'&' :
''), $param,
"align=".$align, $sortfield, $sortorder);
1006 print
getTitleFieldOfList($langs->trans(
"Status"), 0, $_SERVER[
"PHP_SELF"],
"active", ($page ?
'page='.$page.
'&' :
''), $param,
'align="center"', $sortfield, $sortorder);
1015 $obj = $db->fetch_object(
$resql);
1018 if ($action ==
'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
1019 print
'<tr class="oddeven" id="rowid-'.$obj->rowid.
'">';
1021 $tmpaction =
'edit';
1022 $parameters = array(
'fieldlist'=>$fieldlist,
'tabname'=>$tabname[$id]);
1023 $reshook = $hookmanager->executeHooks(
'editEmailTemplateFieldlist', $parameters, $obj, $tmpaction);
1024 $error = $hookmanager->error; $errors = $hookmanager->errors;
1027 if (empty($reshook)) {
1028 fieldList($fieldlist, $obj, $tabname[$id],
'edit');
1031 print
'<td></td><td></td><td></td>';
1032 print
'<td class="center">';
1033 print
'<input type="hidden" name="page" value="'.$page.
'">';
1034 print
'<input type="hidden" name="rowid" value="'.$rowid.
'">';
1035 print
'<input type="submit" class="button buttongen button-save" name="actionmodify" value="'.$langs->trans(
"Modify").
'">';
1036 print
'<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).
'"></div>';
1037 print
'<input type="submit" class="button buttongen button-cancel" name="actioncancel" value="'.$langs->trans(
"Cancel").
'">';
1040 $fieldsforcontent = array(
'topic',
'joinfiles',
'content');
1041 if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
1042 $fieldsforcontent = array(
'topic',
'joinfiles',
'content',
'content_lines');
1044 foreach ($fieldsforcontent as $tmpfieldlist) {
1047 $valuetoshow = $obj->{$tmpfieldlist};
1053 print
'</tr><tr class="oddeven" nohover tr-'.$tmpfieldlist.
'-'.$rowid.
' ">';
1054 print
'<td colspan="8">';
1055 if ($tmpfieldlist ==
'topic') {
1056 print
'<strong>'.$form->textwithpicto($langs->trans(
"Topic"), $tabhelp[$id][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'</strong> ';
1057 print
'<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.
'-'.$rowid.
'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} :
'').
'">';
1059 if ($tmpfieldlist ==
'joinfiles') {
1060 print
'<strong>'.$form->textwithpicto($langs->trans(
"FilesAttachedToEmail"), $tabhelp[$id][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'</strong> ';
1061 print
'<input type="text" class="flat maxwidth50" name="'.$tmpfieldlist.
'-'.$rowid.
'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} :
'').
'">';
1068 $acceptlocallinktomedia =
getDolGlobalInt(
'MAIN_DISALLOW_MEDIAS_IN_EMAIL_TEMPLATES') ? 0 : 1;
1069 if ($acceptlocallinktomedia) {
1070 global $dolibarr_main_url_root;
1071 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1074 $newUrlArray = parse_url($urlwithouturlroot);
1075 $hosttocheck = $newUrlArray[
'host'];
1076 $hosttocheck = str_replace(array(
'[',
']'),
'', $hosttocheck);
1078 if (function_exists(
'gethostbyname')) {
1079 $iptocheck = gethostbyname($hosttocheck);
1081 $iptocheck = $hosttocheck;
1085 if (!filter_var($iptocheck, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
1087 $acceptlocallinktomedia = 0;
1091 if (preg_match(
'/http:/i', $urlwithouturlroot)) {
1093 $acceptlocallinktomedia = 0;
1098 if ($tmpfieldlist ==
'content') {
1099 print
$form->textwithpicto($langs->trans(
"Content"), $tabhelp[$id][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'<br>';
1100 $okforextended =
true;
1101 if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
1102 $okforextended =
false;
1104 $doleditor =
new DolEditor($tmpfieldlist.
'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} :
''),
'', 500,
'dolibarr_mailings',
'In', 0, $acceptlocallinktomedia, $okforextended, ROWS_6,
'90%');
1105 print $doleditor->Create(1);
1107 if ($tmpfieldlist ==
'content_lines') {
1108 print
$form->textwithpicto($langs->trans(
"ContentForLines"), $tabhelp[$id][$tmpfieldlist], 1,
'help',
'', 0, 2, $tmpfieldlist).
'<br>';
1109 $okforextended =
true;
1110 if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
1111 $okforextended =
false;
1113 $doleditor =
new DolEditor($tmpfieldlist.
'-'.$rowid, (! empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} :
''),
'', 140,
'dolibarr_mailings',
'In', 0, $acceptlocallinktomedia, $okforextended, ROWS_6,
'90%');
1114 print $doleditor->Create(1);
1128 $tempmodulekey = $obj->module;
1129 if (empty($conf->$tempmodulekey) || empty($conf->$tempmodulekey->enabled)) {
1135 $keyforobj =
'type_template';
1136 if (!in_array($obj->$keyforobj, array_keys($elementList))) {
1141 if (!
dol_eval($obj->enabled, 1, 1,
'1')) {
1148 print
'<tr class="oddeven" id="rowid-'.$obj->rowid.
'">';
1150 $tmpaction =
'view';
1151 $parameters = array(
'fieldlist'=>$fieldlist,
'tabname'=>$tabname[$id]);
1152 $reshook = $hookmanager->executeHooks(
'viewEmailTemplateFieldlist', $parameters, $obj, $tmpaction);
1154 $error = $hookmanager->error; $errors = $hookmanager->errors;
1156 if (empty($reshook)) {
1157 foreach ($fieldlist as $field => $value) {
1158 if (in_array($fieldlist[$field], array(
'content',
'content_lines'))) {
1165 $valuetoshow = $obj->{$fieldlist[$field]};
1166 if ($value ==
'label' || $value ==
'topic') {
1167 if ($langs->trans($valuetoshow) != $valuetoshow) {
1168 $valuetoshow = $langs->trans($valuetoshow);
1172 if ($value ==
'label') {
1173 $class .=
' tdoverflowmax100';
1175 if ($value ==
'topic') {
1176 $class .=
' tdoverflowmax200 small';
1178 if ($value ==
'type_template') {
1179 $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
1182 if ($value ==
'lang' && $valuetoshow) {
1183 $valuetoshow = $valuetoshow.
' - '.$langs->trans(
"Language_".$valuetoshow);
1185 if ($value ==
'fk_user') {
1186 if ($valuetoshow > 0) {
1187 $fuser =
new User($db);
1188 $fuser->fetch($valuetoshow);
1189 $valuetoshow = $fuser->getNomUrl(1);
1192 if ($value ==
'private') {
1195 $valuetoshow =
yn($valuetoshow);
1200 if ($value ==
'position') {
1203 if ($value ==
'joinfiles') {
1212 $class .=
' '.$align;
1217 print
'<!-- '.$fieldlist[$field].
' -->';
1218 print
'<td class="'.$class.
'"';
1219 if (in_array($value, array(
'code',
'label',
'topic'))) {
1220 print
' title="'.dol_escape_htmltag($valuetoshow).
'"';
1230 $iserasable = 1; $canbedisabled = 1; $canbemodified = 1;
1231 if (!$user->admin && $obj->fk_user != $user->id) {
1237 $url = $_SERVER[
"PHP_SELF"].
'?'.($page ?
'page='.$page.
'&' :
'').
'sortfield='.$sortfield.
'&sortorder='.$sortorder.
'&rowid='.(!empty($obj->rowid) ? $obj->rowid : (!empty($obj->code) ? $obj->code :
'')).
'&code='.(!empty($obj->code) ?urlencode($obj->code) :
'');
1243 print
'<td class="center nowrap">';
1244 if ($canbedisabled) {
1245 print
'<a class="reposition" href="'.$url.
'&action='.$acts[$obj->active].
'&token='.
newToken().
'">'.$actl[$obj->active].
'</a>';
1247 print
'<span class="opacitymedium">'.$actl[$obj->active].
'</span>';
1252 print
'<td class="center nowraponall" width="64">';
1253 if ($canbemodified) {
1254 print
'<a class="reposition editfielda" href="'.$url.
'&action=edit&token='.
newToken().
'">'.
img_edit().
'</a>';
1257 print
'<a class="marginleftonly" href="'.$url.
'&action=delete&token='.
newToken().
'">'.
img_delete().
'</a>';
1271 if ($nbqualified == 0) {
1273 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
1282 if (!empty($user->admin) && (empty($_SESSION[
'leftmenu']) || $_SESSION[
'leftmenu'] !=
'email_templates')) {
1301 function fieldList($fieldlist, $obj =
'', $tabname =
'', $context =
'')
1303 global $conf, $langs, $user, $db;
1305 global $elementList;
1309 foreach ($fieldlist as $field => $value) {
1310 if ($value ==
'fk_user') {
1313 print
$form->select_dolusers(empty($obj->{$value}) ?
'' : $obj->{$value},
'fk_user', 1,
null, 0, ($user->admin ?
'' :
'hierarchyme'),
null, 0, 0, 0,
'', 0,
'',
'minwidth150 maxwidth300');
1315 if ($context ==
'add') {
1316 print $user->getNomUrl(1);
1317 $forcedvalue = $user->id;
1319 if ($obj && !empty($obj->{$value}) && $obj->{$value} > 0) {
1320 $fuser =
new User($db);
1321 $fuser->fetch($obj->{$value});
1322 print $fuser->getNomUrl(1);
1323 $forcedvalue = $fuser->id;
1325 $forcedvalue = $obj->{$value};
1329 print
'<input type="hidden" value="'.$forcedvalue.
'" name="'.$keyname.
'">';
1332 } elseif ($value ==
'lang') {
1334 if (!empty($conf->global->MAIN_MULTILANGS)) {
1335 $selectedlang =
GETPOSTISSET(
'langcode') ?
GETPOST(
'langcode',
'aZ09') : $langs->defaultlang;
1336 if ($context ==
'edit') {
1337 $selectedlang = $obj->{$value};
1339 print $formadmin->select_language($selectedlang,
'langcode', 0,
null, 1, 0, 0,
'maxwidth150');
1341 if (!empty($obj->{$value})) {
1342 print $obj->{$value}.
' - '.$langs->trans(
'Language_'.$obj->{$value});
1345 if ($keyname ==
'lang') {
1346 $keyname =
'langcode';
1348 print
'<input type="hidden" value="'.(empty($obj->{$value}) ?
'' : $obj->{$value}).
'" name="'.$keyname.
'">';
1351 } elseif ($value ==
'type_template') {
1353 print
'<td class="center">';
1354 if ($context ==
'edit' && !empty($obj->{$value}) && !in_array($obj->{$value}, array_keys($elementList))) {
1356 print
'<input type="hidden" name="type_template" value="'.$obj->{$value}.
'">';
1357 print $obj->{$value};
1359 print
$form->selectarray(
'type_template', $elementList, (!empty($obj->{$value}) ? $obj->{$value}:
''), 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth150', 1,
'', 0, 1);
1362 } elseif ($context ==
'add' && in_array($value, array(
'topic',
'joinfiles',
'content',
'content_lines'))) {
1364 } elseif ($context ==
'edit' && in_array($value, array(
'topic',
'joinfiles',
'content',
'content_lines'))) {
1366 } elseif ($context ==
'hide' && in_array($value, array(
'topic',
'joinfiles',
'content',
'content_lines'))) {
1369 $size =
''; $class =
''; $classtd =
'';
1370 if ($value ==
'code') {
1371 $class =
'maxwidth100';
1373 if ($value ==
'label') {
1374 $class =
'maxwidth200';
1376 if ($value ==
'private') {
1377 $class =
'maxwidth50'; $classtd =
'center';
1379 if ($value ==
'position') {
1380 $class =
'maxwidth50'; $classtd =
'center';
1382 if ($value ==
'libelle') {
1383 $class =
'quatrevingtpercent';
1385 if ($value ==
'topic') {
1386 $class =
'quatrevingtpercent';
1388 if ($value ==
'sortorder' || $value ==
'sens' || $value ==
'category_type') {
1389 $size =
'size="2" ';
1392 print
'<td'.($classtd ?
' class="'.$classtd.
'"' :
'').
'>';
1393 if ($value ==
'private') {
1394 if (empty($user->admin)) {
1395 print
$form->selectyesno($value,
'1', 1);
1398 print
$form->selectyesno($value, (isset($obj->{$value}) ? $obj->{$value}:
''), 1);
1401 print
'<input type="text" '.$size.
'class="flat'.($class ?
' '.$class :
'').
'" value="'.(isset($obj->{$value}) ? $obj->{$value}:
'').
'" name="'. $value .
'">';