-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.php
267 lines (247 loc) · 14.7 KB
/
Settings.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
<?php
include("connection.php");
session_start(); // Start the session
if (!isset($_SESSION['login'])) {
header("Location: index.php");
} else {
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" href="./img/favicon.ico">
<!-- fontawesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
crossorigin="anonymous" referrerpolicy="no-referrer"/>
<!-- bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD"
crossorigin="anonymous">
<!-- main css -->
<link rel="stylesheet" type="text/css" href="./css/style.css">
<title>Settings</title>
</head>
<body class="bg-gray">
<!--============ Header =========-->
<?php
include 'header.php';
?>
<!-- ================= Main ================= -->
<div class="container-fluid" style="margin-bottom: 100px;">
<div class="row justify-content-evenly">
<!-- ================= Sidebar ================= -->
<div class="col-12 col-lg-3">
<div class="d-none d-xxl-block h-100 fixed-top overflow-hidden scrollbar"
style="max-width: 360px; width: 100%; z-index: 4">
<ul class="navbar-nav mt-4 ms-3 d-flex flex-column pb-5 mb-5" style="padding-top: 56px">
<!-- top -->
<!-- avatar -->
<li class="dropdown-item p-1 rounded">
<a href="Settings.php" class="d-flex align-items-center text-decoration-none text-dark">
<div class="p-2">
<img src="https://source.unsplash.com/collection/happy-people" alt="avatar"
class="rounded-circle me-2"
style="width: 38px; height: 38px; object-fit: cover"/>
</div>
<div>
<p class="m-0"><?php echo $_SESSION['full_name']; ?></p>
</div>
</a>
</li>
<!-- top 1 -->
<li class="dropdown-item p-1 rounded">
<a href="index.php" class="d-flex align-items-center text-decoration-none text-dark"
id="back-to-home">
<div class="p-2">
<i class="fa-solid fa-home-lg-alt topic-icon active" style="font-size: 35px;"></i>
</div>
<div>
<p class="m-0" style="padding-left: 10px;" id="back-to-home-text">Back to Home</p>
</div>
</a>
</li>
<hr class="m-0"/>
</ul>
</div>
</div>
<!-- ================= Timeline ================= -->
<div class="col-12 col-lg-12">
<div class="d-flex flex-column justify-content-center mx-auto main-container">
<?php
// Update password
if (isset($_POST['update-password'])) {
$currentPassword = $_POST['currentPassword'];
$newPassword = $_POST['newPassword'];
$confirmNewPassword = $_POST['confirmNewPassword'];
$staff_id = $_SESSION['staff_id'];
// Check if the current password is correct
$sql = "SELECT * FROM Staff WHERE StaffID = '$staff_id'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$password = $row['Password'];
if (!password_verify($currentPassword, $password)) {
echo "<div class='alert alert-danger mt-3' role='alert'>The current password you entered is incorrect.</div>";
} else {
// Check if the new password and the confirmation password match
if ($newPassword !== $confirmNewPassword) {
echo "<div class='alert alert-danger mt-3' role='alert'>The new password and confirmation password do not match.</div>";
} else {
// Update the password in the database with the new password
$newPasswordHash = password_hash($newPassword, PASSWORD_DEFAULT);
$sql = "UPDATE Staff SET password = '$newPasswordHash' WHERE StaffID = '$staff_id'";
if (mysqli_query($conn, $sql)) {
echo "<div class='alert alert-success mt-3' role='alert'>Your password has been updated.</div>";
} else {
echo "<div class='alert alert-danger mt-3' role='alert'>An error occurred while updating your password. Please try again later.</div>";
}
}
}
}
?>
<!-- Change Pass -->
<div class="card mb-3">
<div class="card-header bg-primary text-white">Change Password</div>
<div class="card-body">
<form action="Settings.php" method="post">
<div class="mb-3">
<label for="currentPassword" class="form-label">Current Password</label>
<div class="input-group">
<input type="password" class="form-control form-control-sm" id="currentPassword"
autocomplete="current-password" name="currentPassword">
<button class="btn btn-outline-secondary" type="button"
id="showCurrentPasswordBtn">
<i class="fa fa-eye"></i>
</button>
</div>
</div>
<div class="mb-3">
<label for="newPassword" class="form-label">New Password</label>
<div class="input-group">
<input type="password" class="form-control form-control-sm" id="newPassword"
autocomplete="new-password" name="newPassword">
<button class="btn btn-outline-secondary" type="button" id="showNewPasswordBtn">
<i class="fa fa-eye"></i>
</button>
</div>
</div>
<div class="mb-3">
<label for="confirmNewPassword" class="form-label">Confirm New Password</label>
<div class="input-group">
<input type="password" class="form-control form-control-sm"
id="confirmNewPassword" autocomplete="new-password"
name="confirmNewPassword">
<button class="btn btn-outline-secondary" type="button"
id="showConfirmNewPasswordBtn">
<i class="fa fa-eye"></i>
</button>
</div>
</div>
<button type="submit" class="btn btn-primary" name="update-password">Save Changes
</button>
</form>
</div>
</div>
<!-- Hide pass -->
<script>
// Get the buttons and input fields
const showCurrentPasswordBtn = document.getElementById("showCurrentPasswordBtn");
const showNewPasswordBtn = document.getElementById("showNewPasswordBtn");
const showConfirmNewPasswordBtn = document.getElementById("showConfirmNewPasswordBtn");
const currentPasswordInput = document.getElementById("currentPassword");
const newPasswordInput = document.getElementById("newPassword");
const confirmNewPasswordInput = document.getElementById("confirmNewPassword");
// Toggle password visibility when the buttons are clicked
showCurrentPasswordBtn.addEventListener("click", () => {
if (currentPasswordInput.type === "password") {
currentPasswordInput.type = "text";
} else {
currentPasswordInput.type = "password";
}
});
showNewPasswordBtn.addEventListener("click", () => {
if (newPasswordInput.type === "password") {
newPasswordInput.type = "text";
} else {
newPasswordInput.type = "password";
}
});
showConfirmNewPasswordBtn.addEventListener("click", () => {
if (confirmNewPasswordInput.type === "password") {
confirmNewPasswordInput.type = "text";
} else {
confirmNewPasswordInput.type = "password";
}
});
</script>
<?php
// Get the staff's current information
$staff_id = $_SESSION['staff_id'];
$sql = "SELECT * FROM Staff, Role, Department WHERE Staff.RoleID = Role.RoleID AND Staff.DepartmentID = Department.DepartmentID AND StaffID = '$staff_id'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
// Update staff information
if (isset($_POST['update-account'])) {
$full_name = $_POST['full_name'];
$email = $_POST['email'];
$sql = "UPDATE Staff SET FullName = '$full_name', Email = '$email' WHERE StaffID = '$staff_id'";
mysqli_query($conn, $sql);
// Update the current row to show the new information
$row['FullName'] = $full_name;
$row['Email'] = $email;
// Update the session variables to show the new information
$_SESSION['full_name'] = $full_name;
echo "<div class='alert alert-success mt-3' role='alert'>Your account information has been updated.</div>";
}
?>
<div class="card mb-3">
<div class="card-header bg-primary text-white">Change Account Information</div>
<div class="card-body">
<form action="Settings.php" method="post">
<div class="mb-3">
<label for="fullName" class="form-label">Full Name</label>
<input type="text" class="form-control" id="fullName" name="full_name"
value="<?php echo $row['FullName']; ?>">
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" name="email"
value="<?php echo $row['Email']; ?>" required readonly
style="background-color: #e9ecef;">
</div>
<div class="mb-3">
<label for="roleName" class="form-label">Role Name</label>
<input type="text" class="form-control" id="roleName"
value="<?php echo $row['RoleName']; ?>" readonly
style="background-color: #e9ecef;">
</div>
<div class="mb-3">
<label for="departmentName" class="form-label">Department Name</label>
<input type="text" class="form-control" id="departmentName"
value="<?php echo $row['DepartmentName']; ?>" readonly
style="background-color: #e9ecef;">
</div>
<button type="submit" class="btn btn-primary" name="update-account">Save Changes
</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<!--============ Footer =========-->
<?php
include 'footer.php';
?>
<!-- bootstrap -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN"
crossorigin="anonymous"></script>
<!-- main js -->
<script src="./js/main.js"></script>
</body>
</html>
<?php } ?>