dolibarr 22.0.5
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-2024 Alexandre Spangaro <aspangaro@easya.solutions>
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 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}
95if (!$user->hasRight('accounting', 'chartofaccount')) {
97}
98
99
100// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
101$hookmanager->initHooks(array('admin'));
102
103// This page is a generic page to edit dictionaries
104// Put here declaration of dictionaries properties
105
106// Name of SQL tables of dictionaries
107$tabname = array();
108
109$tabname[31] = MAIN_DB_PREFIX."accounting_system";
110
111// Dictionary labels
112$tablib = array();
113$tablib[31] = "Pcg_version";
114
115// Requests to extract data
116$tabsql = array();
117$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";
118
119// Criteria to sort dictionaries
120$tabsqlsort = array();
121$tabsqlsort[31] = "pcg_version ASC";
122
123// Nom des champs en resultat de select pour affichage du dictionnaire
124$tabfield = array();
125$tabfield[31] = "pcg_version,label,country_id,country";
126
127// Nom des champs d'edition pour modification d'un enregistrement
128$tabfieldvalue = array();
129$tabfieldvalue[31] = "pcg_version,label,country";
130
131// Nom des champs dans la table pour insertion d'un enregistrement
132$tabfieldinsert = array();
133$tabfieldinsert[31] = "pcg_version,label,fk_country";
134
135// Nom du rowid si le champ n'est pas de type autoincrement
136// Example: "" if id field is "rowid" and has autoincrement on
137// "nameoffield" if id field is not "rowid" or has not autoincrement on
138$tabrowid = array();
139$tabrowid[31] = "";
140
141// List of help for fields
142$tabhelp = array();
143$tabhelp[31] = array('pcg_version' => $langs->trans("EnterAnyCode"));
144
145$permissiontoeditchart = $user->hasRight('accounting', 'chartofaccount');
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 if ($tabrowid[$id]) {
203 // Get free id for insert
204 $sql = "SELECT MAX(".$db->sanitize($tabrowid[$id]).") as newid FROM ".$db->sanitize($tabname[$id]);
205 $result = $db->query($sql);
206 if ($result) {
207 $obj = $db->fetch_object($result);
208 $newid = ($obj->newid + 1);
209 } else {
210 dol_print_error($db);
211 }
212 }
213
214 // Add new entry
215 $sql = "INSERT INTO ".$db->sanitize($tabname[$id])." (";
216 // List of fields
217 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
218 $sql .= $db->sanitize($tabrowid[$id]).",";
219 }
220 $sql .= $db->sanitize($tabfieldinsert[$id]);
221 $sql .= ",active)";
222 $sql .= " VALUES(";
223
224 // List of values
225 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
226 $sql .= $newid.",";
227 }
228 $i = 0;
229 foreach ($listfieldinsert as $f => $value) {
230 if ($value == 'price' || preg_match('/^amount/i', $value) || $value == 'taux') {
231 $_POST[$listfieldvalue[$i]] = price2num(GETPOST($listfieldvalue[$i]), 'MU');
232 } elseif ($value == 'entity') {
233 $_POST[$listfieldvalue[$i]] = $conf->entity;
234 }
235 if ($i) {
236 $sql .= ",";
237 }
238 if (GETPOST($listfieldvalue[$i]) == '') {
239 $sql .= "null";
240 } else {
241 $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
242 }
243 $i++;
244 }
245 $sql .= ",1)";
246
247 dol_syslog("actionadd", LOG_DEBUG);
248 $result = $db->query($sql);
249 if ($result) { // Add is ok
250 setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
251 $_POST = array('id' => $id); // Clean $_POST array, we keep only
252 } else {
253 if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
254 setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
255 } else {
256 dol_print_error($db);
257 }
258 }
259 }
260
261 // Si verif ok et action modify, on modifie la ligne
262 if ($ok && GETPOST('actionmodify', 'alpha')) {
263 if ($tabrowid[$id]) {
264 $rowidcol = $tabrowid[$id];
265 } else {
266 $rowidcol = "rowid";
267 }
268
269 // Modify entry
270 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET ";
271 // Modifie valeur des champs
272 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
273 $sql .= $db->sanitize($tabrowid[$id])." = ";
274 $sql .= "'".$db->escape($rowid)."', ";
275 }
276 $i = 0;
277 foreach ($listfieldmodify as $field) {
278 if ($field == 'price' || preg_match('/^amount/i', $field) || $field == 'taux') {
279 $_POST[$listfieldvalue[$i]] = price2num(GETPOST($listfieldvalue[$i]), 'MU');
280 } elseif ($field == 'entity') {
281 $_POST[$listfieldvalue[$i]] = $conf->entity;
282 }
283 if ($i) {
284 $sql .= ",";
285 }
286 $sql .= $field."=";
287 if (GETPOST($listfieldvalue[$i]) == '') {
288 $sql .= "null";
289 } else {
290 $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
291 }
292 $i++;
293 }
294 $sql .= " WHERE ".$rowidcol." = ".((int) $rowid);
295
296 dol_syslog("actionmodify", LOG_DEBUG);
297 //print $sql;
298 $resql = $db->query($sql);
299 if (!$resql) {
300 setEventMessages($db->error(), null, 'errors');
301 }
302 }
303}
304
305if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontoeditchart) { // @phpstan-ignore-line
306 if ($tabrowid[$id]) {
307 $rowidcol = $tabrowid[$id];
308 } else {
309 $rowidcol = "rowid";
310 }
311
312 $sql = "DELETE from ".$db->sanitize($tabname[$id])." WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
313
314 dol_syslog("delete", LOG_DEBUG);
315 $result = $db->query($sql);
316 if (!$result) {
317 if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
318 setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
319 } else {
320 dol_print_error($db);
321 }
322 }
323}
324
325// activate
326if ($action == 'activate' && $permissiontoeditchart) { // @phpstan-ignore-line
327 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 1 WHERE rowid = ".((int) $rowid);
328 $result = $db->query($sql);
329 if (!$result) {
330 dol_print_error($db);
331 }
332}
333
334// disable
335if ($action == $acts[1] && $permissiontoeditchart) { // @phpstan-ignore-line
336 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 0 WHERE rowid = ".((int) $rowid);
337 $result = $db->query($sql);
338 if (!$result) {
339 dol_print_error($db);
340 }
341}
342
343
344/*
345 * View
346 */
347
348$form = new Form($db);
349$formadmin = new FormAdmin($db);
350
351$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
352
353llxHeader('', $langs->trans("Pcg_version"), $help_url, '', 0, 0, '', '', '', 'mod-accountancy page-admin_accountmodel');
354
355$titre = $langs->trans($tablib[$id]);
356$linkback = '';
357
358print load_fiche_titre($titre, $linkback, 'title_accountancy');
359
360
361// Confirmation de la suppression de la ligne
362if ($action == 'delete') {
363 print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.urlencode((string) ($page)).'&' : '').'sortfield='.urlencode((string) ($sortfield)).'&sortorder='.urlencode((string) ($sortorder)).'&rowid='.urlencode((string) ($rowid)).'&code='.urlencode((string) ($code)).'&id='.urlencode((string) ($id)), $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1);
364}
365
366
367// Complete requete recherche valeurs avec critere de tri
368$sql = $tabsql[$id];
369
370if ($search_country_id > 0) {
371 if (preg_match('/ WHERE /', $sql)) {
372 $sql .= " AND ";
373 } else {
374 $sql .= " WHERE ";
375 }
376 $sql .= " c.rowid = ".((int) $search_country_id);
377}
378
379// If sort order is "country", we use country_code instead
380if ($sortfield == 'country') {
381 $sortfield = 'country_code';
382}
383$sql .= $db->order($sortfield, $sortorder);
384$sql .= $db->plimit($listlimit + 1, $offset);
385//print $sql;
386
387$fieldlist = explode(',', $tabfield[$id]);
388
389print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
390print '<input type="hidden" name="token" value="'.newToken().'">';
391
392print '<div class="div-table-responsive">';
393print '<table class="noborder centpercent">';
394
395// Form to add a new line
396
397$fieldlist = explode(',', $tabfield[$id]);
398
399// Line for title
400print '<tr class="liste_titre">';
401foreach ($fieldlist as $field => $value) {
402 // Determine le nom du champ par rapport aux noms possibles
403 // dans les dictionnaires de donnees
404 $valuetoshow = ucfirst($fieldlist[$field]); // By default
405 $valuetoshow = $langs->trans($valuetoshow); // try to translate
406 $class = "left";
407 if ($fieldlist[$field] == 'code') {
408 $valuetoshow = $langs->trans("Code");
409 }
410 if ($fieldlist[$field] == 'label') {
411 $valuetoshow = $langs->trans("Label");
412 $class = 'minwidth300';
413 }
414 if ($fieldlist[$field] == 'country') {
415 if (in_array('region_id', $fieldlist)) {
416 print '<td>&nbsp;</td>';
417 continue;
418 } // For region page, we do not show the country input
419 $valuetoshow = $langs->trans("Country");
420 }
421 if ($fieldlist[$field] == 'country_id') {
422 $valuetoshow = '';
423 }
424 if ($fieldlist[$field] == 'pcg_version' || $fieldlist[$field] == 'fk_pcg_version') {
425 $valuetoshow = $langs->trans("Pcg_version");
426 }
427 //var_dump($value);
428
429 if ($valuetoshow != '') {
430 print '<td class="'.$class.'">';
431 if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
432 print '<a href="'.$tabhelp[$id][$value].'">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
433 } elseif (!empty($tabhelp[$id][$value])) {
434 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
435 } else {
436 print $valuetoshow;
437 }
438 print '</td>';
439 }
440}
441
442print '<td>';
443print '<input type="hidden" name="id" value="'.$id.'">';
444print '</td>';
445print '<td></td>';
446print '<td></td>';
447print '</tr>';
448
449// Line to enter new values
450print '<tr class="oddeven">';
451
452$obj = new stdClass();
453// If data was already input, we define them in obj to populate input fields.
454if (GETPOST('actionadd', 'alpha')) {
455 foreach ($fieldlist as $key => $val) {
456 if (GETPOST($val)) {
457 $obj->$val = GETPOST($val);
458 }
459 }
460}
461
462$tmpaction = 'create';
463$parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
464$reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
465$error = $hookmanager->error;
466$errors = $hookmanager->errors;
467
468if (empty($reshook)) {
469 fieldListAccountModel($fieldlist, $obj, $tabname[$id], 'add');
470}
471
472print '<td colspan="3" class="right">';
473print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'">';
474print '</td>';
475print "</tr>";
476
477$colspan = count($fieldlist) + 3;
478
479print '<tr><td colspan="'.$colspan.'">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
480
481
482
483// List of available values in database
484dol_syslog("htdocs/admin/dict", LOG_DEBUG);
485$resql = $db->query($sql);
486if ($resql) {
487 $num = $db->num_rows($resql);
488 $i = 0;
489
490 $param = '&id='.urlencode((string) ($id));
491 if ($search_country_id > 0) {
492 $param .= '&search_country_id='.urlencode((string) ($search_country_id));
493 }
494 $paramwithsearch = $param;
495 if ($sortorder) {
496 $paramwithsearch .= '&sortorder='.urlencode($sortorder);
497 }
498 if ($sortfield) {
499 $paramwithsearch .= '&sortfield='.urlencode($sortfield);
500 }
501
502 // There is several pages
503 if ($num > $listlimit) {
504 print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).'">';
505 print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit ? 1 : 0), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
506 print '</td></tr>';
507 }
508
509 // Title line with search boxes
510 print '<tr class="liste_titre liste_titre_add">';
511 foreach ($fieldlist as $field => $value) {
512 $showfield = 1; // By default
513
514 if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
515 $showfield = 0;
516 }
517
518 if ($showfield) {
519 if ($value == 'country') {
520 print '<td class="liste_titre">';
521 print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth200 maxwidthonsmartphone');
522 print '</td>';
523 } else {
524 print '<td class="liste_titre"></td>';
525 }
526 }
527 }
528 print '<td class="liste_titre"></td>';
529 print '<td class="liste_titre right" colspan="2">';
530 $searchpicto = $form->showFilterAndCheckAddButtons(0);
531 print $searchpicto;
532 print '</td>';
533 print '</tr>';
534
535 // Title of lines
536 print '<tr class="liste_titre">';
537 print getTitleFieldOfList($langs->trans("Pcg_version"), 0, $_SERVER["PHP_SELF"], "pcg_version", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
538 print getTitleFieldOfList($langs->trans("Label"), 0, $_SERVER["PHP_SELF"], "label", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
539 print getTitleFieldOfList($langs->trans("Country"), 0, $_SERVER["PHP_SELF"], "country_code", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
540 print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
541 print getTitleFieldOfList('');
542 print getTitleFieldOfList('');
543 print '</tr>';
544
545 if ($num) {
546 $i = 0;
547 // Lines with values
548 while ($i < $num) {
549 $obj = $db->fetch_object($resql);
550 //print_r($obj);
551
552 print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
553 if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
554 print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
555 print '<input type="hidden" name="token" value="'.newToken().'">';
556 print '<input type="hidden" name="page" value="'.$page.'">';
557 print '<input type="hidden" name="rowid" value="'.$rowid.'">';
558
559 $tmpaction = 'edit';
560 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
561 $reshook = $hookmanager->executeHooks('editDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
562 $error = $hookmanager->error;
563 $errors = $hookmanager->errors;
564
565 if (empty($reshook)) {
566 fieldListAccountModel($fieldlist, $obj, $tabname[$id], 'edit');
567 }
568
569 print '<td colspan="3" class="right">';
570 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").'">';
571 print '&nbsp;<input type="submit" class="button button-cancel smallpaddingimp" name="actioncancel" value="'.$langs->trans("Cancel").'">';
572 print '</td>';
573 } else {
574 $tmpaction = 'view';
575 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
576 $reshook = $hookmanager->executeHooks('viewDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
577
578 $error = $hookmanager->error;
579 $errors = $hookmanager->errors;
580
581 if (empty($reshook)) {
582 foreach ($fieldlist as $field => $value) {
583 $showfield = 1;
584 $class = "left";
585 $tmpvar = $fieldlist[$field];
586 $valuetoshow = $obj->$tmpvar;
587 if ($valuetoshow == 'all') {
588 $valuetoshow = $langs->trans('All');
589 } elseif ($fieldlist[$field] == 'country') {
590 if (empty($obj->country_code)) {
591 $valuetoshow = '-';
592 } else {
593 $key = $langs->trans("Country".strtoupper($obj->country_code));
594 $valuetoshow = ($key != "Country".strtoupper($obj->country_code) ? $obj->country_code." - ".$key : $obj->country);
595 }
596 } elseif ($fieldlist[$field] == 'country_id') {
597 $showfield = 0;
598 }
599
600 $class = 'tddict';
601 if ($fieldlist[$field] == 'tracking') {
602 $class .= ' tdoverflowauto';
603 }
604 // Show value for field
605 if ($showfield) {
606 print '<!-- '.$fieldlist[$field].' --><td class="'.$class.'">'.$valuetoshow.'</td>';
607 }
608 }
609 }
610
611 // Can an entry be erased or disabled ?
612 $iserasable = 1;
613 $canbedisabled = 1;
614 $canbemodified = 1; // true by default
615
616 $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) : '');
617 $url .= '&'.$param.'&';
618
619 // Active
620 print '<td class="center nowrap">';
621 if ($canbedisabled) {
622 print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
623 } else {
624 print $langs->trans("AlwaysActive");
625 }
626 print "</td>";
627
628 // Modify link
629 if ($canbemodified) {
630 print '<td class="center"><a class="reposition editfielda" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a></td>';
631 } else {
632 print '<td>&nbsp;</td>';
633 }
634
635 // Delete link
636 if ($iserasable) {
637 print '<td class="center"><a href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a></td>';
638 } else {
639 print '<td>&nbsp;</td>';
640 }
641
642 print "</tr>\n";
643 }
644
645 $i++;
646 }
647 } else {
648 print '<tr><td colspan="6"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
649 }
650} else {
651 dol_print_error($db);
652}
653
654print '</table>';
655print '</div>';
656
657print '</form>';
658
659print '<br>';
660
661// End of page
662llxFooter();
663$db->close();
664
665
675function fieldListAccountModel($fieldlist, $obj = null, $tabname = '', $context = '')
676{
677 global $langs, $db;
678 global $form;
679
680 $formadmin = new FormAdmin($db);
681 $formcompany = new FormCompany($db);
682 $formaccounting = new FormAccounting($db);
683
684 foreach ($fieldlist as $field => $value) {
685 if ($fieldlist[$field] == 'country') {
686 if (in_array('region_id', $fieldlist)) {
687 print '<td>';
688 //print join(',',$fieldlist);
689 print '</td>';
690 continue;
691 } // For state page, we do not show the country input (we link to region, not country)
692 print '<td>';
693 $fieldname = 'country';
694 print $form->select_country((!empty($obj->country_code) ? $obj->country_code : (!empty($obj->country) ? $obj->country : '')), $fieldname, '', 28, 'maxwidth200 maxwidthonsmartphone');
695 print '</td>';
696 } elseif ($fieldlist[$field] == 'country_id') {
697 if (!in_array('country', $fieldlist)) { // If there is already a field country, we don't show country_id (avoid duplicate)
698 $country_id = (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
699 print '<td>';
700 print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">';
701 print '</td>';
702 }
703 } elseif ($fieldlist[$field] == 'type_cdr') {
704 if ($fieldlist[$field] == 'type_cdr') {
705 print '<td class="center">';
706 } else {
707 print '<td>';
708 }
709 if ($fieldlist[$field] == 'type_cdr') {
710 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]} : ''));
711 } else {
712 print $form->selectyesno($fieldlist[$field], (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : ''), 1);
713 }
714 print '</td>';
715 } elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
716 print '<td><input type="text" class="flat" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" size="10" name="'.$fieldlist[$field].'"></td>';
717 } else {
718 print '<td>';
719 $class = '';
720 if ($fieldlist[$field] == 'pcg_version') {
721 $class = 'width150';
722 }
723 if ($fieldlist[$field] == 'label') {
724 $class = 'width300';
725 }
726 print '<input type="text" class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" name="'.$fieldlist[$field].'">';
727 print '</td>';
728 }
729 }
730}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
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.
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_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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
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.
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
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.