-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreatecountdown.php
111 lines (100 loc) · 2.75 KB
/
createcountdown.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
<?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);
$xml = simplexml_load_file($CONFIG_FILENAME);
if (!$xml) {
echo "Kann die Konfiguration (".$CONFIG_FILENAME.") nicht laden!\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
exit(4);
}
// Suppress DateTime warnings
date_default_timezone_set('Europe/Berlin');
//zeitzone geradeziehen
if(!empty($xml->global->timezone)) {
date_default_timezone_set($xml->global->timezone);
}
if(!isset($_GET['mode'])){
echo'Neuen Timer erstellen!';
echo'<br>Minuten auswählen:';
echo'
<form method="POST" action="erstellen.php?mode=submit">
<td><td>
<select name="minutes">
';
for($i=1; $i <45; $i++){
echo '<option>'. $i .'</option>';
}
echo'
<option>60</option>
<option>90</option>
<option>120</option>
<option>180</option>
</select>
</td><br><td>
<select name="device">
';
for($i=1; $i <45; $i++){
echo '<option>'. $i .'</option>';
}
echo'
<option>60</option>
<option>90</option>
<option>120</option>
<option>180</option>
</select>
</td><br>
<select name="action">
<option>ON</option>
<option>OFF</option>
</select>
<td colspan="2">
<input class="submit_button" type="submit" name="submitbutton" value="Speichern">
</td>
</form>
';
}
if(isset($_GET['mode']) AND $_GET['mode']=="submit" )
{
$newid=1;
foreach($xml->timer as $timer) {
$oldid=(integer)$timer->id;
if($oldid >= $newid) {
$newid = $oldid + 1;
}
}
if(!empty($_POST['minutes'])){
$heute = date("Y-m-d H:i", strtotime("0 week 0 days 0 hours ". $_POST['minutes'] ." minutes"));
$xmle = $xml->addChild('timer');
$xmle->id = $newid;
$xmle->time = $heute;
$xmle->device = $_POST['device'];
$xmle->action = $_POST['action'];
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xml->asXML());
$dom->save($CONFIG_FILENAME);
#echo 'Erfolgreich gespeichert!';
#header( 'location:index.phppp' );
echo '1';
}else{
echo '0';
}
}
?>