-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme.alg.php
More file actions
64 lines (48 loc) · 1.59 KB
/
theme.alg.php
File metadata and controls
64 lines (48 loc) · 1.59 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
60
61
62
63
64
<?php
declare(strict_types=1);
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if(!isset ($_SESSION['adminLoged']))
{
header('Location: ../panel.login.php');
exit();
}
function updateUserTheme($newTheme): void {
require '../panel.connect.php';
$conn = new mysqli($host, $db_user, $db_password, $db_name);
if ($conn->connect_errno) {
$_SESSION['message'] = 'Connection failed: '.$conn->connect_error;
header('Location: ../panel.php?window=themes');
exit();
}
$query = "UPDATE `settings` SET `value` = ? WHERE `name` = 'active_theme'";
$stmt = $conn->prepare($query);
if (!$stmt) {
$_SESSION['message'] = 'Error prep query: '.$conn->error;
header('Location: ../panel.php?window=themes');
exit();
}
$stmt->bind_param("s", $newTheme);
if (!$stmt->execute()) {
$_SESSION['message'] = 'Error during query: '.$stmt->error;
header('Location: ../panel.php?window=themes');
exit();
}
$stmt->close();
$conn->close();
}
include dirname(__DIR__, 2) . '/themes/handlers/index.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['theme'])) {
$newTheme = $_POST['theme'];
if (in_array($newTheme, getAvailableThemes())) {
updateUserTheme($newTheme);
$_SESSION['message'] = 'Theme changed to: '.htmlspecialchars($newTheme);
header('Location: ../panel.php?window=themes');
exit();
} else {
$_SESSION['message'] = 'Invalid theme!';
header('Location: ../panel.php?window=themes');
exit();
}
}