--- /dev/null
+<?php
+
+ if (isset($_POST['show_reports'])) {
+ header(sprintf("Location: http%s://%s/%s/from/%s/to/%s", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, $_POST['from'], $_POST['to']));
+ exit;
+ }
+
+ function show_reports_form($from = null, $to = null) {
+ form("noprint standout");
+ echo "<p>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 "<select name=\"from\">\n";
+ for ($date = $then; $date <= $now; $date += 86400) {
+ option("from", date('Y-m-d', $date), date('j F Y', $date), $from);
+ }
+ echo "</select> to <select name=\"to\">\n";
+ for ($date = $then; $date <= $now; $date += 86400) {
+ option("to", date('Y-m-d', $date), date('j F Y', $date), $to);
+ }
+ echo "</select>\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 "<p>Invalid report start date!</p>\n";
+ return false;
+ }
+ $start = mktime(0, 0, 0, $m, $d, $y);
+
+ list($y, $m, $d) = explode('-', $to);
+ if (! checkdate($m, $d, $y)) {
+ echo "<p>Invalid report end date!</p>\n";
+ return false;
+ }
+ $end = mktime(0, 0, 0, $m, $d, $y);
+
+ if ($end < $start) {
+ echo "<p>Report end date is earlier than start date!</p>\n";
+ return false;
+ }
+
+ return true;
+ }
+
+ function show_reports($from, $to) {
+ if (! check_report_dates($from, $to)) return;
+
+ echo "<p>Showing reports for the period <strong>$from</strong> to <strong>$to</strong>.</p>\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);
+?>