dolibarr  9.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 <http://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 $bankcateg = new BankCateg($db);
43 $categid = GETPOST('categid');
44 $label = GETPOST("label");
45 
46 /*
47  * Add category
48  */
49 if (GETPOST('add'))
50 {
51  if ($label) {
52  $bankcateg = new BankCateg($db);
53  $bankcateg->label = GETPOST('label');
54  $bankcateg->create($user);
55  }
56 }
57 
58 if ($categid) {
59  $bankcateg = new BankCateg($db);
60 
61  if ($bankcateg->fetch($categid) > 0) {
62 
63  //Update category
64  if (GETPOST('update') && $label) {
65 
66  $bankcateg->label = $label;
67  $bankcateg->update($user);
68  }
69  //Delete category
70  if ($action == 'delete') {
71  $bankcateg->delete($user);
72  }
73  }
74 }
75 
76 
77 /*
78  * View
79  */
80 
81 llxHeader();
82 
83 
84 print load_fiche_titre($langs->trans("RubriquesTransactions"));
85 
86 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
87 if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
88 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
89 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
90 print '<input type="hidden" name="action" value="list">';
91 /*print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
92 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
93 print '<input type="hidden" name="page" value="'.$page.'">';
94 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
95 */
96 
97 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
98 print '<table class="noborder" width="100%">';
99 print '<tr class="liste_titre">';
100 print '<td>'.$langs->trans("Ref").'</td><td colspan="2">'.$langs->trans("Label").'</td>';
101 print "</tr>\n";
102 
103 // Line to add category
104 if ($action != 'edit')
105 {
106 
107  print '<tr class="oddeven">';
108  print '<td>&nbsp;</td><td><input name="label" type="text" size="45"></td>';
109  print '<td align="center"><input type="submit" name="add" class="button" value="'.$langs->trans("Add").'"></td>';
110  print '</tr>';
111 }
112 
113 
114 $sql = "SELECT rowid, label";
115 $sql.= " FROM ".MAIN_DB_PREFIX."bank_categ";
116 $sql.= " WHERE entity = ".$conf->entity;
117 $sql.= " ORDER BY label";
118 
119 $result = $db->query($sql);
120 if ($result)
121 {
122  $num = $db->num_rows($result);
123  $i = 0; $total = 0;
124 
125  while ($i < $num)
126  {
127  $objp = $db->fetch_object($result);
128 
129  print '<tr class="oddeven">';
130  print '<td><a href="'.DOL_URL_ROOT.'/compta/bank/budget.php?bid='.$objp->rowid.'">'.$objp->rowid.'</a></td>';
131  if (GETPOST('action','aZ09') == 'edit' && GETPOST("categid")== $objp->rowid)
132  {
133  print "<td colspan=2>";
134  print '<input type="hidden" name="categid" value="'.$objp->rowid.'">';
135  print '<input name="label" type="text" size=45 value="'.$objp->label.'">';
136  print '<input type="submit" name="update" class="button" value="'.$langs->trans("Edit").'">';
137 
138  print "</td>";
139  }
140  else
141  {
142  print "<td >".$objp->label."</td>";
143  print '<td style="text-align: center;">';
144  print '<a href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&amp;action=edit">'.img_edit().'</a>&nbsp;&nbsp;';
145  print '<a href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&amp;action=delete">'.img_delete().'</a></td>';
146  }
147  print "</tr>";
148  $i++;
149  }
150  $db->free($result);
151 }
152 
153 print '</table>';
154 print '</div>';
155 
156 print '</form>';
157 
158 // End of page
159 llxFooter();
160 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
img_edit($titlealt='default', $float=0, $other='class="pictoedit"')
Show logo editer/modifier fiche.
img_delete($titlealt='default', $other='class="pictodelete"')
Show delete logo.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage bank categories.
llxHeader()
Empty header.
Definition: wrapper.php:44