$id, "day" => $day, "accid" => $accid, "catid" => $catid, "amount" => $amount, "description" => $desc); } fclose($f); unlock($file); return 1; } function store_transaction() { global $transaction; global $trans; global $yearmonth; $file = $transaction . $yearmonth; if ((!lock($file)) || (!($f = fopen($file, 'w')))) return 0; foreach ($trans as $t) fputs ($f, $t["id"]." ".$t["day"]." ".$t["accid"]." ".$t["catid"]." ". $t["amount"]." ".$t["description"]."\n"); fclose($f); unlock($file); return 1; } function copy_transaction($day, $accid, $catid, $amount, $desc, $myearmonth) { global $transaction; global $trans; global $yearmonth; $file = $transaction . $myearmonth; if (!lock($file)) return 0; $id = 0; if ($f = fopen($file, 'r')) { while (!feof($f)) { list($_id, $_day, $_accid, $_catid, $_amount, $_desc) = explode (" ", rtrim(fgets($f, 1024)), 6); if (!$_id) continue; $id = $_id; } fclose($f); } $id++; if (!($f = fopen($file, 'a'))) return 0; fputs ($f, $id." ".$day." ".$accid." ".$catid." ".$amount." ".$desc."\n"); fclose($f); unlock($file); return 1; } /* Initialization */ $transaction = $transactiondir . $table . "."; load_transaction(); ?>