dolibarr  17.0.4
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  //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
300 }
301 
302 if (GETPOST('actioncancel', 'alpha')) {
303  //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
304 }
305 
306 if ($action == 'confirm_delete' && $confirm == 'yes') { // delete
307  if ($tabrowid[$id]) {
308  $rowidcol = $tabrowid[$id];
309  } else {
310  $rowidcol = "rowid";
311  }
312 
313  $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol." = ".((int) $rowid);
314 
315  dol_syslog("delete", LOG_DEBUG);
316  $result = $db->query($sql);
317  if (!$result) {
318  if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
319  setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
320  } else {
321  dol_print_error($db);
322  }
323  }
324 }
325 
326 // activate
327 if ($action == $acts[0]) {
328  if ($tabrowid[$id]) {
329  $rowidcol = $tabrowid[$id];
330  } else {
331  $rowidcol = "rowid";
332  }
333 
334  if ($rowid) {
335  $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol." = ".((int) $rowid);
336  } elseif ($code) {
337  $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$db->escape($code)."'";
338  }
339 
340  $result = $db->query($sql);
341  if (!$result) {
342  dol_print_error($db);
343  }
344 }
345 
346 // disable
347 if ($action == $acts[1]) {
348  if ($tabrowid[$id]) {
349  $rowidcol = $tabrowid[$id];
350  } else {
351  $rowidcol = "rowid";
352  }
353 
354  if ($rowid) {
355  $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol." = ".((int) $rowid);
356  } elseif ($code) {
357  $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$db->escape($code)."'";
358  }
359 
360  $result = $db->query($sql);
361  if (!$result) {
362  dol_print_error($db);
363  }
364 }
365 
366 // favorite
367 if ($action == 'activate_favorite') {
368  if ($tabrowid[$id]) {
369  $rowidcol = $tabrowid[$id];
370  } else {
371  $rowidcol = "rowid";
372  }
373 
374  if ($rowid) {
375  $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol." = ".((int) $rowid);
376  } elseif ($code) {
377  $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".$db->escape($code)."'";
378  }
379 
380  $result = $db->query($sql);
381  if (!$result) {
382  dol_print_error($db);
383  }
384 }
385 
386 // disable favorite
387 if ($action == 'disable_favorite') {
388  if ($tabrowid[$id]) {
389  $rowidcol = $tabrowid[$id];
390  } else {
391  $rowidcol = "rowid";
392  }
393 
394  if ($rowid) {
395  $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol." = ".((int) $rowid);
396  } elseif ($code) {
397  $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".$db->escape($code)."'";
398  }
399 
400  $result = $db->query($sql);
401  if (!$result) {
402  dol_print_error($db);
403  }
404 }
405 
406 
407 /*
408  * View
409  */
410 
411 $form = new Form($db);
412 $formadmin = new FormAdmin($db);
413 
414 llxHeader();
415 
416 $titre = $langs->trans($tablib[$id]);
417 $linkback = '';
418 
419 print load_fiche_titre($titre, $linkback, 'title_accountancy');
420 
421 
422 // Confirmation de la suppression de la ligne
423 if ($action == 'delete') {
424  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);
425 }
426 //var_dump($elementList);
427 
428 /*
429  * Show a dictionary
430  */
431 if ($id) {
432  // Complete requete recherche valeurs avec critere de tri
433  $sql = $tabsql[$id];
434 
435  if ($search_country_id > 0) {
436  if (preg_match('/ WHERE /', $sql)) {
437  $sql .= " AND ";
438  } else {
439  $sql .= " WHERE ";
440  }
441  $sql .= " c.rowid = ".((int) $search_country_id);
442  }
443 
444  // If sort order is "country", we use country_code instead
445  if ($sortfield == 'country') {
446  $sortfield = 'country_code';
447  }
448  $sql .= $db->order($sortfield, $sortorder);
449  $sql .= $db->plimit($listlimit + 1, $offset);
450  //print $sql;
451 
452  $fieldlist = explode(',', $tabfield[$id]);
453 
454  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
455  print '<input type="hidden" name="token" value="'.newToken().'">';
456 
457  print '<div class="div-table-responsive">';
458  print '<table class="noborder centpercent">';
459 
460  // Form to add a new line
461  if ($tabname[$id]) {
462  $fieldlist = explode(',', $tabfield[$id]);
463 
464  // Line for title
465  print '<tr class="liste_titre">';
466  foreach ($fieldlist as $field => $value) {
467  // Determine le nom du champ par rapport aux noms possibles
468  // dans les dictionnaires de donnees
469  $valuetoshow = ucfirst($fieldlist[$field]); // Par defaut
470  $valuetoshow = $langs->trans($valuetoshow); // try to translate
471  $class = "left";
472  if ($fieldlist[$field] == 'code') {
473  $valuetoshow = $langs->trans("Code");
474  }
475  if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
476  $valuetoshow = $langs->trans("Label");
477  }
478  if ($fieldlist[$field] == 'country') {
479  if (in_array('region_id', $fieldlist)) {
480  print '<td>&nbsp;</td>'; continue;
481  } // For region page, we do not show the country input
482  $valuetoshow = $langs->trans("Country");
483  }
484  if ($fieldlist[$field] == 'country_id') {
485  $valuetoshow = '';
486  }
487  if ($fieldlist[$field] == 'pcg_version' || $fieldlist[$field] == 'fk_pcg_version') {
488  $valuetoshow = $langs->trans("Pcg_version");
489  }
490 
491  if ($valuetoshow != '') {
492  print '<td class="'.$class.'">';
493  if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
494  print '<a href="'.$tabhelp[$id][$value].'">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
495  } elseif (!empty($tabhelp[$id][$value])) {
496  print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
497  } else {
498  print $valuetoshow;
499  }
500  print '</td>';
501  }
502  }
503 
504  print '<td>';
505  print '<input type="hidden" name="id" value="'.$id.'">';
506  print '</td>';
507  print '<td style="min-width: 26px;"></td>';
508  print '<td style="min-width: 26px;"></td>';
509  print '</tr>';
510 
511  // Line to enter new values
512  print '<tr class="oddeven">';
513 
514  $obj = new stdClass();
515  // If data was already input, we define them in obj to populate input fields.
516  if (GETPOST('actionadd', 'alpha')) {
517  foreach ($fieldlist as $key => $val) {
518  if (GETPOST($val)) {
519  $obj->$val = GETPOST($val);
520  }
521  }
522  }
523 
524  $tmpaction = 'create';
525  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
526  $reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
527  $error = $hookmanager->error; $errors = $hookmanager->errors;
528 
529  if (empty($reshook)) {
530  fieldListAccountModel($fieldlist, $obj, $tabname[$id], 'add');
531  }
532 
533  print '<td colspan="3" class="right">';
534  print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'">';
535  print '</td>';
536  print "</tr>";
537 
538  $colspan = count($fieldlist) + 3;
539 
540  print '<tr><td colspan="'.$colspan.'">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
541  }
542 
543 
544 
545  // List of available values in database
546  dol_syslog("htdocs/admin/dict", LOG_DEBUG);
547  $resql = $db->query($sql);
548  if ($resql) {
549  $num = $db->num_rows($resql);
550  $i = 0;
551 
552  $param = '&id='.urlencode($id);
553  if ($search_country_id > 0) {
554  $param .= '&search_country_id='.urlencode($search_country_id);
555  }
556  $paramwithsearch = $param;
557  if ($sortorder) {
558  $paramwithsearch .= '&sortorder='.urlencode($sortorder);
559  }
560  if ($sortfield) {
561  $paramwithsearch .= '&sortfield='.urlencode($sortfield);
562  }
563 
564  // There is several pages
565  if ($num > $listlimit) {
566  print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).'">';
567  print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
568  print '</td></tr>';
569  }
570 
571  // Title line with search boxes
572  print '<tr class="liste_titre liste_titre_add">';
573  foreach ($fieldlist as $field => $value) {
574  $showfield = 1; // By defaut
575 
576  if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
577  $showfield = 0;
578  }
579 
580  if ($showfield) {
581  if ($value == 'country') {
582  print '<td class="liste_titre">';
583  print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth200 maxwidthonsmartphone');
584  print '</td>';
585  } else {
586  print '<td class="liste_titre"></td>';
587  }
588  }
589  }
590  print '<td class="liste_titre"></td>';
591  print '<td class="liste_titre right" colspan="2">';
592  $searchpicto = $form->showFilterAndCheckAddButtons(0);
593  print $searchpicto;
594  print '</td>';
595  print '</tr>';
596 
597  // Title of lines
598  print '<tr class="liste_titre">';
599  print getTitleFieldOfList($langs->trans("Pcg_version"), 0, $_SERVER["PHP_SELF"], "pcg_version", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
600  print getTitleFieldOfList($langs->trans("Label"), 0, $_SERVER["PHP_SELF"], "label", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
601  print getTitleFieldOfList($langs->trans("Country"), 0, $_SERVER["PHP_SELF"], "country_code", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
602  print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
603  print getTitleFieldOfList('');
604  print getTitleFieldOfList('');
605  print '</tr>';
606 
607  if ($num) {
608  $i = 0;
609  // Lines with values
610  while ($i < $num) {
611  $obj = $db->fetch_object($resql);
612  //print_r($obj);
613 
614  print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
615  if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
616  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
617  print '<input type="hidden" name="token" value="'.newToken().'">';
618  print '<input type="hidden" name="page" value="'.$page.'">';
619  print '<input type="hidden" name="rowid" value="'.$rowid.'">';
620 
621  $tmpaction = 'edit';
622  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
623  $reshook = $hookmanager->executeHooks('editDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
624  $error = $hookmanager->error; $errors = $hookmanager->errors;
625 
626  if (empty($reshook)) {
627  fieldListAccountModel($fieldlist, $obj, $tabname[$id], 'edit');
628  }
629 
630  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").'">';
631  print '&nbsp;<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'"></td>';
632  } else {
633  $tmpaction = 'view';
634  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
635  $reshook = $hookmanager->executeHooks('viewDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
636 
637  $error = $hookmanager->error; $errors = $hookmanager->errors;
638 
639  if (empty($reshook)) {
640  foreach ($fieldlist as $field => $value) {
641  $showfield = 1;
642  $class = "left";
643  $valuetoshow = $obj->{$fieldlist[$field]};
644  if ($value == 'type_template') {
645  $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
646  }
647  if ($value == 'element') {
648  $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
649  } elseif ($value == 'source') {
650  $valuetoshow = isset($sourceList[$valuetoshow]) ? $sourceList[$valuetoshow] : $valuetoshow;
651  } elseif ($valuetoshow == 'all') {
652  $valuetoshow = $langs->trans('All');
653  } elseif ($fieldlist[$field] == 'country') {
654  if (empty($obj->country_code)) {
655  $valuetoshow = '-';
656  } else {
657  $key = $langs->trans("Country".strtoupper($obj->country_code));
658  $valuetoshow = ($key != "Country".strtoupper($obj->country_code) ? $obj->country_code." - ".$key : $obj->country);
659  }
660  } elseif ($fieldlist[$field] == 'country_id') {
661  $showfield = 0;
662  }
663 
664  $class = 'tddict';
665  if ($fieldlist[$field] == 'tracking') {
666  $class .= ' tdoverflowauto';
667  }
668  // Show value for field
669  if ($showfield) {
670  print '<!-- '.$fieldlist[$field].' --><td class="'.$class.'">'.$valuetoshow.'</td>';
671  }
672  }
673  }
674 
675  // Can an entry be erased or disabled ?
676  $iserasable = 1; $canbedisabled = 1; $canbemodified = 1; // true by default
677 
678  $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) : '');
679  if ($param) {
680  $url .= '&'.$param;
681  }
682  $url .= '&';
683 
684  // Active
685  print '<td class="center nowrap">';
686  if ($canbedisabled) {
687  print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
688  } else {
689  print $langs->trans("AlwaysActive");
690  }
691  print "</td>";
692 
693  // Modify link
694  if ($canbemodified) {
695  print '<td class="center"><a class="reposition editfielda" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a></td>';
696  } else {
697  print '<td>&nbsp;</td>';
698  }
699 
700  // Delete link
701  if ($iserasable) {
702  print '<td class="center"><a href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a></td>';
703  } else {
704  print '<td>&nbsp;</td>';
705  }
706 
707  print "</tr>\n";
708  }
709 
710  $i++;
711  }
712  }
713  } else {
714  dol_print_error($db);
715  }
716 
717  print '</table>';
718  print '</div>';
719 
720  print '</form>';
721 }
722 
723 print '<br>';
724 
725 // End of page
726 llxFooter();
727 $db->close();
728 
729 
739 function fieldListAccountModel($fieldlist, $obj = '', $tabname = '', $context = '')
740 {
741  global $conf, $langs, $db;
742  global $form;
743  global $region_id;
744  global $elementList, $sourceList;
745 
746  $formadmin = new FormAdmin($db);
747  $formcompany = new FormCompany($db);
748  $formaccounting = new FormAccounting($db);
749 
750  foreach ($fieldlist as $field => $value) {
751  if ($fieldlist[$field] == 'country') {
752  if (in_array('region_id', $fieldlist)) {
753  print '<td>';
754  //print join(',',$fieldlist);
755  print '</td>';
756  continue;
757  } // For state page, we do not show the country input (we link to region, not country)
758  print '<td>';
759  $fieldname = 'country';
760  print $form->select_country((!empty($obj->country_code) ? $obj->country_code : (!empty($obj->country) ? $obj->country : '')), $fieldname, '', 28, 'maxwidth200 maxwidthonsmartphone');
761  print '</td>';
762  } elseif ($fieldlist[$field] == 'country_id') {
763  if (!in_array('country', $fieldlist)) { // If there is already a field country, we don't show country_id (avoid duplicate)
764  $country_id = (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
765  print '<td>';
766  print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">';
767  print '</td>';
768  }
769  } elseif ($fieldlist[$field] == 'type_cdr') {
770  if ($fieldlist[$field] == 'type_cdr') {
771  print '<td class="center">';
772  } else {
773  print '<td>';
774  }
775  if ($fieldlist[$field] == 'type_cdr') {
776  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]}:''));
777  } else {
778  print $form->selectyesno($fieldlist[$field], (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:''), 1);
779  }
780  print '</td>';
781  } elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
782  print '<td><input type="text" class="flat" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:'').'" size="10" name="'.$fieldlist[$field].'"></td>';
783  } else {
784  print '<td>';
785  $size = ''; $class = '';
786  if ($fieldlist[$field] == 'code') {
787  $size = 'size="8" ';
788  }
789  if ($fieldlist[$field] == 'position') {
790  $size = 'size="4" ';
791  }
792  if ($fieldlist[$field] == 'libelle') {
793  $size = 'centpercent';
794  }
795  if ($fieldlist[$field] == 'sortorder' || $fieldlist[$field] == 'sens' || $fieldlist[$field] == 'category_type') {
796  $size = 'size="2" ';
797  }
798  print '<input type="text" '.$size.' class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
799  print '</td>';
800  }
801  }
802 }
fieldListAccountModel($fieldlist, $obj='', $tabname='', $context='')
Show fields in insert/edit mode.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage generation of HTML components for accounting management.
Class to generate html code for admin pages.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
print_fleche_navigation($page, $file, $options='', $nextpage=0, $betweenarrows='', $afterarrows='', $limit=-1, $totalnboflines=0, $hideselectlimit=0, $beforearrows='')
Function to show navigation arrows into lists.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.