-
Notifications
You must be signed in to change notification settings - Fork 8
/
my_buses.php
164 lines (164 loc) · 5.48 KB
/
my_buses.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
<?php
session_start();
if (!isset($_SESSION['user']) || $_SESSION['user']['utype'] != "Owner")
header("Location: index.php");
$add = "";
if (isset($_POST['add'])) {
require_once 'inc/database.php';
$conn = initDB();
$sql = "insert into buses (bname, bus_no, from_loc, from_time, to_loc, to_time, fare, owner_id) values ('";
$sql .= $_POST['bname']."','".$_POST['bus_no']."','".$_POST['from_loc']."','".$_POST['from_time']."','";
$sql .= $_POST['to_loc']."','".$_POST['to_time']."','".$_POST['fare']."','".$_SESSION['user']['id']."')";
if ($conn->query($sql)) {
$add = "ok";
}
else {
$add = $sql . "<br/>" .$conn->error;
}
$conn->close();
}
include 'inc/basic_template.php';
t_header("Bus Ticket Booking");
t_login_nav();
t_owner_sidebar();
?>
<div class="modal" tabindex="-1" role="dialog" style="display: <?php echo ($_GET['act'] == 'add') ? 'block' : 'none';?>">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Add Bus</h5>
<a href="my_buses.php"><button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button></a>
</div>
<form method="post" action="my_buses.php">
<div class="modal-body">
<p>
<div class="form-group row">
<div class="col-sm-3">Bus Name</div>
<div class="col-sm-8">
<input type="text" name="bname" class="form-control"/>
</div>
</div>
<div class="form-group row">
<div class="col-sm-3">Bus No.</div>
<div class="col-sm-8">
<input type="text" name="bus_no" class="form-control"/>
</div>
</div>
<div class="form-group row">
<div class="col-sm-3">From</div>
<div class="col-sm-8">
<input type="text" name="from_loc" class="form-control" id="inputFrom"/>
</div>
</div>
<div class="form-group row">
<div class="col-sm-3">Diparture Time</div>
<div class="col-sm-8">
<input type="text" name="from_time" class="form-control"/>
</div>
</div>
<div class="form-group row">
<div class="col-sm-3">To</div>
<div class="col-sm-8">
<input type="text" name="to_loc" class="form-control" id="inputTo"/>
</div>
</div>
<link rel="stylesheet" href="css/easy-autocomplete.min.css"/>
<script src="js/jquery.easy-autocomplete.min.js"></script>
<script>
var opt = {
url: "inc/ajax.php?type=locations",
list: {
match: {
enabled: true
}
}
};
$("#inputFrom").easyAutocomplete(opt);
$("#inputTo").easyAutocomplete(opt);
</script>
<div class="form-group row">
<div class="col-sm-3">Arrival Time</div>
<div class="col-sm-8">
<input type="text" name="to_time" class="form-control"/>
</div>
</div>
<div class="form-group row">
<div class="col-sm-3">Fare</div>
<div class="col-sm-8">
<input type="text" name="fare" class="form-control"/>
</div>
</div>
</p>
</div>
<div class="modal-footer">
<input type="submit" class="btn btn-primary" value="Add" name="add"/>
<a href="my_buses.php"><button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button></a>
</div>
</form>
</div>
</div>
</div>
<div class="container">
<?php
if ($add!="") {
if ($add == "ok") {
echo '<div class="alert alert-success">Bus Added <strong>Success</strong>fully!</div>';
}
else {
echo '<div class="alert alert-danger"><strong>Error: </strong>'.$acc.'</div>';
}
}
?>
<div class="row mb-2">
<h4 class="col-md-3">My Buses</h4>
<div class="col-md-8 text-right ml-4">
<a href="my_buses.php?act=add"><button type="button" class="btn btn-sm btn-primary">+ Add Bus</button></a>
</div>
</div>
<table width="95%" class="table-con">
<tr class="head">
<th>ID</th>
<th>Bus Name</th>
<th>Bus No.</th>
<th>From</th>
<th>Diparture</th>
<th>To</th>
<th>Arrival</th>
<th>Fare</th>
<th>Status</th>
</tr>
<?php
require_once 'inc/database.php';
$conn = initDB();
$res = $conn->query("select * from buses where owner_id=" . $_SESSION['user']['id']);
if ($res->num_rows == 0) {
echo '
<tr class="row">
<td colspan="9">No Bus</td>
</tr>';
}
else {
while ($row = $res->fetch_assoc()) {
echo '
<tr class="content">
<td>' . $row["id"] . '</td>
<td>' . $row["bname"] . '</td>
<td>' . $row["bus_no"] . '</td>
<td>' . $row["from_loc"] . '</td>
<td>' . $row["from_time"] . '</td>
<td>' . $row["to_loc"] . '</td>
<td>' . $row["to_time"] . '</td>
<td>' . $row["fare"] . '</td>
<td>' . (($row["approved"]) ? '<i class="fa fa-check text-success"></i>' : '<i class="fa fa-times text-danger"></i>' ) . '</td>
</tr>';
}
}
$conn->close();
?>
</table>
</div>
<?php
t_footer();
?>