<?php // Schalter speichert/liest/liefert Schaltzustand aus SQLite3 Datenbank, Tabelle: pseudodevice
error_reporting(0);
require_once("../db.php");// SQLite3 Datenbankoeffner
require_once("../include/psg.php");
$p_id=1;// Diese id aus der Datenbank gehoert diesen Schalter
try {// Dann versuchen wir es mal...
$count = $dbh->exec("CREATE TABLE IF NOT EXISTS pseudodevice (id INTEGER PRIMARY KEY, active VARCHAR(255), type VARCHAR(255), temp VARCHAR(255), watt VARCHAR(255), command VARCHAR(255), command0 VARCHAR(255), command1 VARCHAR(255))");
$sth = $dbh->prepare('SELECT id FROM pseudodevice WHERE id = '.$p_id.'');
$sth->execute();
$Status = $sth->fetch(PDO::FETCH_ASSOC);
if ($Status=="") {
$count = $dbh->exec("INSERT INTO pseudodevice (active,type,temp,watt,command,command0,command1) VALUES ('1','S','20','2.25','http://snom1/command.htm?number=200','http://snom1/screen.bmp','http://snom1/command.htm?number=100')");
}
if ($_GET[info]=="status") {
$sth = $dbh->prepare('SELECT active,type FROM pseudodevice WHERE id = '.$p_id.'');
$sth->execute();
$Status = $sth->fetch(PDO::FETCH_ASSOC);
if ($Status[active]=="1") {
throw new Exception(trim($Status[type])."#".trim($Status[active])."#");
}
if ($Status[active]=="0") {
throw new Exception(trim($Status[type])."#".trim($Status[active])."#");
}}
if ($_GET[schalter]=="1") {
$count = $dbh->exec("UPDATE pseudodevice SET active = '1' WHERE id = ".$p_id."");
$sth = $dbh->prepare('SELECT id,active,type,command FROM pseudodevice WHERE id = '.$p_id.'');
$sth->execute();
$Status = $sth->fetch(PDO::FETCH_ASSOC);
if ($Status[active]=="1") {
webget($Status[command],"");
throw new Exception(trim($Status[type]."#".$Status[active])."#");
}}
if ($_GET[schalter]=="0") {
$count = $dbh->exec("UPDATE pseudodevice SET active = '0' WHERE id = ".$p_id."");
$sth = $dbh->prepare('SELECT active,type,command1 FROM pseudodevice WHERE id = '.$p_id.'');
$sth->execute();
$Status = $sth->fetch(PDO::FETCH_ASSOC);
if ($Status[active]=="0") {
webget($Status[command1],"");
throw new Exception(trim($Status[type]."#".$Status[active])."#");
}}
throw new Exception($Status[type]."##E##");
}
catch(Exception $e) {
echo $e->getMessage();
}
?>