-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseatlayout1.php
307 lines (282 loc) · 11.9 KB
/
seatlayout1.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<body style="background-color:#e7eae5">
<style type="text/css">
.sty{
padding-left:300px;
width:30%;
height: 500px;
float:left;
}
.border{
border-left: 1px solid gray;
position: absolute;
margin-left:600px;
height: 450px;
}
.container {
display: inline;
position: relative;
padding-left: 32px;
margin-bottom: 12px;
cursor: pointer;
font-size: 22px;
}
.container input {
position: absolute;
opacity: 0;
cursor: pointer;
}
.checkmark-green {
position: absolute;
left: 0;
height: 30px;
width: 34px;
background-color: green;
text-align:center;
border: 1px solid green;
border-radius: 7px;
color:white;
font-family:sans-serif;
font-size:16px;
font-weight:bold;
padding-top:4px;
}
.container:hover input ~ .checkmark-green {
background-color: #ccc;
}
.container input:checked ~ .checkmark-green {
background-color: #2196F3;
}
.checkmark-green:after {
content: "";
position: absolute;
display: none;
}
.container input:checked ~ .checkmark-green:after {
display: block;
}
.checkmark-red {
position: absolute;
left: 0;
height: 30px;
width: 34px;
background-color: red;
text-align:center;
border: 1px solid red;
border-radius: 7px;
color:white;
font-family:sans-serif;
font-size:16px;
font-weight:bold;
padding-top:4px;
}
.button {
background-color: lightgray;
border: none;
color: black;
padding: 15px 15px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.button1:hover {
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);
}
</style>
<?php
define('DBSERVER', 'localhost');
define('DBUSERNAME', 'root');
define('DBPASSWORD', '');
define('DBNAME', 'bus');
$db=mysqli_connect(DBSERVER,DBUSERNAME,DBPASSWORD,DBNAME);
if($db===false){
die("Error: connection error.".mysql_connect_error());
}
$bus_no=$_GET['bus_no'];
$source=$_GET['source'];
$destination=$_GET['destination'];
$date=$_GET['date'];
$i0="create table t0(j_date varchar(10))";
mysqli_query($db, $i0);
$sqlinsert0 = $db->prepare("INSERT INTO t0 VALUES(?)");
$sqlinsert0->bind_param('s',$date);
$result0 = $sqlinsert0->execute();
$i1="create table t2(bus_no varchar(10),src_city char(15),dst_city char(15))";
mysqli_query($db, $i1);
$sqlinsert1 = $db->prepare("INSERT INTO t2 VALUES(?,?,?)");
$sqlinsert1->bind_param('sss', $bus_no,$source,$destination);
$result1 = $sqlinsert1->execute();
$i2="CREATE view src as SELECT t2.bus_no,t2.src_city,t2.dst_city,stops.stop_id 'src_id' FROM t2 INNER JOIN stops ON stops.bus_no =t2.bus_no and t2.src_city=stops.stop_name";
mysqli_query($db, $i2);
$i3="CREATE view dst as SELECT t2.bus_no,t2.src_city,t2.dst_city,stops.stop_id 'dst_id' FROM t2 INNER JOIN stops ON stops.bus_no =t2.bus_no and t2.dst_city=stops.stop_name";
mysqli_query($db, $i3);
$i4="ALTER TABLE t2 ADD COLUMN dst_id TINYINT UNSIGNED NOT NULL DEFAULT 0";
mysqli_query($db, $i4);
$i5="UPDATE t2 INNER JOIN dst ON t2.bus_no=dst.bus_no SET t2.dst_id = dst.dst_id";
mysqli_query($db, $i5);
$i6="ALTER TABLE t2 ADD COLUMN src_id TINYINT UNSIGNED NOT NULL DEFAULT 0";
mysqli_query($db, $i6);
$i7="UPDATE t2 INNER JOIN src ON t2.bus_no=src.bus_no SET t2.src_id = src.src_id";
mysqli_query($db, $i7);
$i8="CREATE VIEW booked AS SELECT seats.bus_no,seats.seat_no,customers.source_city,customers.dst_city FROM customers INNER JOIN seats INNER JOIN t0 ON customers.seat_no=seats.seat_no and customers.bus_no=seats.bus_no and customers.j_date=t0.j_date";
mysqli_query($db, $i8);
$i9="CREATE TABLE booke select * from booked";
mysqli_query($db, $i9);
$i10="ALTER TABLE booke ADD COLUMN src_id TINYINT UNSIGNED NOT NULL DEFAULT 0";
mysqli_query($db, $i10);
$i11="UPDATE booke INNER JOIN stops ON booke.bus_no=stops.bus_no and booke.source_city=stops.stop_name SET booke.src_id = stops.stop_id";
mysqli_query($db, $i11);
$i12="ALTER TABLE booke ADD COLUMN dst_id TINYINT UNSIGNED NOT NULL DEFAULT 0";
mysqli_query($db, $i12);
$i13="UPDATE booke INNER JOIN stops ON booke.bus_no=stops.bus_no and booke.dst_city=stops.stop_name SET booke.dst_id = stops.stop_id";
mysqli_query($db, $i13);
$i14="CREATE view book as SELECT booke.bus_no, booke.seat_no FROM booke INNER JOIN t2 ON booke.bus_no=t2.bus_no and (t2.src_id = booke.src_id or (t2.src_id > booke.src_id and t2.src_id<booke.dst_id))";
mysqli_query($db, $i14);
$i15="CREATE view book1 as select seats.* from seats left join book on seats.seat_no =book.seat_no and seats.bus_no=book.bus_no where book.seat_no IS NULL";
mysqli_query($db, $i15);
$i16="CREATE TABLE bookfinal as select seat_no,seat_type from book1 inner join t2 on t2.bus_no=book1.bus_no";
mysqli_query($db, $i16);
$drp0="DROP TABLE t0";
$drp1="DROP TABLE t2";
$drp2="DROP VIEW src";
$drp3="DROP VIEW dst";
$drp4="DROP VIEW book";
$drp5="DROP VIEW book1";
$drp6="DROP TABLE booke";
$drp7="DROP VIEW booked";
mysqli_query($db,$drp0);
mysqli_query($db,$drp1);
mysqli_query($db,$drp2);
mysqli_query($db,$drp3);
mysqli_query($db,$drp4);
mysqli_query($db,$drp5);
mysqli_query($db,$drp6);
mysqli_query($db,$drp7);
$query = $db->prepare("SELECT seat_no FROM bookfinal WHERE seat_no=?");
echo "<div class='sty' style='padding-top:100px;padding-bottom:10px'>";
echo "<h1 style='font-family:sans-serif; font-size:40px'>Select your seat</h1>";
echo '<form id="myform" class="myform " style="padding-left:30px" method="post" name="myform">';
for($x=1;$x<=36;$x++){
$query->bind_param('s',$x);
$query->execute();
$row = $query->fetch();
if($row){
$checkmark="checkmark-green";
$disable='';
}
else{
$checkmark="checkmark-red";
$disable='disabled="true"';
}
if($x==1){
echo '<div>';
echo '<label class="container">
<input type="checkbox" '.$disable.' name="myCheckboxes[]" value="'.$x.'">
<span class="'.$checkmark.'" >1</span>
</label>';
echo '<label class="container">
<input type="checkbox" >
<span class="'.$checkmark.'" style="background-color:white ;border: 2px solid white; border-radius: 7px;"></span>
</label>';
echo '<label class="container">
<input type="checkbox" >
<span class="'.$checkmark.'" style="background-color:white ;border: 2px solid white; border-radius: 7px;"></span>
</label>';
}
elseif($x==2 || $x==3){
echo '<label class="container">
<input type="checkbox" '.$disable.' name="myCheckboxes[]" value="'.$x.'">
<span class="'.$checkmark.'">'.$x.'</span>
</label>';
if($x==3){
echo '</div>';
}
}
else{
if($x%4==3){
echo '<label class="container">
<input type="checkbox" '.$disable.' name="myCheckboxes[]" value="'.$x.'">
<span class="'.$checkmark.'" >'.$x.'</span>
</label>';
if($x==35){
}
else{
echo '</div>';
}
}
else if($x%4==1 && $x!=33){
echo '<label class="container">
<input type="checkbox" '.$disable.' name="myCheckboxes[]" value="'.$x.'">
<span class="'.$checkmark.'">'.$x.'</span>
</label>';
echo '<label class="container">
<input type="checkbox" '.$disable.' name="myCheckboxes[]" value="'.$x.'">
<span class="'.$checkmark.'" style="background-color:white ;border: 2px solid white; border-radius: 7px;"></span>
</label>';
}
else{
if($x%4==0 && $x!=36){
echo '<div style="margin-top:20px">';
}
echo '<label class="container">
<input type="checkbox" '.$disable.' name="myCheckboxes[]" value="'.$x.'">
<span class="'.$checkmark.'">'.$x.'</span>
</label>';
}
}
}
echo "</div>";
echo '<div style="padding-top:40px;">
<button id="submit" type="button">Book Seats</button>
</div>';
echo '</form>';
echo "</div>";
$query->close();
include 'drop1.php';
mysqli_close($db);
?>
<div style='padding-top:180px;height:400px;'>
<div class="border">
<div style="padding-left:30px">
<h1 style="padding-bottom:px">Booking Details</h1>
<h2>Selected Seats (<span id="length"></span>): <span id="seats"></span></h3>
<?php
echo'<button id="checkout" class="button button1">Checkout</button>';
?>
<span class="checkmark-green" style=" margin-left:40px;margin-top: 90px;background-color:green ;border: 2px solid green; border-radius: 7px;"></span>
<span style="font-family:sans-serif;position:absolute;color:black;margin-top: 98px;margin-left:-40px">Available Seats</span>
<span class="checkmark-green" style=" margin-left:40px;margin-top: 150px;background-color:red ;border: 2px solid red; border-radius: 7px;"></span>
<span style="font-family:sans-serif;position:absolute;color:black;margin-top: 154px;margin-left:-40px">Already Booked</span>
<span class="checkmark-green" style=" margin-left:40px;margin-top: 210px;background-color:#2196F3; border: 2px solid #2196F3; border-radius: 7px;"></span>
<span style="font-family:sans-serif;position:absolute;color:black;margin-top: 214px;margin-left:-40px">Selected Seats</span>
</div>
</div>
</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
function submitForm() {
var form = document.myform;
var dataString = $(form).serialize();
var a=dataString.replace(/myCheckboxes%5B%5D=/g, "");
var arr = a.split("&");
var count=arr.length;
document.getElementById("length").innerHTML = count;
var str="";
for (var i=0;i<count;i++){
str=str+arr[i]+", ";
}
document.getElementById("seats").innerHTML = str.substring(0, str.length - 2);
sessionStorage.setItem("arr", JSON.stringify(arr));
}
$("#submit").click(submitForm);
function checkout(){
arr = JSON.parse(sessionStorage.getItem("arr"));
document.location="details.php?test=" + arr +"&bus_no="+"<?php echo $bus_no ?>"+"&source="+"<?php echo $source ?>"+"&destination="+"<?php echo $destination ?>"+"&date="+"<?php echo $date ?>";
}
$("#checkout").click(checkout);
});
</script>