-
Notifications
You must be signed in to change notification settings - Fork 8
/
buses.php
87 lines (83 loc) · 2.56 KB
/
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
<?php
session_start();
if (!isset($_SESSION['user']) || $_SESSION['user']['utype'] != "Admin")
header("Location: index.php");
include 'inc/basic_template.php';
t_header("Bus Ticket Booking — User Manager");
t_login_nav();
t_admin_sidebar();
if (isset($_GET['toggle'])) {
require_once 'inc/database.php';
$conn = initDB();
if ($conn->query("update buses set approved=".$_GET['toggle']." where id=".$_GET['id']))
echo '<script>alert("OK");</script>';
else
echo '<script>alert("Fail");</script>';
$conn->close();
}
?>
<div class="row mb-2">
<h4 class="col-md-3">Buses</h4>
<div class="col-md-8 text-right ml-4">
<form method="post" action="">
<input type="text" name="bus" class="form-control-sm" value="<?php echo (isset($_POST['bus'])) ? $_POST['bus'] : ""; ?>">
<button type="submit" class="btn btn-sm btn-primary"><i class="fa fa-search"></i> Search</button>
</form>
</div>
</div>
<table width="95%" class="table-con">
<tr class="head">
<th>ID</th>
<th>Bus Name</th>
<th>Bus No.</th>
<th>Owner</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();
$sql = "select *,users.uname as owner,buses.id as bid from buses, users where owner_id=users.id";
if (isset($_POST['bus'])) {
$sql .= " and (bname like '%".$_POST['bus']."%' or bus_no like '%".$_POST['bus']."%')";
}
$sql .= " order by approved";
$res = $conn->query($sql);
if ($res->num_rows == 0) {
echo '
<tr class="row">
<td colspan="9" class="text-center">No Bus</td>
</tr>';
}
else {
while ($row = $res->fetch_assoc()) {
echo '
<tr class="content">
<td>' . $row["bid"] . '</td>
<td>' . $row["bname"] . '</td>
<td>' . $row["bus_no"] . '</td>
<td>' . $row["owner"] . '</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><a href="buses.php?id=' . $row["bid"] . '&toggle=';
if ($row["approved"])
echo '0" title="Click to Unapprove"><i class="fa fa-check text-success">';
else
echo '1" title="Click to Approve"><i class="fa fa-times text-danger">';
echo '</i></a></td></tr>';
}
}
$conn->close();
?>
</table>
</div>
<?php
t_footer();
?>