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