172 lines
8.3 KiB
PHP
172 lines
8.3 KiB
PHP
<?php
|
|
require_once 'config.php';
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$success = '';
|
|
$error = '';
|
|
|
|
$userSettings = getUserSettings($_SESSION['user_id']);
|
|
$notificationSettings = getUserNotificationSettings($_SESSION['user_id']);
|
|
$notificationTypes = [
|
|
1 => ['name' => 'announcement', 'label' => t('system_announcements'), 'description' => t('system_announcements_desc')],
|
|
2 => ['name' => 'tips', 'label' => t('usage_tips'), 'description' => t('usage_tips_desc')],
|
|
3 => ['name' => 'feedback_result', 'label' => t('feedback_results'), 'description' => t('feedback_results_desc')],
|
|
4 => ['name' => 'image_feedback', 'label' => t('image_feedback'), 'description' => t('image_feedback_desc')]
|
|
];
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$dark_mode = isset($_POST['dark_mode']) ? 1 : 0;
|
|
$language = $_POST['language'] ?? 'zh-CN';
|
|
$items_per_page = intval($_POST['items_per_page'] ?? 20);
|
|
$email_notifications = isset($_POST['email_notifications']) ? 1 : 0;
|
|
$browser_notifications = isset($_POST['browser_notifications']) ? 1 : 0;
|
|
|
|
$notification_settings = [];
|
|
foreach ($notificationTypes as $type_id => $type) {
|
|
$notification_settings[$type_id] = isset($_POST['notification_' . $type_id]);
|
|
}
|
|
|
|
if ($items_per_page < 5 || $items_per_page > 100) {
|
|
$error = t('items_per_page_range_error');
|
|
} else {
|
|
$newSettings = [
|
|
'dark_mode' => $dark_mode,
|
|
'language' => $language,
|
|
'items_per_page' => $items_per_page,
|
|
'email_notifications' => $email_notifications,
|
|
'browser_notifications' => $browser_notifications
|
|
];
|
|
|
|
if (updateUserSettings($_SESSION['user_id'], $newSettings) &&
|
|
updateUserNotificationSettings($_SESSION['user_id'], $notification_settings)) {
|
|
$success = t('settings_saved');
|
|
$userSettings = $newSettings;
|
|
$notificationSettings = $notification_settings;
|
|
$_SESSION['language'] = $language;
|
|
} else {
|
|
$error = t('save_failed');
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="<?php echo $lang; ?>" data-theme="<?php echo $userSettings['dark_mode'] ? 'dark' : 'light'; ?>">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?php echo t('settings'); ?> - <?php echo SITE_NAME; ?></title>
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
|
<link rel="stylesheet" href="css/style.css">
|
|
</head>
|
|
<body>
|
|
<?php include 'components/navbar.php'; ?>
|
|
|
|
<div class="container">
|
|
<h1><i class="fas fa-sliders-h"></i> <?php echo t('settings'); ?></h1>
|
|
|
|
<?php if($success): ?>
|
|
<div class="alert alert-success">
|
|
<i class="fas fa-check-circle"></i> <?php echo $success; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if($error): ?>
|
|
<div class="alert alert-error">
|
|
<i class="fas fa-exclamation-triangle"></i> <?php echo $error; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="settings-container">
|
|
<form method="POST" action="">
|
|
<div class="setting-group card">
|
|
<h3><i class="fas fa-palette"></i> <?php echo t('appearance_settings'); ?></h3>
|
|
|
|
<div class="form-group">
|
|
<label class="checkbox-label">
|
|
<input type="checkbox" name="dark_mode" <?php echo $userSettings['dark_mode'] ? 'checked' : ''; ?>>
|
|
<span class="checkmark"></span>
|
|
<i class="fas fa-moon"></i> <?php echo t('enable_dark_mode'); ?>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="setting-group card">
|
|
<h3><i class="fas fa-desktop"></i> <?php echo t('display_settings'); ?></h3>
|
|
|
|
<div class="form-group">
|
|
<label for="items_per_page">
|
|
<i class="fas fa-list"></i> <?php echo t('items_per_page'); ?>
|
|
</label>
|
|
<select id="items_per_page" name="items_per_page">
|
|
<option value="10" <?php echo $userSettings['items_per_page'] == 10 ? 'selected' : ''; ?>>10</option>
|
|
<option value="20" <?php echo $userSettings['items_per_page'] == 20 ? 'selected' : ''; ?>>20</option>
|
|
<option value="30" <?php echo $userSettings['items_per_page'] == 30 ? 'selected' : ''; ?>>30</option>
|
|
<option value="50" <?php echo $userSettings['items_per_page'] == 50 ? 'selected' : ''; ?>>50</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="setting-group card">
|
|
<h3><i class="fas fa-bell"></i> <?php echo t('notification_settings'); ?></h3>
|
|
|
|
<div class="form-group">
|
|
<label class="checkbox-label">
|
|
<input type="checkbox" name="email_notifications" <?php echo $userSettings['email_notifications'] ? 'checked' : ''; ?>>
|
|
<span class="checkmark"></span>
|
|
<i class="fas fa-envelope"></i> <?php echo t('enable_email_notifications'); ?>
|
|
</label>
|
|
<small><?php echo t('email_notifications_desc'); ?></small>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="checkbox-label">
|
|
<input type="checkbox" name="browser_notifications" <?php echo $userSettings['browser_notifications'] ? 'checked' : ''; ?>>
|
|
<span class="checkmark"></span>
|
|
<i class="fas fa-bell"></i> <?php echo t('enable_browser_notifications'); ?>
|
|
</label>
|
|
<small><?php echo t('browser_notifications_desc'); ?></small>
|
|
</div>
|
|
|
|
<div class="notification-types">
|
|
<h4><i class="fas fa-list-alt"></i> <?php echo t('notification_types'); ?></h4>
|
|
<?php foreach($notificationTypes as $type_id => $type): ?>
|
|
<div class="form-group">
|
|
<label class="checkbox-label">
|
|
<input type="checkbox" name="notification_<?php echo $type_id; ?>"
|
|
<?php echo ($notificationSettings[$type['name']] ?? true) ? 'checked' : ''; ?>>
|
|
<span class="checkmark"></span>
|
|
<strong><?php echo $type['label']; ?></strong>
|
|
<br>
|
|
<small style="margin-left: 25px; color: #666;"><?php echo $type['description']; ?></small>
|
|
</label>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="setting-group card">
|
|
<h3><i class="fas fa-language"></i> <?php echo t('language_settings'); ?></h3>
|
|
|
|
<div class="form-group">
|
|
<label for="language">
|
|
<i class="fas fa-globe"></i> <?php echo t('interface_language'); ?>
|
|
</label>
|
|
<select id="language" name="language">
|
|
<option value="zh-CN" <?php echo $userSettings['language'] == 'zh-CN' ? 'selected' : ''; ?>><?php echo t('simplified_chinese'); ?></option>
|
|
<option value="en" <?php echo $userSettings['language'] == 'en' ? 'selected' : ''; ?>><?php echo t('english'); ?></option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary btn-full">
|
|
<i class="fas fa-save"></i> <?php echo t('save_settings'); ?>
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|