-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
142 lines (126 loc) · 4.18 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<html>
<head>
<title>Sparkle Profile Data Lookup</title>
</head>
<body>
<?php
// $Id: profileLookup.php 6 2006-06-09 23:50:23Z atomicbird $
// $HeadURL: http://sparkleplus.googlecode.com/svn/trunk/profileLookup.php $
require("profileConfig.php");
require("profileDB.php");
$debug = 0;
/*
always do a lookup.
if start and end specified, use them if valid.
if only end set, use start of 1 month ago
if neither set, use default start & end
*/
// If end is set, make sure it looks like a date
if (isset($_GET['end']) && (dateValidate($_GET['end']))) {
$end_date = $_GET['end'];
} else {
// default end date is now
$end_date = strftime("%Y-%m-%d %H:%M:%S");
}
// check that start looks like a date
if (dateValidate($_GET['start'])) {
$start_date = $_GET['start'];
} else {
// default start date is one month before end date
$start_timestamp = strtotime("$end_date 1 year ago");
$start_date = strftime("%Y-%m-%d %H:%M:%S", $start_timestamp);
}
profileLookup();
function dateValidate($date) {
if (preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$/', $date)) {
$timestamp = strtotime($date);
return checkdate(date('m',$timestamp), date('d',$timestamp), date('Y',$timestamp));
} else {
return 0;
}
}
function profileLookupForm() {
}
function profileLookup() {
global $start_date, $end_date;
// connect to the database
if (!TryOpenDB()) {
abortAndExit();
}
// Get REPORT_ID for all reports between specified dates.
//$start_date = '2006-01-01';
//$end_date = strftime("%Y-%m-%d %H:%m:%S");
print "<table>\n";
print "<tr><td>Start date:</td><td>$start_date</td>\n";
print "<tr><td>End date:</td><td>$end_date</td>\n";
print "</table>\n";
$queryString = "select REPORT_ID,REPORT_DATE from profileReport_1 where REPORT_DATE >= '" . $start_date . "' and REPORT_DATE <= '" . $end_date . " ORDER BY REPORT_DATE'";
//print "query: $queryString<br />\n";
// report_ids will be an associative array: keys=report_ids, values=dates
$report_ids_lookup = mysqli_query(getDBLink(), $queryString);
if (!$report_ids_lookup) {
abortAndExit();
//print "Could not look up row IDs with query $queryString<br />\n";
}
if (mysqli_num_rows($report_ids_lookup) == 0) {
print "<p>No reports found in this date range</p>\n";
return;
}
while ($row = mysqli_fetch_assoc($report_ids_lookup)) {
//print $row['REPORT_ID'] . ": " . $row['REPORT_DATE'];
$report_ids[$row['REPORT_ID']] = $row['REPORT_DATE'];
}
mysqli_free_result($report_ids_lookup);
if ($debug) {
print "Report IDs:<br />\n";
print_r($report_ids);
print "<br \>\n";
}
// Now dsplay a table of reported data for these REPORT_IDs.
// Could find keys in advance using "select REPORT_KEY from reportRecord group by REPORT_KEY"
// knownReportKeys is a (non-associative) array where each entry is a key used in a profile report.
$knownReportKeysLookup = mysqli_query(getDBLink(), "select REPORT_KEY from reportRecord_1 group by REPORT_KEY");
if (!$knownReportKeysLookup) {
abortAndExit();
}
while ($row = mysqli_fetch_array($knownReportKeysLookup)) {
$knownReportKeys[] = $row[0];
}
mysqli_free_result($knownReportKeysLookup);
if ($debug) {
print "known keys:<br />\n";
print_r($knownReportKeys);
}
print "<table><tr><td>Date</td>\n";
foreach($knownReportKeys as $reportKey) {
print "<td>$reportKey</td>\n";
}
print "</td>\n";
while(list($report_id, $report_date) = each($report_ids)) {
$queryString = "select REPORT_KEY,REPORT_VALUE from reportRecord_1 where REPORT_ID='" . $report_id . "'";
// report_records will be an assoc array, keys from knownReportKeys, values with the corresponding value
$reportRecordsLookup = mysqli_query(getDBLink(), $queryString);
if (!$reportRecordsLookup) {
abortAndExit();
}
while ($row = mysqli_fetch_assoc($reportRecordsLookup)) {
$reportRecords[$row['REPORT_KEY']] = $row['REPORT_VALUE'];
}
mysqli_free_result($reportRecordsLookup);
if ($debug) {
print "<br />report records: <br />\n";
print_r($reportRecords);
print "<br />\n";
}
print "<tr><td>$report_date</td>\n";
foreach($knownReportKeys as $reportKey) {
print "<td>" . $reportRecords[$reportKey] . "</td>\n";
}
print "</tr>\n";
}
print "</table>\n";
CloseDB();
}
?>
</body>
</html>