dolibarr 21.0.0-beta
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 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// TODO Remove this file, this page is replaced by standard view categorie page
31
32// Load Dolibarr environment
33require '../../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
35require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
36
37
46// Load translation files required by the page
47$langs->loadLangs(array('banks', 'categories'));
48
49
50// Get Parameters
51$action = GETPOST('action', 'aZ09');
52$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
53$categid = GETPOST('categid');
54$label = GETPOST("label");
55
56
57// Initialize a technical objects
58$bankcateg = new BankCateg($db);
59
60
61// Security Check Access Control
62if (!$user->hasRight('banque', 'configurer')) {
64}
65
66
67
68/*
69 * Actions
70 */
71
72if (GETPOST('add')) {
73 if ($label) {
74 $bankcateg = new BankCateg($db);
75 $bankcateg->label = GETPOST('label');
76 $bankcateg->create($user);
77 }
78}
79
80if ($categid) {
81 $bankcateg = new BankCateg($db);
82
83 if ($bankcateg->fetch($categid) > 0) {
84 //Update category
85 if (GETPOST('update') && $label) {
86 $bankcateg->label = $label;
87 $bankcateg->update($user);
88 }
89 //Delete category
90 if ($action == 'delete' && $user->hasRight('banque', 'configurer')) {
91 $bankcateg->delete($user);
92 }
93 }
94}
95
96
97/*
98 * View
99 */
100
101$title = $langs->trans('RubriquesTransactions');
102$help_url = 'EN:Module_Banks_and_Cash|FR:Module_Banques_et_Caisses|ES:M&oacute;dulo_Bancos_y_Cajas';
103
104llxHeader('', $title, $help_url);
105
106
107print load_fiche_titre($langs->trans("RubriquesTransactions"), '', 'object_category');
108
109print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
110if ($optioncss != '') {
111 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
112}
113print '<input type="hidden" name="token" value="'.newToken().'">';
114print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
115print '<input type="hidden" name="action" value="list">';
116/*print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
117print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
118print '<input type="hidden" name="page" value="'.$page.'">';
119print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
120*/
121
122print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
123print '<table class="noborder centpercent">';
124print '<tr class="liste_titre">';
125print '<td>'.$langs->trans("Ref").'</td><td>'.$langs->trans("Label").'</td>';
126print '<td></td>';
127print '<td></td>';
128print "</tr>\n";
129
130// Line to add category
131if ($action != 'edit') {
132 print '<tr class="oddeven">';
133 print '<td>&nbsp;</td><td><input name="label" type="text" class="maxwidth100"></td>';
134 print '<td></td>';
135 print '<td class="center"><input type="submit" name="add" class="button button-add small" value="'.$langs->trans("Add").'"></td>';
136 print '</tr>';
137}
138
139// Get bank line categorie ID
140include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
141$cats = new Categorie($db);
142$catTypeID = $cats->getMapId()[Categorie::TYPE_BANK_LINE];
143
144$sql = "SELECT rowid, label";
145$sql .= " FROM ".MAIN_DB_PREFIX."categorie";
146$sql .= " WHERE entity = ".$conf->entity." AND type = " . ((int) $catTypeID);
147$sql .= " ORDER BY rowid";
148
149$result = $db->query($sql);
150if ($result) {
151 $num = $db->num_rows($result);
152 $i = 0;
153 $total = 0;
154
155 while ($i < $num) {
156 $objp = $db->fetch_object($result);
157
158 print '<tr class="oddeven">';
159 print '<td>'.$objp->rowid.'</td>';
160 if (GETPOST('action', 'aZ09') == 'edit' && GETPOST("categid") == $objp->rowid) {
161 print '<td colspan="3">';
162 print '<input type="hidden" name="categid" value="'.$objp->rowid.'">';
163 print '<input name="label" type="text" size=45 value="'.$objp->label.'">';
164 print '<input type="submit" name="update" class="button" value="'.$langs->trans("Edit").'">';
165 print "</td>";
166 } else {
167 print "<td>".$objp->label."</td>";
168 print '<td>';
169 //print '<a href="'.DOL_URL_ROOT.'/compta/bank/budget.php?bid='.$objp->rowid.'">'.$langs->trans("List").'</a>';
170 print '</td>';
171 print '<td class="center">';
172 print '<a class="editfielda reposition marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
173 print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
174 print '</td>';
175 }
176 print "</tr>";
177 $i++;
178 }
179 $db->free($result);
180}
181
182print '</table>';
183print '</div>';
184
185print '</form>';
186
187// End of page
188llxFooter();
189$db->close();
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 manage bank categories.
Class to manage categories.
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_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.