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