initial work on admin/POI functionality - list all and create implemented

This commit is contained in:
Sundog Jones 2024-05-06 12:40:50 -04:00
parent e9a5db769a
commit f51acb42d6

View File

@ -0,0 +1,109 @@
<?php
$db_path = realpath(dirname(__FILE__) . '/../config/db.php');
require_once($db_path);
require_once(realpath(dirname(__FILE__) . '/../header.php'));
?>
<h1>Wander Admin</h1>
<h2>Points of Interest</h2>
<p><a href='./pois.php?action=create'>Create New Point of Interest</a></p>
<?php
if (!isset($_GET['action']) && !isset($_POST['action'])) {
?>
<table border=1>
<tr>
<td>ID</td>
<td>Name</td>
<td>Description</td>
<td>Active?</td>
<td>Latitude</td>
<td>Longitude</td>
<td>Radius</td>
<td>Map Marker</td>
</tr>
<?php
$results = $conn->query('SELECT * FROM POIs');
while ($row = $results->fetchArray()) {
?>
<tr>
<td><a href='./pois.php?action=edit&id=<?= $row['id'] ?>'><?= $row['id'] ?></a></td>
<td><?= $row['name'] ?></td>
<td><?= $row['description'] ?></td>
<td><?= $row['is_active'] ?></td>
<td><?= $row['latitude'] ?></td>
<td><?= $row['longitude'] ?></td>
<td><?= $row['radius'] ?></td>
<td><?= $row['map_marker_icon'] ?></td>
</tr>
<?php
}
?>
</table>
<?php
} else {
switch ($_REQUEST['action']) {
case 'create':
// create POI form
?>
<h3>Create a New Point of Interest</h3>
<form method='POST' action='pois.php'>
<input type='hidden' name='action' value='save' />
<p><label for='name'>Name: </label><input type='text' name='name' /></p>
<p><label for='description'>Description: </label><input type='text' name='description' /></p>
<p><label for='latitude'>Latitude: </label><input type='text' name='latitude' /></p>
<p><label for='longitude'>Longitude: </label><input type='text' name='longitude' /></p>
<p><label for='radius'>Radius: </label><input type='text' name='radius' /></p>
<p><label for='is_active'>Is Active? </label><input type='checkbox' name='is_active' checked /></p>
<p><label for='map_marker_icon'>Map Marker: </label><input type='text' name='map_marker_icon' /></p>
<p><input type='submit' value='Save POI' /></p>
</form>
<?php
break;
case 'save':
if (isset($_POST['name']) && isset($_POST['latitude']) && isset($_POST['longitude']) && isset($_POST['is_active'])) {
// do the insert
$stmt = $conn->prepare('INSERT INTO POIs (name, description, latitude, longitude, radius, is_active, map_marker_icon) VALUES (:name, :description, :latitude, :longitude, :radius, :is_active, :map_marker_icon)');
if ($stmt) {
$stmt->bindValue(':name', $_POST['name'], SQLITE3_TEXT);
$stmt->bindValue(':description', $_POST['description'], SQLITE3_TEXT);
$stmt->bindValue(':latitude', $_POST['latitude'], SQLITE3_FLOAT);
$stmt->bindValue(':longitude', $_POST['longitude'], SQLITE3_FLOAT);
$stmt->bindValue(':radius', empty($_POST['radius']) ? 25 : $_POST['radius']);
$stmt->bindValue(':is_active', $_POST['is_active'] === "on" ? 1 : 0, SQLITE3_INTEGER);
$stmt->bindValue(':map_marker_icon', $_POST['map_marker_icon'], SQLITE3_TEXT);
$result = $stmt->execute();
if ($result) {
echo "<p>Record created. <a href='pois.php'>&lt; back to Points of Interest</a></p>\n";
} else {
echo "<p><strong>OOPS!</strong> There was a problem adding the new point of interest!</p>\n";
}
} else {
echo "<p><strong>OOPS!</strong> There was a problem adding the new point of interest!!</p>\n";
}
} else {
echo "<strong>Name, Latitude, Longitude are required - please go back and try again</strong>\n";
}
break;
case 'edit':
case 'update':
case 'delete':
default:
echo "Unknown action: " . $_GET['action'];
}
}
?>
<p><a href="index.php">&lt; back to Admin</a></p>
<?php
require_once(realpath(dirname(__FILE__) . '/../footer.php'));
?>