-
Notifications
You must be signed in to change notification settings - Fork 1
/
bus_info.php
334 lines (253 loc) · 15.4 KB
/
bus_info.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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<?php include "includes/db.php"; ?>
<?php include "includes/header.php"; ?>
<!-- Navigation -->
<?php include "includes/navigation.php"; ?>
<!-- Page Content -->
<div class="container">
<div class="row">
<!-- Blog Entries Column -->
<div class="col-md-8">
<?php
if(isset($_GET['bus_id'])) {
$selected_bus = $_GET['bus_id'];
}
$query = "SELECT * FROM posts WHERE post_id = $selected_bus ";
$select_all_bus_query = mysqli_query($connection,$query);
while($row = mysqli_fetch_assoc($select_all_bus_query)) {
$bus_title = $row['post_title'];
$bus_author = $row['post_author'];
$bus_date = $row['post_date'];
$bus_image = $row['post_image'];
$bus_content = $row['post_content'];
$bus_id = $row['post_id'];
$bus_via = $row['post_via'];
$times = $row['post_via_time'];
$bus_cat = $row['post_category_id'];
$available_seats = $row['available_seats'];
$max_seats = $row['max_seats'];
$bus_stations = explode(" ",$bus_via);
$bus_times = explode(" ",$times);
?>
<!-- First Blog Post -->
<h2>
<a href="bus_info.php?bus_id=<?php echo $post_id; ?>"><?php echo $bus_title; ?></a>
</h2>
<p class="lead">
by <a href="index.php"><?php echo $bus_author; ?></a>
</p>
<p><span class="glyphicon glyphicon-time"></span> Posted on <?php echo $bus_date; ?></p>
<hr>
<img class="img-responsive" src="images/<?php echo $bus_image; ?>" alt="">
<hr>
<p><?php echo $bus_content ?></p>
<div class="jumbotron jumb">
<h2><b>Seat Matrix:</b></h2>
<h5>Max: <?php echo $max_seats ?></h5>
<h5>Available: <?php echo $available_seats ?></h5>
<h2><b>Stations Covered:</b></h2>
<table class="table table-striped" style="width: 100%; margin-top:-20px;">
<thead>
<th><u>Station</u></th>
<th><u>Time</u> </th>
</thead>
<tbody>
<?php
for ($i=0; $i < sizeof($bus_stations); $i++) { ?>
<tr>
<td><?php echo $bus_stations[$i]; ?></td>
<td><?php echo $bus_times[$i]; ?></td>
</tr> <?php
}
?>
<br>
</tbody>
</table>
</div>
<?php
if (isset($_SESSION['s_id'])) {
# code...
?>
<div class="jumbotron">
<div class="container-fluid">
<h2>Enter Details:</h2>
<form action="" method="post" class="form-horizontal">
<select name="passenger_count" style="margin-bottom: 15px;margin-top: 15px;">
<option value="0">Ticket Count</option>
<?php
for ($i=1; $i <= $available_seats; $i++) { ?>
<option value="<?php echo $i ?>"><?php echo $i ?></option> <?php
}
?>
</select>
<button class="btn-xs btn-primary" style="margin-left: 5px;">GO</button>
</form>
<form action="bus_info.php?bus_id=<?php echo $selected_bus ?>&count=<?php echo $_POST['passenger_count'] ?>" method="post" class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-2" for="email">Source:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="email" placeholder="Source" name="source">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Destination:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="email" placeholder="Destination" name="destination">
</div>
</div>
<?php
if (isset($_POST['passenger_count'])) {
$count = $_POST['passenger_count'];
//echo "<h1>$count</h1>";
for ($i=0; $i < $count; $i++) {
?>
<h6><?php echo "Passenger "; echo $i+1;?></h6>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Name:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="email" placeholder="Name" name="name<?php echo "$i" ?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Age:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="email" placeholder="Age" name="age<?php echo "$i" ?>">
</div>
</div>
<?php
}
}
?>
<!-- <button class="btn btn-primary" name="book" style="margin-left: 40%; margin-top: 15px;">Book Tickets</button> -->
<a href="receipt.php" class="btn btn-primary" name="book" style="margin-left: 40%; margin-top: 15px;"> Book Tickets</a>
</form>
<?php
if (isset($_POST['book'])) {
//echo "<h1>hello</h1>";
if (isset($_GET['count'])) {
$count = $_GET['count'];
}
$source = $_POST['source'];
$destination = $_POST['destination'];
$cost = 0;
for ($i=0; $i < sizeof($bus_stations); $i++) {
if($bus_stations[$i]==$source) {
//echo $bus_stations[$i];
for ($j=$i; $j < sizeof($bus_stations); $j++) {
//echo $bus_stations[$j];
$k=$j+1;
$begin = $bus_stations[$j];
$inter = $bus_stations[$k];
$query_new = "SELECT * FROM cost WHERE start='$begin' AND stopage='$inter' AND category=$bus_cat ";
$get_cost = mysqli_query($connection,$query_new);
while($row = mysqli_fetch_assoc($get_cost)) {
$station_cost = $row['cost'];
echo $station_cost;
$cost += $station_cost;
}
if($bus_stations[$k]==$destination)
break;
}
break;
}
}
//echo $cost;
// $query = "INSERT INTO orders(bus_id,user_id,user_name,user_age,source,destination,date) VALUES($selected_bus, $_SESSION['s_username'],$source,$destination,now())";
$arr = array();
$arr1 = array();
for ($i=0; $i < $count; $i++) {
//echo "<h1>hello</h1>";
$name_query = 'name'.$i ;
$age_query = 'age'.$i ;
//echo $what;
array_push($arr,$_POST[$name_query]);
array_push($arr1,$_POST[$age_query]);
}
for ($i=0; $i < $count; $i++) {
$curr_name = $arr[$i];
$curr_age = $arr1[$i];
$user_id = $_SESSION['s_id'];
$query = "INSERT INTO orders(bus_id, user_id, user_name, user_age, source, destination,date,cost) VALUES($selected_bus, $user_id , '$curr_name', '$curr_age', '$source', '$destination', now(),$cost)";
$query_seat_update = "UPDATE posts SET available_seats = $available_seats + $count WHERE post_id = $bus_id";
//echo $arr[$i];
//echo $_SESSION['s_id'];
$update_seats_available = mysqli_query($connection,$query_seat_update);
$booking_query = mysqli_query($connection,$query);
if (!$booking_query) {
die("Query Failed" . mysqli_error($connection));
}
}
//header("Location: profile.php");
}
?>
</div>
</div>
<?php } ?>
<hr>
<?php } ?>
<!-- Blog Comments -->
<?php
if (isset($_POST['submit_query'])) {
$user_name = ucfirst($_SESSION['s_username']) ;
if($user_name == "") {
$user_name = "(unknown)";
}
$user_email = $_POST['user_email'];
$user_query = $_POST['user_query'];
$query = "INSERT INTO query(query_bus_id, query_user, query_email, query_date, query_content, query_replied) VALUES ('$selected_bus', '$user_name', '$user_email', now(), '$user_query', 'no')";
$query_insert = mysqli_query($connection, $query);
if(!$query_insert) {
die("Query Failed" . mysqli_error($connection));
}
$query = "UPDATE posts SET post_query_count = post_query_count + 1 WHERE post_id = $bus_id";
$increase_query_count = mysqli_query($connection,$query);
}
?>
<!-- Comments Form -->
<div class="well">
<h4>Leave a Comment:</h4>
<form action="bus_info.php?bus_id=<?php echo $selected_bus ?>" method="post" role="form">
<!-- <div class="form-group">
<label for="name">Name</label>
<input class="form-control" name="user_name"></textarea>
</div> -->
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" name="user_email"></textarea>
</div>
<div class="form-group">
<label> Query</label>
<textarea class="form-control" rows="3" name="user_query"></textarea>
</div>
<button type="submit" class="btn btn-primary" name="submit_query">Submit</button>
</form>
</div>
<hr>
<!-- Posted Comments -->
<?php
$query = "SELECT * FROM query WHERE query_bus_id = $bus_id";
$get_query = mysqli_query($connection,$query);
while ($row = mysqli_fetch_assoc($get_query)) {
$query_user = $row['query_user'];
$query_content = $row['query_content'];
$query_date = $row['query_date'];
?>
<!-- Comment -->
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" src="http://placehold.it/64x64" alt="">
</a>
<div class="media-body">
<h4 class="media-heading"> <?php echo $query_user; ?>
<small><?php echo $query_date; ?></small>
</h4>
<?php echo $query_content; ?>
</div>
</div>
<?php } ?>
</div>
<!-- Blog Sidebar Widgets Column -->
<?php include "includes/sidebar.php"; ?>
</div>
<!-- /.row -->
<hr>
<?php include "includes/footer.php"; ?>