dolibarr 25.0.0-alpha
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-2026 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2025-2026 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 $result = $bankcateg->create($user);
78 if ($result < 0) {
79 setEventMessages($bankcateg->error, $bankcateg->errors, 'errors');
80 }
81 }
82}
83
84if ($categid) {
85 $bankcateg = new BankCateg($db);
86
87 if ($bankcateg->fetch((int) $categid) > 0) {
88 //Update category
89 if (GETPOST('update') && $label) {
90 $bankcateg->label = $label;
91 $result = $bankcateg->update($user);
92 if ($result < 0) {
93 setEventMessages($bankcateg->error, $bankcateg->errors, 'errors');
94 }
95 }
96 //Delete category
97 if ($action == 'delete' && $user->hasRight('banque', 'configurer')) {
98 $result = $bankcateg->delete($user);
99 if ($result < 0) {
100 setEventMessages($bankcateg->error, $bankcateg->errors, 'errors');
101 }
102 }
103 }
104}
105
106
107/*
108 * View
109 */
110
111$title = $langs->trans('RubriquesTransactions');
112$help_url = 'EN:Module_Banks_and_Cash|FR:Module_Banques_et_Caisses|ES:M&oacute;dulo_Bancos_y_Cajas';
113
114llxHeader('', $title, $help_url);
115
116
117print load_fiche_titre($langs->trans("RubriquesTransactions"), '', 'object_category');
118
119print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
120if ($optioncss != '') {
121 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
122}
123print '<input type="hidden" name="token" value="'.newToken().'">';
124print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
125print '<input type="hidden" name="action" value="list">';
126/*print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
127print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
128print '<input type="hidden" name="page" value="'.$page.'">';
129print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
130*/
131
132print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
133print '<table class="noborder centpercent">';
134print '<tr class="liste_titre">';
135print '<td>'.$langs->trans("Ref").'</td><td>'.$langs->trans("Label").'</td>';
136print '<td></td>';
137print '<td></td>';
138print "</tr>\n";
139
140// Line to add category
141if ($action != 'edit') {
142 print '<tr class="oddeven">';
143 print '<td>&nbsp;</td><td><input name="label" type="text" class="maxwidth100"></td>';
144 print '<td></td>';
145 print '<td class="center"><input type="submit" name="add" class="button button-add small" value="'.$langs->trans("Add").'"></td>';
146 print '</tr>';
147}
148
149// Get bank line categorie ID
150include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
151$cats = new Categorie($db);
152$catTypeID = $cats->getMapId()[Categorie::TYPE_BANK_LINE];
153
154$sql = "SELECT rowid, label";
155$sql .= " FROM ".MAIN_DB_PREFIX."categorie";
156$sql .= " WHERE entity = ".((int) $conf->entity)." AND type = " . ((int) $catTypeID);
157$sql .= " ORDER BY rowid";
158
159$result = $db->query($sql);
160if ($result) {
161 $num = $db->num_rows($result);
162 $i = 0;
163 $total = 0;
164
165 while ($i < $num) {
166 $objp = $db->fetch_object($result);
167
168 print '<tr class="oddeven">';
169 print '<td>'.$objp->rowid.'</td>';
170 if (GETPOST('action', 'aZ09') == 'edit' && GETPOST("categid") == $objp->rowid) {
171 print '<td colspan="3">';
172 print '<input type="hidden" name="categid" value="'.$objp->rowid.'">';
173 print '<input name="label" type="text" size=45 value="'.$objp->label.'">';
174 print '<input type="submit" name="update" class="button" value="'.$langs->trans("Edit").'">';
175 print "</td>";
176 } else {
177 print "<td>".$objp->label."</td>";
178 print '<td>';
179 //print '<a href="'.DOL_URL_ROOT.'/compta/bank/budget.php?bid='.$objp->rowid.'">'.$langs->trans("List").'</a>';
180 print '</td>';
181 print '<td class="center">';
182 print '<a class="editfielda reposition marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
183 print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
184 print '</td>';
185 }
186 print "</tr>";
187 $i++;
188 }
189 $db->free($result);
190}
191
192print '</table>';
193print '</div>';
194
195print '</form>';
196
197// End of page
198llxFooter();
199$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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.