-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomerRequestExtra.php
245 lines (223 loc) · 9.03 KB
/
customerRequestExtra.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
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
<div class="containerReg">
<?php
// include the header
session_start();
include('header.php');
?>
<style>
.btn {
display: inline-block;
color: white;
text-align: center;
font-size: 14px;
padding: 10px 20px;
margin: 10px 2px;
cursor: pointer;
border: none;
border-radius: 4px;
text-decoration: none;
transition-duration: 0.4s;
}
.btn-red {
background-color: #f44336;
}
.btn-orange {
background-color: #FFA500;
}
.btn:hover {
opacity: 0.8;
}
/* Styling the dropdown */
.select-dropdown {
display: inline-block;
width: 100%;
max-width: 300px;
padding: 8px 16px;
margin: 8px 0;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 14px;
background-color: white;
color: black;
cursor: pointer;
}
.select-dropdown:hover {
border-color: #888;
}
</style>
<h1>Welcome to the Request Extras page, <?php echo $_SESSION['customerusername']; ?>!</h1>
<form action="customerHub.php" method="post" style="display: inline;">
<input type="submit" value="Back to Customer Hub" class="btn btn-orange">
</form>
<h1>Available extras</h1>
</div>
<div class="container">
<?php
// Query the database to retrieve the customer's name
$CustomerName = $_SESSION['customerusername'];
// Query the database to retrieve the customer's name
$CustomerName = $_SESSION['customerusername'];
$query5 = "SELECT * FROM extra_list";
$result5 = mysqli_query($conn, $query5);
if (mysqli_num_rows($result5) > 0) {
echo "<table>";
echo "<tr><th>Extra Name</th><th>Price</th></tr>";
while ($row = mysqli_fetch_assoc($result5)) {
// Display the customer information on the web page
echo "<tr>";
echo "<td>" . $row["ExtraName"] . "</td>";
echo "<td>" . $row["ExtraPrice"] . "</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
echo "<h1>Your selected extras</h1>";
$query = "SELECT CustomerID FROM customer WHERE CustomerLogin = '$CustomerName'";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) == 1) {
$row = mysqli_fetch_assoc($result);
$custid = $row['CustomerID'];
// Query the customer information table using the customer's name
$query2 = "SELECT e.* FROM booked_extras e INNER JOIN reservation r ON e.ReservationID = r.ReservationID WHERE r.CustomerID = '$custid'";
$result2 = mysqli_query($conn, $query2);
if ($result2) { // add this check
echo "<form action='customerRequestExtra.php' method='POST'>";
echo "<table>";
echo "<tr><th>Extra ID</th><th>Reservation ID</th><th>Price</th><th>Extra Description</th><th>Operations</th></tr>";
// loop over $result data
if (mysqli_num_rows($result2) > 0) {
while ($row = mysqli_fetch_assoc($result2)) {
// Display the customer information on the web page
$ExtraID = $row["ExtraID"];
$ReservationID = $row["ReservationID"];
$ExtraPrice = $row["ExtraPrice"];
$ExtraDesc = $row["ExtraDescription"];
echo "<tr>";
echo "<td>" . $row["ExtraID"] . "</td>";
echo "<td>" . $row["ReservationID"] . "</td>";
echo "<td>" . $row["ExtraPrice"] . "</td>";
echo "<td>" . $row["ExtraDescription"] . "</td>";
echo "<td><input type='submit' class='btn btn-red' value='Delete!' id='delete' name='delete[$ExtraID]'></td>";
echo "</tr>";
}
} else {
echo "0 results";
}
// end table
echo "</table>";
echo "</form>";
} else {
echo "Error executing query: " . mysqli_error($conn);
}
}
// Retrieve available reservations for the customer
$query4 = "SELECT r.ReservationID FROM reservation r WHERE r.CustomerID = '$custid'";
$result4 = mysqli_query($conn, $query4);
$reservationIDs = [];
while ($row = mysqli_fetch_assoc($result4)) {
$reservationIDs[] = $row['ReservationID'];
}
?>
<div class="containerReg">
<h1>Please fill in this form to request an extra.</h1>
<form action="customerRequestExtra.php" method="POST">
<label for="reservationID"><b>Reservation ID</b></label></br>
<select name="reservationID" id="reservationID" class="select-dropdown">
<?php
foreach ($reservationIDs as $reservationID) {
echo '<option value="' . $reservationID . '">' . $reservationID . '</option>';
}
?>
</select></br>
<label for="description"><b>Choose an extra</b></label></br>
<select name="description" id="description" class="select-dropdown">
<option value="Room Service">Room Service</option>
<option value="Car Rental">Car Rental</option>
<option value="Firmer pillows">Firmer pillows</option>
<option value="Electric socket adapters">Electric socket adapters</option>
<option value="Bottle of champagne">Bottle of champagne</option>
</select>
<label for="extraDate">Select date for extra:</label>
<input type="date" id="extraDate" name="extraDate">
<button type="submit" class="btn btn-orange" id="requestExtra" name="requestExtra">Request Extra</button>
</form>
</div>
<?php
if (isset($_POST['requestExtra'])) {
$reservationID = $_POST['reservationID'];
$description = $_POST['description'];
$extradate = $_POST['extraDate'];
$price = 15;
$query1 = "SELECT CustomerCheckedIn, ResCheckInDate, ResCheckOutDate FROM reservation WHERE ReservationID='$reservationID'";
$result1 = mysqli_query($conn, $query1);
if (mysqli_num_rows($result1) > 0) {
$row = mysqli_fetch_assoc($result1);
}
if ($row['CustomerCheckedIn'] == 1) {
if($row['ResCheckInDate'] < $extradate && $extradate < $row['ResCheckOutDate']){
$query2 = "INSERT INTO booked_extras (ReservationID, ExtraPrice, ExtraDate, ExtraDescription)
VALUES ('$reservationID', '$price', '$extradate', '$description')";
$result2 = mysqli_query($conn, $query2);
if ($result2) {
echo "Extra requested successfully.";
echo '<script type="text/javascript">';
echo 'alert("Extra Requested Successfully!");';
echo 'window.location.href = "customerRequestExtra.php";';
echo '</script>';
} else {
echo "Error requesting extra: " . mysqli_error($conn);
echo '<script type="text/javascript">';
echo 'alert("There was an Error! Try again!");';
echo 'window.location.href = "customerRequestExtra.php";';
echo '</script>';
}
} else {
echo "Error requesting extra: " . mysqli_error($conn);
echo '<script type="text/javascript">';
echo 'alert("Extras can only be requested for days between checkin and checkout dates");';
echo 'window.location.href = "customerRequestExtra.php";';
echo '</script>';
}
} else {
echo "Error requesting extra: " . mysqli_error($conn);
echo '<script type="text/javascript">';
echo 'alert("Customer not checked in yet.");';
echo 'window.location.href = "customerRequestExtra.php";';
echo '</script>';
}
}
// if the delete button is pressed
if (isset($_POST['delete'])) {
// Get the Room Number of the row to be deleted
$extraToDelete = key($_POST['delete']);
// sql to select
$sql_select = "SELECT * FROM booked_extras WHERE ExtraID='$extraToDelete'";
// get results of select sql
$result_select = mysqli_query($conn, $sql_select);
// check if result is not 0
if (mysqli_num_rows($result_select) == 0) {
echo '<script type="text/javascript">';
echo 'alert("Record does not exist!");';
echo 'window.location.href = "customerRequestExtra.php";';
echo '</script>';
} else { // if exists
// sql to delete
$sql_delete = "DELETE FROM booked_extras WHERE ExtraID='$extraToDelete'";
// if deletes, good
if (mysqli_query($conn, $sql_delete)) {
echo '<script type="text/javascript">';
echo 'alert("Record deleted successfully!");';
echo 'window.location.href = "customerRequestExtra.php";';
echo '</script>';
} else { // if not, bad
echo '<script type="text/javascript">';
echo 'alert("There was an Error! Try again!");';
echo 'window.location.href = "customerRequestExtra.php";';
echo '</script>';
}
}}
// include the header
include('footer.php');
?>