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