-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings_actions.php
More file actions
59 lines (46 loc) · 1.83 KB
/
Copy pathsettings_actions.php
File metadata and controls
59 lines (46 loc) · 1.83 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
<?php
require_once __DIR__ . '/autoload.php';
use App\Core\Bootstrap;
use App\Helpers\SecurityHelper;
use App\Helpers\AuditHelper;
Bootstrap::init();
const REDIRECT_LOCATION = "Location: ";
const REDIRECT_DASHBOARD = REDIRECT_LOCATION . BASE_URL . "dashboard.php"; // Safe internal redirect
if (!isset($_SESSION['user_id'])) {
header(REDIRECT_LOCATION . BASE_URL . "index.php");
exit();
}
$user_id = $_SESSION['user_id'];
$action = $_POST['action'] ?? '';
if ($action == 'toggle_currency') {
SecurityHelper::verifyCsrfToken($_POST['csrf_token'] ?? '');
$current = $_SESSION['preferences']['base_currency'] ?? 'AED';
$new = ($current == 'AED') ? 'INR' : 'AED';
try {
$stmt = $pdo->prepare("UPDATE user_preferences SET base_currency = ? WHERE user_id = ?");
$stmt->execute([$new, $user_id]);
$_SESSION['preferences']['base_currency'] = $new;
AuditHelper::log($pdo, 'preference_change', "Changed base currency to $new");
header(REDIRECT_DASHBOARD);
exit();
} catch (Exception $e) {
error_log("Currency toggle error: " . $e->getMessage());
die("Update failed: A system error occurred.");
}
} elseif ($action == 'toggle_theme') {
SecurityHelper::verifyCsrfToken($_POST['csrf_token'] ?? '');
$current = $_SESSION['preferences']['theme_preference'] ?? 'dark';
$new = ($current == 'dark') ? 'light' : 'dark';
try {
$stmt = $pdo->prepare("UPDATE user_preferences SET theme_preference = ? WHERE user_id = ?");
$stmt->execute([$new, $user_id]);
$_SESSION['preferences']['theme_preference'] = $new;
header(REDIRECT_DASHBOARD);
exit();
} catch (Exception $e) {
error_log("Theme toggle error: " . $e->getMessage());
die("Update failed: A system error occurred.");
}
}
header(REDIRECT_DASHBOARD);
exit();