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