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
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,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 {
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 {
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) {
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) {
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 (!empty($search) && is_array($search)) {
751 foreach ($search as $key => $val) {
752 if (is_array($search[$key]) && count($search[$key])) {
753 foreach ($search[$key] as $skey) {
754 if ($skey != '') {
755 $param .= '&search_'.$key.'[]='.urlencode($skey);
756 }
757 }
758 } elseif ($search[$key] != '') {
759 $param .= '&search_'.$key.'='.urlencode($search[$key]);
760 }
761 }
762}
763if ($optioncss != '') {
764 $param .= '&optioncss='.urlencode($optioncss);
765}
766// Add $param from extra fields
767include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
768// Add $param from hooks
769$parameters = array();
770$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
771$param .= $hookmanager->resPrint;
772
773
774$titlepicto = 'title_setup';
775
776
777$url = DOL_URL_ROOT.'/admin/mails_templates.php?action=create';
778$newcardbutton = '';
779$newcardbutton .= dolGetButtonTitle($langs->trans('NewEMailTemplate'), '', 'fa fa-plus-circle', $url, '', (int) $permissiontoadd);
780
781
782$param = '';
783if ($search_label) {
784 $param .= '&search_label='.urlencode($search_label);
785}
786if (!empty($search_lang) && $search_lang != '-1') {
787 $param .= '&search_lang='.urlencode($search_lang);
788}
789if ($search_type_template != '-1') {
790 $param .= '&search_type_template='.urlencode($search_type_template);
791}
792if ($search_fk_user > 0) {
793 $param .= '&search_fk_user='.urlencode($search_fk_user);
794}
795if ($search_module) {
796 $param .= '&search_module='.urlencode($search_module);
797}
798if ($search_topic) {
799 $param .= '&search_topic='.urlencode($search_topic);
800}
801
802$paramwithsearch = $param;
803if ($sortorder) {
804 $paramwithsearch .= '&sortorder='.urlencode($sortorder);
805}
806if ($sortfield) {
807 $paramwithsearch .= '&sortfield='.urlencode($sortfield);
808}
809if ($limit) {
810 $paramwithsearch .= '&limit='.((int) $limit);
811}
812if (GETPOST('from', 'alpha')) {
813 $paramwithsearch .= '&from='.urlencode(GETPOST('from', 'alpha'));
814}
815
816$massactionbutton = '';
817
818
819// List of available record in database
820dol_syslog("htdocs/admin/mails_templates.php", LOG_DEBUG);
821
822$resql = $db->query($sql);
823if (!$resql) {
825 exit;
826}
827
828$nbtotalofrecords = $db->num_rows($resql);
829
830$sql .= $db->plimit($limit + 1, $offset);
831
832$resql = $db->query($sql);
833if (!$resql) {
835 exit;
836}
837
838$num = $db->num_rows($resql);
839
840if ($action != 'create') {
841 print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST" id="list_of_c_email_templates" spellcheck="false">';
842 print '<input type="hidden" name="token" value="'.newToken().'">';
843 print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
844}
845
846if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
847 print load_fiche_titre($title, '', $titlepicto);
848} else {
849 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'tools', 0, $newcardbutton, '', $limit, 'limit', 0, 1);
850}
851
852if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
853 $head = email_admin_prepare_head();
854
855 print dol_get_fiche_head($head, 'templates', '', -1);
856
857 if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
858 print load_fiche_titre('', $newcardbutton, '');
859 }
860}
861
862
863// Confirm deletion of record
864if ($action == 'delete') {
865 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);
866}
867
868
869$fieldlist = explode(',', $tabfield[25]);
870
871if ($action == 'create') {
872 // If data was already input, we define them in obj to populate input fields.
873 $obj = new stdClass();
874 $obj->label = GETPOST('label');
875 $obj->lang = GETPOST('lang');
876 $obj->type_template = GETPOST('type_template');
877 $obj->fk_user = GETPOSTINT('fk_user');
878 $obj->private = GETPOSTINT('private');
879 $obj->position = GETPOST('position');
880 $obj->topic = GETPOST('topic');
881 $obj->joinfiles = GETPOST('joinfiles');
882 $obj->defaultfortype = GETPOST('defaultfortype') ? 1 : 0;
883 $obj->content = GETPOST('content', 'restricthtml');
884
885 // Form to add a new line
886 print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST" id="create_c_email_template" spellcheck="false">';
887 print '<input type="hidden" name="token" value="'.newToken().'">';
888 print '<input type="hidden" name="action" value="add">';
889 print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
890 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
891
892 print '<div class="div-table-responsive-no-min">';
893 print '<table class="noborder centpercent" id="table_create_c_email_template">';
894
895 // Line to enter new values (title)
896 print '<tr class="liste_titre">';
897 foreach ($fieldlist as $field => $value) {
898 // Determine the field name based on the possible names
899 // in the data dictionaries.
900 $valuetoshow = ucfirst($fieldlist[$field]); // Par default
901 $valuetoshow = $langs->trans($valuetoshow); // try to translate
902 $css = "left";
903 if ($fieldlist[$field] == 'module') {
904 $valuetoshow = '&nbsp;';
905 }
906 if ($fieldlist[$field] == 'fk_user') {
907 $valuetoshow = $langs->trans("Owner");
908 }
909 if ($fieldlist[$field] == 'lang') {
910 $valuetoshow = (!getDolGlobalInt('MAIN_MULTILANGS') ? '&nbsp;' : $langs->trans("Language"));
911 }
912 if ($fieldlist[$field] == 'type') {
913 $valuetoshow = $langs->trans("Type");
914 }
915 if ($fieldlist[$field] == 'position') {
916 $css = 'center';
917 }
918 if ($fieldlist[$field] == 'code') {
919 $valuetoshow = $langs->trans("Code");
920 }
921 if ($fieldlist[$field] == 'label') {
922 $valuetoshow = $langs->trans("Label");
923 }
924 if ($fieldlist[$field] == 'type_template') {
925 $valuetoshow = $langs->trans("TypeOfTemplate");
926 $css = "center";
927 }
928 if (in_array($fieldlist[$field], array('private', 'private', 'defaultfortype'))) {
929 $css = 'center';
930 }
931
932 if ($fieldlist[$field] == 'topic') {
933 $valuetoshow = '';
934 }
935 if ($fieldlist[$field] == 'joinfiles') {
936 $valuetoshow = '';
937 }
938 if ($fieldlist[$field] == 'content') {
939 $valuetoshow = '';
940 }
941 if ($fieldlist[$field] == 'content_lines') {
942 $valuetoshow = '';
943 }
944 if ($valuetoshow != '') {
945 print '<th class="'.$css.'">';
946 if (!empty($tabhelp[25][$value]) && preg_match('/^http(s*):/i', $tabhelp[25][$value])) {
947 print '<a href="'.$tabhelp[25][$value].'" target="_blank" rel="noopener noreferrer">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
948 } elseif (!empty($tabhelp[25][$value])) {
949 if (in_array($value, array('topic'))) {
950 print $form->textwithpicto($valuetoshow, $tabhelp[25][$value], 1, 'help', '', 0, 2, $value); // Tooltip on click
951 } else {
952 print $form->textwithpicto($valuetoshow, $tabhelp[25][$value], 1, 'help', '', 0, 2); // Tooltip on hover
953 }
954 } else {
955 print $valuetoshow;
956 }
957 print '</th>';
958 }
959 }
960 print '<th>';
961 print '</th>';
962 print '</tr>';
963
964 $tmpaction = 'create';
965 $parameters = array(
966 'fieldlist' => $fieldlist,
967 'tabname' => $tabname[25]
968 );
969 $reshook = $hookmanager->executeHooks('createEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
970 $error = $hookmanager->error;
971 $errors = $hookmanager->errors;
972
973
974 // Line to enter new values (input fields)
975 print '<tr class="oddeven">';
976
977 if (empty($reshook)) {
978 if ($action == 'edit') {
979 fieldList($fieldlist, $obj, $tabname[25], 'hide');
980 } else {
981 fieldList($fieldlist, $obj, $tabname[25], 'add');
982 }
983 }
984 // Action column
985 print '<td class="right">';
986 print '</td>';
987 print "</tr>";
988
989 print '<tr class="oddeven nodrag nodrop nohover"><td colspan="9" style="padding-left: 20px; padding-right: 20px;">';
990
991 // Show fields for topic, join files and body
992 $fieldsforcontent = array('topic', 'email_from', 'joinfiles', 'content');
993 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TO')) {
994 $fieldsforcontent[] = 'email_to';
995 }
996 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOCC')) {
997 $fieldsforcontent[] = 'email_tocc';
998 }
999 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOBCC')) {
1000 $fieldsforcontent[] = 'email_tobcc';
1001 }
1002 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
1003 $fieldsforcontent[] = 'content_lines';
1004 }
1005 foreach ($fieldsforcontent as $tmpfieldlist) {
1006 print '<div class="inline-block lineformailtemplatefield paddingtop paddingbottom centpercent">';
1007 // Topic of email
1008 if ($tmpfieldlist == 'topic') {
1009 print '<span class="bold minwidth150 inline-block">'.$form->textwithpicto($langs->trans("Topic"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</span>';
1010 }
1011 if ($tmpfieldlist == 'email_from') {
1012 print '<span class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("MailFrom"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</span>';
1013 }
1014 if ($tmpfieldlist == 'email_to') {
1015 print '<span class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("MailTo"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</span>';
1016 }
1017 if ($tmpfieldlist == 'email_tocc') {
1018 print '<span class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("MailCC"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</span>';
1019 }
1020 if ($tmpfieldlist == 'email_tobcc') {
1021 print '<span class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("MailCCC"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</span>';
1022 }
1023 if ($tmpfieldlist == 'joinfiles') {
1024 print '<span class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</span>';
1025 }
1026 if ($tmpfieldlist == 'content') {
1027 print '<span class="minwidth150 inline-block margintoponly">'.$form->textwithpicto($langs->trans("Content"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</span><br>';
1028 }
1029 if ($tmpfieldlist == 'content_lines') {
1030 print '<span class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</span><br>';
1031 }
1032
1033 // Input field
1034 if ($tmpfieldlist == 'topic') {
1035 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '').'">';
1036 } elseif ($tmpfieldlist == 'email_from') {
1037 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '').'" spellcheck="false">';
1038 } elseif ($tmpfieldlist == 'email_to') {
1039 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '').'" spellcheck="false">';
1040 } elseif ($tmpfieldlist == 'email_tocc') {
1041 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '').'" spellcheck="false">';
1042 } elseif ($tmpfieldlist == 'email_tobcc') {
1043 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '').'" spellcheck="false">';
1044 } elseif ($tmpfieldlist == 'joinfiles') {
1045 print $form->selectyesno($tmpfieldlist, (isset($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '0'), 1, false, 0, 1);
1046 } else {
1047 $okforextended = true;
1048 if (!getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) {
1049 $okforextended = false;
1050 }
1051 $doleditor = new DolEditor($tmpfieldlist, (!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : ''), '', 400, 'dolibarr_mailings', 'In', false, $acceptlocallinktomedia, $okforextended, ROWS_6, '90%');
1052 print $doleditor->Create(1);
1053 }
1054 print '</div>';
1055 print '<br>';
1056 }
1057
1058 print '</tr>';
1059
1060 print '</table>';
1061
1062 if ($action != 'edit') {
1063 print '<center>';
1064 print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'"> ';
1065 print '<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
1066 print '</center>';
1067 }
1068
1069 print '</div>';
1070 print '</form>';
1071
1072 print '<br><br><br>';
1073}
1074
1075
1076print '<div class="div-table-responsive-no-min">';
1077print '<table class="noborder centpercent" id="table_list_of_c_email_templates">';
1078
1079$i = 0;
1080
1081// There is several pages
1082/*
1083if ($num > $limit) {
1084 print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).'">';
1085 print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $limit ? 1 : 0), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
1086 print '</td></tr>';
1087}
1088*/
1089
1090// Title line with search boxes
1091print '<tr class="liste_titre" id="Title line with search boxes">';
1092// Action column
1093if ($conf->main_checkbox_left_column) {
1094 print '<td class="liste_titre center" width="64">';
1095 $searchpicto = $form->showFilterButtons();
1096 print $searchpicto;
1097 print '</td>';
1098}
1099foreach ($fieldlist as $field => $value) {
1100 if ($value == 'module') {
1101 print '<td class="liste_titre"><input type="text" name="search_module" class="maxwidth75" value="'.dol_escape_htmltag($search_module).'" spellcheck="false"></td>';
1102 } elseif ($value == 'label') {
1103 print '<td class="liste_titre"><input type="text" name="search_label" class="maxwidth75" value="'.dol_escape_htmltag($search_label).'" spellcheck="false"></td>';
1104 } elseif ($value == 'lang') {
1105 print '<td class="liste_titre">';
1106 print $formadmin->select_language($search_lang, 'search_lang', 0, array(), 1, 0, 0, 'maxwidth100');
1107 print '</td>';
1108 } elseif ($value == 'fk_user') {
1109 print '<td class="liste_titre">';
1110 print $form->select_dolusers($search_fk_user, 'search_fk_user', 1, null, 0, ($user->admin ? '' : 'hierarchyme'), array(), '0', 0, 0, '', 0, '', 'maxwidth100', 1);
1111 print '</td>';
1112 } elseif ($value == 'topic') {
1113 print '<td class="liste_titre"><input type="text" class="maxwidth150" name="search_topic" value="'.dol_escape_htmltag($search_topic).'" spellcheck="false"></td>';
1114 } elseif ($value == 'type_template') {
1115 print '<td class="liste_titre center">';
1116 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1117 print $form->selectarray('search_type_template', $elementList, $search_type_template, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100 maxwidth125', 1, '', 0, 1);
1118 print '</td>';
1119 } elseif (!in_array($value, array('content', 'content_lines'))) {
1120 print '<td class="liste_titre"></td>';
1121 }
1122}
1123/*if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
1124 print '<td class="liste_titre"></td>';
1125}*/
1126// Status
1127print '<td></td>';
1128
1129// 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
1130if (!empty($arrayfields['t.tms']['checked'])) {
1131 print '<td></td>'; // tms / Modif. date
1132}
1133if (!empty($arrayfields['t.datec']['checked'])) {
1134 print '<td></td>'; // datec / Date creation
1135}
1136// Action column
1137if (!$conf->main_checkbox_left_column) {
1138 print '<td class="liste_titre center" width="64">';
1139 $searchpicto = $form->showFilterButtons();
1140 print $searchpicto;
1141 print '</td>';
1142}
1143print '</tr>';
1144
1145// Title of lines
1146print '<tr class="liste_titre" id="Title of lines">';
1147// Action column
1148if ($conf->main_checkbox_left_column) {
1149 print getTitleFieldOfList('');
1150}
1151array_push($fieldlist, "tms", "datec");
1152foreach ($fieldlist as $field => $value) {
1153 $showfield = 1; // By default
1154 $css = "left";
1155 $sortable = 1;
1156 $valuetoshow = '';
1157 $forcenowrap = 1;
1158 /*
1159 $tmparray=getLabelOfField($fieldlist[$field]);
1160 $showfield=$tmp['showfield'];
1161 $valuetoshow=$tmp['valuetoshow'];
1162 $css=$tmp['align'];
1163 $sortable=$tmp['sortable'];
1164 */
1165 $valuetoshow = ucfirst($fieldlist[$field]); // By default
1166 $valuetoshow = $langs->trans($valuetoshow); // try to translate
1167 if ($fieldlist[$field] == 'module') {
1168 $css = 'tdoverflowmax100';
1169 }
1170 if ($fieldlist[$field] == 'fk_user') {
1171 $valuetoshow = $langs->trans("Owner");
1172 }
1173 if ($fieldlist[$field] == 'lang') {
1174 $valuetoshow = $langs->trans("Language");
1175 }
1176 if ($fieldlist[$field] == 'type') {
1177 $valuetoshow = $langs->trans("Type");
1178 }
1179 if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
1180 $valuetoshow = $langs->trans("Label");
1181 }
1182 if ($fieldlist[$field] == 'type_template') {
1183 $css = 'center';
1184 $valuetoshow = $langs->trans("TypeOfTemplate");
1185 }
1186 if ($fieldlist[$field] == 'private') {
1187 $css = 'center';
1188 }
1189 if ($fieldlist[$field] == 'position') {
1190 $css = 'center';
1191 }
1192 if ($fieldlist[$field] == 'tms') {
1193 $valuetoshow = 'Modif. date';
1194 }
1195 if ($fieldlist[$field] == 'datec') {
1196 $valuetoshow = 'Date creation';
1197 }
1198
1199 if ($fieldlist[$field] == 'joinfiles') {
1200 $valuetoshow = $langs->trans("FilesAttachedToEmail");
1201 $css = 'center';
1202 $forcenowrap = 0;
1203 }
1204 if ($fieldlist[$field] == 'content') {
1205 $valuetoshow = $langs->trans("Content");
1206 $showfield = 0;
1207 }
1208 if ($fieldlist[$field] == 'content_lines') {
1209 $valuetoshow = $langs->trans("ContentForLines");
1210 $showfield = 0;
1211 }
1212 if ($value == 'tms' && empty($arrayfields['t'.$value]['checked'])) {
1213 $showfield = 0;
1214 }
1215 if ($value == 'datec' && empty($arrayfields['t.'.$value]['checked'])) {
1216 $showfield = 0;
1217 }
1218
1219 // Show fields
1220 if ($showfield) {
1221 if (!empty($tabhelp[25][$value])) {
1222 if (in_array($value, array('topic'))) {
1223 $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[25][$value], 1, 'help', '', 0, 2, 'tooltip'.$value, $forcenowrap); // Tooltip on click
1224 } else {
1225 $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[25][$value], 1, 'help', '', 0, 2, '', $forcenowrap); // Tooltip on hover
1226 }
1227 }
1228 $sortfieldtouse = ($sortable ? $fieldlist[$field] : '');
1229 if ($sortfieldtouse == 'type_template') {
1230 $sortfieldtouse .= ',lang,position,label';
1231 }
1232 print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], $sortfieldtouse, ($page ? 'page='.$page.'&' : ''), $paramwithsearch, '', $sortfield, $sortorder, $css.' ');
1233 }
1234}
1235
1236print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $paramwithsearch, '', $sortfield, $sortorder, 'center ');
1237// Action column
1238if (!$conf->main_checkbox_left_column) {
1239 print getTitleFieldOfList('');
1240}
1241print '</tr>';
1242
1243$nbqualified = 0;
1244if ($num) {
1245 // Lines with values
1246 while ($i < $num) {
1247 $obj = $db->fetch_object($resql);
1248
1249 if ($obj) {
1250 if (($action == 'edit' || $action == 'preview') && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
1251 // TODO Move this 2 lines into a popup
1252 print '<tr class="nohover oddeven noborderbottom" id="rowid-'.$obj->rowid.'" name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'">';
1253
1254 $tmpaction = 'edit';
1255 if ($action == 'edit') {
1256 // do not show tms and datec
1257 $fieldlist = explode(',', $tabfield[25]);
1258 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[25]);
1259 } else {
1260 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[25]);
1261 }
1262 $reshook = $hookmanager->executeHooks('editEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1263 $error = $hookmanager->error;
1264 $errors = $hookmanager->errors;
1265
1266 $colspan = 0;
1267
1268 // Action column
1269 if ($conf->main_checkbox_left_column) {
1270 print '<td class="center">';
1271 print '</td>';
1272 $colspan++;
1273 }
1274 // Show main fields
1275 if (empty($reshook)) {
1276 $colspan += fieldList($fieldlist, $obj, $tabname[25], $action);
1277 }
1278 // Action column
1279 if (!$conf->main_checkbox_left_column) {
1280 print '<td class="center">';
1281 print '</td>';
1282 $colspan++;
1283 }
1284 print "</tr>\n";
1285
1286 print '<tr class="oddeven nohover" id="tr-aaa-'.$rowid.'">';
1287 if ($conf->main_checkbox_left_column) {
1288 print '<td class="center"></td>';
1289 }
1290 print '<td colspan="'.($colspan - 1).'" class="" style="padding-left: 20px; padding-right: 20px;">';
1291
1292 $fieldsforcontent = array('topic', 'email_from', 'joinfiles', 'content');
1293 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TO')) {
1294 $fieldsforcontent[] = 'email_to';
1295 }
1296 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOCC')) {
1297 $fieldsforcontent[] = 'email_tocc';
1298 }
1299 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_USE_TOBCC')) {
1300 $fieldsforcontent[] = 'email_tobcc';
1301 }
1302 if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
1303 $fieldsforcontent[] = 'content_lines';
1304 }
1305
1306 $parameters = array('fieldsforcontent' => &$fieldsforcontent, 'tabname' => $tabname[25]);
1307 $hookmanager->executeHooks('editEmailTemplateFieldsForContent', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1308
1309 print '<div class="lineformailtemplatefield centpercent">';
1310 foreach ($fieldsforcontent as $tmpfieldlist) {
1311 $showfield = 1;
1312 $css = "left";
1313 $valuetoshow = $obj->$tmpfieldlist;
1314
1315 $class = 'tddict';
1316 // Show value for field
1317 if ($showfield) {
1318 print '<div class="inline-block lineformailtemplatefield paddingtop paddingbottom centpercent">';
1319 // Show line for topic, joinfiles and content
1320 if ($tmpfieldlist == 'topic') {
1321 print '<div class="minwidth150 inline-block bold">'.$form->textwithpicto($langs->trans("Topic"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</div> ';
1322 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'"'.($action != 'edit' ? ' disabled' : '').'>';
1323 print '<br>'."\n";
1324 }
1325 if ($tmpfieldlist == 'email_from') {
1326 print '<div class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("MailFrom"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</div> ';
1327 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'"'.($action != 'edit' ? ' disabled' : '').' spellcheck="false">';
1328 print '<br>'."\n";
1329 }
1330 if ($tmpfieldlist == 'email_to') {
1331 print '<div class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("MailTo"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</div> ';
1332 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'"'.($action != 'edit' ? ' disabled' : '').' spellcheck="false">';
1333 print '<br>'."\n";
1334 }
1335 if ($tmpfieldlist == 'email_tocc') {
1336 print '<div class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("MailCC"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</div> ';
1337 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'"'.($action != 'edit' ? ' disabled' : '').' spellcheck="false">';
1338 print '<br>'."\n";
1339 }
1340 if ($tmpfieldlist == 'email_tobcc') {
1341 print '<div class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("MailCCC"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</div> ';
1342 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'"'.($action != 'edit' ? ' disabled' : '').' spellcheck="false">';
1343 print '<br>'."\n";
1344 }
1345 if ($tmpfieldlist == 'joinfiles') {
1346 print '<div class="minwidth150 inline-block">'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[25][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</div> ';
1347 print $form->selectyesno($tmpfieldlist.'-'.$rowid, (isset($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '0'), 1, ($action != 'edit'), 0, 1);
1348 print '<br>'."\n";
1349 }
1350
1351 if ($tmpfieldlist == 'content') {
1352 print $form->textwithpicto($langs->trans("Content"), $tabhelp[25][$tmpfieldlist], 1, 'help', 'margintoponly', 0, 2, $tmpfieldlist).'<br>';
1353 $okforextended = true;
1354 if (!getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) {
1355 $okforextended = false;
1356 }
1357 $doleditor = new DolEditor($tmpfieldlist.'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 450, 'dolibarr_mailings', 'In', false, $acceptlocallinktomedia, $okforextended, ROWS_6, '80%', ($action != 'edit' ? 1 : 0));
1358 print $doleditor->Create(1);
1359 }
1360 if ($tmpfieldlist == 'content_lines') {
1361 print '<br>'."\n";
1362 print $form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[25][$tmpfieldlist], 1, 'help', 'margintoponly', 0, 2, $tmpfieldlist).'<br>';
1363 $okforextended = true;
1364 if (!getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) {
1365 $okforextended = false;
1366 }
1367 $doleditor = new DolEditor($tmpfieldlist.'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 140, 'dolibarr_mailings', 'In', false, $acceptlocallinktomedia, $okforextended, ROWS_6, '80%');
1368 print $doleditor->Create(1);
1369 }
1370 print '</div>';
1371 }
1372 }
1373 print '</div>';
1374 print '<center><input type="hidden" name="page" value="'.$page.'">';
1375 print '<input type="hidden" name="rowid" value="'.$rowid.'">';
1376 if ($action == 'edit') {
1377 print '<input type="submit" class="button buttongen button-save" name="actionmodify" value="'.$langs->trans("Save").'">';
1378 }
1379 print '<input type="submit" class="button buttongen button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
1380 print '</center>';
1381 print '</td>';
1382
1383 if (!$conf->main_checkbox_left_column) {
1384 print '<td class="center"></td>';
1385 }
1386
1387 print '</tr>';
1388
1389 $nbqualified++;
1390 } else {
1391 // If template is for a module, check module is enabled.
1392 if ($obj->module) {
1393 $tempmodulekey = $obj->module;
1394 if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1395 $i++;
1396 continue;
1397 }
1398 }
1399
1400 $keyforobj = 'type_template';
1401 if (!in_array($obj->$keyforobj, array_keys($elementList))) {
1402 $i++;
1403 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)
1404 }
1405 // Test on 'enabled'
1406 if (! (int) dol_eval((string) $obj->enabled, 1, 1, '1')) {
1407 $i++;
1408 continue; // Email template not qualified
1409 }
1410
1411 $nbqualified++;
1412
1413 // Can an entry be erased or disabled ?
1414 $iserasable = 1;
1415 $canbedisabled = 1;
1416 $canbemodified = 1; // true by default
1417 if (!$user->admin && $obj->fk_user != $user->id) {
1418 $iserasable = 0;
1419 $canbedisabled = 0;
1420 $canbemodified = 0;
1421 }
1422
1423 $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) : '');
1424 if ($param) {
1425 $url .= '&'.$param;
1426 }
1427
1428 print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
1429
1430 // Action column - Modify link / Delete link
1431 if ($conf->main_checkbox_left_column) {
1432 print '<td class="center nowraponall" width="64">';
1433 if ($canbemodified) {
1434 print '<a class="reposition editfielda" href="'.$url.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
1435 } else {
1436 print '<a class="reposition editfielda" href="'.$url.'&action=preview&token='.newToken().'">'.img_view().'</a>';
1437 }
1438 if ($iserasable) {
1439 print '<a class="reposition marginleftonly" href="'.$url.'&action=delete&token='.newToken().$param.'">'.img_delete().'</a>';
1440 }
1441 print '</td>';
1442 }
1443
1444 $tmpaction = 'view';
1445 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[25]);
1446 $reshook = $hookmanager->executeHooks('viewEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1447
1448 $error = $hookmanager->error;
1449 $errors = $hookmanager->errors;
1450
1451 if (empty($reshook)) {
1452 foreach ($fieldlist as $field => $value) {
1453 if (in_array($fieldlist[$field], array('content', 'content_lines'))) {
1454 continue;
1455 }
1456 $showfield = 1;
1457 $css = "";
1458 $class = "tddict";
1459 $title = '';
1460 $tmpvar = $fieldlist[$field];
1461 $valuetoshow = $obj->$tmpvar;
1462 if ($value == 'label' || $value == 'topic') {
1463 if ($langs->trans($valuetoshow) != $valuetoshow) {
1464 $valuetoshow = $langs->trans($valuetoshow);
1465 }
1466 $valuetoshow = dol_escape_htmltag($valuetoshow);
1467 }
1468 if ($value == 'label') {
1469 $class .= ' tdoverflowmax200';
1470 }
1471 if ($value == 'topic') {
1472 $class .= ' tdoverflowmax200 small';
1473 }
1474 if ($value == 'type_template') {
1475 $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
1476 $css = "center tdoverflowmax150";
1477 }
1478 if ($value == 'lang' && $valuetoshow) {
1479 $valuetoshow = $valuetoshow.' - '.$langs->trans("Language_".$valuetoshow);
1480 $class .= ' tdoverflowmax100';
1481 }
1482 if ($value == 'fk_user') {
1483 if ($valuetoshow > 0) {
1484 $fuser = new User($db);
1485 $fuser->fetch($valuetoshow);
1486 $valuetoshow = $fuser->getNomUrl(-1);
1487
1488 if ($obj->private) {
1489 $valuetoshow = img_picto($langs->transnoentitiesnoconv("Private"), 'lock', 'class="pictofixedwidth"').$valuetoshow;
1490 }
1491
1492 $class .= ' tdoverflowmax100';
1493 }
1494 }
1495 if ($value == 'private') {
1496 $css = "center";
1497 if ($valuetoshow) {
1498 $valuetoshow = yn($valuetoshow);
1499 } else {
1500 $valuetoshow = '';
1501 }
1502 }
1503 if ($value == 'position') {
1504 $css = "center";
1505 }
1506 if (in_array($value, array('joinfiles', 'defaultfortype'))) {
1507 $css = "center";
1508 if ($valuetoshow) {
1509 //$valuetoshow = yn(1);
1510 $valuetoshow = '<input type="checkbox" checked="checked" disabled>';
1511 } else {
1512 $valuetoshow = '';
1513 }
1514 }
1515 if ($css) {
1516 $class .= ' '.$css;
1517 }
1518
1519 if ($value == 'tms' && empty($arrayfields['t'.$value]['checked'])) {
1520 $showfield = 0;
1521 }
1522 if ($value == 'datec' && empty($arrayfields['t.'.$value]['checked'])) {
1523 $showfield = 0;
1524 }
1525
1526 // Show value for field
1527 if ($showfield) {
1528 print '<!-- '.$fieldlist[$field].' -->';
1529 print '<td class="'.$class.'"';
1530 if (in_array($value, array('code', 'label', 'topic'))) {
1531 print ' title="'.dol_escape_htmltag($valuetoshow).'"';
1532 }
1533 print '>';
1534 print $valuetoshow;
1535 print '</td>';
1536 }
1537 }
1538 }
1539
1540 // Status / Active
1541 print '<td class="center nowrap">';
1542 if ($canbedisabled) {
1543 print '<a class="reposition" href="'.$url.'&action='.$acts[$obj->active].'&token='.newToken().'">'.$actl[$obj->active].'</a>';
1544 } else {
1545 print '<span class="opacitymedium">'.$actl[$obj->active].'</span>';
1546 }
1547 print "</td>";
1548
1549 // Action column - Modify link / Delete link
1550 if (!$conf->main_checkbox_left_column) {
1551 print '<td class="center nowraponall" width="64">';
1552 if ($canbemodified) {
1553 print '<a class="reposition editfielda" href="'.$url.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
1554 }
1555 if ($iserasable) {
1556 print '<a class="reposition marginleftonly" href="'.$url.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
1557 //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
1558 }
1559 print '</td>';
1560 }
1561
1562 print "</tr>\n";
1563 }
1564 }
1565
1566 $i++;
1567 }
1568}
1569
1570// If no record found
1571if ($nbqualified == 0) {
1572 $colspan = 12;
1573 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1574}
1575
1576print '</table>';
1577print '</div>';
1578
1579if ($action != 'create') {
1580 print '</form>';
1581}
1582
1583if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
1584 print dol_get_fiche_end();
1585}
1586
1587
1588// End of page
1589llxFooter();
1590$db->close();
1591
1592
1602function fieldList($fieldlist, $obj = null, $tabname = '', $context = '')
1603{
1604 global $langs, $user, $db;
1605 global $form;
1606 global $elementList;
1607
1608 $formadmin = new FormAdmin($db);
1609 $nboffieldsprinted = 0;
1610
1611 foreach ($fieldlist as $value) {
1612 //print $value;
1613 if ($value == 'module') {
1614 print '<td></td>';
1615 $nboffieldsprinted++;
1616 } elseif ($value == 'fk_user') {
1617 print '<td>';
1618 if ($user->admin && $context != 'preview') {
1619 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');
1620 } else {
1621 if ($context == 'add') { // I am not admin and we show the add form
1622 print $user->getNomUrl(-1); // Me
1623 $forcedvalue = $user->id;
1624 } else {
1625 if ($obj && !empty($obj->$value) && $obj->$value > 0) {
1626 $fuser = new User($db);
1627 $fuser->fetch($obj->$value);
1628 print $fuser->getNomUrl(-1);
1629 $forcedvalue = $fuser->id;
1630 } else {
1631 $forcedvalue = $obj->$value;
1632 }
1633 }
1634 $keyname = $value;
1635 print '<input type="hidden" value="'.$forcedvalue.'" name="'.$keyname.'">';
1636 }
1637 print '</td>';
1638 $nboffieldsprinted++;
1639 } elseif ($value == 'lang') {
1640 print '<td>';
1641 if (getDolGlobalInt('MAIN_MULTILANGS') && $context != 'preview') {
1642 $selectedlang = GETPOSTISSET('langcode') ? GETPOST('langcode', 'aZ09') : $langs->defaultlang;
1643 if ($context == 'edit') {
1644 $selectedlang = $obj->lang;
1645 }
1646 print $formadmin->select_language($selectedlang, 'langcode', 0, array(), $langs->trans("Language"), 0, 0, 'maxwidth100');
1647 } else {
1648 if (!empty($obj->lang)) {
1649 print $obj->lang.' - '.$langs->trans('Language_'.$obj->lang);
1650 }
1651 $keyname = $value;
1652 if ($keyname == 'lang') {
1653 $keyname = 'langcode'; // Avoid conflict with lang param
1654 }
1655 print '<input type="hidden" value="'.(empty($obj->lang) ? '' : $obj->lang).'" name="'.$keyname.'">';
1656 }
1657 print '</td>';
1658 $nboffieldsprinted++;
1659 } elseif ($value == 'type_template') {
1660 // Le type de template
1661 print '<td class="center">';
1662 if (($context == 'edit' && !empty($obj->type_template) && !in_array($obj->type_template, array_keys($elementList))) || $context == 'preview') {
1663 // Current template type is an unknown type, so we must keep it as it is.
1664 print '<input type="hidden" name="type_template" value="'.$obj->type_template.'">';
1665 print $obj->type_template;
1666 } else {
1667 print $form->selectarray('type_template', $elementList, (!empty($obj->type_template) ? $obj->type_template : ''), 1, 0, 0, '', 0, 0, 0, '', 'minwidth75 maxwidth125', 1, '', 0, 1);
1668 }
1669 print '</td>';
1670 $nboffieldsprinted++;
1671 } elseif ($context == 'add' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1672 //print '<td></td>';
1673 } elseif ($context == 'edit' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1674 print '<td></td>';
1675 $nboffieldsprinted++;
1676 } elseif ($context == 'preview' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1677 print '<td></td>';
1678 $nboffieldsprinted++;
1679 } elseif ($context == 'hide' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1680 //print '<td></td>';
1681 } else {
1682 $size = '';
1683 $class = '';
1684 $classtd = '';
1685 if ($value == 'code') {
1686 $class = 'maxwidth100';
1687 }
1688 if ($value == 'label') {
1689 $class = 'maxwidth200';
1690 }
1691 if ($value == 'private') {
1692 $class = 'maxwidth50';
1693 $classtd = 'center';
1694 }
1695 if ($value == 'position') {
1696 $class = 'maxwidth50 center';
1697 $classtd = 'center';
1698 }
1699 if ($value == 'topic') {
1700 $class = 'quatrevingtpercent';
1701 }
1702 if ($value == 'defaultfortype') {
1703 $class = 'width25 center';
1704 $classtd = 'center';
1705 }
1706
1707 print '<td'.($classtd ? ' class="'.$classtd.'"' : '').'>';
1708 if (in_array($value, array('defaultfortype', 'private')) && $context != 'preview') {
1709 if (empty($user->admin)) {
1710 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1711 print $form->selectyesno($value, GETPOSTISSET($value) ? GETPOSTINT($value) : (($context != 'add' && isset($obj->$value)) ? $obj->$value : '1'), 1, false, 0, 1);
1712 } else {
1713 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1714 print $form->selectyesno($value, (isset($obj->$value) ? $obj->$value : ''), 1, false, 0, 1);
1715 }
1716 } else {
1717 print '<input type="text" '.$size.'class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->$value) ? $obj->$value : '').'" name="'. $value .'"'.($context == 'preview' ? ' disabled' : '').' spellcheck="false">';
1718 }
1719 print '</td>';
1720 $nboffieldsprinted++;
1721 }
1722 }
1723
1724 return $nboffieldsprinted;
1725}
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.
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:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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:519
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:717
img_view($titlealt='default', $float=0, $other='class="valignmiddle"')
Show logo view card.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
Definition html.lib.php:172
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
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.