$b["day"]) return 1; else return -1; } function test_amount($a, $b) { if ($a["amount"] == $b["amount"]) return 0; elseif ($a["amount"] > $b["amount"]) return 1; else return -1; } function test_account($a, $b) { return strcmp(get_account($a["accid"]), get_account($b["accid"])); } function test_category($a, $b) { return strcmp(get_category($a["catid"]), get_category($b["catid"])); } function test_description($a, $b) { return strcmp($a["description"], $b["description"]); } function get_transaction($id) { global $trans; if (count($trans)) foreach ($trans as $t) if ($t["id"] == $id) return $t["description"]; return ""; } function get_transaction_maxlength() { global $trans; $maxlength = 0; if (count($trans)) foreach ($trans as $t) if (strlen($t["description"]) > $maxlength) $maxlength = strlen($t["description"]); return $maxlength; } function add_transaction($day, $accid, $catid, $amount, $desc) { global $trans; global $yearmonth; if (strftime("%Y%m%d", strtotime(sprintf("%s%02d", $yearmonth, $day))) != sprintf("%s%02d", $yearmonth, $day)) return false; if ($accid < 0) return false; if ($catid <= 0) $catid = 0; if ($amount == 0) return false; $id = ""; if (count($trans)) foreach ($trans as $t) if ($t["id"] > $id) $id = $t["id"]; $trans[] = array("id" => ++$id, "day" => $day, "accid" => $accid, "catid" => $catid, "amount" => $amount, "description" => $desc); return store_transaction($id); } function modify_transaction_day($id, $day) { global $trans; global $yearmonth; if (strftime("%Y%m%d", strtotime(sprintf("%s%02d", $yearmonth, $day))) != sprintf("%s%02d", $yearmonth, $day)) return false; if (count($trans)) foreach ($trans as $key => $t) if ($t["id"] == $id) { $trans[$key]["day"] = $day; return store_transaction($id); } return false; } function modify_transaction_amount($id, $amount) { global $trans; global $yearmonth; if ($amount == 0) return false; if (count($trans)) foreach ($trans as $key => $t) if ($t["id"] == $id) { $trans[$key]["amount"] = $amount; return store_transaction($id); } return false; } function modify_transaction_account($id, $accid) { global $trans; global $yearmonth; if ($accid < 0) return false; if (count($trans)) foreach ($trans as $key => $t) if ($t["id"] == $id) { $trans[$key]["accid"] = $accid; return store_transaction($id); } return false; } function modify_transaction_category($id, $catid) { global $trans; global $yearmonth; if ($catid < 0) $catid = 0; if (count($trans)) foreach ($trans as $key => $t) if ($t["id"] == $id) { $trans[$key]["catid"] = $catid; return store_transaction($id); } return false; } function modify_transaction_description($id, $desc) { global $trans; global $yearmonth; if (count($trans)) foreach ($trans as $key => $t) if ($t["id"] == $id) { $trans[$key]["description"] = $desc; return store_transaction($id); } return false; } function delete_transaction($id) { global $trans; if (count($trans)) foreach ($trans as $key => $t) if ($t["id"] == $id) { unset($trans[$key]); return store_transaction($id); } return false; } function move_transaction($id, $move_yearmonth) { global $trans; global $yearmonth; if ($yearmonth == $move_yearmonth) return false; if (count($trans)) foreach ($trans as $key => $t) if ($t["id"] == $id) { if (copy_transaction($t["day"], $t["accid"], $t["catid"], $t["amount"], $t["description"], $move_yearmonth)) { unset($trans[$key]); return store_transaction($id); } else return false; } return false; } /* Initialization */ include($lib_dir.$db_type."/transaction.php"); ?>