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