/
edit_device.php
executable file
·112 lines (90 loc) · 3.11 KB
/
edit_device.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
$directaccess = true;
error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
require("config.php");
/*
<devices>
<device>
<id>1</id>
<name>Lichterkette Wohnzimmertür</name>
<vendor>intertechno</vendor>
<address>
<masterdip>M</masterdip>
<slavedip>2</slavedip>
<tx433version/>
<rawCodeOn/>
<rawCodeOff/>
</address>
<room>Flur</room>
<favorite>true</favorite>
<status>OFF</status>
</device>
*/
$r_action = (string)$_POST['action'];
$r_id = (string)$_POST['id'];
$r_name = (string)$_POST['name'];
$r_room = (string)$_POST['room'];
$r_vendor = (string)$_POST['vendor'];
$r_masterdip = (string)$_POST['masterdip'];
$r_slavedip = (string)$_POST['slavedip'];
$r_rawCodeOn = (string)$_POST['rawCodeOn'];
$r_rawCodeOff = (string)$_POST['rawCodeOff'];
$r_tx433version = (string)$_POST['tx433version'];
$r_btnLabelOn = (string)$_POST['btnLabelOn'];
$r_btnLabelOff = (string)$_POST['btnLabelOff'];
$r_favorite = (string)$_POST['favorite'];
$r_senderid = (string)$_POST['senderid'];
switch ($r_action) {
case "add":
$newid=1;
foreach($xml->devices->device as $device) {
$oldid=(integer)$device->id;
if($oldid >= $newid) {
$newid = $oldid + 1;
}
}
$newdevice = $xml->devices->addChild('device');
if(!empty($r_btnLabelOn)) {
$newdevice->addAttribute('buttonLabelOn', $r_btnLabelOn);
}
if(!empty($r_btnLabelOff)) {
$newdevice->addAttribute('buttonLabelOff', $r_btnLabelOff);
}
$newdevice->addChild('id', $newid);
$newdevice->addChild('name', $r_name);
$newdevice->addChild('vendor', $r_vendor);
$newdeviceaddress = $newdevice->addChild('address');
$newdeviceaddress->addChild('masterdip', $r_masterdip);
$newdeviceaddress->addChild('slavedip', $r_slavedip);
$newdeviceaddress->addChild('tx433version', $r_tx433version);
if($r_vendor == "url") {
$newdeviceaddress->addChild('rawCodeOn', str_replace('&','&',$r_rawCodeOn));
$newdeviceaddress->addChild('rawCodeOff', str_replace('&','&',$r_rawCodeOff));
} else {
$newdeviceaddress->addChild('rawCodeOn', $r_rawCodeOn);
$newdeviceaddress->addChild('rawCodeOff', $r_rawCodeOff);
}
$newdevice->addChild('room', $r_room);
$newdevice->addChild('favorite', $r_favorite);
$newdevice->addChild('senderid', $r_senderid);
$newdevice->addChild('status', 'OFF');
if(check_device($newdevice)) {
echo "ok";
config_save();
}
break;
case "edit":
break;
case "delete":
$xpath='//device/id[.="'.$r_id.'"]/parent::*';
$res = $xml->xpath($xpath);
$parent = $res[0];
unset($parent[0]);
echo "ok";
config_save();
break;
default:
echo "unsupported";
break;
}
?>