Added administration support
authorJoey Schulze <joey@infodrom.org>
Sat, 17 Mar 2007 17:59:12 +0000 (17:59 +0000)
committerJoey Schulze <joey@infodrom.org>
Sat, 17 Mar 2007 17:59:12 +0000 (17:59 +0000)
src/InfoCon/account/update.wml

index e103a46..1b85f02 100644 (file)
@@ -4,12 +4,57 @@
 
 <page func=InfoCon title="Kontoführung">
 
+<?
+  if ($_POST[formtype] == "admin" || $_POST[formtype] == "newaccount")
+    $ktoname = "Administration";
+?>
+
 <account_heading>
 
 <sql_prepare>
 <form_to_yyyymmdd>
 
 <?
+  if ($_POST[formtype] == "admin") {
+    $query = "SELECT blz_kto,name,display FROM account_names ORDER BY name";
+    $sth = pg_exec ($dbh, $query);
+
+    for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
+      $row = pg_fetch_array ($sth, $nr);
+
+      $query = sprintf ("UPDATE account_names SET name='%s',display=%d WHERE blz_kto = '%s'",
+                       $_POST['name_' . $row['blz_kto']],
+                       $_POST['display_' . $row['blz_kto']] ? 1 : 0,
+                       $row['blz_kto']);
+
+      pg_exec ($dbh, $query);
+      $output = "Kontoinformationen aktualisiert.";      
+    }
+  } elseif ($_POST[formtype] == "newaccount") {
+    if (isset($_POST['blz']) && isset($_POST['kto']) && isset($_POST['name'])) {
+      $query = sprintf ("INSERT INTO account_names (blz_kto,name,display) ".
+                       "VALUES ('%s:%s','%s',1)",
+                       $_POST['blz'],
+                       $_POST['kto'],
+                       $_POST['name']);
+      pg_exec ($dbh, $query);
+
+      $query = sprintf ("INSERT INTO account (blz_kto,statement,datum,from_to,descr,category,value_eur) ".
+                       "VALUES ('%s:%s','%s','%s','Account Administration','Initial Zero Statement','Miscellaneous',0.0)",
+                       $_POST['blz'],
+                       $_POST['kto'],
+                       date("Y") . "/00",
+                       date("Y-m-j"));
+      pg_exec ($dbh, $query);
+
+      $output = "Neues Konto erstellt.";
+    } else {
+      $output = "Nicht ausreichend Informationen gegeben.";
+    }
+    phpinfo();
+    exit (0);
+  } else {
+
   $table = "account";
   $field = "value_eur";
   if ((strlen ($_POST[currency]) > 0) && ($_POST[currency] == "dm")) {
     $output = "Neuen Posten aufgenommen.";
   }
   $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");
+  }
 
   echo ("<p>".$output."</p>");
 ?>