Exemplo n.º 1
0
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 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 = mysql_query($queryString);
    if (!$report_ids_lookup) {
        abortAndExit();
        //print "Could not look up row IDs with query $queryString<br />\n";
    }
    if (mysql_num_rows($report_ids_lookup) == 0) {
        print "<p>No reports found in this date range</p>\n";
        return;
    }
    while ($row = mysql_fetch_assoc($report_ids_lookup)) {
        //print $row['REPORT_ID'] . ": " . $row['REPORT_DATE'];
        $report_ids[$row['REPORT_ID']] = $row['REPORT_DATE'];
    }
    mysql_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 = mysql_query("select REPORT_KEY from reportRecord group by REPORT_KEY");
    if (!$knownReportKeysLookup) {
        abortAndExit();
    }
    while ($row = mysql_fetch_array($knownReportKeysLookup)) {
        $knownReportKeys[] = $row[0];
    }
    mysql_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 where REPORT_ID='" . $report_id . "'";
        // report_records will be an assoc array, keys from knownReportKeys, values with the corresponding value
        $reportRecordsLookup = mysql_query($queryString);
        if (!$reportRecordsLookup) {
            abortAndExit();
        }
        while ($row = mysql_fetch_assoc($reportRecordsLookup)) {
            $reportRecords[$row['REPORT_KEY']] = $row['REPORT_VALUE'];
        }
        mysql_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();
}
Exemplo n.º 2
0
    print "{$queryString}<br />";
}
$sqlResult = mysql_query($queryString);
if (!$sqlResult) {
    abortAndExit();
}
$record_id = mysql_insert_id();
global $appcastKeys;
// parse the data report
while (list($key, $value) = each($_GET)) {
    // Date,
    if (array_key_exists($key, $appcastKeys) && $appcastKeys[$key] == 1) {
        $value = mysql_real_escape_string($value);
        $queryString = "INSERT INTO reportRecord (REPORT_KEY, REPORT_VALUE, REPORT_ID) VALUES (\"" . $key . "\",\"" . $value . "\",\"" . $record_id . "\")";
        if ($debug) {
            print "{$key}: {$value}<br />\n";
            print "{$queryString}<br />";
        }
        $sqlResult = mysql_query($queryString);
        if (!$sqlResult) {
            abortAndExit();
        }
    }
}
CloseDB();
if ($debug) {
    print "</body>\n";
}
?>