dolibarr 24.0.0-beta
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("errors", "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 {
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 .= $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 setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
242 } else {
244 }
245 }
246 }
247
248 // If check ok and action modify, we modify the line
249 if ($ok && GETPOST('actionmodify', 'alpha')) {
250 if ($tabrowid[$id]) {
251 $rowidcol = $tabrowid[$id];
252 } else {
253 $rowidcol = "rowid";
254 }
255
256 // Modify entry
257 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET ";
258 // Modify field values
259 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
260 $sql .= $db->sanitize($tabrowid[$id])." = ";
261 $sql .= "'".$db->escape($rowid)."', ";
262 }
263 $i = 0;
264 foreach ($listfieldmodify as $field) {
265 if ($field == 'fk_country' && GETPOST('country') > 0) {
266 $_POST[$listfieldvalue[$i]] = GETPOST('country');
267 } elseif ($field == 'entity') {
268 $_POST[$listfieldvalue[$i]] = $conf->entity;
269 }
270 if ($i) {
271 $sql .= ",";
272 }
273 $sql .= $field."=";
274 if (GETPOST($listfieldvalue[$i]) == '' && !$listfieldvalue[$i] == 'range_account') {
275 $sql .= "null"; // For range_account, we want/accept code = ''
276 } else {
277 $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
278 }
279 $i++;
280 }
281 $sql .= " WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
282
283 dol_syslog("actionmodify", LOG_DEBUG);
284 //print $sql;
285 $resql = $db->query($sql);
286 if (!$resql) {
287 setEventMessages($db->error(), null, 'errors');
288 }
289 }
290}
291
292if ($action == 'confirm_delete' && $confirm == 'yes') { // delete
293 $rowidcol = "rowid";
294
295 $sql = "DELETE from ".$db->sanitize($tabname[$id])." WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
296
297 dol_syslog("delete", LOG_DEBUG);
298 $result = $db->query($sql);
299 if (!$result) {
300 if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
301 setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
302 } else {
304 }
305 }
306}
307
308// activate
309if ($action == $acts[0]) {
310 $sql = '';
311 $rowidcol = "rowid";
312
313 if ($rowid) {
314 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 1 WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
315 } elseif ($code) {
316 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 1 WHERE code = '".$db->escape($code)."'";
317 }
318
319 if ($sql) {
320 $result = $db->query($sql);
321 if (!$result) {
323 }
324 }
325}
326
327// disable
328if ($action == $acts[1]) {
329 $sql = '';
330 $rowidcol = "rowid";
331
332 if ($rowid) {
333 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 0 WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
334 } elseif ($code) {
335 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 0 WHERE code = '".$db->escape($code)."'";
336 }
337
338 if ($sql) {
339 $result = $db->query($sql);
340 if (!$result) {
342 }
343 }
344}
345
346/*
347 * View
348 */
349
350$form = new Form($db);
351$formadmin = new FormAdmin($db);
352
353$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
354
355llxHeader('', $langs->trans('DictionaryAccountancyCategory'), $help_url, '', 0, 0, '', '', '', 'mod-accountancy page-admin_categories_list');
356
357$titre = $langs->trans($tablib[$id]);
358$linkback = '';
359$titlepicto = 'setup';
360
361print load_fiche_titre($titre, $linkback, $titlepicto);
362
363print '<span class="opacitymedium">'.$langs->trans("AccountingAccountReportsDesc", $langs->transnoentitiesnoconv("ByPersonalizedAccountGroups")).'</span><br><br>';
364
365// Confirmation of the deletion of the line
366if ($action == 'delete') {
367 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);
368}
369
370// Complete search query with sorting criteria
371$sql = $tabsql[$id];
372
373if ($search_country_id > 0) {
374 if (preg_match('/ WHERE /', $sql)) {
375 $sql .= " AND ";
376 } else {
377 $sql .= " WHERE ";
378 }
379 $sql .= " (r.fk_country = ".((int) $search_country_id)." OR r.fk_country = 0)";
380}
381
382// If sort order is "country", we use country_code instead
383if ($sortfield == 'country') {
384 $sortfield = 'country_code';
385}
386
387$sql .= $db->order($sortfield, $sortorder);
388$sql .= $db->plimit($listlimit + 1, $offset);
389
390
391$fieldlist = explode(',', $tabfield[$id]);
392
393$param = '&id='.$id;
394if ($search_country_id > 0) {
395 $param .= '&search_country_id='.urlencode((string) ($search_country_id));
396}
397$paramwithsearch = $param;
398if ($sortorder) {
399 $paramwithsearch .= '&sortorder='.urlencode($sortorder);
400}
401if ($sortfield) {
402 $paramwithsearch .= '&sortfield='.urlencode($sortfield);
403}
404if (GETPOST('from', 'alpha')) {
405 $paramwithsearch .= '&from='.urlencode(GETPOST('from', 'alpha'));
406}
407if ($listlimit) {
408 $paramwithsearch .= '&listlimit='.urlencode((string) (GETPOSTINT('listlimit')));
409}
410print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
411print '<input type="hidden" name="token" value="'.newToken().'">';
412print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
413print '<input type="hidden" name="sortfield" value="'.dol_escape_htmltag($sortfield).'">';
414print '<input type="hidden" name="sortorder" value="'.dol_escape_htmltag($sortorder).'">';
415
416
417print '<div class="div-table-responsive-no-min">';
418print '<table class="noborder centpercent">';
419
420// Form to add a new line
421if ($tabname[$id]) {
422 $fieldlist = explode(',', $tabfield[$id]);
423
424 // Line for title
425 print '<tr class="liste_titre">';
426 // Action column
427 if ($conf->main_checkbox_left_column) {
428 print '<td></td>';
429 }
430 foreach ($fieldlist as $field => $value) {
431 // Determine the field name based on the possible names
432 // in the data dictionaries.
433 $valuetoshow = ucfirst($fieldlist[$field]); // By default
434 $valuetoshow = $langs->trans($valuetoshow); // try to translate
435 $class = "left";
436 if ($fieldlist[$field] == 'code') {
437 $valuetoshow = $langs->trans("Code");
438 $class = 'width75';
439 }
440 if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
441 $valuetoshow = $langs->trans("Label");
442 }
443 if ($fieldlist[$field] == 'country') {
444 $valuetoshow = $langs->trans("Country");
445 }
446
447 if ($valuetoshow != '') {
448 print '<td class="'.$class.'">';
449 if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
450 print '<a href="'.$tabhelp[$id][$value].'">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
451 } elseif (!empty($tabhelp[$id][$value])) {
452 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
453 } else {
454 print $valuetoshow;
455 }
456 print '</td>';
457 }
458 }
459
460 print '<td>';
461 print '<input type="hidden" name="id" value="'.$id.'">';
462 print '</td>';
463 print '<td></td>';
464 // Action column
465 if (!$conf->main_checkbox_left_column) {
466 print '<td></td>';
467 }
468 print '</tr>';
469
470 // Line to enter new values
471 print '<tr class="oddeven nodrag nodrop nohover">';
472
473 // Action column
474 if ($conf->main_checkbox_left_column) {
475 print '<td></td>';
476 }
477
478 $obj = new stdClass();
479 // If data was already input, we define them in obj to populate input fields.
480 if (GETPOST('actionadd', 'alpha')) {
481 foreach ($fieldlist as $key => $val) {
482 if (GETPOST($val) != '') {
483 $obj->$val = GETPOST($val);
484 }
485 }
486 }
487
488 $tmpaction = 'create';
489 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
490 $reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
491 $error = $hookmanager->error;
492 $errors = $hookmanager->errors;
493
494 if (empty($reshook)) {
495 fieldListAccountingReport($fieldlist, $obj, $tabname[$id], 'add');
496 }
497
498 print '<td colspan="2" class="right">';
499 print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'">';
500 print '</td>';
501
502 // Action column
503 if (!$conf->main_checkbox_left_column) {
504 print '<td></td>';
505 }
506
507 print "</tr>";
508
509 $colspan = count($fieldlist) + 3;
510 if ($id == 45) {
511 $colspan++;
512 }
513}
514
515print '</table>';
516print '</div>';
517
518print '<div class="div-table-responsive">';
519print '<table class="noborder centpercent">';
520
521// List of available record in database
522dol_syslog("htdocs/accountancy/admin/categories_list.php", LOG_DEBUG);
523
524$resql = $db->query($sql);
525if ($resql) {
526 $num = $db->num_rows($resql);
527 $i = 0;
528
529 // There is several pages
530 if ($num > $listlimit) {
531 print '<tr class="none"><td class="right" colspan="'.(2 + count($fieldlist)).'">';
532 print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit ? 1 : 0), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
533 print '</td></tr>';
534 }
535
536 $filterfound = 0;
537 foreach ($fieldlist as $field => $value) {
538 $showfield = 1; // By default
539 if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
540 $showfield = 0;
541 }
542 if ($showfield) {
543 if ($value == 'country') {
544 $filterfound++;
545 }
546 }
547 }
548
549 // Title line with search boxes
550 print '<tr class="liste_titre liste_titre_filter">';
551
552 // Action column
553 if ($conf->main_checkbox_left_column) {
554 print '<td class="liste_titre center">';
555 if ($filterfound) {
556 $searchpicto = $form->showFilterAndCheckAddButtons(0);
557 print $searchpicto;
558 }
559 print '</td>';
560 }
561
562 $filterfound = 0;
563 foreach ($fieldlist as $field => $value) {
564 $showfield = 1; // By default
565
566 if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
567 $showfield = 0;
568 }
569
570 if ($showfield) {
571 if ($value == 'country') {
572 print '<td class="liste_titre">';
573 print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth150 maxwidthonsmartphone');
574 print '</td>';
575 $filterfound++;
576 } else {
577 print '<td class="liste_titre"></td>';
578 }
579 }
580 }
581 print '<td class="liste_titre"></td>';
582 // Action column
583 if (!$conf->main_checkbox_left_column) {
584 print '<td class="liste_titre center">';
585 if ($filterfound) {
586 $searchpicto = $form->showFilterAndCheckAddButtons(0);
587 print $searchpicto;
588 }
589 print '</td>';
590 }
591 print '</tr>';
592
593 // Title of lines
594 print '<tr class="liste_titre">';
595 // Action column
596 if ($conf->main_checkbox_left_column) {
597 print getTitleFieldOfList('');
598 }
599 foreach ($fieldlist as $field => $value) {
600 // Determines the name of the field in relation to the possible names
601 // in data dictionaries
602 $showfield = 1; // By default
603 $class = "left";
604 $sortable = 1;
605 $valuetoshow = '';
606
607 $valuetoshow = ucfirst($fieldlist[$field]); // By default
608 $valuetoshow = $langs->trans($valuetoshow); // try to translate
609 if ($fieldlist[$field] == 'code') {
610 $valuetoshow = $langs->trans("Code");
611 }
612 if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
613 $valuetoshow = $langs->trans("Label");
614 }
615 if ($fieldlist[$field] == 'country') {
616 $valuetoshow = $langs->trans("Country");
617 }
618 if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
619 $showfield = 0;
620 }
621 // Affiche nom du champ
622 if ($showfield) {
623 print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable ? $fieldlist[$field] : ''), ($page ? 'page='.$page.'&' : ''), $param, "", $sortfield, $sortorder, $class.' ');
624 }
625 }
626 print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
627 // Action column
628 if (!$conf->main_checkbox_left_column) {
629 print getTitleFieldOfList('');
630 }
631 print '</tr>';
632
633
634 if ($num) {
635 $imaxinloop = ($listlimit ? min($num, $listlimit) : $num);
636
637 // Lines with values
638 while ($i < $imaxinloop) {
639 $obj = $db->fetch_object($resql);
640
641 //print_r($obj);
642 print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
643 if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
644 $tmpaction = 'edit';
645 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
646 $reshook = $hookmanager->executeHooks('editDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
647 $error = $hookmanager->error;
648 $errors = $hookmanager->errors;
649
650 // Actions
651 if ($conf->main_checkbox_left_column) {
652 print '<td></td>';
653 }
654
655 // Show fields
656 if (empty($reshook)) {
657 fieldListAccountingReport($fieldlist, $obj, $tabname[$id], 'edit');
658 }
659
660 print '<td class="center">';
661 print '<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'"></div>';
662 print '<input type="hidden" name="page" value="'.$page.'">';
663 print '<input type="hidden" name="rowid" value="'.$rowid.'">';
664 print '<input type="submit" class="button button-edit smallpaddingimp" name="actionmodify" value="'.$langs->trans("Modify").'">';
665 print '<input type="submit" class="button button-cancel smallpaddingimp" name="actioncancel" value="'.$langs->trans("Cancel").'">';
666 print '</td>';
667 // Actions
668 if (!$conf->main_checkbox_left_column) {
669 print '<td></td>';
670 }
671 } else {
672 // Can an entry be erased or disabled ?
673 $iserasable = 1;
674 $canbedisabled = 1;
675 $canbemodified = 1; // true by default
676 if (isset($obj->code)) {
677 if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i', $obj->code))) {
678 $iserasable = 0;
679 $canbedisabled = 0;
680 }
681 }
682 $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) : '');
683 $url .= '&'.$param;
684 $url .= '&';
685
686 $canbemodified = $iserasable;
687
688 $tmpaction = 'view';
689 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
690 $reshook = $hookmanager->executeHooks('viewDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
691
692 $error = $hookmanager->error;
693 $errors = $hookmanager->errors;
694
695 // Actions
696 if ($conf->main_checkbox_left_column) {
697 print '<td class="center">';
698 if ($canbemodified) {
699 print '<a class="reposition editfielda marginleftonly marginrightonly" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a>';
700 }
701 if ($iserasable) {
702 if ($user->admin) {
703 print '<a class="marginleftonly marginrightonly" href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a>';
704 }
705 }
706 print '</td>';
707 }
708
709 if (empty($reshook)) {
710 foreach ($fieldlist as $field => $value) {
711 $showfield = 1;
712 $title = '';
713 $class = 'tddict';
714
715 $tmpvar = $fieldlist[$field];
716 $valuetoshow = $obj->$tmpvar;
717 if ($valuetoshow == 'all') {
718 $valuetoshow = $langs->trans('All');
719 } elseif ($fieldlist[$field] == 'country') {
720 if (empty($obj->country_code)) {
721 $valuetoshow = '-';
722 } else {
723 $key = $langs->trans("Country".strtoupper($obj->country_code));
724 $valuetoshow = ($key != "Country".strtoupper($obj->country_code) ? $obj->country_code." - ".$key : $obj->country);
725 }
726 } elseif (in_array($fieldlist[$field], array('label'))) {
727 $class = "tdoverflowmax250";
728 $title = $valuetoshow;
729 } elseif ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
730 $showfield = 0;
731 }
732
733 // Show value for field
734 if ($showfield) {
735 print '<!-- '.$fieldlist[$field].' --><td class="'.$class.'"'.($title ? ' title="'.dol_escape_htmltag($title).'"' : '').'>'.dol_escape_htmltag($valuetoshow).'</td>';
736 }
737 }
738 }
739
740 // Active
741 print '<td class="center" class="nowrap">';
742 if ($canbedisabled) {
743 print '<a class="reposition" href="'.$url.'action='.$acts[$obj->active].'&token='.newToken().'">'.$actl[$obj->active].'</a>';
744 } else {
745 print $langs->trans("AlwaysActive");
746 }
747 print "</td>";
748
749 // Actions
750 if (!$conf->main_checkbox_left_column) {
751 print '<td class="center">';
752 if ($canbemodified) {
753 print '<a class="reposition editfielda paddingleft marginleftonly marginrightonly paddingright" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a>';
754 }
755 if ($iserasable) {
756 if ($user->admin) {
757 print '<a class="paddingleft marginleftonly marginrightonly paddingright" href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a>';
758 }
759 }
760 print '</td>';
761 }
762 }
763 print "</tr>\n";
764 $i++;
765 }
766 } else {
767 $colspan = 10;
768 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</td></tr>';
769 }
770} else {
772}
773
774print '</table>';
775print '</div>';
776
777print '</form>';
778
779print '<br>';
780
781// End of page
782llxFooter();
783$db->close();
784
785
795function fieldListAccountingReport($fieldlist, $obj = null, $tabname = '', $context = '')
796{
797 global $form, $mysoc;
798
799 foreach ($fieldlist as $field => $value) {
800 if ($fieldlist[$field] == 'country') {
801 print '<td>';
802 $fieldname = 'country';
803 if ($context == 'add') {
804 $fieldname = 'country_id';
805 $preselectcountrycode = GETPOSTISSET('country_id') ? GETPOSTINT('country_id') : $mysoc->country_code;
806 print $form->select_country($preselectcountrycode, $fieldname, '', 28, 'maxwidth150 maxwidthonsmartphone');
807 } else {
808 $preselectcountrycode = (empty($obj->country_code) ? (empty($obj->country) ? $mysoc->country_code : $obj->country) : $obj->country_code);
809 print $form->select_country($preselectcountrycode, $fieldname, '', 28, 'maxwidth150 maxwidthonsmartphone');
810 }
811 print '</td>';
812 } elseif ($fieldlist[$field] == 'country_id') {
813 if (!in_array('country', $fieldlist)) { // If there is already a field country, we don't show country_id (avoid duplicate)
814 $country_id = (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
815 print '<td>';
816 print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">';
817 print '</td>';
818 }
819 } elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
820 print '<td><input type="text" class="flat minwidth100" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" name="'.$fieldlist[$field].'"></td>';
821 } else {
822 print '<td>';
823 $class = '';
824 if (in_array($fieldlist[$field], array('label'))) {
825 $class = 'maxwidth150';
826 }
827 print '<input type="text" class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" name="'.$fieldlist[$field].'">';
828 print '</td>';
829 }
830 }
831}
$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
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.
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify 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...
$context
@method int call_trigger(string $triggerName, ?User $user)
Definition logout.php:42
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.