dolibarr 21.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 *
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
29// TODO Remove this file, this page is replaced by standard view categorie page
30
31// Load Dolibarr environment
32require '../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
34require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
35
36
37// Load translation files required by the page
38$langs->loadLangs(array('banks', 'categories'));
39
40
41// Get Parameters
42$action = GETPOST('action', 'aZ09');
43$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
44$categid = GETPOST('categid');
45$label = GETPOST("label");
46
47
48// Initialize a technical objects
49$bankcateg = new BankCateg($db);
50
51
52// Security Check Access Control
53if (!$user->hasRight('banque', 'configurer')) {
55}
56
57
58
59/*
60 * Actions
61 */
62
63if (GETPOST('add')) {
64 if ($label) {
65 $bankcateg = new BankCateg($db);
66 $bankcateg->label = GETPOST('label');
67 $bankcateg->create($user);
68 }
69}
70
71if ($categid) {
72 $bankcateg = new BankCateg($db);
73
74 if ($bankcateg->fetch($categid) > 0) {
75 //Update category
76 if (GETPOST('update') && $label) {
77 $bankcateg->label = $label;
78 $bankcateg->update($user);
79 }
80 //Delete category
81 if ($action == 'delete' && $user->hasRight('banque', 'configurer')) {
82 $bankcateg->delete($user);
83 }
84 }
85}
86
87
88/*
89 * View
90 */
91
92$title = $langs->trans('RubriquesTransactions');
93$help_url = 'EN:Module_Banks_and_Cash|FR:Module_Banques_et_Caisses|ES:M&oacute;dulo_Bancos_y_Cajas';
94
95llxHeader('', $title, $help_url);
96
97
98print load_fiche_titre($langs->trans("RubriquesTransactions"), '', 'object_category');
99
100print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
101if ($optioncss != '') {
102 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
103}
104print '<input type="hidden" name="token" value="'.newToken().'">';
105print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
106print '<input type="hidden" name="action" value="list">';
107/*print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
108print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
109print '<input type="hidden" name="page" value="'.$page.'">';
110print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
111*/
112
113print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
114print '<table class="noborder centpercent">';
115print '<tr class="liste_titre">';
116print '<td>'.$langs->trans("Ref").'</td><td>'.$langs->trans("Label").'</td>';
117print '<td></td>';
118print '<td></td>';
119print "</tr>\n";
120
121// Line to add category
122if ($action != 'edit') {
123 print '<tr class="oddeven">';
124 print '<td>&nbsp;</td><td><input name="label" type="text" class="maxwidth100"></td>';
125 print '<td></td>';
126 print '<td class="center"><input type="submit" name="add" class="button button-add small" value="'.$langs->trans("Add").'"></td>';
127 print '</tr>';
128}
129
130// Get bank line categorie ID
131include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
132$cats = new Categorie($db);
133$catTypeID = $cats->getMapId()[Categorie::TYPE_BANK_LINE];
134
135$sql = "SELECT rowid, label";
136$sql .= " FROM ".MAIN_DB_PREFIX."categorie";
137$sql .= " WHERE entity = ".$conf->entity." AND type = " . ((int) $catTypeID);
138$sql .= " ORDER BY rowid";
139
140$result = $db->query($sql);
141if ($result) {
142 $num = $db->num_rows($result);
143 $i = 0;
144 $total = 0;
145
146 while ($i < $num) {
147 $objp = $db->fetch_object($result);
148
149 print '<tr class="oddeven">';
150 print '<td>'.$objp->rowid.'</td>';
151 if (GETPOST('action', 'aZ09') == 'edit' && GETPOST("categid") == $objp->rowid) {
152 print '<td colspan="3">';
153 print '<input type="hidden" name="categid" value="'.$objp->rowid.'">';
154 print '<input name="label" type="text" size=45 value="'.$objp->label.'">';
155 print '<input type="submit" name="update" class="button" value="'.$langs->trans("Edit").'">';
156 print "</td>";
157 } else {
158 print "<td>".$objp->label."</td>";
159 print '<td>';
160 //print '<a href="'.DOL_URL_ROOT.'/compta/bank/budget.php?bid='.$objp->rowid.'">'.$langs->trans("List").'</a>';
161 print '</td>';
162 print '<td class="center">';
163 print '<a class="editfielda reposition marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
164 print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
165 print '</td>';
166 }
167 print "</tr>";
168 $i++;
169 }
170 $db->free($result);
171}
172
173print '</table>';
174print '</div>';
175
176print '</form>';
177
178// End of page
179llxFooter();
180$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:70
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.