-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedit_group.php
72 lines (58 loc) · 1.55 KB
/
edit_group.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
<?php
$directaccess = true;
error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
require("config.php");
$r_action = (string)$_POST['action'];
$r_id = (string)$_POST['id'];
$r_name = (string)$_POST['Groupname'];
switch ($r_action) {
case "add":
$newid=1;
foreach($xml->groups->group as $group) {
$oldid=(integer)$group->id;
if($oldid >= $newid) {
$newid = $oldid + 1;
}
}
$newgroup = $xml->groups->addChild('group');
$newgroup->addChild('id', $newid);
$newgroup->addChild('name', $r_name);
unset($_POST['action']);
unset($_POST['id']);
unset($_POST['Groupname']); # Entfernen
$string = array_keys($_POST); # Array umdrehen
for($i=0; $i<count($string); $i++){
$newgroup->addChild('deviceid', $string[$i]);
}
echo'ok';
config_save();
break;
case "edit":
$xpath='//group/id[.="'.$r_id.'"]/parent::*';
$res = $xml->xpath($xpath);
$parent = $res[0];
$parent[0]->name = $r_name;
unset($_POST['action']);
unset($_POST['id']);
unset($_POST['Groupname']); # Entfernen
$string = array_keys($_POST); # Array umdrehen
unset($parent[0]->deviceid);
foreach($string as $device){
$parent[0]->addChild('deviceid', $device);
}
echo "ok";
config_save();
break;
case "delete":
$xpath='//group/id[.="'.$r_id.'"]/parent::*';
$res = $xml->xpath($xpath);
$parent = $res[0];
unset($parent[0]);
echo "ok";
config_save();
break;
default:
echo "unsupported";
break;
}
?>