-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.php
103 lines (95 loc) · 4.09 KB
/
view.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
<!DOCTYPE html>
<head>
<title></title>
<link rel="stylesheet" href="/assets/css/index.css">
</head>
<body>
<?php include("header.php"); ?>
<main>
<section class="view-page">
<?php
ob_start();
include("functions.php");
$result = call_api("https://ec2-18-220-186-80.us-east-2.compute.amazonaws.com/api/list_devices");
$resultsArray = json_decode($result, true);
$devices = get_msg_data($resultsArray);
$result = call_api("https://ec2-18-220-186-80.us-east-2.compute.amazonaws.com/api/list_manufacturers");
$resultsArray = json_decode($result, true);
$manufacturers = get_msg_data($resultsArray);
?>
<div class="parent"><h1>View and Search Equipment</h1></div>
<div class="parent">
<form method="POST" class="search-bar" action="">
<label for="status">Status:</label>
<select name="status">
<option value="ACTIVE">ACTIVE</option>
<option value="INACTIVE">INACTIVE</option>
<option value="BOTH">ACTIVE/INACTIVE</option>
</select>
<label for="device">Device:</label>
<select name="device_id">
<option selected disabled>Choose Device</option>
<?php
foreach($devices as $key=>$value)
{
echo '<option value="'.$key.'">'.$value.'</option>';
}
?>
</select>
<label for="manufacturer">Manufacturer:</label>
<select name="manufacturer_id">
<option selected disabled>Choose Manufacturer</option>
<?php
foreach($manufacturers as $key=>$value)
{
echo '<option value="'.$key.'">'.$value.'</option>';
}
?>
</select>
<label for="serial_number">Serial #:</label>
<input type="text" id="serialInput" name="serial_number" placeholder="Format: SN-09091asda309asd">
<button type="submit" name="submit-equipment">View Equipment</button>
</form>
</div>
</section>
<section class="results">
<div class="parent">
<?php
ob_start();
if ( isset( $_POST[ 'submit-equipment' ] ) ) {
$status = $_REQUEST[ 'status' ];
$manufacturer_id = $_REQUEST[ 'manufacturer_id' ];
$device_id = $_REQUEST[ 'device_id' ];
$serial_number = $_REQUEST[ 'serial_number' ];
$url = "https://ec2-18-220-186-80.us-east-2.compute.amazonaws.com/api/new_search?status=$status";
if ($device_id && (!$manufacturer_id && !$serial_number))
{
$url = "https://ec2-18-220-186-80.us-east-2.compute.amazonaws.com/api/new_search?status=$status&device_id=$device_id";
}
if ($manufacturer_id && (!$device_id && !$serial_number))
{
$url = "https://ec2-18-220-186-80.us-east-2.compute.amazonaws.com/api/new_search?status=$status&manufacturer_id=$manufacturer_id";
}
if ($serial_number && (!$device_id && !$manufacturer_id))
{
$encoded_serial = urlencode($serial_number);
$url = "https://ec2-18-220-186-80.us-east-2.compute.amazonaws.com/api/new_search?status=$status&serial_number=$encoded_serial";
}
if ($device_id && $manufacturer_id && (!$serial_number))
{
$url = "https://ec2-18-220-186-80.us-east-2.compute.amazonaws.com/api/new_search?status=$status&device_id=$device_id&manufacturer_id=$manufacturer_id";
}
if ($device_id && $manufacturer_id && $serial_number) {
$url = "https://ec2-18-220-186-80.us-east-2.compute.amazonaws.com/api/new_search?status=$status&serial_number=$serial_number&device_id=$device_id&manufacturer_id=$manufacturer_id";
}
$result = call_api( $url );
display_search_results($result);
}
?>
</div>
</section>
</main>
</body>
<script>
</script>
</html>