-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_element.php
More file actions
118 lines (99 loc) · 3.86 KB
/
add_element.php
File metadata and controls
118 lines (99 loc) · 3.86 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
<?php
session_start();
require_once __DIR__ . '/includes/Auth.php';
require_once __DIR__ . '/includes/Database.php';
if (!isset($_SESSION['username'])) {
header('Location: login.php');
exit;
}
$pdo = Database::connect();
$id_geosite = $_GET['id_geosite'] ?? null;
if (!$id_geosite) {
die("No id of geosite.");
}
// Fetch geosite data
$stmt = $pdo->prepare("SELECT * FROM geosites WHERE fid = ?");
$stmt->execute([$id_geosite]);
$geosite = $stmt->fetch();
if (!$geosite) {
die("Geosite does not exist.");
}
// Fetch ENUM velue
function getEnumValues(PDO $pdo, string $table, string $column): array {
$stmt = $pdo->query("SHOW COLUMNS FROM `$table` LIKE '$column'");
$row = $stmt->fetch();
if (!$row) return [];
preg_match_all("/'([^']+)'/", $row['Type'], $matches);
return $matches[1];
}
// Fetch ENUM values for 'type' and 'scale'
$type_options = getEnumValues($pdo, 'elements', 'type');
$scale_options = getEnumValues($pdo, 'elements', 'scale');
?>
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/style.css">
<title>Add geodiversity element to: <?= htmlspecialchars($geosite['name']) ?></title>
</head>
<body>
<div class="page-container">
<h1>Add geodiversity element to geosite: <?= htmlspecialchars($geosite['name']) ?></h1>
<form action="save_element.php" method="post" class="form-box responsive-form">
<input type="hidden" name="id_geosite" value="<?= $id_geosite ?>">
<div class="form-grid">
<div class="form-group">
<label for="type">Spatial type</label>
<select name="type" id="type" required>
<?php foreach ($type_options as $option): ?>
<option value="<?= htmlspecialchars($option) ?>"><?= htmlspecialchars(ucfirst($option)) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="scale">Scale</label>
<select name="scale" id="scale">
<?php foreach ($scale_options as $option): ?>
<option value="<?= htmlspecialchars($option) ?>"><?= htmlspecialchars(ucfirst($option)) ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<fieldset class="classification">
<legend>Relevance</legend>
<label class="class-option">
<input type="checkbox" name="abiotic" value="1" checked>
Abiotic
</label>
<label class="class-option">
<input type="checkbox" name="biotic" value="1">
Biotic
</label>
<label class="class-option">
<input type="checkbox" name="cultural" value="1">
Cultural
</label>
</fieldset>
<div class="form-grid">
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" id="name">
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea name="description" id="description"></textarea>
</div>
</div>
<div class="form-group full-width">
<label for="geometry">GeoJSON</label>
<textarea name="geometry" id="geometry" rows="5" placeholder='{"type":"Point","coordinates":[...]}'></textarea>
</div>
<div class="form-actions">
<button type="submit" class="btn-link">💾 Save element</button>
<a href="geosite.php?fid=<?= $id_geosite ?>" class="btn-link">⬅ Return</a>
</div>
</form>
</div>
</body>
</html>