-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomerHub.php
191 lines (161 loc) · 6.4 KB
/
customerHub.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
<?php
// Display errors for debugging
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Start a session and connect to the hotel database
session_start();
// include the header file for the page
include('header.php');
?>
<!-- Add the CSS for the buttons -->
<style>
.btn-container {
display: flex;
justify-content: center;
align-items: center;
}
.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-edit {
background-color: #4CAF50;
}
.btn-request {
background-color: #FFA500;
}
.btn-logout {
background-color: #008CBA;
}
.btn-delete {
background-color: #f44336;
}
.btn-generate {
background-color: #6c757d;
}
.btn:hover {
opacity: 0.8;
}
</style>
<h1>Welcome to the Customer Hub,
<?php echo $_SESSION['customerusername']; ?>!
</h1>
<?php
// Get the customer's username from the session
$CustomerName = $_SESSION['customerusername'];
// Query the database to retrieve the customer's ID
$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 ID
$query2 = "SELECT reservation.*, room.RoomPrice, SUM(booked_extras.ExtraPrice) AS AdditionalCharges FROM reservation INNER JOIN room ON reservation.RoomNUM = room.RoomNUM LEFT JOIN booked_extras ON reservation.ReservationID = booked_extras.ReservationID WHERE reservation.CustomerID = '$custid' GROUP BY reservation.ReservationID";
$result2 = mysqli_query($conn, $query2);
// Start the form and table to display reservation data
echo "<form action='customerHub.php' method='POST'>";
echo "<table>";
echo "<tr><th>Reservation ID</th><th>Check-In date</th><th>Check-out date</th><th>Customer ID</th><th>Room Number</th><th>Total Cost</th><th>Additional Charges</th><th>Total Bill</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
$ReservationID = $row["ReservationID"];
$RoomCheckIn = $row["ResCheckInDate"];
$RoomCheckOut = $row["ResCheckOutDate"];
$CustomerId = $row["CustomerID"];
$RoomNum = $row["RoomNUM"];
$PricePerNight = $row["RoomPrice"];
// Calculate the number of nights and total cost
$date1 = new DateTime($RoomCheckIn);
$date2 = new DateTime($RoomCheckOut);
$interval = $date1->diff($date2);
$numNights = (int)$interval->format('%a');
$TotalCost = $numNights * $PricePerNight;
// Additional Charges
$AdditionalCharges = $row["AdditionalCharges"] ? $row["AdditionalCharges"] : 0;
// Calculate Total Bill
$TotalBill = $TotalCost + $AdditionalCharges;
// Display the table row with reservation data and a delete button
echo "<tr>";
echo "<td>" . $row["ReservationID"] . "</td>";
echo "<td>" . $row["ResCheckInDate"] . "</td>";
echo "<td>" . $row["ResCheckOutDate"] . "</td>";
echo "<td>" . $row["CustomerID"] . "</td>";
echo "<td>" . $row["RoomNUM"] . "</td>";
echo "<td>€" . $TotalCost . "</td>";
echo "<td>€" . $AdditionalCharges . "</td>";
echo "<td>€" . $TotalBill . "</td>";
echo "<td>";
echo "<input type='submit' value='Delete!' class='btn btn-delete' name='delete[$ReservationID]'>";
echo "<a href='generateBill.php?reservationID=$ReservationID' class='btn btn-generate' style='margin-left: 5px;'>Generate Bill</a>";
echo "</td>";
echo "</tr>";
}
} else {
echo "0 results";
}
// End table and form
echo "</table>";
echo "</form>";
}
// if the delete button is pressed
if (isset($_POST['delete'])) {
// Get the reservation ID of the row to be deleted
$reservationToDelete = key($_POST['delete']);
// SQL to select the reservation
$sql_select = "SELECT * FROM reservation WHERE ReservationID='$reservationToDelete'";
// Get the result of the select SQL
$result_select = mysqli_query($conn, $sql_select);
// Check if the result is not empty
if (mysqli_num_rows($result_select) == 0) {
echo '<script type="text/javascript">';
echo 'alert("Record does not exist!");';
echo 'window.location.href = "customerHUB.php";';
echo '</script>';
} else { // If the reservation exists
// SQL to delete the reservation
$sql_delete = "DELETE FROM reservation WHERE ReservationID='$reservationToDelete'";
// If the reservation is deleted, display a success message
if (mysqli_query($conn, $sql_delete)) {
echo '<script type="text/javascript">';
echo 'alert("Record deleted successfully!");';
echo 'window.location.href = "customerHUB.php";';
echo '</script>';
} else { // If the reservation is not deleted, display an error message
echo '<script type="text/javascript">';
echo 'alert("There was an Error! Try again!");';
echo 'window.location.href = "customerHUB.php";';
echo '</script>';
}
}}
?>
<!-- Buttons container -->
<div class='btn-container'>
<!-- Edit details button -->
<form action="customerEditDetails.php" method="post">
<input type="submit" value="Edit Your Details" class="btn btn-edit">
</form>
<!-- Request an extra button -->
<form action="customerRequestExtra.php" method="post">
<input type="submit" value="Request an Extra" class="btn btn-request">
</form>
<!-- Logout button -->
<form action="customerLogout.php" method="post">
<input type="submit" value="Logout" class="btn btn-logout">
</form>
</div>
<?php
// include the footer file for the page
include('footer.php');
?>