This commit is contained in:
2026-05-12 10:16:16 +07:00
parent bae0569701
commit c2efc4414f
37 changed files with 2222 additions and 18 deletions
+3
View File
@@ -0,0 +1,3 @@
<?php
header('Content-Type: application/json');
echo json_encode(['success'=>true,'msg'=>'API placeholder untuk fitur jalan/parsel']);
+46
View File
@@ -0,0 +1,46 @@
<?php
header('Content-Type: application/json');
include __DIR__ . '/../db_config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$id = $_POST['id'] ?? '';
if (empty($id)) {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'ID wajib diisi']);
exit;
}
// Ambil data gambar untuk dihapus
$stmt = $conn->prepare("SELECT gambar FROM jalan_rusak WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
if ($row && $row['gambar'] && file_exists(__DIR__ . '/../' . $row['gambar'])) {
unlink(__DIR__ . '/../' . $row['gambar']);
}
$stmt->close();
// Hapus record
$stmt = $conn->prepare("DELETE FROM jalan_rusak WHERE id = ?");
$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();
?>
+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();
?>
+49
View File
@@ -0,0 +1,49 @@
<!doctype html>
<html lang="id">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Fitur Jalan & Parsel</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.css" />
<style>html,body,#map{height:100%;margin:0} .controls{position:absolute;top:8px;left:8px;z-index:400;background:#fff;padding:6px}</style>
</head>
<body>
<div class="controls">
<label>Tipe Jalan: <select id="tipe"><option value="nasional">Jalan Nasional</option><option value="provinsi">Jalan Provinsi</option><option value="kabupaten">Jalan Kabupaten</option></select></label>
</div>
<div id="map"></div>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.js"></script>
<script src="https://unpkg.com/@turf/turf@6.5.0/turf.min.js"></script>
<script>
const map = L.map('map').setView([-0.03,109.34],13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
const drawnItems = new L.FeatureGroup().addTo(map);
const drawControl = new L.Control.Draw({ edit: { featureGroup: drawnItems } });
map.addControl(drawControl);
function styleByRoad(type){
if(type==='nasional') return {color:'#d62728',weight:5};
if(type==='provinsi') return {color:'#ff7f0e',weight:4};
return {color:'#2ca02c',weight:3};
}
map.on(L.Draw.Event.CREATED, function (e) {
const layer = e.layer;
if (layer instanceof L.Polyline && !(layer instanceof L.Polygon)){
const tipe = document.getElementById('tipe').value;
layer.setStyle(styleByRoad(tipe));
layer.properties = {type:'road', road_type:tipe};
} else if (layer instanceof L.Polygon){
const geo = layer.toGeoJSON();
const area = turf.area(geo); // in square meters
layer.properties = {type:'parsel', luas_m2: Math.round(area)};
layer.bindPopup('Parsel — Luas: '+Math.round(area)+' m²');
}
drawnItems.addLayer(layer);
});
</script>
</body>
</html>
+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 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();
?>