48 lines
1.8 KiB
PHP
48 lines
1.8 KiB
PHP
<?php
|
|
include 'db.php';
|
|
|
|
if (isset($_GET['action']) && $_GET['action'] === 'delete' && isset($_GET['id'])) {
|
|
$id = (int) $_GET['id'];
|
|
$conn->query("DELETE FROM tempat WHERE id = $id");
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
if (isset($_GET['action']) && $_GET['action'] === 'edit' &&
|
|
isset($_GET['id'], $_GET['nama'], $_GET['nomor'], $_GET['status'])) {
|
|
$id = (int) $_GET['id'];
|
|
$nama = $conn->real_escape_string($_GET['nama']);
|
|
$nomor = $conn->real_escape_string($_GET['nomor']);
|
|
$status = $conn->real_escape_string($_GET['status']);
|
|
$conn->query("UPDATE tempat SET nama_tempat='$nama', nomor_tempat='$nomor', status='$status' WHERE id=$id");
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
if (isset($_GET['action']) && $_GET['action'] === 'update_pos' &&
|
|
isset($_GET['id'], $_GET['lat'], $_GET['lng'])) {
|
|
$id = (int) $_GET['id'];
|
|
$lat = (float) $_GET['lat'];
|
|
$lng = (float) $_GET['lng'];
|
|
$result = $conn->query("UPDATE tempat SET latitude='$lat', longitude='$lng' WHERE id=$id");
|
|
header('Content-Type: text/plain');
|
|
echo ($result) ? 'ok' : 'error: ' . $conn->error;
|
|
exit;
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save'])) {
|
|
$nama = $conn->real_escape_string($_POST['nama']);
|
|
$nomor = $conn->real_escape_string($_POST['nomor']);
|
|
$status = $conn->real_escape_string($_POST['status']);
|
|
$lat = (float) $_POST['lat'];
|
|
$lng = (float) $_POST['lng'];
|
|
$sql = "INSERT INTO tempat (nama_tempat, nomor_tempat, status, latitude, longitude)
|
|
VALUES ('$nama','$nomor','$status','$lat','$lng')";
|
|
if ($conn->query($sql)) {
|
|
header('Location: index.php?saved=1');
|
|
exit;
|
|
}
|
|
header('Location: tambah.php?err=' . urlencode($conn->error));
|
|
exit;
|
|
}
|