dolibarr  17.0.3
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 $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 print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
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] == 'type') {
473  if ($tabname[$id] == MAIN_DB_PREFIX."c_paiement") {
474  $valuetoshow = $form->textwithtooltip($langs->trans("Type"), $langs->trans("TypePaymentDesc"), 2, 1, img_help(1, ''));
475  } else {
476  $valuetoshow = $langs->trans("Type");
477  }
478  }
479  if ($fieldlist[$field] == 'code') {
480  $valuetoshow = $langs->trans("Code");
481  }
482  if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
483  $valuetoshow = $langs->trans("Label");
484  }
485  if ($fieldlist[$field] == 'libelle_facture') {
486  $valuetoshow = $langs->trans("LabelOnDocuments");
487  }
488  if ($fieldlist[$field] == 'country') {
489  $valuetoshow = $langs->trans("Country");
490  }
491  if ($fieldlist[$field] == 'accountancy_code') {
492  $valuetoshow = $langs->trans("AccountancyCode");
493  }
494  if ($fieldlist[$field] == 'accountancy_code_sell') {
495  $valuetoshow = $langs->trans("AccountancyCodeSell");
496  }
497  if ($fieldlist[$field] == 'accountancy_code_buy') {
498  $valuetoshow = $langs->trans("AccountancyCodeBuy");
499  }
500  if ($fieldlist[$field] == 'pcg_version' || $fieldlist[$field] == 'fk_pcg_version') {
501  $valuetoshow = $langs->trans("Pcg_version");
502  }
503  if ($fieldlist[$field] == 'range_account') {
504  $valuetoshow = $langs->trans("Comment");
505  }
506  if ($fieldlist[$field] == 'category_type') {
507  $valuetoshow = $langs->trans("Calculated");
508  }
509 
510  if ($valuetoshow != '') {
511  print '<td class="'.$class.'">';
512  if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
513  print '<a href="'.$tabhelp[$id][$value].'">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
514  } elseif (!empty($tabhelp[$id][$value])) {
515  print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
516  } else {
517  print $valuetoshow;
518  }
519  print '</td>';
520  }
521  }
522 
523  print '<td>';
524  print '<input type="hidden" name="id" value="'.$id.'">';
525  print '</td>';
526  print '<td style="min-width: 26px;"></td>';
527  print '<td style="min-width: 26px;"></td>';
528  print '<td style="min-width: 26px;"></td>';
529  print '</tr>';
530 
531  // Line to enter new values
532  print '<tr class="oddeven nodrag nodrop nohover">';
533 
534  $obj = new stdClass();
535  // If data was already input, we define them in obj to populate input fields.
536  if (GETPOST('actionadd', 'alpha')) {
537  foreach ($fieldlist as $key => $val) {
538  if (GETPOST($val) != '') {
539  $obj->$val = GETPOST($val);
540  }
541  }
542  }
543 
544  $tmpaction = 'create';
545  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
546  $reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
547  $error = $hookmanager->error; $errors = $hookmanager->errors;
548 
549  if (empty($reshook)) {
550  fieldListAccountingCategories($fieldlist, $obj, $tabname[$id], 'add');
551  }
552 
553  print '<td colspan="4" class="right">';
554  print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'">';
555  print '</td>';
556  print "</tr>";
557 
558  $colspan = count($fieldlist) + 3;
559  if ($id == 32) {
560  $colspan++;
561  }
562 
563  print '<tr><td colspan="'.$colspan.'">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
564 }
565 
566 // List of available record in database
567 dol_syslog("htdocs/accountancy/admin/categories_list.php", LOG_DEBUG);
568 
569 $resql = $db->query($sql);
570 if ($resql) {
571  $num = $db->num_rows($resql);
572  $i = 0;
573 
574  $param = '&id='.$id;
575  if ($search_country_id > 0) {
576  $param .= '&search_country_id='.urlencode($search_country_id);
577  }
578  $paramwithsearch = $param;
579  if ($sortorder) {
580  $paramwithsearch .= '&sortorder='.$sortorder;
581  }
582  if ($sortfield) {
583  $paramwithsearch .= '&sortfield='.$sortfield;
584  }
585  if (GETPOST('from', 'alpha')) {
586  $paramwithsearch .= '&from='.GETPOST('from', 'alpha');
587  }
588  // There is several pages
589  if ($num > $listlimit) {
590  print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).'">';
591  print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
592  print '</td></tr>';
593  }
594 
595  // Title line with search boxes
596  print '<tr class="liste_titre liste_titre_add liste_titre_filter">';
597  $filterfound = 0;
598  foreach ($fieldlist as $field => $value) {
599  $showfield = 1; // By defaut
600 
601  if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
602  $showfield = 0;
603  }
604 
605  if ($showfield) {
606  if ($value == 'country') {
607  print '<td class="liste_titre">';
608  print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth150 maxwidthonsmartphone');
609  print '</td>';
610  $filterfound++;
611  } else {
612  print '<td class="liste_titre"></td>';
613  }
614  }
615  }
616  print '<td class="liste_titre"></td>';
617  print '<td class="liste_titre"></td>';
618  print '<td class="liste_titre"></td>';
619  print '<td class="liste_titre center">';
620  if ($filterfound) {
621  $searchpicto = $form->showFilterAndCheckAddButtons(0);
622  print $searchpicto;
623  }
624  print '</td>';
625  print '</tr>';
626 
627  // Title of lines
628  print '<tr class="liste_titre">';
629  foreach ($fieldlist as $field => $value) {
630  // Determines the name of the field in relation to the possible names
631  // in data dictionaries
632  $showfield = 1; // By default
633  $class = "left";
634  $sortable = 1;
635  $valuetoshow = '';
636 
637  $valuetoshow = ucfirst($fieldlist[$field]); // By default
638  $valuetoshow = $langs->trans($valuetoshow); // try to translate
639  if ($fieldlist[$field] == 'source') {
640  $valuetoshow = $langs->trans("Contact");
641  }
642  if ($fieldlist[$field] == 'price') {
643  $valuetoshow = $langs->trans("PriceUHT");
644  }
645  if ($fieldlist[$field] == 'taux') {
646  if ($tabname[$id] != MAIN_DB_PREFIX."c_revenuestamp") {
647  $valuetoshow = $langs->trans("Rate");
648  } else {
649  $valuetoshow = $langs->trans("Amount");
650  }
651  $class = 'center';
652  }
653  if ($fieldlist[$field] == 'type') {
654  $valuetoshow = $langs->trans("Type");
655  }
656  if ($fieldlist[$field] == 'code') {
657  $valuetoshow = $langs->trans("Code");
658  }
659  if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
660  $valuetoshow = $langs->trans("Label");
661  }
662  if ($fieldlist[$field] == 'country') {
663  $valuetoshow = $langs->trans("Country");
664  }
665  if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
666  $showfield = 0;
667  }
668  if ($fieldlist[$field] == 'accountancy_code') {
669  $valuetoshow = $langs->trans("AccountancyCode");
670  }
671  if ($fieldlist[$field] == 'accountancy_code_sell') {
672  $valuetoshow = $langs->trans("AccountancyCodeSell");
673  $sortable = 0;
674  }
675  if ($fieldlist[$field] == 'accountancy_code_buy') {
676  $valuetoshow = $langs->trans("AccountancyCodeBuy");
677  $sortable = 0;
678  }
679  if ($fieldlist[$field] == 'fk_pcg_version') {
680  $valuetoshow = $langs->trans("Pcg_version");
681  }
682  if ($fieldlist[$field] == 'account_parent') {
683  $valuetoshow = $langs->trans("Accountsparent");
684  }
685  if ($fieldlist[$field] == 'pcg_type') {
686  $valuetoshow = $langs->trans("Pcg_type");
687  }
688  if ($fieldlist[$field] == 'type_template') {
689  $valuetoshow = $langs->trans("TypeOfTemplate");
690  }
691  if ($fieldlist[$field] == 'range_account') {
692  $valuetoshow = $langs->trans("Comment");
693  }
694  if ($fieldlist[$field] == 'category_type') {
695  $valuetoshow = $langs->trans("Calculated");
696  }
697  // Affiche nom du champ
698  if ($showfield) {
699  print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable ? $fieldlist[$field] : ''), ($page ? 'page='.$page.'&' : ''), $param, "", $sortfield, $sortorder, $class.' ');
700  }
701  }
702  print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
703  print getTitleFieldOfList('');
704  print getTitleFieldOfList('');
705  print getTitleFieldOfList('');
706  print '</tr>';
707 
708  if ($num) {
709  // Lines with values
710  while ($i < $num) {
711  $obj = $db->fetch_object($resql);
712  //print_r($obj);
713  print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
714  if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
715  $tmpaction = 'edit';
716  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
717  $reshook = $hookmanager->executeHooks('editDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
718  $error = $hookmanager->error; $errors = $hookmanager->errors;
719 
720  // Show fields
721  if (empty($reshook)) {
722  fieldListAccountingCategories($fieldlist, $obj, $tabname[$id], 'edit');
723  }
724 
725  print '<td></td>';
726  print '<td></td>';
727  print '<td class="center">';
728  print '<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'"></div>';
729  print '<input type="hidden" name="page" value="'.$page.'">';
730  print '<input type="hidden" name="rowid" value="'.$rowid.'">';
731  print '<input type="submit" class="button button-edit smallpaddingimp" name="actionmodify" value="'.$langs->trans("Modify").'">';
732  print '<input type="submit" class="button button-cancel smallpaddingimp" name="actioncancel" value="'.$langs->trans("Cancel").'">';
733  print '</td>';
734  print '<td></td>';
735  } else {
736  $tmpaction = 'view';
737  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
738  $reshook = $hookmanager->executeHooks('viewDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
739 
740  $error = $hookmanager->error; $errors = $hookmanager->errors;
741 
742  if (empty($reshook)) {
743  foreach ($fieldlist as $field => $value) {
744  $showfield = 1;
745  $class = "left";
746  $valuetoshow = $obj->{$fieldlist[$field]};
747  if ($value == 'category_type') {
748  $valuetoshow = yn($valuetoshow);
749  } elseif ($valuetoshow == 'all') {
750  $valuetoshow = $langs->trans('All');
751  } elseif ($fieldlist[$field] == 'country') {
752  if (empty($obj->country_code)) {
753  $valuetoshow = '-';
754  } else {
755  $key = $langs->trans("Country".strtoupper($obj->country_code));
756  $valuetoshow = ($key != "Country".strtoupper($obj->country_code) ? $obj->country_code." - ".$key : $obj->country);
757  }
758  } elseif ($fieldlist[$field] == 'label' && $tabname[$id] == MAIN_DB_PREFIX.'c_country') {
759  $key = $langs->trans("Country".strtoupper($obj->code));
760  $valuetoshow = ($obj->code && $key != "Country".strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
761  } elseif ($fieldlist[$field] == 'label' && $tabname[$id] == MAIN_DB_PREFIX.'c_availability') {
762  $langs->loadLangs(array("propal"));
763  $key = $langs->trans("AvailabilityType".strtoupper($obj->code));
764  $valuetoshow = ($obj->code && $key != "AvailabilityType".strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
765  } elseif ($fieldlist[$field] == 'libelle' && $tabname[$id] == MAIN_DB_PREFIX.'c_actioncomm') {
766  $key = $langs->trans("Action".strtoupper($obj->code));
767  $valuetoshow = ($obj->code && $key != "Action".strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
768  } elseif ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
769  $showfield = 0;
770  }
771 
772  $class = 'tddict';
773  // Show value for field
774  if ($showfield) {
775  print '<!-- '.$fieldlist[$field].' --><td class="'.$class.'">'.dol_escape_htmltag($valuetoshow).'</td>';
776  }
777  }
778  }
779 
780  // Can an entry be erased or disabled ?
781  $iserasable = 1; $canbedisabled = 1; $canbemodified = 1; // true by default
782  if (isset($obj->code)) {
783  if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i', $obj->code))) {
784  $iserasable = 0; $canbedisabled = 0;
785  }
786  }
787 
788  $canbemodified = $iserasable;
789 
790  $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) : '');
791  if ($param) {
792  $url .= '&'.$param;
793  }
794  $url .= '&';
795 
796  // Active
797  print '<td class="center" class="nowrap">';
798  if ($canbedisabled) {
799  print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
800  } else {
801  print $langs->trans("AlwaysActive");
802  }
803  print "</td>";
804 
805  // Modify link
806  if ($canbemodified) {
807  print '<td class="center"><a class="reposition editfielda" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a></td>';
808  } else {
809  print '<td>&nbsp;</td>';
810  }
811 
812  // Delete link
813  if ($iserasable) {
814  print '<td class="center">';
815  if ($user->admin) {
816  print '<a href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a>';
817  }
818  //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
819  print '</td>';
820  } else {
821  print '<td>&nbsp;</td>';
822  }
823 
824  // Link to setup the group
825  print '<td class="center">';
826  if (empty($obj->formula)) {
827  print '<a href="'.DOL_URL_ROOT.'/accountancy/admin/categories.php?action=display&save_lastsearch_values=1&account_category='.$obj->rowid.'">';
828  print $langs->trans("ListOfAccounts");
829  print '</a>';
830 
831  // Count number of accounts into group
832  $nbofaccountintogroup = 0;
833  $listofaccountintogroup = $accountingcategory->getCptsCat($obj->rowid);
834  $nbofaccountintogroup = count($listofaccountintogroup);
835  //if ($nbofaccountintogroup > 0) {
836  print ' <span class="opacitymedium">('.$langs->trans("NAccounts", $nbofaccountintogroup).')</span>';
837  //} else {
838  // print ' <span class="opacitymedium">(0)</span>';
839  //}
840  }
841  print '</td>';
842  }
843  print "</tr>\n";
844  $i++;
845  }
846  }
847 } else {
848  dol_print_error($db);
849 }
850 
851 print '</table>';
852 print '</div>';
853 
854 print '</form>';
855 
856 print '<br>';
857 
858 // End of page
859 llxFooter();
860 $db->close();
861 
862 
872 function fieldListAccountingCategories($fieldlist, $obj = '', $tabname = '', $context = '')
873 {
874  global $conf, $langs, $db;
875  global $form, $mysoc;
876 
877  $formadmin = new FormAdmin($db);
878  $formcompany = new FormCompany($db);
879  if (isModEnabled('accounting')) {
880  $formaccounting = new FormAccounting($db);
881  }
882 
883  foreach ($fieldlist as $field => $value) {
884  if ($fieldlist[$field] == 'country') {
885  print '<td>';
886  $fieldname = 'country';
887  if ($context == 'add') {
888  $fieldname = 'country_id';
889  $preselectcountrycode = GETPOSTISSET('country_id') ? GETPOST('country_id', 'int') : $mysoc->country_code;
890  print $form->select_country($preselectcountrycode, $fieldname, '', 28, 'maxwidth150 maxwidthonsmartphone');
891  } else {
892  $preselectcountrycode = (empty($obj->country_code) ? (empty($obj->country) ? $mysoc->country_code : $obj->country) : $obj->country_code);
893  print $form->select_country($preselectcountrycode, $fieldname, '', 28, 'maxwidth150 maxwidthonsmartphone');
894  }
895  print '</td>';
896  } elseif ($fieldlist[$field] == 'country_id') {
897  if (!in_array('country', $fieldlist)) { // If there is already a field country, we don't show country_id (avoid duplicate)
898  $country_id = (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
899  print '<td>';
900  print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">';
901  print '</td>';
902  }
903  } elseif ($fieldlist[$field] == 'category_type') {
904  print '<td>';
905  print $form->selectyesno($fieldlist[$field], (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:''), 1);
906  print '</td>';
907  } elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
908  print '<td><input type="text" class="flat minwidth100" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'"></td>';
909  } else {
910  print '<td>';
911  $size = ''; $class = '';
912  if ($fieldlist[$field] == 'code') {
913  $class = 'maxwidth100';
914  }
915  if ($fieldlist[$field] == 'position') {
916  $class = 'maxwidth50';
917  }
918  if ($fieldlist[$field] == 'libelle') {
919  $class = 'quatrevingtpercent';
920  }
921  if ($fieldlist[$field] == 'sortorder' || $fieldlist[$field] == 'category_type') {
922  $size = 'size="2" ';
923  }
924  print '<input type="text" '.$size.'class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
925  print '</td>';
926  }
927  }
928 }
yn
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Definition: functions.lib.php:6677
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1493
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
getTitleFieldOfList
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
Definition: functions.lib.php:5201
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5360
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:520
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:4993
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:1297
img_help
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
Definition: functions.lib.php:4630
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:4538
FormAccounting
Class to manage generation of HTML components for accounting management.
Definition: html.formaccounting.class.php:33
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:4024
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:4578
$resql
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
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1628
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11290
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
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:421
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
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:5559
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8465
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:1120
fieldListAccountingCategories
fieldListAccountingCategories($fieldlist, $obj='', $tabname='', $context='')
Show fields in insert/edit mode.
Definition: categories_list.php:872