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$search_fk_user = GETPOST('search_fk_user', 'intcomma');
83$search_topic = GETPOST('search_topic', 'alpha');
84$search_module = GETPOST('search_module', 'alpha');
85
86$acts = array();
87$actl = array();
88$acts[0] = "activate";
89$acts[1] = "disable";
90$actl[0] = img_picto($langs->trans("Disabled"), 'switch_off', 'class="size15x"');
91$actl[1] = img_picto($langs->trans("Activated"), 'switch_on', 'class="size15x"');
92
93$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
94$sortfield = GETPOST('sortfield', 'aZ09comma');
95$sortorder = GETPOST('sortorder', 'aZ09comma');
96$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
97if (empty($page) || $page == -1) {
98 $page = 0;
99} // If $page is not defined, or '' or -1
100$offset = $limit * $page;
101$pageprev = $page - 1;
102$pagenext = $page + 1;
103
104if (empty($sortfield)) {
105 $sortfield = 'type_template,lang,position,label';
106}
107if (empty($sortorder)) {
108 $sortorder = 'ASC';
109}
110
111// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
112$hookmanager->initHooks(array('emailtemplates'));
113
114$object = new CEmailTemplate($db);
115
116// Definition of array of fields for columns from ->fields
117$tableprefix = 't';
118$arrayfields = array();
119foreach ($object->fields as $key => $val) {
120 // If $val['visible']==0, then we never show the field
121 if (!empty($val['visible'])) {
122 $visible = (int) dol_eval((string) $val['visible'], 1);
123 $arrayfields[$tableprefix.'.'.$key] = array(
124 'label' => $val['label'],
125 'checked' => (($visible < 0) ? '0' : '1'),
126 'enabled' => (string) (int) (abs($visible) != 3 && (bool) dol_eval((string) $val['enabled'], 1)),
127 'position' => $val['position'],
128 'help' => isset($val['help']) ? $val['help'] : ''
129 );
130 }
131}
132
133// Security
134if (!empty($user->socid)) {
136}
137
138$permissiontoadd = 1;
139$permissiontoedit = ($user->admin ? 1 : 0);
140$permissiontodelete = ($user->admin ? 1 : 0);
141
142$tmpmailtemplate = new CEmailTemplate($db);
143if ($rowid > 0) {
144 $result = $tmpmailtemplate->fetch($rowid);
145 if ($tmpmailtemplate->fk_user == $user->id) {
146 $permissiontoedit = 1;
147 $permissiontodelete = 1;
148 }
149}
150
151// Old way to define field.
152
153// Name of SQL tables of dictionaries
154$tabname = array();
155$tabname[25] = MAIN_DB_PREFIX."c_email_templates";
156
157// Name of the fields in the result of select to display the dictionary
158// Names of fields in select results for dictionary display (AI translated)
159$tabfield = array();
160$tabfield[25] = "label,lang,type_template,fk_user,private,position,module,topic,joinfiles,defaultfortype,content";
161if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
162 $tabfield[25] .= ',content_lines';
163}
164
165// Name of editing fields for record modification
166// Names of edit fields for modifying a record (AI translated)
167$tabfieldvalue = array();
168$tabfieldvalue[25] = "label,lang,type_template,fk_user,private,position,topic,email_from,joinfiles,defaultfortype,content";
169if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TO')) {
170 $tabfieldvalue[25] .= ',email_to';
171}
172if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOCC')) {
173 $tabfieldvalue[25] .= ',email_tocc';
174}
175if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOBCC')) {
176 $tabfieldvalue[25] .= ',email_tobcc';
177}
178if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
179 $tabfieldvalue[25] .= ',content_lines';
180}
181
182// Name of the fields in the table for inserting a record
183// Field names in the table for inserting a record (AI translated)
184$tabfieldinsert = array();
185$tabfieldinsert[25] = "label,lang,type_template,fk_user,private,position,topic,email_from,joinfiles,defaultfortype,content,datec";
186if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TO')) {
187 $tabfieldvalue[25] .= ',email_to';
188}
189if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOCC')) {
190 $tabfieldvalue[25] .= ',email_tocc';
191}
192if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOBCC')) {
193 $tabfieldvalue[25] .= ',email_tobcc';
194}
195if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
196 $tabfieldinsert[25] .= ',content_lines';
197}
198$tabfieldinsert[25] .= ',entity'; // Must be at end because not into other arrays
199
200// List of help for fields
201// Set MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES to allow edit of template for lines
202require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
203if (!getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
204 $targetobject = fetchObjectByElement(0, $tmpmailtemplate->type_template);
205
206 $tmp = FormMail::getAvailableSubstitKey('formemail', $targetobject);
207
208 $tmp['__(AnyTranslationKey)__'] = 'Translation';
209 $helpsubstit = $langs->trans("AvailableVariables").':<br>';
210 $helpsubstitforlines = $langs->trans("AvailableVariables").':<br>';
211 foreach ($tmp as $key => $val) {
212 $helpsubstit .= $key.' -> '.$val.'<br>';
213 $helpsubstitforlines .= $key.' -> '.$val.'<br>';
214 }
215} else {
216 $targetobject = fetchObjectByElement(0, $tmpmailtemplate->type_template);
217
218 $tmp = FormMail::getAvailableSubstitKey('formemailwithlines', $targetobject);
219
220 $tmp['__(AnyTranslationKey)__'] = 'Translation';
221 $helpsubstit = $langs->trans("AvailableVariables").':<br>';
222 $helpsubstitforlines = $langs->trans("AvailableVariables").':<br>';
223 foreach ($tmp as $key => $val) {
224 $helpsubstit .= $key.' -> '.$val.'<br>';
225 }
226 $tmp = FormMail::getAvailableSubstitKey('formemailforlines');
227 foreach ($tmp as $key => $val) {
228 $helpsubstitforlines .= $key.' -> '.$val.'<br>';
229 }
230}
231
232
233$tabhelp = array();
234$tabhelp[25] = array(
235 'label' => $langs->trans('EnterAnyCode'),
236 'type_template' => $langs->trans("TemplateForElement"),
237 'private' => $langs->trans("TemplateIsVisibleByOwnerOnly"),
238 'position' => $langs->trans("PositionIntoComboList"),
239 'topic' => '<span class="small">'.$helpsubstit.'</span>',
240 'email_from' => $langs->trans('ForceEmailFrom'),
241 'email_to' => $langs->trans('MailTo'),
242 'email_tocc' => $langs->trans('MailCC'),
243 'email_tobcc' => $langs->trans('MailCCC'),
244 'joinfiles' => $langs->trans('AttachMainDocByDefault'),
245 'defaultfortype' => $langs->trans("DefaultForTypeDesc"),
246 'content' => '<span class="small">'.$helpsubstit.'</span>',
247 'content_lines' => '<span class="small">'.$helpsubstitforlines.'</span>'
248);
249
250
251// We save list of template email Dolibarr can manage. This list can found by a grep into code on "->param['models']"
252$elementList = array();
253// Add all and none after the sort
254
255$elementList['all'] = '-- '.dol_escape_htmltag($langs->trans("All")).' --';
256$elementList['none'] = '-- '.dol_escape_htmltag($langs->trans("None")).' --';
257$elementList['user'] = img_picto('', 'user', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToUser'));
258if (isModEnabled('member') && $user->hasRight('adherent', 'lire')) {
259 $elementList['member'] = img_picto('', 'object_member', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToMember'));
260}
261if (isModEnabled('recruitment') && $user->hasRight('recruitment', 'recruitmentjobposition', 'read')) {
262 $elementList['recruitmentcandidature_send'] = img_picto('', 'recruitmentcandidature', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('RecruitmentCandidatures'));
263}
264if (isModEnabled('expensereport') && $user->hasRight('expensereport', 'lire')) {
265 $elementList['expensereport_send'] = img_picto('', 'trip', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendExpenseReport'));
266}
267if (isModEnabled('holiday') && $user->hasRight('holiday', 'read')) {
268 $elementList['holiday'] = img_picto('', 'holiday', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendLeaves'));
269}
270if (isModEnabled("societe") && $user->hasRight('societe', 'lire')) {
271 $elementList['thirdparty'] = img_picto('', 'company', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToThirdparty'));
272}
273if (isModEnabled("societe") && $user->hasRight('societe', 'contact', 'lire')) {
274 $elementList['contact'] = img_picto('', 'contact', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToContact'));
275}
276if (isModEnabled('project')) {
277 $elementList['project'] = img_picto('', 'project', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToProject'));
278}
279if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
280 $elementList['propal_send'] = img_picto('', 'propal', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendProposal'));
281}
282if (isModEnabled('order') && $user->hasRight('commande', 'lire')) {
283 $elementList['order_send'] = img_picto('', 'order', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendOrder'));
284}
285if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
286 $elementList['facture_send'] = img_picto('', 'bill', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendInvoice'));
287}
288if (isModEnabled("shipping")) {
289 $elementList['shipping_send'] = img_picto('', 'dolly', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendShipment'));
290 $elementList['delivery_send'] = img_picto('', 'dolly', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendDelivery'));
291}
292if (isModEnabled("reception")) {
293 $elementList['reception_send'] = img_picto('', 'dollyrevert', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendReception'));
294}
295if (isModEnabled('intervention')) {
296 $elementList['fichinter_send'] = img_picto('', 'intervention', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendIntervention'));
297}
298if (isModEnabled('supplier_proposal')) {
299 $elementList['supplier_proposal_send'] = img_picto('', 'propal', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendSupplierRequestForQuotation'));
300}
301if (isModEnabled("supplier_order") && ($user->hasRight('fournisseur', 'commande', 'lire') || $user->hasRight('supplier_order', 'read'))) {
302 $elementList['order_supplier_send'] = img_picto('', 'order', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendSupplierOrder'));
303}
304if (isModEnabled("supplier_invoice") && ($user->hasRight('fournisseur', 'facture', 'lire') || $user->hasRight('supplier_invoice', 'read'))) {
305 $elementList['invoice_supplier_send'] = img_picto('', 'bill', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendSupplierInvoice'));
306}
307if (isModEnabled("supplier_invoice") && ($user->hasRight('fournisseur', 'facture', 'creer') || $user->hasRight("supplier_invoice", "write"))) {
308 $elementList['supplier_payment_send'] = img_picto('', 'bill', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('SuppliersPayment'));
309}
310if (isModEnabled('contract') && $user->hasRight('contrat', 'lire')) {
311 $elementList['contract'] = img_picto('', 'contract', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendContract'));
312}
313if (isModEnabled('ticket') && $user->hasRight('ticket', 'read')) {
314 $elementList['ticket_send'] = img_picto('', 'ticket', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToTicket'));
315}
316if (isModEnabled('agenda')) {
317 $elementList['actioncomm_send'] = img_picto('', 'action', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendEventPush'));
318}
319if (isModEnabled('eventorganization') && $user->hasRight('project', 'read')) {
320 $elementList['conferenceorbooth'] = img_picto('', 'action', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendEventOrganization'));
321}
322if (isModEnabled('partnership') && $user->hasRight('partnership', 'read')) {
323 $elementList['partnership_send'] = img_picto('', 'partnership', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToPartnership'));
324}
325if (isModEnabled('product') && $user->hasRight('produit', 'lire')) {
326 $elementList['product_send'] = img_picto('', 'product', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('Product'));
327}
328if (isModEnabled('stocktransfer')) {
329 $elementList['stocktransfer_send'] = '<span class="fas fa-box-open em080 valignmiddle pictomodule paddingrightonly" style="color: #a69944;"></span>'.dol_escape_htmltag($langs->trans('MailToSendStockTransfer'));
330}
331
332$parameters = array('elementList' => $elementList);
333$reshook = $hookmanager->executeHooks('emailElementlist', $parameters); // Note that $action and $object may have been modified by some hooks
334if ($reshook == 0) {
335 foreach ($hookmanager->resArray as $item => $value) {
336 $elementList[$item] = $value;
337 }
338}
339
340$error = 0;
341
342$acceptlocallinktomedia = (acceptLocalLinktoMedia() > 0 ? 1 : 0);
343
344
345/*
346 * Actions
347 */
348
349if (GETPOST('cancel', 'alpha') || GETPOST('actioncancel', 'alpha')) {
350 $action = 'list';
351 $massaction = '';
352
353 if (!empty($backtopage)) {
354 header("Location: ".$backtopage);
355 exit(1);
356 }
357}
358if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
359 $massaction = '';
360}
361
362$parameters = array();
363$object = null;
364$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
365if ($reshook < 0) {
366 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
367}
368
369if (empty($reshook)) {
370 // Selection of new fields
371 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
372
373 // Purge search criteria
374 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
375 // All tests are required to be compatible with all browsers
376 $search_label = '';
377 $search_type_template = '';
378 $search_lang = '';
379 $search_fk_user = '';
380 $search_topic = '';
381 $search_module = '';
382 $toselect = array();
383 $search_array_options = array();
384 }
385
386 // Actions add or modify an email template
387 if ((GETPOST('actionadd', 'alpha') && $permissiontoadd) || (GETPOST('actionmodify', 'alpha') && $permissiontoedit)) {
388 $listfield = explode(',', str_replace(' ', '', $tabfield[25]));
389 $listfieldinsert = explode(',', $tabfieldinsert[25]);
390 $listfieldmodify = explode(',', $tabfieldvalue[25]);
391 $listfieldvalue = explode(',', $tabfieldvalue[25]);
392
393 // Check that all fields are filled
394 $ok = 1;
395 foreach ($listfield as $f => $value) {
396 // Not mandatory fields
397 if (in_array($value, ['joinfiles', 'defaultfortype', 'content', 'content_lines', 'module', 'tms', 'datec', 'email_to', 'email_tocc', 'email_tobcc'])) {
398 continue;
399 }
400
401 // Rename some POST variables into a generic name
402 if (GETPOST('actionmodify', 'alpha') && $value == 'topic') {
403 $_POST['topic'] = GETPOST('topic-'.$rowid);
404 }
405
406 if ((!GETPOSTISSET($value) || GETPOST($value) == '' || GETPOST($value) == '-1') && $value != 'lang' && $value != 'fk_user' && $value != 'position') {
407 $ok = 0;
408 $fieldnamekey = $listfield[$f];
409 // We take translate key of field
410 if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) {
411 $fieldnamekey = 'Code';
412 }
413 if ($fieldnamekey == 'code') {
414 $fieldnamekey = 'Code';
415 }
416 if ($fieldnamekey == 'note') {
417 $fieldnamekey = 'Note';
418 }
419 if ($fieldnamekey == 'type_template') {
420 $fieldnamekey = 'TypeOfTemplate';
421 }
422 if ($fieldnamekey == 'fk_user') {
423 $fieldnamekey = 'Owner';
424 }
425 if ($fieldnamekey == 'private') {
426 $fieldnamekey = 'Private';
427 }
428 if ($fieldnamekey == 'position') {
429 $fieldnamekey = 'Position';
430 }
431 if ($fieldnamekey == 'topic') {
432 $fieldnamekey = 'Topic';
433 }
434
435 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
436 $action = 'create';
437 }
438 }
439
440 // If previous test is ok action is add, we add the line
441 if ($ok && GETPOST('actionadd')) {
442 // Add new entry
443 $sql = "INSERT INTO ".$db->sanitize($tabname[25])." (";
444 // List of fields
445 $sql .= $tabfieldinsert[25];
446 $sql .= ", active, enabled)";
447 $sql .= " VALUES(";
448
449 // List of values
450 $i = 0;
451 $now = dol_now();
452 foreach ($listfieldinsert as $f => $value) {
453 $keycode = isset($listfieldvalue[$i]) ? $listfieldvalue[$i] : "";
454 if ($value == 'lang') {
455 $keycode = 'langcode';
456 }
457 if (empty($keycode)) {
458 $keycode = $value;
459 }
460
461 // Clean input variables
462 if ($value == 'entity') {
463 $_POST[$keycode] = $conf->entity;
464 }
465 if ($value == 'fk_user' && !($_POST[$keycode] > 0)) {
466 $_POST[$keycode] = '';
467 }
468 if ($value == 'private' && !is_numeric($_POST[$keycode])) {
469 $_POST[$keycode] = '0';
470 }
471 if ($value == 'position' && !is_numeric($_POST[$keycode])) {
472 $_POST[$keycode] = '1';
473 }
474 if ($value == 'defaultfortype' && !is_numeric($_POST[$keycode])) {
475 $_POST[$keycode] = '0';
476 }
477 //var_dump($keycode.' '.$value);
478
479 if ($i) {
480 $sql .= ", ";
481 }
482 if ($keycode == 'datec') {
483 $sql .= "'".$db->idate($now)."'";
484 } elseif (GETPOST($keycode) == '' && $keycode != 'langcode') {
485 $sql .= "null"; // langcode must be '' if not defined so the unique key that include lang will work
486 } elseif (GETPOST($keycode) == '0' && $keycode == 'langcode') {
487 $sql .= "''"; // langcode must be '' if not defined so the unique key that include lang will work
488 } elseif ($keycode == 'fk_user') {
489 if (!$user->admin) { // A non admin user can only edit its own template
490 $sql .= " ".((int) $user->id);
491 } else {
492 $sql .= " ".(GETPOSTINT($keycode));
493 }
494 } elseif ($keycode == 'content') {
495 $sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
496 } elseif (in_array($keycode, array('joinfiles', 'defaultfortype', 'private', 'position', 'entity'))) {
497 $sql .= GETPOSTINT($keycode);
498 } else {
499 $sql .= "'".$db->escape(GETPOST($keycode, 'alphanohtml'))."'";
500 }
501 $i++;
502 }
503 $sql .= ", 1, 1)";
504
505 dol_syslog("actionadd", LOG_DEBUG);
506 $result = $db->query($sql);
507 if ($result) { // Add is ok
508 setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
509 $_POST = array('id' => 25); // Clean $_POST array, we keep only id
510
511 if (!empty($backtopage)) {
512 header("Location: ".$backtopage);
513 exit(1);
514 }
515 } else {
516 if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
517 setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
518 } else {
519 dol_print_error($db);
520 }
521 $action = 'create';
522 }
523 }
524
525 // We modify the line
526 if ($ok && GETPOST('actionmodify')) {
527 $rowidcol = "rowid";
528
529 if (GETPOSTINT('fk_user') <= 0 && GETPOST('private')) {
530 setEventMessages($langs->trans("AnOwnerMustBeSetIfEmailTemplateIsPrivate"), null, 'errors');
531 $error++;
532 $action = 'edit';
533 }
534
535 if (!$error) {
536 // Modify entry
537 $sql = "UPDATE ".$db->sanitize($tabname[25])." SET ";
538 // Modify value of fields
539 $i = 0;
540 foreach ($listfieldmodify as $field) {
541 if ($field == 'entity') {
542 // entity not present on listfieldmodify array
543 $keycode = $field;
544 $_POST[$keycode] = $conf->entity;
545 } else {
546 $keycode = $listfieldvalue[$i];
547 }
548
549 if ($field == 'lang') {
550 $keycode = 'langcode';
551 }
552 if (empty($keycode)) {
553 $keycode = $field;
554 }
555
556 // Rename some POST variables into a generic name
557 if ($field == 'topic') {
558 $_POST['topic'] = GETPOST('topic-'.$rowid);
559 }
560 if ($field == 'joinfiles') {
561 $_POST['joinfiles'] = GETPOST('joinfiles-'.$rowid);
562 }
563 if ($field == 'content') {
564 $_POST['content'] = GETPOST('content-'.$rowid, 'restricthtml');
565 }
566 if ($field == 'content_lines') {
567 $_POST['content_lines'] = GETPOST('content_lines-'.$rowid, 'restricthtml');
568 }
569 if ($field == 'email_from') {
570 $_POST['email_from'] = GETPOST('email_from-'.$rowid, 'email');
571 }
572 if ($field == 'email_to') {
573 $_POST['email_to'] = GETPOST('email_to-'.$rowid, 'email');
574 }
575 if ($field == 'email_tocc') {
576 $_POST['email_tocc'] = GETPOST('email_tocc-'.$rowid, 'email');
577 }
578 if ($field == 'email_tobcc') {
579 $_POST['email_tobcc'] = GETPOST('email_tobcc-'.$rowid, 'email');
580 }
581
582 if ($i) {
583 $sql .= ", ";
584 }
585 $sql .= $field." = ";
586
587 if ((GETPOST($keycode) == '' && in_array($keycode, array('langcode'))) || (!in_array($keycode, array('langcode', 'position', 'private', 'defaultfortype')) && !GETPOST($keycode))) {
588 $sql .= "null"; // langcode,... must be '' if not defined so the unique key that include lang will work
589 } elseif ($keycode == 'langcode' && (GETPOST($keycode) == '0' || GETPOST($keycode) == '-1')) {
590 $sql .= "''"; // langcode must be '' if not defined so the unique key that include lang will work
591 } elseif ($keycode == 'fk_user') {
592 if (!$user->admin) { // A non admin user can only edit its own template
593 $sql .= ((int) $user->id);
594 } else {
595 $sql .= (GETPOSTINT($keycode) > 0 ? GETPOSTINT($keycode) : "null");
596 }
597 } elseif ($keycode == 'content') {
598 $sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
599 } elseif ($keycode == 'position') {
600 $sql .= (GETPOSTINT($keycode) > 0 ? GETPOSTINT($keycode) : 1);
601 } elseif (in_array($keycode, array('joinfiles', 'defaultfortype', 'private'))) {
602 $sql .= GETPOSTINT($keycode);
603 } else {
604 $sql .= "'".$db->escape(GETPOST($keycode, 'alphanohtml'))."'";
605 }
606 $i++;
607 }
608
609 $sql .= " WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
610 if (!$user->admin) { // A non admin user can only edit its own template
611 $sql .= " AND fk_user = ".((int) $user->id);
612 }
613
614 dol_syslog("actionmodify", LOG_DEBUG);
615
616 //print $sql; exit;
617 $resql = $db->query($sql);
618 if (!$resql) {
619 $error++;
620 setEventMessages($db->error(), null, 'errors');
621 $action = 'edit';
622 }
623 }
624
625 if (!$error) {
626 setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
627 }
628 }
629 }
630
631 if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) { // delete
632 $rowidcol = "rowid";
633
634 $sql = "DELETE from ".$db->sanitize($tabname[25])." WHERE rowid = ".((int) $rowid);
635 if (!$user->admin) { // A non admin user can only edit its own template
636 $sql .= " AND fk_user = ".((int) $user->id);
637 }
638 dol_syslog("delete", LOG_DEBUG);
639 $result = $db->query($sql);
640 if (!$result) {
641 if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
642 setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
643 } else {
644 dol_print_error($db);
645 }
646 }
647 }
648
649 // activate
650 if ($action == $acts[0] && $permissiontoedit) {
651 $rowidcol = "rowid";
652
653 $sql = "UPDATE ".$db->sanitize($tabname[25])." SET active = 1 WHERE rowid = ".((int) $rowid);
654
655 $result = $db->query($sql);
656 if (!$result) {
657 dol_print_error($db);
658 }
659 }
660
661 // disable
662 if ($action == $acts[1] && $permissiontoedit) {
663 $rowidcol = "rowid";
664
665 $sql = "UPDATE ".$db->sanitize($tabname[25])." SET active = 0 WHERE rowid = ".((int) $rowid);
666
667 $result = $db->query($sql);
668 if (!$result) {
669 dol_print_error($db);
670 }
671 }
672}
673
674
675/*
676 * View
677 */
678
679$form = new Form($db);
680$formadmin = new FormAdmin($db);
681
682$now = dol_now();
683
684//$help_url = "EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
685$help_url = '';
686if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
687 $title = $langs->trans("EMailsSetup");
688} else {
689 $title = $langs->trans("EMailTemplates");
690}
691$morejs = array();
692$morecss = array();
693
694$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,";
695$sql .= " content_lines, content, enabled, active, tms, datec";
696$sql .= " FROM ".MAIN_DB_PREFIX."c_email_templates";
697$sql .= " WHERE entity IN (".getEntity('email_template').")";
698if (!$user->admin) {
699 $sql .= " AND (private = 0 OR (private = 1 AND fk_user = ".((int) $user->id)."))"; // Show only public and private to me
700 $sql .= " AND (active = 1 OR fk_user = ".((int) $user->id).")"; // Show only active or owned by me
701}
702if (!getDolGlobalInt('MAIN_MULTILANGS')) {
703 $sql .= " AND (lang = '".$db->escape($langs->defaultlang)."' OR lang IS NULL OR lang = '')";
704}
705if ($search_label) {
706 $sql .= natural_search('label', $search_label);
707}
708if ($search_type_template != '' && $search_type_template != '-1') {
709 $sql .= natural_search('type_template', $search_type_template);
710}
711if ($search_lang) {
712 $sql .= natural_search('lang', $search_lang);
713}
714if ($search_fk_user != '' && $search_fk_user != '-1') {
715 $sql .= natural_search('fk_user', $search_fk_user, 2);
716}
717if ($search_module) {
718 $sql .= natural_search('module', $search_module);
719}
720// Exclude disabled modules
721$listofmodules = implode(",", array_keys($conf->modules));
722$sql .= "AND (".natural_search('module', $listofmodules, 3, 1)." OR module IS NULL)";
723if ($search_topic) {
724 $sql .= natural_search('topic', $search_topic);
725}
726// If sort order is "country", we use country_code instead
727if ($sortfield == 'country') {
728 $sortfield = 'country_code';
729}
730$sql .= $db->order($sortfield, $sortorder);
731//print $sql;
732
733// Output page
734// --------------------------------------------------------------------
735
736llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'mod-admin page-mails_templates');
737
738$arrayofselected = is_array($toselect) ? $toselect : array();
739
740$param = '';
741if (!empty($mode)) {
742 $param .= '&mode='.urlencode($mode);
743}
744if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
745 $param .= '&contextpage='.urlencode($contextpage);
746}
747if ($limit > 0 && $limit != $conf->liste_limit) {
748 $param .= '&limit='.((int) $limit);
749}
750if ($optioncss != '') {
751 $param .= '&optioncss='.urlencode($optioncss);
752}
753// Add $param from extra fields
754include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
755// Add $param from hooks
756$parameters = array();
757$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
758$param .= $hookmanager->resPrint;
759
760
761$titlepicto = 'title_setup';
762
763
764$url = DOL_URL_ROOT.'/admin/mails_templates.php?action=create';
765$newcardbutton = '';
766$newcardbutton .= dolGetButtonTitle($langs->trans('NewEMailTemplate'), '', 'fa fa-plus-circle', $url, '', (int) $permissiontoadd);
767
768
769$param = '';
770if ($search_label) {
771 $param .= '&search_label='.urlencode($search_label);
772}
773if (!empty($search_lang) && $search_lang != '-1') {
774 $param .= '&search_lang='.urlencode($search_lang);
775}
776if ($search_type_template != '-1') {
777 $param .= '&search_type_template='.urlencode($search_type_template);
778}
779if ($search_fk_user > 0) {
780 $param .= '&search_fk_user='.urlencode($search_fk_user);
781}
782if ($search_module) {
783 $param .= '&search_module='.urlencode($search_module);
784}
785if ($search_topic) {
786 $param .= '&search_topic='.urlencode($search_topic);
787}
788
789$paramwithsearch = $param;
790if ($sortorder) {
791 $paramwithsearch .= '&sortorder='.urlencode($sortorder);
792}
793if ($sortfield) {
794 $paramwithsearch .= '&sortfield='.urlencode($sortfield);
795}
796if ($limit) {
797 $paramwithsearch .= '&limit='.((int) $limit);
798}
799if (GETPOST('from', 'alpha')) {
800 $paramwithsearch .= '&from='.urlencode(GETPOST('from', 'alpha'));
801}
802
803$massactionbutton = '';
804
805
806// List of available record in database
807dol_syslog("htdocs/admin/mails_templates.php", LOG_DEBUG);
808
809$resql = $db->query($sql);
810if (!$resql) {
811 dol_print_error($db);
812 exit;
813}
814
815$nbtotalofrecords = $db->num_rows($resql);
816
817$sql .= $db->plimit($limit + 1, $offset);
818
819$resql = $db->query($sql);
820if (!$resql) {
821 dol_print_error($db);
822 exit;
823}
824
825$num = $db->num_rows($resql);
826
827if ($action != 'create') {
828 print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST" id="list_of_c_email_templates" spellcheck="false">';
829 print '<input type="hidden" name="token" value="'.newToken().'">';
830 print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
831} else {
832 // Form to add a new line
833 print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST" id="create_c_email_template" spellcheck="false">';
834 print '<input type="hidden" name="token" value="'.newToken().'">';
835 print '<input type="hidden" name="action" value="add">';
836 print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
837 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
838}
839
840if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
841 print load_fiche_titre($title, '', $titlepicto);
842} else {
843 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'tools', 0, $newcardbutton, '', $limit, 'limit', 0, 1);
844}
845
846if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
847 $head = email_admin_prepare_head();
848
849 print dol_get_fiche_head($head, 'templates', '', -1);
850
851 if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
852 print load_fiche_titre('', $newcardbutton, '');
853 }
854}
855
856
857// Confirm deletion of record
858if ($action == 'delete') {
859 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);
860}
861
862
863$fieldlist = explode(',', $tabfield[25]);
864
865if ($action == 'create') {
866 // If data was already input, we define them in obj to populate input fields.
867 $obj = new stdClass();
868 $obj->label = GETPOST('label');
869 $obj->lang = GETPOST('lang');
870 $obj->type_template = GETPOST('type_template');
871 $obj->fk_user = GETPOSTINT('fk_user');
872 $obj->private = GETPOSTINT('private');
873 $obj->position = GETPOST('position');
874 $obj->topic = GETPOST('topic');
875 $obj->joinfiles = GETPOST('joinfiles');
876 $obj->defaultfortype = GETPOST('defaultfortype') ? 1 : 0;
877 $obj->content = GETPOST('content', 'restricthtml');
878
879 print '<div class="div-table-responsive-no-min">';
880 print '<table class="noborder centpercent" id="table_create_c_email_template">';
881
882 // Line to enter new values (title)
883 print '<tr class="liste_titre">';
884 foreach ($fieldlist as $field => $value) {
885 // Determine the field name based on the possible names
886 // in the data dictionaries.
887 $valuetoshow = ucfirst($fieldlist[$field]); // Par default
888 $valuetoshow = $langs->trans($valuetoshow); // try to translate
889 $css = "left";
890 if ($fieldlist[$field] == 'module') {
891 $valuetoshow = '&nbsp;';
892 }
893 if ($fieldlist[$field] == 'fk_user') {
894 $valuetoshow = $langs->trans("Owner");
895 }
896 if ($fieldlist[$field] == 'lang') {
897 $valuetoshow = (!getDolGlobalInt('MAIN_MULTILANGS') ? '&nbsp;' : $langs->trans("Language"));
898 }
899 if ($fieldlist[$field] == 'type') {
900 $valuetoshow = $langs->trans("Type");
901 }
902 if ($fieldlist[$field] == 'position') {
903 $css = 'center';
904 }
905 if ($fieldlist[$field] == 'code') {
906 $valuetoshow = $langs->trans("Code");
907 }
908 if ($fieldlist[$field] == 'label') {
909 $valuetoshow = $langs->trans("Label");
910 }
911 if ($fieldlist[$field] == 'type_template') {
912 $valuetoshow = $langs->trans("TypeOfTemplate");
913 $css = "center";
914 }
915 if (in_array($fieldlist[$field], array('private', 'private', 'defaultfortype'))) {
916 $css = 'center';
917 }
918
919 if ($fieldlist[$field] == 'topic') {
920 $valuetoshow = '';
921 }
922 if ($fieldlist[$field] == 'joinfiles') {
923 $valuetoshow = '';
924 }
925 if ($fieldlist[$field] == 'content') {
926 $valuetoshow = '';
927 }
928 if ($fieldlist[$field] == 'content_lines') {
929 $valuetoshow = '';
930 }
931 if ($valuetoshow != '') {
932 print '<th class="'.$css.'">';
933 if (!empty($tabhelp[25][$value]) && preg_match('/^http(s*):/i', $tabhelp[25][$value])) {
934 print '<a href="'.$tabhelp[25][$value].'" target="_blank" rel="noopener noreferrer">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
935 } elseif (!empty($tabhelp[25][$value])) {
936 if (in_array($value, array('topic'))) {
937 print $form->textwithpicto($valuetoshow, $tabhelp[25][$value], 1, 'help', '', 0, 2, $value); // Tooltip on click
938 } else {
939 print $form->textwithpicto($valuetoshow, $tabhelp[25][$value], 1, 'help', '', 0, 2); // Tooltip on hover
940 }
941 } else {
942 print $valuetoshow;
943 }
944 print '</th>';
945 }
946 }
947 print '<th>';
948 print '</th>';
949 print '</tr>';
950
951 $tmpaction = 'create';
952 $parameters = array(
953 'fieldlist' => $fieldlist,
954 'tabname' => $tabname[25]
955 );
956 $reshook = $hookmanager->executeHooks('createEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
957 $error = $hookmanager->error;
958 $errors = $hookmanager->errors;
959
960
961 // Line to enter new values (input fields)
962 print '<tr class="oddeven">';
963
964 if (empty($reshook)) {
965 if ($action == 'edit') {
966 fieldList($fieldlist, $obj, $tabname[25], 'hide');
967 } else {
968 fieldList($fieldlist, $obj, $tabname[25], 'add');
969 }
970 }
971 // Action column
972 print '<td class="right">';
973 print '</td>';
974 print "</tr>";
975
976 print '<tr class="oddeven nodrag nodrop nohover"><td colspan="9" style="padding-left: 20px; padding-right: 20px;">';
977
978 // Show fields for topic, join files and body
979 $fieldsforcontent = array('topic', 'email_from', 'joinfiles', 'content');
980 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TO')) {
981 $fieldsforcontent[] = 'email_to';
982 }
983 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOCC')) {
984 $fieldsforcontent[] = 'email_tocc';
985 }
986 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOBCC')) {
987 $fieldsforcontent[] = 'email_tobcc';
988 }
989 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
990 $fieldsforcontent[] = 'content_lines';
991 }
992 foreach ($fieldsforcontent as $tmpfieldlist) {
993 print '<div class="inline-block lineformailtemplatefield paddingtop paddingbottom centpercent">';
994 // Topic of email
995 if ($tmpfieldlist == 'topic') {
996 print '<span class="bold minwidth150 inline-block">'.$form->textwithpicto($langs->trans("Topic"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</span>';
997 }
998 if ($tmpfieldlist == 'email_from') {
999 print '<span class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("MailFrom"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</span>';
1000 }
1001 if ($tmpfieldlist == 'email_to') {
1002 print '<span class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("MailTo"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</span>';
1003 }
1004 if ($tmpfieldlist == 'email_tocc') {
1005 print '<span class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("MailCC"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</span>';
1006 }
1007 if ($tmpfieldlist == 'email_tobcc') {
1008 print '<span class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("MailCCC"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</span>';
1009 }
1010 if ($tmpfieldlist == 'joinfiles') {
1011 print '<span class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</span>';
1012 }
1013 if ($tmpfieldlist == 'content') {
1014 print '<span class="minwidth150 inline-block margintoponly">'.$form->textwithpicto($langs->trans("Content"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</span>';
1015
1016 // Add layout and AI tools for content
1017 $out = '';
1018 $formmail = new FormMail($db);
1019 $formmail->withlayout = 'email';
1020 $formmail->withaiprompt = 'html';
1021 $formmail->withfckeditor = 1;
1022
1023 $showlinktolayout = (getDolGlobalInt('MAIN_EMAIL_USE_LAYOUT') ? $formmail->withlayout : '');
1024 $showlinktolayoutlabel = $langs->trans("FillMessageWithALayout");
1025 $showlinktoai = (isModEnabled('ai') ? 'textgenerationemail' : '');
1026 $showlinktoailabel = $langs->trans("FillMessageWithAIContent");
1027 $htmlname = 'content';
1028 include DOL_DOCUMENT_ROOT.'/core/tpl/formlayoutai.tpl.php';
1029 print $out;
1030 print '<br>';
1031 }
1032 if ($tmpfieldlist == 'content_lines') {
1033 print '<span class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</span><br>';
1034 }
1035
1036 // Input field
1037 if ($tmpfieldlist == 'topic') {
1038 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '').'">';
1039 } elseif ($tmpfieldlist == 'email_from') {
1040 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '').'" spellcheck="false">';
1041 } elseif ($tmpfieldlist == 'email_to') {
1042 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '').'" spellcheck="false">';
1043 } elseif ($tmpfieldlist == 'email_tocc') {
1044 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '').'" spellcheck="false">';
1045 } elseif ($tmpfieldlist == 'email_tobcc') {
1046 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '').'" spellcheck="false">';
1047 } elseif ($tmpfieldlist == 'joinfiles') {
1048 print $form->selectyesno($tmpfieldlist, (isset($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '0'), 1, false, 0, 1);
1049 } else {
1050 $okforextended = true;
1051 if (!getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) {
1052 $okforextended = false;
1053 }
1054 $doleditor = new DolEditor($tmpfieldlist, (!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : ''), '', 400, 'dolibarr_mailings', 'In', false, $acceptlocallinktomedia, $okforextended, ROWS_6, '90%');
1055 print $doleditor->Create(1);
1056 }
1057 print '</div>';
1058 print '<br>';
1059 }
1060
1061 print '</tr>';
1062
1063 print '</table>';
1064
1065 if ($action != 'edit') {
1066 print '<center>';
1067 print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'"> ';
1068 print '<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
1069 print '</center>';
1070 }
1071
1072 print '</div>';
1073 print '</form>';
1074
1075 print '<br><br><br>';
1076}
1077
1078if ($action != 'create') {
1079 print '<div class="div-table-responsive-no-min">';
1080 print '<table class="noborder centpercent" id="table_list_of_c_email_templates">';
1081
1082 $i = 0;
1083
1084 // There is several pages
1085 /*
1086 if ($num > $limit) {
1087 print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).'">';
1088 print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $limit ? 1 : 0), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
1089 print '</td></tr>';
1090 }
1091 */
1092
1093 // Title line with search boxes
1094 print '<tr class="liste_titre" id="Title line with search boxes">';
1095 // Action column
1096 if ($conf->main_checkbox_left_column) {
1097 print '<td class="liste_titre center" width="64">';
1098 $searchpicto = $form->showFilterButtons();
1099 print $searchpicto;
1100 print '</td>';
1101 }
1102 foreach ($fieldlist as $field => $value) {
1103 if ($value == 'module') {
1104 print '<td class="liste_titre"><input type="text" name="search_module" class="maxwidth75" value="'.dol_escape_htmltag($search_module).'" spellcheck="false"></td>';
1105 } elseif ($value == 'label') {
1106 print '<td class="liste_titre"><input type="text" name="search_label" class="maxwidth75" value="'.dol_escape_htmltag($search_label).'" spellcheck="false"></td>';
1107 } elseif ($value == 'lang') {
1108 print '<td class="liste_titre">';
1109 print $formadmin->select_language($search_lang, 'search_lang', 0, array(), 1, 0, 0, 'maxwidth100');
1110 print '</td>';
1111 } elseif ($value == 'fk_user') {
1112 print '<td class="liste_titre">';
1113 print $form->select_dolusers($search_fk_user, 'search_fk_user', 1, null, 0, ($user->admin ? '' : 'hierarchyme'), array(), '0', 0, 0, '', 0, '', 'maxwidth100', 1);
1114 print '</td>';
1115 } elseif ($value == 'topic') {
1116 print '<td class="liste_titre"><input type="text" class="maxwidth150" name="search_topic" value="'.dol_escape_htmltag($search_topic).'" spellcheck="false"></td>';
1117 } elseif ($value == 'type_template') {
1118 print '<td class="liste_titre center">';
1119 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1120 print $form->selectarray('search_type_template', $elementList, $search_type_template, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100 maxwidth125', 1, '', 0, 1);
1121 print '</td>';
1122 } elseif (!in_array($value, array('content', 'content_lines'))) {
1123 print '<td class="liste_titre"></td>';
1124 }
1125 }
1126 /*if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
1127 print '<td class="liste_titre"></td>';
1128 }*/
1129 // Status
1130 print '<td></td>';
1131
1132 // 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
1133 if (!empty($arrayfields['t.tms']['checked'])) {
1134 print '<td></td>'; // tms / Modif. date
1135 }
1136 if (!empty($arrayfields['t.datec']['checked'])) {
1137 print '<td></td>'; // datec / Date creation
1138 }
1139 // Action column
1140 if (!$conf->main_checkbox_left_column) {
1141 print '<td class="liste_titre center" width="64">';
1142 $searchpicto = $form->showFilterButtons();
1143 print $searchpicto;
1144 print '</td>';
1145 }
1146 print '</tr>';
1147
1148 // Title of lines
1149 print '<tr class="liste_titre" id="Title of lines">';
1150 // Action column
1151 if ($conf->main_checkbox_left_column) {
1152 print getTitleFieldOfList('');
1153 }
1154 array_push($fieldlist, "tms", "datec");
1155 foreach ($fieldlist as $field => $value) {
1156 $showfield = 1; // By default
1157 $css = "left";
1158 $sortable = 1;
1159 $valuetoshow = '';
1160 $forcenowrap = 1;
1161 /*
1162 $tmparray=getLabelOfField($fieldlist[$field]);
1163 $showfield=$tmp['showfield'];
1164 $valuetoshow=$tmp['valuetoshow'];
1165 $css=$tmp['align'];
1166 $sortable=$tmp['sortable'];
1167 */
1168 $valuetoshow = ucfirst($fieldlist[$field]); // By default
1169 $valuetoshow = $langs->trans($valuetoshow); // try to translate
1170 if ($fieldlist[$field] == 'module') {
1171 $css = 'tdoverflowmax100';
1172 }
1173 if ($fieldlist[$field] == 'fk_user') {
1174 $valuetoshow = $langs->trans("Owner");
1175 }
1176 if ($fieldlist[$field] == 'lang') {
1177 $valuetoshow = $langs->trans("Language");
1178 }
1179 if ($fieldlist[$field] == 'type') {
1180 $valuetoshow = $langs->trans("Type");
1181 }
1182 if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
1183 $valuetoshow = $langs->trans("Label");
1184 }
1185 if ($fieldlist[$field] == 'type_template') {
1186 $css = 'center';
1187 $valuetoshow = $langs->trans("TypeOfTemplate");
1188 }
1189 if ($fieldlist[$field] == 'private') {
1190 $css = 'center';
1191 }
1192 if ($fieldlist[$field] == 'position') {
1193 $css = 'center';
1194 }
1195 if ($fieldlist[$field] == 'tms') {
1196 $valuetoshow = 'Modif. date';
1197 }
1198 if ($fieldlist[$field] == 'datec') {
1199 $valuetoshow = 'Date creation';
1200 }
1201
1202 if ($fieldlist[$field] == 'joinfiles') {
1203 $valuetoshow = $langs->trans("FilesAttachedToEmail");
1204 $css = 'center';
1205 $forcenowrap = 0;
1206 }
1207 if ($fieldlist[$field] == 'content') {
1208 $valuetoshow = $langs->trans("Content");
1209 $showfield = 0;
1210 }
1211 if ($fieldlist[$field] == 'content_lines') {
1212 $valuetoshow = $langs->trans("ContentForLines");
1213 $showfield = 0;
1214 }
1215 if ($value == 'tms' && empty($arrayfields['t'.$value]['checked'])) {
1216 $showfield = 0;
1217 }
1218 if ($value == 'datec' && empty($arrayfields['t.'.$value]['checked'])) {
1219 $showfield = 0;
1220 }
1221
1222 // Show fields
1223 if ($showfield) {
1224 if (!empty($tabhelp[25][$value])) {
1225 if (in_array($value, array('topic'))) {
1226 $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[25][$value], 1, 'help', '', 0, 2, 'tooltip'.$value, $forcenowrap); // Tooltip on click
1227 } else {
1228 $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[25][$value], 1, 'help', '', 0, 2, '', $forcenowrap); // Tooltip on hover
1229 }
1230 }
1231 $sortfieldtouse = ($sortable ? $fieldlist[$field] : '');
1232 if ($sortfieldtouse == 'type_template') {
1233 $sortfieldtouse .= ',lang,position,label';
1234 }
1235 print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], $sortfieldtouse, ($page ? 'page='.$page.'&' : ''), $paramwithsearch, '', $sortfield, $sortorder, $css.' ');
1236 }
1237 }
1238
1239 print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $paramwithsearch, '', $sortfield, $sortorder, 'center ');
1240 // Action column
1241 if (!$conf->main_checkbox_left_column) {
1242 print getTitleFieldOfList('');
1243 }
1244 print '</tr>';
1245
1246 $nbqualified = 0;
1247 if ($num) {
1248 // Lines with values
1249 while ($i < $num) {
1250 $obj = $db->fetch_object($resql);
1251
1252 if ($obj) {
1253 if (($action == 'edit' || $action == 'preview') && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
1254 // TODO Move this 2 lines into a popup
1255 print '<tr class="nohover oddeven noborderbottom" id="rowid-'.$obj->rowid.'" name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'">';
1256
1257 $tmpaction = 'edit';
1258 if ($action == 'edit') {
1259 // do not show tms and datec
1260 $fieldlist = explode(',', $tabfield[25]);
1261 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[25]);
1262 } else {
1263 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[25]);
1264 }
1265 $reshook = $hookmanager->executeHooks('editEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1266 $error = $hookmanager->error;
1267 $errors = $hookmanager->errors;
1268
1269 $colspan = 0;
1270
1271 // Action column
1272 if ($conf->main_checkbox_left_column) {
1273 print '<td class="center">';
1274 print '</td>';
1275 $colspan++;
1276 }
1277 // Show main fields
1278 if (empty($reshook)) {
1279 $colspan += fieldList($fieldlist, $obj, $tabname[25], $action);
1280 }
1281 // Action column
1282 if (!$conf->main_checkbox_left_column) {
1283 print '<td class="center">';
1284 print '</td>';
1285 $colspan++;
1286 }
1287 print "</tr>\n";
1288
1289 print '<tr class="oddeven nohover" id="tr-aaa-'.$rowid.'">';
1290 if ($conf->main_checkbox_left_column) {
1291 print '<td class="center"></td>';
1292 }
1293 print '<td colspan="'.($colspan - 1).'" class="" style="padding-left: 20px; padding-right: 20px;">';
1294
1295 $fieldsforcontent = array('topic', 'email_from', 'joinfiles', 'content');
1296 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TO')) {
1297 $fieldsforcontent[] = 'email_to';
1298 }
1299 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOCC')) {
1300 $fieldsforcontent[] = 'email_tocc';
1301 }
1302 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOBCC')) {
1303 $fieldsforcontent[] = 'email_tobcc';
1304 }
1305 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
1306 $fieldsforcontent[] = 'content_lines';
1307 }
1308
1309 $parameters = array('fieldsforcontent' => &$fieldsforcontent, 'tabname' => $tabname[25]);
1310 $hookmanager->executeHooks('editEmailTemplateFieldsForContent', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1311
1312 print '<div class="lineformailtemplatefield centpercent">';
1313 foreach ($fieldsforcontent as $tmpfieldlist) {
1314 $showfield = 1;
1315 $css = "left";
1316 $valuetoshow = $obj->$tmpfieldlist;
1317
1318 $class = 'tddict';
1319 // Show value for field
1320 if ($showfield) {
1321 print '<div class="inline-block lineformailtemplatefield paddingtop paddingbottom centpercent">';
1322 // Show line for topic, joinfiles and content
1323 if ($tmpfieldlist == 'topic') {
1324 print '<div class="minwidth150 inline-block bold">'.$form->textwithpicto($langs->trans("Topic"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</div> ';
1325 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'"'.($action != 'edit' ? ' disabled' : '').'>';
1326 print '<br>'."\n";
1327 }
1328 if ($tmpfieldlist == 'email_from') {
1329 print '<div class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("MailFrom"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</div> ';
1330 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'"'.($action != 'edit' ? ' disabled' : '').' spellcheck="false">';
1331 print '<br>'."\n";
1332 }
1333 if ($tmpfieldlist == 'email_to') {
1334 print '<div class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("MailTo"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</div> ';
1335 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'"'.($action != 'edit' ? ' disabled' : '').' spellcheck="false">';
1336 print '<br>'."\n";
1337 }
1338 if ($tmpfieldlist == 'email_tocc') {
1339 print '<div class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("MailCC"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</div> ';
1340 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'"'.($action != 'edit' ? ' disabled' : '').' spellcheck="false">';
1341 print '<br>'."\n";
1342 }
1343 if ($tmpfieldlist == 'email_tobcc') {
1344 print '<div class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("MailCCC"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</div> ';
1345 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'"'.($action != 'edit' ? ' disabled' : '').' spellcheck="false">';
1346 print '<br>'."\n";
1347 }
1348 if ($tmpfieldlist == 'joinfiles') {
1349 print '<div class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</div> ';
1350 print $form->selectyesno($tmpfieldlist.'-'.$rowid, (isset($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '0'), 1, ($action != 'edit'), 0, 1);
1351 print '<br>'."\n";
1352 }
1353
1354 if ($tmpfieldlist == 'content') {
1355 print '<div class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("Content"), $tabhelp[25][$tmpfieldlist], 1, 'help', 'margintoponly', 0, 2, $tmpfieldlist).'</div>';
1356
1357 // Add layout and AI tools for content
1358 $out = '';
1359
1360 $formmail = new FormMail($db);
1361 $formmail->withlayout = 'email';
1362 $formmail->withaiprompt = 'html';
1363 $formmail->withfckeditor = 1;
1364
1365 $showlinktolayout = (getDolGlobalInt('MAIN_EMAIL_USE_LAYOUT') ? $formmail->withlayout : '');
1366 $showlinktolayoutlabel = $langs->trans("FillMessageWithALayout");
1367 $showlinktoai = (isModEnabled('ai') ? 'textgenerationemail' : '');
1368 $showlinktoailabel = $langs->trans("FillMessageWithAIContent");
1369 $htmlname = 'content_'.$rowid;
1370 include DOL_DOCUMENT_ROOT.'/core/tpl/formlayoutai.tpl.php';
1371 print $out;
1372
1373 $okforextended = true;
1374 if (!getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) {
1375 $okforextended = false;
1376 }
1377 $doleditor = new DolEditor($tmpfieldlist.'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 450, 'dolibarr_mailings', 'In', false, $acceptlocallinktomedia, $okforextended, ROWS_6, '80%', ($action != 'edit' ? 1 : 0));
1378 print $doleditor->Create(1);
1379 }
1380 if ($tmpfieldlist == 'content_lines') {
1381 print '<br>'."\n";
1382 print $form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[25][$tmpfieldlist], 1, 'help', 'margintoponly', 0, 2, $tmpfieldlist).'<br>';
1383 $okforextended = true;
1384 if (!getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) {
1385 $okforextended = false;
1386 }
1387 $doleditor = new DolEditor($tmpfieldlist.'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 140, 'dolibarr_mailings', 'In', false, $acceptlocallinktomedia, $okforextended, ROWS_6, '80%');
1388 print $doleditor->Create(1);
1389 }
1390 print '</div>';
1391 }
1392 }
1393 print '</div>';
1394 print '<center><input type="hidden" name="page" value="'.$page.'">';
1395 print '<input type="hidden" name="rowid" value="'.$rowid.'">';
1396 if ($action == 'edit') {
1397 print '<input type="submit" class="button buttongen button-save" name="actionmodify" value="'.$langs->trans("Save").'">';
1398 }
1399 print '<input type="submit" class="button buttongen button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
1400 print '</center>';
1401 print '</td>';
1402
1403 if (!$conf->main_checkbox_left_column) {
1404 print '<td class="center"></td>';
1405 }
1406
1407 print '</tr>';
1408
1409 $nbqualified++;
1410 } else {
1411 // If template is for a module, check module is enabled.
1412 if ($obj->module) {
1413 $tempmodulekey = $obj->module;
1414 if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1415 $i++;
1416 continue;
1417 }
1418 }
1419
1420 $keyforobj = 'type_template';
1421 if (!in_array($obj->$keyforobj, array_keys($elementList))) {
1422 $i++;
1423 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)
1424 }
1425 // Test on 'enabled'
1426 if (! (int) dol_eval((string) $obj->enabled, 1, 1, '1')) {
1427 $i++;
1428 continue; // Email template not qualified
1429 }
1430
1431 $nbqualified++;
1432
1433 // Can an entry be erased or disabled ?
1434 $iserasable = 1;
1435 $canbedisabled = 1;
1436 $canbemodified = 1; // true by default
1437 if (!$user->admin && $obj->fk_user != $user->id) {
1438 $iserasable = 0;
1439 $canbedisabled = 0;
1440 $canbemodified = 0;
1441 }
1442
1443 $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) : '');
1444 if ($param) {
1445 $url .= '&'.$param;
1446 }
1447
1448 print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
1449
1450 // Action column - Modify link / Delete link
1451 if ($conf->main_checkbox_left_column) {
1452 print '<td class="center nowraponall" width="64">';
1453 if ($canbemodified) {
1454 print '<a class="reposition editfielda" href="'.$url.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
1455 } else {
1456 print '<a class="reposition editfielda" href="'.$url.'&action=preview&token='.newToken().'">'.img_view().'</a>';
1457 }
1458 if ($iserasable) {
1459 print '<a class="reposition marginleftonly" href="'.$url.'&action=delete&token='.newToken().$param.'">'.img_delete().'</a>';
1460 }
1461 print '</td>';
1462 }
1463
1464 $tmpaction = 'view';
1465 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[25]);
1466 $reshook = $hookmanager->executeHooks('viewEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1467
1468 $error = $hookmanager->error;
1469 $errors = $hookmanager->errors;
1470
1471 if (empty($reshook)) {
1472 foreach ($fieldlist as $field => $value) {
1473 if (in_array($fieldlist[$field], array('content', 'content_lines'))) {
1474 continue;
1475 }
1476 $showfield = 1;
1477 $css = "";
1478 $class = "tddict";
1479 $title = '';
1480 $tmpvar = $fieldlist[$field];
1481 $valuetoshow = $obj->$tmpvar;
1482 if ($value == 'label' || $value == 'topic') {
1483 if ($langs->trans($valuetoshow) != $valuetoshow) {
1484 $valuetoshow = $langs->trans($valuetoshow);
1485 }
1486 $valuetoshow = dol_escape_htmltag($valuetoshow);
1487 }
1488 if ($value == 'label') {
1489 $class .= ' tdoverflowmax200';
1490 }
1491 if ($value == 'topic') {
1492 $class .= ' tdoverflowmax200 small';
1493 }
1494 if ($value == 'type_template') {
1495 $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
1496 $css = "center tdoverflowmax150";
1497 }
1498 if ($value == 'lang' && $valuetoshow) {
1499 $valuetoshow = $valuetoshow.' - '.$langs->trans("Language_".$valuetoshow);
1500 $class .= ' tdoverflowmax100';
1501 }
1502 if ($value == 'fk_user') {
1503 if ($valuetoshow > 0) {
1504 $fuser = new User($db);
1505 $fuser->fetch($valuetoshow);
1506 $valuetoshow = $fuser->getNomUrl(-1);
1507
1508 if ($obj->private) {
1509 $valuetoshow = img_picto($langs->transnoentitiesnoconv("Private"), 'lock', 'class="pictofixedwidth"').$valuetoshow;
1510 }
1511
1512 $class .= ' tdoverflowmax100';
1513 }
1514 }
1515 if ($value == 'private') {
1516 $css = "center";
1517 if ($valuetoshow) {
1518 $valuetoshow = yn($valuetoshow);
1519 } else {
1520 $valuetoshow = '';
1521 }
1522 }
1523 if ($value == 'position') {
1524 $css = "center";
1525 }
1526 if (in_array($value, array('joinfiles', 'defaultfortype'))) {
1527 $css = "center";
1528 if ($valuetoshow) {
1529 //$valuetoshow = yn(1);
1530 $valuetoshow = '<input type="checkbox" checked="checked" disabled>';
1531 } else {
1532 $valuetoshow = '';
1533 }
1534 }
1535 if ($css) {
1536 $class .= ' '.$css;
1537 }
1538
1539 if ($value == 'tms' && empty($arrayfields['t'.$value]['checked'])) {
1540 $showfield = 0;
1541 }
1542 if ($value == 'datec' && empty($arrayfields['t.'.$value]['checked'])) {
1543 $showfield = 0;
1544 }
1545
1546 // Show value for field
1547 if ($showfield) {
1548 print '<!-- '.$fieldlist[$field].' -->';
1549 print '<td class="'.$class.'"';
1550 if (in_array($value, array('code', 'label', 'topic'))) {
1551 print ' title="'.dol_escape_htmltag($valuetoshow).'"';
1552 }
1553 print '>';
1554 print $valuetoshow;
1555 print '</td>';
1556 }
1557 }
1558 }
1559
1560 // Status / Active
1561 print '<td class="center nowrap">';
1562 if ($canbedisabled) {
1563 print '<a class="reposition" href="'.$url.'&action='.$acts[$obj->active].'&token='.newToken().'">'.$actl[$obj->active].'</a>';
1564 } else {
1565 print '<span class="opacitymedium">'.$actl[$obj->active].'</span>';
1566 }
1567 print "</td>";
1568
1569 // Action column - Modify link / Delete link
1570 if (!$conf->main_checkbox_left_column) {
1571 print '<td class="center nowraponall" width="64">';
1572 if ($canbemodified) {
1573 print '<a class="reposition editfielda" href="'.$url.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
1574 }
1575 if ($iserasable) {
1576 print '<a class="reposition marginleftonly" href="'.$url.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
1577 //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
1578 }
1579 print '</td>';
1580 }
1581
1582 print "</tr>\n";
1583 }
1584 }
1585
1586 $i++;
1587 }
1588 }
1589
1590 // If no record found
1591 if ($nbqualified == 0) {
1592 $colspan = 12;
1593 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1594 }
1595
1596 print '</table>';
1597 print '</div>';
1598
1599 print '</form>';
1600}
1601
1602if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
1603 print dol_get_fiche_end();
1604}
1605
1606
1607// End of page
1608llxFooter();
1609$db->close();
1610
1611
1621function fieldList($fieldlist, $obj = null, $tabname = '', $context = '')
1622{
1623 global $langs, $user, $db;
1624 global $form;
1625 global $elementList;
1626
1627 $formadmin = new FormAdmin($db);
1628 $nboffieldsprinted = 0;
1629
1630 foreach ($fieldlist as $value) {
1631 //print $value;
1632 if ($value == 'module') {
1633 print '<td></td>';
1634 $nboffieldsprinted++;
1635 } elseif ($value == 'fk_user') {
1636 print '<td>';
1637 if ($user->admin && $context != 'preview') {
1638 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');
1639 } else {
1640 if ($context == 'add') { // I am not admin and we show the add form
1641 print $user->getNomUrl(-1); // Me
1642 $forcedvalue = $user->id;
1643 } else {
1644 if ($obj && !empty($obj->$value) && $obj->$value > 0) {
1645 $fuser = new User($db);
1646 $fuser->fetch($obj->$value);
1647 print $fuser->getNomUrl(-1);
1648 $forcedvalue = $fuser->id;
1649 } else {
1650 $forcedvalue = $obj->$value;
1651 }
1652 }
1653 $keyname = $value;
1654 print '<input type="hidden" value="'.$forcedvalue.'" name="'.$keyname.'">';
1655 }
1656 print '</td>';
1657 $nboffieldsprinted++;
1658 } elseif ($value == 'lang') {
1659 print '<td>';
1660 if (getDolGlobalInt('MAIN_MULTILANGS') && $context != 'preview') {
1661 $selectedlang = GETPOSTISSET('langcode') ? GETPOST('langcode', 'aZ09') : $langs->defaultlang;
1662 if ($context == 'edit') {
1663 $selectedlang = $obj->lang;
1664 }
1665 print $formadmin->select_language($selectedlang, 'langcode', 0, array(), $langs->trans("Language"), 0, 0, 'maxwidth100');
1666 } else {
1667 if (!empty($obj->lang)) {
1668 print $obj->lang.' - '.$langs->trans('Language_'.$obj->lang);
1669 }
1670 $keyname = $value;
1671 if ($keyname == 'lang') {
1672 $keyname = 'langcode'; // Avoid conflict with lang param
1673 }
1674 print '<input type="hidden" value="'.(empty($obj->lang) ? '' : $obj->lang).'" name="'.$keyname.'">';
1675 }
1676 print '</td>';
1677 $nboffieldsprinted++;
1678 } elseif ($value == 'type_template') {
1679 // Le type de template
1680 print '<td class="center">';
1681 if (($context == 'edit' && !empty($obj->type_template) && !in_array($obj->type_template, array_keys($elementList))) || $context == 'preview') {
1682 // Current template type is an unknown type, so we must keep it as it is.
1683 print '<input type="hidden" name="type_template" value="'.$obj->type_template.'">';
1684 print $obj->type_template;
1685 } else {
1686 print $form->selectarray('type_template', $elementList, (!empty($obj->type_template) ? $obj->type_template : ''), 1, 0, 0, '', 0, 0, 0, '', 'minwidth75 maxwidth125', 1, '', 0, 1);
1687 }
1688 print '</td>';
1689 $nboffieldsprinted++;
1690 } elseif ($context == 'add' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1691 //print '<td></td>';
1692 } elseif ($context == 'edit' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1693 print '<td></td>';
1694 $nboffieldsprinted++;
1695 } elseif ($context == 'preview' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1696 print '<td></td>';
1697 $nboffieldsprinted++;
1698 } elseif ($context == 'hide' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1699 //print '<td></td>';
1700 } else {
1701 $size = '';
1702 $class = '';
1703 $classtd = '';
1704 if ($value == 'code') {
1705 $class = 'maxwidth100';
1706 }
1707 if ($value == 'label') {
1708 $class = 'maxwidth200';
1709 }
1710 if ($value == 'private') {
1711 $class = 'maxwidth50';
1712 $classtd = 'center';
1713 }
1714 if ($value == 'position') {
1715 $class = 'maxwidth50 center';
1716 $classtd = 'center';
1717 }
1718 if ($value == 'topic') {
1719 $class = 'quatrevingtpercent';
1720 }
1721 if ($value == 'defaultfortype') {
1722 $class = 'width25 center';
1723 $classtd = 'center';
1724 }
1725
1726 print '<td'.($classtd ? ' class="'.$classtd.'"' : '').'>';
1727 if (in_array($value, array('defaultfortype', 'private')) && $context != 'preview') {
1728 if (empty($user->admin)) {
1729 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1730 print $form->selectyesno($value, GETPOSTISSET($value) ? GETPOSTINT($value) : (($context != 'add' && isset($obj->$value)) ? $obj->$value : '1'), 1, false, 0, 1);
1731 } else {
1732 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1733 print $form->selectyesno($value, (isset($obj->$value) ? $obj->$value : ''), 1, false, 0, 1);
1734 }
1735 } else {
1736 print '<input type="text" '.$size.'class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->$value) ? $obj->$value : '').'" name="'. $value .'"'.($context == 'preview' ? ' disabled' : '').' spellcheck="false">';
1737 }
1738 print '</td>';
1739 $nboffieldsprinted++;
1740 }
1741 }
1742
1743 return $nboffieldsprinted;
1744}
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
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 Dolibarr users.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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:540
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:738
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:181
fieldList($fieldlist, $obj=null, $tabname='', $context='')
Show fields in insert/edit mode.
$context
@method int call_trigger(string $triggerName, ?User $user)
Definition logout.php:42
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.