-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeleteUser.php
More file actions
104 lines (80 loc) · 2.34 KB
/
deleteUser.php
File metadata and controls
104 lines (80 loc) · 2.34 KB
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
<script>
var delVar = null;
var upVar = null;
</script>
<?php
if(!empty($_POST['delete'])) {
$xml = new DomDocument("1.0","UTF-8");
$xml->load('userDataBase.xml');
$list = $xml->getElementsByTagName("user");
$id = $_POST["ID"];
$targetNode = null;
foreach($list as $domElement){
$IDNUMTag = $domElement->getElementsByTagName("ID");
$attrValue = $IDNUMTag->item(0)->nodeValue;
if($attrValue == $id){
$targetNode = $domElement;
}
}
if($targetNode != null){
$targetNode->parentNode->removeChild($targetNode);
}
$xml->formatoutput = true;
$xml->save('userDataBase.xml');
}
if(!empty($_POST['update'])) {
$xml = new DomDocument("1.0","UTF-8");
$xml->load('userDataBase.xml');
$firstName = $_POST["firstName"];
$lastName = $_POST["lastName"];
$id = $_POST["ID"];
$email = $_POST["email"];
$password = $_POST["password"];
$admin = $_POST["admin"];
if($admin == null){
$admin = "false";
} else $admin = "true";
$list = $xml->getElementsByTagName("user");
$targetNode = null;
foreach($list as $domElement){
$IDNUMTag = $domElement->getElementsByTagName("ID");
$attrValue = $IDNUMTag->item(0)->nodeValue;
if($attrValue == $id){
$targetNode = $domElement;
}
}
if($targetNode != null){
$targetNode->parentNode->removeChild($targetNode);
}
$rootTag = $xml->getElementsByTagName("root")->item(0);
$userTag = $xml->createElement("user");
$firstNameTag = $xml->createElement("firstName", $firstName);
$lastNameTag = $xml->createElement("lastName", $lastName);
$IDTag = $xml->createElement("ID", $id);
$emailTag = $xml->createElement("email", $email);
$passwordTag = $xml->createElement("password", $password);
$adminTag = $xml->createElement("admin", $admin);
$userTag->appendChild($firstNameTag);
$userTag->appendChild($lastNameTag);
$userTag->appendChild($IDTag);
$userTag->appendChild($emailTag);
$userTag->appendChild($passwordTag);
$userTag->appendChild($adminTag);
$rootTag->appendChild($userTag);
$xml->save('userDataBase.xml');
}
?>
<script>
<?php
if(!empty($_POST['update']))
echo "upVar = '$id';";
else echo "delVar = '$id';";
?>
if(delVar == null){
alert("User with id " + upVar + " has been successfully modified.");
window.location.href = "allUsers.php";
} else {
alert("User with id " + delVar + " has been successfully deleted.");
window.location.href = "allUsers.php";
}
</script>