From: Iain Patterson
Date: Tue, 23 Jul 2013 21:33:12 +0000 (+0100)
Subject: Framework for reports.
X-Git-Tag: 2013-09-11~6
X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=8ed7023cec6e6c090aa4c0776f5b30cad8f59c11;p=readifood.git
Framework for reports.
---
diff --git a/lib/header.php b/lib/header.php
index 75cd167..0582fcb 100644
--- a/lib/header.php
+++ b/lib/header.php
@@ -19,8 +19,10 @@
Hubs
/
Donations
+/
+Reports
-@
+@
logout
$charity"; ?>
diff --git a/lib/report.php b/lib/report.php
new file mode 100644
index 0000000..e74ac07
--- /dev/null
+++ b/lib/report.php
@@ -0,0 +1,83 @@
+Show reports covering the period from ";
+
+ /* Default to last month. */
+ list($y, $m, $d) = explode('-', date('Y-m-d', time()));
+ $latest = "$y-$m-$d";
+ $now = mktime(0, 0, 0, $m, $d, $y);
+ $first = mktime(0, 0, 0, $m, 1, $y);
+ $last = $first - 86400;
+ $date = date('Y-m-d', $last);
+ if (is_null($to)) $to = $date;
+ list($y, $m, $d) = explode('-', $date);
+ $first = mktime(0, 0, 0, $m, 1, $y);
+ if (is_null($from)) $from = date('Y-m-d', $first);
+ $date = $first;
+ for ($i = 0; $i < 2; $i++) {
+ $date -= 86400;
+ list ($y, $m, $d) = explode('-', date('Y-m-d', $date));
+ $date = mktime(0, 0, 0, $m, 1, $y);
+ }
+ $oldest = date('Y-m-d', $date);
+ $then = $date;
+
+ echo " to \n";
+
+ submit("show_reports", "Show");
+ end_form();
+ }
+
+ function check_report_dates($from, $to) {
+ list($y, $m, $d) = explode('-', $from);
+ if (! checkdate($m, $d, $y)) {
+ echo "Invalid report start date!
\n";
+ return false;
+ }
+ $start = mktime(0, 0, 0, $m, $d, $y);
+
+ list($y, $m, $d) = explode('-', $to);
+ if (! checkdate($m, $d, $y)) {
+ echo "Invalid report end date!
\n";
+ return false;
+ }
+ $end = mktime(0, 0, 0, $m, $d, $y);
+
+ if ($end < $start) {
+ echo "Report end date is earlier than start date!
\n";
+ return false;
+ }
+
+ return true;
+ }
+
+ function show_reports($from, $to) {
+ if (! check_report_dates($from, $to)) return;
+
+ echo "Showing reports for the period $from to $to.
\n";
+ }
+
+ if (count($parameters)) {
+ if ($parameters[0] == "from") {
+ $from = $parameters[1];
+ if ($parameters[2] == "to") $to = $parameters[3];
+ show_reports($from, $to);
+ }
+ }
+ show_reports_form($from, $to);
+?>