diff --git a/index.php b/index.php new file mode 100644 index 0000000..4724ed8 --- /dev/null +++ b/index.php @@ -0,0 +1,1027 @@ + + + + + + + WEBGIS— Peta Interaktif + + + + + + + + + + + + +
+ + + + +
+
+ + +
+ + +
+ ✏️ Klik pada peta untuk mulai menggambar. Dobel-klik untuk selesai. +    +
+ + + + + + + + \ No newline at end of file diff --git a/koneksi.php b/koneksi.php new file mode 100644 index 0000000..e1dceb5 --- /dev/null +++ b/koneksi.php @@ -0,0 +1,14 @@ +set_charset('utf8mb4'); + +if ($conn->connect_error) { + http_response_code(500); + die(json_encode(['status' => 'error', 'message' => 'Koneksi gagal: ' . $conn->connect_error])); +} \ No newline at end of file diff --git a/proses.php b/proses.php new file mode 100644 index 0000000..1fb6f2d --- /dev/null +++ b/proses.php @@ -0,0 +1,178 @@ + 'error', 'message' => 'Nama wajib diisi!']); + exit; + } + $jenis_valid = ['marker', 'polyline', 'polygon']; + if (!in_array($jenis, $jenis_valid)) { + echo json_encode(['status' => 'error', 'message' => 'Jenis geometri tidak valid!']); + exit; + } + // Validasi JSON koordinat + $koord_test = json_decode($koord, true); + if ($koord_test === null) { + echo json_encode(['status' => 'error', 'message' => 'Koordinat tidak valid!']); + exit; + } + + $stmt = $conn->prepare( + "INSERT INTO geometri_sigma (nama_objek, no_wa, buka_24jam, jenis_geometri, koordinat) VALUES (?, ?, ?, ?, ?)" + ); + $stmt->bind_param('sssss', $nama, $wa, $jam, $jenis, $koord); + + if ($stmt->execute()) { + echo json_encode(['status' => 'ok', 'id' => $stmt->insert_id, 'message' => 'Data berhasil disimpan!']); + } else { + echo json_encode(['status' => 'error', 'message' => 'Gagal menyimpan: ' . $stmt->error]); + } + $stmt->close(); + exit; +} + +// ============================================================ +// READ — Ambil semua data (untuk reload tanpa refresh halaman) +// ============================================================ +if ($aksi === 'baca') { + $result = $conn->query("SELECT * FROM geometri_sigma ORDER BY created_at DESC"); + $data = []; + while ($row = $result->fetch_assoc()) { + $data[] = $row; + } + echo json_encode(['status' => 'ok', 'data' => $data]); + exit; +} + +// ============================================================ +// READ SINGLE — Ambil satu data berdasarkan ID +// ============================================================ +if ($aksi === 'detail') { + $id = intval($_GET['id'] ?? 0); + $stmt = $conn->prepare("SELECT * FROM geometri_sigma WHERE id = ?"); + $stmt->bind_param('i', $id); + $stmt->execute(); + $row = $stmt->get_result()->fetch_assoc(); + if ($row) { + echo json_encode(['status' => 'ok', 'data' => $row]); + } else { + echo json_encode(['status' => 'error', 'message' => 'Data tidak ditemukan']); + } + $stmt->close(); + exit; +} + +// ============================================================ +// UPDATE — Perbarui data & koordinat +// ============================================================ +if ($aksi === 'update') { + $id = intval($_POST['id'] ?? 0); + $nama = bersih($_POST['nama'] ?? ''); + $wa = bersih($_POST['wa'] ?? ''); + $jam = ($_POST['jam'] ?? 'Tidak') === 'Ya' ? 'Ya' : 'Tidak'; + $koord = $_POST['koordinat'] ?? ''; + + if (!$id || !$nama) { + echo json_encode(['status' => 'error', 'message' => 'ID dan Nama wajib ada!']); + exit; + } + + $fields = "nama_objek=?, no_wa=?, buka_24jam=?"; + $params = [$nama, $wa, $jam]; + $types = 'sss'; + + // Update koordinat jika dikirim (drag marker / edit polyline/polygon) + if ($koord) { + $koord_test = json_decode($koord, true); + if ($koord_test !== null) { + $fields .= ", koordinat=?"; + $params[] = $koord; + $types .= 's'; + } + } + + $params[] = $id; + $types .= 'i'; + + $stmt = $conn->prepare("UPDATE geometri_sigma SET $fields WHERE id = ?"); + $stmt->bind_param($types, ...$params); + + if ($stmt->execute()) { + echo json_encode(['status' => 'ok', 'message' => 'Data berhasil diperbarui!']); + } else { + echo json_encode(['status' => 'error', 'message' => 'Gagal update: ' . $stmt->error]); + } + $stmt->close(); + exit; +} + +// ============================================================ +// UPDATE KOORDINAT SAJA — khusus drag marker +// ============================================================ +if ($aksi === 'update_koord') { + $id = intval($_POST['id'] ?? 0); + $koord = $_POST['koordinat'] ?? ''; + + if (!$id || !$koord) { + echo json_encode(['status' => 'error', 'message' => 'ID dan koordinat wajib ada!']); + exit; + } + + $stmt = $conn->prepare("UPDATE geometri_sigma SET koordinat=? WHERE id=?"); + $stmt->bind_param('si', $koord, $id); + if ($stmt->execute()) { + echo json_encode(['status' => 'ok', 'message' => 'Koordinat diperbarui!']); + } else { + echo json_encode(['status' => 'error', 'message' => 'Gagal: ' . $stmt->error]); + } + $stmt->close(); + exit; +} + +// ============================================================ +// DELETE — Hapus berdasarkan ID +// ============================================================ +if ($aksi === 'hapus') { + $id = intval($_POST['id'] ?? $_GET['id'] ?? 0); + if (!$id) { + echo json_encode(['status' => 'error', 'message' => 'ID tidak valid!']); + exit; + } + + $stmt = $conn->prepare("DELETE FROM geometri_sigma WHERE id=?"); + $stmt->bind_param('i', $id); + if ($stmt->execute()) { + echo json_encode(['status' => 'ok', 'message' => 'Data berhasil dihapus!']); + } else { + echo json_encode(['status' => 'error', 'message' => 'Gagal hapus: ' . $stmt->error]); + } + $stmt->close(); + exit; +} + +// ── Default: aksi tidak dikenali ───────────────────── +echo json_encode(['status' => 'error', 'message' => "Aksi '$aksi' tidak dikenali."]); \ No newline at end of file