dolibarr 21.0.0-alpha
journals_list.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017-2024 Alexandre Spangaro <aspangaro@easya.solutions>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 *
19 */
20
27if (!defined('CSRFCHECK_WITH_TOKEN')) {
28 define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
29}
30
31// Load Dolibarr environment
32require '../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
40
41// Load translation files required by the page
42$langs->loadLangs(array("admin", "compta", "accountancy"));
43
44$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view';
45$confirm = GETPOST('confirm', 'alpha');
46$id = 35;
47$rowid = GETPOST('rowid', 'alpha');
48$code = GETPOST('code', 'alpha');
49
50// Security access
51if (!$user->hasRight('accounting', 'chartofaccount')) {
53}
54
55$acts = array();
56$acts[0] = "activate";
57$acts[1] = "disable";
58$actl = array();
59$actl[0] = img_picto($langs->trans("Disabled"), 'switch_off', 'class="size15x"');
60$actl[1] = img_picto($langs->trans("Activated"), 'switch_on', 'class="size15x"');
61
62$listoffset = GETPOST('listoffset', 'alpha');
63$listlimit = GETPOSTINT('listlimit') > 0 ? GETPOSTINT('listlimit') : 1000;
64$active = 1;
65
66$sortfield = GETPOST('sortfield', 'aZ09comma');
67$sortorder = GETPOST('sortorder', 'aZ09comma');
68$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
69if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
70 // If $page is not defined, or '' or -1 or if we click on clear filters
71 $page = 0;
72}
73$offset = $listlimit * $page;
74$pageprev = $page - 1;
75$pagenext = $page + 1;
76if (empty($sortfield)) {
77 $sortfield = 'code';
78}
79if (empty($sortorder)) {
80 $sortorder = 'ASC';
81}
82
83$error = 0;
84
85$search_country_id = GETPOST('search_country_id', 'int');
86
87// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an 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// Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this.
94$taborder = array(35);
95
96// Name of SQL tables of dictionaries
97$tabname = array();
98$tabname[35] = MAIN_DB_PREFIX."accounting_journal";
99
100// Dictionary labels
101$tablib = array();
102$tablib[35] = "DictionaryAccountancyJournal";
103
104// Requests to extract data
105$tabsql = array();
106$tabsql[35] = "SELECT a.rowid as rowid, a.code as code, a.label, a.nature, a.active FROM ".MAIN_DB_PREFIX."accounting_journal as a";
107
108// Criteria to sort dictionaries
109$tabsqlsort = array();
110$tabsqlsort[35] = "code ASC";
111
112// Nom des champs en resultat de select pour affichage du dictionnaire
113$tabfield = array();
114$tabfield[35] = "code,label,nature";
115
116// Nom des champs d'edition pour modification d'un enregistrement
117$tabfieldvalue = array();
118$tabfieldvalue[35] = "code,label,nature";
119
120// Nom des champs dans la table pour insertion d'un enregistrement
121$tabfieldinsert = array();
122$tabfieldinsert[35] = "code,label,nature";
123
124// Nom du rowid si le champ n'est pas de type autoincrement
125// Example: "" if id field is "rowid" and has autoincrement on
126// "nameoffield" if id field is not "rowid" or has not autoincrement on
127$tabrowid = array();
128$tabrowid[35] = "";
129
130// Condition to show dictionary in setup page
131$tabcond = array();
132$tabcond[35] = isModEnabled('accounting');
133
134// List of help for fields
135$tabhelp = array();
136$tabhelp[35] = array('code' => $langs->trans("EnterAnyCode"));
137
138// List of check for fields (NOT USED YET)
139$tabfieldcheck = array();
140$tabfieldcheck[35] = array();
141
142// Complete all arrays with entries found into modules
143complete_dictionary_with_modules($taborder, $tabname, $tablib, $tabsql, $tabsqlsort, $tabfield, $tabfieldvalue, $tabfieldinsert, $tabrowid, $tabcond, $tabhelp, $tabfieldcheck);
144
145
146// Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
147$elementList = array();
148// Must match ids defined into eldy.lib.php
149$sourceList = array(
150 '1' => $langs->trans('AccountingJournalType1'),
151 '2' => $langs->trans('AccountingJournalType2'),
152 '3' => $langs->trans('AccountingJournalType3'),
153 '4' => $langs->trans('AccountingJournalType4'),
154 '5' => $langs->trans('AccountingJournalType5'),
155 '8' => $langs->trans('AccountingJournalType8'),
156 '9' => $langs->trans('AccountingJournalType9'),
157);
158
159/*
160 * Actions
161 */
162
163if (GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter_x', 'alpha')) {
164 $search_country_id = '';
165}
166
167// Actions add or modify an entry into a dictionary
168if (GETPOST('actionadd', 'alpha') || GETPOST('actionmodify', 'alpha')) {
169 $listfield = explode(',', str_replace(' ', '', $tabfield[$id]));
170 $listfieldinsert = explode(',', $tabfieldinsert[$id]);
171 $listfieldmodify = explode(',', $tabfieldinsert[$id]);
172 $listfieldvalue = explode(',', $tabfieldvalue[$id]);
173
174 // Check that all fields are filled
175 $ok = 1;
176
177 // Other checks
178 if (GETPOSTISSET("code")) {
179 if (GETPOST("code") == '0') {
180 $ok = 0;
181 setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
182 }
183 }
184 if (!GETPOST('label', 'alpha')) {
185 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
186 $ok = 0;
187 }
188
189 // Si verif ok et action add, on ajoute la ligne
190 if ($ok && GETPOST('actionadd', 'alpha')) {
191 $newid = 0; // Initialise before if for static analysis
192 if ($tabrowid[$id]) {
193 // Get free id for insert
194 $sql = "SELECT MAX(".$db->sanitize($tabrowid[$id]).") 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 .= $tabrowid[$id].",";
209 }
210 $sql .= $db->sanitize($tabfieldinsert[$id]);
211 $sql .= ",active,entity)";
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 ($i) {
221 $sql .= ",";
222 }
223 if (GETPOST($listfieldvalue[$i]) == '') {
224 $sql .= "null"; // For vat, we want/accept code = ''
225 } else {
226 $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
227 }
228 $i++;
229 }
230 $sql .= ",1,".$conf->entity.")";
231
232 dol_syslog("actionadd", LOG_DEBUG);
233 $result = $db->query($sql);
234 if ($result) { // Add is ok
235 setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
236 $_POST = array('id' => $id); // Clean $_POST array, we keep only id
237 } else {
238 if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
239 setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
240 } else {
241 dol_print_error($db);
242 }
243 }
244 }
245
246 // Si verif ok et action modify, on modifie la ligne
247 if ($ok && GETPOST('actionmodify', 'alpha')) {
248 if ($tabrowid[$id]) {
249 $rowidcol = $tabrowid[$id];
250 } else {
251 $rowidcol = "rowid";
252 }
253
254 // Modify entry
255 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET ";
256 // Modifie valeur des champs
257 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
258 $sql .= $db->sanitize($tabrowid[$id])." = ";
259 $sql .= "'".$db->escape($rowid)."', ";
260 }
261 $i = 0;
262 foreach ($listfieldmodify as $field) {
263 if ($i) {
264 $sql .= ",";
265 }
266 $sql .= $field." = ";
267 $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
268 $i++;
269 }
270 $sql .= " WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
271 $sql .= " AND entity = ".((int) $conf->entity);
272
273 dol_syslog("actionmodify", LOG_DEBUG);
274 //print $sql;
275 $resql = $db->query($sql);
276 if (!$resql) {
277 setEventMessages($db->error(), null, 'errors');
278 }
279 }
280}
281
282if ($action == 'confirm_delete' && $confirm == 'yes') { // delete
283 if ($tabrowid[$id]) {
284 $rowidcol = $tabrowid[$id];
285 } else {
286 $rowidcol = "rowid";
287 }
288
289 $sql = "DELETE from ".$db->sanitize($tabname[$id])." WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
290 $sql .= " AND entity = ".((int) $conf->entity);
291
292 dol_syslog("delete", LOG_DEBUG);
293 $result = $db->query($sql);
294 if (!$result) {
295 if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
296 setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
297 } else {
298 dol_print_error($db);
299 }
300 }
301}
302
303// activate
304if ($action == $acts[0]) {
305 if ($tabrowid[$id]) {
306 $rowidcol = $tabrowid[$id];
307 } else {
308 $rowidcol = "rowid";
309 }
310
311 if ($rowid) {
312 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 1 WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
313 } elseif ($code) {
314 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 1 WHERE code = '".$db->escape($code)."'";
315 }
316 $sql .= " AND entity = ".$conf->entity;
317
318 $result = $db->query($sql);
319 if (!$result) {
320 dol_print_error($db);
321 }
322}
323
324// disable
325if ($action == $acts[1]) {
326 if ($tabrowid[$id]) {
327 $rowidcol = $tabrowid[$id];
328 } else {
329 $rowidcol = "rowid";
330 }
331
332 if ($rowid) {
333 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 0 WHERE ".$db->sanitize($rowidcol)." = ".((int) $rowid);
334 } elseif ($code) {
335 $sql = "UPDATE ".$db->sanitize($tabname[$id])." SET active = 0 WHERE code='".$db->escape($code)."'";
336 }
337 $sql .= " AND entity = ".$conf->entity;
338
339 $result = $db->query($sql);
340 if (!$result) {
341 dol_print_error($db);
342 }
343}
344
345
346/*
347 * View
348 */
349
350$form = new Form($db);
351$formadmin = new FormAdmin($db);
352
353$title = $langs->trans('AccountingJournals');
354$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
355llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-accountancy page-admin_journals_list');
356
357$titre = $langs->trans("DictionarySetup");
358$linkback = '';
359if ($id) {
360 $titre .= ' - '.$langs->trans($tablib[$id]);
361 $titlepicto = 'title_accountancy';
362} else {
363 $titlepicto = '';
364}
365
366print load_fiche_titre($titre, $linkback, $titlepicto);
367
368
369// Confirmation de la suppression de la ligne
370if ($action == 'delete') {
371 print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$code.'&id='.$id, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1);
372}
373
374/*
375 * Show a dictionary
376 */
377if ($id) {
378 // Complete requete recherche valeurs avec critere de tri
379 $sql = $tabsql[$id];
380 $sql .= " WHERE a.entity = ".((int) $conf->entity);
381
382 // If sort order is "country", we use country_code instead
383 if ($sortfield == 'country') {
384 $sortfield = 'country_code';
385 }
386 $sql .= $db->order($sortfield, $sortorder);
387 $sql .= $db->plimit($listlimit + 1, $offset);
388
389 $fieldlist = explode(',', $tabfield[$id]);
390
391 print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
392 print '<input type="hidden" name="token" value="'.newToken().'">';
393 print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
394
395 print '<div class="div-table-responsive">';
396 print '<table class="noborder centpercent">';
397
398 // Form to add a new line
399 if ($tabname[$id]) {
400 $fieldlist = explode(',', $tabfield[$id]);
401
402 // Line for title
403 print '<tr class="liste_titre">';
404 foreach ($fieldlist as $field => $value) {
405 // Determine le nom du champ par rapport aux noms possibles
406 // dans les dictionnaires de donnees
407 $valuetoshow = ucfirst($fieldlist[$field]); // By default
408 $valuetoshow = $langs->trans($valuetoshow); // try to translate
409 $class = "left";
410 if ($fieldlist[$field] == 'code') {
411 $valuetoshow = $langs->trans("Code");
412 }
413 if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
414 $valuetoshow = $langs->trans("Label");
415 }
416 if ($fieldlist[$field] == 'nature') {
417 $valuetoshow = $langs->trans("NatureOfJournal");
418 }
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
433 print '<td>';
434 print '<input type="hidden" name="id" value="'.$id.'">';
435 print '</td>';
436 print '<td></td>';
437 print '<td></td>';
438 print '<td></td>';
439 print '</tr>';
440
441 // Line to enter new values
442 print '<tr class="oddeven nodrag nodrop nohover">';
443
444 $obj = new stdClass();
445 // If data was already input, we define them in obj to populate input fields.
446 if (GETPOST('actionadd', 'alpha')) {
447 foreach ($fieldlist as $key => $val) {
448 if (GETPOST($val) != '') {
449 $obj->$val = GETPOST($val);
450 }
451 }
452 }
453
454 $tmpaction = 'create';
455 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
456 $reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
457 $error = $hookmanager->error;
458 $errors = $hookmanager->errors;
459
460 if (empty($reshook)) {
461 fieldListJournal($fieldlist, $obj, $tabname[$id], 'add');
462 }
463
464 print '<td colspan="4" class="right">';
465 print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'">';
466 print '</td>';
467 print "</tr>";
468
469 print '<tr><td colspan="7">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
470 }
471
472
473
474 // List of available record in database
475 dol_syslog("htdocs/admin/dict", LOG_DEBUG);
476 $resql = $db->query($sql);
477 if ($resql) {
478 $num = $db->num_rows($resql);
479 $i = 0;
480
481 $param = '&id='.((int) $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='.$sortorder;
488 }
489 if ($sortfield) {
490 $paramwithsearch .= '&sortfield='.$sortfield;
491 }
492 if (GETPOST('from', 'alpha')) {
493 $paramwithsearch .= '&from='.GETPOST('from', 'alpha');
494 }
495
496 // There is several pages
497 if ($num > $listlimit) {
498 print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).'">';
499 print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit ? 1 : 0), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
500 print '</td></tr>';
501 }
502
503 // Title line with search boxes
504 /*print '<tr class="liste_titre_filter liste_titre_add">';
505 print '<td class="liste_titre"></td>';
506 print '<td class="liste_titre"></td>';
507 print '<td class="liste_titre"></td>';
508 print '<td class="liste_titre"></td>';
509 print '<td class="liste_titre"></td>';
510 print '<td class="liste_titre"></td>';
511 print '<td class="liste_titre center">';
512 $searchpicto=$form->showFilterButtons();
513 print $searchpicto;
514 print '</td>';
515 print '</tr>';
516 */
517
518 // Title of lines
519 print '<tr class="liste_titre liste_titre_add">';
520 foreach ($fieldlist as $field => $value) {
521 // Determine le nom du champ par rapport aux noms possibles
522 // dans les dictionnaires de donnees
523 $showfield = 1; // By default
524 $class = "left";
525 $sortable = 1;
526 $valuetoshow = '';
527 /*
528 $tmparray=getLabelOfField($fieldlist[$field]);
529 $showfield=$tmp['showfield'];
530 $valuetoshow=$tmp['valuetoshow'];
531 $align=$tmp['align'];
532 $sortable=$tmp['sortable'];
533 */
534 $valuetoshow = ucfirst($fieldlist[$field]); // By default
535 $valuetoshow = $langs->trans($valuetoshow); // try to translate
536 if ($fieldlist[$field] == 'code') {
537 $valuetoshow = $langs->trans("Code");
538 }
539 if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
540 $valuetoshow = $langs->trans("Label");
541 }
542 if ($fieldlist[$field] == 'nature') {
543 $valuetoshow = $langs->trans("NatureOfJournal");
544 }
545
546 // Affiche nom du champ
547 if ($showfield) {
548 print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable ? $fieldlist[$field] : ''), ($page ? 'page='.$page.'&' : ''), $param, "", $sortfield, $sortorder, $class.' ');
549 }
550 }
551 print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
552 print getTitleFieldOfList('');
553 print getTitleFieldOfList('');
554 print getTitleFieldOfList('');
555 print '</tr>';
556
557 if ($num) {
558 // Lines with values
559 while ($i < $num) {
560 $obj = $db->fetch_object($resql);
561 //print_r($obj);
562 print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
563 if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
564 $tmpaction = 'edit';
565 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
566 $reshook = $hookmanager->executeHooks('editDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
567 $error = $hookmanager->error;
568 $errors = $hookmanager->errors;
569
570 // Show fields
571 if (empty($reshook)) {
572 fieldListJournal($fieldlist, $obj, $tabname[$id], 'edit');
573 }
574
575 print '<td class="center" colspan="4">';
576 print '<input type="hidden" name="page" value="'.$page.'">';
577 print '<input type="hidden" name="rowid" value="'.$rowid.'">';
578 print '<input type="submit" class="button button-edit" name="actionmodify" value="'.$langs->trans("Modify").'">';
579 print '<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
580 print '<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'"></div>';
581 print '</td>';
582 } else {
583 $tmpaction = 'view';
584 $parameters = array('fieldlist' => $fieldlist, 'tabname' => $tabname[$id]);
585 $reshook = $hookmanager->executeHooks('viewDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
586
587 $error = $hookmanager->error;
588 $errors = $hookmanager->errors;
589
590 if (empty($reshook)) {
591 $langs->load("accountancy");
592 foreach ($fieldlist as $field => $value) {
593 $showfield = 1;
594 $class = "left";
595 $tmpvar = $fieldlist[$field];
596 $valuetoshow = $obj->$tmpvar;
597 if ($valuetoshow == 'all') {
598 $valuetoshow = $langs->trans('All');
599 } elseif ($fieldlist[$field] == 'nature' && $tabname[$id] == MAIN_DB_PREFIX.'accounting_journal') {
600 $key = $langs->trans("AccountingJournalType".strtoupper($obj->nature));
601 $valuetoshow = ($obj->nature && $key != "AccountingJournalType".strtoupper($langs->trans($obj->nature)) ? $key : $obj->{$fieldlist[$field]});
602 } elseif ($fieldlist[$field] == 'label' && $tabname[$id] == MAIN_DB_PREFIX.'accounting_journal') {
603 $valuetoshow = $langs->trans($obj->label);
604 }
605
606 $class = 'tddict';
607 // Show value for field
608 if ($showfield) {
609 print '<!-- '.$fieldlist[$field].' --><td class="'.$class.'">'.dol_escape_htmltag($valuetoshow).'</td>';
610 }
611 }
612 }
613
614 // Can an entry be erased or disabled ?
615 $iserasable = 1;
616 $canbedisabled = 1;
617 $canbemodified = 1; // true by default
618 if (isset($obj->code) && $id != 10) {
619 if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i', $obj->code))) {
620 $iserasable = 0;
621 $canbedisabled = 0;
622 }
623 }
624
625 $canbemodified = $iserasable;
626
627 $url = $_SERVER["PHP_SELF"].'?'.($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) : '');
628 if ($param) {
629 $url .= '&'.$param;
630 }
631 $url .= '&';
632
633 // Active
634 print '<td class="nowrap center">';
635 if ($canbedisabled) {
636 print '<a href="'.$url.'action='.$acts[$obj->active].'&token='.newToken().'">'.$actl[$obj->active].'</a>';
637 } else {
638 print $langs->trans("AlwaysActive");
639 }
640 print "</td>";
641
642 // Modify link
643 if ($canbemodified) {
644 print '<td class="center"><a class="reposition editfielda" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a></td>';
645 } else {
646 print '<td>&nbsp;</td>';
647 }
648
649 // Delete link
650 if ($iserasable) {
651 print '<td class="center">';
652 if ($user->admin) {
653 print '<a href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a>';
654 }
655 //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
656 print '</td>';
657 } else {
658 print '<td>&nbsp;</td>';
659 }
660
661 print '<td></td>';
662
663 print '</td>';
664 }
665
666 print "</tr>\n";
667 $i++;
668 }
669 }
670 } else {
671 dol_print_error($db);
672 }
673
674 print '</table>';
675 print '</div>';
676
677 print '</form>';
678}
679
680print '<br>';
681
682// End of page
683llxFooter();
684$db->close();
685
686
696function fieldListJournal($fieldlist, $obj = null, $tabname = '', $context = '')
697{
698 global $conf, $langs, $db;
699 global $form, $mysoc;
700 global $region_id;
701 global $elementList, $sourceList, $localtax_typeList;
702 global $bc;
703
704 $formadmin = new FormAdmin($db);
705 $formcompany = new FormCompany($db);
706
707 foreach ($fieldlist as $field => $value) {
708 if ($fieldlist[$field] == 'nature') {
709 print '<td>';
710 print $form->selectarray('nature', $sourceList, (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : ''));
711 print '</td>';
712 } elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
713 print '<td><input type="text" class="flat minwidth100" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" name="'.$fieldlist[$field].'"></td>';
714 } else {
715 print '<td>';
716 $size = '';
717 $class = '';
718 if ($fieldlist[$field] == 'code') {
719 $class = 'maxwidth100';
720 }
721 if ($fieldlist[$field] == 'label') {
722 $class = 'quatrevingtpercent';
723 }
724 if ($fieldlist[$field] == 'sortorder' || $fieldlist[$field] == 'sens' || $fieldlist[$field] == 'category_type') {
725 $size = 'size="2" ';
726 }
727 print '<input type="text" '.$size.'class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" name="'.$fieldlist[$field].'">';
728 print '</td>';
729 }
730 }
731}
$id
Definition account.php:39
complete_dictionary_with_modules(&$taborder, &$tabname, &$tablib, &$tabsql, &$tabsqlsort, &$tabfield, &$tabfieldvalue, &$tabfieldinsert, &$tabrowid, &$tabcond, &$tabhelp, &$tabcomplete)
Add external modules to list of dictionaries.
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 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.
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
fieldListJournal($fieldlist, $obj=null, $tabname='', $context='')
Show fields in insert/edit mode.
$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.