-
Notifications
You must be signed in to change notification settings - Fork 0
/
admindash.php
315 lines (243 loc) · 11.3 KB
/
admindash.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
<!doctype html>
<html lang="en">
<?php
include 'connect.php';
?>
<head>
<meta charset="UTF-8"/>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/admin1.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>AdminDash</title>
</head>
<body>
<div class="sidebar">
<div class="sidebar_logo">
<div class="logo_cont">
<img height="45px" src="https://img.icons8.com/external-flatart-icons-outline-flatarticons/64/FFFFFF/external-train-hotel-services-and-city-elements-flatart-icons-outline-flatarticons.png" alt="LOGO">
<h2>IRTBS</h2></div>
</div>
<div class="sidebar_menu">
<ul>
<li>
<a href=""><span class="img"></span>
<span class="disc">Dashboard</span>
</a>
</li>
<li>
<a href="admindash.php"><span class="img"></span>
<span class="disc">Trains</span>
</a>
</li>
<li>
<a href="addtrain.php"><span class="img"></span>
<span class="disc">Add Train</span>
</a>
</li>
<li>
<a href="userlist.php"><span class="img"></span>
<span class="disc">Users</span>
</a>
</li>
<li>
<a href="booked.php"><span class="img"></span>
<span class="disc">Reserved</span>
</a>
</li>
<li>
<a href="logout.php"><span class="img"></span>
<span class="disc">Logout</span>
</a>
</li>
</ul>
</div>
</div>
<div class="main_container">
<header>
<div class="menu_box">
<img height="30px" src="https://img.icons8.com/ios-filled/50/00000/menu--v1.png" alt="menu--v1"/>
<h2>Dashboard</h2>
</div>
<div class="user_wrapper">
<svg xmlns="http://www.w3.org/2000/svg" height="3rem" viewBox="0 0 512 512"><!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --><style>svg{fill:#007bff}</style><path d="M399 384.2C376.9 345.8 335.4 320 288 320H224c-47.4 0-88.9 25.8-111 64.2c35.2 39.2 86.2 63.8 143 63.8s107.8-24.7 143-63.8zM0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256zm256 16a72 72 0 1 0 0-144 72 72 0 1 0 0 144z"/></svg>
<div>
<?php
if (isset($_SESSION['user_id'])) {
$userId = $_SESSION['user_id'];
// Assuming $conn is your database connection
$stmt = $conn->prepare("SELECT username FROM user WHERE id = ?");
$stmt->bind_param("i", $userId); // Assuming user ID is an integer
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$username = $row['username'];
?>
<h3><?php echo $username; ?></h3>
<?php
} else {
echo "User not found in the database.";
}
$stmt->close();
} else {
echo "User not logged in.";
}
?>
<small>Admin</small>
</div>
</div>
</header>
<main>
<div class="cards">
<div class="card">
<div>
<?php
$sql = 'SELECT COUNT(status) AS count FROM bookings where status="confirmed"';
$result = $conn->query($sql);
$count = ($result && $row = $result->fetch_assoc()) ? $row['count'] : 0;
?>
<h1><?php echo $count; ?></h1>
<span>Passengers</span>
</div>
<div class="img_card">
<svg class="ico_card" xmlns="http://www.w3.org/2000/svg" height="3rem" viewBox="0 0 576 512"><!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --><path d="M432 96a48 48 0 1 0 0-96 48 48 0 1 0 0 96zM347.7 200.5c1-.4 1.9-.8 2.9-1.2l-16.9 63.5c-5.6 21.1-.1 43.6 14.7 59.7l70.7 77.1 22 88.1c4.3 17.1 21.7 27.6 38.8 23.3s27.6-21.7 23.3-38.8l-23-92.1c-1.9-7.8-5.8-14.9-11.2-20.8l-49.5-54 19.3-65.5 9.6 23c4.4 10.6 12.5 19.3 22.8 24.5l26.7 13.3c15.8 7.9 35 1.5 42.9-14.3s1.5-35-14.3-42.9L505 232.7l-15.3-36.8C472.5 154.8 432.3 128 387.7 128c-22.8 0-45.3 4.8-66.1 14l-8 3.5c-32.9 14.6-58.1 42.4-69.4 76.5l-2.6 7.8c-5.6 16.8 3.5 34.9 20.2 40.5s34.9-3.5 40.5-20.2l2.6-7.8c5.7-17.1 18.3-30.9 34.7-38.2l8-3.5zm-30 135.1l-25 62.4-59.4 59.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L340.3 441c4.6-4.6 8.2-10.1 10.6-16.1l14.5-36.2-40.7-44.4c-2.5-2.7-4.8-5.6-7-8.6zM256 274.1c-7.7-4.4-17.4-1.8-21.9 5.9l-32 55.4L147.7 304c-15.3-8.8-34.9-3.6-43.7 11.7L40 426.6c-8.8 15.3-3.6 34.9 11.7 43.7l55.4 32c15.3 8.8 34.9 3.6 43.7-11.7l64-110.9c1.5-2.6 2.6-5.2 3.3-8L261.9 296c4.4-7.7 1.8-17.4-5.9-21.9z"/></svg>
</div>
</div>
<div class="card">
<div>
<?php
$sql = 'SELECT COUNT(trainid) AS count FROM trainsch';
$result = $conn->query($sql);
$count = ($result && $row = $result->fetch_assoc()) ? $row['count'] : 0;
?>
<h1><?php echo $count; ?></h1>
<span>Trains</span>
</div>
<div class="img_card">
<svg class="ico_card" xmlns="http://www.w3.org/2000/svg" height="3rem" viewBox="0 0 448 512"><!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --><path d="M96 0C43 0 0 43 0 96V352c0 48 35.2 87.7 81.1 94.9l-46 46C28.1 499.9 33.1 512 43 512H82.7c8.5 0 16.6-3.4 22.6-9.4L160 448H288l54.6 54.6c6 6 14.1 9.4 22.6 9.4H405c10 0 15-12.1 7.9-19.1l-46-46c46-7.1 81.1-46.9 81.1-94.9V96c0-53-43-96-96-96H96zM64 96c0-17.7 14.3-32 32-32H352c17.7 0 32 14.3 32 32v96c0 17.7-14.3 32-32 32H96c-17.7 0-32-14.3-32-32V96zM224 288a48 48 0 1 1 0 96 48 48 0 1 1 0-96z"/></svg>
</div>
</div>
<div class="card">
<div>
<?php
$sql = "SELECT COUNT(*) AS count FROM bookings WHERE status = 'cancelled'";
$result = $conn->query($sql);
$count = ($result && $row = $result->fetch_assoc()) ? $row['count'] : 0;
?>
<h1><?php echo $count; ?></h1>
<span>Cancelled Tickets</span>
</div>
<div class="img_card">
<img class="ico_card" src="img/cancel.png" alt="" height="37">
</div>
</div>
<div class="card">
<div>
<?php
$sql = 'SELECT SUM(price) AS total FROM bookings where status ="confirmed"';
$result = $conn->query($sql);
if ($result && $row = $result->fetch_assoc()) {
$total = $row['total'];
} else {
$total = 0;
}
?>
<h1><?php echo $total; ?> $</h1>
<span>Earings</span>
</div>
<div class="img_card">
<img class="ico_card" src="img/money.png" alt="" height="37">
</div>
</div>
<div class="card">
<div>
<?php
$sql = 'SELECT COUNT(username) AS count FROM user';
$result = $conn->query($sql);
$count = ($result && $row = $result->fetch_assoc()) ? $row['count'] : 0;
?>
<h1><?php echo $count; ?> </h1>
<span>Users</span>
</div>
<div class="img_card">
<img class="ico_card" src="img/users.png" alt="" height="37">
</div>
</div>
<div class="card">
<div>
<?php
$sql = 'SELECT sum(AvailableSeats) AS count FROM trainsch';
$result = $conn->query($sql);
$count = ($result && $row = $result->fetch_assoc()) ? $row['count'] : 0;
?>
<h1><?php echo $count; ?></h1>
<span>Available Tickets</span>
</div>
<div class="img_card">
<img class="ico_card" src="img/tickets.png" alt="" height="37">
</div>
</div>
</div>
<div class="grid1">
<div class="Trains">
<div class="box">
<div class="box_header">
<h2>TRAINS</h2>
</div>
<div class="box_body">
<table width="100%">
<thead>
<tr>
<td>Train ID</td>
<td>Train name</td>
<td>Source</td>
<td>Destination</td></td>
<td>depart Time</td>
<td>Date</td>
<td>Action</td>
</tr>
</thead>
<tbody>
<?php
$sql="select * from trainsch";
$result=$conn->query($sql);
if($result->num_rows > 0)
{
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row["trainid"] . "</td>";
echo "<td>" . $row["trainname"] . "</td>";
echo "<td>" . $row["depstation"] . "</td>";
echo "<td>" . $row["arrstation"] . "</td>";
echo "<td>" . $row["deptime"] . "</td>";
echo "<td>" . $row["date"] . "</td>";
echo "<td>";
echo "<form method='post' action='deltrain.php' onsubmit='return confirmDelete()'>"; // Adjust the action attribute based on your backend logic
echo "<input type='hidden' name='trainid' value='" . $row["trainid"] . "'>";
echo "<button type='submit'>DELETE</button>";
echo "</form>";
echo "</td>";
echo "</tr>";
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
<!-- -----------Trains table end ----- ---------->
<!------------------------------------------>
<!-- -------users box end ------------- -->
</main>
</div>
<script type="module" src="main.js"></script>
<script>
function confirmDelete() {
return confirm("Are you sure you want to delete this record?");
}
</script>
</body>
</html>