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