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