DARK LIGHT
This commit is contained in:
parent
5b5ac99cae
commit
c0b4015a24
@ -1,4 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
// Request log
|
||||||
|
file_put_contents('requests.log', date('Y-m-d H:i:s') . " - api_v1_user.php - " . $_SERVER['REQUEST_METHOD'] . " - POST: " . json_encode($_POST) . "\n", FILE_APPEND);
|
||||||
require_once 'auth/session.php';
|
require_once 'auth/session.php';
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
@ -9,18 +11,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$username = $_POST['username'] ?? $user['username'];
|
$username = !empty($_POST['username']) ? $_POST['username'] : $user['username'];
|
||||||
$avatar_url = $_POST['avatar_url'] ?? $user['avatar_url'];
|
$avatar_url = isset($_POST['avatar_url']) ? $_POST['avatar_url'] : $user['avatar_url'];
|
||||||
$dnd_mode = isset($_POST['dnd_mode']) ? (int)$_POST['dnd_mode'] : (int)($user['dnd_mode'] ?? 0);
|
$dnd_mode = isset($_POST['dnd_mode']) ? (int)$_POST['dnd_mode'] : (int)($user['dnd_mode'] ?? 0);
|
||||||
$sound_notifications = isset($_POST['sound_notifications']) ? (int)$_POST['sound_notifications'] : (int)($user['sound_notifications'] ?? 0);
|
$sound_notifications = isset($_POST['sound_notifications']) ? (int)$_POST['sound_notifications'] : (int)($user['sound_notifications'] ?? 0);
|
||||||
$theme = $_POST['theme'] ?? $user['theme'] ?? 'dark';
|
$theme = !empty($_POST['theme']) ? $_POST['theme'] : (!empty($user['theme']) ? $user['theme'] : 'dark');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stmt = db()->prepare("UPDATE users SET username = ?, avatar_url = ?, dnd_mode = ?, sound_notifications = ?, theme = ? WHERE id = ?");
|
$stmt = db()->prepare("UPDATE users SET username = ?, avatar_url = ?, dnd_mode = ?, sound_notifications = ?, theme = ? WHERE id = ?");
|
||||||
$stmt->execute([$username, $avatar_url, $dnd_mode, $sound_notifications, $theme, $user['id']]);
|
$stmt->execute([$username, $avatar_url, $dnd_mode, $sound_notifications, $theme, $user['id']]);
|
||||||
|
|
||||||
$_SESSION['username'] = $username; // Update session if stored (though getCurrentUser fetches from DB)
|
|
||||||
|
|
||||||
echo json_encode(['success' => true]);
|
echo json_encode(['success' => true]);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||||
|
|||||||
@ -79,6 +79,16 @@
|
|||||||
border-color: #c7ccd1;
|
border-color: #c7ccd1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[data-theme="dark"] .btn-outline-secondary {
|
||||||
|
color: #b5bac1;
|
||||||
|
border-color: #4e5058;
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-theme="dark"] .btn-outline-secondary:hover {
|
||||||
|
background-color: #4e5058;
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
[data-theme="light"] .btn-check:checked + .btn-outline-secondary {
|
[data-theme="light"] .btn-check:checked + .btn-outline-secondary {
|
||||||
background-color: var(--blurple) !important;
|
background-color: var(--blurple) !important;
|
||||||
border-color: var(--blurple) !important;
|
border-color: var(--blurple) !important;
|
||||||
|
|||||||
@ -2231,22 +2231,38 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
const saveSettingsBtn = document.getElementById('save-settings-btn');
|
const saveSettingsBtn = document.getElementById('save-settings-btn');
|
||||||
saveSettingsBtn?.addEventListener('click', async () => {
|
saveSettingsBtn?.addEventListener('click', async () => {
|
||||||
const form = document.getElementById('user-settings-form');
|
const form = document.getElementById('user-settings-form');
|
||||||
|
if (!form) return;
|
||||||
|
|
||||||
const formData = new FormData(form);
|
const formData = new FormData(form);
|
||||||
const dndMode = document.getElementById('dnd-switch').checked ? '1' : '0';
|
|
||||||
formData.append('dnd_mode', dndMode);
|
|
||||||
|
|
||||||
const theme = form.querySelector('input[name="theme"]:checked').value;
|
// Ensure switches are correctly sent as 1/0
|
||||||
|
const dndMode = document.getElementById('dnd-switch')?.checked ? '1' : '0';
|
||||||
|
const soundNotifications = document.getElementById('sound-switch')?.checked ? '1' : '0';
|
||||||
|
formData.set('dnd_mode', dndMode);
|
||||||
|
formData.set('sound_notifications', soundNotifications);
|
||||||
|
|
||||||
|
// Explicitly get theme to ensure it's captured
|
||||||
|
const themeInput = form.querySelector('input[name="theme"]:checked');
|
||||||
|
const theme = themeInput ? themeInput.value : 'dark';
|
||||||
|
formData.set('theme', theme);
|
||||||
|
|
||||||
|
// Visual feedback
|
||||||
document.body.setAttribute('data-theme', theme);
|
document.body.setAttribute('data-theme', theme);
|
||||||
|
|
||||||
const resp = await fetch('api_v1_user.php', {
|
try {
|
||||||
method: 'POST',
|
const resp = await fetch('api_v1_user.php?v=' + Date.now(), {
|
||||||
body: formData
|
method: 'POST',
|
||||||
});
|
body: formData
|
||||||
const result = await resp.json();
|
});
|
||||||
if (result.success) {
|
const result = await resp.json();
|
||||||
location.reload();
|
if (result.success) {
|
||||||
} else {
|
window.location.href = window.location.pathname + window.location.search;
|
||||||
alert(result.error || 'Failed to save settings');
|
} else {
|
||||||
|
alert(result.error || 'Failed to save settings');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error saving settings:', e);
|
||||||
|
alert('Failed to save settings. Please check your connection.');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
26
index.php
26
index.php
@ -306,7 +306,7 @@ $projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body data-theme="<?php echo htmlspecialchars($user['theme'] ?? 'dark'); ?>">
|
<body data-theme="<?php echo htmlspecialchars($user['theme'] ?: 'dark'); ?>">
|
||||||
|
|
||||||
<div class="discord-app">
|
<div class="discord-app">
|
||||||
<!-- Servers Sidebar -->
|
<!-- Servers Sidebar -->
|
||||||
@ -1022,13 +1022,23 @@ $emote_html = '<img src="' . htmlspecialchars($ce['path']) . '" alt="' . htmlspe
|
|||||||
<label class="form-check-label text-white" for="sound-switch">Sound Notifications</label>
|
<label class="form-check-label text-white" for="sound-switch">Sound Notifications</label>
|
||||||
<div class="form-text text-muted" style="font-size: 0.8em;">Play a sound when you are mentioned.</div>
|
<div class="form-text text-muted" style="font-size: 0.8em;">Play a sound when you are mentioned.</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-2">
|
<div class="mb-3">
|
||||||
<label class="form-label text-white d-block" style="font-size: 0.9em;">Appearance</label>
|
<label class="form-label text-uppercase fw-bold" style="font-size: 0.7em; color: var(--text-muted);">Appearance</label>
|
||||||
<div class="btn-group w-100" role="group">
|
<div class="row g-2">
|
||||||
<input type="radio" class="btn-check" name="theme" id="theme-dark" value="dark" <?php echo ($user['theme'] ?? 'dark') == 'dark' ? 'checked' : ''; ?>>
|
<div class="col-6">
|
||||||
<label class="btn btn-outline-secondary btn-sm" for="theme-dark">Dark</label>
|
<input type="radio" class="btn-check" name="theme" id="theme-dark" value="dark" <?php echo ($user['theme'] ?? 'dark') == 'dark' ? 'checked' : ''; ?> onchange="document.body.setAttribute('data-theme', 'dark')">
|
||||||
<input type="radio" class="btn-check" name="theme" id="theme-light" value="light" <?php echo ($user['theme'] ?? 'dark') == 'light' ? 'checked' : ''; ?>>
|
<label class="btn btn-outline-secondary w-100 py-3" for="theme-dark">
|
||||||
<label class="btn btn-outline-secondary btn-sm" for="theme-light">Light</label>
|
<i class="fa-solid fa-moon d-block mb-1"></i>
|
||||||
|
Dark
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="col-6">
|
||||||
|
<input type="radio" class="btn-check" name="theme" id="theme-light" value="light" <?php echo ($user['theme'] ?? 'dark') == 'light' ? 'checked' : ''; ?> onchange="document.body.setAttribute('data-theme', 'light')">
|
||||||
|
<label class="btn btn-outline-secondary w-100 py-3" for="theme-light">
|
||||||
|
<i class="fa-solid fa-sun d-block mb-1"></i>
|
||||||
|
Light
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -301,3 +301,5 @@
|
|||||||
2026-02-16 20:18:56 - GET /?fl_project=38443 - POST: []
|
2026-02-16 20:18:56 - GET /?fl_project=38443 - POST: []
|
||||||
2026-02-16 20:29:33 - GET /index.php?server_id=1&channel_id=6 - POST: []
|
2026-02-16 20:29:33 - GET /index.php?server_id=1&channel_id=6 - POST: []
|
||||||
2026-02-16 20:29:40 - GET /index.php?server_id=1&channel_id=6 - POST: []
|
2026-02-16 20:29:40 - GET /index.php?server_id=1&channel_id=6 - POST: []
|
||||||
|
2026-02-16 20:35:04 - GET /?fl_project=38443 - POST: []
|
||||||
|
2026-02-16 20:49:01 - GET /index.php?server_id=1&channel_id=6 - POST: []
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user