-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_theme.php
More file actions
124 lines (105 loc) · 4.26 KB
/
add_theme.php
File metadata and controls
124 lines (105 loc) · 4.26 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
session_start();
require_once __DIR__ . '/includes/Auth.php';
require_once __DIR__ . '/includes/Database.php';
if (!isset($_SESSION['username'])) {
header("Location: login.php");
exit;
}
$id_element = isset($_GET['id_element']) ? intval($_GET['id_element']) : 0;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$id_element = intval($_POST['id_element']);
$theme_process = trim($_POST['theme_process']);
$feature_name = trim($_POST['feature_name']);
$description = trim($_POST['description']);
try {
$pdo = Database::connect();
$stmt = $pdo->prepare("
INSERT INTO themes (id_element, theme_process, feature_name, description)
VALUES (?, ?, ?, ?)
");
$stmt->execute([$id_element, $theme_process, $feature_name, $description]);
$theme_id = $pdo->lastInsertId();
// Save categories
if (!empty($_POST['classes'])) {
$stmt = $pdo->prepare("INSERT INTO element_classes (theme_id, class_id) VALUES (?, ?)");
foreach ($_POST['classes'] as $class_id) {
$stmt->execute([$theme_id, $class_id]);
}
}
header("Location: geosite.php?fid=" . intval($_GET['fid']));
exit;
} catch (Exception $e) {
$error = "An error occured when adding theme: " . $e->getMessage();
}
}
?>
<?php
// Fetch geodiversity classifications
$pdo = Database::connect();
$stmt = $pdo->query("SELECT * FROM classifications");
$classifications = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Fetch categories of individual classifications
$stmt = $pdo->query("SELECT * FROM classes ORDER BY classification_id, parent_id, name");
$classes = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Parent and child grouping
$classTree = [];
foreach ($classes as $class) {
$classTree[$class['classification_id']][$class['parent_id']][] = $class;
}
// Show classification tree
function renderClassTree($classificationId, $parentId, $classTree, $prefix = '') {
if (!isset($classTree[$classificationId][$parentId])) return;
foreach ($classTree[$classificationId][$parentId] as $class) {
echo '<label class="class-option" style="margin-left:'.(20*($class['level']-1)).'px">';
echo '<input type="checkbox" name="classes[]" value="'.$class['id'].'"> ';
echo htmlspecialchars($class['name']);
echo '</label>';
renderClassTree($classificationId, $class['id'], $classTree, $prefix.'--');
}
}
?>
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/style.css">
<title>Add theme or process</title>
</head>
<body>
<div class="page-container">
<h1>Add theme or process</h1>
<?php if (!empty($error)): ?>
<p style="color:red;"><?= htmlspecialchars($error) ?></p>
<?php endif; ?>
<form method="post" class="form-box responsive-form">
<input type="hidden" name="id_element" value="<?= htmlspecialchars($id_element) ?>">
<div class="form-group">
<label for="theme_process">Process</label>
<input type="text" id="theme_process" name="theme_process" required>
</div>
<div class="form-group">
<label for="feature_name">Feature name</label>
<input type="text" id="feature_name" name="feature_name" required>
</div>
<div class="form-group full-width">
<label for="description">Description</label>
<textarea id="description" name="description" rows="5" required></textarea>
</div>
<h3>Classification</h3>
<?php foreach ($classifications as $classification): ?>
<fieldset class="classification">
<legend><?= htmlspecialchars($classification['name']) ?></legend>
<div class="class-options">
<?php renderClassTree($classification['id'], null, $classTree); ?>
</div>
</fieldset>
<?php endforeach; ?>
<div class="form-actions">
<button type="submit" class="btn-link">➕ Add theme</button>
<a href="javascript:history.back()" class="btn-link">⬅ Return</a>
</div>
</form>
</div>
</body>
</html>