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