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