dolibarr  13.0.2
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-2020 Frédéric France <frederic.france@netlogic.fr>
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program. If not, see <https://www.gnu.org/licenses/>.
28  */
29 
36 require '../main.inc.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
44 
45 // Load translation files required by the page
46 $langs->loadLangs(array("errors", "admin", "mails", "languages"));
47 
48 $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view';
49 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
50 
51 $id = GETPOST('id', 'int');
52 $rowid = GETPOST('rowid', 'alpha');
53 $search_label = GETPOST('search_label', 'alphanohtml'); // Must allow value like 'Abc Def' or '(MyTemplateName)'
54 $search_type_template = GETPOST('search_type_template', 'alpha');
55 $search_lang = GETPOST('search_lang', 'alpha');
56 $search_fk_user = GETPOST('search_fk_user', 'intcomma');
57 $search_topic = GETPOST('search_topic', 'alpha');
58 
59 if (!empty($user->socid)) accessforbidden();
60 
61 $acts = array();
62 $actl = array();
63 $acts[0] = "activate";
64 $acts[1] = "disable";
65 $actl[0] = img_picto($langs->trans("Disabled"), 'switch_off');
66 $actl[1] = img_picto($langs->trans("Activated"), 'switch_on');
67 
68 $listoffset = GETPOST('listoffset', 'alpha');
69 $listlimit = GETPOST('listlimit', 'alpha') > 0 ?GETPOST('listlimit', 'alpha') : 1000;
70 
71 $sortfield = GETPOST("sortfield", 'alpha');
72 $sortorder = GETPOST("sortorder", 'alpha');
73 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
74 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
75 $offset = $listlimit * $page;
76 $pageprev = $page - 1;
77 $pagenext = $page + 1;
78 
79 if (empty($sortfield)) $sortfield = 'type_template, lang, position, label';
80 if (empty($sortorder)) $sortorder = 'ASC';
81 
82 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
83 $hookmanager->initHooks(array('emailtemplates'));
84 
85 // Name of SQL tables of dictionaries
86 $tabname = array();
87 $tabname[25] = MAIN_DB_PREFIX."c_email_templates";
88 
89 // Nom des champs en resultat de select pour affichage du dictionnaire
90 $tabfield = array();
91 $tabfield[25] = "label,lang,type_template,fk_user,private,position,topic,joinfiles,content";
92 if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) $tabfield[25] .= ',content_lines';
93 
94 // Nom des champs d'edition pour modification d'un enregistrement
95 $tabfieldvalue = array();
96 $tabfieldvalue[25] = "label,lang,type_template,fk_user,private,position,topic,joinfiles,content";
97 if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) $tabfieldvalue[25] .= ',content_lines';
98 
99 // Nom des champs dans la table pour insertion d'un enregistrement
100 $tabfieldinsert = array();
101 $tabfieldinsert[25] = "label,lang,type_template,fk_user,private,position,topic,joinfiles,content";
102 if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) $tabfieldinsert[25] .= ',content_lines';
103 $tabfieldinsert[25] .= ',entity'; // Must be at end because not into other arrays
104 
105 // Condition to show dictionary in setup page
106 $tabcond = array();
107 $tabcond[25] = true;
108 
109 // List of help for fields
110 // Set MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES to allow edit of template for lines
111 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
112 $formmail = new FormMail($db);
113 if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES))
114 {
115  $tmp = FormMail::getAvailableSubstitKey('formemail');
116  $tmp['__(AnyTranslationKey)__'] = 'Translation';
117  $helpsubstit = $langs->trans("AvailableVariables").':<br>';
118  $helpsubstitforlines = $langs->trans("AvailableVariables").':<br>';
119  foreach ($tmp as $key => $val)
120  {
121  $helpsubstit .= $key.' -> '.$val.'<br>';
122  $helpsubstitforlines .= $key.' -> '.$val.'<br>';
123  }
124 } else {
125  $tmp = FormMail::getAvailableSubstitKey('formemailwithlines');
126  $tmp['__(AnyTranslationKey)__'] = 'Translation';
127  $helpsubstit = $langs->trans("AvailableVariables").':<br>';
128  $helpsubstitforlines = $langs->trans("AvailableVariables").':<br>';
129  foreach ($tmp as $key => $val)
130  {
131  $helpsubstit .= $key.' -> '.$val.'<br>';
132  }
133  $tmp = FormMail::getAvailableSubstitKey('formemailforlines');
134  foreach ($tmp as $key => $val)
135  {
136  $helpsubstitforlines .= $key.' -> '.$val.'<br>';
137  }
138 }
139 
140 
141 $tabhelp = array();
142 $tabhelp[25] = array(
143  'topic'=>$helpsubstit,
144  'joinfiles'=>$langs->trans('AttachMainDocByDefault'),
145  'content'=>$helpsubstit,
146  'content_lines'=>$helpsubstitforlines,
147  'type_template'=>$langs->trans("TemplateForElement"),
148  'private'=>$langs->trans("TemplateIsVisibleByOwnerOnly"),
149  'position'=>$langs->trans("PositionIntoComboList")
150 );
151 
152 // List of check for fields (NOT USED YET)
153 $tabfieldcheck = array();
154 $tabfieldcheck[25] = array();
155 
156 
157 $elementList = array();
158 
159 // We save list of template email Dolibarr can manage. This list can found by a grep into code on "->param['models']"
160 $elementList = array();
161 // Add all and none after the sort
162 $elementList['all'] = '-- '.dol_escape_htmltag($langs->trans("All")).' --';
163 $elementList['none'] = '-- '.dol_escape_htmltag($langs->trans("None")).' --';
164 $elementList['user'] = img_picto('', 'user', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToUser'));
165 if ($conf->adherent->enabled && $user->rights->adherent->lire) {
166  $elementList['member'] = img_picto('', 'object_member', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToMember'));
167 }
168 if ($conf->recruitment->enabled && $user->rights->recruitment->recruitmentjobposition->read) {
169  $elementList['recruitmentcandidature_send'] = img_picto('', 'recruitmentcandidature', 'class="paddingright"').dol_escape_htmltag($langs->trans('RecruitmentCandidatures'));
170 }
171 if ($conf->societe->enabled && $user->rights->societe->lire) {
172  $elementList['thirdparty'] = img_picto('', 'company', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToThirdparty'));
173 }
174 if ($conf->projet->enabled) {
175  $elementList['project'] = img_picto('', 'project', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToProject'));
176 }
177 if ($conf->propal->enabled && $user->rights->propal->lire) {
178  $elementList['propal_send'] = img_picto('', 'propal', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToSendProposal'));
179 }
180 if ($conf->commande->enabled && $user->rights->commande->lire) {
181  $elementList['order_send'] = img_picto('', 'order', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToSendOrder'));
182 }
183 if ($conf->facture->enabled && $user->rights->facture->lire) {
184  $elementList['facture_send'] = img_picto('', 'bill', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToSendInvoice'));
185 }
186 if ($conf->expedition->enabled) {
187  $elementList['shipping_send'] = img_picto('', 'dolly', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToSendShipment'));
188 }
189 if ($conf->reception->enabled) {
190  $elementList['reception_send'] = img_picto('', 'dolly', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToSendReception'));
191 }
192 if ($conf->ficheinter->enabled) {
193  $elementList['fichinter_send'] = img_picto('', 'intervention', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToSendIntervention'));
194 }
195 if ($conf->supplier_proposal->enabled) {
196  $elementList['supplier_proposal_send'] = img_picto('', 'propal', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToSendSupplierRequestForQuotation'));
197 }
198 if (($conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || ($conf->supplier_order->enabled && $user->rights->supplier_order->lire)) {
199  $elementList['order_supplier_send'] = img_picto('', 'order', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToSendSupplierOrder'));
200 }
201 if (($conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || ($conf->supplier_invoice->enabled && $user->rights->supplier_invoice->lire)) {
202  $elementList['invoice_supplier_send'] = img_picto('', 'bill', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToSendSupplierInvoice'));
203 }
204 if ($conf->contrat->enabled && $user->rights->contrat->lire) {
205  $elementList['contract'] = img_picto('', 'contract', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToSendContract'));
206 }
207 if ($conf->ticket->enabled && $user->rights->ticket->read) {
208  $elementList['ticket_send'] = img_picto('', 'ticket', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToTicket'));
209 }
210 if ($conf->agenda->enabled) {
211  $elementList['actioncomm_send'] = img_picto('', 'action', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToSendEventPush'));
212 }
213 
214 $parameters = array('elementList'=>$elementList);
215 $reshook = $hookmanager->executeHooks('emailElementlist', $parameters); // Note that $action and $object may have been modified by some hooks
216 if ($reshook == 0) {
217  foreach ($hookmanager->resArray as $item => $value) {
218  $elementList[$item] = $value;
219  }
220 }
221 
222 //asort($elementList);
223 
224 $id = 25;
225 
226 
227 /*
228  * Actions
229  */
230 
231 if (GETPOST('cancel', 'alpha')) {
232  $action = 'list';
233  $massaction = '';
234 }
235 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
236 
237 $parameters = array();
238 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
239 if ($reshook < 0) {
240  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
241 }
242 
243 if (empty($reshook)) {
244  // Purge search criteria
245  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
246  // All tests are required to be compatible with all browsers
247  $search_label = '';
248  $search_type_template = '';
249  $search_lang = '';
250  $search_fk_user = '';
251  $search_topic = '';
252  $toselect = '';
253  $search_array_options = array();
254  }
255 
256  // Actions add or modify an entry into a dictionary
257  if (GETPOST('actionadd', 'alpha') || GETPOST('actionmodify', 'alpha')) {
258  $listfield = explode(',', str_replace(' ', '', $tabfield[$id]));
259  $listfieldinsert = explode(',', $tabfieldinsert[$id]);
260  $listfieldmodify = explode(',', $tabfieldinsert[$id]);
261  $listfieldvalue = explode(',', $tabfieldvalue[$id]);
262 
263  // Check that all fields are filled
264  $ok = 1;
265  foreach ($listfield as $f => $value) {
266  // Not mandatory fields
267  if ($value == 'joinfiles') continue;
268  if ($value == 'content') continue;
269  if ($value == 'content_lines') continue;
270 
271  // Rename some POST variables into a generic name
272  if (GETPOST('actionmodify', 'alpha') && $value == 'topic') $_POST['topic'] = $_POST['topic-'.$rowid];
273 
274  if ((!GETPOSTISSET($value) || GETPOST($value) == '' || GETPOST($value) == '-1') && $value != 'lang' && $value != 'fk_user' && $value != 'position')
275  {
276  $ok = 0;
277  $fieldnamekey = $listfield[$f];
278  // We take translate key of field
279  if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) $fieldnamekey = 'Code';
280  if ($fieldnamekey == 'code') $fieldnamekey = 'Code';
281  if ($fieldnamekey == 'note') $fieldnamekey = 'Note';
282  if ($fieldnamekey == 'type_template') $fieldnamekey = 'TypeOfTemplate';
283  if ($fieldnamekey == 'fk_user') $fieldnamekey = 'Owner';
284  if ($fieldnamekey == 'private') $fieldnamekey = 'Private';
285  if ($fieldnamekey == 'position') $fieldnamekey = 'Position';
286  if ($fieldnamekey == 'topic') $fieldnamekey = 'Topic';
287 
288  setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
289  }
290  }
291 
292  // Si verif ok et action add, on ajoute la ligne
293  if ($ok && GETPOST('actionadd'))
294  {
295  // Add new entry
296  $sql = "INSERT INTO ".$tabname[$id]." (";
297  // List of fields
298  $sql .= $tabfieldinsert[$id];
299  $sql .= ",active)";
300  $sql .= " VALUES(";
301 
302  // List of values
303  $i = 0;
304  foreach ($listfieldinsert as $f => $value)
305  {
306  $keycode = $listfieldvalue[$i];
307  if ($value == 'lang') $keycode = 'langcode';
308  if (empty($keycode)) $keycode = $value;
309 
310  // Clean input variables
311  if ($value == 'entity') $_POST[$keycode] = $conf->entity;
312  if ($value == 'fk_user' && !($_POST[$keycode] > 0)) $_POST[$keycode] = '';
313  if ($value == 'private' && !is_numeric($_POST[$keycode])) $_POST[$keycode] = '0';
314  if ($value == 'position' && !is_numeric($_POST[$keycode])) $_POST[$keycode] = '1';
315  //var_dump($keycode.' '.$value);
316 
317  if ($i) $sql .= ", ";
318  if (GETPOST($keycode) == '' && $keycode != 'langcode') $sql .= "null"; // langcode must be '' if not defined so the unique key that include lang will work
319  elseif (GETPOST($keycode) == '0' && $keycode == 'langcode') $sql .= "''"; // langcode must be '' if not defined so the unique key that include lang will work
320  elseif ($keycode == 'fk_user') {
321  if (!$user->admin) { // A non admin user can only edit its own template
322  $sql .= " ".((int) $user->id);
323  } else {
324  $sql .= " ".((int) GETPOST($keycode, 'int'));
325  }
326  } elseif ($keycode == 'content') {
327  $sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
328  } elseif (in_array($keycode, array('joinfiles', 'private', 'position'))) {
329  $sql .= (int) GETPOST($keycode, 'int');
330  } else {
331  $sql .= "'".$db->escape(GETPOST($keycode, 'nohtml'))."'";
332  }
333  $i++;
334  }
335  $sql .= ", 1)";
336 
337  dol_syslog("actionadd", LOG_DEBUG);
338  $result = $db->query($sql);
339  if ($result) // Add is ok
340  {
341  setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
342  $_POST = array('id'=>$id); // Clean $_POST array, we keep only id
343  } else {
344  if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
345  setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
346  } else {
347  dol_print_error($db);
348  }
349  }
350  }
351 
352  // We modify the line
353  if ($ok && GETPOST('actionmodify'))
354  {
355  $rowidcol = "rowid";
356 
357  // Modify entry
358  $sql = "UPDATE ".$tabname[$id]." SET ";
359  // Modifie valeur des champs
360  $i = 0;
361  foreach ($listfieldmodify as $field)
362  {
363  $keycode = $listfieldvalue[$i];
364  if ($field == 'lang') $keycode = 'langcode';
365  if (empty($keycode)) $keycode = $field;
366 
367  // Rename some POST variables into a generic name
368  if ($field == 'fk_user' && !($_POST['fk_user'] > 0)) $_POST['fk_user'] = '';
369  if ($field == 'topic') $_POST['topic'] = $_POST['topic-'.$rowid];
370  if ($field == 'joinfiles') $_POST['joinfiles'] = $_POST['joinfiles-'.$rowid];
371  if ($field == 'content') $_POST['content'] = $_POST['content-'.$rowid];
372  if ($field == 'content_lines') $_POST['content_lines'] = $_POST['content_lines-'.$rowid];
373  if ($field == 'entity') $_POST[$keycode] = $conf->entity;
374 
375  if ($i) $sql .= ", ";
376  $sql .= $field."=";
377 
378  if (GETPOST($keycode) == '' || ($keycode != 'langcode' && $keycode != 'position' && $keycode != 'private' && !GETPOST($keycode))) $sql .= "null"; // langcode,... must be '' if not defined so the unique key that include lang will work
379  elseif (GETPOST($keycode) == '0' && $keycode == 'langcode') $sql .= "''"; // langcode must be '' if not defined so the unique key that include lang will work
380  elseif ($keycode == 'fk_user') {
381  if (!$user->admin) { // A non admin user can only edit its own template
382  $sql .= " ".((int) $user->id);
383  } else {
384  $sql .= " ".((int) GETPOST($keycode, 'int'));
385  }
386  } elseif ($keycode == 'content') {
387  $sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
388  } elseif (in_array($keycode, array('joinfiles', 'private', 'position'))) {
389  $sql .= (int) GETPOST($keycode, 'int');
390  } else {
391  $sql .= "'".$db->escape(GETPOST($keycode, 'nohtml'))."'";
392  }
393 
394  $i++;
395  }
396 
397  $sql .= " WHERE ".$rowidcol." = ".((int) $rowid);
398  if (!$user->admin) { // A non admin user can only edit its own template
399  $sql .= " AND fk_user = ".((int) $user->id);
400  }
401  //print $sql;exit;
402  dol_syslog("actionmodify", LOG_DEBUG);
403  //print $sql;
404  $resql = $db->query($sql);
405  if ($resql)
406  {
407  setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
408  } else {
409  setEventMessages($db->error(), null, 'errors');
410  }
411  }
412  }
413 
414  if ($action == 'confirm_delete' && $confirm == 'yes') // delete
415  {
416  $rowidcol = "rowid";
417 
418  $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol."=".((int) $rowid);
419  if (!$user->admin) { // A non admin user can only edit its own template
420  $sql .= " AND fk_user = ".((int) $user->id);
421  }
422  dol_syslog("delete", LOG_DEBUG);
423  $result = $db->query($sql);
424  if (!$result)
425  {
426  if ($db->errno() == 'DB_ERROR_CHILD_EXISTS')
427  {
428  setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
429  } else {
430  dol_print_error($db);
431  }
432  }
433  }
434 
435  // activate
436  if ($action == $acts[0])
437  {
438  $rowidcol = "rowid";
439 
440  $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."=".((int) $rowid);
441 
442  $result = $db->query($sql);
443  if (!$result)
444  {
445  dol_print_error($db);
446  }
447  }
448 
449  // disable
450  if ($action == $acts[1])
451  {
452  $rowidcol = "rowid";
453 
454  $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."=".((int) $rowid);
455 
456  $result = $db->query($sql);
457  if (!$result)
458  {
459  dol_print_error($db);
460  }
461  }
462 }
463 
464 
465 /*
466  * View
467  */
468 
469 $form = new Form($db);
470 $formadmin = new FormAdmin($db);
471 
472 $help_url = '';
473 $title = $langs->trans("EMailsSetup");
474 
475 llxHeader('', $title, $help_url);
476 
477 $linkback = '';
478 $titlepicto = 'title_setup';
479 
480 print load_fiche_titre($title, $linkback, $titlepicto);
481 
482 $head = email_admin_prepare_head();
483 
484 print dol_get_fiche_head($head, 'templates', '', -1);
485 
486 // Confirmation de la suppression de la ligne
487 if ($action == 'delete')
488 {
489  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);
490 }
491 
492 
493 $sql = "SELECT rowid as rowid, module, label, type_template, lang, fk_user, private, position, topic, joinfiles, content_lines, content, enabled, active";
494 $sql .= " FROM ".MAIN_DB_PREFIX."c_email_templates";
495 $sql .= " WHERE entity IN (".getEntity('email_template').")";
496 if (!$user->admin)
497 {
498  $sql .= " AND (private = 0 OR (private = 1 AND fk_user = ".$user->id."))"; // Show only public and private to me
499  $sql .= " AND (active = 1 OR fk_user = ".$user->id.")"; // Show only active or owned by me
500 }
501 if (empty($conf->global->MAIN_MULTILANGS))
502 {
503  $sql .= " AND (lang = '".$db->escape($langs->defaultlang)."' OR lang IS NULL OR lang = '')";
504 }
505 if ($search_label) $sql .= natural_search('label', $search_label);
506 if ($search_type_template != '' && $search_type_template != '-1') $sql .= natural_search('type_template', $search_type_template);
507 if ($search_lang) $sql .= natural_search('lang', $search_lang);
508 if ($search_fk_user != '' && $search_fk_user != '-1') $sql .= natural_search('fk_user', $search_fk_user, 2);
509 if ($search_topic) $sql .= natural_search('topic', $search_topic);
510 // If sort order is "country", we use country_code instead
511 if ($sortfield == 'country') $sortfield = 'country_code';
512 $sql .= $db->order($sortfield, $sortorder);
513 $sql .= $db->plimit($listlimit + 1, $offset);
514 //print $sql;
515 
516 $fieldlist = explode(',', $tabfield[$id]);
517 
518 if ($action == 'view') {
519  // Form to add a new line
520  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
521  print '<input type="hidden" name="token" value="'.newToken().'">';
522  print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
523 
524  print '<div class="div-table-responsive-no-min">';
525  print '<table class="noborder centpercent">';
526 
527  // Line to enter new values (title)
528  print '<tr class="liste_titre">';
529  foreach ($fieldlist as $field => $value)
530  {
531  // Determine le nom du champ par rapport aux noms possibles
532  // dans les dictionnaires de donnees
533  $valuetoshow = ucfirst($fieldlist[$field]); // Par defaut
534  $valuetoshow = $langs->trans($valuetoshow); // try to translate
535  $align = "left";
536  if ($fieldlist[$field] == 'fk_user') { $valuetoshow = $langs->trans("Owner"); }
537  if ($fieldlist[$field] == 'lang') { $valuetoshow = (empty($conf->global->MAIN_MULTILANGS) ? '&nbsp;' : $langs->trans("Language")); }
538  if ($fieldlist[$field] == 'type') { $valuetoshow = $langs->trans("Type"); }
539  if ($fieldlist[$field] == 'code') { $valuetoshow = $langs->trans("Code"); }
540  if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') { $valuetoshow = $langs->trans("Code"); }
541  if ($fieldlist[$field] == 'type_template') { $valuetoshow = $langs->trans("TypeOfTemplate"); $align = "center"; }
542  if ($fieldlist[$field] == 'private') { $align = 'center'; }
543  if ($fieldlist[$field] == 'position') { $align = 'center'; }
544 
545  if ($fieldlist[$field] == 'topic') { $valuetoshow = ''; }
546  if ($fieldlist[$field] == 'joinfiles') { $valuetoshow = ''; }
547  if ($fieldlist[$field] == 'content') { $valuetoshow = ''; }
548  if ($fieldlist[$field] == 'content_lines') { $valuetoshow = ''; }
549 
550  if ($valuetoshow != '')
551  {
552  print '<td class="'.$align.'">';
553  if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) print '<a href="'.$tabhelp[$id][$value].'" target="_blank">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
554  elseif (!empty($tabhelp[$id][$value]))
555  {
556  if (in_array($value, array('topic'))) print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, $value); // Tooltip on click
557  else print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2); // Tooltip on hover
558  } else print $valuetoshow;
559  print '</td>';
560  }
561  }
562  print '<td>';
563  print '<input type="hidden" name="id" value="'.$id.'">';
564  print '</td>';
565  print '</tr>';
566 
567  $obj = new stdClass();
568  // If data was already input, we define them in obj to populate input fields.
569  if (GETPOST('actionadd'))
570  {
571  foreach ($fieldlist as $key => $val) {
572  if (GETPOST($val) != '')
573  $obj->$val = GETPOST($val);
574  }
575  }
576 
577  $tmpaction = 'create';
578  $parameters = array(
579  'fieldlist' => $fieldlist,
580  'tabname' => $tabname[$id]
581  );
582  $reshook = $hookmanager->executeHooks('createEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
583  $error = $hookmanager->error;
584  $errors = $hookmanager->errors;
585 
586 
587  // Line to enter new values (input fields)
588  print '<tr class="oddeven">';
589 
590  if (empty($reshook))
591  {
592  if ($action == 'edit') {
593  fieldList($fieldlist, $obj, $tabname[$id], 'hide');
594  } else {
595  fieldList($fieldlist, $obj, $tabname[$id], 'add');
596  }
597  }
598 
599  print '<td class="right">';
600  print '</td>';
601  print "</tr>";
602 
603  // Show fields for topic, join files and body
604  $fieldsforcontent = array('topic', 'joinfiles', 'content');
605  if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) { $fieldsforcontent = array('topic', 'joinfiles', 'content', 'content_lines'); }
606  foreach ($fieldsforcontent as $tmpfieldlist)
607  {
608  print '<tr class="impair nodrag nodrop nohover"><td colspan="6" class="nobottom">';
609 
610  // Label
611  if ($tmpfieldlist == 'topic')
612  {
613  print '<strong>'.$form->textwithpicto($langs->trans("Topic"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
614  }
615  if ($tmpfieldlist == 'joinfiles')
616  {
617  print '<strong>'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
618  }
619  if ($tmpfieldlist == 'content')
620  print $form->textwithpicto($langs->trans("Content"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
621  if ($tmpfieldlist == 'content_lines')
622  print $form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
623 
624  // Input field
625  if ($tmpfieldlist == 'topic') {
626  print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'">';
627  } elseif ($tmpfieldlist == 'joinfiles') {
628  print '<input type="text" class="flat maxwidth50" name="'.$tmpfieldlist.'" value="'.(isset($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '1').'">';
629  } else {
630  // print '<textarea cols="3" rows="'.ROWS_2.'" class="flat" name="'.$fieldlist[$field].'">'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'</textarea>';
631  $okforextended = true;
632  if (empty($conf->global->FCKEDITOR_ENABLE_MAIL))
633  $okforextended = false;
634  $doleditor = new DolEditor($tmpfieldlist, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 180, 'dolibarr_mailings', 'In', 0, false, $okforextended, ROWS_4, '90%');
635  print $doleditor->Create(1);
636  }
637  print '</td>';
638  if ($tmpfieldlist == 'topic') {
639  print '<td class="center" rowspan="'.(count($fieldsforcontent)).'">';
640  if ($action != 'edit') {
641  print '<input type="submit" class="button" name="actionadd" value="'.$langs->trans("Add").'">';
642  }
643  print '</td>';
644  }
645  // else print '<td></td>';
646  print '</tr>';
647  }
648 
649  print '</table>';
650  print '</div>';
651  print '</form>';
652  print '<br>';
653 } // END IF not edit
654 
655 print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
656 print '<input type="hidden" name="token" value="'.newToken().'">';
657 print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
658 
659 print '<div class="div-table-responsive-no-min">';
660 print '<table class="noborder centpercent">';
661 
662 // List of available record in database
663 dol_syslog("htdocs/admin/dict", LOG_DEBUG);
664 $resql = $db->query($sql);
665 if ($resql)
666 {
667  $num = $db->num_rows($resql);
668  $i = 0;
669 
670  $param = '&id='.$id;
671  if ($search_label) $param .= '&search_label='.urlencode($search_label);
672  if ($search_lang > 0) $param .= '&search_lang='.urlencode($search_lang);
673  if ($search_type_template != '-1') $param .= '&search_type_template='.urlencode($search_type_template);
674  if ($search_fk_user > 0) $param .= '&search_fk_user='.urlencode($search_fk_user);
675  if ($search_topic) $param .= '&search_topic='.urlencode($search_topic);
676 
677  $paramwithsearch = $param;
678  if ($sortorder) $paramwithsearch .= '&sortorder='.urlencode($sortorder);
679  if ($sortfield) $paramwithsearch .= '&sortfield='.urlencode($sortfield);
680  if (GETPOST('from', 'alpha')) $paramwithsearch .= '&from='.urlencode(GETPOST('from', 'alpha'));
681 
682  // There is several pages
683  if ($num > $listlimit)
684  {
685  print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).'">';
686  print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
687  print '</td></tr>';
688  }
689 
690 
691  // Title line with search boxes
692  print '<tr class="liste_titre">';
693 
694  foreach ($fieldlist as $field => $value)
695  {
696  if ($value == 'label') {
697  print '<td class="liste_titre"><input type="text" name="search_label" class="maxwidth200" value="'.dol_escape_htmltag($search_label).'"></td>';
698  } elseif ($value == 'lang') {
699  print '<td class="liste_titre">';
700  print $formadmin->select_language($search_lang, 'search_lang', 0, null, 1, 0, 0, 'maxwidth150');
701  print '</td>';
702  } elseif ($value == 'fk_user') {
703  print '<td class="liste_titre">';
704  print $form->select_dolusers($search_fk_user, 'search_fk_user', 1, null, 0, ($user->admin ? '' : 'hierarchyme'), null, 0, 0, 1, '', 0, '', 'maxwidth150');
705  print '</td>';
706  } elseif ($value == 'topic') {
707  print '<td class="liste_titre"><input type="text" name="search_topic" value="'.dol_escape_htmltag($search_topic).'"></td>';
708  } elseif ($value == 'type_template') {
709  print '<td class="liste_titre center">';
710  print $form->selectarray('search_type_template', $elementList, $search_type_template, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth200', 1, '', 0, 1);
711  print '</td>';
712  } elseif (!in_array($value, array('content', 'content_lines'))) {
713  print '<td class="liste_titre"></td>';
714  }
715  }
716 
717  if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) print '<td class="liste_titre"></td>';
718 
719  // Action column
720  print '<td class="liste_titre right" width="64">';
721  $searchpicto = $form->showFilterButtons();
722  print $searchpicto;
723  print '</td>';
724  print '</tr>';
725 
726  // Title of lines
727  print '<tr class="liste_titre">';
728  foreach ($fieldlist as $field => $value)
729  {
730  $showfield = 1; // By defaut
731  $align = "left";
732  $sortable = 1;
733  $valuetoshow = '';
734  $forcenowrap = 1;
735  /*
736  $tmparray=getLabelOfField($fieldlist[$field]);
737  $showfield=$tmp['showfield'];
738  $valuetoshow=$tmp['valuetoshow'];
739  $align=$tmp['align'];
740  $sortable=$tmp['sortable'];
741  */
742  $valuetoshow = ucfirst($fieldlist[$field]); // By defaut
743  $valuetoshow = $langs->trans($valuetoshow); // try to translate
744  if ($fieldlist[$field] == 'fk_user') { $valuetoshow = $langs->trans("Owner"); }
745  if ($fieldlist[$field] == 'lang') { $valuetoshow = $langs->trans("Language"); }
746  if ($fieldlist[$field] == 'type') { $valuetoshow = $langs->trans("Type"); }
747  if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') { $valuetoshow = $langs->trans("Code"); }
748  if ($fieldlist[$field] == 'type_template') { $valuetoshow = $langs->trans("TypeOfTemplate"); }
749  if ($fieldlist[$field] == 'private') { $align = 'center'; }
750  if ($fieldlist[$field] == 'position') { $align = 'center'; }
751 
752  if ($fieldlist[$field] == 'joinfiles') { $valuetoshow = $langs->trans("FilesAttachedToEmail"); $align = 'center'; $forcenowrap = 0; }
753  if ($fieldlist[$field] == 'content') { $valuetoshow = $langs->trans("Content"); $showfield = 0; }
754  if ($fieldlist[$field] == 'content_lines') { $valuetoshow = $langs->trans("ContentLines"); $showfield = 0; }
755 
756  // Show fields
757  if ($showfield)
758  {
759  if (!empty($tabhelp[$id][$value]))
760  {
761  if (in_array($value, array('topic'))) $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, 'tooltip'.$value, $forcenowrap); // Tooltip on click
762  else $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, '', $forcenowrap); // Tooltip on hover
763  }
764  print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable ? $fieldlist[$field] : ''), ($page ? 'page='.$page.'&' : ''), $param, "align=".$align, $sortfield, $sortorder);
765  }
766  }
767 
768  print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, 'align="center"', $sortfield, $sortorder);
770  print '</tr>';
771 
772  if ($num)
773  {
774  // Lines with values
775  while ($i < $num)
776  {
777  $obj = $db->fetch_object($resql);
778 
779  if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code)))
780  {
781  print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
782 
783  $tmpaction = 'edit';
784  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
785  $reshook = $hookmanager->executeHooks('editEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
786  $error = $hookmanager->error; $errors = $hookmanager->errors;
787 
788  // Show fields
789  if (empty($reshook)) fieldList($fieldlist, $obj, $tabname[$id], 'edit');
790 
791  print '<td></td><td></td><td></td>';
792  print '<td class="center">';
793  print '<input type="hidden" name="page" value="'.$page.'">';
794  print '<input type="hidden" name="rowid" value="'.$rowid.'">';
795  print '<input type="submit" class="button buttongen" name="actionmodify" value="'.$langs->trans("Modify").'">';
796  print '<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'"></div>';
797  print '<input type="submit" class="button buttongen button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
798  print '</td>';
799 
800  $fieldsforcontent = array('topic', 'joinfiles', 'content');
801  if (!empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES))
802  {
803  $fieldsforcontent = array('topic', 'joinfiles', 'content', 'content_lines');
804  }
805  foreach ($fieldsforcontent as $tmpfieldlist)
806  {
807  $showfield = 1;
808  $align = "left";
809  $valuetoshow = $obj->{$tmpfieldlist};
810 
811  $class = 'tddict';
812  // Show value for field
813  if ($showfield) {
814  // Show line for topic, joinfiles and content
815  print '</tr><tr class="oddeven" nohover tr-'.$tmpfieldlist.'-'.$rowid.' ">';
816  print '<td colspan="8">';
817  if ($tmpfieldlist == 'topic')
818  {
819  print '<strong>'.$form->textwithpicto($langs->trans("Topic"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
820  print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'">';
821  }
822  if ($tmpfieldlist == 'joinfiles')
823  {
824  print '<strong>'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
825  print '<input type="text" class="flat maxwidth50" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'">';
826  }
827  if ($tmpfieldlist == 'content')
828  {
829  print $form->textwithpicto($langs->trans("Content"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
830  $okforextended = true;
831  if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) $okforextended = false;
832  $doleditor = new DolEditor($tmpfieldlist.'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 500, 'dolibarr_mailings', 'In', 0, false, $okforextended, ROWS_6, '90%');
833  print $doleditor->Create(1);
834  }
835  print '</td>';
836  print '<td></td>';
837  print '<td></td>';
838  }
839  }
840 
841  print "</tr>\n";
842  } else {
843  // If template is for a module, check module is enabled.
844  if ($obj->module) {
845  $tempmodulekey = $obj->module;
846  if (empty($conf->$tempmodulekey) || empty($conf->$tempmodulekey->enabled)) {
847  $i++;
848  continue;
849  }
850  }
851 
852  $keyforobj = 'type_template';
853  if (!in_array($obj->$keyforobj, array_keys($elementList)))
854  {
855  $i++;
856  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)
857  }
858  // Test on 'enabled'
859  if (!dol_eval($obj->enabled, 1))
860  {
861  $i++;
862  continue; // Email template not qualified
863  }
864 
865  print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
866 
867  $tmpaction = 'view';
868  $parameters = array('var'=>$var, 'fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
869  $reshook = $hookmanager->executeHooks('viewEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
870 
871  $error = $hookmanager->error; $errors = $hookmanager->errors;
872 
873  if (empty($reshook))
874  {
875  foreach ($fieldlist as $field => $value)
876  {
877  if (in_array($fieldlist[$field], array('content', 'content_lines'))) continue;
878  $showfield = 1;
879  $align = "";
880  $class = "tddict";
881  $valuetoshow = $obj->{$fieldlist[$field]};
882  if ($value == 'label' || $value == 'topic') {
883  $valuetoshow = dol_escape_htmltag($valuetoshow);
884  }
885  if ($value == 'label') {
886  $class .= ' tdoverflowmax100';
887  }
888  /*if ($value == 'topic') {
889  $class .= ' tdoverflowmax300';
890  }*/
891  if ($value == 'type_template') {
892  $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
893  $align = "center";
894  }
895  if ($value == 'lang' && $valuetoshow) {
896  $valuetoshow = $valuetoshow.' - '.$langs->trans("Language_".$valuetoshow);
897  }
898  if ($value == 'fk_user') {
899  if ($valuetoshow > 0)
900  {
901  $fuser = new User($db);
902  $fuser->fetch($valuetoshow);
903  $valuetoshow = $fuser->getNomUrl(1);
904  }
905  }
906  if ($value == 'private') {
907  $align = "center";
908  if ($valuetoshow) $valuetoshow = yn($valuetoshow);
909  else $valuetoshow = '';
910  }
911  if ($value == 'position') {
912  $align = "center";
913  }
914  if ($value == 'joinfiles') {
915  $align = "center";
916  if ($valuetoshow) $valuetoshow = 1;
917  else $valuetoshow = '';
918  }
919  if ($align) $class .= ' '.$align;
920 
921  // Show value for field
922  if ($showfield) {
923  print '<!-- '.$fieldlist[$field].' -->';
924  print '<td class="'.$class.'">'.$valuetoshow.'</td>';
925  }
926  }
927  }
928 
929  // Can an entry be erased or disabled ?
930  $iserasable = 1; $canbedisabled = 1; $canbemodified = 1; // true by default
931  if (!$user->admin && $obj->fk_user != $user->id)
932  {
933  $iserasable = 0;
934  $canbedisabled = 0;
935  $canbemodified = 0;
936  }
937 
938  $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) : '');
939  if ($param) $url .= '&'.$param;
940  $url .= '&';
941 
942  // Status / Active
943  print '<td class="center nowrap">';
944  if ($canbedisabled) print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
945  else print '<span class="opacitymedium">'.$actl[$obj->active].'</span>';
946  print "</td>";
947 
948  // Modify link / Delete link
949  print '<td class="center nowraponall" width="64">';
950  if ($canbemodified) print '<a class="reposition editfielda" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a>';
951  if ($iserasable)
952  {
953  print '<a class="marginleftonly" href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a>';
954  //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
955  }
956  print '</td>';
957 
958  /*
959  $fieldsforcontent = array('content');
960  if (! empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES))
961  {
962  $fieldsforcontent = array('content', 'content_lines');
963  }
964  foreach ($fieldsforcontent as $tmpfieldlist)
965  {
966  $showfield = 1;
967  $align = "left";
968  $valuetoshow = $obj->{$tmpfieldlist};
969 
970  $class = 'tddict';
971  // Show value for field
972  if ($showfield) {
973 
974  print '</tr><tr class="oddeven" nohover tr-'.$tmpfieldlist.'-'.$i.' "><td colspan="5">'; // To create an artificial CR for the current tr we are on
975  $okforextended = true;
976  if (empty($conf->global->FCKEDITOR_ENABLE_MAIL))
977  $okforextended = false;
978  $doleditor = new DolEditor($tmpfieldlist.'-'.$i, (! empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 140, 'dolibarr_mailings', 'In', 0, false, $okforextended, ROWS_6, '90%', 1);
979  print $doleditor->Create(1);
980  print '</td>';
981  print '<td></td><td></td><td></td>';
982 
983  }
984  }*/
985 
986  print "</tr>\n";
987  }
988 
989 
990  $i++;
991  }
992  }
993 } else {
994  dol_print_error($db);
995 }
996 
997 print '</table>';
998 print '</div>';
999 
1000 print '</form>';
1001 
1002 
1004 
1005 // End of page
1006 llxFooter();
1007 $db->close();
1008 
1009 
1019 function fieldList($fieldlist, $obj = '', $tabname = '', $context = '')
1020 {
1021  global $conf, $langs, $user, $db;
1022  global $form;
1023  global $elementList;
1024 
1025  $formadmin = new FormAdmin($db);
1026 
1027  foreach ($fieldlist as $field => $value)
1028  {
1029  if ($fieldlist[$field] == 'fk_user')
1030  {
1031  print '<td>';
1032  if ($user->admin) {
1033  print $form->select_dolusers($obj->{$fieldlist[$field]}, 'fk_user', 1, null, 0, ($user->admin ? '' : 'hierarchyme'), null, 0, 0, 1, '', 0, '', 'maxwidth200');
1034  } else {
1035  if ($context == 'add') // I am not admin and we show the add form
1036  {
1037  print $user->getNomUrl(1); // Me
1038  $forcedvalue = $user->id;
1039  } else {
1040  if ($obj && !empty($obj->{$fieldlist[$field]}) && $obj->{$fieldlist[$field]} > 0)
1041  {
1042  $fuser = new User($db);
1043  $fuser->fetch($obj->{$fieldlist[$field]});
1044  print $fuser->getNomUrl(1);
1045  $forcedvalue = $fuser->id;
1046  } else {
1047  $forcedvalue = $obj->{$fieldlist[$field]};
1048  }
1049  }
1050  $keyname = $fieldlist[$field];
1051  print '<input type="hidden" value="'.$forcedvalue.'" name="'.$keyname.'">';
1052  }
1053  print '</td>';
1054  } elseif ($fieldlist[$field] == 'lang')
1055  {
1056  print '<td>';
1057  if (!empty($conf->global->MAIN_MULTILANGS))
1058  {
1059  $selectedlang = GETPOSTISSET('langcode') ?GETPOST('langcode', 'aZ09') : $langs->defaultlang;
1060  if ($context == 'edit') $selectedlang = $obj->{$fieldlist[$field]};
1061  print $formadmin->select_language($selectedlang, 'langcode', 0, null, 1, 0, 0, 'maxwidth150');
1062  } else {
1063  if (!empty($obj->{$fieldlist[$field]}))
1064  {
1065  print $obj->{$fieldlist[$field]}.' - '.$langs->trans('Language_'.$obj->{$fieldlist[$field]});
1066  }
1067  $keyname = $fieldlist[$field];
1068  if ($keyname == 'lang') $keyname = 'langcode'; // Avoid conflict with lang param
1069  print '<input type="hidden" value="'.$obj->{$fieldlist[$field]}.'" name="'.$keyname.'">';
1070  }
1071  print '</td>';
1072  }
1073  // Le type de template
1074  elseif ($fieldlist[$field] == 'type_template')
1075  {
1076  print '<td class="center">';
1077  if ($context == 'edit' && !empty($obj->{$fieldlist[$field]}) && !in_array($obj->{$fieldlist[$field]}, array_keys($elementList)))
1078  {
1079  // Current template type is an unknown type, so we must keep it as it is.
1080  print '<input type="hidden" name="type_template" value="'.$obj->{$fieldlist[$field]}.'">';
1081  print $obj->{$fieldlist[$field]};
1082  } else {
1083  print $form->selectarray('type_template', $elementList, (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:''), 1, 0, 0, '', 0, 0, 0, '', 'maxwidth200', 1, '', 0, 1);
1084  }
1085  print '</td>';
1086  } elseif ($context == 'add' && in_array($fieldlist[$field], array('topic', 'joinfiles', 'content', 'content_lines'))) continue;
1087  elseif ($context == 'edit' && in_array($fieldlist[$field], array('topic', 'joinfiles', 'content', 'content_lines'))) continue;
1088  elseif ($context == 'hide' && in_array($fieldlist[$field], array('topic', 'joinfiles', 'content', 'content_lines'))) continue;
1089  else {
1090  $size = ''; $class = ''; $classtd = '';
1091  if ($fieldlist[$field] == 'code') $class = 'maxwidth100';
1092  if ($fieldlist[$field] == 'label') $class = 'maxwidth200';
1093  if ($fieldlist[$field] == 'private') { $class = 'maxwidth50'; $classtd = 'center'; }
1094  if ($fieldlist[$field] == 'position') { $class = 'maxwidth50'; $classtd = 'center'; }
1095  if ($fieldlist[$field] == 'libelle') $class = 'quatrevingtpercent';
1096  if ($fieldlist[$field] == 'topic') $class = 'quatrevingtpercent';
1097  if ($fieldlist[$field] == 'sortorder' || $fieldlist[$field] == 'sens' || $fieldlist[$field] == 'category_type') $size = 'size="2" ';
1098 
1099  print '<td'.($classtd ? ' class="'.$classtd.'"' : '').'>';
1100  if ($fieldlist[$field] == 'private')
1101  {
1102  if (empty($user->admin))
1103  {
1104  print $form->selectyesno($fieldlist[$field], '1', 1);
1105  } else {
1106  //print '<input type="text" '.$size.'class="flat'.($class?' '.$class:'').'" value="1" name="'.$fieldlist[$field].'">';
1107  print $form->selectyesno($fieldlist[$field], (isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:''), 1);
1108  }
1109  } else {
1110  print '<input type="text" '.$size.'class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
1111  }
1112  print '</td>';
1113  }
1114  }
1115 }
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
Classe permettant la generation du formulaire html d&#39;envoi de mail unitaire Usage: $formail = new For...
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_eval($s, $returnvalue=0, $hideerrors=1)
Replace eval function to add more security.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor &quot;?&quot;.
email_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: admin.lib.php:1845
Class to manage Dolibarr users.
Definition: user.class.php:44
Class to generate html code for admin pages.
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:44
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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...
static getAvailableSubstitKey($mode= 'formemail', $object=null)
Get list of substitution keys available for emails.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
print_fleche_navigation($page, $file, $options= '', $nextpage=0, $betweenarrows= '', $afterarrows= '', $limit=-1, $totalnboflines=0, $hideselectlimit=0, $beforearrows= '')
Function to show navigation arrows into lists.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage a WYSIWYG editor.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip= '', $forcenowrapcolumntitle=0)
Get title line of an array.
fieldList($fieldlist, $obj= '', $tabname= '', $context= '')
Show fields in insert/edit mode.
Definition: dict.php:1817
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...