-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmode.php
49 lines (43 loc) · 1.28 KB
/
cmode.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
<?php
include 'config.php';
function getUserPreferredMode($userId, $pdo) {
$stmt = $pdo->prepare('SELECT preferred_mode FROM users WHERE id = ?');
$stmt->execute([$userId]);
$preferredMode = $stmt->fetchColumn();
return $preferredMode;
}
function echoStylesheetTag($preferredMode) {
$stylesheet = '';
switch ($preferredMode) {
case 'dark':
$stylesheet = '/css/dark-mode.css';
break;
case 'blue':
$stylesheet = '/css/blue.css';
break;
case 'nothing':
$stylesheet = '';
break;
case 'opposite':
$stylesheet = '/css/opposite.css';
break;
case 'liberatube':
$stylesheet = '/css/liberatube.css';
break;
case 'nature':
$stylesheet = '/css/green.css';
break;
default:
$stylesheet = '/css/mainsite.css';
}
echo '<link rel="stylesheet" href="' . $stylesheet . '">';
echo '<script>console.log("Preferred Mode:", ' . json_encode($preferredMode) . ');</script>';
}
if (isset($_SESSION['user_id'])) {
$userId = $_SESSION['user_id'];
$preferredMode = getUserPreferredMode($userId, $pdo);
} else {
$preferredMode = 'light';
}
echoStylesheetTag($preferredMode);
?>