-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
187 lines (154 loc) · 7.15 KB
/
admin.php
File metadata and controls
187 lines (154 loc) · 7.15 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?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();
$geosite = null;
if (isset($_GET['id'])) {
$stmt = $pdo->prepare("SELECT * FROM geosites WHERE fid = ?");
$stmt->execute([$_GET['id']]);
$geosite = $stmt->fetch();
}
?>
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<title><?= $geosite ? "Edit" : "Add" ?> geosite / geodiversity site</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="page-container">
<h1><?= $geosite ? "Edit" : "Add" ?> geosite / geodiversity site</h1>
<form id="geosite-form" action="save_geosite.php" method="post" class="form-box responsive-form">
<?php if ($geosite): ?>
<input type="hidden" name="id_geosite" value="<?= htmlspecialchars($geosite['fid']) ?>">
<?php endif; ?>
<div class="form-group">
<label for="name">Name</label>
<input type="text" id="name" name="name" value="<?= htmlspecialchars($geosite['name'] ?? '') ?>" required>
</div>
<div class="form-group form-group-full">
<label for="description">Description</label>
<textarea id="description" name="description" rows="4"><?= htmlspecialchars($geosite['description'] ?? '') ?></textarea>
</div>
<div class="form-group form-group-full">
<label for="property">Property</label>
<textarea id="property" name="property" rows="4"><?= htmlspecialchars($geosite['property'] ?? '') ?></textarea>
</div>
<div class="form-group form-group-full">
<label for="use_limitations">Use limitations</label>
<textarea id="use_limitations" name="use_limitations" rows="4"><?= htmlspecialchars($geosite['use_limitations'] ?? '') ?></textarea>
</div>
<div class="form-group form-group-full">
<label for="access">Access</label>
<textarea id="access" name="access" rows="4"><?= htmlspecialchars($geosite['access'] ?? '') ?></textarea>
</div>
<div class="form-group form-group-full">
<label for="safety">Safety</label>
<textarea id="safety" name="safety" rows="4"><?= htmlspecialchars($geosite['safety'] ?? '') ?></textarea>
</div>
<div class="form-group form-group-full">
<label for="interpretatives">Interpretatives</label>
<textarea id="interpretatives" name="interpretatives" rows="4"><?= htmlspecialchars($geosite['interpretatives'] ?? '') ?></textarea>
</div>
<div class="form-group form-group-full">
<label for="infrastructure">Infrastructure</label>
<textarea id="infrastructure" name="infrastructure" rows="4"><?= htmlspecialchars($geosite['infrastructure'] ?? '') ?></textarea>
</div>
<div class="form-group form-group-full">
<label for="protection_status">Protection</label>
<textarea id="protection_status" name="protection_status" rows="4"><?= htmlspecialchars($geosite['protection_status'] ?? '') ?></textarea>
</div>
<div class="form-group form-group-full">
<label for="fragility">Fragility</label>
<textarea id="fragility" name="fragility" rows="4"><?= htmlspecialchars($geosite['fragility'] ?? '') ?></textarea>
</div>
<div class="form-group form-group-full">
<label for="vulnerability">Vulnerability</label>
<textarea id="vulnerability" name="vulnerability" rows="4"><?= htmlspecialchars($geosite['vulnerability'] ?? '') ?></textarea>
</div>
<div class="form-group">
<label for="x_coordinate">X (Longitude)</label>
<input type="text" id="x_coordinate" name="x_coordinate"
value="<?= htmlspecialchars($geosite['x_coordinate'] ?? '') ?>">
</div>
<div class="form-group">
<label for="y_coordinate">Y (Latitude)</label>
<input type="text" id="y_coordinate" name="y_coordinate"
value="<?= htmlspecialchars($geosite['y_coordinate'] ?? '') ?>">
</div>
<div class="form-group">
<label for="zoom_level">Zoom level</label>
<input type="number" id="zoom_level" name="zoom_level"
value="<?= htmlspecialchars($geosite['zoom_level'] ?? 10) ?>">
</div>
<!-- Map -->
<div class="form-group form-group-full">
<label>Map preview</label>
<div id="map" style="height: 400px; border: 1px solid #ccc; border-radius: 6px;"></div>
</div>
<!-- no data -->
<p id="form-error" style="color: red; display: none; font-weight: bold;">
❗ Locate the site on the map.
</p>
<div class="form-actions">
<button type="submit" class="btn-link">💾 Save</button>
<a href="javascript:history.back()" class="btn-link">⬅ Return</a>
</div>
</form>
</div>
<!-- Leaflet CSS & JS -->
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
// Starting values
let lat = parseFloat(document.getElementById("y_coordinate").value) || 52.0;
let lon = parseFloat(document.getElementById("x_coordinate").value) || 19.0;
let zoom = parseInt(document.getElementById("zoom_level").value) || 6;
// Create map
let map = L.map('map').setView([lat, lon], zoom);
// Add tiles
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
// Marker
let marker = L.marker([lat, lon], {draggable:true}).addTo(map);
// Update field after marker dragging
marker.on('dragend', function(e) {
let pos = marker.getLatLng();
document.getElementById("y_coordinate").value = pos.lat.toFixed(6);
document.getElementById("x_coordinate").value = pos.lng.toFixed(6);
});
// Move marker
map.on('click', function(e) {
marker.setLatLng(e.latlng);
document.getElementById("y_coordinate").value = e.latlng.lat.toFixed(6);
document.getElementById("x_coordinate").value = e.latlng.lng.toFixed(6);
});
// Change zoom level
map.on('zoomend', function() {
document.getElementById("zoom_level").value = map.getZoom();
});
});
</script>
<script>
document.getElementById("geosite-form").addEventListener("submit", function(event) {
const x = document.getElementById("x_coordinate").value.trim();
const y = document.getElementById("y_coordinate").value.trim();
const error = document.getElementById("form-error");
if (!x || !y) {
event.preventDefault();
error.style.display = "block";
} else {
error.style.display = "none";
}
});
</script>
</body>
</html>