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