From 7a7ee029782c812f2cbd9c778773e601ff39fa7e Mon Sep 17 00:00:00 2001
From: Thomas Mudrunka
Date: Sat, 25 May 2013 03:52:29 +0200
Subject: [PATCH] Podpora prejmenovani a ruseni uctu v bance
---
assistants/bank.inc.php | 34 ++++++++++++++++++++++++++++++----
1 file changed, 30 insertions(+), 4 deletions(-)
diff --git a/assistants/bank.inc.php b/assistants/bank.inc.php
index 8f5e164..1937403 100644
--- a/assistants/bank.inc.php
+++ b/assistants/bank.inc.php
@@ -16,9 +16,9 @@ function bank_transaction($ctx, $from, $to, $comment, $amount=0) {
$ctx->db->safe_query($sql);
}
-function bank_get_accounts($ctx) {
+function bank_get_accounts($ctx, $all=false) {
$fetch = $ctx->db->safe_query_fetch('SELECT DISTINCT bank_to FROM bank ORDER BY bank_to;');
- foreach($fetch as $account) $accounts[]=$account['bank_to'];
+ foreach($fetch as $account) if($all || $account['bank_to'][0]!='_') $accounts[]=$account['bank_to'];
return $accounts;
}
@@ -35,6 +35,18 @@ function bank_get_total($ctx, $account, $string=false) {
if($string) return "$deposits-$withdrawals";
return $deposits-$withdrawals;
}
+function bank_rename_account($ctx, $old, $new) {
+ if(in_array($new, bank_get_accounts($ctx, true))) return false;
+ $old=$ctx->db->quote($old);
+ $new=$ctx->db->quote($new);
+
+ return $ctx->db->safe_query(
+ "START TRANSACTION;".
+ "UPDATE bank SET `bank_to`=$new WHERE `bank_to`=$old;".
+ "UPDATE bank SET `bank_from`=$new WHERE `bank_from`=$old;".
+ "COMMIT;"
+ );
+}
function bank_get_overview($ctx) {
$accounts = bank_get_accounts($ctx);
@@ -46,6 +58,13 @@ if(isset($_POST['create_account'])) {
bank_add_account($this, $_POST['account_name']);
$this->post_redirect_get("$URL_INTERNAL","ÃÄet byl vytvoÅen");
}
+if(isset($_POST['rename_account'])) {
+ if(bank_rename_account($this, $_POST['account_old'], $_POST['account_new'])) {
+ $this->post_redirect_get("$URL_INTERNAL","ÃÄet byl upraven");
+ } else {
+ $this->post_redirect_get("$URL_INTERNAL","Takový úÄet již existuje!", false);
+ }
+}
if(isset($_POST['transaction'])) {
if(!is_numeric($_POST['amount']) || $_POST['amount'] < 0) $this->post_redirect_get("$URL_INTERNAL?account=".$_POST['account_from'],"Lze pÅevádÄt jen kladné Äástky", true);
$comment=trim($_POST['comment']);
@@ -58,7 +77,7 @@ if(isset($_POST['transaction'])) {
echo("Banka - ");
echo("Správa úÄtů - ");
echo("ÃÄty: ");
-$accounts = bank_get_accounts($this);
+$accounts = bank_get_accounts($this, $SUBPATH[0]=='admin');
foreach($accounts as $account) echo("$account, ");
switch($SUBPATH[0]) {
@@ -101,10 +120,17 @@ switch($SUBPATH[0]) {
?>
+