-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.php
More file actions
319 lines (286 loc) · 14.5 KB
/
settings.php
File metadata and controls
319 lines (286 loc) · 14.5 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
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
316
317
318
319
<?php
include("assets/php/processes/functions.php");
include("connect.php");
session_start();
userAuth();
$error = "";
$userID = $_SESSION['userID'];
$personalInfoQuery="SELECT * FROM userS WHERE userID=$userID";
$personalInfoResults= executeQuery($personalInfoQuery);
include("assets/php/processes/imageProcessProfile.php");
include("assets/php/processes/imageProcessLogo.php");
include("assets/php/processes/deleteProfileProcess.php");
//updating Fullname and birthday
if(isset($_POST['btnProfile'])){
$firstName=$_POST['firstName'];
$lastName=$_POST['lastName'];
$birthday=$_POST['birthday'];
if (!empty($firstName) && !empty($lastName) && !empty($birthday)) {
$updatePersonalInfoQuery="UPDATE users SET `firstName`='$firstName',`lastName`='$lastName', `birthday`='$birthday' WHERE userID=$userID";
executeQuery($updatePersonalInfoQuery);
header("Location: " . $_SERVER['PHP_SELF']);
exit();
}
}
//updating username and email
if(isset($_POST['btnAccountInfo'])){
$username=$_POST['username'];
$email=$_POST['email'];
if (!empty($username) && !empty($email)) {
$updatePersonalInfoQuery="UPDATE users SET `username`='$username',`email`='$email' WHERE userID = $userID";
executeQuery($updatePersonalInfoQuery);
header("Location: " . $_SERVER['PHP_SELF']);
exit();
}
}
//updating password
if (isset($_POST['btnChangePassword'])) {
$oldpassword = $_POST['oldpassword'];
$newpassword = $_POST['newpassword'];
$confirmpassword = $_POST['confirmpassword'];
// Fetch the current password from the database
$currentpassword = "";
while ($row = mysqli_fetch_assoc($personalInfoResults)) {
$currentpassword = $row['password'];
}
// Validation
if ($oldpassword != $currentpassword) {
$error = "Old Password";
header("Location: " . $_SERVER['PHP_SELF'] . "?error=" . urlencode($error));
exit();
} elseif ($newpassword != $confirmpassword) {
$error = "Passwords do not match";
header("Location: " . $_SERVER['PHP_SELF'] . "?error=" . urlencode($error));
exit();
} elseif (strlen($newpassword) < 8) {
$error = "Passwords 8";
header("Location: " . $_SERVER['PHP_SELF'] . "?error=" . urlencode($error));
exit();
}
else {
// Update password in the database
$error = "success";
$updatePersonalInfoQuery = "UPDATE users SET `password`='$newpassword' WHERE userID = $userID";
executeQuery($updatePersonalInfoQuery);
header("Location: " . $_SERVER['PHP_SELF'] . "?error=" . urlencode($error));
exit();
}
}
//Account Deletion
if(isset($_POST['btnAccountDelete'])){
$deleteAccountQuery="DELETE FROM users WHERE userID = $userID";
executeQuery($deleteAccountQuery);
header("Location: index.php");
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Settings Page</title>
<link rel="icon" href="assets/images/websiteLogo/<?php echo $websiteLogo?>" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link href="https://fonts.googleapis.com/css2?family=Lexend+Exa&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<?php include('assets/shared/navbar.php'); ?>
<?php if(mysqli_num_rows($personalInfoResults)>0){
while($personalInfoRows=mysqli_fetch_assoc($personalInfoResults)){
?>
<div class="container-fluid px-3 px-md-5 py-5">
<!-- Header Navigation -->
<div class="row mb-4 mt-5 align-items-center justify-content-between px-2">
<div class="col-12 col-md-6 pt-3 pt-md-4 order-2 order-md-1">
<h1 class="heading mb-0">SETTINGS</h1>
</div>
<div class="col-12 col-md-auto d-flex flex-row align-items-center pt-3 pt-md-4 order-1 order-md-2">
<div class="col-auto text-md-end">
<span class="subheading" style="color:#1A7431;"><?php echo strtoupper(date('l')); ?></span><br><?php echo date("F d, Y"); ?>
</div>
<div class="col-auto px-3 d-none d-md-block">
<div style="width: 1px; background-color: black; height: 40px;"></div>
</div>
</div>
</div>
<!-- Header Divider -->
<hr class="mb-4">
<!-- Main Content -->
<div class="row g-4">
<!-- Left Column - Profile Section -->
<div class="col-12 col-lg-5">
<div class="card stat-card h-100">
<div class="card-body px-3 px-md-4 d-flex flex-column">
<div class="text-center mb-5">
<img id="profilePreview" src="./assets/images/userProfile/<?php echo $profilePicture?>"
alt="Profile Picture" class="rounded-circle mb-3" style="width: 250px; height: 250px; object-fit: cover;">
<div class="d-flex flex-column flex-md-row flex-sm-row justify-content-center gap-4 mb-4">
<button class="btn btn-primary" data-bs-toggle="modal"
data-bs-target="#uploadProfilePic">Upload Profile Picture</button>
<button class="btn btn-primary" data-bs-toggle="modal"
data-bs-target="#removeProfilePic">Remove Profile Picture</button>
</div>
</div>
<form method="POST" class="flex-grow-1 d-flex flex-column">
<div class="row mb-5">
<div class="col-12">
<label class="paragraph form-label">First Name</label>
<input type="text" class="form-control form-control-lg" name="firstName" value="<?php echo $personalInfoRows['firstName']?>">
</div>
</div>
<div class="mb-5">
<label class="paragraph form-label">Last Name</label>
<input type="text" class="form-control form-control-lg" name="lastName" value="<?php echo $personalInfoRows['lastName']?>">
</div>
<div class="mb-5">
<label class="paragraph form-label">Birthday</label>
<input type="date" class="form-control form-control-lg" name="birthday" value="<?php echo date("Y-m-d", strtotime($personalInfoRows['birthday']))?>">
</div>
<div class="text-end">
<button class="btn btn-primary btn-lg rounded-pill" type="submit" name="btnProfile">SAVE</button>
</div>
</form>
</div>
</div>
</div>
<!-- Right Column - Account Settings -->
<div class="col-12 col-lg-7">
<div class="card border-0 h-100" style="background-color: transparent;">
<div class="card-body px-3 px-md-4">
<!-- Account Information -->
<div class="mb-4">
<h5 class="subheading mb-2">ACCOUNT INFORMATION</h5>
<hr class="mb-3">
<form method="POST">
<div class="mb-3">
<label class="paragraph form-label">Username</label>
<input type="text" class="form-control" name="username" value="<?php echo $personalInfoRows['username']?>">
</div>
<div class="mb-3">
<label class="paragraph form-label">Email</label>
<input type="email" class="form-control" name="email" value="<?php echo $personalInfoRows['email']?>">
</div>
<div class="text-end">
<button class="btn btn-primary rounded-pill" type="submit" name="btnAccountInfo">SAVE</button>
</div>
</form>
</div>
<!-- Change Password -->
<div class="mb-4">
<h5 class="subheading mb-2">CHANGE YOUR PASSWORD</h5>
<hr class="mb-3">
<form method="POST">
<div class="mb-3">
<label class="paragraph form-label">Current Password</label>
<input type="password" class="form-control" name="oldpassword" value="">
</div>
<div class="mb-3">
<label class="paragraph form-label">New Password</label>
<input type="password" class="form-control" name="newpassword">
</div>
<div class="mb-3">
<label class="paragraph form-label">Confirm Password</label>
<input type="password" class="form-control" name="confirmpassword">
</div>
<div class="text-end">
<button class="btn btn-primary rounded-pill" type="submit" name="btnChangePassword">SAVE</button>
</div>
<!-- Alert for incorrect password change -->
<div id="alert-container" class="row justify-content-center mt-2">
<div class="col-12">
<div id="alert" class="alert" role="alert"></div>
</div>
</div>
</form>
</div>
<!-- Delete Account -->
<div class="mt-auto">
<h5 class="subheading mb-2">DELETE YOUR ACCOUNT</h5>
<hr class="mb-3">
<div
class="d-flex flex-column flex-md-row justify-content-between align-items-start align-items-md-center gap-2">
<p class="paragraph mb-0">Once deleted, your account can no longer be retrieved.</p>
<button class="btn btn-danger rounded-pill align-self-end" data-bs-toggle="modal"
data-bs-target="#deleteAccountModal">DELETE</button>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
}
}
?>
<!-- MODALS -->
<!-- Upload Logo Modal -->
<?php include('assets/php/modals/upload-profilePicture-modal.php');?>
<!-- Remove Profile Pic Modal -->
<?php include('assets/php/modals/delete-profilePicture-modal.php');?>
<!-- Confirm the deletion -->
<div class="modal fade" id="confirmRemovePictureModal" tabindex="-1"
aria-labelledby="confirmRemovePicModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content"
style="border-radius: 15px; background-color:rgb(141, 26, 37); color: white; border: none;">
<div class="modal-header" style="border: none;">
<h4 class="modal-title heading text-center w-100" id="confirmRemovePicModalLabel"
style="margin: 0;">
Profile Picture Removed
</h4>
</div>
<div class="modal-body text-center">
Your profile picture has been set to the default.
</div>
<div class="modal-footer d-flex justify-content-center" style="border: none;">
<form method="POST">
<button type="submit" name="btnDeleteProfilePic" class="btn btn-light paragraph" data-bs-dismiss="modal">
Close
</button>
</form>
</div>
</div>
</div>
</div>
<!-- Delete Account Modal -->
<?php include('assets/php/modals/delete-account-modal.php');?>
<!-- Footer -->
<div class="row mt-4">
<div class="col-12">
<hr>
<div class="d-flex justify-content-between">
<a href="https://github.com/FINTALIX" target="_blank" class="text-decoration-none paragraph" style="color: var(--primaryColor)">CONTACT
US</a>
<span class="paragraph">FINTALIX ©2025</span>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
const urlParams = new URLSearchParams(window.location.search);
const error = urlParams.get('error');
const alert = document.getElementById('alert');
if (error) {
alert.textContent =
error === 'Old Password'
? 'Old password does not match.'
: error === 'Passwords do not match'
? 'Passwords do not match.'
: error === 'Passwords 8'
? 'Passwords is not 8 characters long.'
: 'Password updated successfully.';
alert.className =
error === 'success'
? 'alert alert-success'
: 'alert alert-warning';
} else {
alert.classList.add('d-none');
}
history.replaceState(null, document.title, window.location.pathname);
</script>
</body>
</html>