dolibarr 22.0.5
categ.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2013 Charles-Fr BENKE <charles.fr@benke.fr>
6 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
7 * Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
8 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31// TODO Remove this file, this page is replaced by standard view categorie page
32
33// Load Dolibarr environment
34require '../../main.inc.php';
35require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
36require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
37
38
47// Load translation files required by the page
48$langs->loadLangs(array('banks', 'categories'));
49
50
51// Get Parameters
52$action = GETPOST('action', 'aZ09');
53$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
54$categid = GETPOST('categid');
55$label = GETPOST("label");
56
57
58// Initialize a technical objects
59$bankcateg = new BankCateg($db);
60
61
62// Security Check Access Control
63if (!$user->hasRight('banque', 'configurer')) {
65}
66
67
68
69/*
70 * Actions
71 */
72
73if (GETPOST('add')) {
74 if ($label) {
75 $bankcateg = new BankCateg($db);
76 $bankcateg->label = GETPOST('label');
77 $bankcateg->create($user);
78 }
79}
80
81if ($categid) {
82 $bankcateg = new BankCateg($db);
83
84 if ($bankcateg->fetch((int) $categid) > 0) {
85 //Update category
86 if (GETPOST('update') && $label) {
87 $bankcateg->label = $label;
88 $bankcateg->update($user);
89 }
90 //Delete category
91 if ($action == 'delete' && $user->hasRight('banque', 'configurer')) {
92 $bankcateg->delete($user);
93 }
94 }
95}
96
97
98/*
99 * View
100 */
101
102$title = $langs->trans('RubriquesTransactions');
103$help_url = 'EN:Module_Banks_and_Cash|FR:Module_Banques_et_Caisses|ES:M&oacute;dulo_Bancos_y_Cajas';
104
105llxHeader('', $title, $help_url);
106
107
108print load_fiche_titre($langs->trans("RubriquesTransactions"), '', 'object_category');
109
110print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
111if ($optioncss != '') {
112 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
113}
114print '<input type="hidden" name="token" value="'.newToken().'">';
115print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
116print '<input type="hidden" name="action" value="list">';
117/*print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
118print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
119print '<input type="hidden" name="page" value="'.$page.'">';
120print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
121*/
122
123print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
124print '<table class="noborder centpercent">';
125print '<tr class="liste_titre">';
126print '<td>'.$langs->trans("Ref").'</td><td>'.$langs->trans("Label").'</td>';
127print '<td></td>';
128print '<td></td>';
129print "</tr>\n";
130
131// Line to add category
132if ($action != 'edit') {
133 print '<tr class="oddeven">';
134 print '<td>&nbsp;</td><td><input name="label" type="text" class="maxwidth100"></td>';
135 print '<td></td>';
136 print '<td class="center"><input type="submit" name="add" class="button button-add small" value="'.$langs->trans("Add").'"></td>';
137 print '</tr>';
138}
139
140// Get bank line categorie ID
141include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
142$cats = new Categorie($db);
143$catTypeID = $cats->getMapId()[Categorie::TYPE_BANK_LINE];
144
145$sql = "SELECT rowid, label";
146$sql .= " FROM ".MAIN_DB_PREFIX."categorie";
147$sql .= " WHERE entity = ".$conf->entity." AND type = " . ((int) $catTypeID);
148$sql .= " ORDER BY rowid";
149
150$result = $db->query($sql);
151if ($result) {
152 $num = $db->num_rows($result);
153 $i = 0;
154 $total = 0;
155
156 while ($i < $num) {
157 $objp = $db->fetch_object($result);
158
159 print '<tr class="oddeven">';
160 print '<td>'.$objp->rowid.'</td>';
161 if (GETPOST('action', 'aZ09') == 'edit' && GETPOST("categid") == $objp->rowid) {
162 print '<td colspan="3">';
163 print '<input type="hidden" name="categid" value="'.$objp->rowid.'">';
164 print '<input name="label" type="text" size=45 value="'.$objp->label.'">';
165 print '<input type="submit" name="update" class="button" value="'.$langs->trans("Edit").'">';
166 print "</td>";
167 } else {
168 print "<td>".$objp->label."</td>";
169 print '<td>';
170 //print '<a href="'.DOL_URL_ROOT.'/compta/bank/budget.php?bid='.$objp->rowid.'">'.$langs->trans("List").'</a>';
171 print '</td>';
172 print '<td class="center">';
173 print '<a class="editfielda reposition marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
174 print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
175 print '</td>';
176 }
177 print "</tr>";
178 $i++;
179 }
180 $db->free($result);
181}
182
183print '</table>';
184print '</div>';
185
186print '</form>';
187
188// End of page
189llxFooter();
190$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to manage bank categories.
Class to manage categories.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.