43 lines
1.7 KiB
PHP
43 lines
1.7 KiB
PHP
<?php
|
|
// proses_poverty.php
|
|
$conn = new mysqli("localhost", "root", "", "db_poverty_mapping");
|
|
|
|
if ($conn->connect_error) { die("Koneksi gagal: " . $conn->connect_error); }
|
|
|
|
$action = isset($_GET['action']) ? $_GET['action'] : (isset($_POST['action']) ? $_POST['action'] : '');
|
|
|
|
if ($action == 'create' && $_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
$type = $_POST['type'];
|
|
$nama_atribut = $conn->real_escape_string($_POST['nama_atribut']);
|
|
$status = $_POST['status'];
|
|
$geojson = $_POST['geojson'];
|
|
|
|
if ($type == 'ibadah') {
|
|
$sql = "INSERT INTO data_rumah_ibadah (nama_ibadah, jenis_agama, geojson) VALUES ('$nama_atribut', '$status', '$geojson')";
|
|
} else if ($type == 'warga') {
|
|
$solusi = $conn->real_escape_string($_POST['rekomendasi_solusi']);
|
|
$mentah_luas = $_POST['hasil_hitung'];
|
|
preg_match('/[0-9.]+/', $mentah_luas, $matches);
|
|
$luas_clean = isset($matches[0]) ? floatval($matches[0]) : 0;
|
|
|
|
$sql = "INSERT INTO data_warga (nama_kk, klasifikasi, luas_meter, rekomendasi_solusi, geojson)
|
|
VALUES ('$nama_atribut', '$status', '$luas_clean', '$solusi', '$geojson')";
|
|
}
|
|
|
|
if ($conn->query($sql) === TRUE) {
|
|
echo "<script>alert('Data Berhasil Ditambahkan!'); window.location='index.php';</script>";
|
|
}
|
|
}
|
|
|
|
if ($action == 'delete' && isset($_GET['id']) && isset($_GET['type'])) {
|
|
$id = intval($_GET['id']);
|
|
$type = $_GET['type'];
|
|
|
|
$sql = ($type == 'ibadah') ? "DELETE FROM data_rumah_ibadah WHERE id = $id" : "DELETE FROM data_warga WHERE id = $id";
|
|
|
|
if ($conn->query($sql) === TRUE) {
|
|
echo "<script>alert('Data Berhasil Dihapus!'); window.location='index.php';</script>";
|
|
}
|
|
}
|
|
$conn->close();
|
|
?>
|