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