dolibarr  16.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  *
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 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array('banks', 'categories'));
35 
36 $action = GETPOST('action', 'aZ09');
37 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
38 
39 if (!$user->rights->banque->configurer) {
41 }
42 
43 $bankcateg = new BankCateg($db);
44 $categid = GETPOST('categid');
45 $label = GETPOST("label");
46 
47 
48 
49 /*
50  * Actions
51  */
52 
53 if (GETPOST('add')) {
54  if ($label) {
55  $bankcateg = new BankCateg($db);
56  $bankcateg->label = GETPOST('label');
57  $bankcateg->create($user);
58  }
59 }
60 
61 if ($categid) {
62  $bankcateg = new BankCateg($db);
63 
64  if ($bankcateg->fetch($categid) > 0) {
65  //Update category
66  if (GETPOST('update') && $label) {
67  $bankcateg->label = $label;
68  $bankcateg->update($user);
69  }
70  //Delete category
71  if ($action == 'delete') {
72  $bankcateg->delete($user);
73  }
74  }
75 }
76 
77 
78 /*
79  * View
80  */
81 
82 $title = $langs->trans('RubriquesTransactions');
83 $help_url = 'EN:Module_Banks_and_Cash|FR:Module_Banques_et_Caisses|ES:M&oacute;dulo_Bancos_y_Cajas';
84 
85 llxHeader('', $title, $help_url);
86 
87 
88 print load_fiche_titre($langs->trans("RubriquesTransactions"), '', 'object_category');
89 
90 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
91 if ($optioncss != '') {
92  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
93 }
94 print '<input type="hidden" name="token" value="'.newToken().'">';
95 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
96 print '<input type="hidden" name="action" value="list">';
97 /*print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
98 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
99 print '<input type="hidden" name="page" value="'.$page.'">';
100 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
101 */
102 
103 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
104 print '<table class="noborder centpercent">';
105 print '<tr class="liste_titre">';
106 print '<td>'.$langs->trans("Ref").'</td><td>'.$langs->trans("Label").'</td>';
107 print '<td></td>';
108 print '<td></td>';
109 print "</tr>\n";
110 
111 // Line to add category
112 if ($action != 'edit') {
113  print '<tr class="oddeven">';
114  print '<td>&nbsp;</td><td><input name="label" type="text" class="maxwidth100"></td>';
115  print '<td></td>';
116  print '<td class="center"><input type="submit" name="add" class="button button-add small" value="'.$langs->trans("Add").'"></td>';
117  print '</tr>';
118 }
119 
120 
121 $sql = "SELECT rowid, label";
122 $sql .= " FROM ".MAIN_DB_PREFIX."bank_categ";
123 $sql .= " WHERE entity = ".$conf->entity;
124 $sql .= " ORDER BY rowid";
125 
126 $result = $db->query($sql);
127 if ($result) {
128  $num = $db->num_rows($result);
129  $i = 0;
130  $total = 0;
131 
132  while ($i < $num) {
133  $objp = $db->fetch_object($result);
134 
135  print '<tr class="oddeven">';
136  print '<td>'.$objp->rowid.'</td>';
137  if (GETPOST('action', 'aZ09') == 'edit' && GETPOST("categid") == $objp->rowid) {
138  print '<td colspan="3">';
139  print '<input type="hidden" name="categid" value="'.$objp->rowid.'">';
140  print '<input name="label" type="text" size=45 value="'.$objp->label.'">';
141  print '<input type="submit" name="update" class="button" value="'.$langs->trans("Edit").'">';
142  print "</td>";
143  } else {
144  print "<td>".$objp->label."</td>";
145  print '<td>';
146  //print '<a href="'.DOL_URL_ROOT.'/compta/bank/budget.php?bid='.$objp->rowid.'">'.$langs->trans("List").'</a>';
147  print '</td>';
148  print '<td class="center">';
149  print '<a class="editfielda reposition marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
150  print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
151  print '</td>';
152  }
153  print "</tr>";
154  $i++;
155  }
156  $db->free($result);
157 }
158 
159 print '</table>';
160 print '</div>';
161 
162 print '</form>';
163 
164 // End of page
165 llxFooter();
166 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4389
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
img_delete
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
Definition: functions.lib.php:4429
BankCateg
Class to manage bank categories.
Definition: bankcateg.class.php:29
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59