dolibarr  19.0.0-dev
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
37 require '../main.inc.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
44 require_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 
49 if (isModEnabled('adherent')) {
50  $langsArray[]='members';
51 }
52 if (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');
88 if (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 
95 if (empty($sortfield)) {
96  $sortfield = 'type_template,lang,position,label';
97 }
98 if (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";
113 if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
114  $tabfield[25] .= ',content_lines';
115 }
116 
117 // Nom des champs d'edition pour modification d'un enregistrement
118 $tabfieldvalue = array();
119 $tabfieldvalue[25] = "label,lang,type_template,fk_user,private,position,topic,email_from,joinfiles,defaultfortype,content";
120 if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
121  $tabfieldvalue[25] .= ',content_lines';
122 }
123 
124 // Nom des champs dans la table pour insertion d'un enregistrement
125 $tabfieldinsert = array();
126 $tabfieldinsert[25] = "label,lang,type_template,fk_user,private,position,topic,email_from,joinfiles,defaultfortype,content";
127 if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
128  $tabfieldinsert[25] .= ',content_lines';
129 }
130 $tabfieldinsert[25] .= ',entity'; // Must be at end because not into other arrays
131 
132 // Condition to show dictionary in setup page
133 $tabcond = array();
134 $tabcond[25] = true;
135 
136 // List of help for fields
137 // Set MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES to allow edit of template for lines
138 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
139 $formmail = new FormMail($db);
140 if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
141  $tmp = FormMail::getAvailableSubstitKey('formemail');
142  $tmp['__(AnyTranslationKey)__'] = 'Translation';
143  $helpsubstit = $langs->trans("AvailableVariables").':<br>';
144  $helpsubstitforlines = $langs->trans("AvailableVariables").':<br>';
145  foreach ($tmp as $key => $val) {
146  $helpsubstit .= $key.' -> '.$val.'<br>';
147  $helpsubstitforlines .= $key.' -> '.$val.'<br>';
148  }
149 } else {
150  $tmp = FormMail::getAvailableSubstitKey('formemailwithlines');
151  $tmp['__(AnyTranslationKey)__'] = 'Translation';
152  $helpsubstit = $langs->trans("AvailableVariables").':<br>';
153  $helpsubstitforlines = $langs->trans("AvailableVariables").':<br>';
154  foreach ($tmp as $key => $val) {
155  $helpsubstit .= $key.' -> '.$val.'<br>';
156  }
157  $tmp = FormMail::getAvailableSubstitKey('formemailforlines');
158  foreach ($tmp as $key => $val) {
159  $helpsubstitforlines .= $key.' -> '.$val.'<br>';
160  }
161 }
162 
163 
164 $tabhelp = array();
165 $tabhelp[25] = array(
166  'label'=>$langs->trans('EnterAnyCode'),
167  'type_template'=>$langs->trans("TemplateForElement"),
168  'private'=>$langs->trans("TemplateIsVisibleByOwnerOnly"),
169  'position'=>$langs->trans("PositionIntoComboList"),
170  'topic'=>'<span class="small">'.$helpsubstit.'</span>',
171  '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'));
186 if (isModEnabled('adherent') && $user->hasRight('adherent', 'lire')) {
187  $elementList['member'] = img_picto('', 'object_member', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToMember'));
188 }
189 if (isModEnabled('recruitment') && $user->hasRight('recruitment', 'recruitmentjobposition', 'read')) {
190  $elementList['recruitmentcandidature_send'] = img_picto('', 'recruitmentcandidature', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('RecruitmentCandidatures'));
191 }
192 if (isModEnabled("societe") && $user->hasRight('societe', 'lire')) {
193  $elementList['thirdparty'] = img_picto('', 'company', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToThirdparty'));
194 }
195 if (isModEnabled('project')) {
196  $elementList['project'] = img_picto('', 'project', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToProject'));
197 }
198 if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
199  $elementList['propal_send'] = img_picto('', 'propal', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendProposal'));
200 }
201 if (isModEnabled('commande') && $user->hasRight('commande', 'lire')) {
202  $elementList['order_send'] = img_picto('', 'order', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendOrder'));
203 }
204 if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
205  $elementList['facture_send'] = img_picto('', 'bill', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendInvoice'));
206 }
207 if (isModEnabled("expedition")) {
208  $elementList['shipping_send'] = img_picto('', 'dolly', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendShipment'));
209 }
210 if (isModEnabled("reception")) {
211  $elementList['reception_send'] = img_picto('', 'dollyrevert', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendReception'));
212 }
213 if (isModEnabled('ficheinter')) {
214  $elementList['fichinter_send'] = img_picto('', 'intervention', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendIntervention'));
215 }
216 if (isModEnabled('supplier_proposal')) {
217  $elementList['supplier_proposal_send'] = img_picto('', 'propal', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendSupplierRequestForQuotation'));
218 }
219 if (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 }
222 if (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 }
225 if (isModEnabled('contrat') && $user->hasRight('contrat', 'lire')) {
226  $elementList['contract'] = img_picto('', 'contract', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendContract'));
227 }
228 if (isModEnabled('ticket') && !empty($user->rights->ticket->read)) {
229  $elementList['ticket_send'] = img_picto('', 'ticket', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToTicket'));
230 }
231 if (isModEnabled('expensereport') && !empty($user->rights->expensereport->lire)) {
232  $elementList['expensereport_send'] = img_picto('', 'trip', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToExpenseReport'));
233 }
234 if (isModEnabled('agenda')) {
235  $elementList['actioncomm_send'] = img_picto('', 'action', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendEventPush'));
236 }
237 if (isModEnabled('eventorganization') && !empty($user->rights->eventorganization->read)) {
238  $elementList['conferenceorbooth'] = img_picto('', 'action', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendEventOrganization'));
239 }
240 if (isModEnabled('partnership') && !empty($user->rights->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
246 if ($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
257 if (!empty($user->socid)) {
258  accessforbidden();
259 }
260 
261 $permissiontoadd = 1;
262 $permissiontodelete = 1;
263 
264 
265 
266 /*
267  * Actions
268  */
269 
270 if (GETPOST('cancel', 'alpha')) {
271  $action = 'list';
272  $massaction = '';
273 }
274 if (!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
280 if ($reshook < 0) {
281  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
282 }
283 
284 if (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 = '';
571 if (!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').")";
582 if (!$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 }
586 if (!getDolGlobalInt('MAIN_MULTILANGS')) {
587  $sql .= " AND (lang = '".$db->escape($langs->defaultlang)."' OR lang IS NULL OR lang = '')";
588 }
589 if ($search_label) {
590  $sql .= natural_search('label', $search_label);
591 }
592 if ($search_type_template != '' && $search_type_template != '-1') {
593  $sql .= natural_search('type_template', $search_type_template);
594 }
595 if ($search_lang) {
596  $sql .= natural_search('lang', $search_lang);
597 }
598 if ($search_fk_user != '' && $search_fk_user != '-1') {
599  $sql .= natural_search('fk_user', $search_fk_user, 2);
600 }
601 if ($search_module) {
602  $sql .= natural_search('module', $search_module);
603 }
604 if ($search_topic) {
605  $sql .= natural_search('topic', $search_topic);
606 }
607 // If sort order is "country", we use country_code instead
608 if ($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 
618 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
619 
620 $arrayofselected = is_array($toselect) ? $toselect : array();
621 
622 $param = '';
623 if (!empty($mode)) {
624  $param .= '&mode='.urlencode($mode);
625 }
626 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
627  $param .= '&contextpage='.urlencode($contextpage);
628 }
629 if ($limit > 0 && $limit != $conf->liste_limit) {
630  $param .= '&limit='.((int) $limit);
631 }
632 if (!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 }
645 if ($optioncss != '') {
646  $param .= '&optioncss='.urlencode($optioncss);
647 }
648 // Add $param from extra fields
649 include 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 = dolGetButtonTitle($langs->trans('NewEMailTemplate'), '', 'fa fa-plus-circle', $url, '', $permissiontoadd);
662 
663 
664 if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
665  print load_fiche_titre($title, '', $titlepicto);
666 } else {
667  print load_fiche_titre($title, $newcardbutton, $titlepicto);
668 }
669 
670 if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
671  $head = email_admin_prepare_head();
672 
673  print dol_get_fiche_head($head, 'templates', '', -1);
674 
675  if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
676  print load_fiche_titre('', $newcardbutton, '');
677  }
678 }
679 
680 
681 // Confirm deletion of record
682 if ($action == 'delete') {
683  print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.((int) $rowid).'&code='.urlencode($code).'&id='.((int) $id), $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1);
684 }
685 
686 
687 $fieldlist = explode(',', $tabfield[$id]);
688 
689 if ($action == 'create') {
690  // If data was already input, we define them in obj to populate input fields.
691  $obj = new stdClass();
692  $obj->label = GETPOST('label');
693  $obj->lang = GETPOST('lang');
694  $obj->type_template = GETPOST('type_template');
695  $obj->fk_user = GETPOST('fk_user', 'int');
696  $obj->private = GETPOST('private', 'int');
697  $obj->position = GETPOST('position');
698  $obj->topic = GETPOST('topic');
699  $obj->joinfiles = GETPOST('joinfiles');
700  $obj->defaultfortype = GETPOST('defaultfortype') ? 1 : 0;
701  $obj->content = GETPOST('content', 'restricthtml');
702 
703  // Form to add a new line
704  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
705  print '<input type="hidden" name="token" value="'.newToken().'">';
706  print '<input type="hidden" name="action" value="add">';
707  print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
708 
709  print '<div class="div-table-responsive-no-min">';
710  print '<table class="noborder centpercent">';
711 
712  // Line to enter new values (title)
713  print '<tr class="liste_titre">';
714  foreach ($fieldlist as $field => $value) {
715  // Determine le nom du champ par rapport aux noms possibles
716  // dans les dictionnaires de donnees
717  $valuetoshow = ucfirst($fieldlist[$field]); // Par defaut
718  $valuetoshow = $langs->trans($valuetoshow); // try to translate
719  $css = "left";
720  if ($fieldlist[$field] == 'module') {
721  $valuetoshow = '&nbsp;';
722  }
723  if ($fieldlist[$field] == 'fk_user') {
724  $valuetoshow = $langs->trans("Owner");
725  }
726  if ($fieldlist[$field] == 'lang') {
727  $valuetoshow = (!getDolGlobalInt('MAIN_MULTILANGS') ? '&nbsp;' : $langs->trans("Language"));
728  }
729  if ($fieldlist[$field] == 'type') {
730  $valuetoshow = $langs->trans("Type");
731  }
732  if ($fieldlist[$field] == 'position') {
733  $css = 'center';
734  }
735  if ($fieldlist[$field] == 'code') {
736  $valuetoshow = $langs->trans("Code");
737  }
738  if ($fieldlist[$field] == 'label') {
739  $valuetoshow = $langs->trans("Code");
740  }
741  if ($fieldlist[$field] == 'type_template') {
742  $valuetoshow = $langs->trans("TypeOfTemplate"); $css = "center";
743  }
744  if (in_array($fieldlist[$field], array('private', 'private', 'defaultfortype'))) {
745  $css = 'center';
746  }
747 
748  if ($fieldlist[$field] == 'topic') {
749  $valuetoshow = '';
750  }
751  if ($fieldlist[$field] == 'joinfiles') {
752  $valuetoshow = '';
753  }
754  if ($fieldlist[$field] == 'content') {
755  $valuetoshow = '';
756  }
757  if ($fieldlist[$field] == 'content_lines') {
758  $valuetoshow = '';
759  }
760  if ($valuetoshow != '') {
761  print '<th class="'.$css.'">';
762  if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
763  print '<a href="'.$tabhelp[$id][$value].'" target="_blank" rel="noopener noreferrer">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
764  } elseif (!empty($tabhelp[$id][$value])) {
765  if (in_array($value, array('topic'))) {
766  print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, $value); // Tooltip on click
767  } else {
768  print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2); // Tooltip on hover
769  }
770  } else {
771  print $valuetoshow;
772  }
773  print '</th>';
774  }
775  }
776  print '<th>';
777  print '<input type="hidden" name="id" value="'.$id.'">';
778  print '</th>';
779  print '</tr>';
780 
781  $tmpaction = 'create';
782  $parameters = array(
783  'fieldlist' => $fieldlist,
784  'tabname' => $tabname[$id]
785  );
786  $reshook = $hookmanager->executeHooks('createEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
787  $error = $hookmanager->error;
788  $errors = $hookmanager->errors;
789 
790 
791  // Line to enter new values (input fields)
792  print '<tr class="oddeven">';
793 
794  if (empty($reshook)) {
795  if ($action == 'edit') {
796  fieldList($fieldlist, $obj, $tabname[$id], 'hide');
797  } else {
798  fieldList($fieldlist, $obj, $tabname[$id], 'add');
799  }
800  }
801  // Action column
802  print '<td class="right">';
803  print '</td>';
804  print "</tr>";
805 
806  print '<tr class="impair nodrag nodrop nohover"><td colspan="9" class="nobottom">';
807 
808  // Show fields for topic, join files and body
809  $fieldsforcontent = array('topic', 'email_from', 'joinfiles', 'content');
810  if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
811  $fieldsforcontent = array('topic', 'email_from', 'joinfiles', 'content', 'content_lines');
812  }
813  foreach ($fieldsforcontent as $tmpfieldlist) {
814  // Topic of email
815  if ($tmpfieldlist == 'topic') {
816  print '<strong>'.$form->textwithpicto($langs->trans("Topic"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
817  }
818  if ($tmpfieldlist == 'email_from') {
819  print $form->textwithpicto($langs->trans("MailFrom"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist);
820  }
821  if ($tmpfieldlist == 'joinfiles') {
822  print '<strong>'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
823  }
824  if ($tmpfieldlist == 'content') {
825  print $form->textwithpicto($langs->trans("Content"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
826  }
827  if ($tmpfieldlist == 'content_lines') {
828  print $form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
829  }
830 
831  // Input field
832  if ($tmpfieldlist == 'topic') {
833  print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '').'">';
834  } elseif ($tmpfieldlist == 'email_from') {
835  print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '').'">';
836  } elseif ($tmpfieldlist == 'joinfiles') {
837  print $form->selectyesno($tmpfieldlist, (isset($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '0'), 1, false, 0, 1);
838  } else {
839  $okforextended = true;
840  if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
841  $okforextended = false;
842  }
843  $doleditor = new DolEditor($tmpfieldlist, (!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : ''), '', 400, 'dolibarr_mailings', 'In', false, $acceptlocallinktomedia, $okforextended, ROWS_6, '90%');
844  print $doleditor->Create(1);
845  }
846  print '<br>';
847  }
848 
849  print '</tr>';
850 
851  print '</table>';
852 
853  if ($action != 'edit') {
854  print '<center>';
855  print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'"> ';
856  print '<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
857  print '</center>';
858  }
859 
860  print '</div>';
861  print '</form>';
862  print '<br><br>';
863 }
864 
865 // List of available record in database
866 dol_syslog("htdocs/admin/dict", LOG_DEBUG);
867 $resql = $db->query($sql);
868 if (!$resql) {
869  dol_print_error($db);
870  exit;
871 }
872 
873 $num = $db->num_rows($resql);
874 
875 print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
876 print '<input type="hidden" name="token" value="'.newToken().'">';
877 print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
878 
879 print '<div class="div-table-responsive-no-min">';
880 print '<table class="noborder centpercent">';
881 
882 $i = 0;
883 
884 $param = '&id='.((int) $id);
885 if ($search_label) {
886  $param .= '&search_label='.urlencode($search_label);
887 }
888 if ($search_lang > 0) {
889  $param .= '&search_lang='.urlencode($search_lang);
890 }
891 if ($search_type_template != '-1') {
892  $param .= '&search_type_template='.urlencode($search_type_template);
893 }
894 if ($search_fk_user > 0) {
895  $param .= '&search_fk_user='.urlencode($search_fk_user);
896 }
897 if ($search_module) {
898  $param .= '&search_module='.urlencode($search_module);
899 }
900 if ($search_topic) {
901  $param .= '&search_topic='.urlencode($search_topic);
902 }
903 
904 $paramwithsearch = $param;
905 if ($sortorder) {
906  $paramwithsearch .= '&sortorder='.urlencode($sortorder);
907 }
908 if ($sortfield) {
909  $paramwithsearch .= '&sortfield='.urlencode($sortfield);
910 }
911 if (GETPOST('from', 'alpha')) {
912  $paramwithsearch .= '&from='.urlencode(GETPOST('from', 'alpha'));
913 }
914 
915 // There is several pages
916 if ($num > $listlimit) {
917  print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).'">';
918  print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
919  print '</td></tr>';
920 }
921 
922 
923 // Title line with search boxes
924 print '<tr class="liste_titre">';
925 // Action column
926 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
927  print '<td class="liste_titre center" width="64">';
928  $searchpicto = $form->showFilterButtons();
929  print $searchpicto;
930  print '</td>';
931 }
932 foreach ($fieldlist as $field => $value) {
933  if ($value == 'module') {
934  print '<td class="liste_titre"><input type="text" name="search_module" class="maxwidth75" value="'.dol_escape_htmltag($search_module).'"></td>';
935  } elseif ($value == 'label') {
936  print '<td class="liste_titre"><input type="text" name="search_label" class="maxwidth200" value="'.dol_escape_htmltag($search_label).'"></td>';
937  } elseif ($value == 'lang') {
938  print '<td class="liste_titre">';
939  print $formadmin->select_language($search_lang, 'search_lang', 0, null, 1, 0, 0, 'maxwidth100');
940  print '</td>';
941  } elseif ($value == 'fk_user') {
942  print '<td class="liste_titre">';
943  print $form->select_dolusers($search_fk_user, 'search_fk_user', 1, null, 0, ($user->admin ? '' : 'hierarchyme'), null, 0, 0, 0, '', 0, '', 'maxwidth100', 1);
944  print '</td>';
945  } elseif ($value == 'topic') {
946  print '<td class="liste_titre"><input type="text" name="search_topic" value="'.dol_escape_htmltag($search_topic).'"></td>';
947  } elseif ($value == 'type_template') {
948  print '<td class="liste_titre center">';
949  print $form->selectarray('search_type_template', $elementList, $search_type_template, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100 maxwidth125', 1, '', 0, 1);
950  print '</td>';
951  } elseif (!in_array($value, array('content', 'content_lines'))) {
952  print '<td class="liste_titre"></td>';
953  }
954 }
955 /*if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
956  print '<td class="liste_titre"></td>';
957 }*/
958 // Status
959 print '<td></td>';
960 // Action column
961 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
962  print '<td class="liste_titre center" width="64">';
963  $searchpicto = $form->showFilterButtons();
964  print $searchpicto;
965  print '</td>';
966 }
967 print '</tr>';
968 
969 // Title of lines
970 print '<tr class="liste_titre">';
971 // Action column
972 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
973  print getTitleFieldOfList('');
974 }
975 foreach ($fieldlist as $field => $value) {
976  $showfield = 1; // By defaut
977  $css = "left";
978  $sortable = 1;
979  $valuetoshow = '';
980  $forcenowrap = 1;
981  /*
982  $tmparray=getLabelOfField($fieldlist[$field]);
983  $showfield=$tmp['showfield'];
984  $valuetoshow=$tmp['valuetoshow'];
985  $css=$tmp['align'];
986  $sortable=$tmp['sortable'];
987  */
988  $valuetoshow = ucfirst($fieldlist[$field]); // By defaut
989  $valuetoshow = $langs->trans($valuetoshow); // try to translate
990  if ($fieldlist[$field] == 'module') {
991  $css = 'tdoverflowmax100';
992  }
993  if ($fieldlist[$field] == 'fk_user') {
994  $valuetoshow = $langs->trans("Owner");
995  }
996  if ($fieldlist[$field] == 'lang') {
997  $valuetoshow = $langs->trans("Language");
998  }
999  if ($fieldlist[$field] == 'type') {
1000  $valuetoshow = $langs->trans("Type");
1001  }
1002  if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
1003  $valuetoshow = $langs->trans("Code");
1004  }
1005  if ($fieldlist[$field] == 'type_template') {
1006  $css = 'center';
1007  $valuetoshow = $langs->trans("TypeOfTemplate");
1008  }
1009  if ($fieldlist[$field] == 'private') {
1010  $css = 'center';
1011  }
1012  if ($fieldlist[$field] == 'position') {
1013  $css = 'center';
1014  }
1015 
1016  if ($fieldlist[$field] == 'joinfiles') {
1017  $valuetoshow = $langs->trans("FilesAttachedToEmail");
1018  $css = 'center';
1019  $forcenowrap = 0;
1020  }
1021  if ($fieldlist[$field] == 'content') {
1022  $valuetoshow = $langs->trans("Content"); $showfield = 0;
1023  }
1024  if ($fieldlist[$field] == 'content_lines') {
1025  $valuetoshow = $langs->trans("ContentForLines"); $showfield = 0;
1026  }
1027 
1028  // Show fields
1029  if ($showfield) {
1030  if (!empty($tabhelp[$id][$value])) {
1031  if (in_array($value, array('topic'))) {
1032  $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, 'tooltip'.$value, $forcenowrap); // Tooltip on click
1033  } else {
1034  $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, '', $forcenowrap); // Tooltip on hover
1035  }
1036  }
1037  $sortfieldtouse = ($sortable ? $fieldlist[$field] : '');
1038  if ($sortfieldtouse == 'type_template') {
1039  $sortfieldtouse.= 'type_template,lang,position,label';
1040  }
1041  print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], $sortfieldtouse, ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, $css.' ');
1042  }
1043 }
1044 
1045 print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
1046 // Action column
1047 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1048  print getTitleFieldOfList('');
1049 }
1050 print '</tr>';
1051 
1052 if ($num) {
1053  $nbqualified = 0;
1054 
1055  // Lines with values
1056  while ($i < $num) {
1057  $obj = $db->fetch_object($resql);
1058 
1059  if ($obj) {
1060  if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
1061  print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
1062 
1063  $tmpaction = 'edit';
1064  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
1065  $reshook = $hookmanager->executeHooks('editEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1066  $error = $hookmanager->error; $errors = $hookmanager->errors;
1067 
1068  // Action column
1069  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1070  print '<td class="center">';
1071  print '<input type="hidden" name="page" value="'.$page.'">';
1072  print '<input type="hidden" name="rowid" value="'.$rowid.'">';
1073  print '<input type="submit" class="button buttongen button-save" name="actionmodify" value="'.$langs->trans("Modify").'">';
1074  print '<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'"></div>';
1075  print '<input type="submit" class="button buttongen button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
1076  print '</td>';
1077  }
1078  // Show main fields
1079  if (empty($reshook)) {
1080  fieldList($fieldlist, $obj, $tabname[$id], 'edit');
1081  }
1082  // Action column
1083  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1084  print '<td class="center">';
1085  print '<input type="hidden" name="page" value="'.$page.'">';
1086  print '<input type="hidden" name="rowid" value="'.$rowid.'">';
1087  print '<input type="submit" class="button buttongen button-save" name="actionmodify" value="'.$langs->trans("Modify").'">';
1088  print '<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'"></div>';
1089  print '<input type="submit" class="button buttongen button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
1090  print '</td>';
1091  }
1092  print "</tr>\n";
1093 
1094  print '<tr class="oddeven nohover'.(in_array($tmpfieldlist, array('topic', 'joinfiles')) ? ' nobottom' : '').'" id="tr-'.$tmpfieldlist.'-'.$rowid.'">';
1095  print '<td colspan="10">';
1096 
1097  $fieldsforcontent = array('topic', 'email_from','joinfiles', 'content');
1098  if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
1099  $fieldsforcontent[] = 'content_lines';
1100  }
1101  foreach ($fieldsforcontent as $tmpfieldlist) {
1102  $showfield = 1;
1103  $css = "left";
1104  $valuetoshow = $obj->$tmpfieldlist;
1105 
1106  $class = 'tddict';
1107  // Show value for field
1108  if ($showfield) {
1109  // Show line for topic, joinfiles and content
1110  if ($tmpfieldlist == 'topic') {
1111  print '<strong>'.$form->textwithpicto($langs->trans("Topic"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
1112  print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'">';
1113  print '<br>'."\n";
1114  }
1115  if ($tmpfieldlist == 'email_from') {
1116  print '<strong>'.$form->textwithpicto($langs->trans("MailFrom"), $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 == 'joinfiles') {
1121  print '<strong>'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
1122  print $form->selectyesno($tmpfieldlist.'-'.$rowid, (isset($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '0'), 1, false, 0, 1);
1123  print '<br>'."\n";
1124  }
1125 
1126  if ($tmpfieldlist == 'content') {
1127  print $form->textwithpicto($langs->trans("Content"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
1128  $okforextended = true;
1129  if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
1130  $okforextended = false;
1131  }
1132  $doleditor = new DolEditor($tmpfieldlist.'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 500, 'dolibarr_mailings', 'In', 0, $acceptlocallinktomedia, $okforextended, ROWS_6, '90%');
1133  print $doleditor->Create(1);
1134  }
1135  if ($tmpfieldlist == 'content_lines') {
1136  print '<br>'."\n";
1137  print $form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
1138  $okforextended = true;
1139  if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
1140  $okforextended = false;
1141  }
1142  $doleditor = new DolEditor($tmpfieldlist.'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 140, 'dolibarr_mailings', 'In', 0, $acceptlocallinktomedia, $okforextended, ROWS_6, '90%');
1143  print $doleditor->Create(1);
1144  }
1145  }
1146  }
1147  print '</td>';
1148  print '<td></td>';
1149  print '<td></td>';
1150 
1151  print "</tr>\n";
1152 
1153  $nbqualified++;
1154  } else {
1155  // If template is for a module, check module is enabled.
1156  if ($obj->module) {
1157  $tempmodulekey = $obj->module;
1158  if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
1159  $i++;
1160  continue;
1161  }
1162  }
1163 
1164  $keyforobj = 'type_template';
1165  if (!in_array($obj->$keyforobj, array_keys($elementList))) {
1166  $i++;
1167  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)
1168  }
1169  // Test on 'enabled'
1170  if (!dol_eval($obj->enabled, 1, 1, '1')) {
1171  $i++;
1172  continue; // Email template not qualified
1173  }
1174 
1175  $nbqualified++;
1176 
1177  // Can an entry be erased or disabled ?
1178  $iserasable = 1; $canbedisabled = 1; $canbemodified = 1; // true by default
1179  if (!$user->admin && $obj->fk_user != $user->id) {
1180  $iserasable = 0;
1181  $canbedisabled = 0;
1182  $canbemodified = 0;
1183  }
1184 
1185  $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) : '');
1186  if ($param) {
1187  $url .= '&'.$param;
1188  }
1189 
1190  print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
1191 
1192  // Action column - Modify link / Delete link
1193  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1194  print '<td class="center nowraponall" width="64">';
1195  if ($canbemodified) {
1196  print '<a class="reposition editfielda" href="'.$url.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
1197  }
1198  if ($iserasable) {
1199  print '<a class="marginleftonly" href="'.$url.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
1200  //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
1201  }
1202  print '</td>';
1203  }
1204 
1205  $tmpaction = 'view';
1206  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
1207  $reshook = $hookmanager->executeHooks('viewEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1208 
1209  $error = $hookmanager->error; $errors = $hookmanager->errors;
1210 
1211  if (empty($reshook)) {
1212  foreach ($fieldlist as $field => $value) {
1213  if (in_array($fieldlist[$field], array('content', 'content_lines'))) {
1214  continue;
1215  }
1216  $showfield = 1;
1217  $css = "";
1218  $class = "tddict";
1219  $title = '';
1220  $tmpvar = $fieldlist[$field];
1221  $valuetoshow = $obj->$tmpvar;
1222  if ($value == 'label' || $value == 'topic') {
1223  if ($langs->trans($valuetoshow) != $valuetoshow) {
1224  $valuetoshow = $langs->trans($valuetoshow);
1225  }
1226  $valuetoshow = dol_escape_htmltag($valuetoshow);
1227  }
1228  if ($value == 'label') {
1229  $class .= ' tdoverflowmax100';
1230  }
1231  if ($value == 'topic') {
1232  $class .= ' tdoverflowmax200 small';
1233  }
1234  if ($value == 'type_template') {
1235  $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
1236  $css = "center tdoverflowmax150";
1237  }
1238  if ($value == 'lang' && $valuetoshow) {
1239  $valuetoshow = $valuetoshow.' - '.$langs->trans("Language_".$valuetoshow);
1240  $class .= ' tdoverflowmax100';
1241  }
1242  if ($value == 'fk_user') {
1243  if ($valuetoshow > 0) {
1244  $fuser = new User($db);
1245  $fuser->fetch($valuetoshow);
1246  $valuetoshow = $fuser->getNomUrl(1);
1247  $class .= ' tdoverflowmax100';
1248  }
1249  }
1250  if ($value == 'private') {
1251  $css = "center";
1252  if ($valuetoshow) {
1253  $valuetoshow = yn($valuetoshow);
1254  } else {
1255  $valuetoshow = '';
1256  }
1257  }
1258  if ($value == 'position') {
1259  $css = "center";
1260  }
1261  if (in_array($value, array('joinfiles', 'defaultfortype'))) {
1262  $css = "center";
1263  if ($valuetoshow) {
1264  //$valuetoshow = yn(1);
1265  $valuetoshow = '<input type="checkbox" checked="checked" disabled>';
1266  } else {
1267  $valuetoshow = '';
1268  }
1269  }
1270  if ($css) {
1271  $class .= ' '.$css;
1272  }
1273 
1274  // Show value for field
1275  if ($showfield) {
1276  print '<!-- '.$fieldlist[$field].' -->';
1277  print '<td class="'.$class.'"';
1278  if (in_array($value, array('code', 'label', 'topic'))) {
1279  print ' title="'.dol_escape_htmltag($valuetoshow).'"';
1280  }
1281  print '>';
1282  print $valuetoshow;
1283  print '</td>';
1284  }
1285  }
1286  }
1287 
1288  // Status / Active
1289  print '<td class="center nowrap">';
1290  if ($canbedisabled) {
1291  print '<a class="reposition" href="'.$url.'&action='.$acts[$obj->active].'&token='.newToken().'">'.$actl[$obj->active].'</a>';
1292  } else {
1293  print '<span class="opacitymedium">'.$actl[$obj->active].'</span>';
1294  }
1295  print "</td>";
1296 
1297  // Action column - Modify link / Delete link
1298  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1299  print '<td class="center nowraponall" width="64">';
1300  if ($canbemodified) {
1301  print '<a class="reposition editfielda" href="'.$url.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
1302  }
1303  if ($iserasable) {
1304  print '<a class="marginleftonly" href="'.$url.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
1305  //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
1306  }
1307  print '</td>';
1308  }
1309 
1310  print "</tr>\n";
1311  }
1312  }
1313 
1314  $i++;
1315  }
1316 }
1317 
1318 // If no record found
1319 if ($nbqualified == 0) {
1320  $colspan = 12;
1321  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1322 }
1323 
1324 print '</table>';
1325 print '</div>';
1326 
1327 print '</form>';
1328 
1329 
1330 if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
1331  print dol_get_fiche_end();
1332 }
1333 
1334 
1335 // End of page
1336 llxFooter();
1337 $db->close();
1338 
1339 
1349 function fieldList($fieldlist, $obj = '', $tabname = '', $context = '')
1350 {
1351  global $langs, $user, $db;
1352  global $form;
1353  global $elementList;
1354 
1355  $formadmin = new FormAdmin($db);
1356 
1357  foreach ($fieldlist as $field => $value) {
1358  //print $value;
1359  if ($value == 'module') {
1360  print '<td></td>';
1361  } elseif ($value == 'fk_user') {
1362  print '<td>';
1363  if ($user->admin) {
1364  print $form->select_dolusers(empty($obj->$value) ? '' : $obj->$value, 'fk_user', 1, null, 0, ($user->admin ? '' : 'hierarchyme'), null, 0, 0, 0, '', 0, '', 'minwidth75 maxwidth100');
1365  } else {
1366  if ($context == 'add') { // I am not admin and we show the add form
1367  print $user->getNomUrl(1); // Me
1368  $forcedvalue = $user->id;
1369  } else {
1370  if ($obj && !empty($obj->$value) && $obj->$value > 0) {
1371  $fuser = new User($db);
1372  $fuser->fetch($obj->$value);
1373  print $fuser->getNomUrl(1);
1374  $forcedvalue = $fuser->id;
1375  } else {
1376  $forcedvalue = $obj->$value;
1377  }
1378  }
1379  $keyname = $value;
1380  print '<input type="hidden" value="'.$forcedvalue.'" name="'.$keyname.'">';
1381  }
1382  print '</td>';
1383  } elseif ($value == 'lang') {
1384  print '<td>';
1385  if (getDolGlobalInt('MAIN_MULTILANGS')) {
1386  $selectedlang = GETPOSTISSET('langcode') ?GETPOST('langcode', 'aZ09') : $langs->defaultlang;
1387  if ($context == 'edit') {
1388  $selectedlang = $obj->lang;
1389  }
1390  print $formadmin->select_language($selectedlang, 'langcode', 0, null, 1, 0, 0, 'maxwidth100');
1391  } else {
1392  if (!empty($obj->lang)) {
1393  print $obj->lang.' - '.$langs->trans('Language_'.$obj->lang);
1394  }
1395  $keyname = $value;
1396  if ($keyname == 'lang') {
1397  $keyname = 'langcode'; // Avoid conflict with lang param
1398  }
1399  print '<input type="hidden" value="'.(empty($obj->lang) ? '' : $obj->lang).'" name="'.$keyname.'">';
1400  }
1401  print '</td>';
1402  } elseif ($value == 'type_template') {
1403  // Le type de template
1404  print '<td class="center">';
1405  if ($context == 'edit' && !empty($obj->type_template) && !in_array($obj->type_template, array_keys($elementList))) {
1406  // Current template type is an unknown type, so we must keep it as it is.
1407  print '<input type="hidden" name="type_template" value="'.$obj->type_template.'">';
1408  print $obj->type_template;
1409  } else {
1410  print $form->selectarray('type_template', $elementList, (!empty($obj->type_template) ? $obj->type_template:''), 1, 0, 0, '', 0, 0, 0, '', 'minwidth75 maxwidth125', 1, '', 0, 1);
1411  }
1412  print '</td>';
1413  } elseif ($context == 'add' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1414  //print '<td></td>';
1415  } elseif ($context == 'edit' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1416  print '<td></td>';
1417  } elseif ($context == 'hide' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1418  //print '<td></td>';
1419  } else {
1420  $size = ''; $class = ''; $classtd = '';
1421  if ($value == 'code') {
1422  $class = 'maxwidth100';
1423  }
1424  if ($value == 'label') {
1425  $class = 'maxwidth200';
1426  }
1427  if ($value == 'private') {
1428  $class = 'maxwidth50';
1429  $classtd = 'center';
1430  }
1431  if ($value == 'position') {
1432  $class = 'maxwidth50 center';
1433  $classtd = 'center';
1434  }
1435  if ($value == 'topic') {
1436  $class = 'quatrevingtpercent';
1437  }
1438  if ($value == 'defaultfortype') {
1439  $class = 'width25 center';
1440  $classtd = 'center';
1441  }
1442 
1443  print '<td'.($classtd ? ' class="'.$classtd.'"' : '').'>';
1444  if ($value == 'private') {
1445  if (empty($user->admin)) {
1446  print $form->selectyesno($value, '1', 1);
1447  } else {
1448  print $form->selectyesno($value, (isset($obj->$value) ? $obj->$value : ''), 1);
1449  }
1450  } else {
1451  print '<input type="text" '.$size.'class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->$value) ? $obj->$value : '').'" name="'. $value .'">';
1452  }
1453  print '</td>';
1454  }
1455  }
1456 }
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
email_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: admin.lib.php:2046
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage a WYSIWYG editor.
Class to generate html code for admin pages.
Class to manage generation of HTML components Only common components must be here.
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
static getAvailableSubstitKey($mode='formemail', $object=null)
Get list of substitution keys available for emails.
Class to manage Dolibarr users.
Definition: user.class.php:48
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
acceptLocalLinktoMedia()
Check the syntax of some PHP code.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
print_fleche_navigation($page, $file, $options='', $nextpage=0, $betweenarrows='', $afterarrows='', $limit=-1, $totalnboflines=0, $hideselectlimit=0, $beforearrows='', $hidenavigation=0)
Function to show navigation arrows into lists.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
fieldList($fieldlist, $obj='', $tabname='', $context='')
Show fields in insert/edit mode.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.