-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
438 lines (334 loc) · 13.8 KB
/
admin.php
File metadata and controls
438 lines (334 loc) · 13.8 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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
<?php
error_reporting(0);
session_start();
include("dbconnect.php");
$stockrep = 5;
$username = $_SESSION['username'];
if(empty($username)){
die("error 467. bad login! <a href='login.php'>login here</a>");
}
$action = $_REQUEST['action'];
?>
<style>
td { font-size:11px; font-family:verdana; vertical-align:top; background: #EEEEEE; color: #333333; padding: 5px; }
input,select{ font-size:11px;font-family:verdana; }
td:hover{ background: #DDDDDD; color: #FF0000; }
th { background: #007700; color: #eee; font-family: verdana; font-size: 11px;}
a, a:visited { color: #0174d9; text-decoration: none; }
a:hover { text-decoration: underline; }
.a, .a:visited { color: #101010; text-decoration: none;}
.a:hover { background: #eee; text-decoration: none; }
</style>
<title>ADMIN PANEL</title>
<table border='0' width=700 align='center' cellpadding='2' cellspacing='2' bgcolor='#EEEEEE'><tr><td>
<B>administration area</B> <BR><BR>
| <A HREF="admin.php"><B>Home</B></A>
| <A HREF="admin.php?action=showall"><B>Products</B></A>
| <A HREF="admin.php?action=addnew"><B>Add</B></A>
| <A HREF="admin.php?action=viewpaid"><B>Transactions</B></A>
| <A HREF="admin.php?action=validate"><B>Validate Key</B></A>
| <A HREF="admin.php?action=strep"><B>Stock Report</B></A>
| <A HREF="admin.php?action=stockeval"><B>Stock evaluation</B></A>
| <A HREF="login.php?action=logout"><B>Logout </B></A>
</td></tr></table>
<BR><BR>
<?php
if($action=="insert"){
if ($_FILES['logo']['name'] != "") {
$imageInfo = getimagesize($_FILES['logo']['tmp_name']); // get image size
$width = $imageInfo[0]; // image width
$height = $imageInfo[1]; // image height
if($height > 2000 || $width > 2000){
echo "<script> alert('Image is to big! Try to resize the picture!') </script>";
exit;
} // check size
$newimg1 = date("YmdHis").".jpg"; // set name for new image
$newimg2 = date("YmdHis").".pdf"; // set name for pdf if is necesary
if(stristr($_SERVER['OS'],"win")){
$path = "prodimg/";
} // determin path of image folder
elseif(stristr($_SERVER['OS'],"linux")){
$path = str_replace("admin.php","",$_SERVER['SCRIPT_FILENAME']) . "prodimg/";
}
else {
$path = "prodimg/";
}
move_uploaded_file ( $_FILES['logo']['tmp_name'], $path . $newimg1 );
} // copy image in image folder
else{
$newimg1="pc.gif";
} // if is not posible than set image name as pc.gif
$cat = $_POST['cat'];
$price = $_POST['price'];
$prodname = $_POST['prodname'];
$desc = $_POST['descr'];
$stock = $_POST['stock'];
$res = mysql_query("insert into item_tbl(catid,itemname,description,cost,stock,picture)
values('$cat','$prodname','$desc','$price','$stock','$newimg1')");
echo "<script>location.replace('admin.php?action=showall')</script>";
}
elseif($action=="delete"){ // start of delete action
$id = $_GET['id'];
mysql_query("delete from item_tbl where itemid='$id'");
echo "<script>alert('product $id has been deleted')</script>";
echo "<script>location.replace('admin.php?action=showall')</script>";
} // end of delete action
elseif($action=="editprodnow"){
$cat = $_GET['cat'];
$prodname = $_GET['prodname'];
$stock = $_GET['stock'];
$price = $_GET['price'];
$descr = stripslashes($_GET['descr']);
$descr = str_replace("\'", "'", $descr);
$descr = str_replace('\"', '"', $descr);
$id = $_GET['id'];
mysql_query("update item_tbl set catid='$cat', description='$descr', itemname='$prodname', stock='$stock',cost='$price' where itemid='$id'");
echo "<script>alert('product $id has been edited')</script>";
echo "<script>location.replace('admin.php?action=showall')</script>";
}
elseif($action=="showall"){
$res = mysql_query("select * from item_tbl");
$row = mysql_num_rows($res);
echo "<table bgcolor='#000000' border='0' width=700 align='center' cellpadding='1' cellspacing='1'>";
for($i=0;$i<$row;$i++){
$itemid = mysql_result($res,$i,"itemid");
$itemname = mysql_result($res,$i,"itemname");
$cost = mysql_result($res,$i,"cost");
$stock = mysql_result($res,$i,"stock");
$picture = mysql_result($res,$i,"picture");
$description = mysql_result($res,$i,"description");
if($i%2){$bgcolor = "#FFFFFF";} else {$bgcolor = "#DDDDDD";}
echo "
<tr>
<td width=150><B>Title:</B>$itemname<B> <BR>Price: </B>$cost<B><BR>Stocks: $stock</B><BR></td>
<td width=50> <A HREF='admin.php?id=$itemid&action=editprod'>edit</A> <BR>
<A HREF='admin.php?id=$itemid&action=delete'>delete</A><BR>
<A HREF='prodshow.php?id=$itemid' target='_new'>view</A></td>
<td width=50> <img src='prodimg/$picture' width=50 height=40> </td><td> Info:</B> $description</td>
</tr>";
}
echo "</table><BR>";
}
elseif($action=="addnew"){
echo "<CENTER><form action='admin.php' method='post' enctype='multipart/form-data'>";
echo "<select name=cat><option value='' selected> - Select one category -";
$res = mysql_query("select * from category_tbl");
$row = mysql_num_rows($res);
for($i=0;$i<$row;$i++){
echo "<option value='".mysql_result($res,$i,"catid")."'> ".mysql_result($res,$i,"description");
}
echo "</select><BR>";
echo "<table>";
echo "<tr><td> prod. name: </td><td><input type=text name=prodname size=30></td></tr>";
echo "<tr><td> price: </td><td><input type=text name=price size=30 ></td></tr>";
echo "<tr><td> Stock: </td><td><input type=text name=stock size=30 ></td></tr>";
echo "<tr><td> description: </td><td><textarea name=descr cols=30 rows=7></textarea></td></tr>";
echo "<tr><td> prod. image: </td><td><input type=file name=logo size=20></td></tr>";
echo "<tr><td> </td><td><input type=submit name=submit value='add product'></td></tr>";
echo "<tr><td> </td><td><input type=hidden name=action value=insert></td></tr>";
echo "<tr><td></td><td></form></td></tr>";
echo "</table>";
}
elseif($action=="editprod"){
echo "<CENTER><form action='admin.php' method='get'>";
$id = $_GET["id"];
$res = mysql_query("select * from item_tbl where itemid='$id'");
$res2 = mysql_query("select * from category_tbl");
$cid = mysql_result($res,0,"catid");
$name = mysql_result($res,0,"itemname");
$desc = mysql_result($res,0,"description");
$cost = mysql_result($res,0,"cost");
$stock = mysql_result($res,0,"stock");
echo "<table><tr><td>";
echo "category: <select name=cat>";
for($x=0;$x<mysql_num_rows($res2);$x++)
{
$catid = mysql_result($res2,$x,"catid");
$category = mysql_result($res2,$x,"description");
if($cid==$catid) { echo "<option value='$catid' selected>$category"; }
else { echo "<option value='$catid'>$category"; }
}
echo "</select><BR>";
echo "product name: <input type=text name=prodname size=30 value='$name'><BR>";
echo "price: <input type=text name=price size=30 value='$cost'><BR>";
echo "stock: <input type=text name=stock size=30 value='$stock'><BR>";
echo "description: <textarea name=descr cols=30 rows=7>$desc</textarea><BR>";
echo "<input type=submit name=submit value='change product info now'><BR>";
echo "<input type=hidden name=action value=editprodnow><BR>";
echo "<input type=hidden name=id value='".$id."'><BR>";
echo "</form></CENTER>";
echo "</td></tr></table>";
}
elseif($action=="validate"){
echo "<div style='width:700px; margin:auto;'>";
echo " <form action='admin.php' method='get'>
<input type='hidden' name='action' value='validate2'>
<b>Enter KEY</b><br>
<input type='text' name='key' size='30'>
<input type='submit' value='Validate'>
</form>";
}
elseif($action=="viewtr"){
$tid = $_GET['tid'];
$query = "select * from `transaction_tbl` where `tid`='$tid'";
$result = mysql_query($query) or die(mysql_error());
$prid = mysql_result($result,0,"productid");
$curstock = mysql_result(mysql_query("select * from item_tbl where itemid='$prid'"),0,"stock");
$name = mysql_result($result,0,"fname");
$prodname = mysql_result($result,0,"productname");
$contact = mysql_result($result,0,"contact");
$stock = mysql_result($result,0,"stock");
$qty = (int)mysql_result($result,0,"quantity");
$trno = mysql_result($result,0,"key");
$email = mysql_result($result,0,"email");
$tid = mysql_result($result,0,"tid");
$cost = (int)mysql_result($result,0,"price");
$price = number_format($qty * $cost);
$stat = mysql_result($result,0,"orderstat");
$cost = number_format($cost);
echo "<div style='width:700px; margin:auto;'>";
echo "Product name: $prodname<br>
Cost: P$cost <br>
Stocks: $curstock <br><br>
Customer: $name<br>
Ordered: $qty<br>
Contact: $contact<br>
Email: $email<br>
Amount to paid: P$price <br><br>
<a href='admin.php?action=validate2&key=$trno'>Validate</a>";
}
elseif($action=="validate2"){
echo "<div style='width:700px; margin:auto;'>";
$key = $_GET['key'];
$query = "select * from `transaction_tbl` where `key`='$key' and `orderstat`='pending'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_num_rows($result);
$prid = mysql_result($result,0,"productid");
$qty = (int)mysql_result($result,0,"quantity");
$oldstock = mysql_result(mysql_query("select * from item_tbl where itemid='$prid'"),0,"stock");
$newstock = $oldstock - $qty;
if($qty > (int)$oldstock) { die("<script>alert('Out of Stocks !!'); location.replace('admin.php');</script>");}
if($row>0){
$query = "update `transaction_tbl` set `orderstat`='paid', `stock`='$newstock' where `key`='$key'";
$result = mysql_query($query) or die(mysql_error());
mysql_query("update item_tbl set stock = '$newstock' where itemid='$prid'");
echo "<script>alert('Validated Successfully!!')</script>";
echo "<script>location.replace('admin.php')</script>";
}
else { echo "<center>Invalid Key!!"; }
}
elseif($action=="strep"){
$res = mysql_query("select * from item_tbl where stock <= $stockrep");
$row = mysql_num_rows($res);
echo "<div style='width:700px; margin:auto;'>";
echo "<table border='0' cellpadding=1 cellspacing=1 bgcolor='#000' width='70%'>
<th>ItemID</th><th>Product Name</th><th>Category</th><th>Stocks left</th>";
for($x=0;$x<$row;$x++)
{
$itemid = mysql_result($res,$x,"itemid");
$itemname = mysql_result($res,$x,"itemname");
$catid = mysql_result($res,$x,"catid");
$stock = mysql_result($res,$x,"stock");
$picture = mysql_result($res,$x,"picture");
$description = mysql_result($res,$x,"description");
$category = mysql_result(mysql_query("select * from category_tbl where catid=$catid"),0,"description");
if($stock == 0) { $c = "#AC1614"; }
else { $c = "#0174FF"; }
echo "<tr>
<td align='center'>$itemid</td>
<td><a href='admin.php?id=$itemid&action=editprod'><font color='$c'>$itemname</font></a></td>
<td>$category</td>
<td align='center'>$stock</td>
</tr>";
}
echo "</table>";
}
elseif($action=="stockeval"){
echo "<div style='width:700px; margin:auto;'>";
echo "<table cellspacing=1 bgcolor='#000000' border=0 cellpadding=1 width=100%><th width=60>ItemID</th>
<th width=250>Item name</th><th width=100>Cost</th><th width=100>QTY Left</th><th>Amount</th>";
$res = mysql_query("select * from item_tbl");
$row = mysql_num_rows($res);
for($i=0;$i<$row;$i++){
$id = mysql_result($res,$i,"itemid");
$itemname = mysql_result($res,$i,"itemname");
$catid = mysql_result($res,$i,"catid");
$qty = (int)mysql_result($res,$i,"stock");
$picture = mysql_result($res,$i,"picture");
$description = mysql_result($res,$i,"description");
$itemcost = mysql_result($res,$i,"cost");
$amount = $itemcost * $qty;
$total = $total + $amount;
if($qty>=1){
echo "
<tr>
<td align='center'>$id</td>
<td>$itemname</td>
<td align='right'>".number_format($itemcost)."</td>
<td align='center'>$qty</td>
<td align='right'>".number_format($amount)."</td>
</tr>";
}
}
echo "<tr><td></td><td></td><td></td><td align='center'><b>TOTAL</b></td><td align='right'>
<font color='#0174d9'><b>P".number_format($total)."</b></font></td></tr>";
echo "</table></div>";
}
elseif($action=="viewpaid"){
echo "<div style='width:700px; margin:auto;'>";
$query = "select * from `transaction_tbl` where `orderstat`='paid' order by `tid` DESC";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_num_rows($result);
echo "<table border='0' cellspacing='1' cellpadding='1' bgcolor='#000'>";
echo "<th width='60'>ItemID</th><th width='250'>Item name</th><th width='150'>Client name</th>
<th width='60'>Qty</th><th width='75'>Cost</th><th width='100'>Amount</th>";
for($x=0;$x<$row;$x++)
{
$name = mysql_result($result,$x,"fname");
$prodname = mysql_result($result,$x,"productname");
$qty = (int)mysql_result($result,$x,"quantity");
$trno = mysql_result($result,$x,"key");
$tid = mysql_result($result,$x,"tid");
$pid = mysql_result($result,$x,"productid");
$cost = (int)mysql_result($result,$x,"price");
$price = $qty * $cost;
$total = $total + $price;
echo "
<tr>
<td align='center'>$pid</td>
<td>$prodname</td>
<td>$name</td>
<td align='center'>$qty</td>
<td align='right'>".number_format($cost)."</td>
<td align='right'>".number_format($price)."</td>
</tr>";
}
echo "<tr><td></td><td></td><td></td><td></td><td align='center'><b>TOTAL</b>
<td align='right'><font color='#0174d9'><b>P".number_format($total)."</b></font></td></tr>";
echo "</table></div>";
}
else
{
echo "<div style='width:700px; margin:auto;'>";
$query = "select * from `transaction_tbl` where `orderstat`='pending' order by `quantity` desc limit 20";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_num_rows($result);
echo "<b>Pending List($row)</b><br><hr>";
for($x=0;$x<$row;$x++)
{
$name = mysql_result($result,$x,"fname");
$prodname = mysql_result($result,$x,"productname");
$qty = (int)mysql_result($result,$x,"quantity");
$trno = mysql_result($result,$x,"key");
$tid = mysql_result($result,$x,"tid");
$cost = (int)mysql_result($result,$x,"price");
$price = number_format($qty * $cost);
echo "<a href='admin.php?action=viewtr&tid=$tid' class='a'><div class='a'>
Item: $prodname<br>
Price: P$price <br>
Buyer: $name <br>
Key: $trno</div></a><hr>";
}
echo "</div>";
}
?>