-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapprovedEntities.php
218 lines (170 loc) · 7.47 KB
/
approvedEntities.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php include('session.php'); ?>
<?php include('config.php'); ?>
<?php
if($_SESSION['user_type'] != "ADMIN") {
header("Location: index.php");
}
?>
<?php
if($_SERVER["REQUEST_METHOD"] == "POST") {
if(isset($_POST['addName']) && isset($_POST['addType'])) {
$sql = "INSERT INTO FarmItem (Name, IsApproved, Type) VALUES ('" . $_POST['addName'] . "', '1', '" . $_POST['addType'] . "')";
$result = mysqli_query($db,$sql);
if($result == true) {
echo "<script type='text/javascript'>if(!alert(\"Successfully added: " . $_POST['addName'] . "\")) document.location = 'approvedEntities.php';</script>";
} else {
echo "<script type='text/javascript'>if(!alert(\"Error: Could not add: " . $_POST['addName'] . "\")) document.location = 'approvedEntities.php';</script>";
}
}
} else {
if(isset($_GET['deleteName'])) {
$sql = "DELETE FROM FarmItem WHERE Name = '" . $_GET['deleteName'] . "'";
$result = mysqli_query($db,$sql);
if($result == true) {
echo "<script type='text/javascript'>if(!alert(\"Successfully deleted: " . $_GET['deleteName'] . "\")) document.location = 'approvedEntities.php';</script>";
} else {
echo "<script type='text/javascript'>if(!alert(\"Error: Could not delete: " . $_GET['deleteName'] . "\")) document.location = 'approvedEntities.php';</script>";
}
}
}
$farmItemList = array('ANIMAL', 'FRUIT', 'FLOWER', 'VEGETABLE', 'NUT');
?>
<!DOCTYPE html>
<html lang="en">
<?php include("head.php"); ?>
<body>
<?php include("navbar.php"); ?>
<section>
<div class="container">
<div class="row text-center title-space">
<div class="col-md-12">
<h4>Approved Animals/Crops</h4>
<br>
</div>
</div> <!-- End Row -->
<div class="row">
<div class="col-md-6 offset-md-3">
<form class="form-horizontal" id="addItemForm" method="post">
<div class="form-group">
<label class="col-md-12 control-label"><b>Add New Item</b></label>
<label class="col-md-12 control-label" for="type">Type*</label>
<div class="col-md-12 rowspace">
<select id="addType" name="addType" class="form-control">
<option value=""></option>
<?php foreach ($farmItemList as &$value) { ?>
<option value="<?php echo $value ?>"><?php echo $value ?></option>
<?php } ?>
</select>
</div>
<div class="col-md-12 rowspace">
<input id="addName" name="addName" type="text" placeholder="Enter New Crop Name" class="form-control input-md">
</div>
<div class="col-md-12">
<button id="addItem" type="button" onclick="AddItem()" class="btn btn-primary style-bkg" style="width: 100%;">Add to Approved List</button>
</div>
</div> <!-- End form group -->
</form>
</div> <!-- End Column -->
</div> <!-- End Row --> <br>
<div class ="row">
<div class = "col-md-12">
<div class="text-center">
<button class="btn btn-primary style-bkg" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
🔍 Search Table
</button>
</div>
<div class="collapse" id="collapseExample">
<form class="form-horizontal" action="approvedEntities.php" method = "GET">
<fieldset>
<br>
<input id="SEARCH" name="SEARCH" value="true" type = "hidden">
<div class="row rowspace">
<!-- Select Basic -->
<div class="col-md-2 offset-md-3">
<p>Search name</p>
</div>
<!-- Search input-->
<div class="col-md-4">
<input id="inputName" name="inputName" type="search" placeholder="Search Name" class="form-control input-md">
</div>
</div> <!-- End Row -->
<div class="row rowspace">
<div class="col-md-6 offset-md-3">
<select id="Type" name="Type" class="form-control">
<option value="0">Type?</option>
<option value="ANIMAL">Animal</option>
<option value="FRUIT">Fruit</option>
<option value="FLOWER">Flower</option>
<option value="VEGETABLE">Vegetable</option>
<option value="NUT">Nut</option>
</select>
</div>
</div> <!-- End Row -->
<br>
<div class="row">
<!-- Submit Button -->
<div class="col-md-6 offset-md-5">
<input class="btn btn-primary style-bkg btn-md" type="submit" width="100%" value="Search Entities">
</div>
</div>
</fieldset>
</form>
</div> <!-- End Collapse Example -->
</div> <!-- End Column -->
</div> <!-- End Row -->
<br>
<div class ="row">
<div class = "col-md-12">
<div class="property-table table-scroll">
<table class="table table-striped table-sm sortable">
<thead class="thead-dark">
<tr>
<th scope="col">Delete</th>
<th scope="col">Name</th>
<th scope="col">Type</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM FarmItem WHERE IsApproved = '1'";
if (isset($_GET['SEARCH'])) {
if (isset($_GET['inputName']) && $_GET['inputName'] != NULL) {
$query .= " AND Name LIKE '%" . mysqli_real_escape_string($db, $_GET['inputName']) . "%'";
}
if (isset($_GET['Type']) && $_GET['Type'] != '0') {
$query .= " AND Type = '" . mysqli_real_escape_string($db, $_GET['Type']) . "'";
}
}
$query .= " ORDER BY Name";
$approvedItems = mysqli_query($db, $query);
while ($row = mysqli_fetch_array($approvedItems)) { ?>
<tr>
<td class="link-color"><a href=<?php echo "\"approvedEntities.php?deleteName=" . $row['Name'] . "\"";?>>Delete</a></td>
<td><?php echo $row['Name']; ?></td>
<td><?php echo $row['Type']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div> <!-- End Property Table Wrapper -->
</div> <!-- End Column -->
</div> <!-- End Row -->
</div> <!-- End Container -->
</section>
<script>
function AddItem () {
var typeSelect = document.getElementById("addType");
var nameText = document.getElementById("addName");
if(typeSelect.options[typeSelect.selectedIndex].text == "") {
alert("Error: Please select a type");
return;
}
if(nameText.value == "") {
alert("Error: Please input a name");
return;
}
document.getElementById("addItemForm").submit();
}
</script>
</body>
</html>