diff --git a/WebGISPovertyMapping/api/prasejahtera/get_prasejahtera.php b/WebGISPovertyMapping/api/prasejahtera/get_prasejahtera.php index 7344961..ffcae09 100644 --- a/WebGISPovertyMapping/api/prasejahtera/get_prasejahtera.php +++ b/WebGISPovertyMapping/api/prasejahtera/get_prasejahtera.php @@ -3,7 +3,8 @@ require_once '../../auth.php'; requireRole('admin', 'operator'); header('Content-Type: application/json'); -$conn = new mysqli("localhost", "root", "", "webgis"); +require_once '../../../config.php'; +$conn = getDB(); $id = (int) $_GET['id']; $stmt = $conn->prepare("SELECT * FROM rumah_prasejahtera WHERE id = ?"); diff --git a/WebGISPovertyMapping/api/prasejahtera/hapus_prasejahtera.php b/WebGISPovertyMapping/api/prasejahtera/hapus_prasejahtera.php index 4338d33..379de55 100644 --- a/WebGISPovertyMapping/api/prasejahtera/hapus_prasejahtera.php +++ b/WebGISPovertyMapping/api/prasejahtera/hapus_prasejahtera.php @@ -3,8 +3,8 @@ require_once '../../auth.php'; requireRole('admin'); header('Content-Type: application/json'); -// Pastikan nama database sudah benar -$conn = new mysqli("localhost", "root", "", "webgis"); +require_once '../../../config.php'; +$conn = getDB(); if ($conn->connect_error) { echo json_encode(["status" => "error", "message" => "Koneksi database gagal"]); diff --git a/WebGISPovertyMapping/api/prasejahtera/load_prasejahtera.php b/WebGISPovertyMapping/api/prasejahtera/load_prasejahtera.php index 2d73d84..ad61385 100644 --- a/WebGISPovertyMapping/api/prasejahtera/load_prasejahtera.php +++ b/WebGISPovertyMapping/api/prasejahtera/load_prasejahtera.php @@ -1,6 +1,7 @@ query("SELECT * FROM rumah_prasejahtera"); $data = []; while ($row = $result->fetch_assoc()) $data[] = $row; diff --git a/WebGISPovertyMapping/api/prasejahtera/simpan_prasejahtera.php b/WebGISPovertyMapping/api/prasejahtera/simpan_prasejahtera.php index 2b19b43..b7ca8f9 100644 --- a/WebGISPovertyMapping/api/prasejahtera/simpan_prasejahtera.php +++ b/WebGISPovertyMapping/api/prasejahtera/simpan_prasejahtera.php @@ -3,7 +3,8 @@ require_once '../../auth.php'; requireRole('admin', 'operator'); header('Content-Type: application/json'); -$conn = new mysqli("localhost", "root", "", "webgis"); +require_once '../../../config.php'; +$conn = getDB(); $data = json_decode(file_get_contents("php://input"), true); diff --git a/WebGISPovertyMapping/api/prasejahtera/update_prasejahtera.php b/WebGISPovertyMapping/api/prasejahtera/update_prasejahtera.php index a224994..b131633 100644 --- a/WebGISPovertyMapping/api/prasejahtera/update_prasejahtera.php +++ b/WebGISPovertyMapping/api/prasejahtera/update_prasejahtera.php @@ -3,7 +3,8 @@ require_once '../../auth.php'; requireRole('admin', 'operator'); header('Content-Type: application/json'); -$conn = new mysqli("localhost", "root", "", "webgis"); +require_once '../../../config.php'; +$conn = getDB(); $data = json_decode(file_get_contents("php://input"), true); if (!$data || !isset($data['id'])) { diff --git a/WebGISPovertyMapping/api/rumahibadah/get_ibadah.php b/WebGISPovertyMapping/api/rumahibadah/get_ibadah.php index 109fa87..5147d21 100644 --- a/WebGISPovertyMapping/api/rumahibadah/get_ibadah.php +++ b/WebGISPovertyMapping/api/rumahibadah/get_ibadah.php @@ -3,7 +3,8 @@ require_once '../../auth.php'; requireRole('admin', 'operator'); header('Content-Type: application/json'); -$conn = new mysqli("localhost", "root", "", "webgis"); +require_once '../../../config.php'; +$conn = getDB(); $id = (int) $_GET['id']; $stmt = $conn->prepare("SELECT * FROM rumah_ibadah WHERE id = ?"); diff --git a/WebGISPovertyMapping/api/rumahibadah/hapus_ibadah.php b/WebGISPovertyMapping/api/rumahibadah/hapus_ibadah.php index 0eeba62..09ba695 100644 --- a/WebGISPovertyMapping/api/rumahibadah/hapus_ibadah.php +++ b/WebGISPovertyMapping/api/rumahibadah/hapus_ibadah.php @@ -3,7 +3,8 @@ require_once '../../auth.php'; requireRole('admin'); header('Content-Type: application/json'); -$conn = new mysqli('localhost', 'root', '', 'webgis'); +require_once '../../../config.php'; +$conn = getDB(); $data = json_decode(file_get_contents('php://input'), true); $stmt = $conn->prepare("DELETE FROM rumah_ibadah WHERE id = ?"); $stmt->bind_param("i", $data['id']); diff --git a/WebGISPovertyMapping/api/rumahibadah/load_ibadah.php b/WebGISPovertyMapping/api/rumahibadah/load_ibadah.php index d5ff292..2763663 100644 --- a/WebGISPovertyMapping/api/rumahibadah/load_ibadah.php +++ b/WebGISPovertyMapping/api/rumahibadah/load_ibadah.php @@ -1,6 +1,7 @@ query("SELECT * FROM rumah_ibadah"); $data = []; diff --git a/WebGISPovertyMapping/api/rumahibadah/simpan_ibadah.php b/WebGISPovertyMapping/api/rumahibadah/simpan_ibadah.php index fd42d11..d8a4a5a 100644 --- a/WebGISPovertyMapping/api/rumahibadah/simpan_ibadah.php +++ b/WebGISPovertyMapping/api/rumahibadah/simpan_ibadah.php @@ -3,7 +3,8 @@ require_once '../../auth.php'; requireRole('admin', 'operator'); header('Content-Type: application/json'); -$conn = new mysqli('localhost', 'root', '', 'webgis'); +require_once '../../../config.php'; +$conn = getDB(); $data = json_decode(file_get_contents('php://input'), true); $stmt = $conn->prepare("INSERT INTO rumah_ibadah (nama_ibadah, jenis, radius_m, lat, lng) VALUES (?, ?, ?, ?, ?)"); $stmt->bind_param("ssidd", $data['nama_ibadah'], $data['jenis'], $data['radius_m'], $data['lat'], $data['lng']); diff --git a/WebGISPovertyMapping/api/rumahibadah/update_ibadah.php b/WebGISPovertyMapping/api/rumahibadah/update_ibadah.php index 55e80a9..6603ab8 100644 --- a/WebGISPovertyMapping/api/rumahibadah/update_ibadah.php +++ b/WebGISPovertyMapping/api/rumahibadah/update_ibadah.php @@ -3,7 +3,8 @@ require_once '../../auth.php'; requireRole('admin', 'operator'); header('Content-Type: application/json'); -$conn = new mysqli("localhost", "root", "", "webgis"); +require_once '../../../config.php'; +$conn = getDB(); $data = json_decode(file_get_contents("php://input"), true); if (!$data || !isset($data['id'])) { diff --git a/WebGISPovertyMapping/api/users/get_user.php b/WebGISPovertyMapping/api/users/get_user.php index 1a82274..89eb42f 100644 --- a/WebGISPovertyMapping/api/users/get_user.php +++ b/WebGISPovertyMapping/api/users/get_user.php @@ -3,7 +3,8 @@ require_once '../../auth.php'; requireRole('admin'); header('Content-Type: application/json'); -$conn = new mysqli("localhost", "root", "", "webgis"); +require_once '../../../config.php'; +$conn = getDB(); $id = (int) $_GET['id']; $stmt = $conn->prepare("SELECT id, nama, username, role FROM users WHERE id = ?"); diff --git a/WebGISPovertyMapping/api/users/hapus_user.php b/WebGISPovertyMapping/api/users/hapus_user.php index 0181104..b6ed52c 100644 --- a/WebGISPovertyMapping/api/users/hapus_user.php +++ b/WebGISPovertyMapping/api/users/hapus_user.php @@ -3,7 +3,8 @@ require_once '../../auth.php'; requireRole('admin'); header('Content-Type: application/json'); -$conn = new mysqli("localhost", "root", "", "webgis"); +require_once '../../../config.php'; +$conn = getDB(); $data = json_decode(file_get_contents("php://input"), true); $id = (int) $data['id']; diff --git a/WebGISPovertyMapping/api/users/update_user.php b/WebGISPovertyMapping/api/users/update_user.php index 1c2b289..3ca3fef 100644 --- a/WebGISPovertyMapping/api/users/update_user.php +++ b/WebGISPovertyMapping/api/users/update_user.php @@ -3,7 +3,8 @@ require_once '../../auth.php'; requireRole('admin'); header('Content-Type: application/json'); -$conn = new mysqli("localhost", "root", "", "webgis"); +require_once '../../../config.php'; +$conn = getDB(); $data = json_decode(file_get_contents("php://input"), true); if (!$data || !isset($data['id'])) { diff --git a/WebGISPovertyMapping/login.php b/WebGISPovertyMapping/login.php index 36ce25c..8f56bfb 100644 --- a/WebGISPovertyMapping/login.php +++ b/WebGISPovertyMapping/login.php @@ -10,7 +10,8 @@ if (isset($_SESSION['user'])) { $error = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { - $conn = new mysqli("localhost", "root", "", "webgis"); + require_once '../config.php'; + $conn = getDB(); $username = trim($_POST['username']); $password = trim($_POST['password']); diff --git a/WebGISPovertyMapping/users.php b/WebGISPovertyMapping/users.php index 1f50afb..f266cff 100644 --- a/WebGISPovertyMapping/users.php +++ b/WebGISPovertyMapping/users.php @@ -3,7 +3,8 @@ require_once 'auth.php'; requireLogin(); requireRole('admin'); -$conn = new mysqli("localhost", "root", "", "webgis"); +require_once '../config.php'; +$conn = getDB(); $error = ''; $success = ''; diff --git a/config.php b/config.php new file mode 100644 index 0000000..fcc6569 --- /dev/null +++ b/config.php @@ -0,0 +1,16 @@ +connect_error) { + http_response_code(500); + echo json_encode(["status" => "error", "message" => "Koneksi database gagal"]); + exit; + } + return $conn; +} +?> \ No newline at end of file diff --git a/database/webgis.sql b/database/webgis.sql index 6f84395..a7277ef 100644 --- a/database/webgis.sql +++ b/database/webgis.sql @@ -3,9 +3,9 @@ -- https://www.phpmyadmin.net/ -- -- Host: 127.0.0.1 --- Waktu pembuatan: 04 Jun 2026 pada 04.59 --- Versi server: 10.4.32-MariaDB --- Versi PHP: 8.2.12 +-- Generation Time: Jun 10, 2026 at 04:05 PM +-- Server version: 10.4.32-MariaDB +-- PHP Version: 8.2.12 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; START TRANSACTION; @@ -24,7 +24,7 @@ SET time_zone = "+00:00"; -- -------------------------------------------------------- -- --- Struktur dari tabel `area_polygon` +-- Table structure for table `area_polygon` -- CREATE TABLE `area_polygon` ( @@ -36,7 +36,7 @@ CREATE TABLE `area_polygon` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -- --- Dumping data untuk tabel `area_polygon` +-- Dumping data for table `area_polygon` -- INSERT INTO `area_polygon` (`id`, `nama_kavling`, `status_kepemilikan`, `luas_m2`, `geojson`) VALUES @@ -50,7 +50,7 @@ INSERT INTO `area_polygon` (`id`, `nama_kavling`, `status_kepemilikan`, `luas_m2 -- -------------------------------------------------------- -- --- Struktur dari tabel `jalan_polyline` +-- Table structure for table `jalan_polyline` -- CREATE TABLE `jalan_polyline` ( @@ -62,7 +62,7 @@ CREATE TABLE `jalan_polyline` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -- --- Dumping data untuk tabel `jalan_polyline` +-- Dumping data for table `jalan_polyline` -- INSERT INTO `jalan_polyline` (`id`, `nama_jalan`, `status`, `panjang_m`, `geojson`) VALUES @@ -78,7 +78,7 @@ INSERT INTO `jalan_polyline` (`id`, `nama_jalan`, `status`, `panjang_m`, `geojso -- -------------------------------------------------------- -- --- Struktur dari tabel `rumah_ibadah` +-- Table structure for table `rumah_ibadah` -- CREATE TABLE `rumah_ibadah` ( @@ -91,16 +91,17 @@ CREATE TABLE `rumah_ibadah` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -- --- Dumping data untuk tabel `rumah_ibadah` +-- Dumping data for table `rumah_ibadah` -- INSERT INTO `rumah_ibadah` (`id`, `nama_ibadah`, `jenis`, `radius_m`, `lat`, `lng`) VALUES -(1, 'Babul Maghfirah', 'Masjid', 500, -0.05512207163471261, 109.35242215378504); +(1, 'Babul Maghfirah', 'Masjid', 600, -0.05480292153321615, 109.35301758952382), +(4, 'Masjid Raya Mujahiddin', 'Masjid', 500, -0.041434028832777574, 109.33632432523154); -- -------------------------------------------------------- -- --- Struktur dari tabel `rumah_prasejahtera` +-- Table structure for table `rumah_prasejahtera` -- CREATE TABLE `rumah_prasejahtera` ( @@ -120,19 +121,20 @@ CREATE TABLE `rumah_prasejahtera` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -- --- Dumping data untuk tabel `rumah_prasejahtera` +-- Dumping data for table `rumah_prasejahtera` -- INSERT INTO `rumah_prasejahtera` (`id`, `nama_kepala_keluarga`, `penghasilan`, `jumlah_anak`, `umur_anak`, `status_ortu`, `ada_pensiun`, `nominal_pensiun`, `ada_terusan`, `nominal_terusan`, `keterangan`, `lat`, `lng`) VALUES -(10, 'Pak Ambalingham', 2000000.00, 2, '12, 7', 'Bekerja', 'Tidak', 0.00, 'Tidak', 0.00, 'rokok 2 slop sehari', -0.04965587084748121, 109.35713631716), -(11, 'Mas Us', 0.00, 3, '14, 9, 3', 'Pensiun', 'Ya', 400000.00, 'Tidak', 0.00, '', -0.05299500680178904, 109.35927377651974), -(12, 'Robi', 0.00, 1, '13', 'Meninggal', 'Tidak', 0.00, 'Tidak', 0.00, '', -0.051968992262292006, 109.35091436068554), -(13, 'Mas Rian', 0.00, 2, '4, 3', 'Meninggal', 'Tidak', 0.00, 'Ya', 200000.00, '', -0.04951572385615543, 109.3541283718652); +(10, 'Pak Ambalingham', 2000000.00, 2, '12, 7', 'Bekerja', 'Tidak', 0.00, 'Tidak', 0.00, 'rokok 2 slop sehari', -0.04952435403005827, 109.3574379859713), +(12, 'Robi', 0.00, 1, '13', 'Meninggal', 'Tidak', 0.00, 'Tidak', 0.00, '', -0.05197047474609275, 109.35194457542805), +(13, 'Mas Rusdi', 0.00, 2, '4, 3', 'Meninggal', 'Tidak', 0.00, 'Ya', 200000.00, '', -0.04928832854879829, 109.3546487495755), +(14, 'Mas Us', 0.00, 3, '14, 9, 3', 'Pensiun', 'Ya', 400000.00, 'Tidak', 0.00, '', -0.05883415577738937, 109.3555884504947), +(15, 'Herman Santoso', 2000000.00, 2, '21, 10', 'Bekerja', 'Tidak', 0.00, 'Tidak', 0.00, 'rokok 8 slop sehari', -0.04387894972428997, 109.33540877797459); -- -------------------------------------------------------- -- --- Struktur dari tabel `spbu_point` +-- Table structure for table `spbu_point` -- CREATE TABLE `spbu_point` ( @@ -145,7 +147,7 @@ CREATE TABLE `spbu_point` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -- --- Dumping data untuk tabel `spbu_point` +-- Dumping data for table `spbu_point` -- INSERT INTO `spbu_point` (`id`, `lat`, `lng`, `nama_spbu`, `no_wa`, `buka_24jam`) VALUES @@ -157,73 +159,109 @@ INSERT INTO `spbu_point` (`id`, `lat`, `lng`, `nama_spbu`, `no_wa`, `buka_24jam` (17, -0.17363396, 109.43607241, 'RUMAH AKU', '082150711624', 1), (18, -0.11209001, 109.36203003, 'rumah pak amba', '082849696767', 1); +-- -------------------------------------------------------- + +-- +-- Table structure for table `users` +-- + +CREATE TABLE `users` ( + `id` int(11) NOT NULL, + `nama` varchar(100) NOT NULL, + `username` varchar(50) NOT NULL, + `password` varchar(255) NOT NULL, + `role` enum('admin','operator') NOT NULL DEFAULT 'operator', + `created_at` timestamp NOT NULL DEFAULT current_timestamp() +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- +-- Dumping data for table `users` +-- + +INSERT INTO `users` (`id`, `nama`, `username`, `password`, `role`, `created_at`) VALUES +(3, 'Administrator', 'admin', '$2y$10$A.PGTJ3iQJc8hK0maehBtO7a8xWZ5SqoqJnC4wMoSqlhH6PDmjAC.', 'admin', '2026-06-10 05:28:11'), +(5, 'Pak Budi', 'operator', '$2y$10$d37JkJWWY1oYnxZHPqo.6O.q/AdoaW3K8oetf0kLj44o.OxOtJQQu', 'operator', '2026-06-10 08:25:55'); + -- -- Indexes for dumped tables -- -- --- Indeks untuk tabel `area_polygon` +-- Indexes for table `area_polygon` -- ALTER TABLE `area_polygon` ADD PRIMARY KEY (`id`); -- --- Indeks untuk tabel `jalan_polyline` +-- Indexes for table `jalan_polyline` -- ALTER TABLE `jalan_polyline` ADD PRIMARY KEY (`id`); -- --- Indeks untuk tabel `rumah_ibadah` +-- Indexes for table `rumah_ibadah` -- ALTER TABLE `rumah_ibadah` ADD PRIMARY KEY (`id`); -- --- Indeks untuk tabel `rumah_prasejahtera` +-- Indexes for table `rumah_prasejahtera` -- ALTER TABLE `rumah_prasejahtera` ADD PRIMARY KEY (`id`); -- --- Indeks untuk tabel `spbu_point` +-- Indexes for table `spbu_point` -- ALTER TABLE `spbu_point` ADD PRIMARY KEY (`id`); -- --- AUTO_INCREMENT untuk tabel yang dibuang +-- Indexes for table `users` +-- +ALTER TABLE `users` + ADD PRIMARY KEY (`id`), + ADD UNIQUE KEY `username` (`username`); + +-- +-- AUTO_INCREMENT for dumped tables -- -- --- AUTO_INCREMENT untuk tabel `area_polygon` +-- AUTO_INCREMENT for table `area_polygon` -- ALTER TABLE `area_polygon` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9; -- --- AUTO_INCREMENT untuk tabel `jalan_polyline` +-- AUTO_INCREMENT for table `jalan_polyline` -- ALTER TABLE `jalan_polyline` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=13; -- --- AUTO_INCREMENT untuk tabel `rumah_ibadah` +-- AUTO_INCREMENT for table `rumah_ibadah` -- ALTER TABLE `rumah_ibadah` - MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4; + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5; -- --- AUTO_INCREMENT untuk tabel `rumah_prasejahtera` +-- AUTO_INCREMENT for table `rumah_prasejahtera` -- ALTER TABLE `rumah_prasejahtera` - MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=14; + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=16; -- --- AUTO_INCREMENT untuk tabel `spbu_point` +-- AUTO_INCREMENT for table `spbu_point` -- ALTER TABLE `spbu_point` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=19; + +-- +-- AUTO_INCREMENT for table `users` +-- +ALTER TABLE `users` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6; COMMIT; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;