-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadmin.php
More file actions
288 lines (272 loc) · 10.1 KB
/
admin.php
File metadata and controls
288 lines (272 loc) · 10.1 KB
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?php
session_start();
include('db.php');
include('header.php');
?>
<?php
if(!isset($_SESSION['key']))
{
header("Location: /stuff-sharing/login.php?error=NOT_LOGIN");
}
else
{
$email = pg_escape_string($connection,$_SESSION['key']);
$query = "SELECT firstName, lastName, isAdmin FROM users where email='".$email."'";
$result = pg_query($connection,$query) or die('Query failed:'.pg_last_error());
$cRow = pg_fetch_row($result);
if(!$cRow[2])
{
header("Location: /stuff-sharing/error.php");
}
}
if(isset($_POST['deletebidid']))
{
$deletebidid = $_POST['deletebidid'];
$uresult = pg_query($connection, "SELECT userpoint FROM users WHERE email = '".$deletebidid[1]."'");
$oldbidAmount = pg_fetch_row($uresult);
$newbidAmount = $oldbidAmount[0] + $deletebidid[2];
$updateResult = pg_query($connection, "UPDATE users SET userpoint = '".$newbidAmount."' WHERE email = '".$deletebidid[1]."';");
$deleteResult = pg_query($connection, "DELETE FROM biddinglist WHERE itemid = '".$deletebidid[0]."' AND bidderid = '".$deletebidid[1]."';");
if($deleteResult){
echo ("
<div class=\"alert alert-info\">
<a href=\"#\" class=\"close\" data-dismiss=\"alert\" aria-label=\"close\">×</a>
Bid Deleted!
</div>
");
}
}
if(isset($_POST['deleterecordid']))
{
$deleterecordid = $_POST['deleterecordid'];
$deleterecordborrower = $_POST['deleterecordborrower'];
$deleterecordlender = $_POST['deleterecordlender'];
$deleterecordbidamount = $_POST['deleterecordbidamount'];
$uresult = pg_query($connection, "SELECT userpoint FROM users WHERE email = '".$deleterecordborrower."'");
$oldbidAmount = pg_fetch_row($uresult);
$newbidAmount = (int)$oldbidAmount[0] + (int)$deleterecordbidamount;
$updateResult = pg_query($connection, "UPDATE users SET userpoint = '".$newbidAmount."' WHERE email = '".$deleterecordborrower."'");
$deleteResult = pg_query($connection, "DELETE FROM record WHERE itemid = ".$deleterecordid);
if($deleteResult){
echo ("
<div class=\"alert alert-info\">
<a href=\"#\" class=\"close\" data-dismiss=\"alert\" aria-label=\"close\">×</a>
Record Deleted!
</div>
");
}
}
//get users information
$usersResult = pg_query($connection,"SELECT * from Users;")
or die ('Query failed: '.pg_last_error());
//get all items
$itemResult = pg_query($connection,"SELECT * from itemlist;")
or die ('Query failed: '.pg_last_error());
//get all bids
$bidResult = pg_query($connection,"SELECT bl.itemid, il.itemname, bl.bidderid, CONCAT(u.firstname, u.lastname), u.email, bl.bidamount from biddinglist bl INNER JOIN itemlist il ON bl.itemid = il.itemid INNER JOIN users u ON bl.bidderid = u.email;")
or die ('Query failed: '.pg_last_error());
$recordResult = pg_query($connection,"SELECT i.itemId, i.ownerEmail, r.bidderid, i.itemName, i.itemDescription, i.itemCategory, r.bidAmount FROM itemlist i, record r WHERE r.itemId = i.itemId") or die ('Query failed: '.pg_last_error());
if(isset($_POST['userid']))
{
$userid = $_POST['userid'];
$_SESSION['userid'] = $userid;
header("Location: /stuff-sharing/edituser.php");
}
if(isset($_POST['itemid']))
{
$itemid = $_POST['itemid'];
$_SESSION['itemid'] = $itemid;
header("Location: /stuff-sharing/admin_edititem.php");
}
if(isset($_POST['deleteitemid']))
{
$deleteitemid = $_POST['deleteitemid'];
try
{
$deleteResult = pg_query($connection, "DELETE FROM itemlist WHERE itemid = '".$deleteitemid."';");
if($deleteResult)
{
echo ("
<div class=\"alert alert-info\">
<a href=\"#\" class=\"close\" data-dismiss=\"alert\" aria-label=\"close\">×</a>
Item Deleted!
</div>
");
}
else
{
echo ("
<div class=\"alert alert-info\">
<a href=\"#\" class=\"close\" data-dismiss=\"alert\" aria-label=\"close\">×</a>
Please remove the item from advertising first!
</div>
");
}
}
catch(Exception $e)
{
echo ("
<div class=\"alert alert-info\">
<a href=\"#\" class=\"close\" data-dismiss=\"alert\" aria-label=\"close\">×</a>
Please remove the item from advertising first!
</div>
");
}
}
?>
<body>
<?php
include('admin_navbar.php');
?>
<div class="container">
<?php
if(isset($_GET['msg']))
{
if($_GET['msg'] = "ITEM_ADD_SUCCESS")
{
echo "<div class='container'>
<div class='alert alert-success alert-dismissible' role='alert'>
<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button>
<strong>Success!</strong> Item added!
</div></div>";
}
else if ($_GET['msg'] = "ADV_SUCCESS")
{
echo "<div class='container'>
<div class='alert alert-success alert-dismissible' role='alert'>
<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button>
<strong>Success!</strong> Item advertised!
</div></div>";
}
}
?>
</div>
<div class="container">
<div class="starter-template">
<?php
echo "<p>Welcome, " .$cRow[0]. " " .$cRow[1]. "</p>";
?>
</div>
</div>
<div class="container">
<div class="accordionSection" id="editUsers"><h3>Edit Users Credentials</h3>
<div class="table-responsive">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th>First Name</th> <th>Last Name</th> <th>DOB</th> <th>Email</th> <th>User Point</th><th>#Black List</th> <th></th>
</tr>
</thead>
<tbody>
<?php
while($row = pg_fetch_row($usersResult)){
echo "\t<tr>\n";
echo "\t\t<td>$row[0]</td>\n";
echo "\t\t<td>$row[1]</td>\n";
echo "\t\t<td>$row[3]</td>\n";
echo "\t\t<td>$row[4]</td>\n";
echo "\t\t<td>$row[6]</td>\n";
echo "\t\t<td>$row[7]</td>\n";
echo "\t\t<td><form action=\"admin.php\" method=\"post\">";
echo "<input type=\"hidden\" name=\"userid\" value=\"".$row[4]."\"/>";
echo "<button type=\"submit\" class=\"btn btn-success\">Edit</button></form></td>\n";
echo "\t</tr>\n";
}
?>
</tbody>
</table>
</div>
</div>
<div class="accordionSection" id="editItem"><h3>Edit Advertising Items</h3>
<div class="table-responsive">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th>Item ID</th> <th>Owner Email</th> <th>Item Name</th> <th>Item Description</th> <th>Item Category</th> <th></th>
</tr>
</thead>
<tbody>
<?php
while($row = pg_fetch_row($itemResult)){
echo "\t<tr>\n";
echo "\t\t<td>$row[0]</td>\n";
echo "\t\t<td>$row[1]</td>\n";
echo "\t\t<td>$row[2]</td>\n";
echo "\t\t<td>$row[3]</td>\n";
echo "\t\t<td>$row[5]</td>\n";
echo "\t\t<td><form action=\"admin.php\" method=\"post\">";
echo "<input type=\"hidden\" name=\"itemid\" value=\"".$row[0]."\"/>";
echo "<button type=\"submit\" class=\"btn btn-success\">Edit</button></form></td>\n";
echo "\t\t<td><form action=\"admin.php\" method=\"post\">";
echo "<input type=\"hidden\" name=\"deleteitemid\" value=\"".$row[0]."\"/>";
echo "<button type=\"submit\" class=\"btn btn-sm\"><span class=\"glyphicon glyphicon-trash\" aria-hidden=\"true\"></span></button></form></td>\n";
echo "\t</tr>\n";
}
?>
</tbody>
</table>
</div>
</div>
<div class="accordionSection" id="editItem"><h3>Drop Bids</h3>
<div class="table-responsive">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th>Item Name</th> <th>Bidder Name</th> <th>Bid Amount</th> <th></th>
</tr>
</thead>
<tbody>
<?php
while($row = pg_fetch_row($bidResult)){
echo "\t<tr>\n";
echo "\t\t<td>$row[1]</td>\n";
echo "\t\t<td>$row[3]</td>\n";
echo "\t\t<td>$row[5]</td>\n";
echo "\t\t<td><form action=\"admin.php\" method=\"post\">";
$postvalue=array($row[0],$row[2],$row[5]);
foreach($postvalue as $value)
{
echo "<input type=\"hidden\" name=\"deletebidid[]\" value=\"".$value."\"/>";
}
echo "<button type=\"submit\" class=\"btn btn-sm\"><span class=\"glyphicon glyphicon-trash\" aria-hidden=\"true\"></span></button></form></td>\n";
echo "\t</tr>\n";
}
?>
</tbody>
</table>
</div>
</div>
<div class="accordionSection" id="editRecord"><h3>Edit Records</h3>
<div class="table-responsive">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th>Item ID</th> <th>Lender Email</th> <th>Borrower Email</th> <th>Item Name</th> <th>Item Description</th> <th>Item Category</th> <th>Successful Bid Amount</th> <th></th>
</tr>
</thead>
<tbody>
<?php
while($row = pg_fetch_row($recordResult)){
echo "\t<tr>\n";
echo "\t\t<td>$row[0]</td>\n";
echo "\t\t<td>$row[1]</td>\n";
echo "\t\t<td>$row[2]</td>\n";
echo "\t\t<td>$row[3]</td>\n";
echo "\t\t<td>$row[4]</td>\n";
echo "\t\t<td>$row[5]</td>\n";
echo "\t\t<td>$row[6]</td>\n";
echo "\t\t<td><form action=\"admin.php\" method=\"post\">";
echo "<input type=\"hidden\" name=\"deleterecordid\" value=\"".$row[0]."\"/>";
echo "<input type=\"hidden\" name=\"deleterecordlender\" value=\"".$row[1]."\"/>";
echo "<input type=\"hidden\" name=\"deleterecordborrower\" value=\"".$row[2]."\"/>";
echo "<input type=\"hidden\" name=\"deleterecordbidamount\" value=\"".$row[6]."\"/>";
echo "<button type=\"submit\" class=\"btn btn-sm\"><span class=\"glyphicon glyphicon-trash\" aria-hidden=\"true\"></span></button></form></td>\n";
echo "\t</tr>\n";
}
?>
</tbody>
</table>
</div>
</div>
</div>
</body>