forked from neyamulhasan/DropEx-Logistics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadminDashboard.php
More file actions
273 lines (255 loc) · 12.4 KB
/
Copy pathadminDashboard.php
File metadata and controls
273 lines (255 loc) · 12.4 KB
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
<?php
session_start();
require_once 'config.php';
// Check if admin is logged in
if(!isset($_SESSION['admin_id'])) {
header("Location: admin_login.php");
exit;
}
// Handle staff deletion
if(isset($_POST['delete_staff'])) {
$staff_id = mysqli_real_escape_string($conn, $_POST['staff_id']);
// Delete from staff table using prepared statement
$delete_sql = "DELETE FROM staff WHERE StaffID = ?";
$stmt = mysqli_prepare($conn, $delete_sql);
if($stmt) {
mysqli_stmt_bind_param($stmt, "s", $staff_id);
if(mysqli_stmt_execute($stmt)) {
$success_message = "Staff member deleted successfully";
} else {
$error_message = "Error deleting staff member: " . mysqli_error($conn);
}
mysqli_stmt_close($stmt);
} else {
$error_message = "Error preparing delete statement: " . mysqli_error($conn);
}
}
// Handle staff addition
if(isset($_POST['add_staff'])) {
// Sanitize and validate input
$staff_id = mysqli_real_escape_string($conn, $_POST['new_staff_id']);
$pass = mysqli_real_escape_string($conn, $_POST['pass']); // Store password as is since no hashing requirement specified
$name = mysqli_real_escape_string($conn, $_POST['name']);
$designation = mysqli_real_escape_string($conn, $_POST['designation']);
$gender = mysqli_real_escape_string($conn, $_POST['gender']);
$dob = mysqli_real_escape_string($conn, $_POST['dob']);
$doj = mysqli_real_escape_string($conn, $_POST['doj']);
$salary = filter_var($_POST['salary'], FILTER_VALIDATE_INT);
$mobile = mysqli_real_escape_string($conn, $_POST['mobile']);
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
$credits = 0;
// Validate required fields
if(!$staff_id || !$name || !$designation || !$gender || !$dob || !$doj || !$salary || !$mobile || !$email) {
$error_message = "All fields are required and must be valid";
} else {
// Check if StaffID already exists
$check_sql = "SELECT StaffID FROM staff WHERE StaffID = ?";
$check_stmt = mysqli_prepare($conn, $check_sql);
mysqli_stmt_bind_param($check_stmt, "s", $staff_id);
mysqli_stmt_execute($check_stmt);
mysqli_stmt_store_result($check_stmt);
if(mysqli_stmt_num_rows($check_stmt) > 0) {
$error_message = "Staff ID already exists";
} else {
// Insert into staff table using prepared statement
$insert_sql = "INSERT INTO staff (StaffID, Name, Designation, Gender, DOB, DOJ, Salary, Mobile, Email, Credits, pass)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = mysqli_prepare($conn, $insert_sql);
if($stmt) {
mysqli_stmt_bind_param($stmt, "ssssssissss",
$staff_id, $name, $designation, $gender, $dob, $doj, $salary, $mobile, $email, $credits, $pass);
if(mysqli_stmt_execute($stmt)) {
$success_message = "Staff member added successfully";
} else {
$error_message = "Error adding staff member: " . mysqli_error($conn);
}
mysqli_stmt_close($stmt);
} else {
$error_message = "Error preparing insert statement: " . mysqli_error($conn);
}
}
mysqli_stmt_close($check_stmt);
}
}
// Fetch all staff
$staff_sql = "SELECT * FROM staff ORDER BY StaffID";
$staff_result = mysqli_query($conn, $staff_sql);
// Fetch all feedback
$feedback_sql = "SELECT * FROM feedback";
$feedback_result = mysqli_query($conn, $feedback_sql);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DropEx Admin</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
background-image: url('Images/admindasb.jpg');
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="#">DropEx Admin</a>
<div class="navbar-nav ms-auto">
<a class="nav-link" href="admin_logout.php">Logout</a>
</div>
</div>
</nav>
<div class="container mt-4">
<?php if(isset($success_message)): ?>
<div class="alert alert-success"><?php echo $success_message; ?></div>
<?php endif; ?>
<?php if(isset($error_message)): ?>
<div class="alert alert-danger"><?php echo $error_message; ?></div>
<?php endif; ?>
<div class="row">
<div class="col-md-12 mb-4">
<h2 style="color:rgb(255, 255, 255);">Staff Management</h2>
<!-- Add Staff Form -->
<div class="card mb-4">
<div class="card-header">
<h4>Add New Staff</h4>
</div>
<div class="card-body">
<form method="POST" action="">
<div class="row">
<div class="col-md-4 mb-3">
<input type="text" class="form-control" name="new_staff_id" placeholder="Staff ID" required>
</div>
<div class="col-md-4 mb-3">
<input type="text" class="form-control" name="name" placeholder="Name" required>
</div>
<div class="col-md-4 mb-3">
<input type="password" class="form-control" name="pass" placeholder="Password" required>
</div>
<div class="col-md-4 mb-3">
<input type="text" class="form-control" name="designation" placeholder="Designation" required>
</div>
<div class="col-md-4 mb-3">
<select class="form-control" name="gender" required>
<option value="">Select Gender</option>
<option value="M">Male</option>
<option value="F">Female</option>
</select>
</div>
<div class="col-md-4 mb-3">
<input type="date" class="form-control" name="dob" placeholder="Date of Birth" required>
</div>
<div class="col-md-4 mb-3">
<input type="date" class="form-control" name="doj" placeholder="Date of Joining" required>
</div>
<div class="col-md-4 mb-3">
<input type="number" class="form-control" name="salary" placeholder="Salary" required>
</div>
<div class="col-md-4 mb-3">
<input type="tel" class="form-control" name="mobile" placeholder="Mobile" required>
</div>
<div class="col-md-4 mb-3">
<input type="email" class="form-control" name="email" placeholder="Email" required>
</div>
</div>
<button type="submit" name="add_staff" class="btn btn-primary">Add Staff</button>
</form>
</div>
</div>
<!-- Staff List -->
<div class="card">
<div class="card-header">
<h4>Staff List</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Staff ID</th>
<th>Name</th>
<th>Designation</th>
<th>Gender</th>
<th>DOB</th>
<th>DOJ</th>
<th>Salary</th>
<th>Mobile</th>
<th>Email</th>
<th>Credits</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
//this is for only show staff neyamul hasan make changes
while($staff = mysqli_fetch_assoc($staff_result)):
if($staff['Designation'] == 'Staff'):
?>
<tr>
<td><?php echo htmlspecialchars($staff['StaffID']); ?></td>
<td><?php echo htmlspecialchars($staff['Name']); ?></td>
<td><?php echo htmlspecialchars($staff['Designation']); ?></td>
<td><?php echo htmlspecialchars($staff['Gender']); ?></td>
<td><?php echo htmlspecialchars($staff['DOB']); ?></td>
<td><?php echo htmlspecialchars($staff['DOJ']); ?></td>
<td><?php echo htmlspecialchars($staff['Salary']); ?></td>
<td><?php echo htmlspecialchars($staff['Mobile']); ?></td>
<td><?php echo htmlspecialchars($staff['Email']); ?></td>
<td><?php echo htmlspecialchars($staff['Credits']); ?></td>
<td>
<form method="POST" action="" onsubmit="return confirm('Are you sure you want to delete this staff member?');">
<input type="hidden" name="staff_id" value="<?php echo $staff['StaffID']; ?>">
<button type="submit" name="delete_staff" class="btn btn-danger btn-sm">Delete</button>
</form>
</td>
</tr>
<?php
endif;
endwhile;
//this is for only show staff neyamul hasan make changes
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Feedback Section -->
<div class="col-md-12">
<h2 style="color:rgb(255, 255, 255);">Customer Feedback</h2>
<div class="card">
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>No.</th>
<th>Customer Name</th>
<th>Email</th>
<th>Message</th>
</tr>
</thead>
<tbody>
<?php while($feedback = mysqli_fetch_assoc($feedback_result)): ?>
<tr>
<td><?php echo htmlspecialchars($feedback['F.No']); ?></td>
<td><?php echo htmlspecialchars($feedback['Cust_name']); ?></td>
<td><?php echo htmlspecialchars($feedback['Cust_mail']); ?></td>
<td><?php echo htmlspecialchars($feedback['Cust_msg']); ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>