DARK LIGHT
This commit is contained in:
parent
5b5ac99cae
commit
c0b4015a24
@ -1,4 +1,6 @@
|
||||
<?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';
|
||||
header('Content-Type: application/json');
|
||||
|
||||
@ -9,18 +11,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
exit;
|
||||
}
|
||||
|
||||
$username = $_POST['username'] ?? $user['username'];
|
||||
$avatar_url = $_POST['avatar_url'] ?? $user['avatar_url'];
|
||||
$username = !empty($_POST['username']) ? $_POST['username'] : $user['username'];
|
||||
$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);
|
||||
$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 {
|
||||
$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']]);
|
||||
|
||||
$_SESSION['username'] = $username; // Update session if stored (though getCurrentUser fetches from DB)
|
||||
|
||||
echo json_encode(['success' => true]);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||
|
||||
@ -79,6 +79,16 @@
|
||||
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 {
|
||||
background-color: var(--blurple) !important;
|
||||
border-color: var(--blurple) !important;
|
||||
|
||||
@ -2231,22 +2231,38 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const saveSettingsBtn = document.getElementById('save-settings-btn');
|
||||
saveSettingsBtn?.addEventListener('click', async () => {
|
||||
const form = document.getElementById('user-settings-form');
|
||||
if (!form) return;
|
||||
|
||||
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);
|
||||
|
||||
const resp = await fetch('api_v1_user.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
const result = await resp.json();
|
||||
if (result.success) {
|
||||
location.reload();
|
||||
} else {
|
||||
alert(result.error || 'Failed to save settings');
|
||||
try {
|
||||
const resp = await fetch('api_v1_user.php?v=' + Date.now(), {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
const result = await resp.json();
|
||||
if (result.success) {
|
||||
window.location.href = window.location.pathname + window.location.search;
|
||||
} 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>
|
||||
</head>
|
||||
<body data-theme="<?php echo htmlspecialchars($user['theme'] ?? 'dark'); ?>">
|
||||
<body data-theme="<?php echo htmlspecialchars($user['theme'] ?: 'dark'); ?>">
|
||||
|
||||
<div class="discord-app">
|
||||
<!-- 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>
|
||||
<div class="form-text text-muted" style="font-size: 0.8em;">Play a sound when you are mentioned.</div>
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<label class="form-label text-white d-block" style="font-size: 0.9em;">Appearance</label>
|
||||
<div class="btn-group w-100" role="group">
|
||||
<input type="radio" class="btn-check" name="theme" id="theme-dark" value="dark" <?php echo ($user['theme'] ?? 'dark') == 'dark' ? 'checked' : ''; ?>>
|
||||
<label class="btn btn-outline-secondary btn-sm" for="theme-dark">Dark</label>
|
||||
<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 btn-sm" for="theme-light">Light</label>
|
||||
<div class="mb-3">
|
||||
<label class="form-label text-uppercase fw-bold" style="font-size: 0.7em; color: var(--text-muted);">Appearance</label>
|
||||
<div class="row g-2">
|
||||
<div class="col-6">
|
||||
<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')">
|
||||
<label class="btn btn-outline-secondary w-100 py-3" for="theme-dark">
|
||||
<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>
|
||||
|
||||
@ -301,3 +301,5 @@
|
||||
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: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