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