-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcancel_reservation.php
141 lines (132 loc) · 4.12 KB
/
cancel_reservation.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
<?php
/**
* Version : 0.1
* Author: Battulga Myagmarjav
*/
/* get connected */
require 'connect.php';
session_start();
/* this query will give customer all his/her reservations */
$query = "SELECT *
FROM reservation
WHERE Is_cancelled = false AND Username = '" . $_SESSION['username'] . "';";
$result = mysql_query($query);
/* these queries will accomplish what cancel reservation needs */
$query_cancel = "SELECT *
FROM (SELECT *
FROM reservation_has_room
NATURAL JOIN reservation
WHERE reservation.Is_cancelled = false) as A
NATURAL JOIN room
WHERE A.ReservationID = ";
$result_cancel = "";
$query_delete = "DELETE FROM reservation_has_room
WHERE ReservationID = ";
$query_update = "UPDATE reservation
SET Is_cancelled = true
WHERE ReservationID = ";
$reservation = "";
/* instances for dates */
$start_date = $end_date = $days = "";
$cancel_date = date("m/d/Y");
$total_cost = 0;
$refund = 0;
/* after selection, table will appear */
if (isset($_POST['reservation'])) {
while ($row = mysql_fetch_assoc($result)) {
if ($row['ReservationID'] == $_POST['reservation']) {
$start_date = date("m/d/Y", strtotime($row['Start_date']));
$end_date = date("m/d/Y", strtotime($row['End_date']));
$_SESSION['cancel_ID'] = $_POST['reservation'];
$query_cancel .= $_POST['reservation'];
$result_cancel = mysql_query($query_cancel);
break;
}
}
}
/* cancel if user submits */
if (isset($_POST['cancel'])) {
$query_update .= $_SESSION['cancel_ID'] . ";";
mysql_query($query_update);
$query_delete .= $_SESSION['cancel_ID'] . ";";
mysql_query($query_delete);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Cancel Your Reservation</title>
</head>
<body style="text-align: center">
<h1>Cancel Reservation</h1>
<form method="post">
<select id="reservation" name="reservation" onchange="this.form.submit()">
<option value="none">none</option>
<?php
if (!empty($result)) {
while ($row = mysql_fetch_assoc($result)) {
$reservationID = $row['ReservationID'];
echo "<option value=\"" . $reservationID . "\">" . $reservationID . "</option>";
}
}
?>
</select>
<br>
Start Date <input type="text" value="<?php echo $start_date;?>" readonly>
End Date <input type="text" value="<?php echo $end_date;?>" readonly>
<table id="table" style="width: 50%; text-align: center; margin: 0px auto;">
<?php
/* makes your room */
$i = 0;
while (!empty($result_cancel) && $row = mysql_fetch_assoc($result_cancel)) {
/* only one time */
if ($i == 0) {
/* how much will be refunded*/
$total_cost = $row['Total_cost'];
$date1 = date_create($start_date);
$date2 = date_create($cancel_date);
$interval = date_diff($date1, $date2);
$days = $interval->format('%a');
if ($days > 1 && $days < 4) {
$refund = $total_cost * 0.8;
}
if ($days > 3) {
$refund = $total_cost;
}
/* table header */
echo "<tr>";
echo "<th>Room Number</th>";
echo "<th>Room Category</th>";
echo "<th>#persons allowed</th>";
echo "<th>Cost per day</th>";
echo "<th>Cost extra bed per day</th>";
echo "<th>Select Extra Bed</th>";
echo "</tr>";
$i++;
}
echo "<tr>";
echo "<td>" . $row['Room_number'] . "</td>";
echo "<td>" . $row['Category'] . "</td>";
echo "<td>" . $row['Capacity'] . "</td>";
echo "<td>" . $row['Cost'] . "</td>";
echo "<td>" . $row['Cost_extra_bed'] . "</td>";
echo "<td> <input type=\"checkbox\"";
if ($row['Include_extra_bed'] == 1) {
echo "checked disabled";
}
echo "> </td>";
echo "</tr>";
}
?>
</table>
<br>
Total Cost of Reservation <input type="text" value="<?php echo $total_cost;?>" readonly>
<br>
Date of Cancellation <input type="text" value="<?php echo $cancel_date;?>" readonly>
<br>
Amount to be refunded <input type="text" value="<?php echo $refund;?>" readonly>
<br>
<input type="submit" name="cancel" value="Cancel">
<form>
</body>
</html>