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