dolibarr  17.0.4
mails_templates.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
7  * Copyright (C) 2011-2018 Philippe Grand <philippe.grand@atoo-net.com>
8  * Copyright (C) 2011 Remy Younes <ryounes@gmail.com>
9  * Copyright (C) 2012-2015 Marcos García <marcosgdf@gmail.com>
10  * Copyright (C) 2012 Christophe Battarel <christophe.battarel@ltairis.fr>
11  * Copyright (C) 2011-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
12  * Copyright (C) 2015 Ferran Marcet <fmarcet@2byte.es>
13  * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
14  * Copyright (C) 2018-2023 Frédéric France <frederic.france@netlogic.fr>
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program. If not, see <https://www.gnu.org/licenses/>.
28  */
29 
36 // Load Dolibarr environment
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 (in_array($value, ['joinfiles', 'content', 'content_lines', 'module'])) {
309  continue;
310  }
311 
312  // Rename some POST variables into a generic name
313  if (GETPOST('actionmodify', 'alpha') && $value == 'topic') {
314  $_POST['topic'] = GETPOST('topic-'.$rowid);
315  }
316 
317  if ((!GETPOSTISSET($value) || GETPOST($value) == '' || GETPOST($value) == '-1') && $value != 'lang' && $value != 'fk_user' && $value != 'position') {
318  $ok = 0;
319  $fieldnamekey = $listfield[$f];
320  // We take translate key of field
321  if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) {
322  $fieldnamekey = 'Code';
323  }
324  if ($fieldnamekey == 'code') {
325  $fieldnamekey = 'Code';
326  }
327  if ($fieldnamekey == 'note') {
328  $fieldnamekey = 'Note';
329  }
330  if ($fieldnamekey == 'type_template') {
331  $fieldnamekey = 'TypeOfTemplate';
332  }
333  if ($fieldnamekey == 'fk_user') {
334  $fieldnamekey = 'Owner';
335  }
336  if ($fieldnamekey == 'private') {
337  $fieldnamekey = 'Private';
338  }
339  if ($fieldnamekey == 'position') {
340  $fieldnamekey = 'Position';
341  }
342  if ($fieldnamekey == 'topic') {
343  $fieldnamekey = 'Topic';
344  }
345 
346  setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
347  $action = 'create';
348  }
349  }
350 
351  // If previous test is ok action is add, we add the line
352  if ($ok && GETPOST('actionadd')) {
353  // Add new entry
354  $sql = "INSERT INTO ".$tabname[$id]." (";
355  // List of fields
356  $sql .= $tabfieldinsert[$id];
357  $sql .= ", active, enabled)";
358  $sql .= " VALUES(";
359 
360  // List of values
361  $i = 0;
362  foreach ($listfieldinsert as $f => $value) {
363  $keycode = isset($listfieldvalue[$i]) ? $listfieldvalue[$i] : "";
364  if ($value == 'lang') {
365  $keycode = 'langcode';
366  }
367  if (empty($keycode)) {
368  $keycode = $value;
369  }
370 
371  // Clean input variables
372  if ($value == 'entity') {
373  $_POST[$keycode] = $conf->entity;
374  }
375  if ($value == 'fk_user' && !($_POST[$keycode] > 0)) {
376  $_POST[$keycode] = '';
377  }
378  if ($value == 'private' && !is_numeric($_POST[$keycode])) {
379  $_POST[$keycode] = '0';
380  }
381  if ($value == 'position' && !is_numeric($_POST[$keycode])) {
382  $_POST[$keycode] = '1';
383  }
384  //var_dump($keycode.' '.$value);
385 
386  if ($i) {
387  $sql .= ", ";
388  }
389  if (GETPOST($keycode) == '' && $keycode != 'langcode') {
390  $sql .= "null"; // langcode must be '' if not defined so the unique key that include lang will work
391  } elseif (GETPOST($keycode) == '0' && $keycode == 'langcode') {
392  $sql .= "''"; // langcode must be '' if not defined so the unique key that include lang will work
393  } elseif ($keycode == 'fk_user') {
394  if (!$user->admin) { // A non admin user can only edit its own template
395  $sql .= " ".((int) $user->id);
396  } else {
397  $sql .= " ".((int) GETPOST($keycode, 'int'));
398  }
399  } elseif ($keycode == 'content') {
400  $sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
401  } elseif (in_array($keycode, array('joinfiles', 'private', 'position', 'entity'))) {
402  $sql .= (int) GETPOST($keycode, 'int');
403  } else {
404  $sql .= "'".$db->escape(GETPOST($keycode, 'alphanohtml'))."'";
405  }
406  $i++;
407  }
408  $sql .= ", 1, 1)";
409 
410  dol_syslog("actionadd", LOG_DEBUG);
411  $result = $db->query($sql);
412  if ($result) { // Add is ok
413  setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
414  $_POST = array('id'=>$id); // Clean $_POST array, we keep only id
415  } else {
416  if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
417  setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
418  } else {
419  dol_print_error($db);
420  }
421  $action = 'create';
422  }
423  }
424 
425  // We modify the line
426  if ($ok && GETPOST('actionmodify')) {
427  $rowidcol = "rowid";
428 
429  // Modify entry
430  $sql = "UPDATE ".$tabname[$id]." SET ";
431  // Modifie valeur des champs
432  $i = 0;
433  foreach ($listfieldmodify as $field) {
434  if ($field == 'entity') {
435  // entity not present on listfieldmodify array
436  $keycode = $field;
437  $_POST[$keycode] = $conf->entity;
438  } else {
439  $keycode = $listfieldvalue[$i];
440  }
441 
442  if ($field == 'lang') {
443  $keycode = 'langcode';
444  }
445  if (empty($keycode)) {
446  $keycode = $field;
447  }
448 
449  // Rename some POST variables into a generic name
450  if ($field == 'fk_user' && !($_POST['fk_user'] > 0)) {
451  $_POST['fk_user'] = '';
452  }
453  if ($field == 'topic') {
454  $_POST['topic'] = $_POST['topic-'.$rowid];
455  }
456  if ($field == 'joinfiles') {
457  $_POST['joinfiles'] = $_POST['joinfiles-'.$rowid];
458  }
459  if ($field == 'content') {
460  $_POST['content'] = $_POST['content-'.$rowid];
461  }
462  if ($field == 'content_lines') {
463  $_POST['content_lines'] = $_POST['content_lines-'.$rowid];
464  }
465 
466  if ($i) {
467  $sql .= ", ";
468  }
469  $sql .= $field."=";
470 
471  if (GETPOST($keycode) == '' || ($keycode != 'langcode' && $keycode != 'position' && $keycode != 'private' && !GETPOST($keycode))) {
472  $sql .= "null"; // langcode,... must be '' if not defined so the unique key that include lang will work
473  } elseif (GETPOST($keycode) == '0' && $keycode == 'langcode') {
474  $sql .= "''"; // langcode must be '' if not defined so the unique key that include lang will work
475  } elseif ($keycode == 'fk_user') {
476  if (!$user->admin) { // A non admin user can only edit its own template
477  $sql .= " ".((int) $user->id);
478  } else {
479  $sql .= " ".((int) GETPOST($keycode, 'int'));
480  }
481  } elseif ($keycode == 'content') {
482  $sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
483  } elseif (in_array($keycode, array('joinfiles', 'private', 'position'))) {
484  $sql .= (int) GETPOST($keycode, 'int');
485  } else {
486  $sql .= "'".$db->escape(GETPOST($keycode, 'alphanohtml'))."'";
487  }
488 
489  $i++;
490  }
491 
492  $sql .= " WHERE ".$rowidcol." = ".((int) $rowid);
493  if (!$user->admin) { // A non admin user can only edit its own template
494  $sql .= " AND fk_user = ".((int) $user->id);
495  }
496  //print $sql;exit;
497  dol_syslog("actionmodify", LOG_DEBUG);
498  //print $sql;
499  $resql = $db->query($sql);
500  if ($resql) {
501  setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
502  } else {
503  setEventMessages($db->error(), null, 'errors');
504  $action = 'edit';
505  }
506  }
507  }
508 
509  if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) { // delete
510  $rowidcol = "rowid";
511 
512  $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol." = ".((int) $rowid);
513  if (!$user->admin) { // A non admin user can only edit its own template
514  $sql .= " AND fk_user = ".((int) $user->id);
515  }
516  dol_syslog("delete", LOG_DEBUG);
517  $result = $db->query($sql);
518  if (!$result) {
519  if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
520  setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
521  } else {
522  dol_print_error($db);
523  }
524  }
525  }
526 
527  // activate
528  if ($action == $acts[0] && $permissiontoadd) {
529  $rowidcol = "rowid";
530 
531  $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE rowid = ".((int) $rowid);
532 
533  $result = $db->query($sql);
534  if (!$result) {
535  dol_print_error($db);
536  }
537  }
538 
539  // disable
540  if ($action == $acts[1] && $permissiontoadd) {
541  $rowidcol = "rowid";
542 
543  $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE rowid = ".((int) $rowid);
544 
545  $result = $db->query($sql);
546  if (!$result) {
547  dol_print_error($db);
548  }
549  }
550 }
551 
552 
553 /*
554  * View
555  */
556 
557 $form = new Form($db);
558 
559 $now = dol_now();
560 
561 $formadmin = new FormAdmin($db);
562 
563 //$help_url = "EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
564 $help_url = '';
565 if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
566  $title = $langs->trans("EMailsSetup");
567 } else {
568  $title = $langs->trans("EMailTemplates");
569 }
570 $morejs = array();
571 $morecss = array();
572 
573 $sql = "SELECT rowid as rowid, module, label, type_template, lang, fk_user, private, position, topic, joinfiles, content_lines, content, enabled, active";
574 $sql .= " FROM ".MAIN_DB_PREFIX."c_email_templates";
575 $sql .= " WHERE entity IN (".getEntity('email_template').")";
576 if (!$user->admin) {
577  $sql .= " AND (private = 0 OR (private = 1 AND fk_user = ".((int) $user->id)."))"; // Show only public and private to me
578  $sql .= " AND (active = 1 OR fk_user = ".((int) $user->id).")"; // Show only active or owned by me
579 }
580 if (!getDolGlobalInt('MAIN_MULTILANGS')) {
581  $sql .= " AND (lang = '".$db->escape($langs->defaultlang)."' OR lang IS NULL OR lang = '')";
582 }
583 if ($search_label) {
584  $sql .= natural_search('label', $search_label);
585 }
586 if ($search_type_template != '' && $search_type_template != '-1') {
587  $sql .= natural_search('type_template', $search_type_template);
588 }
589 if ($search_lang) {
590  $sql .= natural_search('lang', $search_lang);
591 }
592 if ($search_fk_user != '' && $search_fk_user != '-1') {
593  $sql .= natural_search('fk_user', $search_fk_user, 2);
594 }
595 if ($search_topic) {
596  $sql .= natural_search('topic', $search_topic);
597 }
598 // If sort order is "country", we use country_code instead
599 if ($sortfield == 'country') {
600  $sortfield = 'country_code';
601 }
602 $sql .= $db->order($sortfield, $sortorder);
603 $sql .= $db->plimit($listlimit + 1, $offset);
604 //print $sql;
605 
606 // Output page
607 // --------------------------------------------------------------------
608 
609 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
610 
611 $arrayofselected = is_array($toselect) ? $toselect : array();
612 
613 $param = '';
614 if (!empty($mode)) {
615  $param .= '&mode='.urlencode($mode);
616 }
617 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
618  $param .= '&contextpage='.urlencode($contextpage);
619 }
620 if ($limit > 0 && $limit != $conf->liste_limit) {
621  $param .= '&limit='.urlencode($limit);
622 }
623 if (!empty($search) && is_array($search)) {
624  foreach ($search as $key => $val) {
625  if (is_array($search[$key]) && count($search[$key])) {
626  foreach ($search[$key] as $skey) {
627  if ($skey != '') {
628  $param .= '&search_'.$key.'[]='.urlencode($skey);
629  }
630  }
631  } elseif ($search[$key] != '') {
632  $param .= '&search_'.$key.'='.urlencode($search[$key]);
633  }
634  }
635 }
636 if ($optioncss != '') {
637  $param .= '&optioncss='.urlencode($optioncss);
638 }
639 // Add $param from extra fields
640 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
641 // Add $param from hooks
642 $parameters = array();
643 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
644 $param .= $hookmanager->resPrint;
645 
646 
647 $linkback = '';
648 $titlepicto = 'title_setup';
649 
650 
651 $url = DOL_URL_ROOT.'/admin/mails_templates.php?action=create';
652 $newcardbutton = dolGetButtonTitle($langs->trans('NewEMailTemplate'), '', 'fa fa-plus-circle', $url, '', $permissiontoadd);
653 
654 
655 if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
656  print load_fiche_titre($title, '', $titlepicto);
657 } else {
658  print load_fiche_titre($title, $newcardbutton, $titlepicto);
659 }
660 
661 if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
662  $head = email_admin_prepare_head();
663 
664  print dol_get_fiche_head($head, 'templates', '', -1);
665 
666  if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
667  print load_fiche_titre('', $newcardbutton, '');
668  }
669 }
670 
671 
672 // Confirm deletion of record
673 if ($action == 'delete') {
674  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);
675 }
676 
677 
678 $fieldlist = explode(',', $tabfield[$id]);
679 
680 if ($action == 'create') {
681  // If data was already input, we define them in obj to populate input fields.
682  $obj = new stdClass();
683  $obj->label = GETPOST('label');
684  $obj->lang = GETPOST('lang');
685  $obj->type_template = GETPOST('type_template');
686  $obj->fk_user = GETPOST('fk_user', 'int');
687  $obj->private = GETPOST('private', 'int');
688  $obj->position = GETPOST('position');
689  $obj->topic = GETPOST('topic');
690  $obj->joinfiles = GETPOST('joinfiles');
691  $obj->content = GETPOST('content', 'restricthtml');
692 
693  // Form to add a new line
694  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
695  print '<input type="hidden" name="token" value="'.newToken().'">';
696  print '<input type="hidden" name="action" value="add">';
697  print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
698 
699  print '<div class="div-table-responsive-no-min">';
700  print '<table class="noborder centpercent">';
701 
702  // Line to enter new values (title)
703  print '<tr class="liste_titre">';
704  foreach ($fieldlist as $field => $value) {
705  // Determine le nom du champ par rapport aux noms possibles
706  // dans les dictionnaires de donnees
707  $valuetoshow = ucfirst($fieldlist[$field]); // Par defaut
708  $valuetoshow = $langs->trans($valuetoshow); // try to translate
709  $align = "left";
710  if ($fieldlist[$field] == 'fk_user') {
711  $valuetoshow = $langs->trans("Owner");
712  }
713  if ($fieldlist[$field] == 'lang') {
714  $valuetoshow = (!getDolGlobalInt('MAIN_MULTILANGS') ? '&nbsp;' : $langs->trans("Language"));
715  }
716  if ($fieldlist[$field] == 'type') {
717  $valuetoshow = $langs->trans("Type");
718  }
719  if ($fieldlist[$field] == 'code') {
720  $valuetoshow = $langs->trans("Code");
721  }
722  if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
723  $valuetoshow = $langs->trans("Code");
724  }
725  if ($fieldlist[$field] == 'type_template') {
726  $valuetoshow = $langs->trans("TypeOfTemplate"); $align = "center";
727  }
728  if ($fieldlist[$field] == 'private') {
729  $align = 'center';
730  }
731  if ($fieldlist[$field] == 'position') {
732  $align = 'center';
733  }
734 
735  if ($fieldlist[$field] == 'topic') {
736  $valuetoshow = '';
737  }
738  if ($fieldlist[$field] == 'joinfiles') {
739  $valuetoshow = '';
740  }
741  if ($fieldlist[$field] == 'content') {
742  $valuetoshow = '';
743  }
744  if ($fieldlist[$field] == 'content_lines') {
745  $valuetoshow = '';
746  }
747  if ($valuetoshow != '') {
748  print '<th class="'.$align.'">';
749  if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
750  print '<a href="'.$tabhelp[$id][$value].'" target="_blank" rel="noopener noreferrer">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
751  } elseif (!empty($tabhelp[$id][$value])) {
752  if (in_array($value, array('topic'))) {
753  print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, $value); // Tooltip on click
754  } else {
755  print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2); // Tooltip on hover
756  }
757  } else {
758  print $valuetoshow;
759  }
760  print '</th>';
761  }
762  }
763  print '<th>';
764  print '<input type="hidden" name="id" value="'.$id.'">';
765  print '</th>';
766  print '</tr>';
767 
768  $tmpaction = 'create';
769  $parameters = array(
770  'fieldlist' => $fieldlist,
771  'tabname' => $tabname[$id]
772  );
773  $reshook = $hookmanager->executeHooks('createEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
774  $error = $hookmanager->error;
775  $errors = $hookmanager->errors;
776 
777 
778  // Line to enter new values (input fields)
779  print '<tr class="oddeven">';
780 
781  if (empty($reshook)) {
782  if ($action == 'edit') {
783  fieldList($fieldlist, $obj, $tabname[$id], 'hide');
784  } else {
785  fieldList($fieldlist, $obj, $tabname[$id], 'add');
786  }
787  }
788 
789  print '<td class="right">';
790  print '</td>';
791  print "</tr>";
792 
793  // Show fields for topic, join files and body
794  $fieldsforcontent = array('topic', 'joinfiles', 'content');
795  if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
796  $fieldsforcontent = array('topic', 'joinfiles', 'content', 'content_lines');
797  }
798  foreach ($fieldsforcontent as $tmpfieldlist) {
799  print '<tr class="impair nodrag nodrop nohover"><td colspan="7" class="nobottom">';
800 
801  // Label
802  if ($tmpfieldlist == 'topic') {
803  print '<strong>'.$form->textwithpicto($langs->trans("Topic"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
804  }
805  if ($tmpfieldlist == 'joinfiles') {
806  print '<strong>'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
807  }
808  if ($tmpfieldlist == 'content') {
809  print $form->textwithpicto($langs->trans("Content"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
810  }
811  if ($tmpfieldlist == 'content_lines') {
812  print $form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
813  }
814 
815  // Input field
816  if ($tmpfieldlist == 'topic') {
817  print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '').'">';
818  } elseif ($tmpfieldlist == 'joinfiles') {
819  print $form->selectyesno($tmpfieldlist, (isset($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '0'), 1, false, 0, 1);
820  } else {
821  $okforextended = true;
822  if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
823  $okforextended = false;
824  }
825  $doleditor = new DolEditor($tmpfieldlist, (!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : ''), '', 180, 'dolibarr_mailings', 'In', false, $acceptlocallinktomedia, $okforextended, ROWS_4, '90%');
826  print $doleditor->Create(1);
827  }
828  print '</td>';
829  print '</tr>';
830  }
831 
832  print '</table>';
833 
834  if ($action != 'edit') {
835  print '<center>';
836  print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'"> ';
837  print '<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
838  print '</center>';
839  }
840 
841  print '</div>';
842  print '</form>';
843  print '<br><br>';
844 }
845 
846 // List of available record in database
847 dol_syslog("htdocs/admin/dict", LOG_DEBUG);
848 $resql = $db->query($sql);
849 if (!$resql) {
850  dol_print_error($db);
851  exit;
852 }
853 
854 $num = $db->num_rows($resql);
855 
856 print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
857 print '<input type="hidden" name="token" value="'.newToken().'">';
858 print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
859 
860 print '<div class="div-table-responsive-no-min">';
861 print '<table class="noborder centpercent">';
862 
863 $i = 0;
864 
865 $param = '&id='.$id;
866 if ($search_label) {
867  $param .= '&search_label='.urlencode($search_label);
868 }
869 if ($search_lang > 0) {
870  $param .= '&search_lang='.urlencode($search_lang);
871 }
872 if ($search_type_template != '-1') {
873  $param .= '&search_type_template='.urlencode($search_type_template);
874 }
875 if ($search_fk_user > 0) {
876  $param .= '&search_fk_user='.urlencode($search_fk_user);
877 }
878 if ($search_topic) {
879  $param .= '&search_topic='.urlencode($search_topic);
880 }
881 
882 $paramwithsearch = $param;
883 if ($sortorder) {
884  $paramwithsearch .= '&sortorder='.urlencode($sortorder);
885 }
886 if ($sortfield) {
887  $paramwithsearch .= '&sortfield='.urlencode($sortfield);
888 }
889 if (GETPOST('from', 'alpha')) {
890  $paramwithsearch .= '&from='.urlencode(GETPOST('from', 'alpha'));
891 }
892 
893 // There is several pages
894 if ($num > $listlimit) {
895  print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).'">';
896  print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
897  print '</td></tr>';
898 }
899 
900 
901 // Title line with search boxes
902 print '<tr class="liste_titre">';
903 
904 foreach ($fieldlist as $field => $value) {
905  if ($value == 'label') {
906  print '<td class="liste_titre"><input type="text" name="search_label" class="maxwidth200" value="'.dol_escape_htmltag($search_label).'"></td>';
907  } elseif ($value == 'lang') {
908  print '<td class="liste_titre">';
909  print $formadmin->select_language($search_lang, 'search_lang', 0, null, 1, 0, 0, 'maxwidth100');
910  print '</td>';
911  } elseif ($value == 'fk_user') {
912  print '<td class="liste_titre">';
913  print $form->select_dolusers($search_fk_user, 'search_fk_user', 1, null, 0, ($user->admin ? '' : 'hierarchyme'), null, 0, 0, 0, '', 0, '', 'maxwidth125', 1);
914  print '</td>';
915  } elseif ($value == 'topic') {
916  print '<td class="liste_titre"><input type="text" name="search_topic" value="'.dol_escape_htmltag($search_topic).'"></td>';
917  } elseif ($value == 'type_template') {
918  print '<td class="liste_titre center">';
919  print $form->selectarray('search_type_template', $elementList, $search_type_template, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100 maxwidth125', 1, '', 0, 1);
920  print '</td>';
921  } elseif (!in_array($value, array('content', 'content_lines'))) {
922  print '<td class="liste_titre"></td>';
923  }
924 }
925 
926 if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
927  print '<td class="liste_titre"></td>';
928 }
929 
930 // Action column
931 print '<td class="liste_titre right" width="64">';
932 $searchpicto = $form->showFilterButtons();
933 print $searchpicto;
934 print '</td>';
935 print '</tr>';
936 
937 // Title of lines
938 print '<tr class="liste_titre">';
939 foreach ($fieldlist as $field => $value) {
940  $showfield = 1; // By defaut
941  $align = "left";
942  $sortable = 1;
943  $valuetoshow = '';
944  $forcenowrap = 1;
945  /*
946  $tmparray=getLabelOfField($fieldlist[$field]);
947  $showfield=$tmp['showfield'];
948  $valuetoshow=$tmp['valuetoshow'];
949  $align=$tmp['align'];
950  $sortable=$tmp['sortable'];
951  */
952  $valuetoshow = ucfirst($fieldlist[$field]); // By defaut
953  $valuetoshow = $langs->trans($valuetoshow); // try to translate
954  if ($fieldlist[$field] == 'fk_user') {
955  $valuetoshow = $langs->trans("Owner");
956  }
957  if ($fieldlist[$field] == 'lang') {
958  $valuetoshow = $langs->trans("Language");
959  }
960  if ($fieldlist[$field] == 'type') {
961  $valuetoshow = $langs->trans("Type");
962  }
963  if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
964  $valuetoshow = $langs->trans("Code");
965  }
966  if ($fieldlist[$field] == 'type_template') {
967  $align = 'center';
968  $valuetoshow = $langs->trans("TypeOfTemplate");
969  }
970  if ($fieldlist[$field] == 'private') {
971  $align = 'center';
972  }
973  if ($fieldlist[$field] == 'position') {
974  $align = 'center';
975  }
976 
977  if ($fieldlist[$field] == 'joinfiles') {
978  $valuetoshow = $langs->trans("FilesAttachedToEmail"); $align = 'center'; $forcenowrap = 0;
979  }
980  if ($fieldlist[$field] == 'content') {
981  $valuetoshow = $langs->trans("Content"); $showfield = 0;
982  }
983  if ($fieldlist[$field] == 'content_lines') {
984  $valuetoshow = $langs->trans("ContentForLines"); $showfield = 0;
985  }
986 
987  // Show fields
988  if ($showfield) {
989  if (!empty($tabhelp[$id][$value])) {
990  if (in_array($value, array('topic'))) {
991  $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, 'tooltip'.$value, $forcenowrap); // Tooltip on click
992  } else {
993  $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, '', $forcenowrap); // Tooltip on hover
994  }
995  }
996  print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable ? $fieldlist[$field] : ''), ($page ? 'page='.$page.'&' : ''), $param, "align=".$align, $sortfield, $sortorder);
997  }
998 }
999 
1000 print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, 'align="center"', $sortfield, $sortorder);
1001 print getTitleFieldOfList('');
1002 print '</tr>';
1003 
1004 if ($num) {
1005  $nbqualified = 0;
1006 
1007  // Lines with values
1008  while ($i < $num) {
1009  $obj = $db->fetch_object($resql);
1010 
1011  if ($obj) {
1012  if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
1013  print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
1014 
1015  $tmpaction = 'edit';
1016  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
1017  $reshook = $hookmanager->executeHooks('editEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1018  $error = $hookmanager->error; $errors = $hookmanager->errors;
1019 
1020  // Show main fields
1021  if (empty($reshook)) {
1022  fieldList($fieldlist, $obj, $tabname[$id], 'edit');
1023  }
1024 
1025  print '<td></td><td></td><td></td>';
1026  print '<td class="center">';
1027  print '<input type="hidden" name="page" value="'.$page.'">';
1028  print '<input type="hidden" name="rowid" value="'.$rowid.'">';
1029  print '<input type="submit" class="button buttongen button-save" name="actionmodify" value="'.$langs->trans("Modify").'">';
1030  print '<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'"></div>';
1031  print '<input type="submit" class="button buttongen button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
1032  print '</td>';
1033 
1034  $fieldsforcontent = array('topic', 'joinfiles', 'content');
1035  if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
1036  $fieldsforcontent = array('topic', 'joinfiles', 'content', 'content_lines');
1037  }
1038  foreach ($fieldsforcontent as $tmpfieldlist) {
1039  $showfield = 1;
1040  $align = "left";
1041  $valuetoshow = $obj->$tmpfieldlist;
1042 
1043  $class = 'tddict';
1044  // Show value for field
1045  if ($showfield) {
1046  // Show line for topic, joinfiles and content
1047  print '</tr><tr class="oddeven" nohover tr-'.$tmpfieldlist.'-'.$rowid.' ">';
1048  print '<td colspan="8">';
1049  if ($tmpfieldlist == 'topic') {
1050  print '<strong>'.$form->textwithpicto($langs->trans("Topic"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
1051  print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'">';
1052  }
1053  if ($tmpfieldlist == 'joinfiles') {
1054  print '<strong>'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
1055  print $form->selectyesno($tmpfieldlist.'-'.$rowid, (isset($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '0'), 1, false, 0, 1);
1056  }
1057 
1058  if ($tmpfieldlist == 'content') {
1059  print $form->textwithpicto($langs->trans("Content"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
1060  $okforextended = true;
1061  if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
1062  $okforextended = false;
1063  }
1064 
1065  $doleditor = new DolEditor($tmpfieldlist.'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 500, 'dolibarr_mailings', 'In', 0, $acceptlocallinktomedia, $okforextended, ROWS_6, '90%');
1066  print $doleditor->Create(1);
1067  }
1068  if ($tmpfieldlist == 'content_lines') {
1069  print $form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
1070  $okforextended = true;
1071  if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
1072  $okforextended = false;
1073  }
1074  $doleditor = new DolEditor($tmpfieldlist.'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 140, 'dolibarr_mailings', 'In', 0, $acceptlocallinktomedia, $okforextended, ROWS_6, '90%');
1075  print $doleditor->Create(1);
1076  }
1077  print '</td>';
1078  print '<td></td>';
1079  print '<td></td>';
1080  }
1081  }
1082 
1083  print "</tr>\n";
1084 
1085  $nbqualified++;
1086  } else {
1087  // If template is for a module, check module is enabled.
1088  if ($obj->module) {
1089  $tempmodulekey = $obj->module;
1090  if (empty($conf->$tempmodulekey) || empty($conf->$tempmodulekey->enabled)) {
1091  $i++;
1092  continue;
1093  }
1094  }
1095 
1096  $keyforobj = 'type_template';
1097  if (!in_array($obj->$keyforobj, array_keys($elementList))) {
1098  $i++;
1099  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)
1100  }
1101  // Test on 'enabled'
1102  if (!dol_eval($obj->enabled, 1, 1, '1')) {
1103  $i++;
1104  continue; // Email template not qualified
1105  }
1106 
1107  $nbqualified++;
1108 
1109  print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
1110 
1111  $tmpaction = 'view';
1112  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
1113  $reshook = $hookmanager->executeHooks('viewEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1114 
1115  $error = $hookmanager->error; $errors = $hookmanager->errors;
1116 
1117  if (empty($reshook)) {
1118  foreach ($fieldlist as $field => $value) {
1119  if (in_array($fieldlist[$field], array('content', 'content_lines'))) {
1120  continue;
1121  }
1122  $showfield = 1;
1123  $align = "";
1124  $class = "tddict";
1125  $title = '';
1126  $valuetoshow = $obj->{$fieldlist[$field]};
1127  if ($value == 'label' || $value == 'topic') {
1128  if ($langs->trans($valuetoshow) != $valuetoshow) {
1129  $valuetoshow = $langs->trans($valuetoshow);
1130  }
1131  $valuetoshow = dol_escape_htmltag($valuetoshow);
1132  }
1133  if ($value == 'label') {
1134  $class .= ' tdoverflowmax100';
1135  }
1136  if ($value == 'topic') {
1137  $class .= ' tdoverflowmax200 small';
1138  }
1139  if ($value == 'type_template') {
1140  $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
1141  $align = "center";
1142  }
1143  if ($value == 'lang' && $valuetoshow) {
1144  $valuetoshow = $valuetoshow.' - '.$langs->trans("Language_".$valuetoshow);
1145  }
1146  if ($value == 'fk_user') {
1147  if ($valuetoshow > 0) {
1148  $fuser = new User($db);
1149  $fuser->fetch($valuetoshow);
1150  $valuetoshow = $fuser->getNomUrl(1);
1151  }
1152  }
1153  if ($value == 'private') {
1154  $align = "center";
1155  if ($valuetoshow) {
1156  $valuetoshow = yn($valuetoshow);
1157  } else {
1158  $valuetoshow = '';
1159  }
1160  }
1161  if ($value == 'position') {
1162  $align = "center";
1163  }
1164  if ($value == 'joinfiles') {
1165  $align = "center";
1166  if ($valuetoshow) {
1167  $valuetoshow = yn(1);
1168  } else {
1169  $valuetoshow = '';
1170  }
1171  }
1172  if ($align) {
1173  $class .= ' '.$align;
1174  }
1175 
1176  // Show value for field
1177  if ($showfield) {
1178  print '<!-- '.$fieldlist[$field].' -->';
1179  print '<td class="'.$class.'"';
1180  if (in_array($value, array('code', 'label', 'topic'))) {
1181  print ' title="'.dol_escape_htmltag($valuetoshow).'"';
1182  }
1183  print '>';
1184  print $valuetoshow;
1185  print '</td>';
1186  }
1187  }
1188  }
1189 
1190  // Can an entry be erased or disabled ?
1191  $iserasable = 1; $canbedisabled = 1; $canbemodified = 1; // true by default
1192  if (!$user->admin && $obj->fk_user != $user->id) {
1193  $iserasable = 0;
1194  $canbedisabled = 0;
1195  $canbemodified = 0;
1196  }
1197 
1198  $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) : '');
1199  if ($param) {
1200  $url .= '&'.$param;
1201  }
1202 
1203  // Status / Active
1204  print '<td class="center nowrap">';
1205  if ($canbedisabled) {
1206  print '<a class="reposition" href="'.$url.'&action='.$acts[$obj->active].'&token='.newToken().'">'.$actl[$obj->active].'</a>';
1207  } else {
1208  print '<span class="opacitymedium">'.$actl[$obj->active].'</span>';
1209  }
1210  print "</td>";
1211 
1212  // Modify link / Delete link
1213  print '<td class="center nowraponall" width="64">';
1214  if ($canbemodified) {
1215  print '<a class="reposition editfielda" href="'.$url.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
1216  }
1217  if ($iserasable) {
1218  print '<a class="marginleftonly" href="'.$url.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
1219  //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
1220  }
1221  print '</td>';
1222 
1223  print "</tr>\n";
1224  }
1225  }
1226 
1227  $i++;
1228  }
1229 }
1230 
1231 // If no record found
1232 if ($nbqualified == 0) {
1233  $colspan = 10;
1234  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1235 }
1236 
1237 print '</table>';
1238 print '</div>';
1239 
1240 print '</form>';
1241 
1242 
1243 if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
1244  print dol_get_fiche_end();
1245 }
1246 
1247 
1248 // End of page
1249 llxFooter();
1250 $db->close();
1251 
1252 
1262 function fieldList($fieldlist, $obj = '', $tabname = '', $context = '')
1263 {
1264  global $conf, $langs, $user, $db;
1265  global $form;
1266  global $elementList;
1267 
1268  $formadmin = new FormAdmin($db);
1269 
1270  foreach ($fieldlist as $field => $value) {
1271  if ($value == 'fk_user') {
1272  print '<td>';
1273  if ($user->admin) {
1274  print $form->select_dolusers(empty($obj->{$value}) ? '' : $obj->{$value}, 'fk_user', 1, null, 0, ($user->admin ? '' : 'hierarchyme'), null, 0, 0, 0, '', 0, '', 'minwidth150 maxwidth200');
1275  } else {
1276  if ($context == 'add') { // I am not admin and we show the add form
1277  print $user->getNomUrl(1); // Me
1278  $forcedvalue = $user->id;
1279  } else {
1280  if ($obj && !empty($obj->{$value}) && $obj->{$value} > 0) {
1281  $fuser = new User($db);
1282  $fuser->fetch($obj->{$value});
1283  print $fuser->getNomUrl(1);
1284  $forcedvalue = $fuser->id;
1285  } else {
1286  $forcedvalue = $obj->{$value};
1287  }
1288  }
1289  $keyname = $value;
1290  print '<input type="hidden" value="'.$forcedvalue.'" name="'.$keyname.'">';
1291  }
1292  print '</td>';
1293  } elseif ($value == 'lang') {
1294  print '<td>';
1295  if (getDolGlobalInt('MAIN_MULTILANGS')) {
1296  $selectedlang = GETPOSTISSET('langcode') ?GETPOST('langcode', 'aZ09') : $langs->defaultlang;
1297  if ($context == 'edit') {
1298  $selectedlang = $obj->lang;
1299  }
1300  print $formadmin->select_language($selectedlang, 'langcode', 0, null, 1, 0, 0, 'maxwidth150');
1301  } else {
1302  if (!empty($obj->lang)) {
1303  print $obj->lang.' - '.$langs->trans('Language_'.$obj->lang);
1304  }
1305  $keyname = $value;
1306  if ($keyname == 'lang') {
1307  $keyname = 'langcode'; // Avoid conflict with lang param
1308  }
1309  print '<input type="hidden" value="'.(empty($obj->lang) ? '' : $obj->lang).'" name="'.$keyname.'">';
1310  }
1311  print '</td>';
1312  } elseif ($value == 'type_template') {
1313  // Le type de template
1314  print '<td class="center">';
1315  if ($context == 'edit' && !empty($obj->type_template) && !in_array($obj->type_template, array_keys($elementList))) {
1316  // Current template type is an unknown type, so we must keep it as it is.
1317  print '<input type="hidden" name="type_template" value="'.$obj->type_template.'">';
1318  print $obj->type_template;
1319  } else {
1320  print $form->selectarray('type_template', $elementList, (!empty($obj->type_template) ? $obj->type_template:''), 1, 0, 0, '', 0, 0, 0, '', 'minwidth150', 1, '', 0, 1);
1321  }
1322  print '</td>';
1323  } elseif ($context == 'add' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1324  continue;
1325  } elseif ($context == 'edit' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1326  continue;
1327  } elseif ($context == 'hide' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1328  continue;
1329  } else {
1330  $size = ''; $class = ''; $classtd = '';
1331  if ($value == 'code') {
1332  $class = 'maxwidth100';
1333  }
1334  if ($value == 'label') {
1335  $class = 'maxwidth200';
1336  }
1337  if ($value == 'private') {
1338  $class = 'maxwidth50'; $classtd = 'center';
1339  }
1340  if ($value == 'position') {
1341  $class = 'maxwidth50 center'; $classtd = 'center';
1342  }
1343  if ($value == 'libelle') {
1344  $class = 'quatrevingtpercent';
1345  }
1346  if ($value == 'topic') {
1347  $class = 'quatrevingtpercent';
1348  }
1349  if ($value == 'sortorder' || $value == 'sens' || $value == 'category_type') {
1350  $size = 'size="2" ';
1351  }
1352 
1353  print '<td'.($classtd ? ' class="'.$classtd.'"' : '').'>';
1354  if ($value == 'private') {
1355  if (empty($user->admin)) {
1356  print $form->selectyesno($value, '1', 1);
1357  } else {
1358  print $form->selectyesno($value, (isset($obj->{$value}) ? $obj->{$value}:''), 1);
1359  }
1360  } else {
1361  print '<input type="text" '.$size.'class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->{$value}) ? $obj->{$value}:'').'" name="'. $value .'">';
1362  }
1363  print '</td>';
1364  }
1365  }
1366 }
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
email_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: admin.lib.php:2016
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage a WYSIWYG editor.
Class to generate html code for admin pages.
Class to manage generation of HTML components Only common components must be here.
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
static getAvailableSubstitKey($mode='formemail', $object=null)
Get list of substitution keys available for emails.
Class to manage Dolibarr users.
Definition: user.class.php:47
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
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
acceptLocalLinktoMedia()
Check the syntax of some PHP code.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_eval($s, $returnvalue=0, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
print_fleche_navigation($page, $file, $options='', $nextpage=0, $betweenarrows='', $afterarrows='', $limit=-1, $totalnboflines=0, $hideselectlimit=0, $beforearrows='')
Function to show navigation arrows into lists.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
fieldList($fieldlist, $obj='', $tabname='', $context='')
Show fields in insert/edit mode.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.