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