dolibarr 25.0.0-alpha
accountmodel.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2011-2019 Philippe Grand <philippe.grand@atoo-net.com>
8 * Copyright (C) 2011 Remy Younes <ryounes@gmail.com>
9 * Copyright (C) 2012-2015 Marcos García <marcosgdf@gmail.com>
10 * Copyright (C) 2012 Christophe Battarel <christophe.battarel@ltairis.fr>
11 * Copyright (C) 2011-2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
12 * Copyright (C) 2015 Ferran Marcet <fmarcet@2byte.es>
13 * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
14 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
15 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 3 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <https://www.gnu.org/licenses/>.
29 */
30
37// Load Dolibarr environment
38require '../../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
45if (isModEnabled('accounting')) {
46 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
47}
48
57// Load translation files required by the page
58$langs->loadLangs(array('accountancy', 'admin', 'companies', 'compta', 'holiday', 'hrm', 'resource'));
59
60$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view';
61$confirm = GETPOST('confirm', 'alpha');
62$id = 31;
63$rowid = GETPOST('rowid', 'alpha');
64$code = GETPOST('code', 'alpha');
65
66$acts = array();
67$actl = array();
68$acts[0] = "activate";
69$acts[1] = "disable";
70$actl[0] = img_picto($langs->trans("Disabled"), 'switch_off', 'class="size15x"');
71$actl[1] = img_picto($langs->trans("Activated"), 'switch_on', 'class="size15x"');
72
73$listoffset = GETPOST('listoffset', 'alpha');
74$listlimit = GETPOSTINT('listlimit') > 0 ? GETPOSTINT('listlimit') : 1000;
75$active = 1;
76
77$sortfield = GETPOST("sortfield", 'aZ09comma');
78$sortorder = GETPOST("sortorder", 'aZ09comma');
79$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
80if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
81 // If $page is not defined, or '' or -1 or if we click on clear filters
82 $page = 0;
83}
84$offset = $listlimit * $page;
85$pageprev = $page - 1;
86$pagenext = $page + 1;
87
88$search_country_id = GETPOST('search_country_id', 'int');
89
90
91// Security check
92if ($user->socid > 0) {
94}
95
96$permissiontoeditchart = $user->hasRight('accounting', 'chartofaccount');
97if (!$user->hasRight('accounting', 'chartofaccount')) {
99}
100
101
102// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
103$hookmanager->initHooks(array('admin'));
104
105// This page is a generic page to edit dictionaries
106// Put here declaration of dictionaries properties
107
108// Name of SQL tables of dictionaries
109$tabname = array();
110
111$tabname[31] = MAIN_DB_PREFIX."accounting_system";
112
113// Dictionary labels
114$tablib = array();
115$tablib[31] = "Pcg_version";
116
117// Requests to extract data
118$tabsql = array();
119$tabsql[31] = "SELECT s.rowid as rowid, pcg_version, s.label, s.fk_country as country_id, c.code as country_code, c.label as country, s.active FROM ".MAIN_DB_PREFIX."accounting_system as s, ".MAIN_DB_PREFIX."c_country as c WHERE s.fk_country=c.rowid and c.active=1";
120
121// Criteria to sort dictionaries
122$tabsqlsort = array();
123$tabsqlsort[31] = "pcg_version ASC";
124
125// Fields names from select for dictionary display
126$tabfield = array();
127$tabfield[31] = "pcg_version,label,country_id,country";
128
129// Field names for editing a record
130$tabfieldvalue = array();
131$tabfieldvalue[31] = "pcg_version,label,country";
132
133// Field names in the table for record insertion
134$tabfieldinsert = array();
135$tabfieldinsert[31] = "pcg_version,label,fk_country";
136
137// Nom du rowid si le champ n'est pas de type autoincrement
138// Example: "" if id field is "rowid" and has autoincrement on
139// "nameoffield" if id field is not "rowid" or has not autoincrement on
140$tabrowid = array();
141$tabrowid[31] = "";
142
143// List of help for fields
144$tabhelp = array();
145$tabhelp[31] = array('pcg_version' => $langs->trans("EnterAnyCode"));
146
147
148/*
149 * Actions
150 */
151
152if (GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter_x', 'alpha')) {
153 $search_country_id = '';
154}
155
156// Actions add or modify an entry into a dictionary
157if (GETPOST('actionadd', 'alpha') || GETPOST('actionmodify', 'alpha')) {
158 $listfield = explode(',', str_replace(' ', '', $tabfield[$id]));
159 $listfieldinsert = explode(',', $tabfieldinsert[$id]);
160 $listfieldmodify = explode(',', $tabfieldinsert[$id]);
161 $listfieldvalue = explode(',', $tabfieldvalue[$id]);
162
163 // Check that all fields are filled
164 $ok = 1;
165 foreach ($listfield as $f => $value) {
166 if ($value == 'country_id' && in_array($tablib[$id], array('Pcg_version'))) {
167 continue; // For some pages, country is not mandatory
168 }
169 if ((!GETPOSTISSET($value)) || GETPOST($value) == '') {
170 $ok = 0;
171 $fieldnamekey = $listfield[$f];
172 // We take translate key of field
173
174 if ($fieldnamekey == 'pcg_version') {
175 $fieldnamekey = 'Pcg_version';
176 }
177 if ($fieldnamekey == 'label') {
178 $fieldnamekey = 'Label';
179 }
180 if ($fieldnamekey == 'country') {
181 $fieldnamekey = "Country";
182 }
183
184 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
185 }
186 }
187 // Other checks
188 if (GETPOSTISSET("pcg_version")) {
189 if (GETPOST("pcg_version") == '0') {
190 $ok = 0;
191 setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
192 }
193 }
194 if (GETPOSTISSET("country") && GETPOST("country") == '0') {
195 $ok = 0;
196 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities("Country")), null, 'errors');
197 }
198
199 // In case of 'actionadd' and with valid parameters, add the line
200 if ($ok && GETPOST('actionadd', 'alpha')) {
201 $newid = 0;
202
203 // Add new entry
204 $sql = "INSERT INTO ".$db->sanitize($tabname[$id])." (";
205 // List of fields
206 $sql .= $db->sanitize($tabfieldinsert[$id]);
207 $sql .= ",active)";
208 $sql .= " VALUES(";
209
210 // List of values
211 $i = 0;
212 foreach ($listfieldinsert as $f => $value) {
213 if ($value == 'price' || preg_match('/^amount/i', $value) || $value == 'taux') {
214 $_POST[$listfieldvalue[$i]] = price2num(GETPOST($listfieldvalue[$i]), 'MU');
215 } elseif ($value == 'entity') {
216 $_POST[$listfieldvalue[$i]] = $conf->entity;
217 }
218 if ($i) {
219 $sql .= ",";
220 }
221 if (GETPOST($listfieldvalue[$i]) == '') {
222 $sql .= "null";
223 } else {
224 $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
225 }
226 $i++;
227 }
228 $sql .= ",1)";
229
230 dol_syslog("actionadd", LOG_DEBUG);
231 $result = $db->query($sql);
232 if ($result) { // Add is ok
233 setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
234 $_POST = array('id' => $id); // Clean $_POST array, we keep only
235 } else {
236 if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
237 $langs->load('errors');
238 setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
239 } else {
240 dol_print_error($db);
241 }
242 }
243 }
244
245 // In case of 'actionmodify' and with valid parameters, modify the line
246 if ($ok && GETPOST('actionmodify', 'alpha')) {
247 // Modify entry
248 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET ";
249 // Change field's value
250
251 $i = 0;
252 foreach ($listfieldmodify as $field) {
253 if ($field == 'price' || preg_match('/^amount/i', $field) || $field == 'taux') {
254 $_POST[$listfieldvalue[$i]] = price2num(GETPOST($listfieldvalue[$i]), 'MU');
255 } elseif ($field == 'entity') {
256 $_POST[$listfieldvalue[$i]] = $conf->entity;
257 }
258 if ($i) {
259 $sql .= ",";
260 }
261 $sql .= $field."=";
262 if (GETPOST($listfieldvalue[$i]) == '') {
263 $sql .= "null";
264 } else {
265 $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
266 }
267 $i++;
268 }
269 $sql .= " WHERE rowid = ".((int) $rowid);
270
271 dol_syslog("actionmodify", LOG_DEBUG);
272 $resql = $db->query($sql);
273 if (!$resql) {
274 setEventMessages($db->error(), null, 'errors');
275 }
276 }
277}
278
279// delete
280if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontoeditchart) {
281 $sql = "DELETE from ".$db->sanitize($tabname[$id])." WHERE rowid = ".((int) $rowid);
282
283 dol_syslog("delete", LOG_DEBUG);
284 $result = $db->query($sql);
285 if (!$result) {
286 if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
287 setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
288 } else {
289 dol_print_error($db);
290 }
291 }
292}
293
294// activate
295if ($action == 'activate' && $permissiontoeditchart) {
296 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 1 WHERE rowid = ".((int) $rowid);
297 $result = $db->query($sql);
298 if (!$result) {
299 dol_print_error($db);
300 }
301}
302
303// disable
304if ($action == $acts[1] && $permissiontoeditchart) {
305 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 0 WHERE rowid = ".((int) $rowid);
306 $result = $db->query($sql);
307 if (!$result) {
308 dol_print_error($db);
309 }
310}
311
312
313/*
314 * View
315 */
316
317$form = new Form($db);
318$formadmin = new FormAdmin($db);
319
320$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
321
322llxHeader('', $langs->trans("Pcg_version"), $help_url, '', 0, 0, '', '', '', 'mod-accountancy page-admin_accountmodel');
323
324$titre = $langs->trans($tablib[$id]);
325$linkback = '';
326
327print load_fiche_titre($titre, $linkback, 'title_accountancy');
328
329
330// Confirmation of line deletion
331if ($action == 'delete') {
332 print $form->formconfirm(dolBuildUrl($_SERVER["PHP_SELF"], ['page'=> $page, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'rowid' => $rowid, 'code' => $code, 'id' => $id]), $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1);
333}
334
335
336// Complete the values search query with the sort order
337$sql = $tabsql[$id];
338
339if ($search_country_id > 0) {
340 if (preg_match('/ WHERE /', $sql)) {
341 $sql .= " AND ";
342 } else {
343 $sql .= " WHERE ";
344 }
345 $sql .= " c.rowid = ".((int) $search_country_id);
346}
347
348// If sort order is "country", we use country_code instead
349if ($sortfield == 'country') {
350 $sortfield = 'country_code';
351}
352$sql .= $db->order($sortfield, $sortorder);
353$sql .= $db->plimit($listlimit + 1, $offset);
354
355$fieldlist = explode(',', $tabfield[$id]);
356
357print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
358print '<input type="hidden" name="token" value="'.newToken().'">';
359
360print '<div class="div-table-responsive">';
361print '<table class="noborder centpercent">';
362
363// Form to add a new line
364
365$fieldlist = explode(',', $tabfield[$id]);
366
367// Line for title
368print '<tr class="liste_titre">';
369foreach ($fieldlist as $field => $value) {
370 // Determine the field name based on the possible names
371 // in the data dictionaries
372 $valuetoshow = ucfirst($fieldlist[$field]); // By default
373 $valuetoshow = $langs->trans($valuetoshow); // try to translate
374 $class = "left";
375 if ($fieldlist[$field] == 'code') {
376 $valuetoshow = $langs->trans("Code");
377 }
378 if ($fieldlist[$field] == 'label') {
379 $valuetoshow = $langs->trans("Label");
380 $class = 'minwidth300';
381 }
382 if ($fieldlist[$field] == 'country') {
383 if (in_array('region_id', $fieldlist)) {
384 print '<td>&nbsp;</td>';
385 continue;
386 } // For region page, we do not show the country input
387 $valuetoshow = $langs->trans("Country");
388 }
389 if ($fieldlist[$field] == 'country_id') {
390 $valuetoshow = '';
391 }
392 if ($fieldlist[$field] == 'pcg_version' || $fieldlist[$field] == 'fk_pcg_version') {
393 $valuetoshow = $langs->trans("Pcg_version");
394 }
395
396 if ($valuetoshow != '') {
397 print '<td class="'.$class.'">';
398 if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
399 print '<a href="'.$tabhelp[$id][$value].'">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
400 } elseif (!empty($tabhelp[$id][$value])) {
401 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
402 } else {
403 print $valuetoshow;
404 }
405 print '</td>';
406 }
407}
408
409print '<td>';
410print '<input type="hidden" name="id" value="'.$id.'">';
411print '</td>';
412print '<td></td>';
413print '<td></td>';
414print '</tr>';
415
416// Line to enter new values
417print '<tr class="oddeven">';
418
419$obj = new stdClass();
420// If data was already input, we define them in obj to populate input fields.
421if (GETPOST('actionadd', 'alpha')) {
422 foreach ($fieldlist as $key => $val) {
423 if (GETPOST($val)) {
424 $obj->$val = GETPOST($val);
425 }
426 }
427}
428
429$tmpaction = 'create';
430$parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
431$reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
432$error = $hookmanager->error;
433$errors = $hookmanager->errors;
434
435if (empty($reshook)) {
436 fieldListAccountModel($fieldlist, $obj, $tabname[$id], 'add');
437}
438
439print '<td colspan="3" class="right">';
440print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'">';
441print '</td>';
442print "</tr>";
443
444$colspan = count($fieldlist) + 3;
445
446print '<tr><td colspan="'.$colspan.'">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
447
448
449
450// List of available values in database
451dol_syslog("htdocs/admin/dict", LOG_DEBUG);
452$resql = $db->query($sql);
453if ($resql) {
454 $num = $db->num_rows($resql);
455 $i = 0;
456
457 $param = '&id='.urlencode((string) ($id));
458 if ($search_country_id > 0) {
459 $param .= '&search_country_id='.urlencode((string) ($search_country_id));
460 }
461 $paramwithsearch = $param;
462 if ($sortorder) {
463 $paramwithsearch .= '&sortorder='.urlencode($sortorder);
464 }
465 if ($sortfield) {
466 $paramwithsearch .= '&sortfield='.urlencode($sortfield);
467 }
468
469 // There is several pages
470 if ($num > $listlimit) {
471 print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).'">';
472 print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit ? 1 : 0), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
473 print '</td></tr>';
474 }
475
476 // Title line with search boxes
477 print '<tr class="liste_titre liste_titre_add">';
478 foreach ($fieldlist as $field => $value) {
479 $showfield = 1; // By default
480
481 if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
482 $showfield = 0;
483 }
484
485 if ($showfield) {
486 if ($value == 'country') {
487 print '<td class="liste_titre">';
488 print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth200 maxwidthonsmartphone');
489 print '</td>';
490 } else {
491 print '<td class="liste_titre"></td>';
492 }
493 }
494 }
495 print '<td class="liste_titre"></td>';
496 print '<td class="liste_titre right" colspan="2">';
497 $searchpicto = $form->showFilterAndCheckAddButtons(0);
498 print $searchpicto;
499 print '</td>';
500 print '</tr>';
501
502 // Title of lines
503 print '<tr class="liste_titre">';
504 print getTitleFieldOfList($langs->trans("Pcg_version"), 0, $_SERVER["PHP_SELF"], "pcg_version", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
505 print getTitleFieldOfList($langs->trans("Label"), 0, $_SERVER["PHP_SELF"], "label", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
506 print getTitleFieldOfList($langs->trans("Country"), 0, $_SERVER["PHP_SELF"], "country_code", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
507 print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
508 print getTitleFieldOfList('');
509 print getTitleFieldOfList('');
510 print '</tr>';
511
512 if ($num) {
513 $i = 0;
514 // Lines with values
515 while ($i < $num) {
516 $obj = $db->fetch_object($resql);
517 //print_r($obj);
518
519 print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
520 if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
521 print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
522 print '<input type="hidden" name="token" value="'.newToken().'">';
523 print '<input type="hidden" name="page" value="'.$page.'">';
524 print '<input type="hidden" name="rowid" value="'.$rowid.'">';
525
526 $tmpaction = 'edit';
527 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
528 $reshook = $hookmanager->executeHooks('editDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
529 $error = $hookmanager->error;
530 $errors = $hookmanager->errors;
531
532 if (empty($reshook)) {
533 fieldListAccountModel($fieldlist, $obj, $tabname[$id], 'edit');
534 }
535
536 print '<td colspan="3" class="right">';
537 print '<a name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'">&nbsp;</a><input type="submit" class="button button-edit smallpaddingimp" name="actionmodify" value="'.$langs->trans("Modify").'">';
538 print '&nbsp;<input type="submit" class="button button-cancel smallpaddingimp" name="actioncancel" value="'.$langs->trans("Cancel").'">';
539 print '</td>';
540 } else {
541 $tmpaction = 'view';
542 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
543 $reshook = $hookmanager->executeHooks('viewDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
544
545 $error = $hookmanager->error;
546 $errors = $hookmanager->errors;
547
548 if (empty($reshook)) {
549 foreach ($fieldlist as $field => $value) {
550 $showfield = 1;
551 $class = "left";
552 $tmpvar = $fieldlist[$field];
553 $valuetoshow = $obj->$tmpvar;
554 if ($valuetoshow == 'all') {
555 $valuetoshow = $langs->trans('All');
556 } elseif ($fieldlist[$field] == 'country') {
557 if (empty($obj->country_code)) {
558 $valuetoshow = '-';
559 } else {
560 $key = $langs->trans("Country".strtoupper($obj->country_code));
561 $valuetoshow = ($key != "Country".strtoupper($obj->country_code) ? $obj->country_code." - ".$key : $obj->country);
562 }
563 } elseif ($fieldlist[$field] == 'country_id') {
564 $showfield = 0;
565 }
566
567 $class = 'tddict';
568 if ($fieldlist[$field] == 'tracking') {
569 $class .= ' tdoverflowauto';
570 }
571 // Show value for field
572 if ($showfield) {
573 print '<!-- '.$fieldlist[$field].' --><td class="'.$class.'">'.dolPrintHTML($valuetoshow).'</td>';
574 }
575 }
576 }
577
578 // $url = $_SERVER["PHP_SELF"].'?token='.newToken().($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) : '');
579 // $url .= '&'.$param.'&';
580
581 $query = [];
582 // decode and add param to query
583 parse_str($param, $query);
584 $query = array_merge($query, [
585 'action' => '',
586 'page' => $page,
587 'sortfield' => $sortfield,
588 'sortorder' => $sortorder,
589 'rowid' => (!empty($obj->rowid) ? $obj->rowid : '')
590 ]);
591
592 // Active
593 print '<td class="center nowrap">';
594 $query['action'] = $acts[$obj->active];
595 print '<a href="'.dolBuildUrl($_SERVER["PHP_SELF"], $query, true).'">'.$actl[$obj->active].'</a>';
596 print "</td>";
597
598 // Modify link
599 $query['action'] = 'edit';
600 print '<td class="center"><a class="reposition editfielda" href="'.dolBuildUrl($_SERVER["PHP_SELF"], $query, true).'">'.img_edit().'</a></td>';
601
602 // Delete link
603 $query['action'] = 'delete';
604 print '<td class="center"><a href="'.dolBuildUrl($_SERVER["PHP_SELF"], $query, true).'">'.img_delete().'</a></td>';
605
606 print "</tr>\n";
607 }
608
609 $i++;
610 }
611 } else {
612 print '<tr><td colspan="6"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
613 }
614} else {
615 dol_print_error($db);
616}
617
618print '</table>';
619print '</div>';
620
621print '</form>';
622
623print '<br>';
624
625// End of page
626llxFooter();
627$db->close();
628
629
639function fieldListAccountModel($fieldlist, $obj = null, $tabname = '', $context = '')
640{
641 global $langs, $db;
642 global $form;
643
644 $formadmin = new FormAdmin($db);
645 $formcompany = new FormCompany($db);
646 $formaccounting = new FormAccounting($db);
647
648 foreach ($fieldlist as $field => $value) {
649 if ($fieldlist[$field] == 'country') {
650 if (in_array('region_id', $fieldlist)) {
651 print '<td>';
652 //print join(',',$fieldlist);
653 print '</td>';
654 continue;
655 } // For state page, we do not show the country input (we link to region, not country)
656 print '<td>';
657 $fieldname = 'country';
658 print $form->select_country((!empty($obj->country_code) ? $obj->country_code : (!empty($obj->country) ? $obj->country : '')), $fieldname, '', 28, 'maxwidth200 maxwidthonsmartphone');
659 print '</td>';
660 } elseif ($fieldlist[$field] == 'country_id') {
661 if (!in_array('country', $fieldlist)) { // If there is already a field country, we don't show country_id (avoid duplicate)
662 $country_id = (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
663 print '<td>';
664 print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">';
665 print '</td>';
666 }
667 } elseif ($fieldlist[$field] == 'type_cdr') {
668 print '<td class="center">';
669 print $form->selectarray($fieldlist[$field], array(0 => $langs->trans('None'), 1 => $langs->trans('AtEndOfMonth'), 2 => $langs->trans('CurrentNext')), (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : ''));
670 print '</td>';
671 } elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
672 print '<td><input type="text" class="flat" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" size="10" name="'.$fieldlist[$field].'"></td>';
673 } else {
674 print '<td>';
675 $class = '';
676 if ($fieldlist[$field] == 'pcg_version') {
677 $class = 'width150';
678 }
679 if ($fieldlist[$field] == 'label') {
680 $class = 'width300';
681 }
682 print '<input type="text" class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" name="'.$fieldlist[$field].'">';
683 print '</td>';
684 }
685 }
686}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
fieldListAccountModel($fieldlist, $obj=null, $tabname='', $context='')
Show fields in insert/edit mode.
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 generation of HTML components for accounting management.
Class to generate html code for admin pages.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
$context
@method int call_trigger(string $triggerName, ?User $user)
Definition command.php:209
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.