-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin_edit_route.php
199 lines (168 loc) · 6.91 KB
/
admin_edit_route.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
<?php
ob_start();
session_start();
if(isset($_SESSION['admin_session_token']) && !empty($_SESSION['admin_session_token']))
{
include("connect.php");
if(!(isset($_REQUEST['bid']) && !empty($_REQUEST['bid'])))
{
header("Location: admin_view_routes.php");
}
$bid = $_REQUEST['bid'];
$routeInfo = mysqli_query($con, "select * from routes where id=$bid");
if(mysqli_num_rows($routeInfo) === 1)
{
$rinfo = mysqli_fetch_assoc($routeInfo);
}
else{
header("Location: admin_view_routes.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Edit Route</title>
<link rel="stylesheet" type="text/css" href="admin_mangage_routes.css" />
<link rel="stylesheet" type="text/css" href="usermenu.css" />
<!-- Link to your external CSS file -->
</head>
<body >
<?php include("adminmenu.php"); ?>
<div class="form-container">
<div class="add-route">
<h1>Edit Route</h1>
<?php
if(isset($_COOKIE['success']))
{
echo "<p class='success'>".$_COOKIE['success']."</p>";
}
if(isset($_COOKIE['error']))
{
echo "<p class='error'>".$_COOKIE['error']."</p>";
}
function filterData($data)
{
return addslashes(strip_tags(trim($data)));
}
if(isset($_POST['submit']))
{
$editSource = isset($_POST['editSource']) ? filterData($_POST['editSource']) : '';
$editDestination = isset($_POST['editDestination']) ? filterData($_POST['editDestination']) : '';
$status = isset($_POST['status']) ? filterData($_POST['status']) : '';
$endTime = isset($_POST['endTime']) ? filterData($_POST['endTime']) : '';
$startTime = isset($_POST['startTime']) ? filterData($_POST['startTime']) : '';
$totalSeats = isset($_POST['totalSeats']) ? filterData($_POST['totalSeats']) : '';
$seatCharge = isset($_POST['seatCharge']) ? filterData($_POST['seatCharge']) : '';
// validations
$errors = [];
if($editSource === "")
{
$errors['editSource'] = "source is required";
}
if($editDestination === "")
{
$errors['editDestination'] = "destination is required";
}
if($status === "")
{
$errors['status'] = "Status is required";
}
if($startTime === "")
{
$errors['startTime'] = "Start time is required";
}
if($endTime === "")
{
$errors['endTime'] = "End time is required";
}
if($seatCharge === "")
{
$errors['seatCharge'] = "Seat Charge is required";
}
else
{
if(!filter_var($seatCharge, FILTER_VALIDATE_INT))
{
$errors['seatCharge'] = "Seat Charge does not allowed chars";
}
}
if($totalSeats === "")
{
$errors['totalSeats'] = "Total seats are required";
}
else
{
if(!filter_var($totalSeats, FILTER_VALIDATE_INT))
{
$errors['totalSeats'] = "Total seats does not allowed chars";
}
}
if(count($errors) == 0)
{
mysqli_query($con, "UPDATE routes SET source='$editSource', destination='$editDestination', status='$status', start_time='$startTime', end_time='$endTime', total_seats='$totalSeats', charge='$seatCharge' where id=$bid");
if(mysqli_affected_rows($con) === 1)
{
setcookie("success", "Bus route updated successfully", time() + 3);
header("location: admin_edit_route.php?bid=".$bid);
}
else{
setcookie("error", "Sorry! Unable to update bus routes", time() + 3);
header("location: admin_edit_route.php?bid=".$bid);
}
}
}
?>
<?php
if(isset($errors['checkbus']))
{
echo "<p class='error'>".$errors['checkbus']."</p>";
}
?>
<form method="POST" action="">
<label for="busNumber">Editing Bus Number : <?php echo $rinfo['busnum']; ?></label>
<hr />
<span class="text-danger" id=""><?php if(isset($errors['busNumber'])) echo $errors['busNumber']; ?></span>
<label for="editSource">Edit Source:</label>
<input type="text" value="<?php echo $rinfo['source']; ?>" id="editSource" name="editSource" />
<span class="text-danger" id=""><?php if(isset($errors['editSource'])) echo $errors['editSource']; ?></span>
<label for="editDestination">Edit Destination:</label>
<input value="<?php echo $rinfo['destination']; ?>" type="text" id="editDestination" name="editDestination" />
<span class="text-danger" id=""><?php if(isset($errors['editDestination'])) echo $errors['editDestination']; ?></span>
<label for="startTime">Start Time:</label>
<input value="<?php echo $rinfo['start_time']; ?>" type="text" id="startTime" name="startTime" />
<span class="text-danger" id=""><?php if(isset($errors['startTime'])) echo $errors['startTime']; ?></span>
<label for="endTime">End Time:</label>
<input value="<?php echo $rinfo['end_time']; ?>" type="text" id="endTime" name="endTime" />
<span class="text-danger" id=""><?php if(isset($errors['endTime'])) echo $errors['endTime']; ?></span>
<label for="totalSeats">Total Seats:</label>
<input value="<?php echo $rinfo['total_seats']; ?>" type="text" id="totalSeats" name="totalSeats" />
<span class="text-danger" id=""><?php if(isset($errors['totalSeats'])) echo $errors['totalSeats']; ?></span>
<label for="seatCharge">Charge / Seat Fare:</label>
<input value="<?php echo $rinfo['charge']; ?>" type="text" id="seatCharge" name="seatCharge" />
<span class="text-danger" id=""><?php if(isset($errors['seatCharge'])) echo $errors['seatCharge']; ?></span>
<label for="status">Status:</label>
<select id="status" name="status">
<option <?php if($rinfo['status'] === 'Active') echo "selected"; ?> value="Active">Active</option>
<option <?php if($rinfo['status'] === 'Deleted') echo "selected"; ?> value="Deleted">Deleted</option>
</select>
<span class="text-danger" id=""><?php if(isset($errors['status'])) echo $errors['status']; ?></span>
<button type="submit" name="submit"
class="submit-button"
id="statusButton"
onclick="toggleStatus()">
Update
</button>
</form>
</div>
</div>
</body>
</html>
<?php
mysqli_close($con);
}
else
{
header("location: login.php");
}
ob_end_flush();
?>