-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcountdowntimer.php
98 lines (83 loc) · 2.92 KB
/
countdowntimer.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
<?php
$CONFIG_FILENAME = 'data/time.xml';
//config.xml dateisystem rechte überprüfen
if(!file_exists($CONFIG_FILENAME)) {
echo "Kann die Konfiguration (".$CONFIG_FILENAME.") nicht finden!\n";
exit(1);
}
if(!is_readable($CONFIG_FILENAME)) {
echo "Kann die Konfiguration (".$CONFIG_FILENAME.") nicht lesen!\n";
exit(2);
}
if(!is_writable($CONFIG_FILENAME)) {
echo "Kann die Konfiguration (".$CONFIG_FILENAME.") nicht schreiben!\n";
exit(3);
}
//config.xml einlesen
libxml_use_internal_errors(true);
$time_xml = simplexml_load_file($CONFIG_FILENAME);
if (!$time_xml) {
echo "Kann die Konfiguration (".$CONFIG_FILENAME.") nicht laden!\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
exit(4);
}
$timestamp = time();
$now = date("Y-m-d H:i",$timestamp);
if((!isset($directaccess)) OR (!$directaccess)) die();
error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
$debug_timer=empty($xml->timers["debug"]) ? "false" : $xml->timers["debug"];
header("Content-Type: text/plain; charset=utf-8");
function countdowntimer_check() {
global $xml;
global $time_xml;
global $debug_timer;
$timeraktivenowon = false;
$timeraktivenowoff = false;
$timeraktive = false;
$pingaktive = false;
$timestamp = time();
$now = date("Y-m-d H:i",$timestamp);
if($debug_timer=="true") debug_timer("Pruefe Countdowntimer...\n");
//Aktuelle Zeit ermitteln und Puffer definieren, die beim Timer berücksichtigt werden sollen
// Timer auslesen und bei gefunden Timern Aktionen ausführen
if(@count($time_xml->timer) <= '0' ){
debug_timer("Kein Countdowntimer gesetzt!\n");
return;
}
foreach ( $time_xml->timer as $user )
{
echo 'Countdowntimer Nr: ' . $user->id . "\n";
echo 'Name: ' . $user->time . "\n";
echo 'DevID: ' .$user->device . "\n";
echo 'Action: '.$user->action . "\n \n";
$count = $user->time;
if ($count == $now){
debug_timer("timer_switch ".$user->device." ".$user->action);
$devicesFound = $xml->xpath("//devices/device/id[text()='".$user->device."']/parent::*");
$device = $devicesFound[0];
send_message($device, $user->action, TRUE);
$device->status = $user->action;
config_save("data/config.xml" , $xml);
}
if ($count <= $now ){
$xpath='//timer/id[.="'.$user->id.'"]/parent::*';
$res = $time_xml->xpath($xpath);
$parent = $res[0];
unset($parent[0]);
config_save($CONFIG_FILENAME , $time_xml);
echo "Erfolgreich bereinigt\n";
}
}
}
function countdowntimer_switch($timer, $action) {
global $xml;
global $debug_timer;
debug_timer("timer_switch ".$timer->id." ".$action);
// Timer mit Device
$devicesFound = $xml->xpath("//devices/device/id[text()='".$timer->typeid."']/parent::*");
$device = $devicesFound[0];
send_message($device, $action, TRUE);
}
?>