-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP_edit.php
233 lines (198 loc) · 12.5 KB
/
P_edit.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
<?php include_once 'P_header.php'; ?>
<?php
include 'dbh.inc.php';
if (isset($_GET['edit'])) {
$Hotel_Res_ID = $_GET['edit'];
if (isset($_POST['update'])) {
$Full_Name = $_POST["FullName"];
$Email = $_POST["Email"];
$Booking_For = $_POST["BookingFor"];
$Hotel_Name = $_POST["HotelName"];
$Package_Name = $_POST["HotelPackage"];
$Check_In_Date = $_POST["CheckIntime"];
$Check_Out_Date = $_POST["CheckOuttime"];
$Room_Type = $_POST["countR"];
$No_Of_Adult = $_POST["countA"];
$No_Of_Children = $_POST["countC"];
$Special_Request = $_POST["SpecialRequest"];
$query = "SELECT `Package_ID` FROM `hotel_package` WHERE `Package_Name` = '$Package_Name'";
$result = $conn->query($query);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$Package_ID = $row['Package_ID'];
$query = "SELECT `Package_Price` FROM `hotel_package` WHERE `Package_ID`='$Package_ID'";
$result = $conn->query($query);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$packagePrice2 = $row['Package_Price'];
$checkInDateTime = new DateTime($Check_In_Date);
$checkOutDateTime = new DateTime($Check_Out_Date);
$interval = $checkInDateTime->diff($checkOutDateTime);
$numNights = $interval->format('%a');
$totalPrice = $packagePrice2 * ($No_Of_Adult + $No_Of_Children) * $numNights;
$update = "UPDATE hotel_reservation SET Package_ID = '$Package_ID', Full_Name = '$Full_Name', Email = '$Email', Booking_For = '$Booking_For', Check_In_Date = '$Check_In_Date', Check_Out_Date = '$Check_Out_Date', Room_Type = '$Room_Type', No_Of_Adult = '$No_Of_Adult', No_Of_Children = '$No_Of_Children', Total_Price = '$totalPrice', Special_Request = '$Special_Request'
WHERE Hotel_Res_ID = '$Hotel_Res_ID'";
$upload = mysqli_query($conn,$update);
if ($upload) {
// Redirect to the view page
header("Location: P_view.php");
exit();
} else {
echo "Error updating reservation: " . $conn->error;
}
} else {
echo "Error: Package not found";
}
}
}
$select = mysqli_query($conn, "SELECT * FROM hotel_reservation WHERE Hotel_Res_ID = '$Hotel_Res_ID'");
$row = mysqli_fetch_assoc($select);
if ($row){
?>
<script src="P_Script.js"></script>
<div class="background">
<div class="transbox">
<!--update form-->
<div class="form">
<form method="POST" action="" name="myForm" id="myForm" onsubmit="return validatemyForm()">
<fieldset>
<legend><span class="number">1</span>Reservation Details</legend>
<input type="text" id="FullName" name="FullName" value="<?php echo $row["Full_Name"]; ?>" placeholder="Full Name *" required autocomplete="off">
<input type="email" id="Email" name="Email" value="<?php echo $row["Email"]; ?>" placeholder="Email *" required autocomplete="off">
<label for="guest">Who are you booking for?</label>
<select id="guest" name="BookingFor" required>
<optgroup label="Booking For">
<option value="main_Guest" <?php if ($row["Booking_For"] == "main_Guest") echo "selected"; ?>>I am the main Guest</option>
<option value="Guest" <?php if ($row["Booking_For"] == "Guest") echo "selected"; ?>>Booking is for someone else</option>
</optgroup>
</select>
<label for="hotel">Select your Hotel :</label>
<select id="hotel" name="HotelName" required>
<optgroup label="Hotel Name">
<option value="Wild Coast Tented Lodge" <?php if ($row["Package_ID"] == "C001") echo "selected"; ?>>Wild Coast Tented Lodge</option>
<option value="Leopard Nest" <?php if ($row["Package_ID"] == "A001") echo "selected"; ?>>Leopard Nest</option>
<option value="Jetwing Yala" <?php if ($row["Package_ID"] == "L002") echo "selected"; ?>>Jetwing Yala</option>
<option value="Cinnamon Yala" <?php if ($row["Package_ID"] == "L001" OR $row["Package_ID"] == "F001") echo "selected"; ?>>Cinnamon Yala</option>
<option value="Yala Eco Tree House" <?php if ($row["Package_ID"] == "A002") echo "selected"; ?>>Yala Eco Tree House</option>
</optgroup>
</select>
<label for="package">Select your Hotel Package:</label>
<select id="package" name="HotelPackage" required>
<optgroup label="Hotel Package">
<option value="Adventure Leopard Package" <?php if ($row["Package_ID"] == "A001") echo "selected"; ?>>Adventure Leopard Package</option>
<option value="Adventure Eco Budget Tree Package" <?php if ($row["Package_ID"] == "A002") echo "selected"; ?>>Adventure Eco Budget Tree Package</option>
<option value="Wild Lodge Package" <?php if ($row["Package_ID"] == "C001") echo "selected"; ?>>Wild Lodge Package</option>
<option value="Sweet Family Package" <?php if ($row["Package_ID"] == "F001") echo "selected"; ?>>Sweet Family Package</option>
<option value="Cinnamon Luxury Package" <?php if ($row["Package_ID"] == "L001") echo "selected"; ?>>Cinnamon Luxury Package</option>
<option value="Jetwing Luxury Package" <?php if ($row["Package_ID"] == "L002") echo "selected"; ?>>Jetwing Luxury Package</option>
</optgroup>
</select>
<label for="count">Room Type: </label>
<input type="number" id="countR" name="countR" min="1" max="3" value="<?php echo $row["Room_Type"]; ?>" placeholder="Bed Count *" required>
<label for="count">No Of Adults: </label>
<input type="number" id="countA" name="countA" min="1" value="<?php echo $row["No_Of_Adult"]; ?>" placeholder="No Of Adults *" required>
<label for="count">No Of Children: </label>
<input type="number" id="countC" name="countC" min="0" value="<?php echo $row["No_Of_Children"]; ?>" placeholder="No Of Children *" required>
<label for="CheckInDate">Check In Date:</label>
<input type="datetime-local" id="CheckIntime" name="CheckIntime" value="<?php echo $row["Check_In_Date"]; ?>" required>
<label for="CheckOutDate">Check Out Date:</label>
<input type="datetime-local" id="CheckOuttime" name="CheckOuttime" value="<?php echo $row["Check_Out_Date"]; ?>" required>
</fieldset>
<fieldset>
<legend><span class="number">2</span> Special Request</legend>
<textarea name="SpecialRequest" id="SpecialRequest" placeholder="Write your special request here. (optional)" autocomplete="off"><?php echo $row["Special_Request"]; ?></textarea>
</fieldset>
<input type="submit" id="resbtn" name="update" value="Update">
</form>
<script>
function validatemyForm() {
// Get the values of the name and email fields
let FullName = document.forms["myForm"]["FullName"].value;
let Email = document.forms["myForm"]["Email"].value;
let BookingFor = document.forms["myForm"]["BookingFor"].value;
let countR = document.forms["myForm"]["countR"].value;
let countA = document.forms["myForm"]["countA"].value;
let countC = document.forms["myForm"]["countC"].value;
let CheckIntime = document.forms["myForm"]["CheckIntime"].value;
let CheckOuttime = document.forms["myForm"]["CheckOuttime"].value;
// Perform validation
if (FullName == "") {
alert("Full Name must be filled out");
return false;
}
if (Email == "") {
alert("Email must be filled out");
return false;
}
if (BookingFor == "") {
alert("Booking For must be filled out");
return false;
}
if (countR == "") {
alert("Room Type must be filled out");
return false;
}
if (countA == "") {
alert("No Of Adults must be filled out");
return false;
}
if (countC == "") {
alert("No Of Children must be filled out");
return false;
}
if (CheckIntime == "") {
alert("Check In time must be filled out");
return false;
}
if (CheckOuttime == "") {
alert("Check Out time must be filled out");
return false;
}
if (!validateRoomCount()){
return false;
}
if (!validateDates()){
return false;
}
alert("Successfully Updated!");
return true;
}
//Room count validation
function validateRoomCount() {
var roomCount = document.getElementById("countR").value;
var adultCount = document.getElementById("countA").value;
if (roomCount < adultCount) {
alert("The Bed count cannot be less than the number of adults.");
return false;
} else {
return true;
}
}
//Date Pick
function validateDates() {
var checkInDate = new Date(document.getElementById("CheckIntime").value);
var checkOutDate = new Date(document.getElementById("CheckOuttime").value);
if (checkOutDate < checkInDate) {
alert("Check-out date cannot be earlier than check-in date");
return false;
} else {
return true;
}
}
//disable previous dates
var today = new Date().toISOString().slice(0, 16);
document.getElementsByName("CheckIntime")[0].min = today;
document.getElementsByName("CheckOuttime")[0].min = today;
</script>
</div>
</div>
</div>
<?php
} else {
echo "no reservation found";
}
}else {
echo "Invalid reservation ID.";
}
?>
<?php include_once 'P_footer.php'; ?>