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