dolibarr  18.0.0
categories_list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2011-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 // Load Dolibarr environment
26 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancycategory.class.php';
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array("errors", "admin", "companies", "resource", "holiday", "accountancy", "hrm"));
38 
39 $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view';
40 $confirm = GETPOST('confirm', 'alpha');
41 $id = 32;
42 $rowid = GETPOST('rowid', 'alpha');
43 $code = GETPOST('code', 'alpha');
44 
45 // Security access
46 if (!$user->hasRight('accounting', 'chartofaccount')) {
48 }
49 
50 $acts[0] = "activate";
51 $acts[1] = "disable";
52 $actl[0] = img_picto($langs->trans("Disabled"), 'switch_off', 'class="size15x"');
53 $actl[1] = img_picto($langs->trans("Activated"), 'switch_on', 'class="size15x"');
54 
55 $listoffset = GETPOST('listoffset', 'alpha');
56 $listlimit = GETPOST('listlimit', 'int') > 0 ?GETPOST('listlimit', 'int') : 1000;
57 
58 $sortfield = GETPOST("sortfield", 'aZ09comma');
59 $sortorder = GETPOST("sortorder", 'aZ09comma');
60 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
61 if (empty($page) || $page == -1) {
62  $page = 0;
63 } // If $page is not defined, or '' or -1
64 $offset = $listlimit * $page;
65 $pageprev = $page - 1;
66 $pagenext = $page + 1;
67 
68 $search_country_id = GETPOST('search_country_id', 'int');
69 
70 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
71 $hookmanager->initHooks(array('admin'));
72 
73 // This page is a generic page to edit dictionaries
74 // Put here declaration of dictionaries properties
75 
76 // Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this.
77 $taborder = array(32);
78 
79 // Name of SQL tables of dictionaries
80 $tabname = array();
81 $tabname[32] = MAIN_DB_PREFIX."c_accounting_category";
82 
83 // Dictionary labels
84 $tablib = array();
85 $tablib[32] = "DictionaryAccountancyCategory";
86 
87 // Requests to extract data
88 $tabsql = array();
89 $tabsql[32] = "SELECT a.rowid as rowid, a.code as code, a.label, a.range_account, a.category_type, a.formula, a.position as position, a.fk_country as country_id, c.code as country_code, c.label as country, a.active FROM ".MAIN_DB_PREFIX."c_accounting_category as a, ".MAIN_DB_PREFIX."c_country as c WHERE a.fk_country=c.rowid and c.active=1";
90 
91 // Criteria to sort dictionaries
92 $tabsqlsort = array();
93 $tabsqlsort[32] = "position ASC";
94 
95 // Name of the fields in the result of select to display the dictionary
96 $tabfield = array();
97 $tabfield[32] = "code,label,range_account,category_type,formula,position,country";
98 
99 // Name of editing fields for record modification
100 $tabfieldvalue = array();
101 $tabfieldvalue[32] = "code,label,range_account,category_type,formula,position,country_id";
102 
103 // Name of the fields in the table for inserting a record
104 $tabfieldinsert = array();
105 $tabfieldinsert[32] = "code,label,range_account,category_type,formula,position,fk_country";
106 
107 // Name of the rowid if the field is not of type autoincrement
108 // Example: "" if id field is "rowid" and has autoincrement on
109 // "nameoffield" if id field is not "rowid" or has not autoincrement on
110 $tabrowid = array();
111 $tabrowid[32] = "";
112 
113 // Condition to show dictionary in setup page
114 $tabcond = array();
115 $tabcond[32] = isModEnabled('accounting');
116 
117 // List of help for fields
118 $tabhelp = array();
119 $tabhelp[32] = array('code'=>$langs->trans("EnterAnyCode"), 'category_type'=>$langs->trans("SetToYesIfGroupIsComputationOfOtherGroups"), 'formula'=>$langs->trans("EnterCalculationRuleIfPreviousFieldIsYes"));
120 
121 // List of check for fields (NOT USED YET)
122 $tabfieldcheck = array();
123 $tabfieldcheck[32] = array();
124 
125 // Complete all arrays with entries found into modules
126 complete_dictionary_with_modules($taborder, $tabname, $tablib, $tabsql, $tabsqlsort, $tabfield, $tabfieldvalue, $tabfieldinsert, $tabrowid, $tabcond, $tabhelp, $tabfieldcheck);
127 
128 $accountingcategory = new AccountancyCategory($db);
129 
130 
131 /*
132  * Actions
133  */
134 
135 if (GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter_x', 'alpha')) {
136  $search_country_id = '';
137 }
138 
139 // Actions add or modify an entry into a dictionary
140 if (GETPOST('actionadd', 'alpha') || GETPOST('actionmodify', 'alpha')) {
141  $listfield = explode(',', str_replace(' ', '', $tabfield[$id]));
142  $listfieldinsert = explode(',', $tabfieldinsert[$id]);
143  $listfieldmodify = explode(',', $tabfieldinsert[$id]);
144  $listfieldvalue = explode(',', $tabfieldvalue[$id]);
145 
146  // Check that all fields are filled
147  $ok = 1;
148  foreach ($listfield as $f => $value) {
149  if ($value == 'formula' && !GETPOST('formula')) {
150  continue;
151  }
152  if ($value == 'range_account' && !GETPOST('range_account')) {
153  continue;
154  }
155  if (($value == 'country' || $value == 'country_id') && GETPOST('country_id')) {
156  continue;
157  }
158  if (!GETPOSTISSET($value) || GETPOST($value) == '') {
159  $ok = 0;
160  $fieldnamekey = $listfield[$f];
161  // We take translate key of field
162  if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) {
163  $fieldnamekey = 'Label';
164  }
165  if ($fieldnamekey == 'code') {
166  $fieldnamekey = 'Code';
167  }
168  if ($fieldnamekey == 'note') {
169  $fieldnamekey = 'Note';
170  }
171  if ($fieldnamekey == 'type') {
172  $fieldnamekey = 'Type';
173  }
174  if ($fieldnamekey == 'position') {
175  $fieldnamekey = 'Position';
176  }
177  if ($fieldnamekey == 'category_type') {
178  $fieldnamekey = 'Calculated';
179  }
180  if ($fieldnamekey == 'country') {
181  $fieldnamekey = 'Country';
182  }
183 
184  setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
185  }
186  }
187  if (GETPOSTISSET("code")) {
188  if (GETPOST("code") == '0') {
189  $ok = 0;
190  setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
191  }
192  }
193  if (GETPOST('position') && !is_numeric(GETPOST('position', 'alpha'))) {
194  $langs->loadLangs(array("errors"));
195  $ok = 0;
196  setEventMessages($langs->transnoentities('ErrorFieldMustBeANumeric', $langs->transnoentities("Position")), null, 'errors');
197  }
198 
199  // Si verif ok et action add, on ajoute la ligne
200  if ($ok && GETPOST('actionadd', 'alpha')) {
201  if ($tabrowid[$id]) {
202  // Recupere id libre pour insertion
203  $newid = 0;
204  $sql = "SELECT max(".$tabrowid[$id].") newid from ".$tabname[$id];
205  $result = $db->query($sql);
206  if ($result) {
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  }
220  $sql .= $tabfieldinsert[$id];
221  $sql .= ",active)";
222  $sql .= " VALUES(";
223 
224  // List of values
225  if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
226  $sql .= $newid.",";
227  }
228  $i = 0;
229  foreach ($listfieldinsert as $f => $value) {
230  if ($value == 'entity') {
231  $_POST[$listfieldvalue[$i]] = $conf->entity;
232  }
233  if ($i) {
234  $sql .= ",";
235  }
236  if (GETPOST($listfieldvalue[$i]) == '' && !$listfieldvalue[$i] == 'formula') {
237  $sql .= "null"; // For vat, we want/accept code = ''
238  } else {
239  $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
240  }
241  $i++;
242  }
243  $sql .= ",1)";
244 
245  dol_syslog("actionadd", LOG_DEBUG);
246  $result = $db->query($sql);
247  if ($result) { // Add is ok
248  setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
249  $_POST = array('id'=>$id); // Clean $_POST array, we keep only
250  } else {
251  if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
252  setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
253  } else {
254  dol_print_error($db);
255  }
256  }
257  }
258 
259  // If check ok and action modify, we modify the line
260  if ($ok && GETPOST('actionmodify', 'alpha')) {
261  if ($tabrowid[$id]) {
262  $rowidcol = $tabrowid[$id];
263  } else {
264  $rowidcol = "rowid";
265  }
266 
267  // Modify entry
268  $sql = "UPDATE ".$tabname[$id]." SET ";
269  // Modifie valeur des champs
270  if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
271  $sql .= $tabrowid[$id]."=";
272  $sql .= "'".$db->escape($rowid)."', ";
273  }
274  $i = 0;
275  foreach ($listfieldmodify as $field) {
276  if ($field == 'fk_country' && GETPOST('country') > 0) {
277  $_POST[$listfieldvalue[$i]] = GETPOST('country');
278  } elseif ($field == 'entity') {
279  $_POST[$listfieldvalue[$i]] = $conf->entity;
280  }
281  if ($i) {
282  $sql .= ",";
283  }
284  $sql .= $field."=";
285  if (GETPOST($listfieldvalue[$i]) == '' && !$listfieldvalue[$i] == 'range_account') {
286  $sql .= "null"; // For range_account, we want/accept code = ''
287  } else {
288  $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
289  }
290  $i++;
291  }
292  $sql .= " WHERE ".$rowidcol." = ".((int) $rowid);
293 
294  dol_syslog("actionmodify", LOG_DEBUG);
295  //print $sql;
296  $resql = $db->query($sql);
297  if (!$resql) {
298  setEventMessages($db->error(), null, 'errors');
299  }
300  }
301  //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
302 }
303 
304 if (GETPOST('actioncancel', 'alpha')) {
305  //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
306 }
307 
308 if ($action == 'confirm_delete' && $confirm == 'yes') { // delete
309  if ($tabrowid[$id]) {
310  $rowidcol = $tabrowid[$id];
311  } else {
312  $rowidcol = "rowid";
313  }
314 
315  $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol." = ".((int) $rowid);
316 
317  dol_syslog("delete", LOG_DEBUG);
318  $result = $db->query($sql);
319  if (!$result) {
320  if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
321  setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
322  } else {
323  dol_print_error($db);
324  }
325  }
326 }
327 
328 // activate
329 if ($action == $acts[0]) {
330  if ($tabrowid[$id]) {
331  $rowidcol = $tabrowid[$id];
332  } else {
333  $rowidcol = "rowid";
334  }
335 
336  if ($rowid) {
337  $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol." = ".((int) $rowid);
338  } elseif ($code) {
339  $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code = '".$db->escape($code)."'";
340  }
341 
342  $result = $db->query($sql);
343  if (!$result) {
344  dol_print_error($db);
345  }
346 }
347 
348 // disable
349 if ($action == $acts[1]) {
350  if ($tabrowid[$id]) {
351  $rowidcol = $tabrowid[$id];
352  } else {
353  $rowidcol = "rowid";
354  }
355 
356  if ($rowid) {
357  $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol." = ".((int) $rowid);
358  } elseif ($code) {
359  $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code = '".$db->escape($code)."'";
360  }
361 
362  $result = $db->query($sql);
363  if (!$result) {
364  dol_print_error($db);
365  }
366 }
367 
368 // favorite
369 if ($action == 'activate_favorite') {
370  if ($tabrowid[$id]) {
371  $rowidcol = $tabrowid[$id];
372  } else {
373  $rowidcol = "rowid";
374  }
375 
376  if ($rowid) {
377  $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol." = ".((int) $rowid);
378  } elseif ($code) {
379  $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code = '".$db->escape($code)."'";
380  }
381 
382  $result = $db->query($sql);
383  if (!$result) {
384  dol_print_error($db);
385  }
386 }
387 
388 // disable favorite
389 if ($action == 'disable_favorite') {
390  if ($tabrowid[$id]) {
391  $rowidcol = $tabrowid[$id];
392  } else {
393  $rowidcol = "rowid";
394  }
395 
396  if ($rowid) {
397  $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol." = ".((int) $rowid);
398  } elseif ($code) {
399  $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code = '".$db->escape($code)."'";
400  }
401 
402  $result = $db->query($sql);
403  if (!$result) {
404  dol_print_error($db);
405  }
406 }
407 
408 
409 /*
410  * View
411  */
412 
413 $form = new Form($db);
414 $formadmin = new FormAdmin($db);
415 
416 llxHeader('', $langs->trans('DictionaryAccountancyCategory'));
417 
418 $titre = $langs->trans($tablib[$id]);
419 $linkback = '';
420 $titlepicto = 'setup';
421 
422 print load_fiche_titre($titre, $linkback, $titlepicto);
423 
424 print '<span class="opacitymedium">'.$langs->trans("AccountingAccountGroupsDesc", $langs->transnoentitiesnoconv("ByPersonalizedAccountGroups")).'</span><br><br>';
425 
426 // Confirmation of the deletion of the line
427 if ($action == 'delete') {
428  print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$code.'&id='.$id.($search_country_id > 0 ? '&search_country_id='.$search_country_id : ''), $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1);
429 }
430 
431 // Complete search query with sorting criteria
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 .= " (a.fk_country = ".((int) $search_country_id)." OR a.fk_country = 0)";
441 }
442 
443 // If sort order is "country", we use country_code instead
444 if ($sortfield == 'country') {
445  $sortfield = 'country_code';
446 }
447 if (empty($sortfield)) {
448  $sortfield = 'position';
449 }
450 
451 $sql .= $db->order($sortfield, $sortorder);
452 $sql .= $db->plimit($listlimit + 1, $offset);
453 //print $sql;
454 
455 $fieldlist = explode(',', $tabfield[$id]);
456 
457 $param = '&id='.$id;
458 if ($search_country_id > 0) {
459  $param .= '&search_country_id='.urlencode($search_country_id);
460 }
461 $paramwithsearch = $param;
462 if ($sortorder) {
463  $paramwithsearch .= '&sortorder='.urlencode($sortorder);
464 }
465 if ($sortfield) {
466  $paramwithsearch .= '&sortfield='.urlencode($sortfield);
467 }
468 if (GETPOST('from', 'alpha')) {
469  $paramwithsearch .= '&from='.urlencode(GETPOST('from', 'alpha'));
470 }
471 
472 print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
473 print '<input type="hidden" name="token" value="'.newToken().'">';
474 print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
475 print '<input type="hidden" name="sortfield" value="'.dol_escape_htmltag($sortfield).'">';
476 print '<input type="hidden" name="sortorder" value="'.dol_escape_htmltag($sortorder).'">';
477 
478 
479 print '<div class="div-table-responsive">';
480 print '<table class="noborder centpercent">';
481 
482 // Form to add a new line
483 if ($tabname[$id]) {
484  $fieldlist = explode(',', $tabfield[$id]);
485 
486  // Line for title
487  print '<tr class="liste_titre">';
488  foreach ($fieldlist as $field => $value) {
489  // Determine le nom du champ par rapport aux noms possibles
490  // dans les dictionnaires de donnees
491  $valuetoshow = ucfirst($fieldlist[$field]); // Par defaut
492  $valuetoshow = $langs->trans($valuetoshow); // try to translate
493  $class = "left";
494  if ($fieldlist[$field] == 'type') {
495  if ($tabname[$id] == MAIN_DB_PREFIX."c_paiement") {
496  $valuetoshow = $form->textwithtooltip($langs->trans("Type"), $langs->trans("TypePaymentDesc"), 2, 1, img_help(1, ''));
497  } else {
498  $valuetoshow = $langs->trans("Type");
499  }
500  }
501  if ($fieldlist[$field] == 'code') {
502  $valuetoshow = $langs->trans("Code");
503  }
504  if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
505  $valuetoshow = $langs->trans("Label");
506  }
507  if ($fieldlist[$field] == 'libelle_facture') {
508  $valuetoshow = $langs->trans("LabelOnDocuments");
509  }
510  if ($fieldlist[$field] == 'country') {
511  $valuetoshow = $langs->trans("Country");
512  }
513  if ($fieldlist[$field] == 'accountancy_code') {
514  $valuetoshow = $langs->trans("AccountancyCode");
515  }
516  if ($fieldlist[$field] == 'accountancy_code_sell') {
517  $valuetoshow = $langs->trans("AccountancyCodeSell");
518  }
519  if ($fieldlist[$field] == 'accountancy_code_buy') {
520  $valuetoshow = $langs->trans("AccountancyCodeBuy");
521  }
522  if ($fieldlist[$field] == 'pcg_version' || $fieldlist[$field] == 'fk_pcg_version') {
523  $valuetoshow = $langs->trans("Pcg_version");
524  }
525  if ($fieldlist[$field] == 'range_account') {
526  $valuetoshow = $langs->trans("Comment");
527  }
528  if ($fieldlist[$field] == 'category_type') {
529  $valuetoshow = $langs->trans("Calculated");
530  }
531 
532  if ($valuetoshow != '') {
533  print '<td class="'.$class.'">';
534  if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
535  print '<a href="'.$tabhelp[$id][$value].'">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
536  } elseif (!empty($tabhelp[$id][$value])) {
537  print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
538  } else {
539  print $valuetoshow;
540  }
541  print '</td>';
542  }
543  }
544 
545  print '<td>';
546  print '<input type="hidden" name="id" value="'.$id.'">';
547  print '</td>';
548  print '<td></td>';
549  print '<td></td>';
550  print '<td></td>';
551  print '</tr>';
552 
553  // Line to enter new values
554  print '<tr class="oddeven nodrag nodrop nohover">';
555 
556  $obj = new stdClass();
557  // If data was already input, we define them in obj to populate input fields.
558  if (GETPOST('actionadd', 'alpha')) {
559  foreach ($fieldlist as $key => $val) {
560  if (GETPOST($val) != '') {
561  $obj->$val = GETPOST($val);
562  }
563  }
564  }
565 
566  $tmpaction = 'create';
567  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
568  $reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
569  $error = $hookmanager->error; $errors = $hookmanager->errors;
570 
571  if (empty($reshook)) {
572  fieldListAccountingCategories($fieldlist, $obj, $tabname[$id], 'add');
573  }
574 
575  print '<td colspan="4" class="right">';
576  print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'">';
577  print '</td>';
578  print "</tr>";
579 
580  $colspan = count($fieldlist) + 3;
581  if ($id == 32) {
582  $colspan++;
583  }
584 
585  print '<tr><td colspan="'.$colspan.'">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
586 }
587 
588 // List of available record in database
589 dol_syslog("htdocs/accountancy/admin/categories_list.php", LOG_DEBUG);
590 
591 $resql = $db->query($sql);
592 if ($resql) {
593  $num = $db->num_rows($resql);
594  $i = 0;
595 
596  // There is several pages
597  if ($num > $listlimit) {
598  print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).'">';
599  print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
600  print '</td></tr>';
601  }
602 
603  // Title line with search boxes
604  print '<tr class="liste_titre liste_titre_add liste_titre_filter">';
605  $filterfound = 0;
606  foreach ($fieldlist as $field => $value) {
607  $showfield = 1; // By defaut
608 
609  if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
610  $showfield = 0;
611  }
612 
613  if ($showfield) {
614  if ($value == 'country') {
615  print '<td class="liste_titre">';
616  print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth150 maxwidthonsmartphone');
617  print '</td>';
618  $filterfound++;
619  } else {
620  print '<td class="liste_titre"></td>';
621  }
622  }
623  }
624  print '<td class="liste_titre"></td>';
625  print '<td class="liste_titre"></td>';
626  print '<td class="liste_titre"></td>';
627  print '<td class="liste_titre center">';
628  if ($filterfound) {
629  $searchpicto = $form->showFilterAndCheckAddButtons(0);
630  print $searchpicto;
631  }
632  print '</td>';
633  print '</tr>';
634 
635  // Title of lines
636  print '<tr class="liste_titre">';
637  foreach ($fieldlist as $field => $value) {
638  // Determines the name of the field in relation to the possible names
639  // in data dictionaries
640  $showfield = 1; // By default
641  $class = "left";
642  $sortable = 1;
643  $valuetoshow = '';
644 
645  $valuetoshow = ucfirst($fieldlist[$field]); // By default
646  $valuetoshow = $langs->trans($valuetoshow); // try to translate
647  if ($fieldlist[$field] == 'source') {
648  $valuetoshow = $langs->trans("Contact");
649  }
650  if ($fieldlist[$field] == 'price') {
651  $valuetoshow = $langs->trans("PriceUHT");
652  }
653  if ($fieldlist[$field] == 'taux') {
654  if ($tabname[$id] != MAIN_DB_PREFIX."c_revenuestamp") {
655  $valuetoshow = $langs->trans("Rate");
656  } else {
657  $valuetoshow = $langs->trans("Amount");
658  }
659  $class = 'center';
660  }
661  if ($fieldlist[$field] == 'type') {
662  $valuetoshow = $langs->trans("Type");
663  }
664  if ($fieldlist[$field] == 'code') {
665  $valuetoshow = $langs->trans("Code");
666  }
667  if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
668  $valuetoshow = $langs->trans("Label");
669  }
670  if ($fieldlist[$field] == 'country') {
671  $valuetoshow = $langs->trans("Country");
672  }
673  if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
674  $showfield = 0;
675  }
676  if ($fieldlist[$field] == 'accountancy_code') {
677  $valuetoshow = $langs->trans("AccountancyCode");
678  }
679  if ($fieldlist[$field] == 'accountancy_code_sell') {
680  $valuetoshow = $langs->trans("AccountancyCodeSell");
681  $sortable = 0;
682  }
683  if ($fieldlist[$field] == 'accountancy_code_buy') {
684  $valuetoshow = $langs->trans("AccountancyCodeBuy");
685  $sortable = 0;
686  }
687  if ($fieldlist[$field] == 'fk_pcg_version') {
688  $valuetoshow = $langs->trans("Pcg_version");
689  }
690  if ($fieldlist[$field] == 'account_parent') {
691  $valuetoshow = $langs->trans("Accountsparent");
692  }
693  if ($fieldlist[$field] == 'pcg_type') {
694  $valuetoshow = $langs->trans("Pcg_type");
695  }
696  if ($fieldlist[$field] == 'type_template') {
697  $valuetoshow = $langs->trans("TypeOfTemplate");
698  }
699  if ($fieldlist[$field] == 'range_account') {
700  $valuetoshow = $langs->trans("Comment");
701  }
702  if ($fieldlist[$field] == 'category_type') {
703  $valuetoshow = $langs->trans("Calculated");
704  }
705  // Affiche nom du champ
706  if ($showfield) {
707  print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable ? $fieldlist[$field] : ''), ($page ? 'page='.$page.'&' : ''), $param, "", $sortfield, $sortorder, $class.' ');
708  }
709  }
710  print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
711  print getTitleFieldOfList('');
712  print getTitleFieldOfList('');
713  print getTitleFieldOfList('');
714  print '</tr>';
715 
716  if ($num) {
717  // Lines with values
718  while ($i < $num) {
719  $obj = $db->fetch_object($resql);
720  //print_r($obj);
721  print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
722  if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
723  $tmpaction = 'edit';
724  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
725  $reshook = $hookmanager->executeHooks('editDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
726  $error = $hookmanager->error; $errors = $hookmanager->errors;
727 
728  // Show fields
729  if (empty($reshook)) {
730  fieldListAccountingCategories($fieldlist, $obj, $tabname[$id], 'edit');
731  }
732 
733  print '<td></td>';
734  print '<td></td>';
735  print '<td class="center">';
736  print '<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'"></div>';
737  print '<input type="hidden" name="page" value="'.$page.'">';
738  print '<input type="hidden" name="rowid" value="'.$rowid.'">';
739  print '<input type="submit" class="button button-edit smallpaddingimp" name="actionmodify" value="'.$langs->trans("Modify").'">';
740  print '<input type="submit" class="button button-cancel smallpaddingimp" name="actioncancel" value="'.$langs->trans("Cancel").'">';
741  print '</td>';
742  print '<td></td>';
743  } else {
744  $tmpaction = 'view';
745  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
746  $reshook = $hookmanager->executeHooks('viewDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
747 
748  $error = $hookmanager->error; $errors = $hookmanager->errors;
749 
750  if (empty($reshook)) {
751  foreach ($fieldlist as $field => $value) {
752  $showfield = 1;
753  $class = "left";
754  $tmpvar = $fieldlist[$field];
755  $valuetoshow = $obj->$tmpvar;
756  if ($value == 'category_type') {
757  $valuetoshow = yn($valuetoshow);
758  } elseif ($valuetoshow == 'all') {
759  $valuetoshow = $langs->trans('All');
760  } elseif ($fieldlist[$field] == 'country') {
761  if (empty($obj->country_code)) {
762  $valuetoshow = '-';
763  } else {
764  $key = $langs->trans("Country".strtoupper($obj->country_code));
765  $valuetoshow = ($key != "Country".strtoupper($obj->country_code) ? $obj->country_code." - ".$key : $obj->country);
766  }
767  } elseif ($fieldlist[$field] == 'label' && $tabname[$id] == MAIN_DB_PREFIX.'c_country') {
768  $key = $langs->trans("Country".strtoupper($obj->code));
769  $valuetoshow = ($obj->code && $key != "Country".strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
770  } elseif ($fieldlist[$field] == 'label' && $tabname[$id] == MAIN_DB_PREFIX.'c_availability') {
771  $langs->loadLangs(array("propal"));
772  $key = $langs->trans("AvailabilityType".strtoupper($obj->code));
773  $valuetoshow = ($obj->code && $key != "AvailabilityType".strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
774  } elseif ($fieldlist[$field] == 'libelle' && $tabname[$id] == MAIN_DB_PREFIX.'c_actioncomm') {
775  $key = $langs->trans("Action".strtoupper($obj->code));
776  $valuetoshow = ($obj->code && $key != "Action".strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
777  } elseif ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
778  $showfield = 0;
779  }
780 
781  $class = 'tddict';
782  // Show value for field
783  if ($showfield) {
784  print '<!-- '.$fieldlist[$field].' --><td class="'.$class.'">'.dol_escape_htmltag($valuetoshow).'</td>';
785  }
786  }
787  }
788 
789  // Can an entry be erased or disabled ?
790  $iserasable = 1; $canbedisabled = 1; $canbemodified = 1; // true by default
791  if (isset($obj->code)) {
792  if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i', $obj->code))) {
793  $iserasable = 0; $canbedisabled = 0;
794  }
795  }
796 
797  $canbemodified = $iserasable;
798 
799  $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) : '');
800  if ($param) {
801  $url .= '&'.$param;
802  }
803  $url .= '&';
804 
805  // Active
806  print '<td class="center" class="nowrap">';
807  if ($canbedisabled) {
808  print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
809  } else {
810  print $langs->trans("AlwaysActive");
811  }
812  print "</td>";
813 
814  // Modify link
815  if ($canbemodified) {
816  print '<td class="center"><a class="reposition editfielda" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a></td>';
817  } else {
818  print '<td>&nbsp;</td>';
819  }
820 
821  // Delete link
822  if ($iserasable) {
823  print '<td class="center">';
824  if ($user->admin) {
825  print '<a href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a>';
826  }
827  //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
828  print '</td>';
829  } else {
830  print '<td>&nbsp;</td>';
831  }
832 
833  // Link to setup the group
834  print '<td>';
835  if (empty($obj->formula)) {
836  print '<a href="'.DOL_URL_ROOT.'/accountancy/admin/categories.php?action=display&save_lastsearch_values=1&account_category='.$obj->rowid.'">';
837  print $langs->trans("ListOfAccounts");
838  print '</a>';
839 
840  // Count number of accounts into group
841  $nbofaccountintogroup = 0;
842  $listofaccountintogroup = $accountingcategory->getCptsCat($obj->rowid);
843  $nbofaccountintogroup = count($listofaccountintogroup);
844  //if ($nbofaccountintogroup > 0) {
845  print ' <span class="opacitymedium">('.$langs->trans("NAccounts", $nbofaccountintogroup).')</span>';
846  //} else {
847  // print ' <span class="opacitymedium">(0)</span>';
848  //}
849  }
850  print '</td>';
851  }
852  print "</tr>\n";
853  $i++;
854  }
855  }
856 } else {
857  dol_print_error($db);
858 }
859 
860 print '</table>';
861 print '</div>';
862 
863 print '</form>';
864 
865 print '<br>';
866 
867 // End of page
868 llxFooter();
869 $db->close();
870 
871 
881 function fieldListAccountingCategories($fieldlist, $obj = '', $tabname = '', $context = '')
882 {
883  global $conf, $langs, $db;
884  global $form, $mysoc;
885 
886  $formadmin = new FormAdmin($db);
887  $formcompany = new FormCompany($db);
888  if (isModEnabled('accounting')) {
889  $formaccounting = new FormAccounting($db);
890  }
891 
892  foreach ($fieldlist as $field => $value) {
893  if ($fieldlist[$field] == 'country') {
894  print '<td>';
895  $fieldname = 'country';
896  if ($context == 'add') {
897  $fieldname = 'country_id';
898  $preselectcountrycode = GETPOSTISSET('country_id') ? GETPOST('country_id', 'int') : $mysoc->country_code;
899  print $form->select_country($preselectcountrycode, $fieldname, '', 28, 'maxwidth150 maxwidthonsmartphone');
900  } else {
901  $preselectcountrycode = (empty($obj->country_code) ? (empty($obj->country) ? $mysoc->country_code : $obj->country) : $obj->country_code);
902  print $form->select_country($preselectcountrycode, $fieldname, '', 28, 'maxwidth150 maxwidthonsmartphone');
903  }
904  print '</td>';
905  } elseif ($fieldlist[$field] == 'country_id') {
906  if (!in_array('country', $fieldlist)) { // If there is already a field country, we don't show country_id (avoid duplicate)
907  $country_id = (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
908  print '<td>';
909  print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">';
910  print '</td>';
911  }
912  } elseif ($fieldlist[$field] == 'category_type') {
913  print '<td>';
914  print $form->selectyesno($fieldlist[$field], (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:''), 1);
915  print '</td>';
916  } elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
917  print '<td><input type="text" class="flat minwidth100" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'"></td>';
918  } else {
919  print '<td>';
920  $size = ''; $class = '';
921  if ($fieldlist[$field] == 'code') {
922  $class = 'maxwidth100';
923  }
924  if ($fieldlist[$field] == 'position') {
925  $class = 'maxwidth50';
926  }
927  if ($fieldlist[$field] == 'libelle') {
928  $class = 'quatrevingtpercent';
929  }
930  if ($fieldlist[$field] == 'sortorder' || $fieldlist[$field] == 'category_type') {
931  $size = 'size="2" ';
932  }
933  print '<input type="text" '.$size.'class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
934  print '</td>';
935  }
936  }
937 }
yn
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Definition: functions.lib.php:6824
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
Definition: functions.lib.php:1600
getTitleFieldOfList
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
Definition: functions.lib.php:5318
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5477
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:609
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:5107
complete_dictionary_with_modules
complete_dictionary_with_modules(&$taborder, &$tabname, &$tablib, &$tabsql, &$tabsqlsort, &$tabfield, &$tabfieldvalue, &$tabfieldinsert, &$tabrowid, &$tabcond, &$tabhelp, &$tabcomplete)
Add external modules to list of dictionaries.
Definition: admin.lib.php:1324
img_help
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
Definition: functions.lib.php:4744
AccountancyCategory
Class to manage categories of an accounting account.
Definition: accountancycategory.class.php:32
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
FormAdmin
Class to generate html code for admin pages.
Definition: html.formadmin.class.php:30
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4652
FormAccounting
Class to manage generation of HTML components for accounting management.
Definition: html.formaccounting.class.php:33
print_fleche_navigation
print_fleche_navigation($page, $file, $options='', $nextpage=0, $betweenarrows='', $afterarrows='', $limit=-1, $totalnboflines=0, $hideselectlimit=0, $beforearrows='', $hidenavigation=0)
Function to show navigation arrows into lists.
Definition: functions.lib.php:5688
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4135
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
img_delete
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
Definition: functions.lib.php:4692
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1741
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
Definition: functions.lib.php:8673
$sql
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11654
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:207
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:509
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
Definition: security.lib.php:1164
fieldListAccountingCategories
fieldListAccountingCategories($fieldlist, $obj='', $tabname='', $context='')
Show fields in insert/edit mode.
Definition: categories_list.php:881