-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpendingEntities.php
165 lines (129 loc) · 5.67 KB
/
pendingEntities.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
<?php include('session.php'); ?>
<?php include('config.php'); ?>
<?php
if($_SESSION['user_type'] != "ADMIN") {
header("Location: index.php");
}
?>
<?php
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 = 'pendingEntities.php';</script>";
} else {
echo "<script type='text/javascript'>if(!alert(\"Error: Could not delete: " . $_GET['deleteName'] . "\")) document.location = 'pendingEntities.php';</script>";
}
} else if(isset($_GET['approveName'])) {
$sql = "UPDATE FarmItem SET IsApproved = '1' WHERE Name = '" . $_GET['approveName'] . "'";
$result = mysqli_query($db,$sql);
if($result == true) {
echo "<script type='text/javascript'>if(!alert(\"Successfully approved: " . $_GET['approveName'] . "\")) document.location = 'pendingEntities.php';</script>";
} else {
echo "<script type='text/javascript'>if(!alert(\"Error: Could not approve: " . $_GET['approveName'] . "\")) document.location = 'pendingEntities.php';</script>";
}
}
?>
<!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>Pending Approval Animals/Crops</h4>
<br>
</div>
</div> <!-- End Row -->
<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="pendingEntities.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">Approve Selection</th>
<th scope="col">Name</th>
<th scope="col">Type</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM FarmItem WHERE IsApproved = '0'";
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";
//echo "<br>" . $query . "<br>";
$unapprovedItems = mysqli_query($db, $query);
while ($row = mysqli_fetch_array($unapprovedItems)) { ?>
<tr>
<td class="link-color"><a href=<?php echo "\"pendingEntities.php?deleteName=" . $row['Name'] . "\"";?>>Delete</a></td>
<td class="link-color"><a href=<?php echo "\"pendingEntities.php?approveName=" . $row['Name'] . "\"";?>>Approve</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>
</body>
</html>