-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaddnewlocation.php
126 lines (110 loc) · 3.83 KB
/
addnewlocation.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
session_start();
include_once "php/config.php";
$usersql=mysqli_query($conn,"SELECT * FROM users WHERE user_id={$_SESSION['unique_id']}");
$user=mysqli_fetch_assoc($usersql);
$sql = mysqli_query($conn, "select * from location");
if($user['role']!=1)
{
header("location: mainpage.php");
}
include_once("navigation.php");
?>
<center><h2>ADD NEW LOCATION</h2></center>
<center><form action="" class="form-horizontal" method="post" name="myForm" id="formpurchase">
<br>
<div class="form-group pt-2">
<div class="form-group">
<h4 class="text-center"></h4>
<br>
<div class="row ml-2">
<div class="col-md-2">
</div>
<div class="col-md-4">
<input type="text" class="form-control" id="location" name="location" placeholder="Location Name">
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-primary" id="addcomponent" name="add">Add to Loaction Table</button>
</div>
<br><br>
<br><br>
<div class="col-sm-offset-2 col-md-9 text-center">
<table class="table table-hover">
<tr>
<th>Location_ID</th>
<th>Location </th>
<th>Delete</th>
</tr>
<?php
while($row = mysqli_fetch_array($sql))
{
if($row['lab_name'] == 'STORE' || $row['lab_name'] == 'DISPOSED' ){
$temp = '<button type="submit" class="btn btn-primary" id="delcomponent" disabled>Not Accessible</button>';
}else {
$temp = '<button type="submit" class="btn btn-danger" id="delcomponent" onclick="myFunction('.$row['lab_id'].')">Delete</button>';
}
echo '<tr>
<td>'.$row['lab_id'].'</td>
<td>'.$row['lab_name'].'</td>
<td>'.$temp.'</td>
</tr>';
}
?>
</table>
</div>
</div>
</div>
</div>
</form></center>
<?php
include_once("footer.php");
?>
<script>
const form=document.querySelector("#formpurchase");
continueBtn1=form.querySelector("#addcomponent");
// errorText = form.querySelector(".error-text");
function myFunction(a) {
console.log(a);
if (confirm("Do you want to delete the delete the location!!")) {
let xhr = new XMLHttpRequest();
xhr.open("GET", "php/deloaction.php?loc_id="+a, true);
xhr.onload = ()=>{
if(xhr.readyState === XMLHttpRequest.DONE){
if(xhr.status === 200){
let data = xhr.response;
alert(data);
}
}
}
let formData = new FormData(form);
xhr.send();
}else{
}}
continueBtn1.onclick = (e)=>{
e.preventDefault();
let xhr = new XMLHttpRequest();
xhr.open("POST", "php/addnewlocation.php", true);
console.log(xhr.response);
xhr.onload = ()=>{
if(xhr.readyState === XMLHttpRequest.DONE){
if(xhr.status === 200){
let data = xhr.response;
console.log(data);
if(data === "success"){
alert("New Location has been added Successfully!!");
document.getElementById("location").value="";
window.location.href="addnewlocation.php";
//document.getElementById("myForm").action = "addnewlocation.php";
}
else{
alert(data);
}
}
}
}
let formData = new FormData(form);
xhr.send(formData);
}
</script>
</body>
</html>