dolibarr 25.0.0-alpha
report_list.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2024-2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
3 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 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
26// Load Dolibarr environment
27require '../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancyreport.class.php';
35
44// Load translation files required by the page
45$langs->loadLangs(array("admin", "companies"));
46
47$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view';
48$confirm = GETPOST('confirm', 'alpha');
49$id = 45;
50$rowid = GETPOST('rowid', 'alpha');
51$code = GETPOST('code', 'alpha');
52
53// Security access
54if (!$user->hasRight('accounting', 'chartofaccount')) {
56}
57
58$acts = array();
59$acts[0] = "activate";
60$acts[1] = "disable";
61$actl = array();
62$actl[0] = img_picto($langs->trans("Disabled"), 'switch_off', 'class="size15x"');
63$actl[1] = img_picto($langs->trans("Activated"), 'switch_on', 'class="size15x"');
64
65$listoffset = GETPOST('listoffset', 'alpha');
66$listlimit = GETPOSTINT('listlimit') > 0 ? GETPOSTINT('listlimit') : 1000;
67
68$sortfield = GETPOST("sortfield", 'aZ09comma');
69$sortorder = GETPOST("sortorder", 'aZ09comma');
70$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
71if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
72 // If $page is not defined, or '' or -1 or if we click on clear filters
73 $page = 0;
74}
75$offset = $listlimit * $page;
76$pageprev = $page - 1;
77$pagenext = $page + 1;
78
79$search_country_id = GETPOST('search_country_id', 'int');
80
81// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an 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(45);
89
90// Name of SQL tables of dictionaries
91$tabname = array();
92$tabname[45] = MAIN_DB_PREFIX."c_accounting_report";
93
94// Dictionary labels
95$tablib = array();
96$tablib[45] = "DictionaryAccountancyReport";
97
98// Requests to extract data
99$tabsql = array();
100$tabsql[45] = "SELECT r.rowid as rowid, r.code as code, r.label, r.fk_country as country_id, c.code as country_code, c.label as country, r.active FROM ".MAIN_DB_PREFIX."c_accounting_report as r, ".MAIN_DB_PREFIX."c_country as c WHERE r.fk_country = c.rowid and c.active=1";
101
102// Criteria to sort dictionaries
103$tabsqlsort = array();
104$tabsqlsort[45] = "code ASC";
105
106// Name of the fields in the result of select to display the dictionary
107$tabfield = array();
108$tabfield[45] = "code,label,country";
109
110// Name of editing fields for record modification
111$tabfieldvalue = array();
112$tabfieldvalue[45] = "code,label,country_id";
113
114// Name of the fields in the table for inserting a record
115$tabfieldinsert = array();
116$tabfieldinsert[45] = "code,label,fk_country";
117
118// Name of the rowid if the field is not of 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[45] = "";
123
124// Condition to show dictionary in setup page
125$tabcond = array();
126$tabcond[45] = isModEnabled('accounting');
127
128// List of help for fields
129$tabhelp = array();
130$tabhelp[45] = array('code' => $langs->trans("EnterAnyCode"));
131
132// List of check for fields (NOT USED YET)
133$tabfieldcheck = array();
134$tabfieldcheck[45] = array();
135
136// Complete all arrays with entries found into modules
137complete_dictionary_with_modules($taborder, $tabname, $tablib, $tabsql, $tabsqlsort, $tabfield, $tabfieldvalue, $tabfieldinsert, $tabrowid, $tabcond, $tabhelp, $tabfieldcheck);
138
139$accountingreport = new AccountancyReport($db);
140
141
142/*
143 * Actions
144 */
145
146if (GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter_x', 'alpha')) {
147 $search_country_id = '';
148}
149
150// Actions add or modify an entry into a dictionary
151if (GETPOST('actionadd', 'alpha') || GETPOST('actionmodify', 'alpha')) {
152 $listfield = explode(',', str_replace(' ', '', $tabfield[$id]));
153 $listfieldinsert = explode(',', $tabfieldinsert[$id]);
154 $listfieldmodify = explode(',', $tabfieldinsert[$id]);
155 $listfieldvalue = explode(',', $tabfieldvalue[$id]);
156
157 // Check that all fields are filled
158 $ok = 1;
159 foreach ($listfield as $f => $value) {
160 if (($value == 'country' || $value == 'country_id') && GETPOST('country_id')) {
161 continue;
162 }
163 if (!GETPOSTISSET($value) || GETPOST($value) == '') {
164 $ok = 0;
165 $fieldnamekey = $listfield[$f];
166 // We take translate key of field
167 if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) {
168 $fieldnamekey = 'Label';
169 }
170 if ($fieldnamekey == 'code') {
171 $fieldnamekey = 'Code';
172 }
173 if ($fieldnamekey == 'country') {
174 $fieldnamekey = 'Country';
175 }
176
177 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
178 }
179 }
180 if (GETPOSTISSET("code")) {
181 if (GETPOST("code") == '0') {
182 $ok = 0;
183 setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
184 }
185 }
186
187 // In case of 'actionadd' and with valid parameters, add the line
188 if ($ok && GETPOST('actionadd', 'alpha')) {
189 $newid = 0;
190
191 if ($tabrowid[$id]) {
192 // Get free id for insert
193 $sql = "SELECT MAX(".$db->sanitize($tabrowid[$id]).") newid FROM ".$db->sanitize($tabname[$id]);
194 $result = $db->query($sql);
195 if ($result) {
196 $obj = $db->fetch_object($result);
197 $newid = ($obj->newid + 1);
198 } else {
199 dol_print_error($db);
200 }
201 }
202
203 // Add new entry
204 $sql = "INSERT INTO ".$db->sanitize($tabname[$id])." (";
205 // List of fields
206 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
207 $sql .= $db->sanitize($tabrowid[$id]).",";
208 }
209 $sql .= $db->sanitize($tabfieldinsert[$id]);
210 $sql .= ",active)";
211 $sql .= " VALUES(";
212
213 // List of values
214 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
215 $sql .= ((int) $newid).",";
216 }
217 $i = 0;
218 foreach ($listfieldinsert as $f => $value) {
219 if ($value == 'entity') {
220 $_POST[$listfieldvalue[$i]] = $conf->entity;
221 }
222 if ($i) {
223 $sql .= ",";
224 }
225 if (GETPOST($listfieldvalue[$i]) == '' && !$listfieldvalue[$i] == 'formula') {
226 $sql .= "null"; // For vat, we want/accept code = ''
227 } else {
228 $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
229 }
230 $i++;
231 }
232 $sql .= ",1)";
233
234 dol_syslog("actionadd", LOG_DEBUG);
235 $result = $db->query($sql);
236 if ($result) { // Add is ok
237 setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
238 $_POST = array('id' => $id); // Clean $_POST array, we keep only
239 } else {
240 if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
241 $langs->load('errors');
242 setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
243 } else {
244 dol_print_error($db);
245 }
246 }
247 }
248
249 // If check ok and action modify, we modify the line
250 if ($ok && GETPOST('actionmodify', 'alpha')) {
251 if ($tabrowid[$id]) {
252 $rowidcol = $tabrowid[$id];
253 } else {
254 $rowidcol = "rowid";
255 }
256
257 // Modify entry
258 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET ";
259 // Modify field values
260 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
261 $sql .= $db->sanitize($tabrowid[$id])." = ";
262 $sql .= "'".$db->escape($rowid)."', ";
263 }
264 $i = 0;
265 foreach ($listfieldmodify as $field) {
266 if ($field == 'fk_country' && GETPOST('country') > 0) {
267 $_POST[$listfieldvalue[$i]] = GETPOST('country');
268 } elseif ($field == 'entity') {
269 $_POST[$listfieldvalue[$i]] = $conf->entity;
270 }
271 if ($i) {
272 $sql .= ",";
273 }
274 $sql .= $field."=";
275 if (GETPOST($listfieldvalue[$i]) == '' && !$listfieldvalue[$i] == 'range_account') {
276 $sql .= "null"; // For range_account, we want/accept code = ''
277 } else {
278 $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
279 }
280 $i++;
281 }
282 $sql .= " WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
283
284 dol_syslog("actionmodify", LOG_DEBUG);
285 //print $sql;
286 $resql = $db->query($sql);
287 if (!$resql) {
288 setEventMessages($db->error(), null, 'errors');
289 }
290 }
291}
292
293if ($action == 'confirm_delete' && $confirm == 'yes') { // delete
294 $rowidcol = "rowid";
295
296 $sql = "DELETE from ".$db->sanitize($tabname[$id])." WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
297
298 dol_syslog("delete", LOG_DEBUG);
299 $result = $db->query($sql);
300 if (!$result) {
301 if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
302 setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
303 } else {
304 dol_print_error($db);
305 }
306 }
307}
308
309// activate
310if ($action == $acts[0]) {
311 $sql = '';
312 $rowidcol = "rowid";
313
314 if ($rowid) {
315 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 1 WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
316 } elseif ($code) {
317 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 1 WHERE code = '".$db->escape($code)."'";
318 }
319
320 if ($sql) {
321 $result = $db->query($sql);
322 if (!$result) {
323 dol_print_error($db);
324 }
325 }
326}
327
328// disable
329if ($action == $acts[1]) {
330 $sql = '';
331 $rowidcol = "rowid";
332
333 if ($rowid) {
334 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 0 WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
335 } elseif ($code) {
336 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 0 WHERE code = '".$db->escape($code)."'";
337 }
338
339 if ($sql) {
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$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
355
356llxHeader('', $langs->trans('DictionaryAccountancyCategory'), $help_url, '', 0, 0, '', '', '', 'mod-accountancy page-admin_categories_list');
357
358$titre = $langs->trans($tablib[$id]);
359$linkback = '';
360$titlepicto = 'setup';
361
362print load_fiche_titre($titre, $linkback, $titlepicto);
363
364print '<span class="opacitymedium">'.$langs->trans("AccountingAccountReportsDesc", $langs->transnoentitiesnoconv("ByPersonalizedAccountGroups")).'</span><br><br>';
365
366// Confirmation of the deletion of the line
367if ($action == 'delete') {
368 print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$code.'&id='.$id.($search_country_id > 0 ? '&search_country_id='.$search_country_id : ''), $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1);
369}
370
371// Complete search query with sorting criteria
372$sql = $tabsql[$id];
373
374if ($search_country_id > 0) {
375 if (preg_match('/ WHERE /', $sql)) {
376 $sql .= " AND ";
377 } else {
378 $sql .= " WHERE ";
379 }
380 $sql .= " (r.fk_country = ".((int) $search_country_id)." OR r.fk_country = 0)";
381}
382
383// If sort order is "country", we use country_code instead
384if ($sortfield == 'country') {
385 $sortfield = 'country_code';
386}
387
388$sql .= $db->order($sortfield, $sortorder);
389$sql .= $db->plimit($listlimit + 1, $offset);
390
391
392$fieldlist = explode(',', $tabfield[$id]);
393
394$param = '&id='.$id;
395if ($search_country_id > 0) {
396 $param .= '&search_country_id='.urlencode((string) ($search_country_id));
397}
398$paramwithsearch = $param;
399if ($sortorder) {
400 $paramwithsearch .= '&sortorder='.urlencode($sortorder);
401}
402if ($sortfield) {
403 $paramwithsearch .= '&sortfield='.urlencode($sortfield);
404}
405if (GETPOST('from', 'alpha')) {
406 $paramwithsearch .= '&from='.urlencode(GETPOST('from', 'alpha'));
407}
408if ($listlimit) {
409 $paramwithsearch .= '&listlimit='.urlencode((string) (GETPOSTINT('listlimit')));
410}
411print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
412print '<input type="hidden" name="token" value="'.newToken().'">';
413print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
414print '<input type="hidden" name="sortfield" value="'.dol_escape_htmltag($sortfield).'">';
415print '<input type="hidden" name="sortorder" value="'.dol_escape_htmltag($sortorder).'">';
416
417
418print '<div class="div-table-responsive-no-min">';
419print '<table class="noborder centpercent">';
420
421// Form to add a new line
422if ($tabname[$id]) {
423 $fieldlist = explode(',', $tabfield[$id]);
424
425 // Line for title
426 print '<tr class="liste_titre">';
427 // Action column
428 if ($conf->main_checkbox_left_column) {
429 print '<td></td>';
430 }
431 foreach ($fieldlist as $field => $value) {
432 // Determine the field name based on the possible names
433 // in the data dictionaries.
434 $valuetoshow = ucfirst($fieldlist[$field]); // By default
435 $valuetoshow = $langs->trans($valuetoshow); // try to translate
436 $class = "left";
437 if ($fieldlist[$field] == 'code') {
438 $valuetoshow = $langs->trans("Code");
439 $class = 'width75';
440 }
441 if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
442 $valuetoshow = $langs->trans("Label");
443 }
444 if ($fieldlist[$field] == 'country') {
445 $valuetoshow = $langs->trans("Country");
446 }
447
448 if ($valuetoshow != '') {
449 print '<td class="'.$class.'">';
450 if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
451 print '<a href="'.$tabhelp[$id][$value].'">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
452 } elseif (!empty($tabhelp[$id][$value])) {
453 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
454 } else {
455 print $valuetoshow;
456 }
457 print '</td>';
458 }
459 }
460
461 print '<td>';
462 print '<input type="hidden" name="id" value="'.$id.'">';
463 print '</td>';
464 print '<td></td>';
465 // Action column
466 if (!$conf->main_checkbox_left_column) {
467 print '<td></td>';
468 }
469 print '</tr>';
470
471 // Line to enter new values
472 print '<tr class="oddeven nodrag nodrop nohover">';
473
474 // Action column
475 if ($conf->main_checkbox_left_column) {
476 print '<td></td>';
477 }
478
479 $obj = new stdClass();
480 // If data was already input, we define them in obj to populate input fields.
481 if (GETPOST('actionadd', 'alpha')) {
482 foreach ($fieldlist as $key => $val) {
483 if (GETPOST($val) != '') {
484 $obj->$val = GETPOST($val);
485 }
486 }
487 }
488
489 $tmpaction = 'create';
490 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
491 $reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
492 $error = $hookmanager->error;
493 $errors = $hookmanager->errors;
494
495 if (empty($reshook)) {
496 fieldListAccountingReport($fieldlist, $obj, $tabname[$id], 'add');
497 }
498
499 print '<td colspan="2" class="right">';
500 print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'">';
501 print '</td>';
502
503 // Action column
504 if (!$conf->main_checkbox_left_column) {
505 print '<td></td>';
506 }
507
508 print "</tr>";
509
510 $colspan = count($fieldlist) + 3;
511 if ($id == 45) {
512 $colspan++;
513 }
514}
515
516print '</table>';
517print '</div>';
518
519print '<div class="div-table-responsive">';
520print '<table class="noborder centpercent">';
521
522// List of available record in database
523dol_syslog("htdocs/accountancy/admin/categories_list.php", LOG_DEBUG);
524
525$resql = $db->query($sql);
526if ($resql) {
527 $num = $db->num_rows($resql);
528 $i = 0;
529
530 // There is several pages
531 if ($num > $listlimit) {
532 print '<tr class="none"><td class="right" colspan="'.(2 + count($fieldlist)).'">';
533 print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit ? 1 : 0), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
534 print '</td></tr>';
535 }
536
537 $filterfound = 0;
538 foreach ($fieldlist as $field => $value) {
539 $showfield = 1; // By default
540 if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
541 $showfield = 0;
542 }
543 if ($showfield) {
544 if ($value == 'country') {
545 $filterfound++;
546 }
547 }
548 }
549
550 // Title line with search boxes
551 print '<tr class="liste_titre liste_titre_filter">';
552
553 // Action column
554 if ($conf->main_checkbox_left_column) {
555 print '<td class="liste_titre center">';
556 if ($filterfound) {
557 $searchpicto = $form->showFilterAndCheckAddButtons(0);
558 print $searchpicto;
559 }
560 print '</td>';
561 }
562
563 $filterfound = 0;
564 foreach ($fieldlist as $field => $value) {
565 $showfield = 1; // By default
566
567 if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
568 $showfield = 0;
569 }
570
571 if ($showfield) {
572 if ($value == 'country') {
573 print '<td class="liste_titre">';
574 print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth150 maxwidthonsmartphone');
575 print '</td>';
576 $filterfound++;
577 } else {
578 print '<td class="liste_titre"></td>';
579 }
580 }
581 }
582 print '<td class="liste_titre"></td>';
583 // Action column
584 if (!$conf->main_checkbox_left_column) {
585 print '<td class="liste_titre center">';
586 if ($filterfound) {
587 $searchpicto = $form->showFilterAndCheckAddButtons(0);
588 print $searchpicto;
589 }
590 print '</td>';
591 }
592 print '</tr>';
593
594 // Title of lines
595 print '<tr class="liste_titre">';
596 // Action column
597 if ($conf->main_checkbox_left_column) {
598 print getTitleFieldOfList('');
599 }
600 foreach ($fieldlist as $field => $value) {
601 // Determines the name of the field in relation to the possible names
602 // in data dictionaries
603 $showfield = 1; // By default
604 $class = "left";
605 $sortable = 1;
606 $valuetoshow = '';
607
608 $valuetoshow = ucfirst($fieldlist[$field]); // By default
609 $valuetoshow = $langs->trans($valuetoshow); // try to translate
610 if ($fieldlist[$field] == 'code') {
611 $valuetoshow = $langs->trans("Code");
612 }
613 if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
614 $valuetoshow = $langs->trans("Label");
615 }
616 if ($fieldlist[$field] == 'country') {
617 $valuetoshow = $langs->trans("Country");
618 }
619 if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
620 $showfield = 0;
621 }
622 // Affiche nom du champ
623 if ($showfield) {
624 print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable ? $fieldlist[$field] : ''), ($page ? 'page='.$page.'&' : ''), $param, "", $sortfield, $sortorder, $class.' ');
625 }
626 }
627 print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
628 // Action column
629 if (!$conf->main_checkbox_left_column) {
630 print getTitleFieldOfList('');
631 }
632 print '</tr>';
633
634
635 if ($num) {
636 $imaxinloop = ($listlimit ? min($num, $listlimit) : $num);
637
638 // Lines with values
639 while ($i < $imaxinloop) {
640 $obj = $db->fetch_object($resql);
641
642 //print_r($obj);
643 print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
644 if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
645 $tmpaction = 'edit';
646 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
647 $reshook = $hookmanager->executeHooks('editDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
648 $error = $hookmanager->error;
649 $errors = $hookmanager->errors;
650
651 // Actions
652 if ($conf->main_checkbox_left_column) {
653 print '<td></td>';
654 }
655
656 // Show fields
657 if (empty($reshook)) {
658 fieldListAccountingReport($fieldlist, $obj, $tabname[$id], 'edit');
659 }
660
661 print '<td class="center">';
662 print '<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'"></div>';
663 print '<input type="hidden" name="page" value="'.$page.'">';
664 print '<input type="hidden" name="rowid" value="'.$rowid.'">';
665 print '<input type="submit" class="button button-edit smallpaddingimp" name="actionmodify" value="'.$langs->trans("Modify").'">';
666 print '<input type="submit" class="button button-cancel smallpaddingimp" name="actioncancel" value="'.$langs->trans("Cancel").'">';
667 print '</td>';
668 // Actions
669 if (!$conf->main_checkbox_left_column) {
670 print '<td></td>';
671 }
672 } else {
673 // Can an entry be erased or disabled ?
674 $iserasable = 1;
675 $canbedisabled = 1;
676 $canbemodified = 1; // true by default
677 if (isset($obj->code)) {
678 if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i', $obj->code))) {
679 $iserasable = 0;
680 $canbedisabled = 0;
681 }
682 }
683 $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) : '');
684 $url .= '&'.$param;
685 $url .= '&';
686
687 $canbemodified = $iserasable;
688
689 $tmpaction = 'view';
690 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
691 $reshook = $hookmanager->executeHooks('viewDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
692
693 $error = $hookmanager->error;
694 $errors = $hookmanager->errors;
695
696 // Actions
697 if ($conf->main_checkbox_left_column) {
698 print '<td class="center">';
699 if ($canbemodified) {
700 print '<a class="reposition editfielda marginleftonly marginrightonly" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a>';
701 }
702 if ($iserasable) {
703 if ($user->admin) {
704 print '<a class="marginleftonly marginrightonly" href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a>';
705 }
706 }
707 print '</td>';
708 }
709
710 if (empty($reshook)) {
711 foreach ($fieldlist as $field => $value) {
712 $showfield = 1;
713 $title = '';
714 $class = 'tddict';
715
716 $tmpvar = $fieldlist[$field];
717 $valuetoshow = $obj->$tmpvar;
718 if ($valuetoshow == 'all') {
719 $valuetoshow = $langs->trans('All');
720 } elseif ($fieldlist[$field] == 'country') {
721 if (empty($obj->country_code)) {
722 $valuetoshow = '-';
723 } else {
724 $key = $langs->trans("Country".strtoupper($obj->country_code));
725 $valuetoshow = ($key != "Country".strtoupper($obj->country_code) ? $obj->country_code." - ".$key : $obj->country);
726 }
727 } elseif (in_array($fieldlist[$field], array('label'))) {
728 $class = "tdoverflowmax250";
729 $title = $valuetoshow;
730 } elseif ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
731 $showfield = 0;
732 }
733
734 // Show value for field
735 if ($showfield) {
736 print '<!-- '.$fieldlist[$field].' --><td class="'.$class.'"'.($title ? ' title="'.dol_escape_htmltag($title).'"' : '').'>'.dol_escape_htmltag($valuetoshow).'</td>';
737 }
738 }
739 }
740
741 // Active
742 print '<td class="center" class="nowrap">';
743 if ($canbedisabled) {
744 print '<a class="reposition" href="'.$url.'action='.$acts[$obj->active].'&token='.newToken().'">'.$actl[$obj->active].'</a>';
745 } else {
746 print $langs->trans("AlwaysActive");
747 }
748 print "</td>";
749
750 // Actions
751 if (!$conf->main_checkbox_left_column) {
752 print '<td class="center">';
753 if ($canbemodified) {
754 print '<a class="reposition editfielda paddingleft marginleftonly marginrightonly paddingright" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a>';
755 }
756 if ($iserasable) {
757 if ($user->admin) {
758 print '<a class="paddingleft marginleftonly marginrightonly paddingright" href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a>';
759 }
760 }
761 print '</td>';
762 }
763 }
764 print "</tr>\n";
765 $i++;
766 }
767 } else {
768 $colspan = 10;
769 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</td></tr>';
770 }
771} else {
772 dol_print_error($db);
773}
774
775print '</table>';
776print '</div>';
777
778print '</form>';
779
780print '<br>';
781
782// End of page
783llxFooter();
784$db->close();
785
786
796function fieldListAccountingReport($fieldlist, $obj = null, $tabname = '', $context = '')
797{
798 global $form, $mysoc;
799
800 foreach ($fieldlist as $field => $value) {
801 if ($fieldlist[$field] == 'country') {
802 print '<td>';
803 $fieldname = 'country';
804 if ($context == 'add') {
805 $fieldname = 'country_id';
806 $preselectcountrycode = GETPOSTISSET('country_id') ? GETPOSTINT('country_id') : $mysoc->country_code;
807 print $form->select_country($preselectcountrycode, $fieldname, '', 28, 'maxwidth150 maxwidthonsmartphone');
808 } else {
809 $preselectcountrycode = (empty($obj->country_code) ? (empty($obj->country) ? $mysoc->country_code : $obj->country) : $obj->country_code);
810 print $form->select_country($preselectcountrycode, $fieldname, '', 28, 'maxwidth150 maxwidthonsmartphone');
811 }
812 print '</td>';
813 } elseif ($fieldlist[$field] == 'country_id') {
814 if (!in_array('country', $fieldlist)) { // If there is already a field country, we don't show country_id (avoid duplicate)
815 $country_id = (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
816 print '<td>';
817 print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">';
818 print '</td>';
819 }
820 } elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
821 print '<td><input type="text" class="flat minwidth100" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" name="'.$fieldlist[$field].'"></td>';
822 } else {
823 print '<td>';
824 $class = '';
825 if (in_array($fieldlist[$field], array('label'))) {
826 $class = 'maxwidth150';
827 }
828 print '<input type="text" class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" name="'.$fieldlist[$field].'">';
829 print '</td>';
830 }
831 }
832}
$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 manage reports for accounting categories.
Class to generate html code for admin pages.
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
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
fieldListAccountingReport($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.