3 if (isset($_POST['show_reports'])) {
4 header(sprintf("Location: http%s://%s/%s/from/%s/to/%s", ($_SERVER['HTTPS']) ? "s" : "", $_SERVER['HTTP_HOST'], $module, $_POST['from'], $_POST['to']));
8 function show_reports_form($from = null, $to = null) {
9 form("noprint standout");
10 echo "<p>Show reports covering the period from ";
12 /* Default to last month. */
13 list($y, $m, $d) = explode('-', date('Y-m-d', time()));
15 $now = mktime(0, 0, 0, $m, $d, $y);
16 $first = mktime(0, 0, 0, $m, 1, $y);
17 $last = $first - 86400;
18 $date = date('Y-m-d', $last);
19 if (is_null($to)) $to = $date;
20 list($y, $m, $d) = explode('-', $date);
21 $first = mktime(0, 0, 0, $m, 1, $y);
22 if (is_null($from)) $from = date('Y-m-d', $first);
24 for ($i = 0; $i < 2; $i++) {
26 list ($y, $m, $d) = explode('-', date('Y-m-d', $date));
27 $date = mktime(0, 0, 0, $m, 1, $y);
29 $oldest = date('Y-m-d', $date);
32 echo "<select name=\"from\">\n";
33 for ($date = $then; $date <= $now; $date += 86400) {
34 option("from", date('Y-m-d', $date), date('j F Y', $date), $from);
36 echo "</select> to <select name=\"to\">\n";
37 for ($date = $then; $date <= $now; $date += 86400) {
38 option("to", date('Y-m-d', $date), date('j F Y', $date), $to);
42 submit("show_reports", "Show");
46 function check_report_dates($from, $to) {
47 list($y, $m, $d) = explode('-', $from);
48 if (! checkdate($m, $d, $y)) {
49 echo "<p>Invalid report start date!</p>\n";
52 $start = mktime(0, 0, 0, $m, $d, $y);
54 list($y, $m, $d) = explode('-', $to);
55 if (! checkdate($m, $d, $y)) {
56 echo "<p>Invalid report end date!</p>\n";
59 $end = mktime(0, 0, 0, $m, $d, $y);
62 echo "<p>Report end date is earlier than start date!</p>\n";
69 function show_reports($from, $to) {
70 if (! check_report_dates($from, $to)) return;
72 echo "<p>Showing reports for the period <strong>$from</strong> to <strong>$to</strong>.</p>\n";
75 if (count($parameters)) {
76 if ($parameters[0] == "from") {
77 $from = $parameters[1];
78 if ($parameters[2] == "to") $to = $parameters[3];
79 show_reports($from, $to);
82 show_reports_form($from, $to);