dolibarr 23.0.3
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 MDW <mdeweerd@users.noreply.github.com>
15 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
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', 'errors', '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// Nom des champs en resultat de select pour affichage du dictionnaire
126$tabfield = array();
127$tabfield[31] = "pcg_version,label,country_id,country";
128
129// Nom des champs d'edition pour modification d'un enregistrement
130$tabfieldvalue = array();
131$tabfieldvalue[31] = "pcg_version,label,country";
132
133// Nom des champs dans la table pour insertion d'un enregistrement
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 // Si verif ok et action add, on ajoute la ligne
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 setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
238 } else {
239 dol_print_error($db);
240 }
241 }
242 }
243
244 // Si verif ok et action modify, on modifie la ligne
245 if ($ok && GETPOST('actionmodify', 'alpha')) {
246 // Modify entry
247 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET ";
248 // Modifie valeur des champs
249
250 $i = 0;
251 foreach ($listfieldmodify as $field) {
252 if ($field == 'price' || preg_match('/^amount/i', $field) || $field == 'taux') {
253 $_POST[$listfieldvalue[$i]] = price2num(GETPOST($listfieldvalue[$i]), 'MU');
254 } elseif ($field == 'entity') {
255 $_POST[$listfieldvalue[$i]] = $conf->entity;
256 }
257 if ($i) {
258 $sql .= ",";
259 }
260 $sql .= $field."=";
261 if (GETPOST($listfieldvalue[$i]) == '') {
262 $sql .= "null";
263 } else {
264 $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
265 }
266 $i++;
267 }
268 $sql .= " WHERE rowid = ".((int) $rowid);
269
270 dol_syslog("actionmodify", LOG_DEBUG);
271 //print $sql;
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 de la suppression de la ligne
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 requete recherche valeurs avec critere de tri
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//print $sql;
355
356$fieldlist = explode(',', $tabfield[$id]);
357
358print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
359print '<input type="hidden" name="token" value="'.newToken().'">';
360
361print '<div class="div-table-responsive">';
362print '<table class="noborder centpercent">';
363
364// Form to add a new line
365
366$fieldlist = explode(',', $tabfield[$id]);
367
368// Line for title
369print '<tr class="liste_titre">';
370foreach ($fieldlist as $field => $value) {
371 // Determine le nom du champ par rapport aux noms possibles
372 // dans les dictionnaires de donnees
373 $valuetoshow = ucfirst($fieldlist[$field]); // By default
374 $valuetoshow = $langs->trans($valuetoshow); // try to translate
375 $class = "left";
376 if ($fieldlist[$field] == 'code') {
377 $valuetoshow = $langs->trans("Code");
378 }
379 if ($fieldlist[$field] == 'label') {
380 $valuetoshow = $langs->trans("Label");
381 $class = 'minwidth300';
382 }
383 if ($fieldlist[$field] == 'country') {
384 if (in_array('region_id', $fieldlist)) {
385 print '<td>&nbsp;</td>';
386 continue;
387 } // For region page, we do not show the country input
388 $valuetoshow = $langs->trans("Country");
389 }
390 if ($fieldlist[$field] == 'country_id') {
391 $valuetoshow = '';
392 }
393 if ($fieldlist[$field] == 'pcg_version' || $fieldlist[$field] == 'fk_pcg_version') {
394 $valuetoshow = $langs->trans("Pcg_version");
395 }
396 //var_dump($value);
397
398 if ($valuetoshow != '') {
399 print '<td class="'.$class.'">';
400 if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
401 print '<a href="'.$tabhelp[$id][$value].'">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
402 } elseif (!empty($tabhelp[$id][$value])) {
403 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
404 } else {
405 print $valuetoshow;
406 }
407 print '</td>';
408 }
409}
410
411print '<td>';
412print '<input type="hidden" name="id" value="'.$id.'">';
413print '</td>';
414print '<td></td>';
415print '<td></td>';
416print '</tr>';
417
418// Line to enter new values
419print '<tr class="oddeven">';
420
421$obj = new stdClass();
422// If data was already input, we define them in obj to populate input fields.
423if (GETPOST('actionadd', 'alpha')) {
424 foreach ($fieldlist as $key => $val) {
425 if (GETPOST($val)) {
426 $obj->$val = GETPOST($val);
427 }
428 }
429}
430
431$tmpaction = 'create';
432$parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
433$reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
434$error = $hookmanager->error;
435$errors = $hookmanager->errors;
436
437if (empty($reshook)) {
438 fieldListAccountModel($fieldlist, $obj, $tabname[$id], 'add');
439}
440
441print '<td colspan="3" class="right">';
442print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'">';
443print '</td>';
444print "</tr>";
445
446$colspan = count($fieldlist) + 3;
447
448print '<tr><td colspan="'.$colspan.'">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
449
450
451
452// List of available values in database
453dol_syslog("htdocs/admin/dict", LOG_DEBUG);
454$resql = $db->query($sql);
455if ($resql) {
456 $num = $db->num_rows($resql);
457 $i = 0;
458
459 $param = '&id='.urlencode((string) ($id));
460 if ($search_country_id > 0) {
461 $param .= '&search_country_id='.urlencode((string) ($search_country_id));
462 }
463 $paramwithsearch = $param;
464 if ($sortorder) {
465 $paramwithsearch .= '&sortorder='.urlencode($sortorder);
466 }
467 if ($sortfield) {
468 $paramwithsearch .= '&sortfield='.urlencode($sortfield);
469 }
470
471 // There is several pages
472 if ($num > $listlimit) {
473 print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).'">';
474 print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit ? 1 : 0), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
475 print '</td></tr>';
476 }
477
478 // Title line with search boxes
479 print '<tr class="liste_titre liste_titre_add">';
480 foreach ($fieldlist as $field => $value) {
481 $showfield = 1; // By default
482
483 if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
484 $showfield = 0;
485 }
486
487 if ($showfield) {
488 if ($value == 'country') {
489 print '<td class="liste_titre">';
490 print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth200 maxwidthonsmartphone');
491 print '</td>';
492 } else {
493 print '<td class="liste_titre"></td>';
494 }
495 }
496 }
497 print '<td class="liste_titre"></td>';
498 print '<td class="liste_titre right" colspan="2">';
499 $searchpicto = $form->showFilterAndCheckAddButtons(0);
500 print $searchpicto;
501 print '</td>';
502 print '</tr>';
503
504 // Title of lines
505 print '<tr class="liste_titre">';
506 print getTitleFieldOfList($langs->trans("Pcg_version"), 0, $_SERVER["PHP_SELF"], "pcg_version", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
507 print getTitleFieldOfList($langs->trans("Label"), 0, $_SERVER["PHP_SELF"], "label", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
508 print getTitleFieldOfList($langs->trans("Country"), 0, $_SERVER["PHP_SELF"], "country_code", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
509 print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
510 print getTitleFieldOfList('');
511 print getTitleFieldOfList('');
512 print '</tr>';
513
514 if ($num) {
515 $i = 0;
516 // Lines with values
517 while ($i < $num) {
518 $obj = $db->fetch_object($resql);
519 //print_r($obj);
520
521 print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
522 if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
523 print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
524 print '<input type="hidden" name="token" value="'.newToken().'">';
525 print '<input type="hidden" name="page" value="'.$page.'">';
526 print '<input type="hidden" name="rowid" value="'.$rowid.'">';
527
528 $tmpaction = 'edit';
529 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
530 $reshook = $hookmanager->executeHooks('editDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
531 $error = $hookmanager->error;
532 $errors = $hookmanager->errors;
533
534 if (empty($reshook)) {
535 fieldListAccountModel($fieldlist, $obj, $tabname[$id], 'edit');
536 }
537
538 print '<td colspan="3" class="right">';
539 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").'">';
540 print '&nbsp;<input type="submit" class="button button-cancel smallpaddingimp" name="actioncancel" value="'.$langs->trans("Cancel").'">';
541 print '</td>';
542 } else {
543 $tmpaction = 'view';
544 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
545 $reshook = $hookmanager->executeHooks('viewDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
546
547 $error = $hookmanager->error;
548 $errors = $hookmanager->errors;
549
550 if (empty($reshook)) {
551 foreach ($fieldlist as $field => $value) {
552 $showfield = 1;
553 $class = "left";
554 $tmpvar = $fieldlist[$field];
555 $valuetoshow = $obj->$tmpvar;
556 if ($valuetoshow == 'all') {
557 $valuetoshow = $langs->trans('All');
558 } elseif ($fieldlist[$field] == 'country') {
559 if (empty($obj->country_code)) {
560 $valuetoshow = '-';
561 } else {
562 $key = $langs->trans("Country".strtoupper($obj->country_code));
563 $valuetoshow = ($key != "Country".strtoupper($obj->country_code) ? $obj->country_code." - ".$key : $obj->country);
564 }
565 } elseif ($fieldlist[$field] == 'country_id') {
566 $showfield = 0;
567 }
568
569 $class = 'tddict';
570 if ($fieldlist[$field] == 'tracking') {
571 $class .= ' tdoverflowauto';
572 }
573 // Show value for field
574 if ($showfield) {
575 print '<!-- '.$fieldlist[$field].' --><td class="'.$class.'">'.$valuetoshow.'</td>';
576 }
577 }
578 }
579
580 // $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) : '');
581 // $url .= '&'.$param.'&';
582
583 $query = [];
584 // decode and add param to query
585 parse_str($param, $query);
586 $query = array_merge($query, [
587 'action' => '',
588 'page' => $page,
589 'sortfield' => $sortfield,
590 'sortorder' => $sortorder,
591 'rowid' => (!empty($obj->rowid) ? $obj->rowid : '')
592 ]);
593
594 // Active
595 print '<td class="center nowrap">';
596 $query['action'] = $acts[$obj->active];
597 print '<a href="'.dolBuildUrl($_SERVER["PHP_SELF"], $query, true).'">'.$actl[$obj->active].'</a>';
598 print "</td>";
599
600 // Modify link
601 $query['action'] = 'edit';
602 print '<td class="center"><a class="reposition editfielda" href="'.dolBuildUrl($_SERVER["PHP_SELF"], $query, true).'">'.img_edit().'</a></td>';
603
604 // Delete link
605 $query['action'] = 'delete';
606 print '<td class="center"><a href="'.dolBuildUrl($_SERVER["PHP_SELF"], $query, true).'">'.img_delete().'</a></td>';
607
608 print "</tr>\n";
609 }
610
611 $i++;
612 }
613 } else {
614 print '<tr><td colspan="6"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
615 }
616} else {
617 dol_print_error($db);
618}
619
620print '</table>';
621print '</div>';
622
623print '</form>';
624
625print '<br>';
626
627// End of page
628llxFooter();
629$db->close();
630
631
641function fieldListAccountModel($fieldlist, $obj = null, $tabname = '', $context = '')
642{
643 global $langs, $db;
644 global $form;
645
646 $formadmin = new FormAdmin($db);
647 $formcompany = new FormCompany($db);
648 $formaccounting = new FormAccounting($db);
649
650 foreach ($fieldlist as $field => $value) {
651 if ($fieldlist[$field] == 'country') {
652 if (in_array('region_id', $fieldlist)) {
653 print '<td>';
654 //print join(',',$fieldlist);
655 print '</td>';
656 continue;
657 } // For state page, we do not show the country input (we link to region, not country)
658 print '<td>';
659 $fieldname = 'country';
660 print $form->select_country((!empty($obj->country_code) ? $obj->country_code : (!empty($obj->country) ? $obj->country : '')), $fieldname, '', 28, 'maxwidth200 maxwidthonsmartphone');
661 print '</td>';
662 } elseif ($fieldlist[$field] == 'country_id') {
663 if (!in_array('country', $fieldlist)) { // If there is already a field country, we don't show country_id (avoid duplicate)
664 $country_id = (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
665 print '<td>';
666 print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">';
667 print '</td>';
668 }
669 } elseif ($fieldlist[$field] == 'type_cdr') {
670 print '<td class="center">';
671 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]} : ''));
672 print '</td>';
673 } elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
674 print '<td><input type="text" class="flat" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" size="10" name="'.$fieldlist[$field].'"></td>';
675 } else {
676 print '<td>';
677 $class = '';
678 if ($fieldlist[$field] == 'pcg_version') {
679 $class = 'width150';
680 }
681 if ($fieldlist[$field] == 'label') {
682 $class = 'width300';
683 }
684 print '<input type="text" class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" name="'.$fieldlist[$field].'">';
685 print '</td>';
686 }
687 }
688}
$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
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.
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.
dolBuildUrl($url, $params=[], $addtoken=false)
Return path of url.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
$context
@method int call_trigger(string $triggerName, ?User $user)
Definition logout.php:42
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.