dolibarr  17.0.0
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 // 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 
73 $acts = array();
74 $actl = array();
75 $acts[0] = "activate";
76 $acts[1] = "disable";
77 $actl[0] = img_picto($langs->trans("Disabled"), 'switch_off', 'class="size15x"');
78 $actl[1] = img_picto($langs->trans("Activated"), 'switch_on', 'class="size15x"');
79 
80 $listoffset = GETPOST('listoffset', 'alpha');
81 $listlimit = GETPOST('listlimit', 'alpha') > 0 ?GETPOST('listlimit', 'alpha') : 1000;
82 
83 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
84 $sortfield = GETPOST('sortfield', 'aZ09comma');
85 $sortorder = GETPOST('sortorder', 'aZ09comma');
86 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
87 if (empty($page) || $page == -1) {
88  $page = 0;
89 } // If $page is not defined, or '' or -1
90 $offset = $listlimit * $page;
91 $pageprev = $page - 1;
92 $pagenext = $page + 1;
93 
94 if (empty($sortfield)) {
95  $sortfield = 'type_template, lang, position, label';
96 }
97 if (empty($sortorder)) {
98  $sortorder = 'ASC';
99 }
100 
101 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
102 $hookmanager->initHooks(array('emailtemplates'));
103 
104 
105 // Name of SQL tables of dictionaries
106 $tabname = array();
107 $tabname[25] = MAIN_DB_PREFIX."c_email_templates";
108 
109 // Nom des champs en resultat de select pour affichage du dictionnaire
110 $tabfield = array();
111 $tabfield[25] = "label,lang,type_template,fk_user,private,position,topic,joinfiles,content";
112 if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
113  $tabfield[25] .= ',content_lines';
114 }
115 
116 // Nom des champs d'edition pour modification d'un enregistrement
117 $tabfieldvalue = array();
118 $tabfieldvalue[25] = "label,lang,type_template,fk_user,private,position,topic,joinfiles,content";
119 if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
120  $tabfieldvalue[25] .= ',content_lines';
121 }
122 
123 // Nom des champs dans la table pour insertion d'un enregistrement
124 $tabfieldinsert = array();
125 $tabfieldinsert[25] = "label,lang,type_template,fk_user,private,position,topic,joinfiles,content";
126 if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
127  $tabfieldinsert[25] .= ',content_lines';
128 }
129 $tabfieldinsert[25] .= ',entity'; // Must be at end because not into other arrays
130 
131 // Condition to show dictionary in setup page
132 $tabcond = array();
133 $tabcond[25] = true;
134 
135 // List of help for fields
136 // Set MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES to allow edit of template for lines
137 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
138 $formmail = new FormMail($db);
139 if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
140  $tmp = FormMail::getAvailableSubstitKey('formemail');
141  $tmp['__(AnyTranslationKey)__'] = 'Translation';
142  $helpsubstit = $langs->trans("AvailableVariables").':<br>';
143  $helpsubstitforlines = $langs->trans("AvailableVariables").':<br>';
144  foreach ($tmp as $key => $val) {
145  $helpsubstit .= $key.' -> '.$val.'<br>';
146  $helpsubstitforlines .= $key.' -> '.$val.'<br>';
147  }
148 } else {
149  $tmp = FormMail::getAvailableSubstitKey('formemailwithlines');
150  $tmp['__(AnyTranslationKey)__'] = 'Translation';
151  $helpsubstit = $langs->trans("AvailableVariables").':<br>';
152  $helpsubstitforlines = $langs->trans("AvailableVariables").':<br>';
153  foreach ($tmp as $key => $val) {
154  $helpsubstit .= $key.' -> '.$val.'<br>';
155  }
156  $tmp = FormMail::getAvailableSubstitKey('formemailforlines');
157  foreach ($tmp as $key => $val) {
158  $helpsubstitforlines .= $key.' -> '.$val.'<br>';
159  }
160 }
161 
162 
163 $tabhelp = array();
164 $tabhelp[25] = array(
165  'label'=>$langs->trans('EnterAnyCode'),
166  'topic'=>'<span class="small">'.$helpsubstit.'</span>',
167  'joinfiles'=>$langs->trans('AttachMainDocByDefault'),
168  'content'=>'<span class="small">'.$helpsubstit.'</span>',
169  'content_lines'=>'<span class="small">'.$helpsubstitforlines.'</span>',
170  'type_template'=>$langs->trans("TemplateForElement"),
171  'private'=>$langs->trans("TemplateIsVisibleByOwnerOnly"),
172  'position'=>$langs->trans("PositionIntoComboList")
173 );
174 
175 
176 // We save list of template email Dolibarr can manage. This list can found by a grep into code on "->param['models']"
177 $elementList = array();
178 // Add all and none after the sort
179 
180 $elementList['all'] = '-- '.dol_escape_htmltag($langs->trans("All")).' --';
181 $elementList['none'] = '-- '.dol_escape_htmltag($langs->trans("None")).' --';
182 $elementList['user'] = img_picto('', 'user', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToUser'));
183 if (isModEnabled('adherent') && !empty($user->rights->adherent->lire)) {
184  $elementList['member'] = img_picto('', 'object_member', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToMember'));
185 }
186 if (isModEnabled('recruitment') && !empty($user->rights->recruitment->recruitmentjobposition->read)) {
187  $elementList['recruitmentcandidature_send'] = img_picto('', 'recruitmentcandidature', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('RecruitmentCandidatures'));
188 }
189 if (isModEnabled("societe") && $user->hasRight('societe', 'lire')) {
190  $elementList['thirdparty'] = img_picto('', 'company', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToThirdparty'));
191 }
192 if (isModEnabled('project')) {
193  $elementList['project'] = img_picto('', 'project', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToProject'));
194 }
195 if (isModEnabled("propal") && !empty($user->rights->propal->lire)) {
196  $elementList['propal_send'] = img_picto('', 'propal', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendProposal'));
197 }
198 if (isModEnabled('commande') && !empty($user->rights->commande->lire)) {
199  $elementList['order_send'] = img_picto('', 'order', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendOrder'));
200 }
201 if (isModEnabled('facture') && !empty($user->rights->facture->lire)) {
202  $elementList['facture_send'] = img_picto('', 'bill', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendInvoice'));
203 }
204 if (isModEnabled("expedition")) {
205  $elementList['shipping_send'] = img_picto('', 'dolly', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendShipment'));
206 }
207 if (isModEnabled("reception")) {
208  $elementList['reception_send'] = img_picto('', 'dollyrevert', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendReception'));
209 }
210 if (isModEnabled('ficheinter')) {
211  $elementList['fichinter_send'] = img_picto('', 'intervention', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendIntervention'));
212 }
213 if (isModEnabled('supplier_proposal')) {
214  $elementList['supplier_proposal_send'] = img_picto('', 'propal', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendSupplierRequestForQuotation'));
215 }
216 if ((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->commande->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_order") && !empty($user->rights->supplier_order->lire))) {
217  $elementList['order_supplier_send'] = img_picto('', 'order', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendSupplierOrder'));
218 }
219 if ((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->facture->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_invoice") && !empty($user->rights->supplier_invoice->lire))) {
220  $elementList['invoice_supplier_send'] = img_picto('', 'bill', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendSupplierInvoice'));
221 }
222 if (isModEnabled('contrat') && !empty($user->rights->contrat->lire)) {
223  $elementList['contract'] = img_picto('', 'contract', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendContract'));
224 }
225 if (isModEnabled('ticket') && !empty($user->rights->ticket->read)) {
226  $elementList['ticket_send'] = img_picto('', 'ticket', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToTicket'));
227 }
228 if (isModEnabled('expensereport') && !empty($user->rights->expensereport->lire)) {
229  $elementList['expensereport_send'] = img_picto('', 'trip', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToExpenseReport'));
230 }
231 if (isModEnabled('agenda')) {
232  $elementList['actioncomm_send'] = img_picto('', 'action', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendEventPush'));
233 }
234 if (isModEnabled('eventorganization') && !empty($user->rights->eventorganization->read)) {
235  $elementList['conferenceorbooth'] = img_picto('', 'action', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendEventOrganization'));
236 }
237 if (!empty($conf->partnership->enabled) && !empty($user->rights->partnership->read)) {
238  $elementList['partnership_send'] = img_picto('', 'partnership', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToPartnership'));
239 }
240 
241 $parameters = array('elementList'=>$elementList);
242 $reshook = $hookmanager->executeHooks('emailElementlist', $parameters); // Note that $action and $object may have been modified by some hooks
243 if ($reshook == 0) {
244  foreach ($hookmanager->resArray as $item => $value) {
245  $elementList[$item] = $value;
246  }
247 }
248 
249 $id = 25;
250 
251 $acceptlocallinktomedia = (acceptLocalLinktoMedia() > 0 ? 1 : 0);
252 
253 // Security
254 if (!empty($user->socid)) {
255  accessforbidden();
256 }
257 
258 $permissiontoadd = 1;
259 $permissiontodelete = 1;
260 
261 
262 
263 /*
264  * Actions
265  */
266 
267 if (GETPOST('cancel', 'alpha')) {
268  $action = 'list';
269  $massaction = '';
270 }
271 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
272  $massaction = '';
273 }
274 
275 $parameters = array();
276 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
277 if ($reshook < 0) {
278  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
279 }
280 
281 if (empty($reshook)) {
282  // Selection of new fields
283  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
284 
285  // Purge search criteria
286  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
287  // All tests are required to be compatible with all browsers
288  $search_label = '';
289  $search_type_template = '';
290  $search_lang = '';
291  $search_fk_user = '';
292  $search_topic = '';
293  $toselect = array();
294  $search_array_options = array();
295  }
296 
297  // Actions add or modify an email template
298  if ((GETPOST('actionadd', 'alpha') || GETPOST('actionmodify', 'alpha')) && $permissiontoadd) {
299  $listfield = explode(',', str_replace(' ', '', $tabfield[$id]));
300  $listfieldinsert = explode(',', $tabfieldinsert[$id]);
301  $listfieldmodify = explode(',', $tabfieldinsert[$id]);
302  $listfieldvalue = explode(',', $tabfieldvalue[$id]);
303 
304  // Check that all fields are filled
305  $ok = 1;
306  foreach ($listfield as $f => $value) {
307  // Not mandatory fields
308  if ($value == 'joinfiles') {
309  continue;
310  }
311  if ($value == 'content') {
312  continue;
313  }
314  if ($value == 'content_lines') {
315  continue;
316  }
317 
318  // Rename some POST variables into a generic name
319  if (GETPOST('actionmodify', 'alpha') && $value == 'topic') {
320  $_POST['topic'] = GETPOST('topic-'.$rowid);
321  }
322 
323  if ((!GETPOSTISSET($value) || GETPOST($value) == '' || GETPOST($value) == '-1') && $value != 'lang' && $value != 'fk_user' && $value != 'position') {
324  $ok = 0;
325  $fieldnamekey = $listfield[$f];
326  // We take translate key of field
327  if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) {
328  $fieldnamekey = 'Code';
329  }
330  if ($fieldnamekey == 'code') {
331  $fieldnamekey = 'Code';
332  }
333  if ($fieldnamekey == 'note') {
334  $fieldnamekey = 'Note';
335  }
336  if ($fieldnamekey == 'type_template') {
337  $fieldnamekey = 'TypeOfTemplate';
338  }
339  if ($fieldnamekey == 'fk_user') {
340  $fieldnamekey = 'Owner';
341  }
342  if ($fieldnamekey == 'private') {
343  $fieldnamekey = 'Private';
344  }
345  if ($fieldnamekey == 'position') {
346  $fieldnamekey = 'Position';
347  }
348  if ($fieldnamekey == 'topic') {
349  $fieldnamekey = 'Topic';
350  }
351 
352  setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
353  $action = 'create';
354  }
355  }
356 
357  // If previous test is ok action is add, we add the line
358  if ($ok && GETPOST('actionadd')) {
359  // Add new entry
360  $sql = "INSERT INTO ".$tabname[$id]." (";
361  // List of fields
362  $sql .= $tabfieldinsert[$id];
363  $sql .= ", active, enabled)";
364  $sql .= " VALUES(";
365 
366  // List of values
367  $i = 0;
368  foreach ($listfieldinsert as $f => $value) {
369  $keycode = isset($listfieldvalue[$i]) ? $listfieldvalue[$i] : "";
370  if ($value == 'lang') {
371  $keycode = 'langcode';
372  }
373  if (empty($keycode)) {
374  $keycode = $value;
375  }
376 
377  // Clean input variables
378  if ($value == 'entity') {
379  $_POST[$keycode] = $conf->entity;
380  }
381  if ($value == 'fk_user' && !($_POST[$keycode] > 0)) {
382  $_POST[$keycode] = '';
383  }
384  if ($value == 'private' && !is_numeric($_POST[$keycode])) {
385  $_POST[$keycode] = '0';
386  }
387  if ($value == 'position' && !is_numeric($_POST[$keycode])) {
388  $_POST[$keycode] = '1';
389  }
390  //var_dump($keycode.' '.$value);
391 
392  if ($i) {
393  $sql .= ", ";
394  }
395  if (GETPOST($keycode) == '' && $keycode != 'langcode') {
396  $sql .= "null"; // langcode must be '' if not defined so the unique key that include lang will work
397  } elseif (GETPOST($keycode) == '0' && $keycode == 'langcode') {
398  $sql .= "''"; // langcode must be '' if not defined so the unique key that include lang will work
399  } elseif ($keycode == 'fk_user') {
400  if (!$user->admin) { // A non admin user can only edit its own template
401  $sql .= " ".((int) $user->id);
402  } else {
403  $sql .= " ".((int) GETPOST($keycode, 'int'));
404  }
405  } elseif ($keycode == 'content') {
406  $sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
407  } elseif (in_array($keycode, array('joinfiles', 'private', 'position', 'entity'))) {
408  $sql .= (int) GETPOST($keycode, 'int');
409  } else {
410  $sql .= "'".$db->escape(GETPOST($keycode, 'alphanohtml'))."'";
411  }
412  $i++;
413  }
414  $sql .= ", 1, 1)";
415 
416  dol_syslog("actionadd", LOG_DEBUG);
417  $result = $db->query($sql);
418  if ($result) { // Add is ok
419  setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
420  $_POST = array('id'=>$id); // Clean $_POST array, we keep only id
421  } else {
422  if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
423  setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
424  } else {
425  dol_print_error($db);
426  }
427  $action = 'create';
428  }
429  }
430 
431  // We modify the line
432  if ($ok && GETPOST('actionmodify')) {
433  $rowidcol = "rowid";
434 
435  // Modify entry
436  $sql = "UPDATE ".$tabname[$id]." SET ";
437  // Modifie valeur des champs
438  $i = 0;
439  foreach ($listfieldmodify as $field) {
440  if ($field == 'entity') {
441  // entity not present on listfieldmodify array
442  $keycode = $field;
443  $_POST[$keycode] = $conf->entity;
444  } else {
445  $keycode = $listfieldvalue[$i];
446  }
447 
448  if ($field == 'lang') {
449  $keycode = 'langcode';
450  }
451  if (empty($keycode)) {
452  $keycode = $field;
453  }
454 
455  // Rename some POST variables into a generic name
456  if ($field == 'fk_user' && !($_POST['fk_user'] > 0)) {
457  $_POST['fk_user'] = '';
458  }
459  if ($field == 'topic') {
460  $_POST['topic'] = $_POST['topic-'.$rowid];
461  }
462  if ($field == 'joinfiles') {
463  $_POST['joinfiles'] = $_POST['joinfiles-'.$rowid];
464  }
465  if ($field == 'content') {
466  $_POST['content'] = $_POST['content-'.$rowid];
467  }
468  if ($field == 'content_lines') {
469  $_POST['content_lines'] = $_POST['content_lines-'.$rowid];
470  }
471 
472  if ($i) {
473  $sql .= ", ";
474  }
475  $sql .= $field."=";
476 
477  if (GETPOST($keycode) == '' || ($keycode != 'langcode' && $keycode != 'position' && $keycode != 'private' && !GETPOST($keycode))) {
478  $sql .= "null"; // langcode,... must be '' if not defined so the unique key that include lang will work
479  } elseif (GETPOST($keycode) == '0' && $keycode == 'langcode') {
480  $sql .= "''"; // langcode must be '' if not defined so the unique key that include lang will work
481  } elseif ($keycode == 'fk_user') {
482  if (!$user->admin) { // A non admin user can only edit its own template
483  $sql .= " ".((int) $user->id);
484  } else {
485  $sql .= " ".((int) GETPOST($keycode, 'int'));
486  }
487  } elseif ($keycode == 'content') {
488  $sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
489  } elseif (in_array($keycode, array('joinfiles', 'private', 'position'))) {
490  $sql .= (int) GETPOST($keycode, 'int');
491  } else {
492  $sql .= "'".$db->escape(GETPOST($keycode, 'alphanohtml'))."'";
493  }
494 
495  $i++;
496  }
497 
498  $sql .= " WHERE ".$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, joinfiles, 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_topic) {
602  $sql .= natural_search('topic', $search_topic);
603 }
604 // If sort order is "country", we use country_code instead
605 if ($sortfield == 'country') {
606  $sortfield = 'country_code';
607 }
608 $sql .= $db->order($sortfield, $sortorder);
609 $sql .= $db->plimit($listlimit + 1, $offset);
610 //print $sql;
611 
612 // Output page
613 // --------------------------------------------------------------------
614 
615 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
616 
617 $arrayofselected = is_array($toselect) ? $toselect : array();
618 
619 $param = '';
620 if (!empty($mode)) {
621  $param .= '&mode='.urlencode($mode);
622 }
623 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
624  $param .= '&contextpage='.urlencode($contextpage);
625 }
626 if ($limit > 0 && $limit != $conf->liste_limit) {
627  $param .= '&limit='.urlencode($limit);
628 }
629 if (!empty($search) && is_array($search)) {
630  foreach ($search as $key => $val) {
631  if (is_array($search[$key]) && count($search[$key])) {
632  foreach ($search[$key] as $skey) {
633  if ($skey != '') {
634  $param .= '&search_'.$key.'[]='.urlencode($skey);
635  }
636  }
637  } elseif ($search[$key] != '') {
638  $param .= '&search_'.$key.'='.urlencode($search[$key]);
639  }
640  }
641 }
642 if ($optioncss != '') {
643  $param .= '&optioncss='.urlencode($optioncss);
644 }
645 // Add $param from extra fields
646 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
647 // Add $param from hooks
648 $parameters = array();
649 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
650 $param .= $hookmanager->resPrint;
651 
652 
653 $linkback = '';
654 $titlepicto = 'title_setup';
655 
656 
657 $url = DOL_URL_ROOT.'/admin/mails_templates.php?action=create';
658 $newcardbutton = dolGetButtonTitle($langs->trans('NewEMailTemplate'), '', 'fa fa-plus-circle', $url, '', $permissiontoadd);
659 
660 
661 if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
662  print load_fiche_titre($title, '', $titlepicto);
663 } else {
664  print load_fiche_titre($title, $newcardbutton, $titlepicto);
665 }
666 
667 if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
668  $head = email_admin_prepare_head();
669 
670  print dol_get_fiche_head($head, 'templates', '', -1);
671 
672  if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
673  print load_fiche_titre('', $newcardbutton, '');
674  }
675 }
676 
677 
678 // Confirm deletion of record
679 if ($action == 'delete') {
680  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);
681 }
682 
683 
684 $fieldlist = explode(',', $tabfield[$id]);
685 
686 if ($action == 'create') {
687  // If data was already input, we define them in obj to populate input fields.
688  $obj = new stdClass();
689  $obj->label = GETPOST('label');
690  $obj->lang = GETPOST('lang');
691  $obj->type_template = GETPOST('type_template');
692  $obj->fk_user = GETPOST('fk_user', 'int');
693  $obj->private = GETPOST('private', 'int');
694  $obj->position = GETPOST('position');
695  $obj->topic = GETPOST('topic');
696  $obj->joinfiles = GETPOST('joinfiles');
697  $obj->content = GETPOST('content', 'restricthtml');
698 
699  // Form to add a new line
700  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
701  print '<input type="hidden" name="token" value="'.newToken().'">';
702  print '<input type="hidden" name="action" value="add">';
703  print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
704 
705  print '<div class="div-table-responsive-no-min">';
706  print '<table class="noborder centpercent">';
707 
708  // Line to enter new values (title)
709  print '<tr class="liste_titre">';
710  foreach ($fieldlist as $field => $value) {
711  // Determine le nom du champ par rapport aux noms possibles
712  // dans les dictionnaires de donnees
713  $valuetoshow = ucfirst($fieldlist[$field]); // Par defaut
714  $valuetoshow = $langs->trans($valuetoshow); // try to translate
715  $align = "left";
716  if ($fieldlist[$field] == 'fk_user') {
717  $valuetoshow = $langs->trans("Owner");
718  }
719  if ($fieldlist[$field] == 'lang') {
720  $valuetoshow = (!getDolGlobalInt('MAIN_MULTILANGS') ? '&nbsp;' : $langs->trans("Language"));
721  }
722  if ($fieldlist[$field] == 'type') {
723  $valuetoshow = $langs->trans("Type");
724  }
725  if ($fieldlist[$field] == 'code') {
726  $valuetoshow = $langs->trans("Code");
727  }
728  if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
729  $valuetoshow = $langs->trans("Code");
730  }
731  if ($fieldlist[$field] == 'type_template') {
732  $valuetoshow = $langs->trans("TypeOfTemplate"); $align = "center";
733  }
734  if ($fieldlist[$field] == 'private') {
735  $align = 'center';
736  }
737  if ($fieldlist[$field] == 'position') {
738  $align = 'center';
739  }
740 
741  if ($fieldlist[$field] == 'topic') {
742  $valuetoshow = '';
743  }
744  if ($fieldlist[$field] == 'joinfiles') {
745  $valuetoshow = '';
746  }
747  if ($fieldlist[$field] == 'content') {
748  $valuetoshow = '';
749  }
750  if ($fieldlist[$field] == 'content_lines') {
751  $valuetoshow = '';
752  }
753  if ($valuetoshow != '') {
754  print '<th class="'.$align.'">';
755  if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
756  print '<a href="'.$tabhelp[$id][$value].'" target="_blank" rel="noopener noreferrer">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
757  } elseif (!empty($tabhelp[$id][$value])) {
758  if (in_array($value, array('topic'))) {
759  print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, $value); // Tooltip on click
760  } else {
761  print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2); // Tooltip on hover
762  }
763  } else {
764  print $valuetoshow;
765  }
766  print '</th>';
767  }
768  }
769  print '<th>';
770  print '<input type="hidden" name="id" value="'.$id.'">';
771  print '</th>';
772  print '</tr>';
773 
774  $tmpaction = 'create';
775  $parameters = array(
776  'fieldlist' => $fieldlist,
777  'tabname' => $tabname[$id]
778  );
779  $reshook = $hookmanager->executeHooks('createEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
780  $error = $hookmanager->error;
781  $errors = $hookmanager->errors;
782 
783 
784  // Line to enter new values (input fields)
785  print '<tr class="oddeven">';
786 
787  if (empty($reshook)) {
788  if ($action == 'edit') {
789  fieldList($fieldlist, $obj, $tabname[$id], 'hide');
790  } else {
791  fieldList($fieldlist, $obj, $tabname[$id], 'add');
792  }
793  }
794 
795  print '<td class="right">';
796  print '</td>';
797  print "</tr>";
798 
799  // Show fields for topic, join files and body
800  $fieldsforcontent = array('topic', 'joinfiles', 'content');
801  if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
802  $fieldsforcontent = array('topic', 'joinfiles', 'content', 'content_lines');
803  }
804  foreach ($fieldsforcontent as $tmpfieldlist) {
805  print '<tr class="impair nodrag nodrop nohover"><td colspan="7" class="nobottom">';
806 
807  // Label
808  if ($tmpfieldlist == 'topic') {
809  print '<strong>'.$form->textwithpicto($langs->trans("Topic"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
810  }
811  if ($tmpfieldlist == 'joinfiles') {
812  print '<strong>'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
813  }
814  if ($tmpfieldlist == 'content') {
815  print $form->textwithpicto($langs->trans("Content"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
816  }
817  if ($tmpfieldlist == 'content_lines') {
818  print $form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
819  }
820 
821  // Input field
822  if ($tmpfieldlist == 'topic') {
823  print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '').'">';
824  } elseif ($tmpfieldlist == 'joinfiles') {
825  print $form->selectyesno($tmpfieldlist, (isset($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '0'), 1, false, 0, 1);
826  } else {
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', false, $acceptlocallinktomedia, $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 }
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, 'maxwidth100');
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, '', 'maxwidth125', 1);
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, '', 'minwidth100 maxwidth125', 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 main 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 $form->selectyesno($tmpfieldlist.'-'.$rowid, (isset($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '0'), 1, false, 0, 1);
1062  }
1063 
1064  if ($tmpfieldlist == 'content') {
1065  print $form->textwithpicto($langs->trans("Content"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
1066  $okforextended = true;
1067  if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
1068  $okforextended = false;
1069  }
1070 
1071  $doleditor = new DolEditor($tmpfieldlist.'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 500, 'dolibarr_mailings', 'In', 0, $acceptlocallinktomedia, $okforextended, ROWS_6, '90%');
1072  print $doleditor->Create(1);
1073  }
1074  if ($tmpfieldlist == 'content_lines') {
1075  print $form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
1076  $okforextended = true;
1077  if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
1078  $okforextended = false;
1079  }
1080  $doleditor = new DolEditor($tmpfieldlist.'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 140, 'dolibarr_mailings', 'In', 0, $acceptlocallinktomedia, $okforextended, ROWS_6, '90%');
1081  print $doleditor->Create(1);
1082  }
1083  print '</td>';
1084  print '<td></td>';
1085  print '<td></td>';
1086  }
1087  }
1088 
1089  print "</tr>\n";
1090 
1091  $nbqualified++;
1092  } else {
1093  // If template is for a module, check module is enabled.
1094  if ($obj->module) {
1095  $tempmodulekey = $obj->module;
1096  if (empty($conf->$tempmodulekey) || empty($conf->$tempmodulekey->enabled)) {
1097  $i++;
1098  continue;
1099  }
1100  }
1101 
1102  $keyforobj = 'type_template';
1103  if (!in_array($obj->$keyforobj, array_keys($elementList))) {
1104  $i++;
1105  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)
1106  }
1107  // Test on 'enabled'
1108  if (!dol_eval($obj->enabled, 1, 1, '1')) {
1109  $i++;
1110  continue; // Email template not qualified
1111  }
1112 
1113  $nbqualified++;
1114 
1115  print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
1116 
1117  $tmpaction = 'view';
1118  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
1119  $reshook = $hookmanager->executeHooks('viewEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1120 
1121  $error = $hookmanager->error; $errors = $hookmanager->errors;
1122 
1123  if (empty($reshook)) {
1124  foreach ($fieldlist as $field => $value) {
1125  if (in_array($fieldlist[$field], array('content', 'content_lines'))) {
1126  continue;
1127  }
1128  $showfield = 1;
1129  $align = "";
1130  $class = "tddict";
1131  $title = '';
1132  $valuetoshow = $obj->{$fieldlist[$field]};
1133  if ($value == 'label' || $value == 'topic') {
1134  if ($langs->trans($valuetoshow) != $valuetoshow) {
1135  $valuetoshow = $langs->trans($valuetoshow);
1136  }
1137  $valuetoshow = dol_escape_htmltag($valuetoshow);
1138  }
1139  if ($value == 'label') {
1140  $class .= ' tdoverflowmax100';
1141  }
1142  if ($value == 'topic') {
1143  $class .= ' tdoverflowmax200 small';
1144  }
1145  if ($value == 'type_template') {
1146  $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
1147  $align = "center";
1148  }
1149  if ($value == 'lang' && $valuetoshow) {
1150  $valuetoshow = $valuetoshow.' - '.$langs->trans("Language_".$valuetoshow);
1151  }
1152  if ($value == 'fk_user') {
1153  if ($valuetoshow > 0) {
1154  $fuser = new User($db);
1155  $fuser->fetch($valuetoshow);
1156  $valuetoshow = $fuser->getNomUrl(1);
1157  }
1158  }
1159  if ($value == 'private') {
1160  $align = "center";
1161  if ($valuetoshow) {
1162  $valuetoshow = yn($valuetoshow);
1163  } else {
1164  $valuetoshow = '';
1165  }
1166  }
1167  if ($value == 'position') {
1168  $align = "center";
1169  }
1170  if ($value == 'joinfiles') {
1171  $align = "center";
1172  if ($valuetoshow) {
1173  $valuetoshow = yn(1);
1174  } else {
1175  $valuetoshow = '';
1176  }
1177  }
1178  if ($align) {
1179  $class .= ' '.$align;
1180  }
1181 
1182  // Show value for field
1183  if ($showfield) {
1184  print '<!-- '.$fieldlist[$field].' -->';
1185  print '<td class="'.$class.'"';
1186  if (in_array($value, array('code', 'label', 'topic'))) {
1187  print ' title="'.dol_escape_htmltag($valuetoshow).'"';
1188  }
1189  print '>';
1190  print $valuetoshow;
1191  print '</td>';
1192  }
1193  }
1194  }
1195 
1196  // Can an entry be erased or disabled ?
1197  $iserasable = 1; $canbedisabled = 1; $canbemodified = 1; // true by default
1198  if (!$user->admin && $obj->fk_user != $user->id) {
1199  $iserasable = 0;
1200  $canbedisabled = 0;
1201  $canbemodified = 0;
1202  }
1203 
1204  $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) : '');
1205  if ($param) {
1206  $url .= '&'.$param;
1207  }
1208 
1209  // Status / Active
1210  print '<td class="center nowrap">';
1211  if ($canbedisabled) {
1212  print '<a class="reposition" href="'.$url.'&action='.$acts[$obj->active].'&token='.newToken().'">'.$actl[$obj->active].'</a>';
1213  } else {
1214  print '<span class="opacitymedium">'.$actl[$obj->active].'</span>';
1215  }
1216  print "</td>";
1217 
1218  // Modify link / Delete link
1219  print '<td class="center nowraponall" width="64">';
1220  if ($canbemodified) {
1221  print '<a class="reposition editfielda" href="'.$url.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
1222  }
1223  if ($iserasable) {
1224  print '<a class="marginleftonly" href="'.$url.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
1225  //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
1226  }
1227  print '</td>';
1228 
1229  print "</tr>\n";
1230  }
1231  }
1232 
1233  $i++;
1234  }
1235 }
1236 
1237 // If no record found
1238 if ($nbqualified == 0) {
1239  $colspan = 10;
1240  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1241 }
1242 
1243 print '</table>';
1244 print '</div>';
1245 
1246 print '</form>';
1247 
1248 
1249 if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
1250  print dol_get_fiche_end();
1251 }
1252 
1253 
1254 // End of page
1255 llxFooter();
1256 $db->close();
1257 
1258 
1268 function fieldList($fieldlist, $obj = '', $tabname = '', $context = '')
1269 {
1270  global $conf, $langs, $user, $db;
1271  global $form;
1272  global $elementList;
1273 
1274  $formadmin = new FormAdmin($db);
1275 
1276  foreach ($fieldlist as $field => $value) {
1277  if ($value == 'fk_user') {
1278  print '<td>';
1279  if ($user->admin) {
1280  print $form->select_dolusers(empty($obj->{$value}) ? '' : $obj->{$value}, 'fk_user', 1, null, 0, ($user->admin ? '' : 'hierarchyme'), null, 0, 0, 0, '', 0, '', 'minwidth150 maxwidth200');
1281  } else {
1282  if ($context == 'add') { // I am not admin and we show the add form
1283  print $user->getNomUrl(1); // Me
1284  $forcedvalue = $user->id;
1285  } else {
1286  if ($obj && !empty($obj->{$value}) && $obj->{$value} > 0) {
1287  $fuser = new User($db);
1288  $fuser->fetch($obj->{$value});
1289  print $fuser->getNomUrl(1);
1290  $forcedvalue = $fuser->id;
1291  } else {
1292  $forcedvalue = $obj->{$value};
1293  }
1294  }
1295  $keyname = $value;
1296  print '<input type="hidden" value="'.$forcedvalue.'" name="'.$keyname.'">';
1297  }
1298  print '</td>';
1299  } elseif ($value == 'lang') {
1300  print '<td>';
1301  if (getDolGlobalInt('MAIN_MULTILANGS')) {
1302  $selectedlang = GETPOSTISSET('langcode') ?GETPOST('langcode', 'aZ09') : $langs->defaultlang;
1303  if ($context == 'edit') {
1304  $selectedlang = $obj->lang;
1305  }
1306  print $formadmin->select_language($selectedlang, 'langcode', 0, null, 1, 0, 0, 'maxwidth150');
1307  } else {
1308  if (!empty($obj->lang)) {
1309  print $obj->lang.' - '.$langs->trans('Language_'.$obj->lang);
1310  }
1311  $keyname = $value;
1312  if ($keyname == 'lang') {
1313  $keyname = 'langcode'; // Avoid conflict with lang param
1314  }
1315  print '<input type="hidden" value="'.(empty($obj->lang) ? '' : $obj->lang).'" name="'.$keyname.'">';
1316  }
1317  print '</td>';
1318  } elseif ($value == 'type_template') {
1319  // Le type de template
1320  print '<td class="center">';
1321  if ($context == 'edit' && !empty($obj->type_template) && !in_array($obj->type_template, array_keys($elementList))) {
1322  // Current template type is an unknown type, so we must keep it as it is.
1323  print '<input type="hidden" name="type_template" value="'.$obj->type_template.'">';
1324  print $obj->type_template;
1325  } else {
1326  print $form->selectarray('type_template', $elementList, (!empty($obj->type_template) ? $obj->type_template:''), 1, 0, 0, '', 0, 0, 0, '', 'minwidth150', 1, '', 0, 1);
1327  }
1328  print '</td>';
1329  } elseif ($context == 'add' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1330  continue;
1331  } elseif ($context == 'edit' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1332  continue;
1333  } elseif ($context == 'hide' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1334  continue;
1335  } else {
1336  $size = ''; $class = ''; $classtd = '';
1337  if ($value == 'code') {
1338  $class = 'maxwidth100';
1339  }
1340  if ($value == 'label') {
1341  $class = 'maxwidth200';
1342  }
1343  if ($value == 'private') {
1344  $class = 'maxwidth50'; $classtd = 'center';
1345  }
1346  if ($value == 'position') {
1347  $class = 'maxwidth50 center'; $classtd = 'center';
1348  }
1349  if ($value == 'libelle') {
1350  $class = 'quatrevingtpercent';
1351  }
1352  if ($value == 'topic') {
1353  $class = 'quatrevingtpercent';
1354  }
1355  if ($value == 'sortorder' || $value == 'sens' || $value == 'category_type') {
1356  $size = 'size="2" ';
1357  }
1358 
1359  print '<td'.($classtd ? ' class="'.$classtd.'"' : '').'>';
1360  if ($value == 'private') {
1361  if (empty($user->admin)) {
1362  print $form->selectyesno($value, '1', 1);
1363  } else {
1364  print $form->selectyesno($value, (isset($obj->{$value}) ? $obj->{$value}:''), 1);
1365  }
1366  } else {
1367  print '<input type="text" '.$size.'class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->{$value}) ? $obj->{$value}:'').'" name="'. $value .'">';
1368  }
1369  print '</td>';
1370  }
1371  }
1372 }
yn
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Definition: functions.lib.php:6675
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:1493
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
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:5201
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5360
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:520
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:4993
img_help
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
Definition: functions.lib.php:4630
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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:1268
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4538
$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:118
acceptLocalLinktoMedia
acceptLocalLinktoMedia()
Check the syntax of some PHP code.
Definition: functions2.lib.php:2863
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:4024
llxHeader
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
img_delete
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
Definition: functions.lib.php:4578
$resql
if(isModEnabled('facture') &&!empty($user->rights->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') &&!empty($user->rights->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)) $resql
Social contributions to pay.
Definition: index.php:745
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:10986
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1628
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:1858
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11259
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2054
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
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:421
email_admin_prepare_head
email_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: admin.lib.php:2016
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:9765
dol_eval
dol_eval($s, $returnvalue=0, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
Definition: functions.lib.php:8924
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:5559
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2951
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8452
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
Definition: security.lib.php:1103
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:96
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:1579