From 39f915d95d7961699f7a71f4daef019c61c0d0ae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?=
 <marcosgdf@gmail.com>
Date: Thu, 10 Mar 2016 19:52:27 +0100
Subject: [PATCH] Reverted use of BankCateg in Bank category listing

---
 htdocs/compta/bank/categ.php | 58 +++++++++++++++++++++++-------------
 1 file changed, 37 insertions(+), 21 deletions(-)

diff --git a/htdocs/compta/bank/categ.php b/htdocs/compta/bank/categ.php
index bfdc004e528..48e8e738fef 100644
--- a/htdocs/compta/bank/categ.php
+++ b/htdocs/compta/bank/categ.php
@@ -89,28 +89,44 @@ print '<tr class="liste_titre">';
 print '<td>'.$langs->trans("Ref").'</td><td colspan="2">'.$langs->trans("Label").'</td>';
 print "</tr>\n";
 
-$var = true;
-
-foreach ($bankcateg->fetchAll() as $category) {
-	$var = !$var;
-	print "<tr ".$bc[$var].">";
-	print '<td><a href="'.DOL_URL_ROOT.'/compta/bank/budget.php?bid='.$category->id.'">'.$category->id.'</a></td>';
-
-	if ($action == 'edit' && $categid == $category->id) {
-		print "<td colspan=2>";
-		print '<input type="hidden" name="categid" value="'.$category->id.'">';
-		print '<input name="label" type="text" size=45 value="'.$category->label.'">';
-		print ' <input type="submit" name="update" class="button" value="'.$langs->trans("Edit").'">';
-
-		print "</td>";
-	} else {
-		print "<td >".$category->label."</td>";
-		print '<td style="text-align: center;">';
-		print '<a href="'.$_SERVER["PHP_SELF"].'?categid='.$category->id.'&amp;action=edit">'.img_edit().'</a>&nbsp;&nbsp;';
-		print '<a href="'.$_SERVER["PHP_SELF"].'?categid='.$category->id.'&amp;action=delete">'.img_delete().'</a></td>';
-	}
+$sql = "SELECT rowid, label";
+$sql.= " FROM ".MAIN_DB_PREFIX."bank_categ";
+$sql.= " WHERE entity = ".$conf->entity;
+$sql.= " ORDER BY label";
 
-	print "</tr>";
+$result = $db->query($sql);
+if ($result)
+{
+	$num = $db->num_rows($result);
+	$i = 0; $total = 0;
+
+	$var=True;
+	while ($i < $num)
+	{
+		$objp = $db->fetch_object($result);
+		$var=!$var;
+		print "<tr ".$bc[$var].">";
+		print '<td><a href="'.DOL_URL_ROOT.'/compta/bank/budget.php?bid='.$objp->rowid.'">'.$objp->rowid.'</a></td>';
+		if (GETPOST("action") == 'edit' && GETPOST("categid")== $objp->rowid)
+		{
+			print "<td colspan=2>";
+			print '<input type="hidden" name="categid" value="'.$objp->rowid.'">';
+			print '<input name="label" type="text" size=45 value="'.$objp->label.'">';
+			print '<input type="submit" name="update" class="button" value="'.$langs->trans("Edit").'">';
+
+			print "</td>";
+		}
+		else
+		{
+			print "<td >".$objp->label."</td>";
+			print '<td style="text-align: center;">';
+			print '<a href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&amp;action=edit">'.img_edit().'</a>&nbsp;&nbsp;';
+			print '<a href="'.$_SERVER["PHP_SELF"].'?categid='.$objp->rowid.'&amp;action=delete">'.img_delete().'</a></td>';
+		}
+		print "</tr>";
+		$i++;
+	}
+	$db->free($result);
 }
 
 
-- 
GitLab