<?php
-$db_handle = new SQLite3("/home/bdsm/bdsm.sqlite3");
+$db = new PDO("sqlite:/home/bdsm/bdsm.sqlite3");
$colors = Array("#55F", "#5F5", "#F55", "#5FF", "#F5F", "#FF5", "#555");
-$result = $db_handle->query("SELECT DISTINCT host FROM MEASUREMENTS");
-while($host = $result->fetchArray(SQLITE3_ASSOC))
+$result = $db->query("SELECT DISTINCT host FROM MEASUREMENTS;");
+$hosts = Array();
+while($host = $result->fetch())
if ( $host['host'] )
array_push($hosts, $host['host']);
-$host = $_GET['host'];
+$host = urldecode($_GET['host']);
+
+//print_r($hosts);
+//$result = $db->query("SELECT * FROM bdsmweb;");
+//print_r($result->fetch());
if( !in_array($host, $hosts) )
die("Error: Host not found.");
-
-
?>
<HTML>
}
context.stroke();
context.beginPath();
-
+
context.strokeStyle = "#000";
for (var i = 50; i < 400; i+=50)
{
context.moveTo(0, i);
context.lineTo(400, i);
}
-
+
context.stroke();
context.beginPath();
context.lineWidth = 2;
-
<?php
- $result = $db_handle->query("SELECT attribute, name FROM bdsmweb WHERE host='$host' AND graph=1");
+ $result = $db->query("SELECT attribute, name FROM bdsmweb WHERE host='$host' AND graph=1;");
$attributes = Array();
- while($attribute = $result->fetchArray(SQLITE3_ASSOC))
+
+ while($attribute = $result->fetch())
+{
if ( $attribute['attribute'] )
$attributes[$attribute['attribute']] = $attribute['name'];
-
+}
$i = 0;
foreach (array_keys($attributes) as $attribute)
{
"WHERE host='$host' AND attribute='$attribute' ".
"ORDER BY timestamp DESC LIMIT 100";
- $result = $db_handle->query($query);
+ $result = $db->query($query);
echo " context.strokeStyle = '$colors[$i]';\n";
- $record = $result->fetchArray(SQLITE3_ASSOC);
+ $record = $result->fetch();
$final = $record['timestamp'];
echo " context.moveTo(0, ".sprintf("%d", $record['value']).");\n";
echo " context.beginPath();\n";
- while( $record = $result->fetchArray(SQLITE3_ASSOC) )
+ while( $record = $result->fetch() )
{
echo " context.lineTo(".sprintf("%d", $final - $record['timestamp']).", ".(400-$record['value']*4).");\n";
}