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