"; $year = "HAS Test"; $gray = "\"#aaaaaa\""; $now = getDate(); $month = $now["month"]; $my_day = $now["mday"]; $tablehead = "   Amount Paid Balance DateItemCost ShareBobAlice BobAlice "; /** * (bucket!) sort by date */ function dateSort(&$_A) { global $field_sep; $days = array("1" => array(), "2" => array(), "3" => array(), "4" => array(), "5" => array(), "6" => array(), "7" => array(), "8" => array(), "9" => array(), "10" => array(), "11" => array(), "12" => array(), "13" => array(), "14" => array(), "15" => array(), "16" => array(), "17" => array(), "18" => array(), "19" => array(), "20" => array(), "21" => array(), "22" => array(), "23" => array(), "24" => array(), "25" => array(), "26" => array(), "27" => array(), "28" => array(), "29" => array(), "30" => array(), "31" => array()); $months = array("Jan" => array(), "Feb" => array(), "Mar" => array(), "Apr" => array(), "May" => array(), "Jun" => array(), "Jul" => array(), "Aug" => array(), "Sep" => array(), "Oct" => array(), "Nov" => array(), "Dec" => array(), ); // push each record into its day array foreach ($_A as $record) { list($mon, $day, $rem) = split($field_sep, $record, 3); array_push($days[$day], $record); } // then put the day-sorted records into their month arrays foreach ($days as $arr) { while (count($arr) > 0) { $record = array_shift($arr); list($mon, $day, $rem) = split($field_sep, $record, 3); array_push($months[$mon], $record); } } // finally, put the month/day sorted records into a flat array $A = array(); foreach ($months as $arr) { while (count($arr) > 0) { array_push($A, array_shift($arr)); } } return $A; } // Add a new record if we got here by the user pushing the "Add New Record" button if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Do some error checking if ($_POST['month'] == 'nomonth') { print("

Add new record failed:
No month selected.

"); } else if (!is_numeric($_POST['day'])) { print("

Add new record failed:
Day must be numeric.

"); } else if ($_POST['day'] > 31 || $_POST['day'] < 1) { print("

Add new record failed:
Day must be in the range [1, 31]

"); } else if (!is_numeric($_POST['cost'])) { print("

Add new record failed:
Cost must be numeric.

"); } else if (!is_numeric($_POST['amtwpd'])) { print("

Add new record failed:
Amounts paid must be numeric.

"); } else if (!is_numeric($_POST['amtlpd'])) { print("

Add new record failed:
Amounts paid must be numeric.

"); } else { // write the new record to the end of the file $file = fopen("$afile", "ab"); fputs($file, $_POST['month']); fputs($file, "$field_sep"); fputs($file, $_POST['day']); fputs($file, "$field_sep"); fputs($file, $_POST['item']); fputs($file, "$field_sep"); fputs($file, $_POST['cost']); fputs($file, "$field_sep"); fputs($file, $_POST['amtwpd']); fputs($file, "$field_sep"); fputs($file, $_POST['amtlpd']); fputs($file, "\n"); fclose($file); // sort the file $lines = file("$afile"); $lines = dateSort($lines); reset($lines); // write out the sorted records to the file $file = fopen("$afile", "wb"); foreach ($lines as $line) { fputs($file, $line); } fclose($file); } } print("Enter something at the bottom. Not very exciting... sorry."); print("

$year

"); print(""); // This dumps the whole file into an array, line by line $lines = file("$afile"); $size_of_lines = sizeof($lines); // Print the records into an HTML table for ($i = 0; $i < $size_of_lines; $i++) { if (($i%$rows_before_header) == 0) { print("$tablehead"); } list($mon, $day, $item, $cost, $wy, $la) = split($field_sep, $lines[$i]); if (substr($item, 0, 4) == "(iou") { // Calculate IOU balance if (substr("$item",4,3) == " l)") { $wbalance = $wbalance - $cost; $lbalance = $lbalance + $cost; } else if (substr("$item",4,3) == " w)") { $wbalance = $wbalance + $cost; $lbalance = $lbalance - $cost; } $share = $la = $wy = "IOU"; } else { // Calculate balances normally $share = $cost/2; $wbalance = $wy - $share + $wbalance; $lbalance = $la - $share + $lbalance; } print(""); print(""); print(""); printf("", $cost); if ("$share" == "IOU") { print(""); print(""); print(""); } else { printf("", $share); printf("", $wy); printf("", $la); } printf("", $wbalance); printf("", $lbalance); print(""); } ?>
$mon $day$item%.2f$share$wy$la%.2f%.2f%.2f%.2f%.2f
Share BobAlice