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