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