dolibarr  9.0.0
journals_list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Alexandre Spangaro <aspangaro@zendsi.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  *
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.'/accountancy/class/accountingjournal.class.php';
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array("admin","compta","accountancy"));
36 
37 $action=GETPOST('action','aZ09')?GETPOST('action','aZ09'):'view';
38 $confirm=GETPOST('confirm','alpha');
39 $id=35;
40 $rowid=GETPOST('rowid','alpha');
41 $code=GETPOST('code','alpha');
42 
43 // Security access
44 if (empty($user->rights->accounting->chartofaccount))
45 {
47 }
48 
49 $acts[0] = "activate";
50 $acts[1] = "disable";
51 $actl[0] = img_picto($langs->trans("Disabled"),'switch_off');
52 $actl[1] = img_picto($langs->trans("Activated"),'switch_on');
53 
54 $listoffset=GETPOST('listoffset', 'alpha');
55 $listlimit=GETPOST('listlimit', 'int')>0?GETPOST('listlimit', 'int'):1000;
56 $active = 1;
57 
58 $sortfield = GETPOST("sortfield",'alpha');
59 $sortorder = GETPOST("sortorder",'alpha');
60 $page = GETPOST("page",'int');
61 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
62 $offset = $listlimit * $page ;
63 $pageprev = $page - 1;
64 $pagenext = $page + 1;
65 if (empty($sortfield)) $sortfield='code';
66 if (empty($sortorder)) $sortorder='ASC';
67 
68 $error = 0;
69 
70 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
71 $hookmanager->initHooks(array('admin'));
72 
73 // This page is a generic page to edit dictionaries
74 // Put here declaration of dictionaries properties
75 
76 // Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this.
77 $taborder=array(35);
78 
79 // Name of SQL tables of dictionaries
80 $tabname=array();
81 $tabname[35]= MAIN_DB_PREFIX."accounting_journal";
82 
83 // Dictionary labels
84 $tablib=array();
85 $tablib[35]= "DictionaryAccountancyJournal";
86 
87 // Requests to extract data
88 $tabsql=array();
89 $tabsql[35]= "SELECT a.rowid as rowid, a.code as code, a.label, a.nature, a.active FROM ".MAIN_DB_PREFIX."accounting_journal as a";
90 
91 // Criteria to sort dictionaries
92 $tabsqlsort=array();
93 $tabsqlsort[35]="code ASC";
94 
95 // Nom des champs en resultat de select pour affichage du dictionnaire
96 $tabfield=array();
97 $tabfield[35]= "code,label,nature";
98 
99 // Nom des champs d'edition pour modification d'un enregistrement
100 $tabfieldvalue=array();
101 $tabfieldvalue[35]= "code,label,nature";
102 
103 // Nom des champs dans la table pour insertion d'un enregistrement
104 $tabfieldinsert=array();
105 $tabfieldinsert[35]= "code,label,nature";
106 
107 // Nom du rowid si le champ n'est pas de type autoincrement
108 // Example: "" if id field is "rowid" and has autoincrement on
109 // "nameoffield" if id field is not "rowid" or has not autoincrement on
110 $tabrowid=array();
111 $tabrowid[35]= "";
112 
113 // Condition to show dictionary in setup page
114 $tabcond=array();
115 $tabcond[35]= ! empty($conf->accounting->enabled);
116 
117 // List of help for fields
118 $tabhelp=array();
119 $tabhelp[35] = array('code'=>$langs->trans("EnterAnyCode"));
120 
121 // List of check for fields (NOT USED YET)
122 $tabfieldcheck=array();
123 $tabfieldcheck[35] = array();
124 
125 // Complete all arrays with entries found into modules
126 complete_dictionary_with_modules($taborder,$tabname,$tablib,$tabsql,$tabsqlsort,$tabfield,$tabfieldvalue,$tabfieldinsert,$tabrowid,$tabcond,$tabhelp,$tabfieldcheck);
127 
128 
129 // Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
130 $elementList = array();
131 // Must match ids defined into eldy.lib.php
132 $sourceList = array(
133  '1' => $langs->trans('AccountingJournalType1'),
134  '2' => $langs->trans('AccountingJournalType2'),
135  '3' => $langs->trans('AccountingJournalType3'),
136  '4' => $langs->trans('AccountingJournalType4'),
137  '5' => $langs->trans('AccountingJournalType5'),
138  '8' => $langs->trans('AccountingJournalType8'),
139  '9' => $langs->trans('AccountingJournalType9'),
140 );
141 
142 /*
143  * Actions
144  */
145 
146 if (GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter_x', 'alpha'))
147 {
148  $search_country_id = '';
149 }
150 
151 // Actions add or modify an entry into a dictionary
152 if (GETPOST('actionadd', 'alpha') || GETPOST('actionmodify', 'alpha'))
153 {
154  $listfield=explode(',', str_replace(' ', '',$tabfield[$id]));
155  $listfieldinsert=explode(',',$tabfieldinsert[$id]);
156  $listfieldmodify=explode(',',$tabfieldinsert[$id]);
157  $listfieldvalue=explode(',',$tabfieldvalue[$id]);
158 
159  // Check that all fields are filled
160  $ok=1;
161  foreach ($listfield as $f => $value)
162  {
163  if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) $fieldnamekey='Label';
164  if ($fieldnamekey == 'code') $fieldnamekey = 'Code';
165  if ($fieldnamekey == 'nature') $fieldnamekey = 'Nature';
166  }
167  // Other checks
168  if (isset($_POST["code"]))
169  {
170  if ($_POST["code"]=='0')
171  {
172  $ok=0;
173  setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
174  }
175  /*if (!is_numeric($_POST['code'])) // disabled, code may not be in numeric base
176  {
177  $ok = 0;
178  $msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).'<br>';
179  }*/
180  }
181  if (! GETPOST('label','alpha'))
182  {
183  setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
184  $ok=0;
185  }
186 
187  // Clean some parameters
188  if ($_POST["accountancy_code"] <= 0) $_POST["accountancy_code"]=''; // If empty, we force to null
189  if ($_POST["accountancy_code_sell"] <= 0) $_POST["accountancy_code_sell"]=''; // If empty, we force to null
190  if ($_POST["accountancy_code_buy"] <= 0) $_POST["accountancy_code_buy"]=''; // If empty, we force to null
191 
192  // Si verif ok et action add, on ajoute la ligne
193  if ($ok && GETPOST('actionadd', 'alpha'))
194  {
195  if ($tabrowid[$id])
196  {
197  // Recupere id libre pour insertion
198  $newid=0;
199  $sql = "SELECT max(".$tabrowid[$id].") newid from ".$tabname[$id];
200  $result = $db->query($sql);
201  if ($result)
202  {
203  $obj = $db->fetch_object($result);
204  $newid=($obj->newid + 1);
205  } else {
206  dol_print_error($db);
207  }
208  }
209 
210  // Add new entry
211  $sql = "INSERT INTO ".$tabname[$id]." (";
212  // List of fields
213  if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
214  $sql.= $tabrowid[$id].",";
215  $sql.= $tabfieldinsert[$id];
216  $sql.=",active,entity)";
217  $sql.= " VALUES(";
218 
219  // List of values
220  if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
221  $sql.= $newid.",";
222  $i=0;
223  foreach ($listfieldinsert as $f => $value)
224  {
225  if ($value == 'entity') {
226  $_POST[$listfieldvalue[$i]] = $conf->entity;
227  }
228  if ($i) $sql.=",";
229  if ($_POST[$listfieldvalue[$i]] == '') $sql.="null"; // For vat, we want/accept code = ''
230  else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
231  $i++;
232  }
233  $sql.=",1,".$conf->entity.")";
234 
235  dol_syslog("actionadd", LOG_DEBUG);
236  $result = $db->query($sql);
237  if ($result) // Add is ok
238  {
239  setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
240  $_POST=array('id'=>$id); // Clean $_POST array, we keep only
241  }
242  else
243  {
244  if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
245  setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
246  }
247  else {
248  dol_print_error($db);
249  }
250  }
251  }
252 
253  // Si verif ok et action modify, on modifie la ligne
254  if ($ok && GETPOST('actionmodify', 'alpha'))
255  {
256  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
257  else { $rowidcol="rowid"; }
258 
259  // Modify entry
260  $sql = "UPDATE ".$tabname[$id]." SET ";
261  // Modifie valeur des champs
262  if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldmodify))
263  {
264  $sql.= $tabrowid[$id]."=";
265  $sql.= "'".$db->escape($rowid)."', ";
266  }
267  $i = 0;
268  foreach ($listfieldmodify as $field)
269  {
270  if ($field == 'price' || preg_match('/^amount/i',$field) || $field == 'taux') {
271  $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU');
272  }
273  else if ($field == 'entity') {
274  $_POST[$listfieldvalue[$i]] = $conf->entity;
275  }
276  if ($i) $sql.=",";
277  $sql.= $field."=";
278  if ($_POST[$listfieldvalue[$i]] == '' && ! ($listfieldvalue[$i] == 'code' && $id == 10)) $sql.="null"; // For vat, we want/accept code = ''
279  else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
280  $i++;
281  }
282  $sql.= " WHERE ".$rowidcol." = '".$rowid."'";
283  $sql.=" AND entity = ".$conf->entity;
284 
285  dol_syslog("actionmodify", LOG_DEBUG);
286  //print $sql;
287  $resql = $db->query($sql);
288  if (! $resql)
289  {
290  setEventMessages($db->error(), null, 'errors');
291  }
292  }
293  //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
294 }
295 
296 //if (GETPOST('actioncancel', 'alpha'))
297 //{
298 // $_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
299 //}
300 
301 if ($action == 'confirm_delete' && $confirm == 'yes') // delete
302 {
303  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
304  else { $rowidcol="rowid"; }
305 
306  $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol."='".$rowid."'";
307  $sql.=" AND entity = ".$conf->entity;
308 
309  dol_syslog("delete", LOG_DEBUG);
310  $result = $db->query($sql);
311  if (! $result)
312  {
313  if ($db->errno() == 'DB_ERROR_CHILD_EXISTS')
314  {
315  setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
316  }
317  else
318  {
319  dol_print_error($db);
320  }
321  }
322 }
323 
324 // activate
325 if ($action == $acts[0])
326 {
327  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
328  else { $rowidcol="rowid"; }
329 
330  if ($rowid) {
331  $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'";
332  }
333  elseif ($code) {
334  $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$code."'";
335  }
336  $sql.=" AND entity = ".$conf->entity;
337 
338  $result = $db->query($sql);
339  if (!$result)
340  {
341  dol_print_error($db);
342  }
343 }
344 
345 // disable
346 if ($action == $acts[1])
347 {
348  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
349  else { $rowidcol="rowid"; }
350 
351  if ($rowid) {
352  $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'";
353  }
354  elseif ($code) {
355  $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$code."'";
356  }
357  $sql.=" AND entity = ".$conf->entity;
358 
359  $result = $db->query($sql);
360  if (!$result)
361  {
362  dol_print_error($db);
363  }
364 }
365 
366 
367 /*
368  * View
369  */
370 
371 $form = new Form($db);
372 $formadmin=new FormAdmin($db);
373 
374 llxHeader();
375 
376 $titre=$langs->trans("DictionarySetup");
377 $linkback='';
378 if ($id)
379 {
380  $titre.=' - '.$langs->trans($tablib[$id]);
381  $titlepicto='title_accountancy';
382 }
383 
384 print load_fiche_titre($titre,$linkback,$titlepicto);
385 
386 
387 // Confirmation de la suppression de la ligne
388 if ($action == 'delete')
389 {
390  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);
391 }
392 //var_dump($elementList);
393 
394 /*
395  * Show a dictionary
396  */
397 if ($id)
398 {
399  // Complete requete recherche valeurs avec critere de tri
400  $sql=$tabsql[$id];
401  $sql.= " WHERE a.entity = ".$conf->entity;
402 
403  // If sort order is "country", we use country_code instead
404  if ($sortfield == 'country') $sortfield='country_code';
405  $sql.=$db->order($sortfield,$sortorder);
406  $sql.=$db->plimit($listlimit+1,$offset);
407 
408  $fieldlist=explode(',',$tabfield[$id]);
409 
410  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
411  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
412  print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from','alpha')).'">';
413 
414  print '<div class="div-table-responsive">';
415  print '<table class="noborder" width="100%">';
416 
417  // Form to add a new line
418  if ($tabname[$id])
419  {
420  $alabelisused=0;
421 
422  $fieldlist=explode(',',$tabfield[$id]);
423 
424  // Line for title
425  print '<tr class="liste_titre">';
426  foreach ($fieldlist as $field => $value)
427  {
428  // Determine le nom du champ par rapport aux noms possibles
429  // dans les dictionnaires de donnees
430  $valuetoshow=ucfirst($fieldlist[$field]); // Par defaut
431  $valuetoshow=$langs->trans($valuetoshow); // try to translate
432  $align="left";
433  if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
434  if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label')
435  {
436  $valuetoshow=$langs->trans("Label");
437  }
438  if ($fieldlist[$field]=='nature') { $valuetoshow=$langs->trans("Nature"); }
439 
440  if ($valuetoshow != '')
441  {
442  print '<td align="'.$align.'">';
443  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>';
444  else if (! empty($tabhelp[$id][$value])) print $form->textwithpicto($valuetoshow,$tabhelp[$id][$value]);
445  else print $valuetoshow;
446  print '</td>';
447  }
448  if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') $alabelisused=1;
449  }
450 
451  print '<td>';
452  print '<input type="hidden" name="id" value="'.$id.'">';
453  print '</td>';
454  print '<td style="min-width: 26px;"></td>';
455  print '<td style="min-width: 26px;"></td>';
456  print '<td style="min-width: 26px;"></td>';
457  print '</tr>';
458 
459  // Line to enter new values
460  print '<tr class="oddeven nodrag nodrap nohover">';
461 
462  $obj = new stdClass();
463  // If data was already input, we define them in obj to populate input fields.
464  if (GETPOST('actionadd', 'alpha'))
465  {
466  foreach ($fieldlist as $key=>$val)
467  {
468  if (GETPOST($val) != '')
469  $obj->$val=GETPOST($val);
470  }
471  }
472 
473  $tmpaction = 'create';
474  $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
475  $reshook=$hookmanager->executeHooks('createDictionaryFieldlist',$parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
476  $error=$hookmanager->error; $errors=$hookmanager->errors;
477 
478  if (empty($reshook))
479  {
480  fieldListJournal($fieldlist,$obj,$tabname[$id],'add');
481  }
482 
483  print '<td colspan="4" align="right">';
484  print '<input type="submit" class="button" name="actionadd" value="'.$langs->trans("Add").'">';
485  print '</td>';
486  print "</tr>";
487 
488  print '<tr><td colspan="7">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
489  }
490 
491 
492 
493  // List of available record in database
494  dol_syslog("htdocs/admin/dict", LOG_DEBUG);
495  $resql=$db->query($sql);
496  if ($resql)
497  {
498  $num = $db->num_rows($resql);
499  $i = 0;
500 
501  $param = '&id='.$id;
502  if ($search_country_id > 0) $param.= '&search_country_id='.$search_country_id;
503  $paramwithsearch = $param;
504  if ($sortorder) $paramwithsearch.= '&sortorder='.$sortorder;
505  if ($sortfield) $paramwithsearch.= '&sortfield='.$sortfield;
506  if (GETPOST('from', 'alpha')) $paramwithsearch.= '&from='.GETPOST('from','alpha');
507 
508  // There is several pages
509  if ($num > $listlimit)
510  {
511  print '<tr class="none"><td align="right" colspan="'.(3+count($fieldlist)).'">';
512  print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page+1).'</span></li>');
513  print '</td></tr>';
514  }
515 
516  // Title line with search boxes
517  print '<tr class="liste_titre_filter liste_titre_add">';
518  print '<td class="liste_titre"></td>';
519  print '<td class="liste_titre"></td>';
520  print '<td class="liste_titre"></td>';
521  print '<td class="liste_titre"></td>';
522  print '<td class="liste_titre"></td>';
523  print '<td class="liste_titre"></td>';
524  print '<td class="liste_titre" align="center">';
525  if ($filterfound)
526  {
527  $searchpicto=$form->showFilterAndCheckAddButtons(0);
528  print $searchpicto;
529  }
530  print '</td>';
531  print '</tr>';
532 
533  // Title of lines
534  print '<tr class="liste_titre">';
535  foreach ($fieldlist as $field => $value)
536  {
537  // Determine le nom du champ par rapport aux noms possibles
538  // dans les dictionnaires de donnees
539  $showfield=1; // By defaut
540  $align="left";
541  $sortable=1;
542  $valuetoshow='';
543  /*
544  $tmparray=getLabelOfField($fieldlist[$field]);
545  $showfield=$tmp['showfield'];
546  $valuetoshow=$tmp['valuetoshow'];
547  $align=$tmp['align'];
548  $sortable=$tmp['sortable'];
549  */
550  $valuetoshow=ucfirst($fieldlist[$field]); // By defaut
551  $valuetoshow=$langs->trans($valuetoshow); // try to translate
552  if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
553  if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') { $valuetoshow=$langs->trans("Label"); }
554  if ($fieldlist[$field]=='nature') { $valuetoshow=$langs->trans("Nature"); }
555 
556  // Affiche nom du champ
557  if ($showfield)
558  {
559  print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable?$fieldlist[$field]:''), ($page?'page='.$page.'&':''), $param, "align=".$align, $sortfield, $sortorder);
560  }
561  }
562  print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page?'page='.$page.'&':''), $param, 'align="center"', $sortfield, $sortorder);
566  print '</tr>';
567 
568  if ($num)
569  {
570  // Lines with values
571  while ($i < $num)
572  {
573  $obj = $db->fetch_object($resql);
574  //print_r($obj);
575  print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
576  if ($action == 'edit' && ($rowid == (! empty($obj->rowid)?$obj->rowid:$obj->code)))
577  {
578  $tmpaction='edit';
579  $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
580  $reshook=$hookmanager->executeHooks('editDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
581  $error=$hookmanager->error; $errors=$hookmanager->errors;
582 
583  // Show fields
584  if (empty($reshook)) fieldListJournal($fieldlist,$obj,$tabname[$id],'edit');
585 
586  print '<td align="center" colspan="4">';
587  print '<input type="hidden" name="page" value="'.$page.'">';
588  print '<input type="hidden" name="rowid" value="'.$rowid.'">';
589  print '<input type="submit" class="button" name="actionmodify" value="'.$langs->trans("Modify").'">';
590  print '<input type="submit" class="button" name="actioncancel" value="'.$langs->trans("Cancel").'">';
591  print '<div name="'.(! empty($obj->rowid)?$obj->rowid:$obj->code).'"></div>';
592  print '</td>';
593  }
594  else
595  {
596  $tmpaction = 'view';
597  $parameters=array('var'=>$var, 'fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
598  $reshook=$hookmanager->executeHooks('viewDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
599 
600  $error=$hookmanager->error; $errors=$hookmanager->errors;
601 
602  if (empty($reshook))
603  {
604  $langs->load("accountancy");
605  foreach ($fieldlist as $field => $value)
606  {
607 
608  $showfield=1;
609  $align="left";
610  $valuetoshow=$obj->{$fieldlist[$field]};
611  if ($valuetoshow=='all') {
612  $valuetoshow=$langs->trans('All');
613  }
614  else if ($fieldlist[$field]=='nature' && $tabname[$id]==MAIN_DB_PREFIX.'accounting_journal') {
615  $key=$langs->trans("AccountingJournalType".strtoupper($obj->nature));
616  $valuetoshow=($obj->nature && $key != "AccountingJournalType".strtoupper($langs->trans($obj->nature))?$key:$obj->{$fieldlist[$field]});
617  }
618  else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'accounting_journal') {
619  $valuetoshow=$langs->trans($obj->label);
620  }
621 
622  $class='tddict';
623  // Show value for field
624  if ($showfield) print '<!-- '.$fieldlist[$field].' --><td align="'.$align.'" class="'.$class.'">'.$valuetoshow.'</td>';
625  }
626  }
627 
628  // Can an entry be erased or disabled ?
629  $iserasable=1;$canbedisabled=1;$canbemodified=1; // true by default
630  if (isset($obj->code) && $id != 10)
631  {
632  if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i',$obj->code))) { $iserasable = 0; $canbedisabled = 0; }
633  else if ($obj->code == 'RECEP') { $iserasable = 0; $canbedisabled = 0; }
634  else if ($obj->code == 'EF0') { $iserasable = 0; $canbedisabled = 0; }
635  }
636 
637  $canbemodified=$iserasable;
638 
639  $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):'');
640  if ($param) $url .= '&'.$param;
641  $url.='&';
642 
643  // Active
644  print '<td align="center" class="nowrap">';
645  if ($canbedisabled) print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
646  else print $langs->trans("AlwaysActive");
647  print "</td>";
648 
649  // Modify link
650  if ($canbemodified) print '<td align="center"><a class="reposition" href="'.$url.'action=edit">'.img_edit().'</a></td>';
651  else print '<td>&nbsp;</td>';
652 
653  // Delete link
654  if ($iserasable)
655  {
656  print '<td align="center">';
657  if ($user->admin) print '<a href="'.$url.'action=delete">'.img_delete().'</a>';
658  //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
659  print '</td>';
660  }
661  else print '<td>&nbsp;</td>';
662 
663  print '<td></td>';
664 
665  print '</td>';
666  }
667 
668  print "</tr>\n";
669  $i++;
670  }
671  }
672  }
673  else {
674  dol_print_error($db);
675  }
676 
677  print '</table>';
678  print '</div>';
679 
680  print '</form>';
681 }
682 
683 print '<br>';
684 
685 // End of page
686 llxFooter();
687 $db->close();
688 
689 
699 function fieldListJournal($fieldlist, $obj='', $tabname='', $context='')
700 {
701  global $conf,$langs,$db;
702  global $form, $mysoc;
703  global $region_id;
704  global $elementList,$sourceList,$localtax_typeList;
705  global $bc;
706 
707  $formadmin = new FormAdmin($db);
708  $formcompany = new FormCompany($db);
709 
710  foreach ($fieldlist as $field => $value)
711  {
712  if ($fieldlist[$field] == 'nature')
713  {
714  print '<td>';
715  print $form->selectarray('nature', $sourceList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
716  print '</td>';
717  }
718  elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
719  print '<td><input type="text" class="flat minwidth100" value="'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'"></td>';
720  }
721  else
722  {
723  print '<td>';
724  $size=''; $class='';
725  if ($fieldlist[$field]=='code') $class='maxwidth100';
726  if ($fieldlist[$field]=='label') $class='quatrevingtpercent';
727  if ($fieldlist[$field]=='sortorder' || $fieldlist[$field]=='sens' || $fieldlist[$field]=='category_type') $size='size="2" ';
728  print '<input type="text" '.$size.'class="flat'.($class?' '.$class:'').'" value="'.(isset($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
729  print '</td>';
730  }
731  }
732 }
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
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_edit($titlealt='default', $float=0, $other='class="pictoedit"')
Show logo editer/modifier fiche.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
img_delete($titlealt='default', $other='class="pictodelete"')
Show delete logo.
Class to generate html code for admin pages.
Class to build HTML component for third parties management Only common components are here...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
print_fleche_navigation($page, $file, $options='', $nextpage=0, $betweenarrows='', $afterarrows='', $limit=-1, $totalnboflines=0, $hideselectlimit=0)
Function to show navigation arrows into lists.
complete_dictionary_with_modules(&$taborder, &$tabname, &$tablib, &$tabsql, &$tabsqlsort, &$tabfield, &$tabfieldvalue, &$tabfieldinsert, &$tabrowid, &$tabcond, &$tabhelp, &$tabfieldcheck)
Add external modules to list of dictionaries.
Definition: admin.lib.php:1088
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='')
Get title line of an array.
llxHeader()
Empty header.
Definition: wrapper.php:44
fieldListJournal($fieldlist, $obj='', $tabname='', $context='')
Show fields in insert/edit mode.
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;...