-
Notifications
You must be signed in to change notification settings - Fork 0
/
editDealForm.php
executable file
·193 lines (182 loc) · 8.66 KB
/
editDealForm.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
<?php
require_once 'Deal.php';
require_once 'Connection.php';
require_once 'DealTableGateway.php';
require_once 'BusinessTableGateway.php';
$id = session_id();
if ($id == "") {
session_start();
}
require 'ensureUserLoggedIn.php';
$username = $_SESSION['user_id'];
if (isset($_GET) && isset($_GET['sortOrder'])) {
$sortOrder = $_GET['sortOrder'];
$columnNames = array("businessID", "business_name", "business_address", "business_lat", "business_long", "business_type");
if (!in_array($sortOrder, $columnNames)) {
$sortOrder = 'businessID';
}
}
else {
$sortOrder = 'businessID';
}
if (!isset($_GET) || !isset($_GET['id'])) {
die('Invalid request');
}
$dealId = $_GET['id'];
$_SESSION['id'] = $dealId;
$connection = Connection::getInstance();
$gateway = new DealTableGateway($connection);
$businessGateway = new BusinessTableGateway($connection);
$businesses = $businessGateway->getBusinessByUserId($username, $sortOrder);
$statement = $gateway->getDealById($dealId);
if ($statement->rowCount() !== 1) {
die("Illegal request");
}
$row = $statement->fetch(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Lato:400,700,900' rel='stylesheet' type='text/css'>
<meta charset="UTF-8">
<script type="text/javascript" src="Javascript/deal.js"></script>
<title>Yoink</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="CSS/bootstrap.min.css" rel="stylesheet">
<link href="CSS/custom.css" rel="stylesheet">
<script src="Javascript/respond.js"></script>
</head>
<body>
<div class="row">
<nav class="navbar navbar-default navbar-fixed-top navbar-inverse">
<div class="container">
<div class="navbar-brand">
<p><a href="index.php"><img src="img/yoinklogosmall.png" alt="" class="img-responsive"></a></p>
</div>
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#collapse">
<span class="sr-only">Toggle navigation</span>
<span class="glyphicon glyphicon-arrow-down"></span>
MENU
</button>
</div>
<div class="collapse navbar-collapse" id="collapse">
<ul class="nav navbar-nav navbar-right">
<li><p><?php
$username = $_SESSION['username'];
$numBus = $_SESSION['numBus'];
echo 'Welcome ' . $username;
?></p></li>
<li><a></a></li>
<li><a href="home.php">Businesses</a></li>
<li><a href="viewDeals.php">Deals</a></li>
<li class=""><?php require 'toolbar.php' ?></li>
</ul>
</div>
</div>
</nav>
</div>
<div class = "row">
<div class="welcome">
<div class="container">
<h1><?php
echo 'Edit ' . $row['deal_description']; ?>
</div>
</div>
</div>
<div class="container">
<form id="editDealForm" name="editDealForm" action="editDeal.php" method="POST">
<input type="hidden" name="id" value="<?php echo $dealId; ?>" />
<table class="table table-bordered table-responsive">
<tbody>
<tr>
<td>Deal</td>
<td>
<input type="text" name="deal_description" value="<?php
if (isset($_POST) && isset($_POST['deal_description'])) {
echo $_POST['deal_description'];
} else
echo $row['deal_description']
?>" />
<span id="dealNameError" class="error">
<?php
if (isset($errorMessage) && isset($errorMessage['deal_description'])) {
echo $errorMessage['deal_description'];
}
?>
</span>
</td>
</tr>
<tr>
<td>Deal Category</td>
<td>
<select name="deal_category">
<option value="Café">Café</option>
<option value="Clothes & Fashion">Clothes & Fashion</option>
<option value="Electronics">Electronics</option>
<option value="Entertainment">Entertainment</option>
<option value="Food & Drink">Food & Drink</option>
<option value="Health & Beauty">Health & Beauty</option>
<option value="Miscellaneous">Miscellaneous</option>
<option value="Music, Movies & Games">Music, Movies & Games</option>
<option value="Pubs">Pubs</option>
<option value="Restaurants">Restaurants</option>
<input type="submit" style="color: transparent; background-color: transparent;" name="deal_category" value="<?php
if (isset($_POST) && isset($_POST['deal_category'])) {
echo $_POST['deal_category'];
}
?>" />
<span id="dealCategoryError" class="error">
<?php
if (isset($errorMessage) && isset($errorMessage['dealCategoryError'])) {
echo $errorMessage['dealCategoryError'];
}
?>
</span>
</select>
</td>
</tr>
<tr>
<td>Business</td>
<td>
<select name="businessId" value="<?php
if (isset($_POST) && isset($_POST['business_name'])) {
echo $_POST['business_name'];
} else
echo $row['business_name']
?>">
<?php
$b = $businesses->fetch(PDO::FETCH_ASSOC);
while ($b) {
echo '<option value="' . $b['businessID'] . '">' . $b['business_name'] . '</option>';
$b = $businesses->fetch(PDO::FETCH_ASSOC);
}
?>
</select>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" id="editDealForm" value="Update Deal" name="updateDeal" />
</td>
</tr>
</tbody>
</table>
</form>
</div>
<div class="row">
<div class = "footerBar navbar-fixed-bottom col-md-12 col-xs-12">
<p>© YOINK! 2016. All rights reserved.</p>
</div>
</div>
<!-- javascript -->
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="Javascript/bootstrap.min.js"></script>
<script>
$('a.btn-info').tooltip();
</script>
</body>
</html>