categ.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. /**
  23. * \file htdocs/compta/bank/categ.php
  24. * \ingroup compta/bank
  25. * \brief Page to manage Bank Categories
  26. */
  27. // Load Dolibarr environment
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array('banks', 'categories'));
  33. // Get Parameters
  34. $action = GETPOST('action', 'aZ09');
  35. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  36. $categid = GETPOST('categid');
  37. $label = GETPOST("label");
  38. // Initialize technical objects
  39. $bankcateg = new BankCateg($db);
  40. // Security Check Access Control
  41. if (!$user->rights->banque->configurer) {
  42. accessforbidden();
  43. }
  44. /*
  45. * Actions
  46. */
  47. if (GETPOST('add')) {
  48. if ($label) {
  49. $bankcateg = new BankCateg($db);
  50. $bankcateg->label = GETPOST('label');
  51. $bankcateg->create($user);
  52. }
  53. }
  54. if ($categid) {
  55. $bankcateg = new BankCateg($db);
  56. if ($bankcateg->fetch($categid) > 0) {
  57. //Update category
  58. if (GETPOST('update') && $label) {
  59. $bankcateg->label = $label;
  60. $bankcateg->update($user);
  61. }
  62. //Delete category
  63. if ($action == 'delete') {
  64. $bankcateg->delete($user);
  65. }
  66. }
  67. }
  68. /*
  69. * View
  70. */
  71. $title = $langs->trans('RubriquesTransactions');
  72. $help_url = 'EN:Module_Banks_and_Cash|FR:Module_Banques_et_Caisses|ES:M&oacute;dulo_Bancos_y_Cajas';
  73. llxHeader('', $title, $help_url);
  74. print load_fiche_titre($langs->trans("RubriquesTransactions"), '', 'object_category');
  75. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  76. if ($optioncss != '') {
  77. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  78. }
  79. print '<input type="hidden" name="token" value="'.newToken().'">';
  80. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  81. print '<input type="hidden" name="action" value="list">';
  82. /*print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  83. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  84. print '<input type="hidden" name="page" value="'.$page.'">';
  85. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  86. */
  87. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  88. print '<table class="noborder centpercent">';
  89. print '<tr class="liste_titre">';
  90. print '<td>'.$langs->trans("Ref").'</td><td>'.$langs->trans("Label").'</td>';
  91. print '<td></td>';
  92. print '<td></td>';
  93. print "</tr>\n";
  94. // Line to add category
  95. if ($action != 'edit') {
  96. print '<tr class="oddeven">';
  97. print '<td>&nbsp;</td><td><input name="label" type="text" class="maxwidth100"></td>';
  98. print '<td></td>';
  99. print '<td class="center"><input type="submit" name="add" class="button button-add small" value="'.$langs->trans("Add").'"></td>';
  100. print '</tr>';
  101. }
  102. $sql = "SELECT rowid, label";
  103. $sql .= " FROM ".MAIN_DB_PREFIX."bank_categ";
  104. $sql .= " WHERE entity = ".$conf->entity;
  105. $sql .= " ORDER BY rowid";
  106. $result = $db->query($sql);
  107. if ($result) {
  108. $num = $db->num_rows($result);
  109. $i = 0;
  110. $total = 0;
  111. while ($i < $num) {
  112. $objp = $db->fetch_object($result);
  113. print '<tr class="oddeven">';
  114. print '<td>'.$objp->rowid.'</td>';
  115. if (GETPOST('action', 'aZ09') == 'edit' && GETPOST("categid") == $objp->rowid) {
  116. print '<td colspan="3">';
  117. print '<input type="hidden" name="categid" value="'.$objp->rowid.'">';
  118. print '<input name="label" type="text" size=45 value="'.$objp->label.'">';
  119. print '<input type="submit" name="update" class="button" value="'.$langs->trans("Edit").'">';
  120. print "</td>";
  121. } else {
  122. print "<td>".$objp->label."</td>";
  123. print '<td>';
  124. //print '<a href="'.DOL_URL_ROOT.'/compta/bank/budget.php?bid='.$objp->rowid.'">'.$langs->trans("List").'</a>';
  125. print '</td>';
  126. print '<td class="center">';
  127. print '<a class="editfielda reposition marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
  128. print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
  129. print '</td>';
  130. }
  131. print "</tr>";
  132. $i++;
  133. }
  134. $db->free($result);
  135. }
  136. print '</table>';
  137. print '</div>';
  138. print '</form>';
  139. // End of page
  140. llxFooter();
  141. $db->close();