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