Initial Commit: Tugas Semua Pertemuan

This commit is contained in:
2026-06-08 22:49:54 +07:00
commit 51ea70b6ce
51 changed files with 6841 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
DB_HOST=localhost
DB_PORT=3306
DB_NAME=spbu_db
DB_USER=root
DB_PASSWORD=
+2
View File
@@ -0,0 +1,2 @@
/uploads/
.env
+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();
?>
+32
View File
@@ -0,0 +1,32 @@
<?php
function loadEnv($path) {
$env = [];
if (!file_exists($path)) return $env;
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
$line = trim($line);
if ($line === '' || $line[0] === '#') continue;
$parts = explode('=', $line, 2);
if (count($parts) === 2) {
$env[trim($parts[0])] = trim(trim($parts[1]), '"\'');
}
}
return $env;
}
$env = loadEnv(__DIR__ . '/.env');
$conn = mysqli_connect(
$env['DB_HOST'] ?? '127.0.0.1',
$env['DB_USER'] ?? 'root',
$env['DB_PASSWORD'] ?? '',
$env['DB_NAME'] ?? 'db_spbu',
(int)($env['DB_PORT'] ?? 3306)
);
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";
?>
+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();
?>