dolibarr 25.0.0-alpha
mails_templates.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2011-2018 Philippe Grand <philippe.grand@atoo-net.com>
8 * Copyright (C) 2011 Remy Younes <ryounes@gmail.com>
9 * Copyright (C) 2012-2015 Marcos García <marcosgdf@gmail.com>
10 * Copyright (C) 2012 Christophe Battarel <christophe.battarel@ltairis.fr>
11 * Copyright (C) 2011-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
12 * Copyright (C) 2015-2024 Ferran Marcet <fmarcet@2byte.es>
13 * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
14 * Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
15 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
16 * Copyright (C) 2025 Vincent Maury <vmaury@timgroup.fr>
17 * Copyright (C) 2025 Jon Bendtsen <jon.bendtsen.github@jonb.dk>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 3 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <https://www.gnu.org/licenses/>.
31 */
32
39// Load Dolibarr environment
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';
56
57// Load translation files required by the page
58$langsArray = array("errors", "admin", "mails", "languages");
59
60if (isModEnabled('member')) {
61 $langsArray[] = 'members';
62}
63if (isModEnabled('eventorganization')) {
64 $langsArray[] = 'eventorganization';
65}
66
67$langs->loadLangs($langsArray);
68
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'); // Result of a confirmation
73$mode = GETPOST('mode', 'aZ09');
74$optioncss = GETPOST('optioncss', 'alpha');
75$backtopage = GETPOST('backtopage');
76$contextpage = GETPOST('contextpage', 'aZ09');
77
78$rowid = (GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('rowid'));
79$search_label = GETPOST('search_label', 'alphanohtml'); // Must allow value like 'Abc Def' or '(MyTemplateName)'
80$search_type_template = GETPOST('search_type_template', 'alpha');
81$search_lang = GETPOST('search_lang', 'alpha');
82$defaulttemplatelang = $langs->defaultlang;
83if (!getDolGlobalInt('MAIN_MULTILANGS')) {
84 $search_lang = '';
85 $templatelangs = new Translate('', $conf);
86 $templatelangs->setDefaultLang(getDolGlobalString('MAIN_LANG_DEFAULT', 'auto'));
87 $defaulttemplatelang = $templatelangs->defaultlang;
88}
89$search_fk_user = GETPOST('search_fk_user', 'intcomma');
90$search_topic = GETPOST('search_topic', 'alpha');
91$search_module = GETPOST('search_module', 'alpha');
92$search_private = GETPOSTISSET('search_private') ? GETPOSTINT('search_private') : -1;
93$search_position = GETPOST('search_position', 'int');
94$search_joinfiles = GETPOSTISSET('search_joinfiles') ? GETPOSTINT('search_joinfiles') : -1;
95$search_defaultfortype = GETPOSTISSET('search_defaultfortype') ? GETPOSTINT('search_defaultfortype') : -1;
96
97$acts = array();
98$actl = array();
99$acts[0] = "activate";
100$acts[1] = "disable";
101$actl[0] = img_picto($langs->trans("Disabled"), 'switch_off', 'class="size15x"');
102$actl[1] = img_picto($langs->trans("Activated"), 'switch_on', 'class="size15x"');
103
104$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
105$sortfield = GETPOST('sortfield', 'aZ09comma');
106$sortorder = GETPOST('sortorder', 'aZ09comma');
107$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
108if (empty($page) || $page == -1) {
109 $page = 0;
110} // If $page is not defined, or '' or -1
111$offset = $limit * $page;
112$pageprev = $page - 1;
113$pagenext = $page + 1;
114
115if (empty($sortfield)) {
116 $sortfield = 'type_template,lang,position,label';
117}
118if (empty($sortorder)) {
119 $sortorder = 'ASC';
120}
121
122// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
123$hookmanager->initHooks(array('emailtemplates'));
124
125$object = new CEmailTemplate($db);
126
127// Definition of array of fields for columns from ->fields
128$tableprefix = 't';
129$arrayfields = array();
130foreach ($object->fields as $key => $val) {
131 // If $val['visible']==0, then we never show the field
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'] : ''
140 );
141 }
142}
143
144$arrayfields['t.lang']['enabled'] = (string) getDolGlobalInt('MAIN_MULTILANGS');
145if (!getDolGlobalInt('MAIN_MULTILANGS')) {
146 $arrayfields['t.lang']['checked'] = '0';
147}
148
149// Security
150if (!empty($user->socid)) {
152}
153
154$permissiontoadd = 1;
155$permissiontoedit = ($user->admin ? 1 : 0);
156$permissiontodelete = ($user->admin ? 1 : 0);
157
158$tmpmailtemplate = new CEmailTemplate($db);
159if ($rowid > 0) {
160 $result = $tmpmailtemplate->fetch($rowid);
161 if ($tmpmailtemplate->fk_user == $user->id) {
162 $permissiontoedit = 1;
163 $permissiontodelete = 1;
164 }
165}
166
167// Old way to define field.
168
169// Name of SQL tables of dictionaries
170$tabname = array();
171$tabname[25] = MAIN_DB_PREFIX."c_email_templates";
172
173// Name of the fields in the result of select to display the dictionary
174// Names of fields in select results for dictionary display (AI translated)
175$tabfield = array();
176$tabfield[25] = "label,lang,type_template,fk_user,private,position,module,topic,joinfiles,defaultfortype,content";
177if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
178 $tabfield[25] .= ',content_lines';
179}
180
181// Name of editing fields for record modification
182// Names of edit fields for modifying a record (AI translated)
183$tabfieldvalue = array();
184$tabfieldvalue[25] = "label,lang,type_template,fk_user,private,position,topic,email_from,joinfiles,defaultfortype,content";
185if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TO')) {
186 $tabfieldvalue[25] .= ',email_to';
187}
188if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOCC')) {
189 $tabfieldvalue[25] .= ',email_tocc';
190}
191if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOBCC')) {
192 $tabfieldvalue[25] .= ',email_tobcc';
193}
194if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
195 $tabfieldvalue[25] .= ',content_lines';
196}
197
198// Name of the fields in the table for inserting a record
199// Field names in the table for inserting a record (AI translated)
200$tabfieldinsert = array();
201$tabfieldinsert[25] = "label,lang,type_template,fk_user,private,position,topic,email_from,joinfiles,defaultfortype,content,datec";
202if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TO')) {
203 $tabfieldvalue[25] .= ',email_to';
204}
205if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOCC')) {
206 $tabfieldvalue[25] .= ',email_tocc';
207}
208if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOBCC')) {
209 $tabfieldvalue[25] .= ',email_tobcc';
210}
211if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
212 $tabfieldinsert[25] .= ',content_lines';
213}
214$tabfieldinsert[25] .= ',entity'; // Must be at end because not into other arrays
215
216// List of help for fields
217// Set MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES to allow edit of template for lines
218require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
219if (!getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
220 $targetobject = fetchObjectByElement(0, $tmpmailtemplate->type_template);
221
222 $tmp = FormMail::getAvailableSubstitKey('formemail', $targetobject);
223
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>';
230 }
231} else {
232 $targetobject = fetchObjectByElement(0, $tmpmailtemplate->type_template);
233
234 $tmp = FormMail::getAvailableSubstitKey('formemailwithlines', $targetobject);
235
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>';
241 }
242 $tmp = FormMail::getAvailableSubstitKey('formemailforlines');
243 foreach ($tmp as $key => $val) {
244 $helpsubstitforlines .= $key.' -> '.$val.'<br>';
245 }
246}
247
248
249$tabhelp = array();
250$tabhelp[25] = array(
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>'
264);
265
266
267// We save list of template email Dolibarr can manage. This list can found by a grep into code on "->param['models']"
268$elementList = array();
269// Add all and none after the sort
270
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'));
276}
277if (isModEnabled('recruitment') && $user->hasRight('recruitment', 'recruitmentjobposition', 'read')) {
278 $elementList['recruitmentcandidature_send'] = img_picto('', 'recruitmentcandidature', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('RecruitmentCandidatures'));
279}
280if (isModEnabled('expensereport') && $user->hasRight('expensereport', 'lire')) {
281 $elementList['expensereport_send'] = img_picto('', 'trip', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendExpenseReport'));
282}
283if (isModEnabled('holiday') && $user->hasRight('holiday', 'read')) {
284 $elementList['holiday'] = img_picto('', 'holiday', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendLeaves'));
285}
286if (isModEnabled("societe") && $user->hasRight('societe', 'lire')) {
287 $elementList['thirdparty'] = img_picto('', 'company', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToThirdparty'));
288}
289if (isModEnabled("societe") && $user->hasRight('societe', 'contact', 'lire')) {
290 $elementList['contact'] = img_picto('', 'contact', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToContact'));
291}
292if (isModEnabled('project')) {
293 $elementList['project'] = img_picto('', 'project', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToProject'));
294}
295if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
296 $elementList['propal_send'] = img_picto('', 'propal', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendProposal'));
297}
298if (isModEnabled('order') && $user->hasRight('commande', 'lire')) {
299 $elementList['order_send'] = img_picto('', 'order', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendOrder'));
300}
301if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
302 $elementList['facture_send'] = img_picto('', 'bill', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendInvoice'));
303}
304if (isModEnabled("shipping")) {
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'));
307}
308if (isModEnabled("reception")) {
309 $elementList['reception_send'] = img_picto('', 'dollyrevert', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendReception'));
310}
311if (isModEnabled('intervention')) {
312 $elementList['fichinter_send'] = img_picto('', 'intervention', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendIntervention'));
313}
314if (isModEnabled('supplier_proposal')) {
315 $elementList['supplier_proposal_send'] = img_picto('', 'propal', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendSupplierRequestForQuotation'));
316}
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'));
319}
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'));
322}
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'));
325}
326if (isModEnabled('contract') && $user->hasRight('contrat', 'lire')) {
327 $elementList['contract'] = img_picto('', 'contract', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendContract'));
328}
329if (isModEnabled('ticket') && $user->hasRight('ticket', 'read')) {
330 $elementList['ticket_send'] = img_picto('', 'ticket', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToTicket'));
331}
332if (isModEnabled('agenda')) {
333 $elementList['actioncomm_send'] = img_picto('', 'action', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendEventPush'));
334}
335if (isModEnabled('eventorganization') && $user->hasRight('project', 'read')) {
336 $elementList['conferenceorbooth'] = img_picto('', 'action', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendEventOrganization'));
337}
338if (isModEnabled('partnership') && $user->hasRight('partnership', 'read')) {
339 $elementList['partnership_send'] = img_picto('', 'partnership', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToPartnership'));
340}
341if (isModEnabled('product') && $user->hasRight('produit', 'lire')) {
342 $elementList['product_send'] = img_picto('', 'product', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('Product'));
343}
344if (isModEnabled('stocktransfer')) {
345 $elementList['stocktransfer_send'] = '<span class="fas fa-box-open em080 valignmiddle pictomodule paddingrightonly" style="color: #a69944;"></span>'.dol_escape_htmltag($langs->trans('MailToSendStockTransfer'));
346}
347
348$parameters = array('elementList' => $elementList);
349$reshook = $hookmanager->executeHooks('emailElementlist', $parameters); // Note that $action and $object may have been modified by some hooks
350if ($reshook == 0) {
351 foreach ($hookmanager->resArray as $item => $value) {
352 $elementList[$item] = $value;
353 }
354}
355
356$error = 0;
357
358$acceptlocallinktomedia = (acceptLocalLinktoMedia() > 0 ? 1 : 0);
359
360
361/*
362 * Actions
363 */
364
365if (GETPOST('cancel', 'alpha') || GETPOST('actioncancel', 'alpha')) {
366 $action = 'list';
367 $massaction = '';
368
369 if (!empty($backtopage)) {
370 header("Location: ".$backtopage);
371 exit(1);
372 }
373}
374if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
375 $massaction = '';
376}
377
378$parameters = array();
379$object = null;
380$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
381if ($reshook < 0) {
382 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
383}
384
385if (empty($reshook)) {
386 // Selection of new fields
387 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
388
389 // Purge search criteria
390 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
391 // All tests are required to be compatible with all browsers
392 $search_label = '';
393 $search_type_template = '';
394 $search_lang = '';
395 $search_fk_user = '';
396 $search_topic = '';
397 $search_module = '';
398 $search_private = -1;
399 $search_position = '';
400 $search_joinfiles = -1;
401 $search_defaultfortype = -1;
402 $toselect = array();
403 $search_array_options = array();
404 }
405
406 // Actions add or modify an email template
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]);
412
413 // Check that all fields are filled
414 $ok = 1;
415 foreach ($listfield as $f => $value) {
416 // Not mandatory fields
417 if (in_array($value, ['joinfiles', 'defaultfortype', 'content', 'content_lines', 'module', 'tms', 'datec', 'email_to', 'email_tocc', 'email_tobcc'])) {
418 continue;
419 }
420
421 // Rename some POST variables into a generic name
422 if (GETPOST('actionmodify', 'alpha') && $value == 'topic') {
423 $_POST['topic'] = GETPOST('topic-'.$rowid);
424 }
425
426 if ((!GETPOSTISSET($value) || GETPOST($value) == '' || GETPOST($value) == '-1') && $value != 'lang' && $value != 'fk_user' && $value != 'position') {
427 $ok = 0;
428 $fieldnamekey = $listfield[$f];
429 // We take translate key of field
430 if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) {
431 $fieldnamekey = 'Code';
432 }
433 if ($fieldnamekey == 'code') {
434 $fieldnamekey = 'Code';
435 }
436 if ($fieldnamekey == 'note') {
437 $fieldnamekey = 'Note';
438 }
439 if ($fieldnamekey == 'type_template') {
440 $fieldnamekey = 'TypeOfTemplate';
441 }
442 if ($fieldnamekey == 'fk_user') {
443 $fieldnamekey = 'Owner';
444 }
445 if ($fieldnamekey == 'private') {
446 $fieldnamekey = 'Private';
447 }
448 if ($fieldnamekey == 'position') {
449 $fieldnamekey = 'Position';
450 }
451 if ($fieldnamekey == 'topic') {
452 $fieldnamekey = 'Topic';
453 }
454
455 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
456 $action = 'create';
457 }
458 }
459
460 // If previous test is ok action is add, we add the line
461 if ($ok && GETPOST('actionadd')) {
462 // Add new entry
463 $sql = "INSERT INTO ".$db->sanitize($tabname[25])." (";
464 // List of fields
465 $sql .= $tabfieldinsert[25];
466 $sql .= ", active, enabled)";
467 $sql .= " VALUES(";
468
469 // List of values
470 $i = 0;
471 $now = dol_now();
472 foreach ($listfieldinsert as $f => $value) {
473 $keycode = isset($listfieldvalue[$i]) ? $listfieldvalue[$i] : "";
474 if ($value == 'lang') {
475 $keycode = 'langcode';
476 }
477 if (empty($keycode)) {
478 $keycode = $value;
479 }
480
481 // Clean input variables
482 if ($value == 'entity') {
483 $_POST[$keycode] = $conf->entity;
484 }
485 if ($value == 'fk_user' && !($_POST[$keycode] > 0)) {
486 $_POST[$keycode] = '';
487 }
488 if ($value == 'private' && !is_numeric($_POST[$keycode])) {
489 $_POST[$keycode] = '0';
490 }
491 if ($value == 'position' && !is_numeric($_POST[$keycode])) {
492 $_POST[$keycode] = '1';
493 }
494 if ($value == 'defaultfortype' && !is_numeric($_POST[$keycode])) {
495 $_POST[$keycode] = '0';
496 }
497 //var_dump($keycode.' '.$value);
498
499 if ($i) {
500 $sql .= ", ";
501 }
502 if ($keycode == 'langcode' && !getDolGlobalInt('MAIN_MULTILANGS')) {
503 $sql .= "'".$db->escape($defaulttemplatelang)."'";
504 } elseif ($keycode == 'datec') {
505 $sql .= "'".$db->idate($now)."'";
506 } elseif (GETPOST($keycode) == '' && $keycode != 'langcode') {
507 $sql .= "null"; // langcode must be '' if not defined so the unique key that include lang will work
508 } elseif ($keycode == 'langcode' && (GETPOST($keycode) == '0' || GETPOST($keycode) == '-1')) {
509 $sql .= "''"; // langcode must be '' if not defined so the unique key that include lang will work
510 } elseif ($keycode == 'fk_user') {
511 if (!$user->admin) { // A non admin user can only edit its own template
512 $sql .= " ".((int) $user->id);
513 } else {
514 $sql .= " ".(GETPOSTINT($keycode));
515 }
516 } elseif ($keycode == 'content') {
517 $sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
518 } elseif (in_array($keycode, array('joinfiles', 'defaultfortype', 'private', 'position', 'entity'))) {
519 $sql .= GETPOSTINT($keycode);
520 } else {
521 $sql .= "'".$db->escape(GETPOST($keycode, 'alphanohtml'))."'";
522 }
523 $i++;
524 }
525 $sql .= ", 1, 1)";
526
527 dol_syslog("actionadd", LOG_DEBUG);
528 $result = $db->query($sql);
529 if ($result) { // Add is ok
530 setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
531 $_POST = array('id' => 25); // Clean $_POST array, we keep only id
532
533 if (!empty($backtopage)) {
534 header("Location: ".$backtopage);
535 exit(1);
536 }
537 } else {
538 if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
539 setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
540 } else {
541 dol_print_error($db);
542 }
543 $action = 'create';
544 }
545 }
546
547 // We modify the line
548 if ($ok && GETPOST('actionmodify')) {
549 $rowidcol = "rowid";
550
551 if (GETPOSTINT('fk_user') <= 0 && GETPOST('private')) {
552 setEventMessages($langs->trans("AnOwnerMustBeSetIfEmailTemplateIsPrivate"), null, 'errors');
553 $error++;
554 $action = 'edit';
555 }
556
557 if (!$error) {
558 // Modify entry
559 $sql = "UPDATE ".$db->sanitize($tabname[25])." SET ";
560 // Modify value of fields
561 $i = 0;
562 foreach ($listfieldmodify as $field) {
563 if ($field == 'entity') {
564 // entity not present on listfieldmodify array
565 $keycode = $field;
566 $_POST[$keycode] = $conf->entity;
567 } else {
568 $keycode = $listfieldvalue[$i];
569 }
570
571 if ($field == 'lang') {
572 $keycode = 'langcode';
573 }
574 if (empty($keycode)) {
575 $keycode = $field;
576 }
577
578 // Rename some POST variables into a generic name
579 if ($field == 'topic') {
580 $_POST['topic'] = GETPOST('topic-'.$rowid);
581 }
582 if ($field == 'joinfiles') {
583 $_POST['joinfiles'] = GETPOST('joinfiles-'.$rowid);
584 }
585 if ($field == 'content') {
586 $_POST['content'] = GETPOST('content-'.$rowid, 'restricthtml');
587 }
588 if ($field == 'content_lines') {
589 $_POST['content_lines'] = GETPOST('content_lines-'.$rowid, 'restricthtml');
590 }
591 if ($field == 'email_from') {
592 $_POST['email_from'] = GETPOST('email_from-'.$rowid, 'email');
593 }
594 if ($field == 'email_to') {
595 $_POST['email_to'] = GETPOST('email_to-'.$rowid, 'email');
596 }
597 if ($field == 'email_tocc') {
598 $_POST['email_tocc'] = GETPOST('email_tocc-'.$rowid, 'email');
599 }
600 if ($field == 'email_tobcc') {
601 $_POST['email_tobcc'] = GETPOST('email_tobcc-'.$rowid, 'email');
602 }
603
604 if ($i) {
605 $sql .= ", ";
606 }
607 $sql .= $field." = ";
608
609 if ($keycode == 'langcode' && !getDolGlobalInt('MAIN_MULTILANGS')) {
610 $sql .= "'".$db->escape($defaulttemplatelang)."'";
611 } elseif ((GETPOST($keycode) == '' && in_array($keycode, array('langcode'))) || (!in_array($keycode, array('langcode', 'position', 'private', 'defaultfortype')) && !GETPOST($keycode))) {
612 $sql .= "null"; // langcode,... must be '' if not defined so the unique key that include lang will work
613 } elseif ($keycode == 'langcode' && (GETPOST($keycode) == '0' || GETPOST($keycode) == '-1')) {
614 $sql .= "''"; // langcode must be '' if not defined so the unique key that include lang will work
615 } elseif ($keycode == 'fk_user') {
616 if (!$user->admin) { // A non admin user can only edit its own template
617 $sql .= ((int) $user->id);
618 } else {
619 $sql .= (GETPOSTINT($keycode) > 0 ? GETPOSTINT($keycode) : "null");
620 }
621 } elseif ($keycode == 'content') {
622 $sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
623 } elseif ($keycode == 'position') {
624 $sql .= (GETPOSTINT($keycode) > 0 ? GETPOSTINT($keycode) : 1);
625 } elseif (in_array($keycode, array('joinfiles', 'defaultfortype', 'private'))) {
626 $sql .= GETPOSTINT($keycode);
627 } else {
628 $sql .= "'".$db->escape(GETPOST($keycode, 'alphanohtml'))."'";
629 }
630 $i++;
631 }
632
633 $sql .= " WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
634 if (!$user->admin) { // A non admin user can only edit its own template
635 $sql .= " AND fk_user = ".((int) $user->id);
636 }
637
638 dol_syslog("actionmodify", LOG_DEBUG);
639
640 //print $sql; exit;
641 $resql = $db->query($sql);
642 if (!$resql) {
643 $error++;
644 setEventMessages($db->error(), null, 'errors');
645 $action = 'edit';
646 }
647 }
648
649 if (!$error) {
650 setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
651 }
652 }
653 }
654
655 if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) { // delete
656 $rowidcol = "rowid";
657
658 $sql = "DELETE from ".$db->sanitize($tabname[25])." WHERE rowid = ".((int) $rowid);
659 if (!$user->admin) { // A non admin user can only edit its own template
660 $sql .= " AND fk_user = ".((int) $user->id);
661 }
662 dol_syslog("delete", LOG_DEBUG);
663 $result = $db->query($sql);
664 if (!$result) {
665 if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
666 setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
667 } else {
668 dol_print_error($db);
669 }
670 }
671 }
672
673 // activate
674 if ($action == $acts[0] && $permissiontoedit) {
675 $rowidcol = "rowid";
676
677 $sql = "UPDATE ".$db->sanitize($tabname[25])." SET active = 1 WHERE rowid = ".((int) $rowid);
678
679 $result = $db->query($sql);
680 if (!$result) {
681 dol_print_error($db);
682 }
683 }
684
685 // disable
686 if ($action == $acts[1] && $permissiontoedit) {
687 $rowidcol = "rowid";
688
689 $sql = "UPDATE ".$db->sanitize($tabname[25])." SET active = 0 WHERE rowid = ".((int) $rowid);
690
691 $result = $db->query($sql);
692 if (!$result) {
693 dol_print_error($db);
694 }
695 }
696}
697
698
699/*
700 * View
701 */
702
703$form = new Form($db);
704$formadmin = new FormAdmin($db);
705
706$now = dol_now();
707
708//$help_url = "EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
709$help_url = '';
710if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
711 $title = $langs->trans("EMailsSetup");
712} else {
713 $title = $langs->trans("EMailTemplates");
714}
715$morejs = array();
716$morecss = array();
717
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').")";
722if (!$user->admin) {
723 $sql .= " AND (private = 0 OR (private = 1 AND fk_user = ".((int) $user->id)."))"; // Show only public and private to me
724 $sql .= " AND (active = 1 OR fk_user = ".((int) $user->id).")"; // Show only active or owned by me
725}
726if ($search_label) {
727 $sql .= natural_search('label', $search_label);
728}
729if ($search_type_template != '' && $search_type_template != '-1') {
730 $sql .= natural_search('type_template', $search_type_template);
731}
732if ($search_lang) {
733 $sql .= natural_search('lang', $search_lang);
734}
735if ($search_fk_user != '' && $search_fk_user != '-1') {
736 $sql .= natural_search('fk_user', $search_fk_user, 2);
737}
738if ($search_module) {
739 $sql .= natural_search('module', $search_module);
740}
741// Exclude disabled modules
742$listofmodules = implode(",", array_keys($conf->modules));
743$sql .= "AND (".natural_search('module', $listofmodules, 3, 1)." OR module IS NULL)";
744if ($search_topic) {
745 $sql .= natural_search('topic', $search_topic);
746}
747if (in_array($search_private, array(0, 1), true)) {
748 $sql .= " AND private = ".((int) $search_private);
749}
750if ($search_position !== '') {
751 $sql .= " AND position = ".((int) $search_position);
752}
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')";
757}
758if (in_array($search_defaultfortype, array(0, 1), true)) {
759 $sql .= " AND COALESCE(defaultfortype, 0) = ".((int) $search_defaultfortype);
760}
761// If sort order is "country", we use country_code instead
762if ($sortfield == 'country') {
763 $sortfield = 'country_code';
764}
765$sql .= $db->order($sortfield, $sortorder);
766//print $sql;
767
768// Output page
769// --------------------------------------------------------------------
770
771llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'mod-admin page-mails_templates');
772
773$arrayofselected = is_array($toselect) ? $toselect : array();
774
775$param = '';
776if (!empty($mode)) {
777 $param .= '&mode='.urlencode($mode);
778}
779if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
780 $param .= '&contextpage='.urlencode($contextpage);
781}
782if ($limit > 0 && $limit != $conf->liste_limit) {
783 $param .= '&limit='.((int) $limit);
784}
785if ($optioncss != '') {
786 $param .= '&optioncss='.urlencode($optioncss);
787}
788// Add $param from extra fields
789include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
790// Add $param from hooks
791$parameters = array();
792$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
793$param .= $hookmanager->resPrint;
794
795
796$titlepicto = 'title_setup';
797
798
799$url = DOL_URL_ROOT.'/admin/mails_templates.php?action=create';
800$newcardbutton = '';
801$newcardbutton .= dolGetButtonTitle($langs->trans('NewEMailTemplate'), '', 'fa fa-plus-circle', $url, '', (int) $permissiontoadd);
802
803
804$param = '';
805if ($search_label) {
806 $param .= '&search_label='.urlencode($search_label);
807}
808if (!empty($search_lang) && $search_lang != '-1') {
809 $param .= '&search_lang='.urlencode($search_lang);
810}
811if ($search_type_template != '-1') {
812 $param .= '&search_type_template='.urlencode($search_type_template);
813}
814if ($search_fk_user > 0) {
815 $param .= '&search_fk_user='.urlencode($search_fk_user);
816}
817if ($search_module) {
818 $param .= '&search_module='.urlencode($search_module);
819}
820if ($search_topic) {
821 $param .= '&search_topic='.urlencode($search_topic);
822}
823
824if (in_array($search_private, array(0, 1), true)) {
825 $param .= '&search_private='.((int) $search_private);
826}
827if ($search_position !== '') {
828 $param .= '&search_position='.((int) $search_position);
829}
830if (in_array($search_joinfiles, array(0, 1), true)) {
831 $param .= '&search_joinfiles='.((int) $search_joinfiles);
832}
833if (in_array($search_defaultfortype, array(0, 1), true)) {
834 $param .= '&search_defaultfortype='.((int) $search_defaultfortype);
835}
836
837$paramwithsearch = $param;
838if ($sortorder) {
839 $paramwithsearch .= '&sortorder='.urlencode($sortorder);
840}
841if ($sortfield) {
842 $paramwithsearch .= '&sortfield='.urlencode($sortfield);
843}
844if ($limit) {
845 $paramwithsearch .= '&limit='.((int) $limit);
846}
847if (GETPOST('from', 'alpha')) {
848 $paramwithsearch .= '&from='.urlencode(GETPOST('from', 'alpha'));
849}
850
851$massactionbutton = '';
852
853
854// List of available record in database
855dol_syslog("htdocs/admin/mails_templates.php", LOG_DEBUG);
856
857$resql = $db->query($sql);
858if (!$resql) {
859 dol_print_error($db);
860 exit;
861}
862
863$nbtotalofrecords = $db->num_rows($resql);
864
865$sql .= $db->plimit($limit + 1, $offset);
866
867$resql = $db->query($sql);
868if (!$resql) {
869 dol_print_error($db);
870 exit;
871}
872
873$num = $db->num_rows($resql);
874
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')).'">';
879} else {
880 // Form to add a new line
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.'">';
886}
887
888if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
889 print load_fiche_titre($title, '', $titlepicto);
890} else {
891 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'tools', 0, $newcardbutton, '', $limit, 'limit', 0, 1);
892}
893
894if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
895 $head = email_admin_prepare_head();
896
897 print dol_get_fiche_head($head, 'templates', '', -1);
898
899 if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
900 print load_fiche_titre('', $newcardbutton, '');
901 }
902}
903
904
905// Confirm deletion of record
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);
908}
909
910
911$fieldlist = explode(',', $tabfield[25]);
912
913if ($action == 'create') {
914 // If data was already input, we define them in obj to populate input fields.
915 $obj = new stdClass();
916 $obj->label = GETPOST('label');
917 $obj->lang = GETPOST('lang');
918 $obj->type_template = GETPOST('type_template');
919 $obj->fk_user = GETPOSTINT('fk_user');
920 $obj->private = GETPOSTINT('private');
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');
926
927 print '<div class="div-table-responsive-no-min">';
928 print '<table class="noborder centpercent" id="table_create_c_email_template">';
929
930 // Line to enter new values (title)
931 print '<tr class="liste_titre">';
932 foreach ($fieldlist as $field => $value) {
933 if ($value == 'lang' && !getDolGlobalInt('MAIN_MULTILANGS')) {
934 continue;
935 }
936 // Determine the field name based on the possible names
937 // in the data dictionaries.
938 $valuetoshow = ucfirst($fieldlist[$field]); // Par default
939 $valuetoshow = $langs->trans($valuetoshow); // try to translate
940 $css = "left";
941 if ($fieldlist[$field] == 'module') {
942 $valuetoshow = '&nbsp;';
943 }
944 if ($fieldlist[$field] == 'fk_user') {
945 $valuetoshow = $langs->trans("Owner");
946 }
947 if ($fieldlist[$field] == 'lang') {
948 $valuetoshow = $langs->trans("Language");
949 }
950 if ($fieldlist[$field] == 'type') {
951 $valuetoshow = $langs->trans("Type");
952 }
953 if ($fieldlist[$field] == 'position') {
954 $css = 'center';
955 }
956 if ($fieldlist[$field] == 'code') {
957 $valuetoshow = $langs->trans("Code");
958 }
959 if ($fieldlist[$field] == 'label') {
960 $valuetoshow = $langs->trans("Label");
961 }
962 if ($fieldlist[$field] == 'type_template') {
963 $valuetoshow = $langs->trans("TypeOfTemplate");
964 $css = "center";
965 }
966 if (in_array($fieldlist[$field], array('private', 'private', 'defaultfortype'))) {
967 $css = 'center';
968 }
969
970 if ($fieldlist[$field] == 'topic') {
971 $valuetoshow = '';
972 }
973 if ($fieldlist[$field] == 'joinfiles') {
974 $valuetoshow = '';
975 }
976 if ($fieldlist[$field] == 'content') {
977 $valuetoshow = '';
978 }
979 if ($fieldlist[$field] == 'content_lines') {
980 $valuetoshow = '';
981 }
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); // Tooltip on click
989 } else {
990 print $form->textwithpicto($valuetoshow, $tabhelp[25][$value], 1, 'help', '', 0, 2); // Tooltip on hover
991 }
992 } else {
993 print $valuetoshow;
994 }
995 print '</th>';
996 }
997 }
998 print '<th>';
999 print '</th>';
1000 print '</tr>';
1001
1002 $tmpaction = 'create';
1003 $parameters = array(
1004 'fieldlist' => $fieldlist,
1005 'tabname' => $tabname[25]
1006 );
1007 $reshook = $hookmanager->executeHooks('createEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1008 $error = $hookmanager->error;
1009 $errors = $hookmanager->errors;
1010
1011
1012 // Line to enter new values (input fields)
1013 print '<tr class="oddeven">';
1014
1015 if (empty($reshook)) {
1016 if ($action == 'edit') {
1017 fieldList($fieldlist, $obj, $tabname[25], 'hide');
1018 } else {
1019 fieldList($fieldlist, $obj, $tabname[25], 'add');
1020 }
1021 }
1022 // Action column
1023 print '<td class="right">';
1024 print '</td>';
1025 print "</tr>";
1026
1027 print '<tr class="oddeven nodrag nodrop nohover"><td colspan="9" style="padding-left: 20px; padding-right: 20px;">';
1028
1029 // Show fields for topic, join files and body
1030 $fieldsforcontent = array('topic', 'email_from', 'joinfiles', 'content');
1031 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TO')) {
1032 $fieldsforcontent[] = 'email_to';
1033 }
1034 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOCC')) {
1035 $fieldsforcontent[] = 'email_tocc';
1036 }
1037 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOBCC')) {
1038 $fieldsforcontent[] = 'email_tobcc';
1039 }
1040 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
1041 $fieldsforcontent[] = 'content_lines';
1042 }
1043 foreach ($fieldsforcontent as $tmpfieldlist) {
1044 print '<div class="inline-block lineformailtemplatefield paddingtop paddingbottom centpercent">';
1045 // Topic of email
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>';
1048 }
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>';
1051 }
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>';
1054 }
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>';
1057 }
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>';
1060 }
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>';
1063 }
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>';
1066
1067 // Add layout and AI tools for content
1068 $out = '';
1069 $formmail = new FormMail($db);
1070 $formmail->withlayout = 'email';
1071 $formmail->withaiprompt = 'html';
1072 $formmail->withfckeditor = 1;
1073
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';
1080 print $out;
1081 print '<br>';
1082 }
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>';
1085 }
1086
1087 // Input field
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);
1100 } else {
1101 $okforextended = true;
1102 if (!getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) {
1103 $okforextended = false;
1104 }
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);
1107 }
1108 print '</div>';
1109 print '<br>';
1110 }
1111
1112 print '</tr>';
1113
1114 print '</table>';
1115
1116 if ($action != 'edit') {
1117 print '<center>';
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").'">';
1120 print '</center>';
1121 }
1122
1123 print '</div>';
1124 print '</form>';
1125
1126 print '<br><br><br>';
1127}
1128
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">';
1132
1133 $i = 0;
1134
1135 // There is several pages
1136 /*
1137 if ($num > $limit) {
1138 print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).'">';
1139 print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $limit ? 1 : 0), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
1140 print '</td></tr>';
1141 }
1142 */
1143
1144 // Title line with search boxes
1145 print '<tr class="liste_titre" id="Title line with search boxes">';
1146 // Action column
1147 if ($conf->main_checkbox_left_column) {
1148 print '<td class="liste_titre center" width="64">';
1149 $searchpicto = $form->showFilterButtons();
1150 print $searchpicto;
1151 print '</td>';
1152 }
1153 foreach ($fieldlist as $field => $value) {
1154 if ($value == 'lang' && !getDolGlobalInt('MAIN_MULTILANGS')) {
1155 continue;
1156 }
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');
1164 print '</td>';
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);
1168 print '</td>';
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">';
1173 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1174 print $form->selectarray('search_type_template', $elementList, $search_type_template, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100 maxwidth125', 1, '', 0, 1);
1175 print '</td>';
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');
1180 print '</td>';
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>';
1185 }
1186 }
1187 /*if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
1188 print '<td class="liste_titre"></td>';
1189 }*/
1190 // Have to expand the id="Title line with search boxes" with 2 extra fields because the line below id="Title of lines" are 2 fields longer
1191 if (!empty($arrayfields['t.tms']['checked'])) {
1192 print '<td class="liste_titre"></td>'; // tms / Modif. date
1193 }
1194 if (!empty($arrayfields['t.datec']['checked'])) {
1195 print '<td class="liste_titre"></td>'; // datec / Date creation
1196 }
1197 // Status
1198 print '<td class="liste_titre center"></td>';
1199
1200 // Action column
1201 if (!$conf->main_checkbox_left_column) {
1202 print '<td class="liste_titre center" width="64">';
1203 $searchpicto = $form->showFilterButtons();
1204 print $searchpicto;
1205 print '</td>';
1206 }
1207 print '</tr>';
1208
1209 // Title of lines
1210 print '<tr class="liste_titre" id="Title of lines">';
1211 // Action column
1212 if ($conf->main_checkbox_left_column) {
1213 print getTitleFieldOfList('');
1214 }
1215 array_push($fieldlist, "tms", "datec");
1216 foreach ($fieldlist as $field => $value) {
1217 if ($value == 'lang' && !getDolGlobalInt('MAIN_MULTILANGS')) {
1218 continue;
1219 }
1220 $showfield = 1; // By default
1221 $css = "left";
1222 $sortable = 1;
1223 $valuetoshow = '';
1224 $forcenowrap = 1;
1225 /*
1226 $tmparray=getLabelOfField($fieldlist[$field]);
1227 $showfield=$tmp['showfield'];
1228 $valuetoshow=$tmp['valuetoshow'];
1229 $css=$tmp['align'];
1230 $sortable=$tmp['sortable'];
1231 */
1232 $valuetoshow = ucfirst($fieldlist[$field]); // By default
1233 $valuetoshow = $langs->trans($valuetoshow); // try to translate
1234 if ($fieldlist[$field] == 'module') {
1235 $css = 'tdoverflowmax100';
1236 }
1237 if ($fieldlist[$field] == 'fk_user') {
1238 $valuetoshow = $langs->trans("Owner");
1239 }
1240 if ($fieldlist[$field] == 'lang') {
1241 $valuetoshow = $langs->trans("Language");
1242 }
1243 if ($fieldlist[$field] == 'type') {
1244 $valuetoshow = $langs->trans("Type");
1245 }
1246 if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
1247 $valuetoshow = $langs->trans("Label");
1248 }
1249 if ($fieldlist[$field] == 'type_template') {
1250 $css = 'center';
1251 $valuetoshow = $langs->trans("TypeOfTemplate");
1252 }
1253 if ($fieldlist[$field] == 'private') {
1254 $css = 'center';
1255 }
1256 if ($fieldlist[$field] == 'position') {
1257 $css = 'center';
1258 }
1259 if ($fieldlist[$field] == 'tms') {
1260 $valuetoshow = 'Modif. date';
1261 }
1262 if ($fieldlist[$field] == 'datec') {
1263 $valuetoshow = 'Date creation';
1264 }
1265
1266 if ($fieldlist[$field] == 'joinfiles') {
1267 $valuetoshow = $langs->trans("FilesAttachedToEmail");
1268 $css = 'center';
1269 $forcenowrap = 0;
1270 }
1271 if ($fieldlist[$field] == 'content') {
1272 $valuetoshow = $langs->trans("Content");
1273 $showfield = 0;
1274 }
1275 if ($fieldlist[$field] == 'content_lines') {
1276 $valuetoshow = $langs->trans("ContentForLines");
1277 $showfield = 0;
1278 }
1279 if ($value == 'tms' && empty($arrayfields['t.'.$value]['checked'])) {
1280 $showfield = 0;
1281 }
1282 if ($value == 'datec' && empty($arrayfields['t.'.$value]['checked'])) {
1283 $showfield = 0;
1284 }
1285
1286 // Show fields
1287 if ($showfield) {
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); // Tooltip on click
1291 } else {
1292 $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[25][$value], 1, 'help', '', 0, 2, '', $forcenowrap); // Tooltip on hover
1293 }
1294 }
1295 $sortfieldtouse = ($sortable ? $fieldlist[$field] : '');
1296 if ($sortfieldtouse == 'type_template') {
1297 $sortfieldtouse .= ',lang,position,label';
1298 }
1299 print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], $sortfieldtouse, ($page ? 'page='.$page.'&' : ''), $paramwithsearch, '', $sortfield, $sortorder, $css.' ');
1300 }
1301 }
1302
1303 print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $paramwithsearch, '', $sortfield, $sortorder, 'center ');
1304 // Action column
1305 if (!$conf->main_checkbox_left_column) {
1306 print getTitleFieldOfList('');
1307 }
1308 print '</tr>';
1309
1310 $nbqualified = 0;
1311 if ($num) {
1312 // Lines with values
1313 while ($i < $num) {
1314 $obj = $db->fetch_object($resql);
1315
1316 if ($obj) {
1317 if (($action == 'edit' || $action == 'preview') && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
1318 // TODO Move this 2 lines into a popup
1319 print '<tr class="nohover oddeven noborderbottom" id="rowid-'.$obj->rowid.'" name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'">';
1320
1321 $tmpaction = 'edit';
1322 if ($action == 'edit') {
1323 // do not show tms and datec
1324 $fieldlist = explode(',', $tabfield[25]);
1325 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[25]);
1326 } else {
1327 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[25]);
1328 }
1329 $reshook = $hookmanager->executeHooks('editEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1330 $error = $hookmanager->error;
1331 $errors = $hookmanager->errors;
1332
1333 $colspan = 0;
1334
1335 // Action column
1336 if ($conf->main_checkbox_left_column) {
1337 print '<td class="center">';
1338 print '</td>';
1339 $colspan++;
1340 }
1341 // Show main fields
1342 if (empty($reshook)) {
1343 $colspan += fieldList($fieldlist, $obj, $tabname[25], $action);
1344 }
1345 // Action column
1346 if (!$conf->main_checkbox_left_column) {
1347 print '<td class="center">';
1348 print '</td>';
1349 $colspan++;
1350 }
1351 print "</tr>\n";
1352
1353 print '<tr class="oddeven nohover" id="tr-aaa-'.$rowid.'">';
1354 if ($conf->main_checkbox_left_column) {
1355 print '<td class="center"></td>';
1356 }
1357 print '<td colspan="'.($colspan - 1).'" class="" style="padding-left: 20px; padding-right: 20px;">';
1358
1359 $fieldsforcontent = array('topic', 'email_from', 'joinfiles', 'content');
1360 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TO')) {
1361 $fieldsforcontent[] = 'email_to';
1362 }
1363 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOCC')) {
1364 $fieldsforcontent[] = 'email_tocc';
1365 }
1366 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOBCC')) {
1367 $fieldsforcontent[] = 'email_tobcc';
1368 }
1369 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
1370 $fieldsforcontent[] = 'content_lines';
1371 }
1372
1373 $parameters = array('fieldsforcontent' => &$fieldsforcontent, 'tabname' => $tabname[25]);
1374 $hookmanager->executeHooks('editEmailTemplateFieldsForContent', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1375
1376 print '<div class="lineformailtemplatefield centpercent">';
1377 foreach ($fieldsforcontent as $tmpfieldlist) {
1378 $showfield = 1;
1379 $css = "left";
1380 $valuetoshow = $obj->$tmpfieldlist;
1381
1382 $class = 'tddict';
1383 // Show value for field
1384 if ($showfield) {
1385 print '<div class="inline-block lineformailtemplatefield paddingtop paddingbottom centpercent">';
1386 // Show line for topic, joinfiles and content
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' : '').'>';
1390 print '<br>'."\n";
1391 }
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">';
1395 print '<br>'."\n";
1396 }
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">';
1400 print '<br>'."\n";
1401 }
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">';
1405 print '<br>'."\n";
1406 }
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">';
1410 print '<br>'."\n";
1411 }
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);
1415 print '<br>'."\n";
1416 }
1417
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>';
1420
1421 // Add layout and AI tools for content
1422 $out = '';
1423
1424 $formmail = new FormMail($db);
1425 $formmail->withlayout = 'email';
1426 $formmail->withaiprompt = 'html';
1427 $formmail->withfckeditor = 1;
1428
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';
1435 print $out;
1436
1437 $okforextended = true;
1438 if (!getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) {
1439 $okforextended = false;
1440 }
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);
1443 }
1444 if ($tmpfieldlist == 'content_lines') {
1445 print '<br>'."\n";
1446 print $form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[25][$tmpfieldlist], 1, 'help', 'margintoponly', 0, 2, $tmpfieldlist).'<br>';
1447 $okforextended = true;
1448 if (!getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) {
1449 $okforextended = false;
1450 }
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);
1453 }
1454 print '</div>';
1455 }
1456 }
1457 print '</div>';
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").'">';
1462 }
1463 print '<input type="submit" class="button buttongen button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
1464 print '</center>';
1465 print '</td>';
1466
1467 if (!$conf->main_checkbox_left_column) {
1468 print '<td class="center"></td>';
1469 }
1470
1471 print '</tr>';
1472
1473 $nbqualified++;
1474 } else {
1475 // If template is for a module, check module is enabled.
1476 if ($obj->module) {
1477 $tempmodulekey = $obj->module;
1478 if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1479 $i++;
1480 continue;
1481 }
1482 }
1483
1484 $keyforobj = 'type_template';
1485 if (!in_array($obj->$keyforobj, array_keys($elementList))) {
1486 $i++;
1487 continue; // It means this is a type of template not into elementList (may be because enabled condition of this type is false because module is not enabled)
1488 }
1489 // Test on 'enabled'
1490 if (! (int) dol_eval((string) $obj->enabled, 1, 1, '1')) {
1491 $i++;
1492 continue; // Email template not qualified
1493 }
1494
1495 $nbqualified++;
1496
1497 // Can an entry be erased or disabled ?
1498 $iserasable = 1;
1499 $canbedisabled = 1;
1500 $canbemodified = 1; // true by default
1501 if (!$user->admin && $obj->fk_user != $user->id) {
1502 $iserasable = 0;
1503 $canbedisabled = 0;
1504 $canbemodified = 0;
1505 }
1506
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) : '');
1508 if ($param) {
1509 $url .= '&'.$param;
1510 }
1511
1512 print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
1513
1514 // Action column - Modify link / Delete link
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>';
1519 } else {
1520 print '<a class="reposition editfielda" href="'.$url.'&action=preview&token='.newToken().'">'.img_view().'</a>';
1521 }
1522 if ($iserasable) {
1523 print '<a class="reposition marginleftonly" href="'.$url.'&action=delete&token='.newToken().$param.'">'.img_delete().'</a>';
1524 }
1525 print '</td>';
1526 }
1527
1528 $tmpaction = 'view';
1529 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[25]);
1530 $reshook = $hookmanager->executeHooks('viewEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1531
1532 $error = $hookmanager->error;
1533 $errors = $hookmanager->errors;
1534
1535 if (empty($reshook)) {
1536 foreach ($fieldlist as $field => $value) {
1537 if ($value == 'lang' && !getDolGlobalInt('MAIN_MULTILANGS')) {
1538 continue;
1539 }
1540 if (in_array($fieldlist[$field], array('content', 'content_lines'))) {
1541 continue;
1542 }
1543 $showfield = 1;
1544 $css = "";
1545 $class = "tddict";
1546 $title = '';
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);
1552 }
1553 $valuetoshow = dol_escape_htmltag($valuetoshow);
1554 }
1555 if ($value == 'label') {
1556 $class .= ' tdoverflowmax200';
1557 }
1558 if ($value == 'topic') {
1559 $class .= ' tdoverflowmax200 small';
1560 }
1561 if ($value == 'type_template') {
1562 $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
1563 $css = "center tdoverflowmax150";
1564 }
1565 if ($value == 'lang' && $valuetoshow) {
1566 $valuetoshow = $valuetoshow.' - '.$langs->trans("Language_".$valuetoshow);
1567 $class .= ' tdoverflowmax100';
1568 }
1569 if ($value == 'fk_user') {
1570 if ($valuetoshow > 0) {
1571 $fuser = new User($db);
1572 $fuser->fetch($valuetoshow);
1573 $valuetoshow = $fuser->getNomUrl(-1);
1574
1575 if ($obj->private) {
1576 $valuetoshow = img_picto($langs->transnoentitiesnoconv("Private"), 'lock', 'class="pictofixedwidth"').$valuetoshow;
1577 }
1578
1579 $class .= ' tdoverflowmax100';
1580 }
1581 }
1582 if ($value == 'private') {
1583 $css = "center";
1584 if ($valuetoshow) {
1585 $valuetoshow = yn($valuetoshow);
1586 } else {
1587 $valuetoshow = '';
1588 }
1589 }
1590 if ($value == 'position') {
1591 $css = "center";
1592 }
1593 if (in_array($value, array('joinfiles', 'defaultfortype'))) {
1594 $css = "center";
1595 if ($valuetoshow) {
1596 //$valuetoshow = yn(1);
1597 $valuetoshow = '<input type="checkbox" checked="checked" disabled>';
1598 } else {
1599 $valuetoshow = '';
1600 }
1601 }
1602 if ($css) {
1603 $class .= ' '.$css;
1604 }
1605
1606 if ($value == 'tms' && empty($arrayfields['t.'.$value]['checked'])) {
1607 $showfield = 0;
1608 }
1609 if ($value == 'datec' && empty($arrayfields['t.'.$value]['checked'])) {
1610 $showfield = 0;
1611 }
1612
1613 // Show value for field
1614 if ($showfield) {
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).'"';
1619 }
1620 print '>';
1621 print $valuetoshow;
1622 print '</td>';
1623 }
1624 }
1625 }
1626
1627 // Status / Active
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>';
1631 } else {
1632 print '<span class="opacitymedium">'.$actl[$obj->active].'</span>';
1633 }
1634 print "</td>";
1635
1636 // Action column - Modify link / Delete link
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>';
1641 }
1642 if ($iserasable) {
1643 print '<a class="reposition marginleftonly" href="'.$url.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
1644 //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
1645 }
1646 print '</td>';
1647 }
1648
1649 print "</tr>\n";
1650 }
1651 }
1652
1653 $i++;
1654 }
1655 }
1656
1657 // If no record found
1658 if ($nbqualified == 0) {
1659 $colspan = 12;
1660 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1661 }
1662
1663 print '</table>';
1664 print '</div>';
1665
1666 print '</form>';
1667}
1668
1669if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
1670 print dol_get_fiche_end();
1671}
1672
1673
1674// End of page
1675llxFooter();
1676$db->close();
1677
1678
1688function fieldList($fieldlist, $obj = null, $tabname = '', $context = '')
1689{
1690 global $langs, $user, $db;
1691 global $form;
1692 global $elementList;
1693
1694 $formadmin = new FormAdmin($db);
1695 $nboffieldsprinted = 0;
1696
1697 foreach ($fieldlist as $value) {
1698 if ($value == 'lang' && !getDolGlobalInt('MAIN_MULTILANGS')) {
1699 continue;
1700 }
1701 //print $value;
1702 if ($value == 'module') {
1703 print '<td></td>';
1704 $nboffieldsprinted++;
1705 } elseif ($value == 'fk_user') {
1706 print '<td>';
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');
1709 } else {
1710 if ($context == 'add') { // I am not admin and we show the add form
1711 print $user->getNomUrl(-1); // Me
1712 $forcedvalue = $user->id;
1713 } else {
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;
1719 } else {
1720 $forcedvalue = $obj->$value;
1721 }
1722 }
1723 $keyname = $value;
1724 print '<input type="hidden" value="'.$forcedvalue.'" name="'.$keyname.'">';
1725 }
1726 print '</td>';
1727 $nboffieldsprinted++;
1728 } elseif ($value == 'lang') {
1729 print '<td>';
1730 if ($context != 'preview') {
1731 $selectedlang = GETPOSTISSET('langcode') ? GETPOST('langcode', 'aZ09') : $langs->defaultlang;
1732 if ($context == 'edit' && !GETPOSTISSET('langcode')) {
1733 $selectedlang = $obj->lang;
1734 }
1735 print $formadmin->select_language($selectedlang, 'langcode', 0, array(), $langs->trans("Language"), 0, 0, 'maxwidth100');
1736 } else {
1737 if (!empty($obj->lang)) {
1738 print $obj->lang.' - '.$langs->trans('Language_'.$obj->lang);
1739 }
1740 $keyname = $value;
1741 if ($keyname == 'lang') {
1742 $keyname = 'langcode'; // Avoid conflict with lang param
1743 }
1744 print '<input type="hidden" value="'.(empty($obj->lang) ? '' : $obj->lang).'" name="'.$keyname.'">';
1745 }
1746 print '</td>';
1747 $nboffieldsprinted++;
1748 } elseif ($value == 'type_template') {
1749 // Le type de template
1750 print '<td class="center">';
1751 if (($context == 'edit' && !empty($obj->type_template) && !in_array($obj->type_template, array_keys($elementList))) || $context == 'preview') {
1752 // Current template type is an unknown type, so we must keep it as it is.
1753 print '<input type="hidden" name="type_template" value="'.$obj->type_template.'">';
1754 print $obj->type_template;
1755 } else {
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);
1757 }
1758 print '</td>';
1759 $nboffieldsprinted++;
1760 } elseif ($context == 'add' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1761 //print '<td></td>';
1762 } elseif ($context == 'edit' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1763 print '<td></td>';
1764 $nboffieldsprinted++;
1765 } elseif ($context == 'preview' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1766 print '<td></td>';
1767 $nboffieldsprinted++;
1768 } elseif ($context == 'hide' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1769 //print '<td></td>';
1770 } else {
1771 $size = '';
1772 $class = '';
1773 $classtd = '';
1774 if ($value == 'code') {
1775 $class = 'maxwidth100';
1776 }
1777 if ($value == 'label') {
1778 $class = 'maxwidth200';
1779 }
1780 if ($value == 'private') {
1781 $class = 'maxwidth50';
1782 $classtd = 'center';
1783 }
1784 if ($value == 'position') {
1785 $class = 'maxwidth50 center';
1786 $classtd = 'center';
1787 }
1788 if ($value == 'topic') {
1789 $class = 'quatrevingtpercent';
1790 }
1791 if ($value == 'defaultfortype') {
1792 $class = 'width25 center';
1793 $classtd = 'center';
1794 }
1795
1796 print '<td'.($classtd ? ' class="'.$classtd.'"' : '').'>';
1797 if (in_array($value, array('defaultfortype', 'private')) && $context != 'preview') {
1798 if (empty($user->admin)) {
1799 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1800 print $form->selectyesno($value, GETPOSTISSET($value) ? GETPOSTINT($value) : (($context != 'add' && isset($obj->$value)) ? $obj->$value : '1'), 1, false, 0, 1);
1801 } else {
1802 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1803 print $form->selectyesno($value, (isset($obj->$value) ? $obj->$value : ''), 1, false, 0, 1);
1804 }
1805 } else {
1806 print '<input type="text" '.$size.'class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->$value) ? $obj->$value : '').'" name="'. $value .'"'.($context == 'preview' ? ' disabled' : '').' spellcheck="false">';
1807 }
1808 print '</td>';
1809 $nboffieldsprinted++;
1810 }
1811 }
1812
1813 return $nboffieldsprinted;
1814}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
email_admin_prepare_head()
Return array head with list of tabs to view object information.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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.
Definition wrapper.php:73
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 generate html code for admin pages.
Class to manage generation of HTML components Only common components must be here.
Class to manage a HTML form to send a unitary email Usage: $formail = new FormMail($db) $formmail->pr...
static getAvailableSubstitKey($mode='formemail', $object=null)
Get list of substitution keys available for emails.
Class to manage translations.
Class to manage Dolibarr users.
$context
@method int call_trigger(string $triggerName, ?User $user)
Definition command.php:209
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.
Definition html.lib.php:542
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.
Definition html.lib.php:740
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)
Definition html.lib.php:183
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.