Initial Commit: Tugas Semua Pertemuan

This commit is contained in:
2026-06-08 22:37:30 +07:00
commit bdfa23b412
50 changed files with 6888 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
CREATE DATABASE db_spbu;
USE db_spbu;
CREATE TABLE spbu (
id INT AUTO_INCREMENT PRIMARY KEY,
nama_spbu VARCHAR(100),
no_spbu VARCHAR(50),
status ENUM('Buka 24 Jam', 'Tidak 24 Jam'),
latitude DOUBLE,
longitude DOUBLE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE jalan (
id INT AUTO_INCREMENT PRIMARY KEY,
nama_jalan VARCHAR(100),
status ENUM('Nasional','Provinsi','Kabupaten'),
panjang DOUBLE,
geojson TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE parsil (
id INT AUTO_INCREMENT PRIMARY KEY,
pemilik VARCHAR(100),
status ENUM('SHM','HGB','HGU','HP'),
luas DOUBLE,
geojson TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS `jalan_rusak` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`deskripsi` TEXT NOT NULL,
`foto` VARCHAR(255) NOT NULL,
`latitude` DOUBLE NOT NULL,
`longitude` DOUBLE NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+19
View File
@@ -0,0 +1,19 @@
<?php
include 'koneksi.php';
if(isset($_POST['id'])){
$id = $_POST['id'];
$stmt = $conn->prepare("DELETE FROM spbu WHERE id=?");
$stmt->bind_param("i", $id);
if($stmt->execute()){
echo "success";
} else {
echo "MYSQL ERROR: " . $stmt->error;
}
$stmt->close();
} else {
echo "ID TIDAK DITEMUKAN";
}
?>
+17
View File
@@ -0,0 +1,17 @@
<?php
include 'koneksi.php';
if(isset($_POST['id'])){
$id = $_POST['id'];
$stmt = $conn->prepare("DELETE FROM jalan WHERE id=?");
$stmt->bind_param("i", $id);
if($stmt->execute()){
echo "success";
} else {
echo "MYSQL ERROR: " . $stmt->error;
}
$stmt->close();
} else {
echo "ID TIDAK DITEMUKAN";
}
?>
+23
View File
@@ -0,0 +1,23 @@
<?php
include 'koneksi.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$id = intval($_POST['id']);
$foto = mysqli_real_escape_string($conn, $_POST['foto']);
// Hapus file foto
$targetDir = "uploads/";
if (!empty($foto) && file_exists($targetDir . $foto)) {
unlink($targetDir . $foto);
}
$query = "DELETE FROM jalan_rusak WHERE id=$id";
if (mysqli_query($conn, $query)) {
echo "success";
} else {
echo "db_error: " . mysqli_error($conn);
}
} else {
echo "invalid_request";
}
?>
+17
View File
@@ -0,0 +1,17 @@
<?php
include 'koneksi.php';
if(isset($_POST['id'])){
$id = $_POST['id'];
$stmt = $conn->prepare("DELETE FROM parsil WHERE id=?");
$stmt->bind_param("i", $id);
if($stmt->execute()){
echo "success";
} else {
echo "MYSQL ERROR: " . $stmt->error;
}
$stmt->close();
} else {
echo "ID TIDAK DITEMUKAN";
}
?>
File diff suppressed because one or more lines are too long
+12
View File
@@ -0,0 +1,12 @@
<?php
include 'koneksi.php';
$result = mysqli_query($conn, "SELECT * FROM jalan");
$data = [];
while($row = mysqli_fetch_assoc($result)){
$data[] = $row;
}
echo json_encode($data);
?>
+10
View File
@@ -0,0 +1,10 @@
<?php
include 'koneksi.php';
$result = mysqli_query($conn, "SELECT * FROM jalan_rusak ORDER BY created_at DESC");
$data = [];
while ($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
header('Content-Type: application/json');
echo json_encode($data);
?>
+12
View File
@@ -0,0 +1,12 @@
<?php
include 'koneksi.php';
$result = mysqli_query($conn, "SELECT * FROM parsil");
$data = [];
while($row = mysqli_fetch_assoc($result)){
$data[] = $row;
}
echo json_encode($data);
?>
+82
View File
@@ -0,0 +1,82 @@
<?php
include 'koneksi.php';
// Baca file GeoJSON
$file = 'geojson/Jaringan_Jalan.json';
if (!file_exists($file)) {
die("❌ File tidak ditemukan!");
}
$json = file_get_contents($file);
$data = json_decode($json, true);
if (!$data || !isset($data['features'])) {
die("❌ Format GeoJSON tidak valid!");
}
// Prepare statement (AMAN)
$stmt = $conn->prepare("
INSERT INTO jalan (nama_jalan, status, panjang, geojson)
VALUES (?, ?, ?, ?)
");
$total = 0;
$success = 0;
$failed = 0;
foreach ($data['features'] as $feature) {
$total++;
// Ambil data dari properties
$nama = $feature['properties']['nama_jalan'] ?? 'Tanpa Nama';
$status = $feature['properties']['status_jal'] ?? 'Kabupaten';
$panjang = $feature['properties']['Plan_Len'] ?? 0;
// Validasi status (biar sesuai ENUM DB)
$allowed_status = ['Nasional', 'Provinsi', 'Kabupaten', 'Kota'];
if (!in_array($status, $allowed_status)) {
$status = 'Kabupaten';
}
// Ambil koordinat
if (!isset($feature['geometry']['coordinates'])) {
$failed++;
continue;
}
$coordinates = $feature['geometry']['coordinates'];
// Convert dari [lng, lat] → [lat, lng]
$geo = [];
foreach ($coordinates as $coord) {
if (count($coord) < 2) continue;
$geo[] = [$coord[1], $coord[0]];
}
if (count($geo) < 2) {
$failed++;
continue;
}
$geojson = json_encode($geo);
// Bind & execute
$stmt->bind_param("ssds", $nama, $status, $panjang, $geojson);
if ($stmt->execute()) {
$success++;
} else {
$failed++;
}
}
$stmt->close();
$conn->close();
// Output hasil
echo "<h2>✅ Import Selesai</h2>";
echo "Total data: $total <br>";
echo "Berhasil: $success <br>";
echo "Gagal: $failed <br>";
?>
File diff suppressed because it is too large Load Diff
+26
View File
@@ -0,0 +1,26 @@
<?php
include 'koneksi.php';
$nama = $_POST['nama'] ?? '';
$no = $_POST['no'] ?? '';
$status = $_POST['status'] ?? '';
$lat = $_POST['lat'] ?? '';
$lng = $_POST['lng'] ?? '';
// VALIDASI
if($nama == "" || $no == "" || $status == "" || $lat == "" || $lng == ""){
echo "DATA TIDAK LENGKAP";
exit;
}
// PREPARED STATEMENT
$stmt = $conn->prepare("INSERT INTO spbu (nama_spbu, no_spbu, status, latitude, longitude) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("sssdd", $nama, $no, $status, $lat, $lng);
if($stmt->execute()){
echo "success";
}else{
echo "MYSQL ERROR: " . $stmt->error;
}
$stmt->close();
?>
+31
View File
@@ -0,0 +1,31 @@
<?php
include 'koneksi.php';
// AMBIL DATA
$nama = $_POST['nama'] ?? '';
$status = $_POST['status'] ?? '';
$panjang = $_POST['panjang'] ?? '';
$geojson = $_POST['geojson'] ?? '';
// VALIDASI DASAR
if($nama == "" || $status == "" || $panjang == "" || $geojson == ""){
echo "DATA TIDAK LENGKAP";
exit;
}
if(strlen($geojson) < 10){
echo "GEOJSON ERROR / TERLALU PENDEK";
exit;
}
// PREPARED STATEMENT (lebih aman dari SQL injection)
$stmt = $conn->prepare("INSERT INTO jalan (nama_jalan, status, panjang, geojson) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssds", $nama, $status, $panjang, $geojson);
if($stmt->execute()){
echo "success";
}else{
echo "MYSQL ERROR: " . $stmt->error;
}
$stmt->close();
?>
+36
View File
@@ -0,0 +1,36 @@
<?php
include 'koneksi.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$deskripsi = mysqli_real_escape_string($conn, $_POST['deskripsi']);
$lat = floatval($_POST['lat']);
$lng = floatval($_POST['lng']);
// Upload foto
$targetDir = "uploads/";
if (!file_exists($targetDir)) {
mkdir($targetDir, 0777, true);
}
$fileName = time() . '_' . basename($_FILES["foto"]["name"]);
$targetFilePath = $targetDir . $fileName;
$fileType = strtolower(pathinfo($targetFilePath, PATHINFO_EXTENSION));
$allowedTypes = array('jpg', 'jpeg', 'png', 'gif');
if (in_array($fileType, $allowedTypes)) {
if (move_uploaded_file($_FILES["foto"]["tmp_name"], $targetFilePath)) {
$query = "INSERT INTO jalan_rusak (deskripsi, foto, latitude, longitude) VALUES ('$deskripsi', '$fileName', $lat, $lng)";
if (mysqli_query($conn, $query)) {
echo "success";
} else {
echo "db_error: " . mysqli_error($conn);
}
} else {
echo "upload_failed";
}
} else {
echo "invalid_format";
}
} else {
echo "invalid_request";
}
?>
+25
View File
@@ -0,0 +1,25 @@
<?php
include 'koneksi.php';
$pemilik = $_POST['pemilik'] ?? '';
$status = $_POST['status'] ?? '';
$luas = $_POST['luas'] ?? '';
$geojson = $_POST['geojson'] ?? '';
// VALIDASI
if($pemilik == "" || $status == "" || $luas == "" || $geojson == ""){
echo "DATA TIDAK LENGKAP";
exit;
}
// PREPARED STATEMENT
$stmt = $conn->prepare("INSERT INTO parsil (pemilik, status, luas, geojson) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssds", $pemilik, $status, $luas, $geojson);
if($stmt->execute()){
echo "success";
}else{
echo "MYSQL ERROR: " . $stmt->error;
}
$stmt->close();
?>
+7
View File
@@ -0,0 +1,7 @@
<?php
$conn = mysqli_connect("127.0.0.1", "root", "", "db_spbu", 3307);
if (!$conn) {
die("Koneksi gagal: " . mysqli_connect_error());
}
?>
+11
View File
@@ -0,0 +1,11 @@
<?php
include 'koneksi.php';
$type = $_POST['type'];
$coords = $_POST['coords'];
mysqli_query($conn, "INSERT INTO shapes (type, coordinates)
VALUES ('$type','$coords')");
echo "success";
?>
+80
View File
@@ -0,0 +1,80 @@
<!DOCTYPE html>
<html lang="en">
<head>
<base target="_top">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Quick Start - Leaflet</title>
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<style>
html, body {
height: 100%;
margin: 0;
}
.leaflet-container {
height: 400px;
width: 600px;
max-width: 100%;
max-height: 100%;
}
</style>
</head>
<body>
<div id="map" style="width: 600px; height: 400px;"></div>
<script>
const map = L.map('map').setView([-0.05559005, 109.3486106], 17);
const tiles = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
const marker = L.marker([-0.05559005, 109.3486106]).addTo(map)
.bindPopup('<b>Hello world!</b><br />I am a popup.').openPopup();
const circle = L.circle([-0.051928, 109.358382], {
color: 'red',
fillColor: '#f03',
fillOpacity: 0.5,
radius: 500
}).addTo(map).bindPopup('I am a circle.');
const polygon = L.polygon([
[-0.056026, 109.356301],
[-0.0474, 109.357696],
[-0.054975, 109.361751]
]).addTo(map).bindPopup('I am a polygon.');
const popup = L.popup()
.setLatLng([-0.05559005, 109.3486106])
.setContent('I am a standalone popup.')
.openOn(map);
function onMapClick(e) {
popup
.setLatLng(e.latlng)
.setContent(`You clicked the map at ${e.latlng.toString()}`)
.openOn(map);
}
map.on('click', onMapClick);
</script>
</body>
</html>
+22
View File
@@ -0,0 +1,22 @@
<?php
include 'koneksi.php';
$id = $_POST['id'] ?? '';
$lat = $_POST['lat'] ?? '';
$lng = $_POST['lng'] ?? '';
if($id == "" || $lat == "" || $lng == ""){
echo "DATA TIDAK LENGKAP";
exit;
}
$stmt = $conn->prepare("UPDATE spbu SET latitude=?, longitude=? WHERE id=?");
$stmt->bind_param("ddi", $lat, $lng, $id);
if($stmt->execute()){
echo "OK";
}else{
echo "MYSQL ERROR: " . $stmt->error;
}
$stmt->close();
?>
+23
View File
@@ -0,0 +1,23 @@
<?php
include 'koneksi.php';
$id = $_POST['id'] ?? '';
$nama = $_POST['nama'] ?? '';
$no = $_POST['no'] ?? '';
$status = $_POST['status'] ?? '';
if($id == "" || $nama == "" || $no == "" || $status == ""){
echo "DATA TIDAK LENGKAP";
exit;
}
$stmt = $conn->prepare("UPDATE spbu SET nama_spbu=?, no_spbu=?, status=? WHERE id=?");
$stmt->bind_param("sssi", $nama, $no, $status, $id);
if($stmt->execute()){
echo "success";
}else{
echo "MYSQL ERROR: " . $stmt->error;
}
$stmt->close();
?>
+21
View File
@@ -0,0 +1,21 @@
<?php
include 'koneksi.php';
$id = $_POST['id'] ?? '';
$nama = $_POST['nama'] ?? '';
$status = $_POST['status'] ?? '';
if($id == "" || $nama == "" || $status == ""){
echo "DATA TIDAK LENGKAP";
exit;
}
$stmt = $conn->prepare("UPDATE jalan SET nama_jalan=?, status=? WHERE id=?");
$stmt->bind_param("ssi", $nama, $status, $id);
if($stmt->execute()){
echo "success";
} else {
echo "MYSQL ERROR: " . $stmt->error;
}
$stmt->close();
?>
+52
View File
@@ -0,0 +1,52 @@
<?php
include 'koneksi.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$id = intval($_POST['id']);
$deskripsi = mysqli_real_escape_string($conn, $_POST['deskripsi']);
$fotoLama = mysqli_real_escape_string($conn, $_POST['foto_lama']);
// Jika ada upload foto baru
if (isset($_FILES['foto']) && $_FILES['foto']['error'] === UPLOAD_ERR_OK) {
$targetDir = "uploads/";
$fileName = time() . '_' . basename($_FILES["foto"]["name"]);
$targetFilePath = $targetDir . $fileName;
$fileType = strtolower(pathinfo($targetFilePath, PATHINFO_EXTENSION));
$allowedTypes = array('jpg', 'jpeg', 'png', 'gif');
if (in_array($fileType, $allowedTypes)) {
if (move_uploaded_file($_FILES["foto"]["tmp_name"], $targetFilePath)) {
// Hapus foto lama jika ada
if (!empty($fotoLama) && file_exists($targetDir . $fotoLama)) {
unlink($targetDir . $fotoLama);
}
$query = "UPDATE jalan_rusak SET deskripsi='$deskripsi', foto='$fileName' WHERE id=$id";
} else {
echo "upload_failed";
exit;
}
} else {
echo "invalid_format";
exit;
}
} else {
// Update tanpa ganti foto
$query = "UPDATE jalan_rusak SET deskripsi='$deskripsi' WHERE id=$id";
}
// Juga bisa update posisi jika dikirim dari drag marker
if (isset($_POST['lat']) && isset($_POST['lng'])) {
$lat = floatval($_POST['lat']);
$lng = floatval($_POST['lng']);
$query = "UPDATE jalan_rusak SET deskripsi='$deskripsi', latitude=$lat, longitude=$lng" . (isset($fileName) ? ", foto='$fileName'" : "") . " WHERE id=$id";
}
if (mysqli_query($conn, $query)) {
echo "success";
} else {
echo "db_error: " . mysqli_error($conn);
}
} else {
echo "invalid_request";
}
?>
+21
View File
@@ -0,0 +1,21 @@
<?php
include 'koneksi.php';
$id = $_POST['id'] ?? '';
$pemilik = $_POST['pemilik'] ?? '';
$status = $_POST['status'] ?? '';
if($id == "" || $pemilik == "" || $status == ""){
echo "DATA TIDAK LENGKAP";
exit;
}
$stmt = $conn->prepare("UPDATE parsil SET pemilik=?, status=? WHERE id=?");
$stmt->bind_param("ssi", $pemilik, $status, $id);
if($stmt->execute()){
echo "success";
} else {
echo "MYSQL ERROR: " . $stmt->error;
}
$stmt->close();
?>
Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB