feat(landing-page):penambahan landing page utama pdemisah antar fitur

This commit is contained in:
2026-06-11 09:58:07 +07:00
parent 6b7fa7e467
commit d78ee0a79e
35 changed files with 5007 additions and 4753 deletions
+39
View File
@@ -0,0 +1,39 @@
<?php
header('Content-Type: application/json');
ini_set('display_errors', '0');
include __DIR__ . '/../../db_config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$id = (int)($_POST['id'] ?? 0);
if ($id <= 0) {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'ID jalan tidak valid']);
$conn->close();
exit;
}
$stmt = $conn->prepare("DELETE FROM spatial_features WHERE id = ?");
if (!$stmt) {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $conn->error]);
$conn->close();
exit;
}
$stmt->bind_param("i", $id);
if ($stmt->execute()) {
echo json_encode(['status' => 'success', 'message' => 'Data jalan berhasil dihapus']);
} else {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $stmt->error]);
}
$stmt->close();
$conn->close();
exit;
}
http_response_code(405);
echo json_encode(['status' => 'error', 'message' => 'Method tidak diizinkan']);
$conn->close();
?>
+52
View File
@@ -0,0 +1,52 @@
<?php
header('Content-Type: application/json');
include __DIR__ . '/../../db_config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$id = (int)($_POST['id'] ?? 0);
if ($id <= 0) {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'ID laporan tidak valid']);
$conn->close();
exit;
}
// Optional: Get file path and delete physical image file
$stmtSelect = $conn->prepare('SELECT gambar FROM jalan_rusak WHERE id = ?');
if ($stmtSelect) {
$stmtSelect->bind_param('i', $id);
$stmtSelect->execute();
$stmtSelect->bind_result($gambar);
if ($stmtSelect->fetch()) {
if ($gambar && file_exists(__DIR__ . '/../../' . $gambar)) {
@unlink(__DIR__ . '/../../' . $gambar);
}
}
$stmtSelect->close();
}
$stmt = $conn->prepare('DELETE FROM jalan_rusak WHERE id = ?');
if (!$stmt) {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $conn->error]);
$conn->close();
exit;
}
$stmt->bind_param('i', $id);
if ($stmt->execute()) {
echo json_encode(['status' => 'success', 'message' => 'Laporan jalan rusak berhasil dihapus']);
} else {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $stmt->error]);
}
$stmt->close();
$conn->close();
exit;
}
http_response_code(405);
echo json_encode(['status' => 'error', 'message' => 'Method tidak diizinkan']);
$conn->close();
?>
+30
View File
@@ -0,0 +1,30 @@
<?php
header('Content-Type: application/json');
include __DIR__ . '/../../db_config.php';
$sql = "SELECT id, nama_objek, kategori, status_objek, type, geometry_data, nilai_ukur, created_at
FROM spatial_features
WHERE kategori IN ('Jalan', 'Jalan Raya')
ORDER BY created_at DESC";
$result = $conn->query($sql);
$features = [];
if (!$result) {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => 'Query gagal: ' . $conn->error]);
$conn->close();
exit;
}
if ($result && $result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$row['geometry_data'] = json_decode($row['geometry_data']);
$row['nilai_ukur'] = (float)$row['nilai_ukur'];
$features[] = $row;
}
}
echo json_encode($features);
$conn->close();
?>
+29
View File
@@ -0,0 +1,29 @@
<?php
header('Content-Type: application/json');
include __DIR__ . '/../../db_config.php';
$sql = "SELECT id, latitude, longitude, jenis_kerusakan, deskripsi, severity, gambar, created_at
FROM jalan_rusak
ORDER BY created_at DESC";
$result = $conn->query($sql);
$data = [];
if (!$result) {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => 'Query gagal: ' . $conn->error]);
$conn->close();
exit;
}
if ($result && $result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$row['latitude'] = (float)$row['latitude'];
$row['longitude'] = (float)$row['longitude'];
$data[] = $row;
}
}
echo json_encode($data);
$conn->close();
?>
+45
View File
@@ -0,0 +1,45 @@
<?php
header('Content-Type: application/json');
ini_set('display_errors', '0');
include __DIR__ . '/../../db_config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$nama = trim($_POST['nama'] ?? '');
$kategori = 'Jalan';
$status = trim($_POST['status'] ?? 'Jalan Kabupaten');
$type = trim($_POST['type'] ?? 'polyline');
$geometry = $_POST['geometry'] ?? '';
$nilai = (float)($_POST['nilai'] ?? 0);
if ($nama === '' || $geometry === '') {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Data jalan tidak lengkap']);
$conn->close();
exit;
}
$stmt = $conn->prepare("INSERT INTO spatial_features (nama_objek, kategori, status_objek, type, geometry_data, nilai_ukur) VALUES (?, ?, ?, ?, ?, ?)");
if (!$stmt) {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $conn->error]);
$conn->close();
exit;
}
$stmt->bind_param("sssssd", $nama, $kategori, $status, $type, $geometry, $nilai);
if ($stmt->execute()) {
echo json_encode(['status' => 'success', 'message' => 'Data jalan berhasil disimpan']);
} else {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $stmt->error]);
}
$stmt->close();
$conn->close();
exit;
}
http_response_code(405);
echo json_encode(['status' => 'error', 'message' => 'Method tidak diizinkan']);
$conn->close();
?>
+72
View File
@@ -0,0 +1,72 @@
<?php
header('Content-Type: application/json');
include __DIR__ . '/../../db_config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$latitude = $_POST['latitude'] ?? '';
$longitude = $_POST['longitude'] ?? '';
$jenis_kerusakan = $_POST['jenis_kerusakan'] ?? '';
$deskripsi = $_POST['deskripsi'] ?? '';
$severity = $_POST['severity'] ?? 'sedang';
if (empty($latitude) || empty($longitude) || empty($jenis_kerusakan)) {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Latitude, longitude, dan jenis kerusakan wajib diisi']);
exit;
}
$gambar = null;
// Handle file upload
if (isset($_FILES['gambar']) && $_FILES['gambar']['error'] === UPLOAD_ERR_OK) {
$allowed = ['jpg', 'jpeg', 'png', 'gif'];
$filename = $_FILES['gambar']['name'];
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
if (!in_array($ext, $allowed)) {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Format gambar hanya JPG, PNG, GIF']);
exit;
}
// Buat folder uploads di root jika belum ada
if (!is_dir(__DIR__ . '/../../uploads')) {
mkdir(__DIR__ . '/../../uploads', 0755, true);
}
// Generate nama file unik
$gambar = 'uploads/' . time() . '_' . basename($filename);
if (!move_uploaded_file($_FILES['gambar']['tmp_name'], __DIR__ . '/../../' . $gambar)) {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => 'Gagal upload gambar']);
exit;
}
}
$stmt = $conn->prepare("INSERT INTO jalan_rusak (latitude, longitude, jenis_kerusakan, deskripsi, severity, gambar) VALUES (?, ?, ?, ?, ?, ?)");
if (!$stmt) {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $conn->error]);
exit;
}
$stmt->bind_param("ddssss", $latitude, $longitude, $jenis_kerusakan, $deskripsi, $severity, $gambar);
if ($stmt->execute()) {
echo json_encode(['status' => 'success', 'message' => 'Laporan jalan rusak berhasil disimpan', 'id' => $stmt->insert_id]);
} else {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $stmt->error]);
}
$stmt->close();
$conn->close();
exit;
}
http_response_code(405);
echo json_encode(['status' => 'error', 'message' => 'Method tidak diizinkan']);
$conn->close();
?>
+66
View File
@@ -0,0 +1,66 @@
<?php
header('Content-Type: application/json');
ini_set('display_errors', '0');
include __DIR__ . '/../../db_config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$id = (int)($_POST['id'] ?? 0);
if ($id <= 0) {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'ID jalan tidak valid']);
$conn->close();
exit;
}
$isGeometryUpdate = isset($_POST['geometry']);
if ($isGeometryUpdate) {
$geometry = $_POST['geometry'] ?? '';
$nilai = (float)($_POST['nilai'] ?? 0);
if ($geometry === '') {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Data geometri kosong']);
$conn->close();
exit;
}
$stmt = $conn->prepare("UPDATE spatial_features SET geometry_data = ?, nilai_ukur = ? WHERE id = ?");
$stmt->bind_param("sdi", $geometry, $nilai, $id);
} else {
$nama = trim($_POST['nama'] ?? '');
$status = trim($_POST['status'] ?? '');
if ($nama === '' || $status === '') {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Nama atau status tidak boleh kosong']);
$conn->close();
exit;
}
$stmt = $conn->prepare("UPDATE spatial_features SET nama_objek = ?, status_objek = ? WHERE id = ?");
$stmt->bind_param("ssi", $nama, $status, $id);
}
if (!$stmt) {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $conn->error]);
$conn->close();
exit;
}
if ($stmt->execute()) {
echo json_encode(['status' => 'success', 'message' => 'Data jalan berhasil diperbarui']);
} else {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $stmt->error]);
}
$stmt->close();
$conn->close();
exit;
}
http_response_code(405);
echo json_encode(['status' => 'error', 'message' => 'Method tidak diizinkan']);
$conn->close();
?>