dolibarr  7.0.0-beta
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 
24 require '../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
32 
33 $langs->load("admin");
34 $langs->load("compta");
35 $langs->load("accountancy");
36 
37 $action=GETPOST('action','alpha')?GETPOST('action','alpha'):'view';
38 $confirm=GETPOST('confirm','alpha');
39 $id=GETPOST('id','int');
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');
55 $listlimit=GETPOST('listlimit')>0?GETPOST('listlimit'):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  '9' => $langs->trans('AccountingJournalType9')
139  );
140 
141 /*
142  * Actions
143  */
144 
145 if (GETPOST('button_removefilter') || GETPOST('button_removefilter.x') || GETPOST('button_removefilter_x'))
146 {
147  $search_country_id = '';
148 }
149 
150 // Actions add or modify an entry into a dictionary
151 if (GETPOST('actionadd') || GETPOST('actionmodify'))
152 {
153  $listfield=explode(',', str_replace(' ', '',$tabfield[$id]));
154  $listfieldinsert=explode(',',$tabfieldinsert[$id]);
155  $listfieldmodify=explode(',',$tabfieldinsert[$id]);
156  $listfieldvalue=explode(',',$tabfieldvalue[$id]);
157 
158  // Check that all fields are filled
159  $ok=1;
160  foreach ($listfield as $f => $value)
161  {
162  if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) $fieldnamekey='Label';
163  if ($fieldnamekey == 'code') $fieldnamekey = 'Code';
164  if ($fieldnamekey == 'nature') $fieldnamekey = 'Nature';
165  }
166  // Other checks
167  if (isset($_POST["code"]))
168  {
169  if ($_POST["code"]=='0')
170  {
171  $ok=0;
172  setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
173  }
174  /*if (!is_numeric($_POST['code'])) // disabled, code may not be in numeric base
175  {
176  $ok = 0;
177  $msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).'<br>';
178  }*/
179  }
180 
181  // Clean some parameters
182  if ($_POST["accountancy_code"] <= 0) $_POST["accountancy_code"]=''; // If empty, we force to null
183  if ($_POST["accountancy_code_sell"] <= 0) $_POST["accountancy_code_sell"]=''; // If empty, we force to null
184  if ($_POST["accountancy_code_buy"] <= 0) $_POST["accountancy_code_buy"]=''; // If empty, we force to null
185 
186  // Si verif ok et action add, on ajoute la ligne
187  if ($ok && GETPOST('actionadd'))
188  {
189  if ($tabrowid[$id])
190  {
191  // Recupere id libre pour insertion
192  $newid=0;
193  $sql = "SELECT max(".$tabrowid[$id].") newid from ".$tabname[$id];
194  $result = $db->query($sql);
195  if ($result)
196  {
197  $obj = $db->fetch_object($result);
198  $newid=($obj->newid + 1);
199 
200  } else {
201  dol_print_error($db);
202  }
203  }
204 
205  // Add new entry
206  $sql = "INSERT INTO ".$tabname[$id]." (";
207  // List of fields
208  if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
209  $sql.= $tabrowid[$id].",";
210  $sql.= $tabfieldinsert[$id];
211  $sql.=",active)";
212  $sql.= " VALUES(";
213 
214  // List of values
215  if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
216  $sql.= $newid.",";
217  $i=0;
218  foreach ($listfieldinsert as $f => $value)
219  {
220  if ($value == 'entity') {
221  $_POST[$listfieldvalue[$i]] = $conf->entity;
222  }
223  if ($i) $sql.=",";
224  if ($_POST[$listfieldvalue[$i]] == '' && ! ($listfieldvalue[$i] == 'code' && $id == 10)) $sql.="null"; // For vat, we want/accept code = ''
225  else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
226  $i++;
227  }
228  $sql.=",1)";
229 
230  dol_syslog("actionadd", LOG_DEBUG);
231  $result = $db->query($sql);
232  if ($result) // Add is ok
233  {
234  setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
235  $_POST=array('id'=>$id); // Clean $_POST array, we keep only
236  }
237  else
238  {
239  if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
240  setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
241  }
242  else {
243  dol_print_error($db);
244  }
245  }
246  }
247 
248  // Si verif ok et action modify, on modifie la ligne
249  if ($ok && GETPOST('actionmodify'))
250  {
251  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
252  else { $rowidcol="rowid"; }
253 
254  // Modify entry
255  $sql = "UPDATE ".$tabname[$id]." SET ";
256  // Modifie valeur des champs
257  if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldmodify))
258  {
259  $sql.= $tabrowid[$id]."=";
260  $sql.= "'".$db->escape($rowid)."', ";
261  }
262  $i = 0;
263  foreach ($listfieldmodify as $field)
264  {
265  if ($field == 'price' || preg_match('/^amount/i',$field) || $field == 'taux') {
266  $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU');
267  }
268  else if ($field == 'entity') {
269  $_POST[$listfieldvalue[$i]] = $conf->entity;
270  }
271  if ($i) $sql.=",";
272  $sql.= $field."=";
273  if ($_POST[$listfieldvalue[$i]] == '' && ! ($listfieldvalue[$i] == 'code' && $id == 10)) $sql.="null"; // For vat, we want/accept code = ''
274  else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
275  $i++;
276  }
277  $sql.= " WHERE ".$rowidcol." = '".$rowid."'";
278 
279  dol_syslog("actionmodify", LOG_DEBUG);
280  //print $sql;
281  $resql = $db->query($sql);
282  if (! $resql)
283  {
284  setEventMessages($db->error(), null, 'errors');
285  }
286  }
287  //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
288 }
289 
290 if (GETPOST('actioncancel'))
291 {
292  //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
293 }
294 
295 if ($action == 'confirm_delete' && $confirm == 'yes') // delete
296 {
297  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
298  else { $rowidcol="rowid"; }
299 
300  $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol."='".$rowid."'";
301 
302  dol_syslog("delete", LOG_DEBUG);
303  $result = $db->query($sql);
304  if (! $result)
305  {
306  if ($db->errno() == 'DB_ERROR_CHILD_EXISTS')
307  {
308  setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
309  }
310  else
311  {
312  dol_print_error($db);
313  }
314  }
315 }
316 
317 // activate
318 if ($action == $acts[0])
319 {
320  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
321  else { $rowidcol="rowid"; }
322 
323  if ($rowid) {
324  $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'";
325  }
326  elseif ($code) {
327  $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$code."'";
328  }
329 
330  $result = $db->query($sql);
331  if (!$result)
332  {
333  dol_print_error($db);
334  }
335 }
336 
337 // disable
338 if ($action == $acts[1])
339 {
340  if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
341  else { $rowidcol="rowid"; }
342 
343  if ($rowid) {
344  $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'";
345  }
346  elseif ($code) {
347  $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$code."'";
348  }
349 
350  $result = $db->query($sql);
351  if (!$result)
352  {
353  dol_print_error($db);
354  }
355 }
356 
357 
358 /*
359  * View
360  */
361 
362 $form = new Form($db);
363 $formadmin=new FormAdmin($db);
364 
365 llxHeader();
366 
367 $titre=$langs->trans("DictionarySetup");
368 $linkback='';
369 if ($id)
370 {
371  $titre.=' - '.$langs->trans($tablib[$id]);
372  $titlepicto='title_accountancy';
373 }
374 
375 print load_fiche_titre($titre,$linkback,$titlepicto);
376 
377 
378 // Confirmation de la suppression de la ligne
379 if ($action == 'delete')
380 {
381  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);
382 }
383 //var_dump($elementList);
384 
385 /*
386  * Show a dictionary
387  */
388 if ($id)
389 {
390  // Complete requete recherche valeurs avec critere de tri
391  $sql=$tabsql[$id];
392 
393  if ($search_country_id > 0)
394  {
395  if (preg_match('/ WHERE /',$sql)) $sql.= " AND ";
396  else $sql.=" WHERE ";
397  $sql.= " c.rowid = ".$search_country_id;
398  }
399 
400  if ($sortfield)
401  {
402  // If sort order is "country", we use country_code instead
403  if ($sortfield == 'country') $sortfield='country_code';
404  $sql.= " ORDER BY ".$sortfield;
405  if ($sortorder)
406  {
407  $sql.=" ".strtoupper($sortorder);
408  }
409  $sql.=", ";
410  // Clear the required sort criteria for the tabsqlsort to be able to force it with selected value
411  $tabsqlsort[$id]=preg_replace('/([a-z]+\.)?'.$sortfield.' '.$sortorder.',/i','',$tabsqlsort[$id]);
412  $tabsqlsort[$id]=preg_replace('/([a-z]+\.)?'.$sortfield.',/i','',$tabsqlsort[$id]);
413  }
414  else {
415  $sql.=" ORDER BY ";
416  }
417  $sql.=$tabsqlsort[$id];
418  $sql.=$db->plimit($listlimit+1,$offset);
419  //print $sql;
420 
421  $fieldlist=explode(',',$tabfield[$id]);
422 
423  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
424  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
425  print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from','alpha')).'">';
426 
427  print '<div class="div-table-responsive">';
428  print '<table class="noborder" width="100%">';
429 
430  // Form to add a new line
431  if ($tabname[$id])
432  {
433  $alabelisused=0;
434  $var=false;
435 
436  $fieldlist=explode(',',$tabfield[$id]);
437 
438  // Line for title
439  print '<tr class="liste_titre">';
440  foreach ($fieldlist as $field => $value)
441  {
442  // Determine le nom du champ par rapport aux noms possibles
443  // dans les dictionnaires de donnees
444  $valuetoshow=ucfirst($fieldlist[$field]); // Par defaut
445  $valuetoshow=$langs->trans($valuetoshow); // try to translate
446  $align="left";
447  if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
448  if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label')
449  {
450  $valuetoshow=$langs->trans("Label");
451  }
452  if ($fieldlist[$field]=='nature') { $valuetoshow=$langs->trans("Nature"); }
453 
454  if ($valuetoshow != '')
455  {
456  print '<td align="'.$align.'">';
457  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>';
458  else if (! empty($tabhelp[$id][$value])) print $form->textwithpicto($valuetoshow,$tabhelp[$id][$value]);
459  else print $valuetoshow;
460  print '</td>';
461  }
462  if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') $alabelisused=1;
463  }
464 
465  print '<td>';
466  print '<input type="hidden" name="id" value="'.$id.'">';
467  print '</td>';
468  print '<td style="min-width: 26px;"></td>';
469  print '<td style="min-width: 26px;"></td>';
470  print '<td style="min-width: 26px;"></td>';
471  print '</tr>';
472 
473  // Line to enter new values
474  print '<tr class="oddeven nodrag nodrap nohover">';
475 
476  $obj = new stdClass();
477  // If data was already input, we define them in obj to populate input fields.
478  if (GETPOST('actionadd'))
479  {
480  foreach ($fieldlist as $key=>$val)
481  {
482  if (GETPOST($val) != '')
483  $obj->$val=GETPOST($val);
484  }
485  }
486 
487  $tmpaction = 'create';
488  $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
489  $reshook=$hookmanager->executeHooks('createDictionaryFieldlist',$parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
490  $error=$hookmanager->error; $errors=$hookmanager->errors;
491 
492  if (empty($reshook))
493  {
494  fieldListJournal($fieldlist,$obj,$tabname[$id],'add');
495  }
496 
497  print '<td colspan="4" align="right">';
498  print '<input type="submit" class="button" name="actionadd" value="'.$langs->trans("Add").'">';
499  print '</td>';
500  print "</tr>";
501 
502  print '<tr><td colspan="7">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
503  }
504 
505 
506 
507  // List of available record in database
508  dol_syslog("htdocs/admin/dict", LOG_DEBUG);
509  $resql=$db->query($sql);
510  if ($resql)
511  {
512  $num = $db->num_rows($resql);
513  $i = 0;
514  $var=true;
515 
516  $param = '&id='.$id;
517  if ($search_country_id > 0) $param.= '&search_country_id='.$search_country_id;
518  $paramwithsearch = $param;
519  if ($sortorder) $paramwithsearch.= '&sortorder='.$sortorder;
520  if ($sortfield) $paramwithsearch.= '&sortfield='.$sortfield;
521  if (GETPOST('from')) $paramwithsearch.= '&from='.GETPOST('from','alpha');
522 
523  // There is several pages
524  if ($num > $listlimit)
525  {
526  print '<tr class="none"><td align="right" colspan="'.(3+count($fieldlist)).'">';
527  print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page+1).'</span></li>');
528  print '</td></tr>';
529  }
530 
531  // Title line with search boxes
532  print '<tr class="liste_titre_filter liste_titre_add">';
533  print '<td class="liste_titre"></td>';
534  print '<td class="liste_titre"></td>';
535  print '<td class="liste_titre"></td>';
536  print '<td class="liste_titre"></td>';
537  print '<td class="liste_titre"></td>';
538  print '<td class="liste_titre"></td>';
539  print '<td class="liste_titre" align="center">';
540  if ($filterfound)
541  {
542  $searchpicto=$form->showFilterAndCheckAddButtons(0);
543  print $searchpicto;
544  }
545  print '</td>';
546  print '</tr>';
547 
548  // Title of lines
549  print '<tr class="liste_titre">';
550  foreach ($fieldlist as $field => $value)
551  {
552  // Determine le nom du champ par rapport aux noms possibles
553  // dans les dictionnaires de donnees
554  $showfield=1; // By defaut
555  $align="left";
556  $sortable=1;
557  $valuetoshow='';
558  /*
559  $tmparray=getLabelOfField($fieldlist[$field]);
560  $showfield=$tmp['showfield'];
561  $valuetoshow=$tmp['valuetoshow'];
562  $align=$tmp['align'];
563  $sortable=$tmp['sortable'];
564  */
565  $valuetoshow=ucfirst($fieldlist[$field]); // By defaut
566  $valuetoshow=$langs->trans($valuetoshow); // try to translate
567  if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
568  if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') { $valuetoshow=$langs->trans("Label"); }
569  if ($fieldlist[$field]=='nature') { $valuetoshow=$langs->trans("Nature"); }
570 
571  // Affiche nom du champ
572  if ($showfield)
573  {
574  print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable?$fieldlist[$field]:''), ($page?'page='.$page.'&':''), $param, "align=".$align, $sortfield, $sortorder);
575  }
576  }
577  print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page?'page='.$page.'&':''), $param, 'align="center"', $sortfield, $sortorder);
581  print '</tr>';
582 
583  if ($num)
584  {
585  // Lines with values
586  while ($i < $num)
587  {
588  $obj = $db->fetch_object($resql);
589  //print_r($obj);
590  print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
591  if ($action == 'edit' && ($rowid == (! empty($obj->rowid)?$obj->rowid:$obj->code)))
592  {
593  $tmpaction='edit';
594  $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
595  $reshook=$hookmanager->executeHooks('editDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
596  $error=$hookmanager->error; $errors=$hookmanager->errors;
597 
598  // Show fields
599  if (empty($reshook)) fieldListJournal($fieldlist,$obj,$tabname[$id],'edit');
600 
601  print '<td align="center" colspan="4">';
602  print '<input type="hidden" name="page" value="'.$page.'">';
603  print '<input type="hidden" name="rowid" value="'.$rowid.'">';
604  print '<input type="submit" class="button" name="actionmodify" value="'.$langs->trans("Modify").'">';
605  print '<input type="submit" class="button" name="actioncancel" value="'.$langs->trans("Cancel").'">';
606  print '<div name="'.(! empty($obj->rowid)?$obj->rowid:$obj->code).'"></div>';
607  print '</td>';
608  }
609  else
610  {
611  $tmpaction = 'view';
612  $parameters=array('var'=>$var, 'fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
613  $reshook=$hookmanager->executeHooks('viewDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
614 
615  $error=$hookmanager->error; $errors=$hookmanager->errors;
616 
617  if (empty($reshook))
618  {
619  foreach ($fieldlist as $field => $value)
620  {
621 
622  $showfield=1;
623  $align="left";
624  $valuetoshow=$obj->{$fieldlist[$field]};
625  if ($valuetoshow=='all') {
626  $valuetoshow=$langs->trans('All');
627  }
628  else if ($fieldlist[$field]=='nature' && $tabname[$id]==MAIN_DB_PREFIX.'accounting_journal') {
629  $langs->load("accountancy");
630  $key=$langs->trans("AccountingJournalType".strtoupper($obj->nature));
631  $valuetoshow=($obj->nature && $key != "AccountingJournalType".strtoupper($obj->nature)?$key:$obj->{$fieldlist[$field]});
632  }
633 
634  $class='tddict';
635  // Show value for field
636  if ($showfield) print '<!-- '.$fieldlist[$field].' --><td align="'.$align.'" class="'.$class.'">'.$valuetoshow.'</td>';
637  }
638  }
639 
640  // Can an entry be erased or disabled ?
641  $iserasable=1;$canbedisabled=1;$canbemodified=1; // true by default
642  if (isset($obj->code) && $id != 10)
643  {
644  if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i',$obj->code))) { $iserasable = 0; $canbedisabled = 0; }
645  else if ($obj->code == 'RECEP') { $iserasable = 0; $canbedisabled = 0; }
646  else if ($obj->code == 'EF0') { $iserasable = 0; $canbedisabled = 0; }
647  }
648 
649  $canbemodified=$iserasable;
650 
651  $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):'');
652  if ($param) $url .= '&'.$param;
653  $url.='&';
654 
655  // Active
656  print '<td align="center" class="nowrap">';
657  if ($canbedisabled) print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
658  else
659  {
660  if (in_array($obj->code, array('AC_OTH','AC_OTH_AUTO'))) print $langs->trans("AlwaysActive");
661  else if (isset($obj->type) && in_array($obj->type, array('systemauto')) && empty($obj->active)) print $langs->trans("Deprecated");
662  else if (isset($obj->type) && in_array($obj->type, array('system')) && ! empty($obj->active) && $obj->code != 'AC_OTH') print $langs->trans("UsedOnlyWithTypeOption");
663  else print $langs->trans("AlwaysActive");
664  }
665  print "</td>";
666 
667  // Modify link
668  if ($canbemodified) print '<td align="center"><a class="reposition" href="'.$url.'action=edit">'.img_edit().'</a></td>';
669  else print '<td>&nbsp;</td>';
670 
671  // Delete link
672  if ($iserasable)
673  {
674  print '<td align="center">';
675  if ($user->admin) print '<a href="'.$url.'action=delete">'.img_delete().'</a>';
676  //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
677  print '</td>';
678  }
679  else print '<td>&nbsp;</td>';
680 
681  print '<td></td>';
682 
683  print '</td>';
684  }
685 
686  print "</tr>\n";
687  $i++;
688  }
689  }
690  }
691  else {
692  dol_print_error($db);
693  }
694 
695  print '</table>';
696  print '</div>';
697 
698  print '</form>';
699 }
700 
701 print '<br>';
702 
703 
704 llxFooter();
705 $db->close();
706 
707 
717 function fieldListJournal($fieldlist, $obj='', $tabname='', $context='')
718 {
719  global $conf,$langs,$db;
720  global $form, $mysoc;
721  global $region_id;
722  global $elementList,$sourceList,$localtax_typeList;
723  global $bc;
724 
725  $formadmin = new FormAdmin($db);
726  $formcompany = new FormCompany($db);
727 
728  foreach ($fieldlist as $field => $value)
729  {
730  if ($fieldlist[$field] == 'nature')
731  {
732  print '<td>';
733  print $form->selectarray('nature', $sourceList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
734  print '</td>';
735  }
736  elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
737  print '<td><input type="text" class="flat minwidth100" value="'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'"></td>';
738  }
739  else
740  {
741  print '<td>';
742  $size=''; $class='';
743  if ($fieldlist[$field]=='code') $class='maxwidth100';
744  if ($fieldlist[$field]=='label') $class='quatrevingtpercent';
745  if ($fieldlist[$field]=='sortorder' || $fieldlist[$field]=='sens' || $fieldlist[$field]=='category_type') $size='size="2" ';
746  print '<input type="text" '.$size.'class="flat'.($class?' '.$class:'').'" value="'.(isset($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
747  print '</td>';
748  }
749  }
750 }
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.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to generate html code for admin pages.
Class to build HTML component for third parties management Only common components are here...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
print_fleche_navigation($page, $file, $options='', $nextpage=0, $betweenarrows='', $afterarrows='', $limit=-1, $totalnboflines=0, $hideselectlimit=0)
Function to show navigation arrows into lists.
complete_dictionary_with_modules(&$taborder, &$tabname, &$tablib, &$tabsql, &$tabsqlsort, &$tabfield, &$tabfieldvalue, &$tabfieldinsert, &$tabrowid, &$tabcond, &$tabhelp, &$tabfieldcheck)
Add external modules to list of dictionaries.
Definition: admin.lib.php:1032
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='')
Get title line of an array.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
img_delete($titlealt= 'default', $other= 'class="pictodelete"')
Show delete logo.
fieldListJournal($fieldlist, $obj='', $tabname='', $context='')
Show fields in insert/edit mode.
print
Draft customers invoices.
Definition: index.php:91
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
img_edit($titlealt= 'default', $float=0, $other= 'class="pictoedit"')
Show logo editer/modifier fiche.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...