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