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