dolibarr  19.0.0-dev
accountmodel.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2019 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-2019 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  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program. If not, see <https://www.gnu.org/licenses/>.
27  */
28 
35 // Load Dolibarr environment
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 if (isModEnabled('accounting')) {
44  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
45 }
46 
47 // Load translation files required by the page
48 $langs->loadLangs(array('accountancy', 'admin', 'companies', 'compta', 'errors', 'holiday', 'hrm', 'resource'));
49 
50 $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view';
51 $confirm = GETPOST('confirm', 'alpha');
52 $id = 31;
53 $rowid = GETPOST('rowid', 'alpha');
54 $code = GETPOST('code', 'alpha');
55 
56 $acts[0] = "activate";
57 $acts[1] = "disable";
58 $actl[0] = img_picto($langs->trans("Disabled"), 'switch_off', 'class="size15x"');
59 $actl[1] = img_picto($langs->trans("Activated"), 'switch_on', 'class="size15x"');
60 
61 $listoffset = GETPOST('listoffset', 'alpha');
62 $listlimit = GETPOST('listlimit', 'int') > 0 ?GETPOST('listlimit', 'int') : 1000;
63 $active = 1;
64 
65 $sortfield = GETPOST("sortfield", 'aZ09comma');
66 $sortorder = GETPOST("sortorder", 'aZ09comma');
67 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
68 if (empty($page) || $page == -1) {
69  $page = 0;
70 } // If $page is not defined, or '' or -1
71 $offset = $listlimit * $page;
72 $pageprev = $page - 1;
73 $pagenext = $page + 1;
74 
75 $search_country_id = GETPOST('search_country_id', 'int');
76 
77 
78 // Security check
79 if ($user->socid > 0) {
81 }
82 if (!$user->hasRight('accounting', 'chartofaccount')) {
84 }
85 
86 
87 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
88 $hookmanager->initHooks(array('admin'));
89 
90 // This page is a generic page to edit dictionaries
91 // Put here declaration of dictionaries properties
92 
93 // Name of SQL tables of dictionaries
94 $tabname = array();
95 
96 $tabname[31] = MAIN_DB_PREFIX."accounting_system";
97 
98 // Dictionary labels
99 $tablib = array();
100 $tablib[31] = "Pcg_version";
101 
102 // Requests to extract data
103 $tabsql = array();
104 $tabsql[31] = "SELECT s.rowid as rowid, pcg_version, s.label, s.fk_country as country_id, c.code as country_code, c.label as country, s.active FROM ".MAIN_DB_PREFIX."accounting_system as s, ".MAIN_DB_PREFIX."c_country as c WHERE s.fk_country=c.rowid and c.active=1";
105 
106 // Criteria to sort dictionaries
107 $tabsqlsort = array();
108 $tabsqlsort[31] = "pcg_version ASC";
109 
110 // Nom des champs en resultat de select pour affichage du dictionnaire
111 $tabfield = array();
112 $tabfield[31] = "pcg_version,label,country_id,country";
113 
114 // Nom des champs d'edition pour modification d'un enregistrement
115 $tabfieldvalue = array();
116 $tabfieldvalue[31] = "pcg_version,label,country";
117 
118 // Nom des champs dans la table pour insertion d'un enregistrement
119 $tabfieldinsert = array();
120 $tabfieldinsert[31] = "pcg_version,label,fk_country";
121 
122 // Nom du rowid si le champ n'est pas de type autoincrement
123 // Example: "" if id field is "rowid" and has autoincrement on
124 // "nameoffield" if id field is not "rowid" or has not autoincrement on
125 $tabrowid = array();
126 $tabrowid[31] = "";
127 
128 // Condition to show dictionary in setup page
129 $tabcond = array();
130 $tabcond[31] = isModEnabled('accounting');
131 
132 // List of help for fields
133 $tabhelp = array();
134 $tabhelp[31] = array('pcg_version'=>$langs->trans("EnterAnyCode"));
135 
136 // List of check for fields (NOT USED YET)
137 $tabfieldcheck = array();
138 $tabfieldcheck[31] = array();
139 
140 
141 // Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
142 $elementList = array();
143 $sourceList = array();
144 
145 
146 
147 /*
148  * Actions
149  */
150 
151 if (GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter_x', 'alpha')) {
152  $search_country_id = '';
153 }
154 
155 // Actions add or modify an entry into a dictionary
156 if (GETPOST('actionadd', 'alpha') || GETPOST('actionmodify', 'alpha')) {
157  $listfield = explode(',', str_replace(' ', '', $tabfield[$id]));
158  $listfieldinsert = explode(',', $tabfieldinsert[$id]);
159  $listfieldmodify = explode(',', $tabfieldinsert[$id]);
160  $listfieldvalue = explode(',', $tabfieldvalue[$id]);
161 
162  // Check that all fields are filled
163  $ok = 1;
164  foreach ($listfield as $f => $value) {
165  if ($value == 'country_id' && in_array($tablib[$id], array('Pcg_version'))) {
166  continue; // For some pages, country is not mandatory
167  }
168  if ((!GETPOSTISSET($value)) || GETPOST($value) == '') {
169  $ok = 0;
170  $fieldnamekey = $listfield[$f];
171  // We take translate key of field
172 
173  if ($fieldnamekey == 'pcg_version') {
174  $fieldnamekey = 'Pcg_version';
175  }
176  if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) {
177  $fieldnamekey = 'Label';
178  }
179 
180  setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
181  }
182  }
183  // Other checks
184  if (GETPOSTISSET("pcg_version")) {
185  if (GETPOST("pcg_version") == '0') {
186  $ok = 0;
187  setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
188  }
189  }
190  if (GETPOSTISSET("country") && (GETPOST("country") == '0') && ($id != 2)) {
191  $ok = 0;
192  setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities("Country")), null, 'errors');
193  }
194 
195  // Si verif ok et action add, on ajoute la ligne
196  if ($ok && GETPOST('actionadd', 'alpha')) {
197  if ($tabrowid[$id]) {
198  // Recupere id libre pour insertion
199  $newid = 0;
200  $sql = "SELECT max(".$tabrowid[$id].") newid from ".$tabname[$id];
201  $result = $db->query($sql);
202  if ($result) {
203  $obj = $db->fetch_object($result);
204  $newid = ($obj->newid + 1);
205  } else {
206  dol_print_error($db);
207  }
208  }
209 
210  // Add new entry
211  $sql = "INSERT INTO ".$tabname[$id]." (";
212  // List of fields
213  if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
214  $sql .= $tabrowid[$id].",";
215  }
216  $sql .= $tabfieldinsert[$id];
217  $sql .= ",active)";
218  $sql .= " VALUES(";
219 
220  // List of values
221  if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
222  $sql .= $newid.",";
223  }
224  $i = 0;
225  foreach ($listfieldinsert as $f => $value) {
226  if ($value == 'price' || preg_match('/^amount/i', $value) || $value == 'taux') {
227  $_POST[$listfieldvalue[$i]] = price2num(GETPOST($listfieldvalue[$i]), 'MU');
228  } elseif ($value == 'entity') {
229  $_POST[$listfieldvalue[$i]] = $conf->entity;
230  }
231  if ($i) {
232  $sql .= ",";
233  }
234  if (GETPOST($listfieldvalue[$i]) == '') {
235  $sql .= "null";
236  } else {
237  $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
238  }
239  $i++;
240  }
241  $sql .= ",1)";
242 
243  dol_syslog("actionadd", LOG_DEBUG);
244  $result = $db->query($sql);
245  if ($result) { // Add is ok
246  setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
247  $_POST = array('id'=>$id); // Clean $_POST array, we keep only
248  } else {
249  if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
250  setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
251  } else {
252  dol_print_error($db);
253  }
254  }
255  }
256 
257  // Si verif ok et action modify, on modifie la ligne
258  if ($ok && GETPOST('actionmodify', 'alpha')) {
259  if ($tabrowid[$id]) {
260  $rowidcol = $tabrowid[$id];
261  } else {
262  $rowidcol = "rowid";
263  }
264 
265  // Modify entry
266  $sql = "UPDATE ".$tabname[$id]." SET ";
267  // Modifie valeur des champs
268  if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
269  $sql .= $tabrowid[$id]."=";
270  $sql .= "'".$db->escape($rowid)."', ";
271  }
272  $i = 0;
273  foreach ($listfieldmodify as $field) {
274  if ($field == 'price' || preg_match('/^amount/i', $field) || $field == 'taux') {
275  $_POST[$listfieldvalue[$i]] = price2num(GETPOST($listfieldvalue[$i]), 'MU');
276  } elseif ($field == 'entity') {
277  $_POST[$listfieldvalue[$i]] = $conf->entity;
278  }
279  if ($i) {
280  $sql .= ",";
281  }
282  $sql .= $field."=";
283  if (GETPOST($listfieldvalue[$i]) == '') {
284  $sql .= "null";
285  } else {
286  $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
287  }
288  $i++;
289  }
290  $sql .= " WHERE ".$rowidcol." = ".((int) $rowid);
291 
292  dol_syslog("actionmodify", LOG_DEBUG);
293  //print $sql;
294  $resql = $db->query($sql);
295  if (!$resql) {
296  setEventMessages($db->error(), null, 'errors');
297  }
298  }
299 }
300 
301 if ($action == 'confirm_delete' && $confirm == 'yes') { // delete
302  if ($tabrowid[$id]) {
303  $rowidcol = $tabrowid[$id];
304  } else {
305  $rowidcol = "rowid";
306  }
307 
308  $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol." = ".((int) $rowid);
309 
310  dol_syslog("delete", LOG_DEBUG);
311  $result = $db->query($sql);
312  if (!$result) {
313  if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
314  setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
315  } else {
316  dol_print_error($db);
317  }
318  }
319 }
320 
321 // activate
322 if ($action == $acts[0]) {
323  if ($tabrowid[$id]) {
324  $rowidcol = $tabrowid[$id];
325  } else {
326  $rowidcol = "rowid";
327  }
328 
329  if ($rowid) {
330  $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol." = ".((int) $rowid);
331  } elseif ($code) {
332  $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$db->escape($code)."'";
333  }
334 
335  $result = $db->query($sql);
336  if (!$result) {
337  dol_print_error($db);
338  }
339 }
340 
341 // disable
342 if ($action == $acts[1]) {
343  if ($tabrowid[$id]) {
344  $rowidcol = $tabrowid[$id];
345  } else {
346  $rowidcol = "rowid";
347  }
348 
349  if ($rowid) {
350  $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol." = ".((int) $rowid);
351  } elseif ($code) {
352  $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$db->escape($code)."'";
353  }
354 
355  $result = $db->query($sql);
356  if (!$result) {
357  dol_print_error($db);
358  }
359 }
360 
361 // favorite
362 if ($action == 'activate_favorite') {
363  if ($tabrowid[$id]) {
364  $rowidcol = $tabrowid[$id];
365  } else {
366  $rowidcol = "rowid";
367  }
368 
369  if ($rowid) {
370  $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol." = ".((int) $rowid);
371  } elseif ($code) {
372  $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".$db->escape($code)."'";
373  }
374 
375  $result = $db->query($sql);
376  if (!$result) {
377  dol_print_error($db);
378  }
379 }
380 
381 // disable favorite
382 if ($action == 'disable_favorite') {
383  if ($tabrowid[$id]) {
384  $rowidcol = $tabrowid[$id];
385  } else {
386  $rowidcol = "rowid";
387  }
388 
389  if ($rowid) {
390  $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol." = ".((int) $rowid);
391  } elseif ($code) {
392  $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".$db->escape($code)."'";
393  }
394 
395  $result = $db->query($sql);
396  if (!$result) {
397  dol_print_error($db);
398  }
399 }
400 
401 
402 /*
403  * View
404  */
405 
406 $form = new Form($db);
407 $formadmin = new FormAdmin($db);
408 
409 llxHeader();
410 
411 $titre = $langs->trans($tablib[$id]);
412 $linkback = '';
413 
414 print load_fiche_titre($titre, $linkback, 'title_accountancy');
415 
416 
417 // Confirmation de la suppression de la ligne
418 if ($action == 'delete') {
419  print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.urlencode($page).'&' : '').'sortfield='.urlencode($sortfield).'&sortorder='.urlencode($sortorder).'&rowid='.urlencode($rowid).'&code='.urlencode($code).'&id='.urlencode($id), $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1);
420 }
421 //var_dump($elementList);
422 
423 /*
424  * Show a dictionary
425  */
426 if ($id) {
427  // Complete requete recherche valeurs avec critere de tri
428  $sql = $tabsql[$id];
429 
430  if ($search_country_id > 0) {
431  if (preg_match('/ WHERE /', $sql)) {
432  $sql .= " AND ";
433  } else {
434  $sql .= " WHERE ";
435  }
436  $sql .= " c.rowid = ".((int) $search_country_id);
437  }
438 
439  // If sort order is "country", we use country_code instead
440  if ($sortfield == 'country') {
441  $sortfield = 'country_code';
442  }
443  $sql .= $db->order($sortfield, $sortorder);
444  $sql .= $db->plimit($listlimit + 1, $offset);
445  //print $sql;
446 
447  $fieldlist = explode(',', $tabfield[$id]);
448 
449  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
450  print '<input type="hidden" name="token" value="'.newToken().'">';
451 
452  print '<div class="div-table-responsive">';
453  print '<table class="noborder centpercent">';
454 
455  // Form to add a new line
456  if ($tabname[$id]) {
457  $fieldlist = explode(',', $tabfield[$id]);
458 
459  // Line for title
460  print '<tr class="liste_titre">';
461  foreach ($fieldlist as $field => $value) {
462  // Determine le nom du champ par rapport aux noms possibles
463  // dans les dictionnaires de donnees
464  $valuetoshow = ucfirst($fieldlist[$field]); // Par defaut
465  $valuetoshow = $langs->trans($valuetoshow); // try to translate
466  $class = "left";
467  if ($fieldlist[$field] == 'code') {
468  $valuetoshow = $langs->trans("Code");
469  }
470  if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
471  $valuetoshow = $langs->trans("Label");
472  }
473  if ($fieldlist[$field] == 'country') {
474  if (in_array('region_id', $fieldlist)) {
475  print '<td>&nbsp;</td>'; continue;
476  } // For region page, we do not show the country input
477  $valuetoshow = $langs->trans("Country");
478  }
479  if ($fieldlist[$field] == 'country_id') {
480  $valuetoshow = '';
481  }
482  if ($fieldlist[$field] == 'pcg_version' || $fieldlist[$field] == 'fk_pcg_version') {
483  $valuetoshow = $langs->trans("Pcg_version");
484  }
485 
486  if ($valuetoshow != '') {
487  print '<td class="'.$class.'">';
488  if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
489  print '<a href="'.$tabhelp[$id][$value].'">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
490  } elseif (!empty($tabhelp[$id][$value])) {
491  print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
492  } else {
493  print $valuetoshow;
494  }
495  print '</td>';
496  }
497  }
498 
499  print '<td>';
500  print '<input type="hidden" name="id" value="'.$id.'">';
501  print '</td>';
502  print '<td></td>';
503  print '<td></td>';
504  print '</tr>';
505 
506  // Line to enter new values
507  print '<tr class="oddeven">';
508 
509  $obj = new stdClass();
510  // If data was already input, we define them in obj to populate input fields.
511  if (GETPOST('actionadd', 'alpha')) {
512  foreach ($fieldlist as $key => $val) {
513  if (GETPOST($val)) {
514  $obj->$val = GETPOST($val);
515  }
516  }
517  }
518 
519  $tmpaction = 'create';
520  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
521  $reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
522  $error = $hookmanager->error; $errors = $hookmanager->errors;
523 
524  if (empty($reshook)) {
525  fieldListAccountModel($fieldlist, $obj, $tabname[$id], 'add');
526  }
527 
528  print '<td colspan="3" class="right">';
529  print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'">';
530  print '</td>';
531  print "</tr>";
532 
533  $colspan = count($fieldlist) + 3;
534 
535  print '<tr><td colspan="'.$colspan.'">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
536  }
537 
538 
539 
540  // List of available values in database
541  dol_syslog("htdocs/admin/dict", LOG_DEBUG);
542  $resql = $db->query($sql);
543  if ($resql) {
544  $num = $db->num_rows($resql);
545  $i = 0;
546 
547  $param = '&id='.urlencode($id);
548  if ($search_country_id > 0) {
549  $param .= '&search_country_id='.urlencode($search_country_id);
550  }
551  $paramwithsearch = $param;
552  if ($sortorder) {
553  $paramwithsearch .= '&sortorder='.urlencode($sortorder);
554  }
555  if ($sortfield) {
556  $paramwithsearch .= '&sortfield='.urlencode($sortfield);
557  }
558 
559  // There is several pages
560  if ($num > $listlimit) {
561  print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).'">';
562  print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
563  print '</td></tr>';
564  }
565 
566  // Title line with search boxes
567  print '<tr class="liste_titre liste_titre_add">';
568  foreach ($fieldlist as $field => $value) {
569  $showfield = 1; // By defaut
570 
571  if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
572  $showfield = 0;
573  }
574 
575  if ($showfield) {
576  if ($value == 'country') {
577  print '<td class="liste_titre">';
578  print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth200 maxwidthonsmartphone');
579  print '</td>';
580  } else {
581  print '<td class="liste_titre"></td>';
582  }
583  }
584  }
585  print '<td class="liste_titre"></td>';
586  print '<td class="liste_titre right" colspan="2">';
587  $searchpicto = $form->showFilterAndCheckAddButtons(0);
588  print $searchpicto;
589  print '</td>';
590  print '</tr>';
591 
592  // Title of lines
593  print '<tr class="liste_titre">';
594  print getTitleFieldOfList($langs->trans("Pcg_version"), 0, $_SERVER["PHP_SELF"], "pcg_version", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
595  print getTitleFieldOfList($langs->trans("Label"), 0, $_SERVER["PHP_SELF"], "label", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
596  print getTitleFieldOfList($langs->trans("Country"), 0, $_SERVER["PHP_SELF"], "country_code", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
597  print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
598  print getTitleFieldOfList('');
599  print getTitleFieldOfList('');
600  print '</tr>';
601 
602  if ($num) {
603  $i = 0;
604  // Lines with values
605  while ($i < $num) {
606  $obj = $db->fetch_object($resql);
607  //print_r($obj);
608 
609  print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
610  if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
611  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
612  print '<input type="hidden" name="token" value="'.newToken().'">';
613  print '<input type="hidden" name="page" value="'.$page.'">';
614  print '<input type="hidden" name="rowid" value="'.$rowid.'">';
615 
616  $tmpaction = 'edit';
617  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
618  $reshook = $hookmanager->executeHooks('editDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
619  $error = $hookmanager->error; $errors = $hookmanager->errors;
620 
621  if (empty($reshook)) {
622  fieldListAccountModel($fieldlist, $obj, $tabname[$id], 'edit');
623  }
624 
625  print '<td colspan="3" class="right"><a name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'">&nbsp;</a><input type="submit" class="button button-edit" name="actionmodify" value="'.$langs->trans("Modify").'">';
626  print '&nbsp;<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'"></td>';
627  } else {
628  $tmpaction = 'view';
629  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
630  $reshook = $hookmanager->executeHooks('viewDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
631 
632  $error = $hookmanager->error; $errors = $hookmanager->errors;
633 
634  if (empty($reshook)) {
635  foreach ($fieldlist as $field => $value) {
636  $showfield = 1;
637  $class = "left";
638  $tmpvar = $fieldlist[$field];
639  $valuetoshow = $obj->$tmpvar;
640  if ($value == 'type_template') {
641  $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
642  }
643  if ($value == 'element') {
644  $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
645  } elseif ($value == 'source') {
646  $valuetoshow = isset($sourceList[$valuetoshow]) ? $sourceList[$valuetoshow] : $valuetoshow;
647  } elseif ($valuetoshow == 'all') {
648  $valuetoshow = $langs->trans('All');
649  } elseif ($fieldlist[$field] == 'country') {
650  if (empty($obj->country_code)) {
651  $valuetoshow = '-';
652  } else {
653  $key = $langs->trans("Country".strtoupper($obj->country_code));
654  $valuetoshow = ($key != "Country".strtoupper($obj->country_code) ? $obj->country_code." - ".$key : $obj->country);
655  }
656  } elseif ($fieldlist[$field] == 'country_id') {
657  $showfield = 0;
658  }
659 
660  $class = 'tddict';
661  if ($fieldlist[$field] == 'tracking') {
662  $class .= ' tdoverflowauto';
663  }
664  // Show value for field
665  if ($showfield) {
666  print '<!-- '.$fieldlist[$field].' --><td class="'.$class.'">'.$valuetoshow.'</td>';
667  }
668  }
669  }
670 
671  // Can an entry be erased or disabled ?
672  $iserasable = 1; $canbedisabled = 1; $canbemodified = 1; // true by default
673 
674  $url = $_SERVER["PHP_SELF"].'?token='.newToken().($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) : '');
675  if ($param) {
676  $url .= '&'.$param;
677  }
678  $url .= '&';
679 
680  // Active
681  print '<td class="center nowrap">';
682  if ($canbedisabled) {
683  print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
684  } else {
685  print $langs->trans("AlwaysActive");
686  }
687  print "</td>";
688 
689  // Modify link
690  if ($canbemodified) {
691  print '<td class="center"><a class="reposition editfielda" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a></td>';
692  } else {
693  print '<td>&nbsp;</td>';
694  }
695 
696  // Delete link
697  if ($iserasable) {
698  print '<td class="center"><a href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a></td>';
699  } else {
700  print '<td>&nbsp;</td>';
701  }
702 
703  print "</tr>\n";
704  }
705 
706  $i++;
707  }
708  }
709  } else {
710  dol_print_error($db);
711  }
712 
713  print '</table>';
714  print '</div>';
715 
716  print '</form>';
717 }
718 
719 print '<br>';
720 
721 // End of page
722 llxFooter();
723 $db->close();
724 
725 
735 function fieldListAccountModel($fieldlist, $obj = '', $tabname = '', $context = '')
736 {
737  global $conf, $langs, $db;
738  global $form;
739  global $region_id;
740  global $elementList, $sourceList;
741 
742  $formadmin = new FormAdmin($db);
743  $formcompany = new FormCompany($db);
744  $formaccounting = new FormAccounting($db);
745 
746  foreach ($fieldlist as $field => $value) {
747  if ($fieldlist[$field] == 'country') {
748  if (in_array('region_id', $fieldlist)) {
749  print '<td>';
750  //print join(',',$fieldlist);
751  print '</td>';
752  continue;
753  } // For state page, we do not show the country input (we link to region, not country)
754  print '<td>';
755  $fieldname = 'country';
756  print $form->select_country((!empty($obj->country_code) ? $obj->country_code : (!empty($obj->country) ? $obj->country : '')), $fieldname, '', 28, 'maxwidth200 maxwidthonsmartphone');
757  print '</td>';
758  } elseif ($fieldlist[$field] == 'country_id') {
759  if (!in_array('country', $fieldlist)) { // If there is already a field country, we don't show country_id (avoid duplicate)
760  $country_id = (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
761  print '<td>';
762  print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">';
763  print '</td>';
764  }
765  } elseif ($fieldlist[$field] == 'type_cdr') {
766  if ($fieldlist[$field] == 'type_cdr') {
767  print '<td class="center">';
768  } else {
769  print '<td>';
770  }
771  if ($fieldlist[$field] == 'type_cdr') {
772  print $form->selectarray($fieldlist[$field], array(0=>$langs->trans('None'), 1=>$langs->trans('AtEndOfMonth'), 2=>$langs->trans('CurrentNext')), (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:''));
773  } else {
774  print $form->selectyesno($fieldlist[$field], (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:''), 1);
775  }
776  print '</td>';
777  } elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
778  print '<td><input type="text" class="flat" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:'').'" size="10" name="'.$fieldlist[$field].'"></td>';
779  } else {
780  print '<td>';
781  $size = ''; $class = '';
782  if ($fieldlist[$field] == 'code') {
783  $size = 'size="8" ';
784  }
785  if ($fieldlist[$field] == 'position') {
786  $size = 'size="4" ';
787  }
788  if ($fieldlist[$field] == 'libelle') {
789  $size = 'centpercent';
790  }
791  if ($fieldlist[$field] == 'sortorder' || $fieldlist[$field] == 'sens' || $fieldlist[$field] == 'category_type') {
792  $size = 'size="2" ';
793  }
794  print '<input type="text" '.$size.' class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
795  print '</td>';
796  }
797  }
798 }
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
getTitleFieldOfList
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
Definition: functions.lib.php:5318
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5477
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:609
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:5107
img_help
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
Definition: functions.lib.php:4744
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
FormAdmin
Class to generate html code for admin pages.
Definition: html.formadmin.class.php:30
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4652
FormAccounting
Class to manage generation of HTML components for accounting management.
Definition: html.formaccounting.class.php:33
print_fleche_navigation
print_fleche_navigation($page, $file, $options='', $nextpage=0, $betweenarrows='', $afterarrows='', $limit=-1, $totalnboflines=0, $hideselectlimit=0, $beforearrows='', $hidenavigation=0)
Function to show navigation arrows into lists.
Definition: functions.lib.php:5688
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5955
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4135
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
img_delete
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
Definition: functions.lib.php:4692
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1741
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
Definition: functions.lib.php:8673
$sql
if(isModEnabled('facture') && $user->hasRight('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') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11654
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:207
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:509
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
Definition: security.lib.php:1169
fieldListAccountModel
fieldListAccountModel($fieldlist, $obj='', $tabname='', $context='')
Show fields in insert/edit mode.
Definition: accountmodel.php:735