dolibarr  13.0.2
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 $bankcateg = new BankCateg($db);
43 $categid = GETPOST('categid');
44 $label = GETPOST("label");
45 
46 
47 
48 /*
49  * Actions
50  */
51 
52 if (GETPOST('add'))
53 {
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 llxHeader();
83 
84 
85 print load_fiche_titre($langs->trans("RubriquesTransactions"), '', 'object_category');
86 
87 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
88 if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
89 print '<input type="hidden" name="token" value="'.newToken().'">';
90 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
91 print '<input type="hidden" name="action" value="list">';
92 /*print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
93 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
94 print '<input type="hidden" name="page" value="'.$page.'">';
95 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
96 */
97 
98 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
99 print '<table class="noborder centpercent">';
100 print '<tr class="liste_titre">';
101 print '<td>'.$langs->trans("Ref").'</td><td>'.$langs->trans("Label").'</td>';
102 print '<td></td>';
103 print '<td></td>';
104 print "</tr>\n";
105 
106 // Line to add category
107 if ($action != 'edit')
108 {
109  print '<tr class="oddeven">';
110  print '<td>&nbsp;</td><td><input name="label" type="text" class="maxwidth100"></td>';
111  print '<td></td>';
112  print '<td class="center"><input type="submit" name="add" class="button" value="'.$langs->trans("Add").'"></td>';
113  print '</tr>';
114 }
115 
116 
117 $sql = "SELECT rowid, label";
118 $sql .= " FROM ".MAIN_DB_PREFIX."bank_categ";
119 $sql .= " WHERE entity = ".$conf->entity;
120 $sql .= " ORDER BY rowid";
121 
122 $result = $db->query($sql);
123 if ($result)
124 {
125  $num = $db->num_rows($result);
126  $i = 0; $total = 0;
127 
128  while ($i < $num)
129  {
130  $objp = $db->fetch_object($result);
131 
132  print '<tr class="oddeven">';
133  print '<td>'.$objp->rowid.'</td>';
134  if (GETPOST('action', 'aZ09') == 'edit' && GETPOST("categid") == $objp->rowid)
135  {
136  print '<td colspan="3">';
137  print '<input type="hidden" name="categid" value="'.$objp->rowid.'">';
138  print '<input name="label" type="text" size=45 value="'.$objp->label.'">';
139  print '<input type="submit" name="update" class="button" value="'.$langs->trans("Edit").'">';
140  print "</td>";
141  } else {
142  print "<td>".$objp->label."</td>";
143  print '<td>';
144  //print '<a href="'.DOL_URL_ROOT.'/compta/bank/budget.php?bid='.$objp->rowid.'">'.$langs->trans("List").'</a>';
145  print '</td>';
146  print '<td class="center">';
147  print '<a class="editfielda reposition marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&amp;action=edit&amp;token='.newToken().'">'.img_edit().'</a>';
148  print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&amp;action=delete&amp;token='.newToken().'">'.img_delete().'</a>';
149  print '</td>';
150  }
151  print "</tr>";
152  $i++;
153  }
154  $db->free($result);
155 }
156 
157 print '</table>';
158 print '</div>';
159 
160 print '</form>';
161 
162 // End of page
163 llxFooter();
164 $db->close();
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 editer/modifier fiche.
llxHeader()
Empty header.
Definition: wrapper.php:45
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
Class to manage bank categories.
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 ...
print
Draft customers invoices.
Definition: index.php:89
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.