dolibarr  x.y.z
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 // Confirmation de la suppression de la ligne
684 if ($action == 'delete') {
685  print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$code.'&id='.$id, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1);
686 }
687 
688 
689 
690 
691 $fieldlist = explode(',', $tabfield[$id]);
692 
693 if ($action == 'create') {
694  // Form to add a new line
695  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
696  print '<input type="hidden" name="token" value="'.newToken().'">';
697  print '<input type="hidden" name="action" value="add">';
698  print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
699 
700  print '<div class="div-table-responsive-no-min">';
701  print '<table class="noborder centpercent">';
702 
703  // Line to enter new values (title)
704  print '<tr class="liste_titre">';
705  foreach ($fieldlist as $field => $value) {
706  // Determine le nom du champ par rapport aux noms possibles
707  // dans les dictionnaires de donnees
708  $valuetoshow = ucfirst($fieldlist[$field]); // Par defaut
709  $valuetoshow = $langs->trans($valuetoshow); // try to translate
710  $align = "left";
711  if ($fieldlist[$field] == 'module') {
712  $valuetoshow = '';
713  }
714  if ($fieldlist[$field] == 'fk_user') {
715  $valuetoshow = $langs->trans("Owner");
716  }
717  if ($fieldlist[$field] == 'lang') {
718  $valuetoshow = (!getDolGlobalInt('MAIN_MULTILANGS') ? '&nbsp;' : $langs->trans("Language"));
719  }
720  if ($fieldlist[$field] == 'type') {
721  $valuetoshow = $langs->trans("Type");
722  }
723  if ($fieldlist[$field] == 'code') {
724  $valuetoshow = $langs->trans("Code");
725  }
726  if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
727  $valuetoshow = $langs->trans("Code");
728  }
729  if ($fieldlist[$field] == 'type_template') {
730  $valuetoshow = $langs->trans("TypeOfTemplate"); $align = "center";
731  }
732  if ($fieldlist[$field] == 'private') {
733  $align = 'center';
734  }
735  if ($fieldlist[$field] == 'position') {
736  $align = 'center';
737  }
738 
739  if ($fieldlist[$field] == 'topic') {
740  $valuetoshow = '';
741  }
742  if ($fieldlist[$field] == 'joinfiles') {
743  $valuetoshow = '';
744  }
745  if ($fieldlist[$field] == 'content') {
746  $valuetoshow = '';
747  }
748  if ($fieldlist[$field] == 'content_lines') {
749  $valuetoshow = '';
750  }
751  if ($valuetoshow != '') {
752  print '<th class="'.$align.'">';
753  if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
754  print '<a href="'.$tabhelp[$id][$value].'" target="_blank" rel="noopener noreferrer">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
755  } elseif (!empty($tabhelp[$id][$value])) {
756  if (in_array($value, array('topic'))) {
757  print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, $value); // Tooltip on click
758  } else {
759  print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2); // Tooltip on hover
760  }
761  } else {
762  print $valuetoshow;
763  }
764  print '</th>';
765  }
766  }
767  print '<th>';
768  print '<input type="hidden" name="id" value="'.$id.'">';
769  print '</th>';
770  print '</tr>';
771 
772  $obj = new stdClass();
773  // If data was already input, we define them in obj to populate input fields.
774  if (GETPOST('actionadd')) {
775  foreach ($fieldlist as $key => $val) {
776  if (GETPOST($val) != '') {
777  $obj->$val = GETPOST($val);
778  }
779  }
780  }
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 
840  $doleditor = new DolEditor($tmpfieldlist, (!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : ''), '', 180, 'dolibarr_mailings', 'In', false, $acceptlocallinktomedia, $okforextended, ROWS_4, '90%');
841  print $doleditor->Create(1);
842  }
843  print '</td>';
844  print '</tr>';
845  }
846 
847  print '</table>';
848 
849  if ($action != 'edit') {
850  print '<center>';
851  print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'"> ';
852  print '<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
853  print '</center>';
854  }
855 
856  print '</div>';
857  print '</form>';
858  print '<br><br>';
859 } // END IF not edit
860 
861 // List of available record in database
862 dol_syslog("htdocs/admin/dict", LOG_DEBUG);
863 $resql = $db->query($sql);
864 if (!$resql) {
865  dol_print_error($db);
866  exit;
867 }
868 
869 $num = $db->num_rows($resql);
870 
871 print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
872 print '<input type="hidden" name="token" value="'.newToken().'">';
873 print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
874 
875 print '<div class="div-table-responsive-no-min">';
876 print '<table class="noborder centpercent">';
877 
878 $i = 0;
879 
880 $param = '&id='.$id;
881 if ($search_label) {
882  $param .= '&search_label='.urlencode($search_label);
883 }
884 if ($search_lang > 0) {
885  $param .= '&search_lang='.urlencode($search_lang);
886 }
887 if ($search_type_template != '-1') {
888  $param .= '&search_type_template='.urlencode($search_type_template);
889 }
890 if ($search_fk_user > 0) {
891  $param .= '&search_fk_user='.urlencode($search_fk_user);
892 }
893 if ($search_module) {
894  $param .= '&search_module='.urlencode($search_module);
895 }
896 if ($search_topic) {
897  $param .= '&search_topic='.urlencode($search_topic);
898 }
899 
900 $paramwithsearch = $param;
901 if ($sortorder) {
902  $paramwithsearch .= '&sortorder='.urlencode($sortorder);
903 }
904 if ($sortfield) {
905  $paramwithsearch .= '&sortfield='.urlencode($sortfield);
906 }
907 if (GETPOST('from', 'alpha')) {
908  $paramwithsearch .= '&from='.urlencode(GETPOST('from', 'alpha'));
909 }
910 
911 // There is several pages
912 if ($num > $listlimit) {
913  print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).'">';
914  print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
915  print '</td></tr>';
916 }
917 
918 
919 // Title line with search boxes
920 print '<tr class="liste_titre">';
921 
922 foreach ($fieldlist as $field => $value) {
923  if ($value == 'module') {
924  print '<td class="liste_titre"><input type="text" name="search_module" class="maxwidth75" value="'.dol_escape_htmltag($search_module).'"></td>';
925  } elseif ($value == 'label') {
926  print '<td class="liste_titre"><input type="text" name="search_label" class="maxwidth200" value="'.dol_escape_htmltag($search_label).'"></td>';
927  } elseif ($value == 'lang') {
928  print '<td class="liste_titre">';
929  print $formadmin->select_language($search_lang, 'search_lang', 0, null, 1, 0, 0, 'maxwidth100');
930  print '</td>';
931  } elseif ($value == 'fk_user') {
932  print '<td class="liste_titre">';
933  print $form->select_dolusers($search_fk_user, 'search_fk_user', 1, null, 0, ($user->admin ? '' : 'hierarchyme'), null, 0, 0, 0, '', 0, '', 'maxwidth100', 1);
934  print '</td>';
935  } elseif ($value == 'topic') {
936  print '<td class="liste_titre"><input type="text" name="search_topic" value="'.dol_escape_htmltag($search_topic).'"></td>';
937  } elseif ($value == 'type_template') {
938  print '<td class="liste_titre center">';
939  print $form->selectarray('search_type_template', $elementList, $search_type_template, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100 maxwidth125', 1, '', 0, 1);
940  print '</td>';
941  } elseif (!in_array($value, array('content', 'content_lines'))) {
942  print '<td class="liste_titre"></td>';
943  }
944 }
945 
946 if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
947  print '<td class="liste_titre"></td>';
948 }
949 
950 // Action column
951 print '<td class="liste_titre right" width="64">';
952 $searchpicto = $form->showFilterButtons();
953 print $searchpicto;
954 print '</td>';
955 print '</tr>';
956 
957 // Title of lines
958 print '<tr class="liste_titre">';
959 foreach ($fieldlist as $field => $value) {
960  $showfield = 1; // By defaut
961  $align = "left";
962  $sortable = 1;
963  $valuetoshow = '';
964  $forcenowrap = 1;
965  /*
966  $tmparray=getLabelOfField($fieldlist[$field]);
967  $showfield=$tmp['showfield'];
968  $valuetoshow=$tmp['valuetoshow'];
969  $align=$tmp['align'];
970  $sortable=$tmp['sortable'];
971  */
972  $valuetoshow = ucfirst($fieldlist[$field]); // By defaut
973  $valuetoshow = $langs->trans($valuetoshow); // try to translate
974  if ($fieldlist[$field] == 'module') {
975  $align = 'tdoverflowmax100';
976  }
977  if ($fieldlist[$field] == 'fk_user') {
978  $valuetoshow = $langs->trans("Owner");
979  }
980  if ($fieldlist[$field] == 'lang') {
981  $valuetoshow = $langs->trans("Language");
982  }
983  if ($fieldlist[$field] == 'type') {
984  $valuetoshow = $langs->trans("Type");
985  }
986  if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
987  $valuetoshow = $langs->trans("Code");
988  }
989  if ($fieldlist[$field] == 'type_template') {
990  $align = 'center';
991  $valuetoshow = $langs->trans("TypeOfTemplate");
992  }
993  if ($fieldlist[$field] == 'private') {
994  $align = 'center';
995  }
996  if ($fieldlist[$field] == 'position') {
997  $align = 'center';
998  }
999 
1000  if ($fieldlist[$field] == 'joinfiles') {
1001  $valuetoshow = $langs->trans("FilesAttachedToEmail"); $align = 'center'; $forcenowrap = 0;
1002  }
1003  if ($fieldlist[$field] == 'content') {
1004  $valuetoshow = $langs->trans("Content"); $showfield = 0;
1005  }
1006  if ($fieldlist[$field] == 'content_lines') {
1007  $valuetoshow = $langs->trans("ContentForLines"); $showfield = 0;
1008  }
1009 
1010  // Show fields
1011  if ($showfield) {
1012  if (!empty($tabhelp[$id][$value])) {
1013  if (in_array($value, array('topic'))) {
1014  $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, 'tooltip'.$value, $forcenowrap); // Tooltip on click
1015  } else {
1016  $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, '', $forcenowrap); // Tooltip on hover
1017  }
1018  }
1019  $sortfieldtouse = ($sortable ? $fieldlist[$field] : '');
1020  if ($sortfieldtouse == 'type_template') {
1021  $sortfieldtouse.= ',label';
1022  }
1023  print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], $sortfieldtouse, ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, $align.' ');
1024  }
1025 }
1026 
1027 print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
1028 print getTitleFieldOfList('');
1029 print '</tr>';
1030 
1031 if ($num) {
1032  $nbqualified = 0;
1033 
1034  // Lines with values
1035  while ($i < $num) {
1036  $obj = $db->fetch_object($resql);
1037 
1038  if ($obj) {
1039  if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
1040  print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
1041 
1042  $tmpaction = 'edit';
1043  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
1044  $reshook = $hookmanager->executeHooks('editEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1045  $error = $hookmanager->error; $errors = $hookmanager->errors;
1046 
1047  // Show main fields
1048  if (empty($reshook)) {
1049  fieldList($fieldlist, $obj, $tabname[$id], 'edit');
1050  }
1051 
1052  print '<td></td><td></td><td></td>';
1053  print '<td class="center">';
1054  print '<input type="hidden" name="page" value="'.$page.'">';
1055  print '<input type="hidden" name="rowid" value="'.$rowid.'">';
1056  print '<input type="submit" class="button buttongen button-save" name="actionmodify" value="'.$langs->trans("Modify").'">';
1057  print '<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'"></div>';
1058  print '<input type="submit" class="button buttongen button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
1059  print '</td>';
1060 
1061  $fieldsforcontent = array('topic', 'joinfiles', 'content');
1062  if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
1063  $fieldsforcontent = array('topic', 'joinfiles', 'content', 'content_lines');
1064  }
1065  foreach ($fieldsforcontent as $tmpfieldlist) {
1066  $showfield = 1;
1067  $align = "left";
1068  $valuetoshow = $obj->$tmpfieldlist;
1069 
1070  $class = 'tddict';
1071  // Show value for field
1072  if ($showfield) {
1073  // Show line for topic, joinfiles and content
1074  print '</tr><tr class="oddeven" nohover tr-'.$tmpfieldlist.'-'.$rowid.' ">';
1075  print '<td colspan="9">';
1076  if ($tmpfieldlist == 'topic') {
1077  print '<strong>'.$form->textwithpicto($langs->trans("Topic"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
1078  print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'">';
1079  }
1080  if ($tmpfieldlist == 'joinfiles') {
1081  print '<strong>'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
1082  print $form->selectyesno($tmpfieldlist.'-'.$rowid, (isset($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '0'), 1, false, 0, 1);
1083  }
1084 
1085  if ($tmpfieldlist == 'content') {
1086  print $form->textwithpicto($langs->trans("Content"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
1087  $okforextended = true;
1088  if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
1089  $okforextended = false;
1090  }
1091  $doleditor = new DolEditor($tmpfieldlist.'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 500, 'dolibarr_mailings', 'In', 0, $acceptlocallinktomedia, $okforextended, ROWS_6, '90%');
1092  print $doleditor->Create(1);
1093  }
1094  if ($tmpfieldlist == 'content_lines') {
1095  print $form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
1096  $okforextended = true;
1097  if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
1098  $okforextended = false;
1099  }
1100  $doleditor = new DolEditor($tmpfieldlist.'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 140, 'dolibarr_mailings', 'In', 0, $acceptlocallinktomedia, $okforextended, ROWS_6, '90%');
1101  print $doleditor->Create(1);
1102  }
1103  print '</td>';
1104  print '<td></td>';
1105  print '<td></td>';
1106  }
1107  }
1108 
1109  print "</tr>\n";
1110 
1111  $nbqualified++;
1112  } else {
1113  // If template is for a module, check module is enabled.
1114  if ($obj->module) {
1115  $tempmodulekey = $obj->module;
1116  if (empty($conf->$tempmodulekey) || empty($conf->$tempmodulekey->enabled)) {
1117  $i++;
1118  continue;
1119  }
1120  }
1121 
1122  $keyforobj = 'type_template';
1123  if (!in_array($obj->$keyforobj, array_keys($elementList))) {
1124  $i++;
1125  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)
1126  }
1127  // Test on 'enabled'
1128  if (!dol_eval($obj->enabled, 1, 1, '1')) {
1129  $i++;
1130  continue; // Email template not qualified
1131  }
1132 
1133  $nbqualified++;
1134 
1135  print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
1136 
1137  $tmpaction = 'view';
1138  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
1139  $reshook = $hookmanager->executeHooks('viewEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
1140 
1141  $error = $hookmanager->error; $errors = $hookmanager->errors;
1142 
1143  if (empty($reshook)) {
1144  foreach ($fieldlist as $field => $value) {
1145  if (in_array($fieldlist[$field], array('content', 'content_lines'))) {
1146  continue;
1147  }
1148  $showfield = 1;
1149  $align = "";
1150  $class = "tddict";
1151  $title = '';
1152  $tmpvar = $fieldlist[$field];
1153  $valuetoshow = $obj->$tmpvar;
1154  if ($value == 'label' || $value == 'topic') {
1155  if ($langs->trans($valuetoshow) != $valuetoshow) {
1156  $valuetoshow = $langs->trans($valuetoshow);
1157  }
1158  $valuetoshow = dol_escape_htmltag($valuetoshow);
1159  }
1160  if ($value == 'label') {
1161  $class .= ' tdoverflowmax100';
1162  }
1163  if ($value == 'topic') {
1164  $class .= ' tdoverflowmax200 small';
1165  }
1166  if ($value == 'type_template') {
1167  $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
1168  $align = "center";
1169  }
1170  if ($value == 'lang' && $valuetoshow) {
1171  $valuetoshow = $valuetoshow.' - '.$langs->trans("Language_".$valuetoshow);
1172  }
1173  if ($value == 'fk_user') {
1174  if ($valuetoshow > 0) {
1175  $fuser = new User($db);
1176  $fuser->fetch($valuetoshow);
1177  $valuetoshow = $fuser->getNomUrl(1);
1178  }
1179  }
1180  if ($value == 'private') {
1181  $align = "center";
1182  if ($valuetoshow) {
1183  $valuetoshow = yn($valuetoshow);
1184  } else {
1185  $valuetoshow = '';
1186  }
1187  }
1188  if ($value == 'position') {
1189  $align = "center";
1190  }
1191  if ($value == 'joinfiles') {
1192  $align = "center";
1193  if ($valuetoshow) {
1194  $valuetoshow = yn(1);
1195  } else {
1196  $valuetoshow = '';
1197  }
1198  }
1199  if ($align) {
1200  $class .= ' '.$align;
1201  }
1202 
1203  // Show value for field
1204  if ($showfield) {
1205  print '<!-- '.$fieldlist[$field].' -->';
1206  print '<td class="'.$class.'"';
1207  if (in_array($value, array('code', 'label', 'topic'))) {
1208  print ' title="'.dol_escape_htmltag($valuetoshow).'"';
1209  }
1210  print '>';
1211  print $valuetoshow;
1212  print '</td>';
1213  }
1214  }
1215  }
1216 
1217  // Can an entry be erased or disabled ?
1218  $iserasable = 1; $canbedisabled = 1; $canbemodified = 1; // true by default
1219  if (!$user->admin && $obj->fk_user != $user->id) {
1220  $iserasable = 0;
1221  $canbedisabled = 0;
1222  $canbemodified = 0;
1223  }
1224 
1225  $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) : '');
1226  if ($param) {
1227  $url .= '&'.$param;
1228  }
1229 
1230  // Status / Active
1231  print '<td class="center nowrap">';
1232  if ($canbedisabled) {
1233  print '<a class="reposition" href="'.$url.'&action='.$acts[$obj->active].'&token='.newToken().'">'.$actl[$obj->active].'</a>';
1234  } else {
1235  print '<span class="opacitymedium">'.$actl[$obj->active].'</span>';
1236  }
1237  print "</td>";
1238 
1239  // Modify link / Delete link
1240  print '<td class="center nowraponall" width="64">';
1241  if ($canbemodified) {
1242  print '<a class="reposition editfielda" href="'.$url.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
1243  }
1244  if ($iserasable) {
1245  print '<a class="marginleftonly" href="'.$url.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
1246  //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
1247  }
1248  print '</td>';
1249 
1250  print "</tr>\n";
1251  }
1252  }
1253 
1254  $i++;
1255  }
1256 }
1257 
1258 // If no record found
1259 if ($nbqualified == 0) {
1260  $colspan = 10;
1261  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1262 }
1263 
1264 print '</table>';
1265 print '</div>';
1266 
1267 print '</form>';
1268 
1269 
1270 if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
1271  print dol_get_fiche_end();
1272 }
1273 
1274 
1275 // End of page
1276 llxFooter();
1277 $db->close();
1278 
1279 
1289 function fieldList($fieldlist, $obj = '', $tabname = '', $context = '')
1290 {
1291  global $langs, $user, $db;
1292  global $form;
1293  global $elementList;
1294 
1295  $formadmin = new FormAdmin($db);
1296 
1297  foreach ($fieldlist as $field => $value) {
1298  if ($value == 'module') {
1299  print '<td></td>';
1300  } elseif ($value == 'fk_user') {
1301  print '<td>';
1302  if ($user->admin) {
1303  print $form->select_dolusers(empty($obj->$value) ? '' : $obj->$value, 'fk_user', 1, null, 0, ($user->admin ? '' : 'hierarchyme'), null, 0, 0, 0, '', 0, '', 'minwidth75 maxwidth100');
1304  } else {
1305  if ($context == 'add') { // I am not admin and we show the add form
1306  print $user->getNomUrl(1); // Me
1307  $forcedvalue = $user->id;
1308  } else {
1309  if ($obj && !empty($obj->$value) && $obj->$value > 0) {
1310  $fuser = new User($db);
1311  $fuser->fetch($obj->$value);
1312  print $fuser->getNomUrl(1);
1313  $forcedvalue = $fuser->id;
1314  } else {
1315  $forcedvalue = $obj->$value;
1316  }
1317  }
1318  $keyname = $value;
1319  print '<input type="hidden" value="'.$forcedvalue.'" name="'.$keyname.'">';
1320  }
1321  print '</td>';
1322  } elseif ($value == 'lang') {
1323  print '<td>';
1324  if (getDolGlobalInt('MAIN_MULTILANGS')) {
1325  $selectedlang = GETPOSTISSET('langcode') ?GETPOST('langcode', 'aZ09') : $langs->defaultlang;
1326  if ($context == 'edit') {
1327  $selectedlang = $obj->lang;
1328  }
1329  print $formadmin->select_language($selectedlang, 'langcode', 0, null, 1, 0, 0, 'maxwidth100');
1330  } else {
1331  if (!empty($obj->lang)) {
1332  print $obj->lang.' - '.$langs->trans('Language_'.$obj->lang);
1333  }
1334  $keyname = $value;
1335  if ($keyname == 'lang') {
1336  $keyname = 'langcode'; // Avoid conflict with lang param
1337  }
1338  print '<input type="hidden" value="'.(empty($obj->lang) ? '' : $obj->lang).'" name="'.$keyname.'">';
1339  }
1340  print '</td>';
1341  } elseif ($value == 'type_template') {
1342  // Le type de template
1343  print '<td class="center">';
1344  if ($context == 'edit' && !empty($obj->type_template) && !in_array($obj->type_template, array_keys($elementList))) {
1345  // Current template type is an unknown type, so we must keep it as it is.
1346  print '<input type="hidden" name="type_template" value="'.$obj->type_template.'">';
1347  print $obj->type_template;
1348  } else {
1349  print $form->selectarray('type_template', $elementList, (!empty($obj->type_template) ? $obj->type_template:''), 1, 0, 0, '', 0, 0, 0, '', 'minwidth75 maxwidth125', 1, '', 0, 1);
1350  }
1351  print '</td>';
1352  } elseif ($context == 'add' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1353  continue;
1354  } elseif ($context == 'edit' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1355  continue;
1356  } elseif ($context == 'hide' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
1357  continue;
1358  } else {
1359  $size = ''; $class = ''; $classtd = '';
1360  if ($value == 'code') {
1361  $class = 'maxwidth100';
1362  }
1363  if ($value == 'label') {
1364  $class = 'maxwidth200';
1365  }
1366  if ($value == 'private') {
1367  $class = 'maxwidth50'; $classtd = 'center';
1368  }
1369  if ($value == 'position') {
1370  $class = 'maxwidth50 center'; $classtd = 'center';
1371  }
1372  if ($value == 'libelle') {
1373  $class = 'quatrevingtpercent';
1374  }
1375  if ($value == 'topic') {
1376  $class = 'quatrevingtpercent';
1377  }
1378  if ($value == 'sortorder' || $value == 'sens' || $value == 'category_type') {
1379  $size = 'size="2" ';
1380  }
1381 
1382  print '<td'.($classtd ? ' class="'.$classtd.'"' : '').'>';
1383  if ($value == 'private') {
1384  if (empty($user->admin)) {
1385  print $form->selectyesno($value, '1', 1);
1386  } else {
1387  print $form->selectyesno($value, (isset($obj->{$value}) ? $obj->{$value}:''), 1);
1388  }
1389  } else {
1390  print '<input type="text" '.$size.'class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->{$value}) ? $obj->{$value}:'').'" name="'. $value .'">';
1391  }
1392  print '</td>';
1393  }
1394  }
1395 }
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:45
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.