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