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