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