dolibarr 19.0.3
accountmodel.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2011-2019 Philippe Grand <philippe.grand@atoo-net.com>
8 * Copyright (C) 2011 Remy Younes <ryounes@gmail.com>
9 * Copyright (C) 2012-2015 Marcos García <marcosgdf@gmail.com>
10 * Copyright (C) 2012 Christophe Battarel <christophe.battarel@ltairis.fr>
11 * Copyright (C) 2011-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 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27 */
28
35// Load Dolibarr environment
36require '../../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
43if (isModEnabled('accounting')) {
44 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
45}
46
47// Load translation files required by the page
48$langs->loadLangs(array('accountancy', 'admin', 'companies', 'compta', 'errors', 'holiday', 'hrm', 'resource'));
49
50$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view';
51$confirm = GETPOST('confirm', 'alpha');
52$id = 31;
53$rowid = GETPOST('rowid', 'alpha');
54$code = GETPOST('code', 'alpha');
55
56$acts[0] = "activate";
57$acts[1] = "disable";
58$actl[0] = img_picto($langs->trans("Disabled"), 'switch_off', 'class="size15x"');
59$actl[1] = img_picto($langs->trans("Activated"), 'switch_on', 'class="size15x"');
60
61$listoffset = GETPOST('listoffset', 'alpha');
62$listlimit = GETPOST('listlimit', 'int') > 0 ? GETPOST('listlimit', 'int') : 1000;
63$active = 1;
64
65$sortfield = GETPOST("sortfield", 'aZ09comma');
66$sortorder = GETPOST("sortorder", 'aZ09comma');
67$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
68if (empty($page) || $page == -1) {
69 $page = 0;
70} // If $page is not defined, or '' or -1
71$offset = $listlimit * $page;
72$pageprev = $page - 1;
73$pagenext = $page + 1;
74
75$search_country_id = GETPOST('search_country_id', 'int');
76
77
78// Security check
79if ($user->socid > 0) {
81}
82if (!$user->hasRight('accounting', 'chartofaccount')) {
84}
85
86
87// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
88$hookmanager->initHooks(array('admin'));
89
90// This page is a generic page to edit dictionaries
91// Put here declaration of dictionaries properties
92
93// Name of SQL tables of dictionaries
94$tabname = array();
95
96$tabname[31] = MAIN_DB_PREFIX."accounting_system";
97
98// Dictionary labels
99$tablib = array();
100$tablib[31] = "Pcg_version";
101
102// Requests to extract data
103$tabsql = array();
104$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";
105
106// Criteria to sort dictionaries
107$tabsqlsort = array();
108$tabsqlsort[31] = "pcg_version ASC";
109
110// Nom des champs en resultat de select pour affichage du dictionnaire
111$tabfield = array();
112$tabfield[31] = "pcg_version,label,country_id,country";
113
114// Nom des champs d'edition pour modification d'un enregistrement
115$tabfieldvalue = array();
116$tabfieldvalue[31] = "pcg_version,label,country";
117
118// Nom des champs dans la table pour insertion d'un enregistrement
119$tabfieldinsert = array();
120$tabfieldinsert[31] = "pcg_version,label,fk_country";
121
122// Nom du rowid si le champ n'est pas de type autoincrement
123// Example: "" if id field is "rowid" and has autoincrement on
124// "nameoffield" if id field is not "rowid" or has not autoincrement on
125$tabrowid = array();
126$tabrowid[31] = "";
127
128// List of help for fields
129$tabhelp = array();
130$tabhelp[31] = array('pcg_version'=>$langs->trans("EnterAnyCode"));
131
132
133// Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
134$elementList = array();
135$sourceList = array();
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') && ($id != 2)) {
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 if ($tabrowid[$id]) {
193 // Get free id for insert
194 $newid = 0;
195 $sql = "SELECT MAX(".$tabrowid[$id].") newid from ".$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 ".$tabname[$id]." (";
207 // List of fields
208 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
209 $sql .= $tabrowid[$id].",";
210 }
211 $sql .= $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 ".$tabname[$id]." SET ";
262 // Modifie valeur des champs
263 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
264 $sql .= $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 ".$tabname[$id]." WHERE ".$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 == $acts[0]) {
318 if ($tabrowid[$id]) {
319 $rowidcol = $tabrowid[$id];
320 } else {
321 $rowidcol = "rowid";
322 }
323
324 if ($rowid) {
325 $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol." = ".((int) $rowid);
326 } elseif ($code) {
327 $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$db->escape($code)."'";
328 }
329
330 $result = $db->query($sql);
331 if (!$result) {
332 dol_print_error($db);
333 }
334}
335
336// disable
337if ($action == $acts[1]) {
338 if ($tabrowid[$id]) {
339 $rowidcol = $tabrowid[$id];
340 } else {
341 $rowidcol = "rowid";
342 }
343
344 if ($rowid) {
345 $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol." = ".((int) $rowid);
346 } elseif ($code) {
347 $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$db->escape($code)."'";
348 }
349
350 $result = $db->query($sql);
351 if (!$result) {
352 dol_print_error($db);
353 }
354}
355
356// favorite
357if ($action == 'activate_favorite') {
358 if ($tabrowid[$id]) {
359 $rowidcol = $tabrowid[$id];
360 } else {
361 $rowidcol = "rowid";
362 }
363
364 if ($rowid) {
365 $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol." = ".((int) $rowid);
366 } elseif ($code) {
367 $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".$db->escape($code)."'";
368 }
369
370 $result = $db->query($sql);
371 if (!$result) {
372 dol_print_error($db);
373 }
374}
375
376// disable favorite
377if ($action == 'disable_favorite') {
378 if ($tabrowid[$id]) {
379 $rowidcol = $tabrowid[$id];
380 } else {
381 $rowidcol = "rowid";
382 }
383
384 if ($rowid) {
385 $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol." = ".((int) $rowid);
386 } elseif ($code) {
387 $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".$db->escape($code)."'";
388 }
389
390 $result = $db->query($sql);
391 if (!$result) {
392 dol_print_error($db);
393 }
394}
395
396
397/*
398 * View
399 */
400
401$form = new Form($db);
402$formadmin = new FormAdmin($db);
403
404$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
405
406llxHeader('', $langs->trans("Pcg_version"), $help_url);
407
408$titre = $langs->trans($tablib[$id]);
409$linkback = '';
410
411print load_fiche_titre($titre, $linkback, 'title_accountancy');
412
413
414// Confirmation de la suppression de la ligne
415if ($action == 'delete') {
416 print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.urlencode($page).'&' : '').'sortfield='.urlencode($sortfield).'&sortorder='.urlencode($sortorder).'&rowid='.urlencode($rowid).'&code='.urlencode($code).'&id='.urlencode($id), $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1);
417}
418//var_dump($elementList);
419
420/*
421 * Show a dictionary
422 */
423if ($id) {
424 // Complete requete recherche valeurs avec critere de tri
425 $sql = $tabsql[$id];
426
427 if ($search_country_id > 0) {
428 if (preg_match('/ WHERE /', $sql)) {
429 $sql .= " AND ";
430 } else {
431 $sql .= " WHERE ";
432 }
433 $sql .= " c.rowid = ".((int) $search_country_id);
434 }
435
436 // If sort order is "country", we use country_code instead
437 if ($sortfield == 'country') {
438 $sortfield = 'country_code';
439 }
440 $sql .= $db->order($sortfield, $sortorder);
441 $sql .= $db->plimit($listlimit + 1, $offset);
442 //print $sql;
443
444 $fieldlist = explode(',', $tabfield[$id]);
445
446 print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
447 print '<input type="hidden" name="token" value="'.newToken().'">';
448
449 print '<div class="div-table-responsive">';
450 print '<table class="noborder centpercent">';
451
452 // Form to add a new line
453
454 if ($tabname[$id]) {
455 $fieldlist = explode(',', $tabfield[$id]);
456
457 // Line for title
458 print '<tr class="liste_titre">';
459 foreach ($fieldlist as $field => $value) {
460 // Determine le nom du champ par rapport aux noms possibles
461 // dans les dictionnaires de donnees
462 $valuetoshow = ucfirst($fieldlist[$field]); // Par defaut
463 $valuetoshow = $langs->trans($valuetoshow); // try to translate
464 $class = "left";
465 if ($fieldlist[$field] == 'code') {
466 $valuetoshow = $langs->trans("Code");
467 }
468 if ($fieldlist[$field] == 'label') {
469 $valuetoshow = $langs->trans("Label");
470 $class = 'minwidth300';
471 }
472 if ($fieldlist[$field] == 'country') {
473 if (in_array('region_id', $fieldlist)) {
474 print '<td>&nbsp;</td>';
475 continue;
476 } // For region page, we do not show the country input
477 $valuetoshow = $langs->trans("Country");
478 }
479 if ($fieldlist[$field] == 'country_id') {
480 $valuetoshow = '';
481 }
482 if ($fieldlist[$field] == 'pcg_version' || $fieldlist[$field] == 'fk_pcg_version') {
483 $valuetoshow = $langs->trans("Pcg_version");
484 }
485 //var_dump($value);
486
487 if ($valuetoshow != '') {
488 print '<td class="'.$class.'">';
489 if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
490 print '<a href="'.$tabhelp[$id][$value].'">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
491 } elseif (!empty($tabhelp[$id][$value])) {
492 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
493 } else {
494 print $valuetoshow;
495 }
496 print '</td>';
497 }
498 }
499
500 print '<td>';
501 print '<input type="hidden" name="id" value="'.$id.'">';
502 print '</td>';
503 print '<td></td>';
504 print '<td></td>';
505 print '</tr>';
506
507 // Line to enter new values
508 print '<tr class="oddeven">';
509
510 $obj = new stdClass();
511 // If data was already input, we define them in obj to populate input fields.
512 if (GETPOST('actionadd', 'alpha')) {
513 foreach ($fieldlist as $key => $val) {
514 if (GETPOST($val)) {
515 $obj->$val = GETPOST($val);
516 }
517 }
518 }
519
520 $tmpaction = 'create';
521 $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
522 $reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
523 $error = $hookmanager->error;
524 $errors = $hookmanager->errors;
525
526 if (empty($reshook)) {
527 fieldListAccountModel($fieldlist, $obj, $tabname[$id], 'add');
528 }
529
530 print '<td colspan="3" class="right">';
531 print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'">';
532 print '</td>';
533 print "</tr>";
534
535 $colspan = count($fieldlist) + 3;
536
537 print '<tr><td colspan="'.$colspan.'">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
538 }
539
540
541
542 // List of available values in database
543 dol_syslog("htdocs/admin/dict", LOG_DEBUG);
544 $resql = $db->query($sql);
545 if ($resql) {
546 $num = $db->num_rows($resql);
547 $i = 0;
548
549 $param = '&id='.urlencode($id);
550 if ($search_country_id > 0) {
551 $param .= '&search_country_id='.urlencode($search_country_id);
552 }
553 $paramwithsearch = $param;
554 if ($sortorder) {
555 $paramwithsearch .= '&sortorder='.urlencode($sortorder);
556 }
557 if ($sortfield) {
558 $paramwithsearch .= '&sortfield='.urlencode($sortfield);
559 }
560
561 // There is several pages
562 if ($num > $listlimit) {
563 print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).'">';
564 print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
565 print '</td></tr>';
566 }
567
568 // Title line with search boxes
569 print '<tr class="liste_titre liste_titre_add">';
570 foreach ($fieldlist as $field => $value) {
571 $showfield = 1; // By defaut
572
573 if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
574 $showfield = 0;
575 }
576
577 if ($showfield) {
578 if ($value == 'country') {
579 print '<td class="liste_titre">';
580 print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth200 maxwidthonsmartphone');
581 print '</td>';
582 } else {
583 print '<td class="liste_titre"></td>';
584 }
585 }
586 }
587 print '<td class="liste_titre"></td>';
588 print '<td class="liste_titre right" colspan="2">';
589 $searchpicto = $form->showFilterAndCheckAddButtons(0);
590 print $searchpicto;
591 print '</td>';
592 print '</tr>';
593
594 // Title of lines
595 print '<tr class="liste_titre">';
596 print getTitleFieldOfList($langs->trans("Pcg_version"), 0, $_SERVER["PHP_SELF"], "pcg_version", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
597 print getTitleFieldOfList($langs->trans("Label"), 0, $_SERVER["PHP_SELF"], "label", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
598 print getTitleFieldOfList($langs->trans("Country"), 0, $_SERVER["PHP_SELF"], "country_code", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
599 print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
600 print getTitleFieldOfList('');
601 print getTitleFieldOfList('');
602 print '</tr>';
603
604 if ($num) {
605 $i = 0;
606 // Lines with values
607 while ($i < $num) {
608 $obj = $db->fetch_object($resql);
609 //print_r($obj);
610
611 print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
612 if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
613 print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
614 print '<input type="hidden" name="token" value="'.newToken().'">';
615 print '<input type="hidden" name="page" value="'.$page.'">';
616 print '<input type="hidden" name="rowid" value="'.$rowid.'">';
617
618 $tmpaction = 'edit';
619 $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
620 $reshook = $hookmanager->executeHooks('editDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
621 $error = $hookmanager->error;
622 $errors = $hookmanager->errors;
623
624 if (empty($reshook)) {
625 fieldListAccountModel($fieldlist, $obj, $tabname[$id], 'edit');
626 }
627
628 print '<td colspan="3" class="right">';
629 print '<a name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'">&nbsp;</a><input type="submit" class="button button-edit" name="actionmodify" value="'.$langs->trans("Modify").'">';
630 print '&nbsp;<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
631 print '</td>';
632 } else {
633 $tmpaction = 'view';
634 $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
635 $reshook = $hookmanager->executeHooks('viewDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
636
637 $error = $hookmanager->error;
638 $errors = $hookmanager->errors;
639
640 if (empty($reshook)) {
641 foreach ($fieldlist as $field => $value) {
642 $showfield = 1;
643 $class = "left";
644 $tmpvar = $fieldlist[$field];
645 $valuetoshow = $obj->$tmpvar;
646 if ($value == 'type_template') {
647 $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
648 }
649 if ($value == 'element') {
650 $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
651 } elseif ($value == 'source') {
652 $valuetoshow = isset($sourceList[$valuetoshow]) ? $sourceList[$valuetoshow] : $valuetoshow;
653 } elseif ($valuetoshow == 'all') {
654 $valuetoshow = $langs->trans('All');
655 } elseif ($fieldlist[$field] == 'country') {
656 if (empty($obj->country_code)) {
657 $valuetoshow = '-';
658 } else {
659 $key = $langs->trans("Country".strtoupper($obj->country_code));
660 $valuetoshow = ($key != "Country".strtoupper($obj->country_code) ? $obj->country_code." - ".$key : $obj->country);
661 }
662 } elseif ($fieldlist[$field] == 'country_id') {
663 $showfield = 0;
664 }
665
666 $class = 'tddict';
667 if ($fieldlist[$field] == 'tracking') {
668 $class .= ' tdoverflowauto';
669 }
670 // Show value for field
671 if ($showfield) {
672 print '<!-- '.$fieldlist[$field].' --><td class="'.$class.'">'.$valuetoshow.'</td>';
673 }
674 }
675 }
676
677 // Can an entry be erased or disabled ?
678 $iserasable = 1;
679 $canbedisabled = 1;
680 $canbemodified = 1; // true by default
681
682 $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) : '');
683 if ($param) {
684 $url .= '&'.$param;
685 }
686 $url .= '&';
687
688 // Active
689 print '<td class="center nowrap">';
690 if ($canbedisabled) {
691 print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
692 } else {
693 print $langs->trans("AlwaysActive");
694 }
695 print "</td>";
696
697 // Modify link
698 if ($canbemodified) {
699 print '<td class="center"><a class="reposition editfielda" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a></td>';
700 } else {
701 print '<td>&nbsp;</td>';
702 }
703
704 // Delete link
705 if ($iserasable) {
706 print '<td class="center"><a href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a></td>';
707 } else {
708 print '<td>&nbsp;</td>';
709 }
710
711 print "</tr>\n";
712 }
713
714 $i++;
715 }
716 } else {
717 print '<tr><td colspan="6"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
718 }
719 } else {
720 dol_print_error($db);
721 }
722
723 print '</table>';
724 print '</div>';
725
726 print '</form>';
727}
728
729print '<br>';
730
731// End of page
732llxFooter();
733$db->close();
734
735
745function fieldListAccountModel($fieldlist, $obj = null, $tabname = '', $context = '')
746{
747 global $langs, $db;
748 global $form;
749 global $elementList, $sourceList;
750
751 $formadmin = new FormAdmin($db);
752 $formcompany = new FormCompany($db);
753 $formaccounting = new FormAccounting($db);
754
755 foreach ($fieldlist as $field => $value) {
756 if ($fieldlist[$field] == 'country') {
757 if (in_array('region_id', $fieldlist)) {
758 print '<td>';
759 //print join(',',$fieldlist);
760 print '</td>';
761 continue;
762 } // For state page, we do not show the country input (we link to region, not country)
763 print '<td>';
764 $fieldname = 'country';
765 print $form->select_country((!empty($obj->country_code) ? $obj->country_code : (!empty($obj->country) ? $obj->country : '')), $fieldname, '', 28, 'maxwidth200 maxwidthonsmartphone');
766 print '</td>';
767 } elseif ($fieldlist[$field] == 'country_id') {
768 if (!in_array('country', $fieldlist)) { // If there is already a field country, we don't show country_id (avoid duplicate)
769 $country_id = (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
770 print '<td>';
771 print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">';
772 print '</td>';
773 }
774 } elseif ($fieldlist[$field] == 'type_cdr') {
775 if ($fieldlist[$field] == 'type_cdr') {
776 print '<td class="center">';
777 } else {
778 print '<td>';
779 }
780 if ($fieldlist[$field] == 'type_cdr') {
781 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]} : ''));
782 } else {
783 print $form->selectyesno($fieldlist[$field], (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : ''), 1);
784 }
785 print '</td>';
786 } elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
787 print '<td><input type="text" class="flat" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" size="10" name="'.$fieldlist[$field].'"></td>';
788 } else {
789 print '<td>';
790 $class = '';
791 if ($fieldlist[$field] == 'pcg_version') {
792 $class = 'width150';
793 }
794 if ($fieldlist[$field] == 'label') {
795 $class = 'width300';
796 }
797 print '<input type="text" class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" name="'.$fieldlist[$field].'">';
798 print '</td>';
799 }
800 }
801}
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($titre, $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.
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 '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier 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.