dolibarr 19.0.4
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
1107 $parameters = array('fieldsforcontent' => &$fieldsforcontent, 'tabname' => $tabname[$id]);
1108 $hookmanager->executeHooks('editEmailTemplateFieldsForContent', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1109
1110 foreach ($fieldsforcontent as $tmpfieldlist) {
1111 $showfield = 1;
1112 $css = "left";
1113 $valuetoshow = $obj->$tmpfieldlist;
1114
1115 $class = 'tddict';
1116 // Show value for field
1117 if ($showfield) {
1118 // Show line for topic, joinfiles and content
1119 if ($tmpfieldlist == 'topic') {
1120 print '<strong>'.$form->textwithpicto($langs->trans("Topic"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
1121 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'">';
1122 print '<br>'."\n";
1123 }
1124 if ($tmpfieldlist == 'email_from') {
1125 print '<strong>'.$form->textwithpicto($langs->trans("MailFrom"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
1126 print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'">';
1127 print '<br>'."\n";
1128 }
1129 if ($tmpfieldlist == 'joinfiles') {
1130 print '<strong>'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
1131 print $form->selectyesno($tmpfieldlist.'-'.$rowid, (isset($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '0'), 1, false, 0, 1);
1132 print '<br>'."\n";
1133 }
1134
1135 if ($tmpfieldlist == 'content') {
1136 print $form->textwithpicto($langs->trans("Content"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
1137 $okforextended = true;
1138 if (!getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) {
1139 $okforextended = false;
1140 }
1141 $doleditor = new DolEditor($tmpfieldlist.'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 500, 'dolibarr_mailings', 'In', 0, $acceptlocallinktomedia, $okforextended, ROWS_6, '90%');
1142 print $doleditor->Create(1);
1143 }
1144 if ($tmpfieldlist == 'content_lines') {
1145 print '<br>'."\n";
1146 print $form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
1147 $okforextended = true;
1148 if (!getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) {
1149 $okforextended = false;
1150 }
1151 $doleditor = new DolEditor($tmpfieldlist.'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 140, 'dolibarr_mailings', 'In', 0, $acceptlocallinktomedia, $okforextended, ROWS_6, '90%');
1152 print $doleditor->Create(1);
1153 }
1154 }
1155 }
1156 print '</td>';
1157 print '<td></td>';
1158 print '<td></td>';
1159
1160 print "</tr>\n";
1161
1162 $nbqualified++;
1163 } else {
1164 // If template is for a module, check module is enabled.
1165 if ($obj->module) {
1166 $tempmodulekey = $obj->module;
1167 if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1168 $i++;
1169 continue;
1170 }
1171 }
1172
1173 $keyforobj = 'type_template';
1174 if (!in_array($obj->$keyforobj, array_keys($elementList))) {
1175 $i++;
1176 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)
1177 }
1178 // Test on 'enabled'
1179 if (!dol_eval($obj->enabled, 1, 1, '1')) {
1180 $i++;
1181 continue; // Email template not qualified
1182 }
1183
1184 $nbqualified++;
1185
1186 // Can an entry be erased or disabled ?
1187 $iserasable = 1;
1188 $canbedisabled = 1;
1189 $canbemodified = 1; // true by default
1190 if (!$user->admin && $obj->fk_user != $user->id) {
1191 $iserasable = 0;
1192 $canbedisabled = 0;
1193 $canbemodified = 0;
1194 }
1195
1196 $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) : '');
1197 if ($param) {
1198 $url .= '&'.$param;
1199 }
1200
1201 print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
1202
1203 // Action column - Modify link / Delete link
1204 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1205 print '<td class="center nowraponall" width="64">';
1206 if ($canbemodified) {
1207 print '<a class="reposition editfielda" href="'.$url.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
1208 }
1209 if ($iserasable) {
1210 print '<a class="reposition marginleftonly" href="'.$url.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
1211 //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
1212 }
1213 print '</td>';
1214 }
1215
1216 $tmpaction = 'view';
1217 $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
1218 $reshook = $hookmanager->executeHooks('viewEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1219
1220 $error = $hookmanager->error;
1221 $errors = $hookmanager->errors;
1222
1223 if (empty($reshook)) {
1224 foreach ($fieldlist as $field => $value) {
1225 if (in_array($fieldlist[$field], array('content', 'content_lines'))) {
1226 continue;
1227 }
1228 $showfield = 1;
1229 $css = "";
1230 $class = "tddict";
1231 $title = '';
1232 $tmpvar = $fieldlist[$field];
1233 $valuetoshow = $obj->$tmpvar;
1234 if ($value == 'label' || $value == 'topic') {
1235 if ($langs->trans($valuetoshow) != $valuetoshow) {
1236 $valuetoshow = $langs->trans($valuetoshow);
1237 }
1238 $valuetoshow = dol_escape_htmltag($valuetoshow);
1239 }
1240 if ($value == 'label') {
1241 $class .= ' tdoverflowmax200';
1242 }
1243 if ($value == 'topic') {
1244 $class .= ' tdoverflowmax200 small';
1245 }
1246 if ($value == 'type_template') {
1247 $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
1248 $css = "center tdoverflowmax150";
1249 }
1250 if ($value == 'lang' && $valuetoshow) {
1251 $valuetoshow = $valuetoshow.' - '.$langs->trans("Language_".$valuetoshow);
1252 $class .= ' tdoverflowmax100';
1253 }
1254 if ($value == 'fk_user') {
1255 if ($valuetoshow > 0) {
1256 $fuser = new User($db);
1257 $fuser->fetch($valuetoshow);
1258 $valuetoshow = $fuser->getNomUrl(1);
1259 $class .= ' tdoverflowmax100';
1260 }
1261 }
1262 if ($value == 'private') {
1263 $css = "center";
1264 if ($valuetoshow) {
1265 $valuetoshow = yn($valuetoshow);
1266 } else {
1267 $valuetoshow = '';
1268 }
1269 }
1270 if ($value == 'position') {
1271 $css = "center";
1272 }
1273 if (in_array($value, array('joinfiles', 'defaultfortype'))) {
1274 $css = "center";
1275 if ($valuetoshow) {
1276 //$valuetoshow = yn(1);
1277 $valuetoshow = '<input type="checkbox" checked="checked" disabled>';
1278 } else {
1279 $valuetoshow = '';
1280 }
1281 }
1282 if ($css) {
1283 $class .= ' '.$css;
1284 }
1285
1286 // Show value for field
1287 if ($showfield) {
1288 print '<!-- '.$fieldlist[$field].' -->';
1289 print '<td class="'.$class.'"';
1290 if (in_array($value, array('code', 'label', 'topic'))) {
1291 print ' title="'.dol_escape_htmltag($valuetoshow).'"';
1292 }
1293 print '>';
1294 print $valuetoshow;
1295 print '</td>';
1296 }
1297 }
1298 }
1299
1300 // Status / Active
1301 print '<td class="center nowrap">';
1302 if ($canbedisabled) {
1303 print '<a class="reposition" href="'.$url.'&action='.$acts[$obj->active].'&token='.newToken().'">'.$actl[$obj->active].'</a>';
1304 } else {
1305 print '<span class="opacitymedium">'.$actl[$obj->active].'</span>';
1306 }
1307 print "</td>";
1308
1309 // Action column - Modify link / Delete link
1310 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1311 print '<td class="center nowraponall" width="64">';
1312 if ($canbemodified) {
1313 print '<a class="reposition editfielda" href="'.$url.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
1314 }
1315 if ($iserasable) {
1316 print '<a class="reposition marginleftonly" href="'.$url.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
1317 //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
1318 }
1319 print '</td>';
1320 }
1321
1322 print "</tr>\n";
1323 }
1324 }
1325
1326 $i++;
1327 }
1328}
1329
1330// If no record found
1331if ($nbqualified == 0) {
1332 $colspan = 12;
1333 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1334}
1335
1336print '</table>';
1337print '</div>';
1338
1339print '</form>';
1340
1341
1342if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
1343 print dol_get_fiche_end();
1344}
1345
1346
1347// End of page
1348llxFooter();
1349$db->close();
1350
1351
1361function fieldList($fieldlist, $obj = null, $tabname = '', $context = '')
1362{
1363 global $langs, $user, $db;
1364 global $form;
1365 global $elementList;
1366
1367 $formadmin = new FormAdmin($db);
1368
1369 foreach ($fieldlist as $field => $value) {
1370 //print $value;
1371 if ($value == 'module') {
1372 print '<td></td>';
1373 } elseif ($value == 'fk_user') {
1374 print '<td>';
1375 if ($user->admin) {
1376 print $form->select_dolusers(empty($obj->$value) ? '' : $obj->$value, 'fk_user', 1, null, 0, ($user->admin ? '' : 'hierarchyme'), null, 0, 0, 0, '', 0, '', 'minwidth75 maxwidth100');
1377 } else {
1378 if ($context == 'add') { // I am not admin and we show the add form
1379 print $user->getNomUrl(1); // Me
1380 $forcedvalue = $user->id;
1381 } else {
1382 if ($obj && !empty($obj->$value) && $obj->$value > 0) {
1383 $fuser = new User($db);
1384 $fuser->fetch($obj->$value);
1385 print $fuser->getNomUrl(1);
1386 $forcedvalue = $fuser->id;
1387 } else {
1388 $forcedvalue = $obj->$value;
1389 }
1390 }
1391 $keyname = $value;
1392 print '<input type="hidden" value="'.$forcedvalue.'" name="'.$keyname.'">';
1393 }
1394 print '</td>';
1395 } elseif ($value == 'lang') {
1396 print '<td>';
1397 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1398 $selectedlang = GETPOSTISSET('langcode') ? GETPOST('langcode', 'aZ09') : $langs->defaultlang;
1399 if ($context == 'edit') {
1400 $selectedlang = $obj->lang;
1401 }
1402 print $formadmin->select_language($selectedlang, 'langcode', 0, null, 1, 0, 0, 'maxwidth100');
1403 } else {
1404 if (!empty($obj->lang)) {
1405 print $obj->lang.' - '.$langs->trans('Language_'.$obj->lang);
1406 }
1407 $keyname = $value;
1408 if ($keyname == 'lang') {
1409 $keyname = 'langcode'; // Avoid conflict with lang param
1410 }
1411 print '<input type="hidden" value="'.(empty($obj->lang) ? '' : $obj->lang).'" name="'.$keyname.'">';
1412 }
1413 print '</td>';
1414 } elseif ($value == 'type_template') {
1415 // Le type de template
1416 print '<td class="center">';
1417 if ($context == 'edit' && !empty($obj->type_template) && !in_array($obj->type_template, array_keys($elementList))) {
1418 // Current template type is an unknown type, so we must keep it as it is.
1419 print '<input type="hidden" name="type_template" value="'.$obj->type_template.'">';
1420 print $obj->type_template;
1421 } else {
1422 print $form->selectarray('type_template', $elementList, (!empty($obj->type_template) ? $obj->type_template : ''), 1, 0, 0, '', 0, 0, 0, '', 'minwidth75 maxwidth125', 1, '', 0, 1);
1423 }
1424 print '</td>';
1425 } elseif ($context == 'add' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1426 //print '<td></td>';
1427 } elseif ($context == 'edit' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1428 print '<td></td>';
1429 } elseif ($context == 'hide' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1430 //print '<td></td>';
1431 } else {
1432 $size = '';
1433 $class = '';
1434 $classtd = '';
1435 if ($value == 'code') {
1436 $class = 'maxwidth100';
1437 }
1438 if ($value == 'label') {
1439 $class = 'maxwidth200';
1440 }
1441 if ($value == 'private') {
1442 $class = 'maxwidth50';
1443 $classtd = 'center';
1444 }
1445 if ($value == 'position') {
1446 $class = 'maxwidth50 center';
1447 $classtd = 'center';
1448 }
1449 if ($value == 'topic') {
1450 $class = 'quatrevingtpercent';
1451 }
1452 if ($value == 'defaultfortype') {
1453 $class = 'width25 center';
1454 $classtd = 'center';
1455 }
1456
1457 print '<td'.($classtd ? ' class="'.$classtd.'"' : '').'>';
1458 if ($value == 'private') {
1459 if (empty($user->admin)) {
1460 print $form->selectyesno($value, '1', 1);
1461 } else {
1462 print $form->selectyesno($value, (isset($obj->$value) ? $obj->$value : ''), 1);
1463 }
1464 } else {
1465 print '<input type="text" '.$size.'class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->$value) ? $obj->$value : '').'" name="'. $value .'">';
1466 }
1467 print '</td>';
1468 }
1469 }
1470}
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.