-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.php
283 lines (255 loc) · 17.6 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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<?php
// Settings page for BuggyBank
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
// Store the current page as the redirect URL
$_SESSION['redirect_after_login'] = 'index.php?page=settings';
header('Location: index.php?page=login');
exit;
}
// Get user data
$user_id = $_SESSION['user_id'];
$user_query = "SELECT * FROM users WHERE id = $user_id";
$user_result = mysqli_query($conn, $user_query);
$user = mysqli_fetch_assoc($user_result);
// Process form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$success_message = '';
$error_message = '';
// Security settings
if (isset($_POST['security_settings'])) {
$enable_2fa = isset($_POST['enable_2fa']) ? 1 : 0;
$login_notifications = isset($_POST['login_notifications']) ? 1 : 0;
$transaction_notifications = isset($_POST['transaction_notifications']) ? 1 : 0;
$update_query = "UPDATE users SET
enable_2fa = $enable_2fa,
login_notifications = $login_notifications,
transaction_notifications = $transaction_notifications
WHERE id = $user_id";
if (mysqli_query($conn, $update_query)) {
$success_message = "Security settings updated successfully!";
// Refresh user data
$user_result = mysqli_query($conn, $user_query);
$user = mysqli_fetch_assoc($user_result);
} else {
$error_message = "Error updating security settings: " . mysqli_error($conn);
}
}
// Notification settings
if (isset($_POST['notification_settings'])) {
$email_notifications = isset($_POST['email_notifications']) ? 1 : 0;
$sms_notifications = isset($_POST['sms_notifications']) ? 1 : 0;
$marketing_emails = isset($_POST['marketing_emails']) ? 1 : 0;
$update_query = "UPDATE users SET
email_notifications = $email_notifications,
sms_notifications = $sms_notifications,
marketing_emails = $marketing_emails
WHERE id = $user_id";
if (mysqli_query($conn, $update_query)) {
$success_message = "Notification settings updated successfully!";
// Refresh user data
$user_result = mysqli_query($conn, $user_query);
$user = mysqli_fetch_assoc($user_result);
} else {
$error_message = "Error updating notification settings: " . mysqli_error($conn);
}
}
// Display settings
if (isset($_POST['display_settings'])) {
$theme = mysqli_real_escape_string($conn, $_POST['theme']);
$language = mysqli_real_escape_string($conn, $_POST['language']);
$timezone = mysqli_real_escape_string($conn, $_POST['timezone']);
$update_query = "UPDATE users SET
theme = '$theme',
language = '$language',
timezone = '$timezone'
WHERE id = $user_id";
if (mysqli_query($conn, $update_query)) {
$success_message = "Display settings updated successfully!";
// Refresh user data
$user_result = mysqli_query($conn, $user_query);
$user = mysqli_fetch_assoc($user_result);
} else {
$error_message = "Error updating display settings: " . mysqli_error($conn);
}
}
}
?>
<div class="container py-5">
<div class="row">
<div class="col-lg-3">
<div class="card shadow-sm mb-4">
<div class="card-body">
<h5 class="card-title mb-3">Settings</h5>
<div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
<button class="nav-link active mb-2" id="v-pills-security-tab" data-bs-toggle="pill" data-bs-target="#v-pills-security" type="button" role="tab" aria-controls="v-pills-security" aria-selected="true">
<i class="fas fa-shield-alt me-2"></i>Security
</button>
<button class="nav-link mb-2" id="v-pills-notifications-tab" data-bs-toggle="pill" data-bs-target="#v-pills-notifications" type="button" role="tab" aria-controls="v-pills-notifications" aria-selected="false">
<i class="fas fa-bell me-2"></i>Notifications
</button>
<button class="nav-link mb-2" id="v-pills-display-tab" data-bs-toggle="pill" data-bs-target="#v-pills-display" type="button" role="tab" aria-controls="v-pills-display" aria-selected="false">
<i class="fas fa-desktop me-2"></i>Display
</button>
<button class="nav-link mb-2" id="v-pills-privacy-tab" data-bs-toggle="pill" data-bs-target="#v-pills-privacy" type="button" role="tab" aria-controls="v-pills-privacy" aria-selected="false">
<i class="fas fa-user-secret me-2"></i>Privacy
</button>
</div>
</div>
</div>
</div>
<div class="col-lg-9">
<?php if (isset($success_message) && !empty($success_message)): ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<i class="fas fa-check-circle me-2"></i><?php echo $success_message; ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php endif; ?>
<?php if (isset($error_message) && !empty($error_message)): ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<i class="fas fa-exclamation-circle me-2"></i><?php echo $error_message; ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php endif; ?>
<div class="tab-content" id="v-pills-tabContent">
<!-- Security Settings -->
<div class="tab-pane fade show active" id="v-pills-security" role="tabpanel" aria-labelledby="v-pills-security-tab">
<div class="card shadow-sm">
<div class="card-header bg-primary text-white">
<h5 class="mb-0"><i class="fas fa-shield-alt me-2"></i>Security Settings</h5>
</div>
<div class="card-body">
<form method="POST" action="index.php?page=settings">
<div class="mb-4">
<h6 class="mb-3">Account Security</h6>
<div class="form-check form-switch mb-3">
<input class="form-check-input" type="checkbox" id="enable_2fa" name="enable_2fa" <?php echo (isset($user['enable_2fa']) && $user['enable_2fa'] == 1) ? 'checked' : ''; ?>>
<label class="form-check-label" for="enable_2fa">Enable Two-Factor Authentication</label>
</div>
<div class="form-check form-switch mb-3">
<input class="form-check-input" type="checkbox" id="login_notifications" name="login_notifications" <?php echo (isset($user['login_notifications']) && $user['login_notifications'] == 1) ? 'checked' : ''; ?>>
<label class="form-check-label" for="login_notifications">Receive notifications for new logins</label>
</div>
<div class="form-check form-switch mb-3">
<input class="form-check-input" type="checkbox" id="transaction_notifications" name="transaction_notifications" <?php echo (isset($user['transaction_notifications']) && $user['transaction_notifications'] == 1) ? 'checked' : ''; ?>>
<label class="form-check-label" for="transaction_notifications">Receive notifications for new transactions</label>
</div>
</div>
<div class="mb-4">
<h6 class="mb-3">Password Management</h6>
<div class="mb-3">
<a href="index.php?page=change_password" class="btn btn-outline-primary">
<i class="fas fa-key me-2"></i>Change Password
</a>
</div>
</div>
<div class="d-grid">
<button type="submit" name="security_settings" class="btn btn-primary">
<i class="fas fa-save me-2"></i>Save Security Settings
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Notification Settings -->
<div class="tab-pane fade" id="v-pills-notifications" role="tabpanel" aria-labelledby="v-pills-notifications-tab">
<div class="card shadow-sm">
<div class="card-header bg-primary text-white">
<h5 class="mb-0"><i class="fas fa-bell me-2"></i>Notification Settings</h5>
</div>
<div class="card-body">
<form method="POST" action="index.php?page=settings">
<div class="mb-4">
<h6 class="mb-3">Communication Preferences</h6>
<div class="form-check form-switch mb-3">
<input class="form-check-input" type="checkbox" id="email_notifications" name="email_notifications" <?php echo (isset($user['email_notifications']) && $user['email_notifications'] == 1) ? 'checked' : ''; ?>>
<label class="form-check-label" for="email_notifications">Email Notifications</label>
</div>
<div class="form-check form-switch mb-3">
<input class="form-check-input" type="checkbox" id="sms_notifications" name="sms_notifications" <?php echo (isset($user['sms_notifications']) && $user['sms_notifications'] == 1) ? 'checked' : ''; ?>>
<label class="form-check-label" for="sms_notifications">SMS Notifications</label>
</div>
<div class="form-check form-switch mb-3">
<input class="form-check-input" type="checkbox" id="marketing_emails" name="marketing_emails" <?php echo (isset($user['marketing_emails']) && $user['marketing_emails'] == 1) ? 'checked' : ''; ?>>
<label class="form-check-label" for="marketing_emails">Marketing Emails</label>
</div>
</div>
<div class="d-grid">
<button type="submit" name="notification_settings" class="btn btn-primary">
<i class="fas fa-save me-2"></i>Save Notification Settings
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Display Settings -->
<div class="tab-pane fade" id="v-pills-display" role="tabpanel" aria-labelledby="v-pills-display-tab">
<div class="card shadow-sm">
<div class="card-header bg-primary text-white">
<h5 class="mb-0"><i class="fas fa-desktop me-2"></i>Display Settings</h5>
</div>
<div class="card-body">
<form method="POST" action="index.php?page=settings">
<div class="mb-3">
<label for="theme" class="form-label">Theme</label>
<select class="form-select" id="theme" name="theme">
<option value="light" <?php echo (isset($user['theme']) && $user['theme'] == 'light') ? 'selected' : ''; ?>>Light</option>
<option value="dark" <?php echo (isset($user['theme']) && $user['theme'] == 'dark') ? 'selected' : ''; ?>>Dark</option>
<option value="system" <?php echo (isset($user['theme']) && $user['theme'] == 'system') ? 'selected' : ''; ?>>System Default</option>
</select>
</div>
<div class="mb-3">
<label for="language" class="form-label">Language</label>
<select class="form-select" id="language" name="language">
<option value="en" <?php echo (isset($user['language']) && $user['language'] == 'en') ? 'selected' : ''; ?>>English</option>
<option value="es" <?php echo (isset($user['language']) && $user['language'] == 'es') ? 'selected' : ''; ?>>Spanish</option>
<option value="fr" <?php echo (isset($user['language']) && $user['language'] == 'fr') ? 'selected' : ''; ?>>French</option>
<option value="de" <?php echo (isset($user['language']) && $user['language'] == 'de') ? 'selected' : ''; ?>>German</option>
</select>
</div>
<div class="mb-3">
<label for="timezone" class="form-label">Timezone</label>
<select class="form-select" id="timezone" name="timezone">
<option value="UTC" <?php echo (isset($user['timezone']) && $user['timezone'] == 'UTC') ? 'selected' : ''; ?>>UTC</option>
<option value="America/New_York" <?php echo (isset($user['timezone']) && $user['timezone'] == 'America/New_York') ? 'selected' : ''; ?>>Eastern Time (ET)</option>
<option value="America/Chicago" <?php echo (isset($user['timezone']) && $user['timezone'] == 'America/Chicago') ? 'selected' : ''; ?>>Central Time (CT)</option>
<option value="America/Denver" <?php echo (isset($user['timezone']) && $user['timezone'] == 'America/Denver') ? 'selected' : ''; ?>>Mountain Time (MT)</option>
<option value="America/Los_Angeles" <?php echo (isset($user['timezone']) && $user['timezone'] == 'America/Los_Angeles') ? 'selected' : ''; ?>>Pacific Time (PT)</option>
<option value="Europe/London" <?php echo (isset($user['timezone']) && $user['timezone'] == 'Europe/London') ? 'selected' : ''; ?>>London</option>
<option value="Europe/Paris" <?php echo (isset($user['timezone']) && $user['timezone'] == 'Europe/Paris') ? 'selected' : ''; ?>>Paris</option>
<option value="Asia/Tokyo" <?php echo (isset($user['timezone']) && $user['timezone'] == 'Asia/Tokyo') ? 'selected' : ''; ?>>Tokyo</option>
</select>
</div>
<div class="d-grid">
<button type="submit" name="display_settings" class="btn btn-primary">
<i class="fas fa-save me-2"></i>Save Display Settings
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Privacy Settings -->
<div class="tab-pane fade" id="v-pills-privacy" role="tabpanel" aria-labelledby="v-pills-privacy-tab">
<div class="card shadow-sm">
<div class="card-header bg-primary text-white">
<h5 class="mb-0"><i class="fas fa-user-secret me-2"></i>Privacy Settings</h5>
</div>
<div class="card-body">
<div class="alert alert-info">
<i class="fas fa-info-circle me-2"></i>Privacy settings are managed through your profile page.
</div>
<div class="d-grid">
<a href="index.php?page=profile" class="btn btn-primary">
<i class="fas fa-user me-2"></i>Go to Profile
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>