dolibarr 25.0.0-alpha
journals_list.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017-2024 Alexandre Spangaro <aspangaro@easya.solutions>
3 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 *
19 */
20
27if (!defined('CSRFCHECK_WITH_TOKEN')) {
28 define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
29}
30
31// Load Dolibarr environment
32require '../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
40
49// Load translation files required by the page
50$langs->loadLangs(array("admin", "compta", "accountancy"));
51
52$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view';
53$confirm = GETPOST('confirm', 'alpha');
54$id = 35;
55$rowid = GETPOST('rowid', 'alpha');
56$code = GETPOST('code', 'alpha');
57
58// Security access
59if (!$user->hasRight('accounting', 'chartofaccount')) {
61}
62
63$acts = array();
64$acts[0] = "activate";
65$acts[1] = "disable";
66$actl = array();
67$actl[0] = img_picto($langs->trans("Disabled"), 'switch_off', 'class="size15x"');
68$actl[1] = img_picto($langs->trans("Activated"), 'switch_on', 'class="size15x"');
69
70$listoffset = GETPOST('listoffset', 'alpha');
71$listlimit = GETPOSTINT('listlimit') > 0 ? GETPOSTINT('listlimit') : 1000;
72$active = 1;
73
74$sortfield = GETPOST('sortfield', 'aZ09comma');
75$sortorder = GETPOST('sortorder', 'aZ09comma');
76$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
77if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
78 // If $page is not defined, or '' or -1 or if we click on clear filters
79 $page = 0;
80}
81$offset = $listlimit * $page;
82$pageprev = $page - 1;
83$pagenext = $page + 1;
84if (empty($sortfield)) {
85 $sortfield = 'code';
86}
87if (empty($sortorder)) {
88 $sortorder = 'ASC';
89}
90
91$error = 0;
92
93$search_country_id = GETPOST('search_country_id', 'int');
94
95// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
96$hookmanager->initHooks(array('admin'));
97
98// This page is a generic page to edit dictionaries
99// Put here declaration of dictionaries properties
100
101// Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this.
102$taborder = array(35);
103
104// Name of SQL tables of dictionaries
105$tabname = array();
106$tabname[35] = MAIN_DB_PREFIX."accounting_journal";
107
108// Dictionary labels
109$tablib = array();
110$tablib[35] = "DictionaryAccountancyJournal";
111
112// Requests to extract data
113$tabsql = array();
114$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";
115
116// Criteria to sort dictionaries
117$tabsqlsort = array();
118$tabsqlsort[35] = "code ASC";
119
120// Name of the fields in the result of select to display the dictionary
121$tabfield = array();
122$tabfield[35] = "code,label,nature";
123
124// Name of editing fields for record modification
125$tabfieldvalue = array();
126$tabfieldvalue[35] = "code,label,nature";
127
128// Name of the fields in the table for inserting a record
129$tabfieldinsert = array();
130$tabfieldinsert[35] = "code,label,nature";
131
132// Nom du rowid si le champ n'est pas de type autoincrement
133// Example: "" if id field is "rowid" and has autoincrement on
134// "nameoffield" if id field is not "rowid" or has not autoincrement on
135$tabrowid = array();
136$tabrowid[35] = "";
137
138// Condition to show dictionary in setup page
139$tabcond = array();
140$tabcond[35] = isModEnabled('accounting');
141
142// List of help for fields
143$tabhelp = array();
144$tabhelp[35] = array('code' => $langs->trans("EnterAnyCode"));
145
146// List of check for fields (NOT USED YET)
147$tabfieldcheck = array();
148$tabfieldcheck[35] = array();
149
150// Complete all arrays with entries found into modules
151complete_dictionary_with_modules($taborder, $tabname, $tablib, $tabsql, $tabsqlsort, $tabfield, $tabfieldvalue, $tabfieldinsert, $tabrowid, $tabcond, $tabhelp, $tabfieldcheck);
152
153
154// Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
155$elementList = array();
156// Must match ids defined into eldy.lib.php
157$sourceList = array(
158 '1' => $langs->trans('AccountingJournalType1'),
159 '2' => $langs->trans('AccountingJournalType2'),
160 '3' => $langs->trans('AccountingJournalType3'),
161 '4' => $langs->trans('AccountingJournalType4'),
162 '5' => $langs->trans('AccountingJournalType5'),
163 '8' => $langs->trans('AccountingJournalType8'),
164 '9' => $langs->trans('AccountingJournalType9'),
165);
166
167if (getDolGlobalInt('ACCOUNTING_DISSOCIATE_CASH_SALES')) {
168 $sourceList['6'] = $langs->trans('AccountingJournalType6');
169}
170
171/*
172 * Actions
173 */
174
175if (GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter_x', 'alpha')) {
176 $search_country_id = '';
177}
178
179// Actions add or modify an entry into a dictionary
180if (GETPOST('actionadd', 'alpha') || GETPOST('actionmodify', 'alpha')) {
181 $listfield = explode(',', str_replace(' ', '', $tabfield[$id]));
182 $listfieldinsert = explode(',', $tabfieldinsert[$id]);
183 $listfieldmodify = explode(',', $tabfieldinsert[$id]);
184 $listfieldvalue = explode(',', $tabfieldvalue[$id]);
185
186 // Check that all fields are filled
187 $ok = 1;
188
189 // Other checks
190 if (GETPOSTISSET("code")) {
191 if (GETPOST("code") == '0') {
192 $ok = 0;
193 setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
194 }
195 }
196 if (!GETPOST('label', 'alpha')) {
197 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
198 $ok = 0;
199 }
200
201 // In case of 'actionadd' and with valid parameters, add the line
202 if ($ok && GETPOST('actionadd', 'alpha')) {
203 $newid = 0; // Initialise before if for static analysis
204 if ($tabrowid[$id]) {
205 // Get free id for insert
206 $sql = "SELECT MAX(".$db->sanitize($tabrowid[$id]).") newid FROM ".$db->sanitize($tabname[$id]);
207 $result = $db->query($sql);
208 if ($result) {
209 $obj = $db->fetch_object($result);
210 $newid = ($obj->newid + 1);
211 } else {
212 dol_print_error($db);
213 }
214 }
215
216 // Add new entry
217 $sql = "INSERT INTO ".$db->sanitize($tabname[$id])." (";
218 // List of fields
219 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
220 $sql .= $tabrowid[$id].",";
221 }
222 $sql .= $db->sanitize($tabfieldinsert[$id]);
223 $sql .= ",active,entity)";
224 $sql .= " VALUES(";
225
226 // List of values
227 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
228 $sql .= ((int) $newid).",";
229 }
230 $i = 0;
231 foreach ($listfieldinsert as $f => $value) {
232 if ($i) {
233 $sql .= ",";
234 }
235 if (GETPOST($listfieldvalue[$i]) == '') {
236 $sql .= "null"; // For vat, we want/accept code = ''
237 } else {
238 $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
239 }
240 $i++;
241 }
242 $sql .= ",1,".((int) $conf->entity).")";
243
244 dol_syslog("actionadd", LOG_DEBUG);
245 $result = $db->query($sql);
246 if ($result) { // Add is ok
247 setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
248 $_POST = array('id' => $id); // Clean $_POST array, we keep only id
249 } else {
250 if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
251 setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
252 } else {
253 dol_print_error($db);
254 }
255 }
256 }
257
258 // If check ok and action modify, we modify the line
259 if ($ok && GETPOST('actionmodify', 'alpha')) {
260 if ($tabrowid[$id]) {
261 $rowidcol = $tabrowid[$id];
262 } else {
263 $rowidcol = "rowid";
264 }
265
266 // Modify entry
267 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET ";
268 // Modify the field values
269 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
270 $sql .= $db->sanitize($tabrowid[$id])." = ";
271 $sql .= "'".$db->escape($rowid)."', ";
272 }
273 $i = 0;
274 foreach ($listfieldmodify as $field) {
275 if ($i) {
276 $sql .= ",";
277 }
278 $sql .= $field." = ";
279 $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
280 $i++;
281 }
282 $sql .= " WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
283 $sql .= " AND entity = ".((int) $conf->entity);
284
285 dol_syslog("actionmodify", LOG_DEBUG);
286 //print $sql;
287 $resql = $db->query($sql);
288 if (!$resql) {
289 setEventMessages($db->error(), null, 'errors');
290 }
291 }
292}
293
294if ($action == 'confirm_delete' && $confirm == 'yes') { // delete
295 if ($tabrowid[$id]) {
296 $rowidcol = $tabrowid[$id];
297 } else {
298 $rowidcol = "rowid";
299 }
300
301 $sql = "DELETE from ".$db->sanitize($tabname[$id])." WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
302 $sql .= " AND entity = ".((int) $conf->entity);
303
304 dol_syslog("delete", LOG_DEBUG);
305 $result = $db->query($sql);
306 if (!$result) {
307 if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
308 setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
309 } else {
310 dol_print_error($db);
311 }
312 }
313}
314
315// activate
316if ($action == $acts[0]) {
317 $sql = '';
318 if ($tabrowid[$id]) {
319 $rowidcol = $tabrowid[$id];
320 } else {
321 $rowidcol = "rowid";
322 }
323
324 if ($rowid) {
325 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 1 WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
326 } elseif ($code) {
327 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 1 WHERE code = '".$db->escape($code)."'";
328 }
329 $sql .= " AND entity = ".((int) $conf->entity);
330
331 $result = $db->query($sql);
332 if (!$result) {
333 dol_print_error($db);
334 }
335}
336
337// disable
338if ($action == $acts[1]) {
339 $sql = '';
340 if ($tabrowid[$id]) {
341 $rowidcol = $tabrowid[$id];
342 } else {
343 $rowidcol = "rowid";
344 }
345
346 if ($rowid) {
347 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 0 WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
348 } elseif ($code) {
349 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 0 WHERE code='".$db->escape($code)."'";
350 }
351 $sql .= " AND entity = ".((int) $conf->entity);
352
353 $result = $db->query($sql);
354 if (!$result) {
355 dol_print_error($db);
356 }
357}
358
359
360/*
361 * View
362 */
363
364$form = new Form($db);
365$formadmin = new FormAdmin($db);
366
367$title = $langs->trans('AccountingJournals');
368$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
369llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-accountancy page-admin_journals_list');
370
371$titre = $langs->trans("DictionarySetup");
372$linkback = '';
373
374$titre .= ' - '.$langs->trans($tablib[$id]);
375$titlepicto = 'title_accountancy';
376
377print load_fiche_titre($titre, $linkback, $titlepicto);
378
379
380// Generate a form to confirm the deletion of the row
381if ($action == 'delete') {
382 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);
383}
384
385/*
386 * Show a dictionary
387 */
388
389// Complete the search query with sort criteria
390$sql = $tabsql[$id];
391$sql .= " WHERE a.entity = ".((int) $conf->entity);
392
393// If sort order is "country", we use country_code instead
394if ($sortfield == 'country') {
395 $sortfield = 'country_code';
396}
397$sql .= $db->order($sortfield, $sortorder);
398$sql .= $db->plimit($listlimit + 1, $offset);
399
400$fieldlist = explode(',', $tabfield[$id]);
401
402print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
403print '<input type="hidden" name="token" value="'.newToken().'">';
404print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
405
406print '<div class="div-table-responsive">';
407print '<table class="noborder centpercent">';
408
409// Form to add a new line
410if ($tabname[$id]) {
411 $fieldlist = explode(',', $tabfield[$id]);
412
413 // Line for title
414 print '<tr class="liste_titre">';
415 foreach ($fieldlist as $field => $value) {
416 // Determine the field name based on the possible names
417 // in the data dictionaries.
418 $valuetoshow = ucfirst($fieldlist[$field]); // By default
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])) {
434 print '<a href="'.$tabhelp[$id][$value].'">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
435 } elseif (!empty($tabhelp[$id][$value])) {
436 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
437 } else {
438 print $valuetoshow;
439 }
440 print '</td>';
441 }
442 }
443
444 print '<td>';
445 print '<input type="hidden" name="id" value="'.$id.'">';
446 print '</td>';
447 print '<td></td>';
448 print '<td></td>';
449 print '<td></td>';
450 print '</tr>';
451
452 // Line to enter new values
453 print '<tr class="oddeven nodrag nodrop nohover">';
454
455 $obj = new stdClass();
456 // If data was already input, we define them in obj to populate input fields.
457 if (GETPOST('actionadd', 'alpha')) {
458 foreach ($fieldlist as $key => $val) {
459 if (GETPOST($val) != '') {
460 $obj->$val = GETPOST($val);
461 }
462 }
463 }
464
465 $tmpaction = 'create';
466 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
467 $reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
468 $error = $hookmanager->error;
469 $errors = $hookmanager->errors;
470
471 if (empty($reshook)) {
472 fieldListJournal($fieldlist, $obj, $tabname[$id], 'add');
473 }
474
475 print '<td colspan="4" class="right">';
476 print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'">';
477 print '</td>';
478 print "</tr>";
479
480 print '<tr><td colspan="7">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
481}
482
483
484
485// List of available record in database
486dol_syslog("htdocs/admin/dict", LOG_DEBUG);
487$resql = $db->query($sql);
488if ($resql) {
489 $num = $db->num_rows($resql);
490 $i = 0;
491
492 $param = '&id='.((int) $id);
493 if ($search_country_id > 0) {
494 $param .= '&search_country_id='.urlencode((string) ($search_country_id));
495 }
496 $paramwithsearch = $param;
497 $paramwithsearch .= '&sortorder='.$sortorder;
498 $paramwithsearch .= '&sortfield='.$sortfield;
499
500 if (GETPOST('from', 'alpha')) {
501 $paramwithsearch .= '&from='.GETPOST('from', 'alpha');
502 }
503
504 // There is several pages
505 if ($num > $listlimit) {
506 print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).'">';
507 print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit ? 1 : 0), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
508 print '</td></tr>';
509 }
510
511 // Title line with search boxes
512 /*print '<tr class="liste_titre_filter liste_titre_add">';
513 print '<td class="liste_titre"></td>';
514 print '<td class="liste_titre"></td>';
515 print '<td class="liste_titre"></td>';
516 print '<td class="liste_titre"></td>';
517 print '<td class="liste_titre"></td>';
518 print '<td class="liste_titre"></td>';
519 print '<td class="liste_titre center">';
520 $searchpicto=$form->showFilterButtons();
521 print $searchpicto;
522 print '</td>';
523 print '</tr>';
524 */
525
526 // Title of lines
527 print '<tr class="liste_titre liste_titre_add">';
528 foreach ($fieldlist as $field => $value) {
529 // Determine the field name based on the possible names
530 // in the data dictionaries.
531 $class = "left";
532 $valuetoshow = '';
533 /*
534 $tmparray=getLabelOfField($fieldlist[$field]);
535 $valuetoshow=$tmp['valuetoshow'];
536 $align=$tmp['align'];
537 $sortable=$tmp['sortable'];
538 */
539 $valuetoshow = ucfirst($fieldlist[$field]); // By default
540 $valuetoshow = $langs->trans($valuetoshow); // try to translate
541 if ($fieldlist[$field] == 'code') {
542 $valuetoshow = $langs->trans("Code");
543 }
544 if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
545 $valuetoshow = $langs->trans("Label");
546 }
547 if ($fieldlist[$field] == 'nature') {
548 $valuetoshow = $langs->trans("NatureOfJournal");
549 }
550
551 // Affiche nom du champ
552 print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], $fieldlist[$field], ($page ? 'page='.$page.'&' : ''), $param, "", $sortfield, $sortorder, $class.' ');
553 }
554 print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
555 print getTitleFieldOfList('');
556 print getTitleFieldOfList('');
557 print getTitleFieldOfList('');
558 print '</tr>';
559
560 if ($num) {
561 // Lines with values
562 while ($i < $num) {
563 $obj = $db->fetch_object($resql);
564 //print_r($obj);
565 print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
566 if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
567 $tmpaction = 'edit';
568 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
569 $reshook = $hookmanager->executeHooks('editDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
570 $error = $hookmanager->error;
571 $errors = $hookmanager->errors;
572
573 // Show fields
574 if (empty($reshook)) {
575 fieldListJournal($fieldlist, $obj, $tabname[$id], 'edit');
576 }
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 button-edit" 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('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;
591 $errors = $hookmanager->errors;
592
593 if (empty($reshook)) {
594 $langs->load("accountancy");
595 foreach ($fieldlist as $field => $value) {
596 $class = "left";
597 $tmpvar = $fieldlist[$field];
598 $valuetoshow = $obj->$tmpvar;
599 if ($valuetoshow == 'all') {
600 $valuetoshow = $langs->trans('All');
601 } elseif ($fieldlist[$field] == 'nature' && $tabname[$id] == MAIN_DB_PREFIX.'accounting_journal') {
602 $key = $langs->trans("AccountingJournalType".strtoupper($obj->nature));
603 $valuetoshow = ($obj->nature && $key != "AccountingJournalType".strtoupper($langs->trans($obj->nature)) ? $key : $obj->{$fieldlist[$field]});
604 } elseif ($fieldlist[$field] == 'label' && $tabname[$id] == MAIN_DB_PREFIX.'accounting_journal') {
605 $valuetoshow = $langs->trans($obj->label);
606 }
607
608 $class = 'tddict';
609 // Show value for field
610 print '<!-- '.$fieldlist[$field].' --><td class="'.$class.'">'.dol_escape_htmltag($valuetoshow).'</td>';
611 }
612 }
613
614 // Can an entry be erased or disabled ?
615 $iserasable = 1;
616 $canbedisabled = 1;
617 $canbemodified = 1; // true by default
618 if (isset($obj->code)) {
619 if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i', $obj->code))) {
620 $iserasable = 0;
621 $canbedisabled = 0;
622 }
623 }
624
625 $canbemodified = $iserasable;
626
627 $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) : '');
628 $url .= '&'.$param;
629 $url .= '&';
630
631 // Active
632 print '<td class="nowrap center">';
633 if ($canbedisabled) {
634 print '<a href="'.$url.'action='.$acts[$obj->active].'&token='.newToken().'">'.$actl[$obj->active].'</a>';
635 } else {
636 print $langs->trans("AlwaysActive");
637 }
638 print "</td>";
639
640 // Modify link
641 if ($canbemodified) {
642 print '<td class="center"><a class="reposition editfielda" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a></td>';
643 } else {
644 print '<td>&nbsp;</td>';
645 }
646
647 // Delete link
648 if ($iserasable) {
649 print '<td class="center">';
650 if ($user->admin) {
651 print '<a href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a>';
652 }
653 //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
654 print '</td>';
655 } else {
656 print '<td>&nbsp;</td>';
657 }
658
659 print '<td></td>';
660
661 print '</td>';
662 }
663
664 print "</tr>\n";
665 $i++;
666 }
667 }
668} else {
669 dol_print_error($db);
670}
671
672print '</table>';
673print '</div>';
674
675print '</form>';
676
677
678print '<br>';
679
680// End of page
681llxFooter();
682$db->close();
683
684
694function fieldListJournal($fieldlist, $obj = null, $tabname = '', $context = '')
695{
696 global $conf, $langs, $db;
697 global $form, $mysoc;
698 global $region_id;
699 global $elementList, $sourceList, $localtax_typeList;
700 global $bc;
701
702 $formadmin = new FormAdmin($db);
703 $formcompany = new FormCompany($db);
704
705 foreach ($fieldlist as $field => $value) {
706 if ($fieldlist[$field] == 'nature') {
707 print '<td>';
708 print $form->selectarray('nature', $sourceList, (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : ''));
709 print '</td>';
710 } elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
711 print '<td><input type="text" class="flat minwidth100" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" name="'.$fieldlist[$field].'"></td>';
712 } else {
713 print '<td>';
714 $size = '';
715 $class = '';
716 if ($fieldlist[$field] == 'code') {
717 $class = 'maxwidth100';
718 }
719 if ($fieldlist[$field] == 'label') {
720 $class = 'quatrevingtpercent';
721 }
722 if ($fieldlist[$field] == 'sortorder' || $fieldlist[$field] == 'sens' || $fieldlist[$field] == 'category_type') {
723 $size = 'size="2" ';
724 }
725 print '<input type="text" '.$size.'class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" name="'.$fieldlist[$field].'">';
726 print '</td>';
727 }
728 }
729}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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.
$context
@method int call_trigger(string $triggerName, ?User $user)
Definition command.php:209
global $mysoc
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
print_fleche_navigation($page, $file, $options='', $nextpage=0, $betweenarrows='', $afterarrows='', $limit=-1, $totalnboflines=0, $selectlimitsuffix='', $beforearrows='', $hidenavigation=0)
Function to show navigation arrows into lists.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
fieldListJournal($fieldlist, $obj=null, $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.