Löschen von Einnahmen und Ausgaben.
[memberdb.git] / include / expenses.php
index 48ca679..dcbd851 100644 (file)
@@ -51,6 +51,10 @@ function db_change_expense($expense) {
     return db_update_single(DB_TABLE_EXPENSES, $expense, sprintf('id=\'%1$d\'', db_escape($id)));
 }
 
+function db_delete_expense($expense) {
+    return db_delete_single(DB_TABLE_EXPENSES, sprintf('id=\'%1$d\'', db_escape($expense['id'])));
+}
+
 /* }}} */
 
 
@@ -105,9 +109,9 @@ function action_create_expense() {/*{{{*/
 function action_change_expense() {/*{{{*/
     if (!isset($_REQUEST['id'])) redirect(link_to('finances'));
     $expense = db_get_expense_with_id($_REQUEST['id']);
+    if (!isset($expense)) redirect(link_to('finances'));
     $expense['date'] = format_date(db_date2unixtime($expense['date']));
     $expense['value']= format_money($expense['value']);
-    if (!isset($expense)) redirect(link_to('finances'));
     $log_messages = array();
     if (isset($_POST['submit'])) {
         if (validate_expense($_POST, $expense, $log_messages)) {
@@ -122,6 +126,23 @@ function action_change_expense() {/*{{{*/
 }/*}}}*/
 
 
+function action_delete_expense() {/*{{{*/
+    if (!isset($_REQUEST['id'])) redirect(link_to('finances'));
+    $expense = db_get_expense_with_id($_REQUEST['id']);
+    if (!isset($expense)) redirect(link_to('finances'));
+    $expense['date'] = format_date(db_date2unixtime($expense['date']));
+    $expense['value']= format_money($expense['value']);
+    $log_messages = array();
+    if (isset($_POST['submit'])) {
+        if (db_delete_expense($expense)) {
+            redirect(link_to('finances'));
+        }
+        echo db_error();
+    }
+    form_expense($expense, 'delete', $log_messages);
+}/*}}}*/
+
+
 function form_expense($expense = array(), $task, $log_messages) {/*{{{*/
     global $EXPENSE_TYPES, $ACCOUNT_TYPES;