-
Notifications
You must be signed in to change notification settings - Fork 0
/
editGiftCard.php
91 lines (83 loc) · 2.04 KB
/
editGiftCard.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
<?php
session_start();
include('header.php');
?>
<html>
<body>
<?php
include('siteNavigator.php');
?>
<h1>Manage Gift Cards</h1>
<form action = "editGiftCard.php" method = "POST">
<table>
<tr>
<td>Search for gift cards</td>
<td><input type = "text" name = "searchtext"></td>
</tr>
<tr>
<td>Look up by vendor ID</td>
<td><input type = "radio" name = "searchtype" value = 'vendorID'/></td>
</tr>
<tr>
<td>Look up by vendor name</td>
<td><input type = "radio" name = "searchtype" value = 'vendorName' CHECKED /></td>
</tr>
<tr><td><br/>
<input type = "submit" value = "Search" id="submit" />
</td></tr>
<!--<tr><td></td></tr> -->
</table>
</form>
<form action = 'giftCardEditor.php' method = 'post'>
<?php
//we can only display this page if user is admin.
include "DB.php";
$searchtype = $_POST['searchtype'];
if ($searchtype != ''){
echo "
<table>
<tr>
<th>Name</th>
<th>Cost</th>
<th>Percent</th>
<th>Available?</th>
</tr>";
$query = "SELECT vendor, orderFormCardID id, cost, percent, isAvailable FROM giftcards WHERE ";
if ($searchtype == 'vendorID'){
$vendorIDtext = $_POST['searchtext'];
$sanitizedText = mysqli_real_escape_string($db, $vendorIDtext);
$query = $query."orderFormCardID = $sanitizedText;";
}else if ($searchtype == 'vendorName'){
$vendorName = $_POST['searchtext'];
$sanitizedText = mysqli_real_escape_string($db, $vendorName);
$query = $query."vendor LIKE '%$sanitizedText%';";
}
$result = mysqli_query($db, $query);
while ($row = mysqli_fetch_array($result)){
$id = $row['id'];
$vendor = $row['vendor'];
$cost = "$".$row['cost'].".00";
$percent = $row['percent']."%";
if ($row['isAvailable'] == 1){
$isAvailable = 'yes';
}else{
$isAvailable = 'no';
}
echo "
<tr>
<td>$vendor</td>
<td>$cost</td>
<td>$percent</td>
<td>$isAvailable</td>
<td><input type = 'submit' value = 'edit' name = '$id'/></td>
</tr>";
}
}
?>
</table></form>
<!-- Page info goes above-->
<?php
include('footer.php');
?>
</body>
</html>