From 7759b83638a88f1029c970e686014692fef84126 Mon Sep 17 00:00:00 2001 From: GuavaPopper Date: Tue, 28 Apr 2026 10:08:31 +0700 Subject: [PATCH] Implement reverse geocoding for Rumah Miskin --- .env | 4 + api/config.php | 46 +++ api/delete_ibadah.php | 24 ++ api/delete_miskin.php | 24 ++ api/get_ibadah.php | 12 + api/get_miskin.php | 12 + api/save_ibadah.php | 31 ++ api/save_miskin.php | 40 +++ api/update_ibadah.php | 31 ++ api/update_miskin.php | 31 ++ db.php | 69 +++++ index.html | 164 +++++++++++ init.log | Bin 0 -> 58 bytes pages/data.html | 213 ++++++++++++++ pages/map.html | 662 ++++++++++++++++++++++++++++++++++++++++++ 15 files changed, 1363 insertions(+) create mode 100644 .env create mode 100644 api/config.php create mode 100644 api/delete_ibadah.php create mode 100644 api/delete_miskin.php create mode 100644 api/get_ibadah.php create mode 100644 api/get_miskin.php create mode 100644 api/save_ibadah.php create mode 100644 api/save_miskin.php create mode 100644 api/update_ibadah.php create mode 100644 api/update_miskin.php create mode 100644 db.php create mode 100644 index.html create mode 100644 init.log create mode 100644 pages/data.html create mode 100644 pages/map.html diff --git a/.env b/.env new file mode 100644 index 0000000..c87d42e --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +DB_HOST=127.0.0.1 +DB_NAME=webgis_miskin +DB_USER=root +DB_PASS= diff --git a/api/config.php b/api/config.php new file mode 100644 index 0000000..ebd04ec --- /dev/null +++ b/api/config.php @@ -0,0 +1,46 @@ + false, 'message' => 'File .env tidak ditemukan']); + exit(); +} + +$env = []; +foreach (file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) { + if (strpos(trim($line), '#') === 0 || !strpos($line, '=')) continue; + list($key, $value) = explode('=', $line, 2); + $env[trim($key)] = trim($value); +} + +$host = $env['DB_HOST'] ?? 'localhost'; +$dbname = $env['DB_NAME'] ?? 'webgis_miskin'; +$username = $env['DB_USER'] ?? 'root'; +$password = $env['DB_PASS'] ?? ''; + +// ── KONEKSI PDO ─────────────────────────────────────────────────────────────── +try { + $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password, [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => false, + ]); + + // ── SCHEMA MIGRATION ─────────────────────────────────────────────────────── + // Pastikan kolom 'alamat' ada di tabel 'rumah_miskin' + try { + $pdo->exec("ALTER TABLE rumah_miskin ADD COLUMN alamat TEXT AFTER id_rumah"); + } catch (PDOException $e) { + // Kolom mungkin sudah ada, abaikan error 1060 (Duplicate column name) + } +} catch (PDOException $e) { + http_response_code(500); + header('Content-Type: application/json'); + echo json_encode(['success' => false, 'message' => 'Koneksi database gagal: ' . $e->getMessage()]); + exit(); +} diff --git a/api/delete_ibadah.php b/api/delete_ibadah.php new file mode 100644 index 0000000..fd8d795 --- /dev/null +++ b/api/delete_ibadah.php @@ -0,0 +1,24 @@ + false, 'message' => 'ID tidak ditemukan']); + exit(); +} + +try { + $stmt = $pdo->prepare("DELETE FROM rumah_ibadah WHERE id = ?"); + $stmt->execute([$input['id']]); + + echo json_encode([ + 'success' => true, + 'message' => 'Data Rumah Ibadah berhasil dihapus' + ]); +} catch (PDOException $e) { + http_response_code(500); + echo json_encode(['success' => false, 'message' => $e->getMessage()]); +} diff --git a/api/delete_miskin.php b/api/delete_miskin.php new file mode 100644 index 0000000..c776cc0 --- /dev/null +++ b/api/delete_miskin.php @@ -0,0 +1,24 @@ + false, 'message' => 'ID Rumah tidak ditemukan']); + exit(); +} + +try { + $stmt = $pdo->prepare("DELETE FROM rumah_miskin WHERE id_rumah = ?"); + $stmt->execute([$input['id_rumah']]); + + echo json_encode([ + 'success' => true, + 'message' => 'Data Rumah Miskin berhasil dihapus' + ]); +} catch (PDOException $e) { + http_response_code(500); + echo json_encode(['success' => false, 'message' => $e->getMessage()]); +} diff --git a/api/get_ibadah.php b/api/get_ibadah.php new file mode 100644 index 0000000..2cffac4 --- /dev/null +++ b/api/get_ibadah.php @@ -0,0 +1,12 @@ +query("SELECT * FROM rumah_ibadah ORDER BY created_at DESC"); + $data = $stmt->fetchAll(); + echo json_encode($data); +} catch (PDOException $e) { + http_response_code(500); + echo json_encode(['success' => false, 'message' => $e->getMessage()]); +} diff --git a/api/get_miskin.php b/api/get_miskin.php new file mode 100644 index 0000000..148bb1e --- /dev/null +++ b/api/get_miskin.php @@ -0,0 +1,12 @@ +query("SELECT * FROM rumah_miskin ORDER BY created_at DESC"); + $data = $stmt->fetchAll(); + echo json_encode($data); +} catch (PDOException $e) { + http_response_code(500); + echo json_encode(['success' => false, 'message' => $e->getMessage()]); +} diff --git a/api/save_ibadah.php b/api/save_ibadah.php new file mode 100644 index 0000000..c05546a --- /dev/null +++ b/api/save_ibadah.php @@ -0,0 +1,31 @@ + false, 'message' => 'Data tidak lengkap']); + exit(); +} + +try { + $stmt = $pdo->prepare("INSERT INTO rumah_ibadah (nama, alamat, latitude, longitude, radius) VALUES (?, ?, ?, ?, ?)"); + $stmt->execute([ + $input['nama'], + $input['alamat'] ?? '', + $input['latitude'], + $input['longitude'], + $input['radius'] ?? 500 + ]); + + echo json_encode([ + 'success' => true, + 'id' => $pdo->lastInsertId(), + 'message' => 'Data Rumah Ibadah berhasil disimpan' + ]); +} catch (PDOException $e) { + http_response_code(500); + echo json_encode(['success' => false, 'message' => $e->getMessage()]); +} diff --git a/api/save_miskin.php b/api/save_miskin.php new file mode 100644 index 0000000..d7fd171 --- /dev/null +++ b/api/save_miskin.php @@ -0,0 +1,40 @@ + false, 'message' => 'Data tidak lengkap']); + exit(); +} + +try { + // Check if ID exists + $check = $pdo->prepare("SELECT id_rumah FROM rumah_miskin WHERE id_rumah = ?"); + $check->execute([$input['id_rumah']]); + if ($check->rowCount() > 0) { + http_response_code(400); + echo json_encode(['success' => false, 'message' => 'ID Rumah sudah terdaftar']); + exit(); + } + + $stmt = $pdo->prepare("INSERT INTO rumah_miskin (id_rumah, alamat, jumlah_kk, jumlah_orang, latitude, longitude) VALUES (?, ?, ?, ?, ?, ?)"); + $stmt->execute([ + $input['id_rumah'], + $input['alamat'] ?? '', + $input['jumlah_kk'] ?? 1, + $input['jumlah_orang'] ?? 1, + $input['latitude'], + $input['longitude'] + ]); + + echo json_encode([ + 'success' => true, + 'message' => 'Data Rumah Miskin berhasil disimpan' + ]); +} catch (PDOException $e) { + http_response_code(500); + echo json_encode(['success' => false, 'message' => $e->getMessage()]); +} diff --git a/api/update_ibadah.php b/api/update_ibadah.php new file mode 100644 index 0000000..ccf37f9 --- /dev/null +++ b/api/update_ibadah.php @@ -0,0 +1,31 @@ + false, 'message' => 'Data tidak lengkap']); + exit(); +} + +try { + $stmt = $pdo->prepare("UPDATE rumah_ibadah SET nama = ?, alamat = ?, latitude = ?, longitude = ?, radius = ? WHERE id = ?"); + $stmt->execute([ + $input['nama'], + $input['alamat'] ?? '', + (float)$input['latitude'], + (float)$input['longitude'], + $input['radius'] ?? 500, + $input['id'] + ]); + + echo json_encode([ + 'success' => true, + 'message' => 'Data Rumah Ibadah berhasil diperbarui' + ]); +} catch (PDOException $e) { + http_response_code(500); + echo json_encode(['success' => false, 'message' => $e->getMessage()]); +} diff --git a/api/update_miskin.php b/api/update_miskin.php new file mode 100644 index 0000000..1ef8968 --- /dev/null +++ b/api/update_miskin.php @@ -0,0 +1,31 @@ + false, 'message' => 'Data tidak lengkap']); + exit(); +} + +try { + $stmt = $pdo->prepare("UPDATE rumah_miskin SET alamat = ?, jumlah_kk = ?, jumlah_orang = ?, latitude = ?, longitude = ? WHERE id_rumah = ?"); + $stmt->execute([ + $input['alamat'] ?? '', + $input['jumlah_kk'] ?? 1, + $input['jumlah_orang'] ?? 1, + (float)$input['latitude'], + (float)$input['longitude'], + $input['id_rumah'] + ]); + + echo json_encode([ + 'success' => true, + 'message' => 'Data Rumah Miskin berhasil diperbarui' + ]); +} catch (PDOException $e) { + http_response_code(500); + echo json_encode(['success' => false, 'message' => $e->getMessage()]); +} diff --git a/db.php b/db.php new file mode 100644 index 0000000..c105a96 --- /dev/null +++ b/db.php @@ -0,0 +1,69 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $pdo_init->exec("CREATE DATABASE IF NOT EXISTS `$dbname`"); + + // Now connect to the specific database + $pdo = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass); + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + // Create tables if not exists + $pdo->exec(" + CREATE TABLE IF NOT EXISTS rumah_ibadah ( + id INT AUTO_INCREMENT PRIMARY KEY, + nama VARCHAR(255) NOT NULL, + alamat TEXT NOT NULL, + latitude DECIMAL(10, 8) NOT NULL, + longitude DECIMAL(11, 8) NOT NULL, + radius INT DEFAULT 500, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ) + "); + + $pdo->exec(" + CREATE TABLE IF NOT EXISTS rumah_miskin ( + id_rumah VARCHAR(50) PRIMARY KEY, + alamat TEXT, + jumlah_kk INT NOT NULL DEFAULT 1, + jumlah_orang INT NOT NULL DEFAULT 1, + latitude DECIMAL(10, 8) NOT NULL, + longitude DECIMAL(11, 8) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ) + "); + + // Ensure alamat column exists if table was already created + try { + $pdo->exec("ALTER TABLE rumah_miskin ADD COLUMN alamat TEXT AFTER id_rumah"); + } catch (PDOException $e) { + // Column might already exist, ignore error + } + +} catch(PDOException $e) { + die("Database Connection failed: " . $e->getMessage()); +} +?> diff --git a/index.html b/index.html new file mode 100644 index 0000000..027dc0d --- /dev/null +++ b/index.html @@ -0,0 +1,164 @@ + + + + + + WebGIS Miskin & Ibadah + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
🏘️
+

WebGIS Miskin & Ibadah

+

+ Sistem Informasi Geografis untuk pemetaan rumah ibadah dan + analisis sebaran keluarga kurang mampu. +

+ + + + + +
+

Mengarahkan ke halaman Peta dalam 5 detik...

+ +
+
+
+ + + + diff --git a/init.log b/init.log new file mode 100644 index 0000000000000000000000000000000000000000..29a78bd74e1df1167874640e9ff8b663140d47e9 GIT binary patch literal 58 zcmezWFMy$lA)g_OA(bJSp@cz!!IvSEp_m~XNag`~ATkpup2?8NkOL&Efa+2hcp11D E0H(PNEdT%j literal 0 HcmV?d00001 diff --git a/pages/data.html b/pages/data.html new file mode 100644 index 0000000..bed0154 --- /dev/null +++ b/pages/data.html @@ -0,0 +1,213 @@ + + + + + + Data Tabular - WebGIS Miskin & Ibadah + + + + + + + + + + + + + + + + + + + +
+ + +
+
+

+ + Manajemen Data +

+

Daftar rumah ibadah dan keluarga miskin dalam matriks tabular.

+
+ +
+ + +
+
+
+
Total Rumah Ibadah
+
-
+
+
+
+
Total Rumah Miskin
+
-
+
+
+
+
Total Jiwa Terdata
+
-
+
+
+ + +
+ +
+
+ + + + + + + + + + + + +
#Nama Rumah IbadahAlamatRadius AnalisisKoordinatAksi
+
+
+ + +
+
+ + + + + + + + + + + + +
ID RumahAlamatJumlah KKJumlah JiwaKoordinatAksi
+
+
+
+
+ + + + + + + +
+ + + + diff --git a/pages/map.html b/pages/map.html new file mode 100644 index 0000000..86c022c --- /dev/null +++ b/pages/map.html @@ -0,0 +1,662 @@ + + + + + + Peta Interaktif - WebGIS Miskin & Ibadah + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ +
+

+ + Mode Operasi +

+
+ + + +
+
+ + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + +