From 1d8c121b11e27b81963bfe5595dff9ca894dde81 Mon Sep 17 00:00:00 2001
From: Joey Schulze
Date: Sun, 6 Apr 2014 08:57:06 +0000
Subject: [PATCH] Use new object-oriented backend
---
src/InfoCon/account/account.inc | 65 ++-------------------------------
src/InfoCon/account/admin.wml | 9 +----
src/InfoCon/account/all.wml | 16 ++++----
src/InfoCon/account/edit.wml | 58 +++++++++++------------------
src/InfoCon/account/index.wml | 9 ++---
src/InfoCon/account/list.wml | 41 +++++++++------------
src/InfoCon/account/query.wml | 44 +++++++---------------
src/InfoCon/account/submenu.inc | 22 -----------
src/InfoCon/account/update.wml | 57 ++++++++++++++---------------
9 files changed, 98 insertions(+), 223 deletions(-)
diff --git a/src/InfoCon/account/account.inc b/src/InfoCon/account/account.inc
index f69d473..f449955 100644
--- a/src/InfoCon/account/account.inc
+++ b/src/InfoCon/account/account.inc
@@ -1,20 +1,9 @@
+
- $dbh = pg_pconnect ("", "", "")
- or die("Unable to connect to SQL server");
-
$ktoname = '';
- if (isset($_REQUEST[blzkto])) {
- $query = sprintf ("SELECT name FROM account_names WHERE blz_kto = '%s'",
- $_REQUEST[blzkto]);
- $sth = pg_exec ($dbh, $query);
-
- $both = explode (":", $_REQUEST[blzkto]);
- if (pg_NumRows ($sth) > 0) {
- $row = pg_fetch_array ($sth, 0);
- $ktoname = sprintf ("%s (BLZ %s, Konto %s)", $row['name'], $both[0], $both[1]);
- } else {
- $ktoname = sprintf ("BLZ %s, Konto %s", $both[0], $both[1]);
- }
+ if (isset($_REQUEST['blzkto'])) {
+ $account = new AccountName($_REQUEST['blzkto']);
+ $ktoname = $account->name();
}
?>
@@ -23,49 +12,3 @@
=$ktoname?>
-
-
-
- function account_names ($dbh, $display, $currency)
- {
- if ($currency == "eur")
- $table = "account";
- else
- $table = "account_dm";
-
- $query = "SELECT DISTINCT $table.blz_kto,name "
- ."FROM $table,account_names "
- ."WHERE $table.blz_kto = account_names.blz_kto "
- ."$display "
- ."ORDER BY name";
- $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
-
- $ret = array();
- for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
- $row = pg_fetch_array ($sth, $nr);
- $ret[$row['blz_kto']] = $row['name'];
- }
- return $ret;
- }
-
- function stand ($dbh,$blzkto,$currency)
- {
- if ($currency == "dm") {
- $query = "SELECT value_dm FROM account_dm WHERE blz_kto='$blzkto'";
- } elseif ($currency == "eur") {
- $query = "SELECT value_eur FROM account WHERE blz_kto='$blzkto'";
- } else {
- # Alert: unknown currency
- $query = '';
- }
- $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
-
- $sum = 0.0;
- for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
- $row = pg_fetch_array ($sth, $nr);
- $sum += $row[0];
- }
- return $sum;
- }
-?>
-
diff --git a/src/InfoCon/account/admin.wml b/src/InfoCon/account/admin.wml
index 3eb1c6a..765ec47 100644
--- a/src/InfoCon/account/admin.wml
+++ b/src/InfoCon/account/admin.wml
@@ -1,5 +1,6 @@
#include
+
@@ -32,16 +33,10 @@ input.entry {
- $dbh = pg_pconnect ("", "", "")
- or die("Unable to connect to SQL server");
-
$query = "SELECT blz_kto,name,display,date_part('year',min(datum)) AS year_from,date_part('year', max(datum)) AS year_to " .
"FROM account_names JOIN account using(blz_kto) " .
"GROUP BY blz_kto,name,display ORDER BY name";
- $sth = pg_exec ($dbh, $query);
-
- for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
- $row = pg_fetch_array ($sth, $nr);
+ foreach ($db->fetchAssocList($query) as $row) {
$both = explode (":", $row['blz_kto']);
printf ("
".
" ".
diff --git a/src/InfoCon/account/all.wml b/src/InfoCon/account/all.wml
index c8a6e84..4d6b136 100644
--- a/src/InfoCon/account/all.wml
+++ b/src/InfoCon/account/all.wml
@@ -1,8 +1,6 @@
#include
#include "account.inc"
-
-
@@ -11,18 +9,18 @@ Die folgenden Konten stehen zur Verf
- $accounts = account_names ($dbh, "", "eur");
+ $accounts = new AccountName(false);
- foreach ($accounts as $kto => $name) {
+ $account = new Accounting(false);
+ foreach ($accounts->getAccounts('eur') as $row) {
printf ("- %s (Stand: %6.2f EUR)",
- urlencode($kto), $name, stand ($dbh, $kto, "eur"));
+ urlencode($row->blz_kto), $row->name, $account->sum($row->blz_kto));
}
- $accounts = account_names ($dbh, "", "dm");
-
- foreach ($accounts as $kto => $name) {
+ $account = new AccountingDM(false);
+ foreach ($accounts->getAccounts('dm') as $row) {
printf ("
- %s (Stand: %6.2f DM)",
- urlencode($kto), $name, stand ($dbh, $kto, "dm"));
+ urlencode($row->blz_kto), $row->name, $account->sum($row->blz_kto));
}
?>
diff --git a/src/InfoCon/account/edit.wml b/src/InfoCon/account/edit.wml
index e93fa64..1bdfa16 100644
--- a/src/InfoCon/account/edit.wml
+++ b/src/InfoCon/account/edit.wml
@@ -1,6 +1,7 @@
#include
#include "account.inc"
+
@@ -9,32 +10,32 @@
$value = "value_eur";
$add = '';
$hidden = '';
- if ((strlen ($_GET[cur]) > 0) && ($_GET[cur] == "dm")) {
+ if ((strlen ($_GET['cur']) > 0) && ($_GET['cur'] == "dm")) {
$table = "account_dm";
$value = "value_dm";
$hidden = '';
$add = "¤cy=dm";
}
- if (!isset($_GET[blzkto]) && isset($_GET[id])) {
- pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
+ if (!isset($_GET['blzkto']) && isset($_GET['id'])) {
+ if ($table == 'account')
+ $accounting = new Accounting($_GET['id']);
+ else
+ $accounting = new AccountingDM($_GET['id']);
+ $row = $accounting->fetch();
- $query = "SELECT $table.blz_kto,datum,category,descr,from_to,statement,$value,name "
- ."FROM $table JOIN account_names using(blz_kto) "
- ."WHERE $table.id = $_GET[id]";
- $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
-
- if (pg_NumRows ($sth) > 0) {
- $row = pg_fetch_array ($sth, 0);
- $date = explode (" ", $row['datum']);
+ if ($row) {
+ $date = explode (" ", $row->datum);
$date = explode ("-", $date[0]);
$date = sprintf ("%d.%d.%d", $date[2], $date[1], $date[0]);
- $blzkto = $row['blz_kto'];
+ $blzkto = $row->blz_kto;
$add .= '&blzkto='. $blzkto;
}
} else {
- $blzkto = $_GET[blzkto];
+ $accounting = new Accounting(false);
+ $blzkto = $_GET['blzkto'];
}
+ $account = new AccountName($blzkto);
?>
-=$row['name']?>
+=$account->fetch()->name;?>
Weiteren Posten aufnehmen', $_POST['blzkto']);
}
- $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
+ $db->execute($query) or die("Datenbank-Abfrage!");
}
echo ("
".$output."
");
--
2.20.1