diff --git a/src/webserver/admin/pois.php b/src/webserver/admin/pois.php index a5bd1da..25840f6 100644 --- a/src/webserver/admin/pois.php +++ b/src/webserver/admin/pois.php @@ -49,28 +49,26 @@ } else { switch ($_REQUEST['action']) { case 'create': - // create POI form -?> -

Create a New Point of Interest

- -
- -

-

-

-

-

-

-

-

-
- -Create a New Point of Interest"; + displayForm(false); + break; + case 'edit': + // edit POI form + echo "

Edit Point of Interest

"; + displayForm(true); 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)'); + // do the insert or update + if (!isset($_POST['id'])) { + // 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)'); + } else { + // update + $stmt = $conn->prepare('UPDATE POIs SET name=:name, description=:description, latitude=:latitude, longitude=:longitude, radius=:radius, is_active=:is_active, map_marker_icon=:map_marker_icon WHERE id = :id'); + if ($stmt) $stmt->bindValue(':id', $_POST['id']); + } if ($stmt) { $stmt->bindValue(':name', $_POST['name'], SQLITE3_TEXT); $stmt->bindValue(':description', $_POST['description'], SQLITE3_TEXT); @@ -80,8 +78,12 @@ $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 "

Record created. < back to Points of Interest

\n"; + if ($result) { + if (isset($_POST['id'])) { + echo "

Record updated. < back to Points of Interest

\n"; + } else { + echo "

Record created. < back to Points of Interest

\n"; + } } else { echo "

OOPS! There was a problem adding the new point of interest!

\n"; } @@ -92,9 +94,6 @@ echo "Name, Latitude, Longitude are required - please go back and try again\n"; } break; - case 'edit': - case 'update': - case 'delete': default: echo "Unknown action: " . $_GET['action']; } @@ -106,4 +105,36 @@ +
+ +prepare('SELECT * FROM POIs WHERE id = :id'); + if ($lookupStmt) { + $lookupStmt->bindValue(':id', $_REQUEST['id']); + $lookupResult = $lookupStmt->execute(); + if ($lookupResult) { + $poi = $lookupResult->fetchArray(); + } + } + echo "

ID: " . $_REQUEST['id'] . "

\n"; + echo "\n"; + } +?> +

/>

+

/>

+

/>

+

/>

+

/>

+

/>

+

/>

+

+
+