dolibarr  7.0.0-beta
accountmodel.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
6  * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
7  * Copyright (C) 2011-2015 Philippe Grand <philippe.grand@atoo-net.com>
8  * Copyright (C) 2011 Remy Younes <ryounes@gmail.com>
9  * Copyright (C) 2012-2015 Marcos García <marcosgdf@gmail.com>
10  * Copyright (C) 2012 Christophe Battarel <christophe.battarel@ltairis.fr>
11  * Copyright (C) 2011-2016 Alexandre Spangaro <aspangaro@zendsi.com>
12  * Copyright (C) 2015 Ferran Marcet <fmarcet@2byte.es>
13  * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
14  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program. If not, see <http://www.gnu.org/licenses/>.
27  */
28 
35 require '../../main.inc.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
42 if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
43 
44 $langs->loadLangs(array("errors","admin","companies","resource","holiday","compta","accountancy","hrm"));
45 
46 $action=GETPOST('action','alpha')?GETPOST('action','alpha'):'view';
47 $confirm=GETPOST('confirm','alpha');
48 $id=GETPOST('id','int');
49 $rowid=GETPOST('rowid','alpha');
50 $code=GETPOST('code','alpha');
51 
52 $acts[0] = "activate";
53 $acts[1] = "disable";
54 $actl[0] = img_picto($langs->trans("Disabled"),'switch_off');
55 $actl[1] = img_picto($langs->trans("Activated"),'switch_on');
56 
57 $listoffset=GETPOST('listoffset');
58 $listlimit=GETPOST('listlimit')>0?GETPOST('listlimit'):1000;
59 $active = 1;
60 
61 $sortfield = GETPOST("sortfield",'alpha');
62 $sortorder = GETPOST("sortorder",'alpha');
63 $page = GETPOST("page",'int');
64 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
65 $offset = $listlimit * $page ;
66 $pageprev = $page - 1;
67 $pagenext = $page + 1;
68 
69 $search_country_id = GETPOST('search_country_id','int');
70 
71 
72 // Security check
73 if ($user->societe_id > 0) accessforbidden();
74 if (! $user->rights->accounting->chartofaccount) accessforbidden();
75 
76 
77 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
78 $hookmanager->initHooks(array('admin'));
79 
80 // This page is a generic page to edit dictionaries
81 // Put here declaration of dictionaries properties
82 
83 // Name of SQL tables of dictionaries
84 $tabname=array();
85 
86 $tabname[31]= MAIN_DB_PREFIX."accounting_system";
87 $tabname[32]= MAIN_DB_PREFIX."c_accounting_category";
88 
89 // Dictionary labels
90 $tablib=array();
91 $tablib[31]= "Pcg_version";
92 $tablib[32]= "DictionaryAccountancyCategory";
93 
94 // Requests to extract data
95 $tabsql=array();
96 $tabsql[31]= "SELECT s.rowid as rowid, pcg_version, s.label, s.fk_country as country_id, c.code as country_code, c.label as country, s.active FROM ".MAIN_DB_PREFIX."accounting_system as s, ".MAIN_DB_PREFIX."c_country as c WHERE s.fk_country=c.rowid and c.active=1";
97 $tabsql[32]= "SELECT a.rowid as rowid, a.code as code, a.label, a.range_account, a.sens, 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";
98 
99 // Criteria to sort dictionaries
100 $tabsqlsort=array();
101 $tabsqlsort[31]="pcg_version ASC";
102 $tabsqlsort[32]="position ASC";
103 
104 // Nom des champs en resultat de select pour affichage du dictionnaire
105 $tabfield=array();
106 $tabfield[31]= "pcg_version,label,country_id,country";
107 $tabfield[32]= "code,label,range_account,sens,category_type,formula,position,country_id,country";
108 
109 // Nom des champs d'edition pour modification d'un enregistrement
110 $tabfieldvalue=array();
111 $tabfieldvalue[31]= "pcg_version,label,country";
112 $tabfieldvalue[32]= "code,label,range_account,sens,category_type,formula,position,country";
113 
114 // Nom des champs dans la table pour insertion d'un enregistrement
115 $tabfieldinsert=array();
116 $tabfieldinsert[31]= "pcg_version,label,fk_country";
117 $tabfieldinsert[32]= "code,label,range_account,sens,category_type,formula,position,fk_country";
118 
119 // Nom du rowid si le champ n'est pas de type autoincrement
120 // Example: "" if id field is "rowid" and has autoincrement on
121 // "nameoffield" if id field is not "rowid" or has not autoincrement on
122 $tabrowid=array();
123 $tabrowid[31]= "";
124 $tabrowid[32]= "";
125 
126 // Condition to show dictionary in setup page
127 $tabcond=array();
128 $tabcond[31]= ! empty($conf->accounting->enabled);
129 $tabcond[32]= ! empty($conf->accounting->enabled);
130 
131 // List of help for fields
132 $tabhelp=array();
133 $tabhelp[31] = array('pcg_version'=>$langs->trans("EnterAnyCode"));
134 $tabhelp[32] = array('code'=>$langs->trans("EnterAnyCode"));
135 
136 // List of check for fields (NOT USED YET)
137 $tabfieldcheck=array();
138 $tabfieldcheck[31] = array();
139 $tabfieldcheck[32] = array();
140 
141 
142 // Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
143 $elementList = array();
144 $sourceList=array();
145 
146 
147 
148 /*
149  * Actions
150  */
151 
152 if (GETPOST('button_removefilter') || GETPOST('button_removefilter.x') || GETPOST('button_removefilter_x'))
153 {
154  $search_country_id = '';
155 }
156 
157 // Actions add or modify an entry into a dictionary
158 if (GETPOST('actionadd') || GETPOST('actionmodify'))
159 {
160  $listfield=explode(',', str_replace(' ', '',$tabfield[$id]));
161  $listfieldinsert=explode(',',$tabfieldinsert[$id]);
162  $listfieldmodify=explode(',',$tabfieldinsert[$id]);
163  $listfieldvalue=explode(',',$tabfieldvalue[$id]);
164 
165  // Check that all fields are filled
166  $ok=1;
167  foreach ($listfield as $f => $value)
168  {
169  if ($value == 'country_id' && in_array($tablib[$id],array('DictionaryVAT','DictionaryRegion','DictionaryCompanyType','DictionaryHolidayTypes','DictionaryRevenueStamp','DictionaryAccountancyCategory','Pcg_version'))) continue; // For some pages, country is not mandatory
170  if ($value == 'country' && in_array($tablib[$id],array('DictionaryCanton','DictionaryCompanyType','DictionaryRevenueStamp'))) continue; // For some pages, country is not mandatory
171  if ($value == 'localtax1' && empty($_POST['localtax1_type'])) continue;
172  if ($value == 'localtax2' && empty($_POST['localtax2_type'])) continue;
173  if ($value == 'color' && empty($_POST['color'])) continue;
174  if ($value == 'formula' && empty($_POST['formula'])) continue;
175  if ((! isset($_POST[$value]) || $_POST[$value]=='')
176  && (! in_array($listfield[$f], array('decalage','module','accountancy_code','accountancy_code_sell','accountancy_code_buy')) // Fields that are not mandatory
177  && (! ($id == 10 && $listfield[$f] == 'code')) // Code is mandatory fir table 10
178  )
179  )
180  {
181  $ok=0;
182  $fieldnamekey=$listfield[$f];
183  // We take translate key of field
184 
185  if ($fieldnamekey == 'pcg_version') $fieldnamekey='Pcg_version';
186  if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) $fieldnamekey='Label';
187  if ($fieldnamekey == 'libelle_facture') $fieldnamekey = 'LabelOnDocuments';
188  if ($fieldnamekey == 'nbjour') $fieldnamekey='NbOfDays';
189  if ($fieldnamekey == 'decalage') $fieldnamekey='Offset';
190  if ($fieldnamekey == 'module') $fieldnamekey='Module';
191  if ($fieldnamekey == 'code') $fieldnamekey = 'Code';
192  if ($fieldnamekey == 'note') $fieldnamekey = 'Note';
193  if ($fieldnamekey == 'taux') $fieldnamekey = 'Rate';
194  if ($fieldnamekey == 'type') $fieldnamekey = 'Type';
195  if ($fieldnamekey == 'position') $fieldnamekey = 'Position';
196  if ($fieldnamekey == 'unicode') $fieldnamekey = 'Unicode';
197  if ($fieldnamekey == 'deductible') $fieldnamekey = 'Deductible';
198  if ($fieldnamekey == 'sortorder') $fieldnamekey = 'SortOrder';
199  if ($fieldnamekey == 'category_type') $fieldnamekey = 'Calculated';
200 
201  setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
202  }
203  }
204  // Other checks
205  if ($tabname[$id] == MAIN_DB_PREFIX."c_actioncomm" && isset($_POST["type"]) && in_array($_POST["type"],array('system','systemauto'))) {
206  $ok=0;
207  setEventMessages($langs->transnoentities('ErrorReservedTypeSystemSystemAuto'), null, 'errors');
208  }
209  if (isset($_POST["code"]))
210  {
211  if ($_POST["code"]=='0')
212  {
213  $ok=0;
214  setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
215  }
216  /*if (!is_numeric($_POST['code'])) // disabled, code may not be in numeric base
217  {
218  $ok = 0;
219  $msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).'<br>';
220  }*/
221  }
222  if (isset($_POST["country"]) && ($_POST["country"]=='0') && ($id != 2))
223  {
224  if (in_array($tablib[$id],array('DictionaryCompanyType','DictionaryHolidayTypes'))) // Field country is no mandatory for such dictionaries
225  {
226  $_POST["country"]='';
227  }
228  else
229  {
230  $ok=0;
231  setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->transnoentities("Country")), null, 'errors');
232  }
233  }
234  if ($id == 3 && ! is_numeric($_POST["code"]))
235  {
236  $ok=0;
237  setEventMessages($langs->transnoentities("ErrorFieldMustBeANumeric",$langs->transnoentities("Code")), null, 'errors');
238  }
239 
240  // Clean some parameters
241  if (isset($_POST["localtax1"]) && empty($_POST["localtax1"])) $_POST["localtax1"]='0'; // If empty, we force to 0
242  if (isset($_POST["localtax2"]) && empty($_POST["localtax2"])) $_POST["localtax2"]='0'; // If empty, we force to 0
243  if ($_POST["accountancy_code"] <= 0) $_POST["accountancy_code"]=''; // If empty, we force to null
244  if ($_POST["accountancy_code_sell"] <= 0) $_POST["accountancy_code_sell"]=''; // If empty, we force to null
245  if ($_POST["accountancy_code_buy"] <= 0) $_POST["accountancy_code_buy"]=''; // If empty, we force to null
246 
247  // Si verif ok et action add, on ajoute la ligne
248  if ($ok && GETPOST('actionadd'))
249  {
250  if ($tabrowid[$id])
251  {
252  // Recupere id libre pour insertion
253  $newid=0;
254  $sql = "SELECT max(".$tabrowid[$id].") newid from ".$tabname[$id];
255  $result = $db->query($sql);
256  if ($result)
257  {
258  $obj = $db->fetch_object($result);
259  $newid=($obj->newid + 1);
260 
261  } else {
262  dol_print_error($db);
263  }
264  }
265 
266  // Add new entry
267  $sql = "INSERT INTO ".$tabname[$id]." (";
268  // List of fields
269  if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
270  $sql.= $tabrowid[$id].",";
271  $sql.= $tabfieldinsert[$id];
272  $sql.=",active)";
273  $sql.= " VALUES(";
274 
275  // List of values
276  if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
277  $sql.= $newid.",";
278  $i=0;
279  foreach ($listfieldinsert as $f => $value)
280  {
281  if ($value == 'price' || preg_match('/^amount/i',$value) || $value == 'taux') {
282  $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU');
283  }
284  else if ($value == 'entity') {
285  $_POST[$listfieldvalue[$i]] = $conf->entity;
286  }
287  if ($i) $sql.=",";
288  if ($_POST[$listfieldvalue[$i]] == '') $sql.="null";
289  else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
290  $i++;
291  }
292  $sql.=",1)";
293 
294  dol_syslog("actionadd", LOG_DEBUG);
295  $result = $db->query($sql);
296  if ($result) // Add is ok
297  {
298  setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
299  $_POST=array('id'=>$id); // Clean $_POST array, we keep only
300  }
301  else
302  {
303  if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
304  setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
305  }
306  else {
307  dol_print_error($db);
308  }
309  }
310  }
311 
312  // Si verif ok et action modify, on modifie la ligne
313  if ($ok && GETPOST('actionmodify'))
314  {
315  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
316  else { $rowidcol="rowid"; }
317 
318  // Modify entry
319  $sql = "UPDATE ".$tabname[$id]." SET ";
320  // Modifie valeur des champs
321  if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldmodify))
322  {
323  $sql.= $tabrowid[$id]."=";
324  $sql.= "'".$db->escape($rowid)."', ";
325  }
326  $i = 0;
327  foreach ($listfieldmodify as $field)
328  {
329  if ($field == 'price' || preg_match('/^amount/i',$field) || $field == 'taux') {
330  $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU');
331  }
332  else if ($field == 'entity') {
333  $_POST[$listfieldvalue[$i]] = $conf->entity;
334  }
335  if ($i) $sql.=",";
336  $sql.= $field."=";
337  if ($_POST[$listfieldvalue[$i]] == '') $sql.="null";
338  else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
339  $i++;
340  }
341  $sql.= " WHERE ".$rowidcol." = '".$rowid."'";
342 
343  dol_syslog("actionmodify", LOG_DEBUG);
344  //print $sql;
345  $resql = $db->query($sql);
346  if (! $resql)
347  {
348  setEventMessages($db->error(), null, 'errors');
349  }
350  }
351  //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
352 }
353 
354 if (GETPOST('actioncancel'))
355 {
356  //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
357 }
358 
359 if ($action == 'confirm_delete' && $confirm == 'yes') // delete
360 {
361  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
362  else { $rowidcol="rowid"; }
363 
364  $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol."='".$rowid."'";
365 
366  dol_syslog("delete", LOG_DEBUG);
367  $result = $db->query($sql);
368  if (! $result)
369  {
370  if ($db->errno() == 'DB_ERROR_CHILD_EXISTS')
371  {
372  setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
373  }
374  else
375  {
376  dol_print_error($db);
377  }
378  }
379 }
380 
381 // activate
382 if ($action == $acts[0])
383 {
384  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
385  else { $rowidcol="rowid"; }
386 
387  if ($rowid) {
388  $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'";
389  }
390  elseif ($code) {
391  $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$code."'";
392  }
393 
394  $result = $db->query($sql);
395  if (!$result)
396  {
397  dol_print_error($db);
398  }
399 }
400 
401 // disable
402 if ($action == $acts[1])
403 {
404  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
405  else { $rowidcol="rowid"; }
406 
407  if ($rowid) {
408  $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'";
409  }
410  elseif ($code) {
411  $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$code."'";
412  }
413 
414  $result = $db->query($sql);
415  if (!$result)
416  {
417  dol_print_error($db);
418  }
419 }
420 
421 // favorite
422 if ($action == 'activate_favorite')
423 {
424  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
425  else { $rowidcol="rowid"; }
426 
427  if ($rowid) {
428  $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol."='".$rowid."'";
429  }
430  elseif ($code) {
431  $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".$code."'";
432  }
433 
434  $result = $db->query($sql);
435  if (!$result)
436  {
437  dol_print_error($db);
438  }
439 }
440 
441 // disable favorite
442 if ($action == 'disable_favorite')
443 {
444  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
445  else { $rowidcol="rowid"; }
446 
447  if ($rowid) {
448  $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol."='".$rowid."'";
449  }
450  elseif ($code) {
451  $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".$code."'";
452  }
453 
454  $result = $db->query($sql);
455  if (!$result)
456  {
457  dol_print_error($db);
458  }
459 }
460 
461 
462 /*
463  * View
464  */
465 
466 $form = new Form($db);
467 $formadmin=new FormAdmin($db);
468 
469 llxHeader();
470 
471 $titre=$langs->trans($tablib[$id]);
472 $linkback='';
473 
474 print load_fiche_titre($titre,$linkback,'title_accountancy');
475 
476 if (empty($id))
477 {
478  print $langs->trans("DictionaryDesc");
479  print " ".$langs->trans("OnlyActiveElementsAreShown")."<br>\n";
480 }
481 print "<br>\n";
482 
483 
484 // Confirmation de la suppression de la ligne
485 if ($action == 'delete')
486 {
487  print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$code.'&id='.$id, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete','',0,1);
488 }
489 //var_dump($elementList);
490 
491 /*
492  * Show a dictionary
493  */
494 if ($id)
495 {
496  // Complete requete recherche valeurs avec critere de tri
497  $sql=$tabsql[$id];
498 
499  if ($search_country_id > 0)
500  {
501  if (preg_match('/ WHERE /',$sql)) $sql.= " AND ";
502  else $sql.=" WHERE ";
503  $sql.= " c.rowid = ".$search_country_id;
504  }
505 
506  if ($sortfield)
507  {
508  // If sort order is "country", we use country_code instead
509  if ($sortfield == 'country') $sortfield='country_code';
510  $sql.= " ORDER BY ".$sortfield;
511  if ($sortorder)
512  {
513  $sql.=" ".strtoupper($sortorder);
514  }
515  $sql.=", ";
516  // Clear the required sort criteria for the tabsqlsort to be able to force it with selected value
517  $tabsqlsort[$id]=preg_replace('/([a-z]+\.)?'.$sortfield.' '.$sortorder.',/i','',$tabsqlsort[$id]);
518  $tabsqlsort[$id]=preg_replace('/([a-z]+\.)?'.$sortfield.',/i','',$tabsqlsort[$id]);
519  }
520  else {
521  $sql.=" ORDER BY ";
522  }
523  $sql.=$tabsqlsort[$id];
524  $sql.=$db->plimit($listlimit+1,$offset);
525  //print $sql;
526 
527  $fieldlist=explode(',',$tabfield[$id]);
528 
529  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
530  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
531 
532  print '<div class="div-table-responsive">';
533  print '<table class="noborder" width="100%">';
534 
535  // Form to add a new line
536  if ($tabname[$id])
537  {
538  $alabelisused=0;
539  $var=false;
540 
541  $fieldlist=explode(',',$tabfield[$id]);
542 
543  // Line for title
544  print '<tr class="liste_titre">';
545  foreach ($fieldlist as $field => $value)
546  {
547  // Determine le nom du champ par rapport aux noms possibles
548  // dans les dictionnaires de donnees
549  $valuetoshow=ucfirst($fieldlist[$field]); // Par defaut
550  $valuetoshow=$langs->trans($valuetoshow); // try to translate
551  $align="left";
552  if ($fieldlist[$field]=='source') { $valuetoshow=$langs->trans("Contact"); }
553  if ($fieldlist[$field]=='price') { $valuetoshow=$langs->trans("PriceUHT"); }
554  if ($fieldlist[$field]=='taux') {
555  if ($tabname[$id] != MAIN_DB_PREFIX."c_revenuestamp") $valuetoshow=$langs->trans("Rate");
556  else $valuetoshow=$langs->trans("Amount");
557  $align='right';
558  }
559  if ($fieldlist[$field]=='localtax1_type') { $valuetoshow=$langs->trans("UseLocalTax")." 2"; $align="center"; $sortable=0; }
560  if ($fieldlist[$field]=='localtax1') { $valuetoshow=$langs->trans("Rate")." 2";}
561  if ($fieldlist[$field]=='localtax2_type') { $valuetoshow=$langs->trans("UseLocalTax")." 3"; $align="center"; $sortable=0; }
562  if ($fieldlist[$field]=='localtax2') { $valuetoshow=$langs->trans("Rate")." 3";}
563  if ($fieldlist[$field]=='organization') { $valuetoshow=$langs->trans("Organization"); }
564  if ($fieldlist[$field]=='lang') { $valuetoshow=$langs->trans("Language"); }
565  if ($fieldlist[$field]=='type') {
566  if ($tabname[$id] == MAIN_DB_PREFIX."c_paiement") $valuetoshow=$form->textwithtooltip($langs->trans("Type"),$langs->trans("TypePaymentDesc"),2,1,img_help(1,''));
567  else $valuetoshow=$langs->trans("Type");
568  }
569  if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
570  if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label')
571  {
572  $valuetoshow=$langs->trans("Label");
573  if ($id != 25) $valuetoshow.="*";
574  }
575  if ($fieldlist[$field]=='libelle_facture') { $valuetoshow=$langs->trans("LabelOnDocuments")."*"; }
576  if ($fieldlist[$field]=='country') {
577  if (in_array('region_id',$fieldlist)) { print '<td>&nbsp;</td>'; continue; } // For region page, we do not show the country input
578  $valuetoshow=$langs->trans("Country");
579  }
580  if ($fieldlist[$field]=='recuperableonly') { $valuetoshow=$langs->trans("NPR"); $align="center"; }
581  if ($fieldlist[$field]=='nbjour') { $valuetoshow=$langs->trans("NbOfDays"); }
582  if ($fieldlist[$field]=='type_cdr') { $valuetoshow=$langs->trans("AtEndOfMonth"); $align="center"; }
583  if ($fieldlist[$field]=='decalage') { $valuetoshow=$langs->trans("Offset"); }
584  if ($fieldlist[$field]=='width') { $valuetoshow=$langs->trans("Width"); }
585  if ($fieldlist[$field]=='height') { $valuetoshow=$langs->trans("Height"); }
586  if ($fieldlist[$field]=='unit') { $valuetoshow=$langs->trans("MeasuringUnit"); }
587  if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $valuetoshow=''; }
588  if ($fieldlist[$field]=='accountancy_code'){ $valuetoshow=$langs->trans("AccountancyCode"); }
589  if ($fieldlist[$field]=='accountancy_code_sell'){ $valuetoshow=$langs->trans("AccountancyCodeSell"); }
590  if ($fieldlist[$field]=='accountancy_code_buy'){ $valuetoshow=$langs->trans("AccountancyCodeBuy"); }
591  if ($fieldlist[$field]=='pcg_version' || $fieldlist[$field]=='fk_pcg_version') { $valuetoshow=$langs->trans("Pcg_version"); }
592  if ($fieldlist[$field]=='account_parent') { $valuetoshow=$langs->trans("Accountparent"); }
593  if ($fieldlist[$field]=='pcg_type') { $valuetoshow=$langs->trans("Pcg_type"); }
594  if ($fieldlist[$field]=='pcg_subtype') { $valuetoshow=$langs->trans("Pcg_subtype"); }
595  if ($fieldlist[$field]=='sortorder') { $valuetoshow=$langs->trans("SortOrder"); }
596  if ($fieldlist[$field]=='short_label') { $valuetoshow=$langs->trans("ShortLabel"); }
597  if ($fieldlist[$field]=='type_template') { $valuetoshow=$langs->trans("TypeOfTemplate"); }
598  if ($fieldlist[$field]=='range_account') { $valuetoshow=$langs->trans("Range"); }
599  if ($fieldlist[$field]=='sens') { $valuetoshow=$langs->trans("Sens"); }
600  if ($fieldlist[$field]=='category_type') { $valuetoshow=$langs->trans("Calculated"); }
601  if ($fieldlist[$field]=='formula') { $valuetoshow=$langs->trans("Formula"); }
602 
603  if ($id == 2) // Special cas for state page
604  {
605  if ($fieldlist[$field]=='region_id') { $valuetoshow='&nbsp;'; $showfield=1; }
606  if ($fieldlist[$field]=='region') { $valuetoshow=$langs->trans("Country").'/'.$langs->trans("Region"); $showfield=1; }
607  }
608 
609  if ($valuetoshow != '')
610  {
611  print '<td align="'.$align.'">';
612  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>';
613  else if (! empty($tabhelp[$id][$value])) print $form->textwithpicto($valuetoshow,$tabhelp[$id][$value]);
614  else print $valuetoshow;
615  print '</td>';
616  }
617  if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') $alabelisused=1;
618  }
619 
620  print '<td>';
621  print '<input type="hidden" name="id" value="'.$id.'">';
622  print '</td>';
623  print '<td style="min-width: 26px;"></td>';
624  print '<td style="min-width: 26px;"></td>';
625  print '</tr>';
626 
627  // Line to enter new values
628  print "<tr ".$bcnd[$var].">";
629 
630  $obj = new stdClass();
631  // If data was already input, we define them in obj to populate input fields.
632  if (GETPOST('actionadd'))
633  {
634  foreach ($fieldlist as $key=>$val)
635  {
636  if (GETPOST($val))
637  $obj->$val=GETPOST($val);
638  }
639  }
640 
641  $tmpaction = 'create';
642  $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
643  $reshook=$hookmanager->executeHooks('createDictionaryFieldlist',$parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
644  $error=$hookmanager->error; $errors=$hookmanager->errors;
645 
646  if ($id == 3) unset($fieldlist[2]);
647 
648  if (empty($reshook))
649  {
650  if ($tabname[$id] == MAIN_DB_PREFIX.'c_email_templates' && $action == 'edit')
651  {
652  fieldListAccountModel($fieldlist,$obj,$tabname[$id],'hide');
653  }
654  else
655  {
656  fieldListAccountModel($fieldlist,$obj,$tabname[$id],'add');
657  }
658  }
659 
660  print '<td colspan="3" align="right">';
661  if ($tabname[$id] != MAIN_DB_PREFIX.'c_email_templates' || $action != 'edit')
662  {
663  print '<input type="submit" class="button" name="actionadd" value="'.$langs->trans("Add").'">';
664  }
665  print '</td>';
666  print "</tr>";
667 
668  $colspan=count($fieldlist)+3;
669 
670  if (! empty($alabelisused)) // If there is one label among fields, we show legend of *
671  {
672  print '<tr><td colspan="'.$colspan.'">* '.$langs->trans("LabelUsedByDefault").'.</td></tr>';
673  }
674  print '<tr><td colspan="'.$colspan.'">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
675  }
676 
677 
678 
679  // List of available values in database
680  dol_syslog("htdocs/admin/dict", LOG_DEBUG);
681  $resql=$db->query($sql);
682  if ($resql)
683  {
684  $num = $db->num_rows($resql);
685  $i = 0;
686  $var=true;
687 
688  $param = '&id='.$id;
689  if ($search_country_id > 0) $param.= '&search_country_id='.$search_country_id;
690  $paramwithsearch = $param;
691  if ($sortorder) $paramwithsearch.= '&sortorder='.$sortorder;
692  if ($sortfield) $paramwithsearch.= '&sortfield='.$sortfield;
693 
694  // There is several pages
695  if ($num > $listlimit)
696  {
697  print '<tr class="none"><td align="right" colspan="'.(3+count($fieldlist)).'">';
698  print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page+1).'</span></li>');
699  print '</td></tr>';
700  }
701 
702  // Title line with search boxes
703  print '<tr class="liste_titre liste_titre_add">';
704  foreach ($fieldlist as $field => $value)
705  {
706  $showfield=1; // By defaut
707 
708  if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $showfield=0; }
709 
710  if ($showfield)
711  {
712  if ($value == 'country')
713  {
714  print '<td class="liste_titre">';
715  print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth200 maxwidthonsmartphone');
716  print '</td>';
717  }
718  else
719  {
720  print '<td class="liste_titre"></td>';
721  }
722  }
723  }
724  print '<td class="liste_titre"></td>';
725  print '<td class="liste_titre" colspan="2" align="right">';
726  $searchpicto=$form->showFilterAndCheckAddButtons(0);
727  print $searchpicto;
728  print '</td>';
729  print '</tr>';
730 
731  // Title of lines
732  print '<tr class="liste_titre">';
733  foreach ($fieldlist as $field => $value)
734  {
735  // Determine le nom du champ par rapport aux noms possibles
736  // dans les dictionnaires de donnees
737  $showfield=1; // By defaut
738  $align="left";
739  $sortable=1;
740  $valuetoshow='';
741  /*
742  $tmparray=getLabelOfField($fieldlist[$field]);
743  $showfield=$tmp['showfield'];
744  $valuetoshow=$tmp['valuetoshow'];
745  $align=$tmp['align'];
746  $sortable=$tmp['sortable'];
747  */
748  $valuetoshow=ucfirst($fieldlist[$field]); // By defaut
749  $valuetoshow=$langs->trans($valuetoshow); // try to translate
750  if ($fieldlist[$field]=='source') { $valuetoshow=$langs->trans("Contact"); }
751  if ($fieldlist[$field]=='price') { $valuetoshow=$langs->trans("PriceUHT"); }
752  if ($fieldlist[$field]=='taux') {
753  if ($tabname[$id] != MAIN_DB_PREFIX."c_revenuestamp") $valuetoshow=$langs->trans("Rate");
754  else $valuetoshow=$langs->trans("Amount");
755  $align='right';
756  }
757  if ($fieldlist[$field]=='localtax1_type') { $valuetoshow=$langs->trans("UseLocalTax")." 2"; $align="center"; $sortable=0; }
758  if ($fieldlist[$field]=='localtax1') { $valuetoshow=$langs->trans("Rate")." 2"; $sortable=0; }
759  if ($fieldlist[$field]=='localtax2_type') { $valuetoshow=$langs->trans("UseLocalTax")." 3"; $align="center"; $sortable=0; }
760  if ($fieldlist[$field]=='localtax2') { $valuetoshow=$langs->trans("Rate")." 3"; $sortable=0; }
761  if ($fieldlist[$field]=='organization') { $valuetoshow=$langs->trans("Organization"); }
762  if ($fieldlist[$field]=='lang') { $valuetoshow=$langs->trans("Language"); }
763  if ($fieldlist[$field]=='type') { $valuetoshow=$langs->trans("Type"); }
764  if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
765  if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label')
766  {
767  $valuetoshow=$langs->trans("Label");
768  if ($id != 25) $valuetoshow.="*";
769  }
770  if ($fieldlist[$field]=='libelle_facture') { $valuetoshow=$langs->trans("LabelOnDocuments")."*"; }
771  if ($fieldlist[$field]=='country') { $valuetoshow=$langs->trans("Country"); }
772  if ($fieldlist[$field]=='recuperableonly') { $valuetoshow=$langs->trans("NPR"); $align="center"; }
773  if ($fieldlist[$field]=='nbjour') { $valuetoshow=$langs->trans("NbOfDays"); }
774  if ($fieldlist[$field]=='type_cdr') { $valuetoshow=$langs->trans("AtEndOfMonth"); $align="center"; }
775  if ($fieldlist[$field]=='decalage') { $valuetoshow=$langs->trans("Offset"); }
776  if ($fieldlist[$field]=='width') { $valuetoshow=$langs->trans("Width"); }
777  if ($fieldlist[$field]=='height') { $valuetoshow=$langs->trans("Height"); }
778  if ($fieldlist[$field]=='unit') { $valuetoshow=$langs->trans("MeasuringUnit"); }
779  if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $showfield=0; }
780  if ($fieldlist[$field]=='accountancy_code'){ $valuetoshow=$langs->trans("AccountancyCode"); }
781  if ($fieldlist[$field]=='accountancy_code_sell'){ $valuetoshow=$langs->trans("AccountancyCodeSell"); $sortable=0; }
782  if ($fieldlist[$field]=='accountancy_code_buy'){ $valuetoshow=$langs->trans("AccountancyCodeBuy"); $sortable=0; }
783  if ($fieldlist[$field]=='fk_pcg_version') { $valuetoshow=$langs->trans("Pcg_version"); }
784  if ($fieldlist[$field]=='account_parent') { $valuetoshow=$langs->trans("Accountsparent"); }
785  if ($fieldlist[$field]=='pcg_type') { $valuetoshow=$langs->trans("Pcg_type"); }
786  if ($fieldlist[$field]=='pcg_subtype') { $valuetoshow=$langs->trans("Pcg_subtype"); }
787  if ($fieldlist[$field]=='sortorder') { $valuetoshow=$langs->trans("SortOrder"); }
788  if ($fieldlist[$field]=='short_label') { $valuetoshow=$langs->trans("ShortLabel"); }
789  if ($fieldlist[$field]=='type_template') { $valuetoshow=$langs->trans("TypeOfTemplate"); }
790  if ($fieldlist[$field]=='range_account') { $valuetoshow=$langs->trans("Range"); }
791  if ($fieldlist[$field]=='sens') { $valuetoshow=$langs->trans("Sens"); }
792  if ($fieldlist[$field]=='category_type') { $valuetoshow=$langs->trans("Calculated"); }
793  if ($fieldlist[$field]=='formula') { $valuetoshow=$langs->trans("Formula"); }
794 
795  // Affiche nom du champ
796  if ($showfield)
797  {
798  print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable?$fieldlist[$field]:''), ($page?'page='.$page.'&':''), $param, "align=".$align, $sortfield, $sortorder);
799  }
800  }
801  print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page?'page='.$page.'&':''), $param, 'align="center"', $sortfield, $sortorder);
804  print '</tr>';
805 
806  if ($num)
807  {
808  // Lines with values
809  while ($i < $num)
810  {
811  $obj = $db->fetch_object($resql);
812  //print_r($obj);
813  print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
814  if ($action == 'edit' && ($rowid == (! empty($obj->rowid)?$obj->rowid:$obj->code)))
815  {
816  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
817  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
818  print '<input type="hidden" name="page" value="'.$page.'">';
819  print '<input type="hidden" name="rowid" value="'.$rowid.'">';
820 
821  $tmpaction='edit';
822  $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
823  $reshook=$hookmanager->executeHooks('editDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
824  $error=$hookmanager->error; $errors=$hookmanager->errors;
825 
826  if (empty($reshook)) fieldListAccountModel($fieldlist,$obj,$tabname[$id],'edit');
827 
828  print '<td colspan="3" align="right"><a name="'.(! empty($obj->rowid)?$obj->rowid:$obj->code).'">&nbsp;</a><input type="submit" class="button" name="actionmodify" value="'.$langs->trans("Modify").'">';
829  print '&nbsp;<input type="submit" class="button" name="actioncancel" value="'.$langs->trans("Cancel").'"></td>';
830  }
831  else
832  {
833  $tmpaction = 'view';
834  $parameters=array('var'=>$var, 'fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
835  $reshook=$hookmanager->executeHooks('viewDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
836 
837  $error=$hookmanager->error; $errors=$hookmanager->errors;
838 
839  if (empty($reshook))
840  {
841  foreach ($fieldlist as $field => $value)
842  {
843 
844  $showfield=1;
845  $align="left";
846  $valuetoshow=$obj->{$fieldlist[$field]};
847  if ($value == 'type_template')
848  {
849  $valuetoshow = isset($elementList[$valuetoshow])?$elementList[$valuetoshow]:$valuetoshow;
850  }
851  if ($value == 'element')
852  {
853  $valuetoshow = isset($elementList[$valuetoshow])?$elementList[$valuetoshow]:$valuetoshow;
854  }
855  else if ($value == 'source')
856  {
857  $valuetoshow = isset($sourceList[$valuetoshow])?$sourceList[$valuetoshow]:$valuetoshow;
858  }
859  else if ($valuetoshow=='all') {
860  $valuetoshow=$langs->trans('All');
861  }
862  else if ($fieldlist[$field]=='country') {
863  if (empty($obj->country_code))
864  {
865  $valuetoshow='-';
866  }
867  else
868  {
869  $key=$langs->trans("Country".strtoupper($obj->country_code));
870  $valuetoshow=($key != "Country".strtoupper($obj->country_code)?$obj->country_code." - ".$key:$obj->country);
871  }
872  }
873  else if ($fieldlist[$field]=='recuperableonly' || $fieldlist[$field]=='type_cdr' || $fieldlist[$field] == 'deductible' || $fieldlist[$field] == 'category_type') {
874  if(empty($valuetoshow)) $valuetoshow = $langs->trans('None');
875  elseif($valuetoshow == 1) $valuetoshow = $langs->trans('AtEndOfMonth');
876  elseif($valuetoshow == 2) $valuetoshow = $langs->trans('CurrentNext');
877  $align="center";
878  }
879  else if ($fieldlist[$field]=='price' || preg_match('/^amount/i',$fieldlist[$field])) {
880  $valuetoshow=price($valuetoshow);
881  }
882  else if ($fieldlist[$field]=='libelle_facture') {
883  $langs->load("bills");
884  $key=$langs->trans("PaymentCondition".strtoupper($obj->code));
885  $valuetoshow=($obj->code && $key != "PaymentCondition".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
886  $valuetoshow=nl2br($valuetoshow);
887  }
888  else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_country') {
889  $key=$langs->trans("Country".strtoupper($obj->code));
890  $valuetoshow=($obj->code && $key != "Country".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
891  }
892  else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_availability') {
893  $langs->load("propal");
894  $key=$langs->trans("AvailabilityType".strtoupper($obj->code));
895  $valuetoshow=($obj->code && $key != "AvailabilityType".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
896  }
897  else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_actioncomm') {
898  $key=$langs->trans("Action".strtoupper($obj->code));
899  $valuetoshow=($obj->code && $key != "Action".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
900  }
901  else if (! empty($obj->code_iso) && $fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_currencies') {
902  $key=$langs->trans("Currency".strtoupper($obj->code_iso));
903  $valuetoshow=($obj->code_iso && $key != "Currency".strtoupper($obj->code_iso)?$key:$obj->{$fieldlist[$field]});
904  }
905  else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_typent') {
906  $key=$langs->trans(strtoupper($obj->code));
907  $valuetoshow=($key != strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
908  }
909  else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_prospectlevel') {
910  $key=$langs->trans(strtoupper($obj->code));
911  $valuetoshow=($key != strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
912  }
913  else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_civility') {
914  $key=$langs->trans("Civility".strtoupper($obj->code));
915  $valuetoshow=($obj->code && $key != "Civility".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
916  }
917  else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_type_contact') {
918  $langs->load('agenda');
919  $key=$langs->trans("TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code));
920  $valuetoshow=($obj->code && $key != "TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
921  }
922  else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_payment_term') {
923  $langs->load("bills");
924  $key=$langs->trans("PaymentConditionShort".strtoupper($obj->code));
925  $valuetoshow=($obj->code && $key != "PaymentConditionShort".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
926  }
927  else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_paiement') {
928  $langs->load("bills");
929  $key=$langs->trans("PaymentType".strtoupper($obj->code));
930  $valuetoshow=($obj->code && $key != "PaymentType".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
931  }
932  else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_input_reason') {
933  $key=$langs->trans("DemandReasonType".strtoupper($obj->code));
934  $valuetoshow=($obj->code && $key != "DemandReasonType".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
935  }
936  else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_input_method') {
937  $langs->load("orders");
938  $key=$langs->trans($obj->code);
939  $valuetoshow=($obj->code && $key != $obj->code)?$key:$obj->{$fieldlist[$field]};
940  }
941  else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_shipment_mode') {
942  $langs->load("sendings");
943  $key=$langs->trans("SendingMethod".strtoupper($obj->code));
944  $valuetoshow=($obj->code && $key != "SendingMethod".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
945  }
946  else if ($fieldlist[$field] == 'libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_paper_format')
947  {
948  $key = $langs->trans('PaperFormat'.strtoupper($obj->code));
949  $valuetoshow = ($obj->code && $key != 'PaperFormat'.strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
950  }
951  else if ($fieldlist[$field] == 'label' && $tabname[$id] == MAIN_DB_PREFIX.'c_type_fees')
952  {
953  $langs->load('trips');
954  $key = $langs->trans(strtoupper($obj->code));
955  $valuetoshow = ($obj->code && $key != strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
956  }
957  else if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') {
958  $showfield=0;
959  }
960  else if ($fieldlist[$field]=='unicode') {
961  $valuetoshow = $langs->getCurrencySymbol($obj->code,1);
962  }
963  else if ($fieldlist[$field]=='label' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_units') {
964  $langs->load("products");
965  $valuetoshow=$langs->trans($obj->{$fieldlist[$field]});
966  }
967  else if ($fieldlist[$field]=='short_label' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_units') {
968  $langs->load("products");
969  $valuetoshow = $langs->trans($obj->{$fieldlist[$field]});
970  }
971  else if (($fieldlist[$field] == 'unit') && ($tabname[$id] == MAIN_DB_PREFIX.'c_paper_format'))
972  {
973  $key = $langs->trans('SizeUnit'.strtolower($obj->unit));
974  $valuetoshow = ($obj->code && $key != 'SizeUnit'.strtolower($obj->unit) ? $key : $obj->{$fieldlist[$field]});
975  }
976  else if ($fieldlist[$field]=='taux') {
977  $valuetoshow = price($valuetoshow, 0, $langs, 0, 0);
978  $align="right";
979  }
980  else if (in_array($fieldlist[$field],array('recuperableonly')))
981  {
982  $align="center";
983  }
984  else if ($fieldlist[$field]=='accountancy_code' || $fieldlist[$field]=='accountancy_code_sell' || $fieldlist[$field]=='accountancy_code_buy') {
985  $valuetoshow = length_accountg($valuetoshow);
986  }
987 
988  $class='tddict';
989  if ($fieldlist[$field] == 'tracking') $class.=' tdoverflowauto';
990  // Show value for field
991  if ($showfield) print '<!-- '.$fieldlist[$field].' --><td align="'.$align.'" class="'.$class.'">'.$valuetoshow.'</td>';
992  }
993  }
994 
995  // Can an entry be erased or disabled ?
996  $iserasable=1;$canbedisabled=1;$canbemodified=1; // true by default
997  if (isset($obj->code) && $id != 10)
998  {
999  if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i',$obj->code))) { $iserasable = 0; $canbedisabled = 0; }
1000  else if ($obj->code == 'RECEP') { $iserasable = 0; $canbedisabled = 0; }
1001  else if ($obj->code == 'EF0') { $iserasable = 0; $canbedisabled = 0; }
1002  }
1003 
1004  if (isset($obj->type) && in_array($obj->type, array('system', 'systemauto'))) { $iserasable=0; }
1005  if (in_array($obj->code, array('AC_OTH','AC_OTH_AUTO')) || in_array($obj->type, array('systemauto'))) { $canbedisabled=0; $canbedisabled = 0; }
1006  $canbemodified=$iserasable;
1007  if ($obj->code == 'RECEP') $canbemodified=1;
1008 
1009  $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):'');
1010  if ($param) $url .= '&'.$param;
1011  $url.='&';
1012 
1013  // Active
1014  print '<td align="center" class="nowrap">';
1015  if ($canbedisabled) print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
1016  else
1017  {
1018  if (in_array($obj->code, array('AC_OTH','AC_OTH_AUTO'))) print $langs->trans("AlwaysActive");
1019  else if (isset($obj->type) && in_array($obj->type, array('systemauto')) && empty($obj->active)) print $langs->trans("Deprecated");
1020  else if (isset($obj->type) && in_array($obj->type, array('system')) && ! empty($obj->active) && $obj->code != 'AC_OTH') print $langs->trans("UsedOnlyWithTypeOption");
1021  else print $langs->trans("AlwaysActive");
1022  }
1023  print "</td>";
1024 
1025  // Modify link
1026  if ($canbemodified) print '<td align="center"><a class="reposition" href="'.$url.'action=edit">'.img_edit().'</a></td>';
1027  else print '<td>&nbsp;</td>';
1028 
1029  // Delete link
1030  if ($iserasable) print '<td align="center"><a href="'.$url.'action=delete">'.img_delete().'</a></td>';
1031  else print '<td>&nbsp;</td>';
1032 
1033  print "</tr>\n";
1034  }
1035  $i++;
1036  }
1037  }
1038  }
1039  else {
1040  dol_print_error($db);
1041  }
1042 
1043  print '</table>';
1044  print '</div>';
1045 
1046  print '</form>';
1047 }
1048 
1049 print '<br>';
1050 
1051 
1052 llxFooter();
1053 $db->close();
1054 
1055 
1065 function fieldListAccountModel($fieldlist, $obj='', $tabname='', $context='')
1066 {
1067  global $conf,$langs,$db;
1068  global $form;
1069  global $region_id;
1070  global $elementList,$sourceList;
1071  global $bc;
1072 
1073  $formadmin = new FormAdmin($db);
1074  $formcompany = new FormCompany($db);
1075  $formaccounting = new FormAccounting($db);
1076 
1077  foreach ($fieldlist as $field => $value)
1078  {
1079  if ($fieldlist[$field] == 'country')
1080  {
1081  if (in_array('region_id',$fieldlist))
1082  {
1083  print '<td>';
1084  //print join(',',$fieldlist);
1085  print '</td>';
1086  continue;
1087  } // For state page, we do not show the country input (we link to region, not country)
1088  print '<td>';
1089  $fieldname='country';
1090  print $form->select_country((! empty($obj->country_code)?$obj->country_code:(! empty($obj->country)?$obj->country:'')), $fieldname, '', 28, 'maxwidth200 maxwidthonsmartphone');
1091  print '</td>';
1092  }
1093  elseif ($fieldlist[$field] == 'country_id')
1094  {
1095  if (! in_array('country',$fieldlist)) // If there is already a field country, we don't show country_id (avoid duplicate)
1096  {
1097  $country_id = (! empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
1098  print '<td>';
1099  print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">';
1100  print '</td>';
1101  }
1102  }
1103  elseif ($fieldlist[$field] == 'region')
1104  {
1105  print '<td>';
1106  $formcompany->select_region($region_id,'region');
1107  print '</td>';
1108  }
1109  elseif ($fieldlist[$field] == 'region_id')
1110  {
1111  $region_id = (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:0);
1112  print '<td>';
1113  print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$region_id.'">';
1114  print '</td>';
1115  }
1116  elseif ($fieldlist[$field] == 'lang')
1117  {
1118  print '<td>';
1119  print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT,'lang');
1120  print '</td>';
1121  }
1122  // Le type de template
1123  elseif ($fieldlist[$field] == 'type_template')
1124  {
1125  print '<td>';
1126  print $form->selectarray('type_template', $elementList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
1127  print '</td>';
1128  }
1129  // Le type de l'element (pour les type de contact)
1130  elseif ($fieldlist[$field] == 'element')
1131  {
1132  print '<td>';
1133  print $form->selectarray('element', $elementList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
1134  print '</td>';
1135  }
1136  // La source de l'element (pour les type de contact)
1137  elseif ($fieldlist[$field] == 'source')
1138  {
1139  print '<td>';
1140  print $form->selectarray('source', $sourceList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
1141  print '</td>';
1142  }
1143  elseif ($fieldlist[$field] == 'type' && $tabname == MAIN_DB_PREFIX."c_actioncomm")
1144  {
1145  print '<td>';
1146  print 'user<input type="hidden" name="type" value="user">';
1147  print '</td>';
1148  }
1149  elseif ($fieldlist[$field] == 'recuperableonly' || $fieldlist[$field] == 'type_cdr' || $fieldlist[$field] == 'deductible' || $fieldlist[$field] == 'category_type') {
1150  if ($fieldlist[$field] == 'type_cdr') print '<td align="center">';
1151  else print '<td>';
1152  if ($fieldlist[$field] == 'type_cdr') {
1153  print $form->selectarray($fieldlist[$field], array(0=>$langs->trans('None'), 1=>$langs->trans('AtEndOfMonth'), 2=>$langs->trans('CurrentNext')), (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
1154  } else {
1155  print $form->selectyesno($fieldlist[$field],(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''),1);
1156  }
1157  print '</td>';
1158  }
1159  elseif (in_array($fieldlist[$field],array('nbjour','decalage','taux','localtax1','localtax2'))) {
1160  $align="left";
1161  if (in_array($fieldlist[$field],array('taux','localtax1','localtax2'))) $align="right"; // Fields aligned on right
1162  print '<td align="'.$align.'">';
1163  print '<input type="text" class="flat" value="'.(isset($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" size="3" name="'.$fieldlist[$field].'">';
1164  print '</td>';
1165  }
1166  elseif (in_array($fieldlist[$field], array('libelle_facture'))) {
1167  print '<td><textarea cols="30" rows="'.ROWS_2.'" class="flat" name="'.$fieldlist[$field].'">'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'</textarea></td>';
1168  }
1169  elseif (in_array($fieldlist[$field], array('content')))
1170  {
1171  if ($tabname == MAIN_DB_PREFIX.'c_email_templates')
1172  {
1173  print '<td colspan="4"></td></tr><tr class="pair nohover"><td colspan="5">'; // To create an artificial CR for the current tr we are on
1174  }
1175  else print '<td>';
1176  if ($context != 'hide')
1177  {
1178  //print '<textarea cols="3" rows="'.ROWS_2.'" class="flat" name="'.$fieldlist[$field].'">'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'</textarea>';
1179  $okforextended=true;
1180  if ($tabname == MAIN_DB_PREFIX.'c_email_templates' && empty($conf->global->FCKEDITOR_ENABLE_MAIL)) $okforextended=false;
1181  $doleditor = new DolEditor($fieldlist[$field], (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''), '', 140, 'dolibarr_mailings', 'In', 0, false, $okforextended, ROWS_5, '90%');
1182  print $doleditor->Create(1);
1183  }
1184  else print '&nbsp;';
1185  print '</td>';
1186  }
1187  elseif ($fieldlist[$field] == 'price' || preg_match('/^amount/i',$fieldlist[$field])) {
1188  print '<td><input type="text" class="flat" value="'.price((! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'')).'" size="8" name="'.$fieldlist[$field].'"></td>';
1189  }
1190  elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
1191  print '<td><input type="text" class="flat" value="'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" size="10" name="'.$fieldlist[$field].'"></td>';
1192  }
1193  elseif ($fieldlist[$field] == 'accountancy_code' || $fieldlist[$field] == 'accountancy_code_sell' || $fieldlist[$field] == 'accountancy_code_buy')
1194  {
1195  print '<td>';
1196  if (! empty($conf->accounting->enabled))
1197  {
1198  $accountancy_account = (! empty($obj->$fieldlist[$field]) ? $obj->$fieldlist[$field] : 0);
1199  print $formaccounting->select_account($accountancy_account, $fieldlist[$field], 1, '', 1, 1, 'maxwidth200 maxwidthonsmartphone');
1200  }
1201  else
1202  {
1203  print '<input type="text" size="10" class="flat" value="'.(isset($obj->$fieldlist[$field])?$obj->$fieldlist[$field]:'').'" name="'.$fieldlist[$field].'">';
1204  }
1205  print '</td>';
1206  }
1207  else
1208  {
1209  print '<td>';
1210  $size=''; $class='';
1211  if ($fieldlist[$field]=='code') $size='size="8" ';
1212  if ($fieldlist[$field]=='position') $size='size="4" ';
1213  if ($fieldlist[$field]=='libelle') $size='centpercent';
1214  if ($fieldlist[$field]=='tracking') $class='centpercent';
1215  if ($fieldlist[$field]=='sortorder' || $fieldlist[$field]=='sens' || $fieldlist[$field]=='category_type') $size='size="2" ';
1216  print '<input type="text" '.$size.' class="flat'.($class?' '.$class:'').'" value="'.(isset($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
1217  print '</td>';
1218  }
1219  }
1220 }
1221 
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)
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
fieldListAccountModel($fieldlist, $obj='', $tabname='', $context='')
Show fields in insert/edit mode.
if(!GETPOST('transkey')&&!GETPOST('transphrase')) else
View.
Definition: notice.php:43
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
if(GETPOST('cancel','alpha')) if(!GETPOST('confirmmassaction','alpha')&&$massaction!= 'presend'&&$massaction!= 'confirm_presend')
Draft customers invoices.
Definition: list.php:147
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.
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.
llxHeader()
Empty header.
Definition: wrapper.php:46
img_delete($titlealt= 'default', $other= 'class="pictodelete"')
Show delete logo.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
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
Class to manage a WYSIWYG editor.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
img_edit($titlealt= 'default', $float=0, $other= 'class="pictoedit"')
Show logo editer/modifier fiche.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...