-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeleteBeacon.php
90 lines (72 loc) · 3.08 KB
/
deleteBeacon.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
<html>
<body>
<h2>Delete Beacon</h2>
<br>
<form method="post" action="<?php echo htmlspecialchars("/deleteBeacon");?>">
<h5>Click the button to have an updated list of available beacons:
<input type="submit" class="button"
name="get_beacons" value="Get Beacons"> </h5>
</form>
<br>
<?php
use GuzzleHttp\Psr7;
use GuzzleHttp\Exception\RequestException;
$page = $_SERVER['/deleteBeacon'];
$tab = " ";
if (isset($_POST['get_beacons'])) {
// Instantiates a new guzzle client.
$client = new GuzzleHttp\Client();
try {
// Send POST request to our server with the JSON beacon
$response = $client->get('http://amaca.ga:8080/beacon');
// DEBUG:
$body = $response->getBody();
if($body) {
// Convert JSON string to Object
$beacon = json_decode($body);
echo "<h3>Available Beacons </h3>";
// Loop through Objects
$ids = array();
foreach($beacon as $key => $value) {
array_push($ids, $value -> id);
echo "<b>ID: " . $value->id . "</b><br>";
echo $tab .
"Name: " . $value -> name . ", " .
"Major: " . $value -> major . ", " .
"Minor: " . $value -> minor . ", " .
"Latitude: " . $value -> latBeacon . ", " .
"Longitude: " . $value -> lonBeacon . "<br>";
}
//DEBUG array
//print_r($ids);
}
} catch (RequestException $e) {
echo Psr7\str($e->getRequest());
if ($e->hasResponse()) {
echo Psr7\str($e->getResponse());
}
}
?>
<br>
<h3> Which beacon do you want to remove? </h3>
<form method="post" action="<?php echo htmlspecialchars("/beaconDelete_post");?>">
<select name = "remove" required>
<option value =""> - Choose ID - </option>
<?php
// Iterating through the ids array
foreach($ids as $item){
?>
<option value="<?php echo $item; ?>"><?php echo $item; ?></option>
<?php
}
?>
</select>
<input type="submit" class="button" name="delete_beacon" value="Delete Beacon">
</form>
<?php
}
?>
</body>
</html>