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