add webtugas folder
This commit is contained in:
-1
Submodule webtugas deleted from 30b16bb877
File diff suppressed because one or more lines are too long
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
header('Access-Control-Allow-Origin: *');
|
||||||
|
header('Access-Control-Allow-Methods: POST, OPTIONS');
|
||||||
|
header('Access-Control-Allow-Headers: Content-Type');
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(200); exit(); }
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'Metode tidak diizinkan']);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once 'db_config.php';
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents('php://input'), true);
|
||||||
|
$username = isset($data['username']) ? trim($data['username']) : '';
|
||||||
|
$oldPassword = isset($data['old_password']) ? $data['old_password'] : '';
|
||||||
|
$newPassword = isset($data['new_password']) ? $data['new_password'] : '';
|
||||||
|
|
||||||
|
if (empty($username) || empty($oldPassword) || empty($newPassword)) {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'Semua field wajib diisi']);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
if (strlen($newPassword) < 6) {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'Password baru minimal 6 karakter']);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch current hashed password
|
||||||
|
$stmt = $conn->prepare("SELECT id, password FROM users WHERE username = ?");
|
||||||
|
$stmt->bind_param('s', $username);
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
|
if ($result->num_rows === 0) {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'User tidak ditemukan']);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$row = $result->fetch_assoc();
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
if (!password_verify($oldPassword, $row['password'])) {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'Password lama tidak sesuai']);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update password
|
||||||
|
$hashed = password_hash($newPassword, PASSWORD_DEFAULT);
|
||||||
|
$upd = $conn->prepare("UPDATE users SET password = ? WHERE id = ?");
|
||||||
|
$upd->bind_param('si', $hashed, $row['id']);
|
||||||
|
|
||||||
|
if ($upd->execute()) {
|
||||||
|
echo json_encode(['status' => 'success', 'message' => 'Password berhasil diubah']);
|
||||||
|
} else {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'Gagal memperbarui password']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$upd->close();
|
||||||
|
$conn->close();
|
||||||
|
?>
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||||
|
echo json_encode(['status'=>'error','message'=>'Metode tidak diizinkan']);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once 'db_config.php';
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents('php://input'), true);
|
||||||
|
$username = isset($data['username']) ? trim($data['username']) : '';
|
||||||
|
$nama = isset($data['nama_lengkap'])? trim($data['nama_lengkap']): '';
|
||||||
|
$password = isset($data['password']) ? $data['password'] : '';
|
||||||
|
$role = isset($data['role']) ? trim($data['role']) : 'operator';
|
||||||
|
|
||||||
|
if (empty($username) || empty($nama) || empty($password)) {
|
||||||
|
echo json_encode(['status'=>'error','message'=>'Semua field wajib diisi']);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
if (strlen($password) < 6) {
|
||||||
|
echo json_encode(['status'=>'error','message'=>'Password minimal 6 karakter']);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
if (!in_array($role, ['admin','operator'])) {
|
||||||
|
echo json_encode(['status'=>'error','message'=>'Role tidak valid']);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cek username sudah ada
|
||||||
|
$chk = $conn->prepare("SELECT id FROM users WHERE username = ?");
|
||||||
|
$chk->bind_param('s', $username);
|
||||||
|
$chk->execute();
|
||||||
|
if ($chk->get_result()->num_rows > 0) {
|
||||||
|
echo json_encode(['status'=>'error','message'=>'Username sudah digunakan']);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
$chk->close();
|
||||||
|
|
||||||
|
$hashed = password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
$stmt = $conn->prepare("INSERT INTO users (username, password, nama_lengkap, role) VALUES (?,?,?,?)");
|
||||||
|
$stmt->bind_param('ssss', $username, $hashed, $nama, $role);
|
||||||
|
|
||||||
|
if ($stmt->execute()) {
|
||||||
|
echo json_encode(['status'=>'success','message'=>'Akun berhasil dibuat','id'=>$conn->insert_id]);
|
||||||
|
} else {
|
||||||
|
echo json_encode(['status'=>'error','message'=>'Gagal membuat akun']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt->close();
|
||||||
|
$conn->close();
|
||||||
|
?>
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
include "db_config.php";
|
||||||
|
|
||||||
|
// Step 1: Update ENUM to include walikota
|
||||||
|
$sql1 = "ALTER TABLE users MODIFY COLUMN role ENUM('admin', 'operator', 'walikota') NOT NULL DEFAULT 'operator'";
|
||||||
|
$r1 = $conn->query($sql1);
|
||||||
|
echo "1. Update ENUM: " . ($r1 ? "OK" : "GAGAL - " . $conn->error) . "\n";
|
||||||
|
|
||||||
|
// Step 2: Add kemiskinan columns (ignore if already exists)
|
||||||
|
$sql2 = "ALTER TABLE kemiskinan
|
||||||
|
ADD COLUMN IF NOT EXISTS tanggal_lahir DATE NULL AFTER nama_kk,
|
||||||
|
ADD COLUMN IF NOT EXISTS pendidikan VARCHAR(100) NULL AFTER tanggal_lahir,
|
||||||
|
ADD COLUMN IF NOT EXISTS riwayat_penyakit TEXT NULL AFTER pendidikan";
|
||||||
|
$r2 = $conn->query($sql2);
|
||||||
|
echo "2. Kolom kemiskinan: " . ($r2 ? "OK" : "GAGAL - " . $conn->error) . "\n";
|
||||||
|
|
||||||
|
// Step 3: Create laporan_masyarakat table
|
||||||
|
$sql3 = "CREATE TABLE IF NOT EXISTS laporan_masyarakat (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
nama_pelapor VARCHAR(150) NOT NULL,
|
||||||
|
kontak VARCHAR(50) NULL,
|
||||||
|
deskripsi_laporan TEXT NOT NULL,
|
||||||
|
lat DECIMAL(10,7) NOT NULL DEFAULT 0,
|
||||||
|
lng DECIMAL(10,7) NOT NULL DEFAULT 0,
|
||||||
|
foto VARCHAR(255) NULL,
|
||||||
|
status ENUM('menunggu', 'diproses', 'selesai') NOT NULL DEFAULT 'menunggu',
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||||
|
$r3 = $conn->query($sql3);
|
||||||
|
echo "3. Tabel laporan_masyarakat: " . ($r3 ? "OK" : "GAGAL - " . $conn->error) . "\n";
|
||||||
|
|
||||||
|
// Step 4: Create histori_bantuan table
|
||||||
|
$sql4 = "CREATE TABLE IF NOT EXISTS histori_bantuan (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
kemiskinan_id INT NOT NULL,
|
||||||
|
jenis_bantuan VARCHAR(150) NOT NULL,
|
||||||
|
tanggal DATE NOT NULL,
|
||||||
|
keterangan TEXT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (kemiskinan_id) REFERENCES kemiskinan(id) ON DELETE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||||
|
$r4 = $conn->query($sql4);
|
||||||
|
echo "4. Tabel histori_bantuan: " . ($r4 ? "OK" : "GAGAL - " . $conn->error) . "\n";
|
||||||
|
|
||||||
|
// Step 5: Create walikota account
|
||||||
|
$pass = password_hash("walikota123", PASSWORD_BCRYPT);
|
||||||
|
$sql5 = "INSERT IGNORE INTO users (username, password, nama_lengkap, role) VALUES ('walikota', '$pass', 'Walikota Pontianak', 'walikota')";
|
||||||
|
$r5 = $conn->query($sql5);
|
||||||
|
echo "5. Akun walikota: " . ($r5 ? "OK (affected: " . $conn->affected_rows . ")" : "GAGAL - " . $conn->error) . "\n";
|
||||||
|
|
||||||
|
echo "\nSelesai! Silakan login dengan username: walikota | password: walikota123\n";
|
||||||
|
?>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
mysqli_report(MYSQLI_REPORT_OFF);
|
||||||
|
|
||||||
|
$host = getenv("DB_HOST") ?: "localhost";
|
||||||
|
$user = "root";
|
||||||
|
$pass = "fira123";
|
||||||
|
$db = "kemiskinan_ibadah";
|
||||||
|
|
||||||
|
$conn = new mysqli($host, $user, $pass, $db);
|
||||||
|
|
||||||
|
if ($conn->connect_error) {
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
die(json_encode([
|
||||||
|
"status" => "error",
|
||||||
|
"message" => "Koneksi database gagal",
|
||||||
|
"detail" => $conn->connect_error
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
$conn->set_charset('utf8mb4');
|
||||||
|
?>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
include "db_config.php";
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents("php://input"), true);
|
||||||
|
$id = intval($data['id'] ?? 0);
|
||||||
|
|
||||||
|
if ($id <= 0) {
|
||||||
|
echo json_encode(["status" => "error", "message" => "ID tidak valid"]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "DELETE FROM histori_bantuan WHERE id=$id";
|
||||||
|
|
||||||
|
if ($conn->query($sql)) {
|
||||||
|
echo json_encode(["status" => "success"]);
|
||||||
|
} else {
|
||||||
|
echo json_encode(["status" => "error", "message" => $conn->error]);
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
include "db_config.php";
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents("php://input"), true);
|
||||||
|
$id = isset($data['id']) ? intval($data['id']) : 0;
|
||||||
|
|
||||||
|
if ($id <= 0) {
|
||||||
|
echo json_encode(["status" => "error", "message" => "ID tidak valid"]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "DELETE FROM kemiskinan WHERE id=$id";
|
||||||
|
|
||||||
|
if ($conn->query($sql)) {
|
||||||
|
echo json_encode(["status" => "success"]);
|
||||||
|
} else {
|
||||||
|
echo json_encode(["status" => "error", "message" => $conn->error]);
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
include "db_config.php";
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents("php://input"), true);
|
||||||
|
$id = intval($data['id'] ?? 0);
|
||||||
|
|
||||||
|
if ($id <= 0) {
|
||||||
|
echo json_encode(["status" => "error", "message" => "ID tidak valid"]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "DELETE FROM laporan_masyarakat WHERE id=$id";
|
||||||
|
|
||||||
|
if ($conn->query($sql)) {
|
||||||
|
echo json_encode(["status" => "success"]);
|
||||||
|
} else {
|
||||||
|
echo json_encode(["status" => "error", "message" => $conn->error]);
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
include "db_config.php";
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents("php://input"), true);
|
||||||
|
$id = isset($data['id']) ? intval($data['id']) : 0;
|
||||||
|
|
||||||
|
if ($id <= 0) {
|
||||||
|
echo json_encode(["status" => "error", "message" => "ID tidak valid"]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "DELETE FROM rumah_ibadah WHERE id=$id";
|
||||||
|
|
||||||
|
if ($conn->query($sql)) {
|
||||||
|
echo json_encode(["status" => "success"]);
|
||||||
|
} else {
|
||||||
|
echo json_encode(["status" => "error", "message" => $conn->error]);
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') { echo json_encode(['status'=>'error']); exit(); }
|
||||||
|
require_once 'db_config.php';
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents('php://input'), true);
|
||||||
|
$id = intval($data['id'] ?? 0);
|
||||||
|
|
||||||
|
if (!$id) { echo json_encode(['status'=>'error','message'=>'ID tidak valid']); exit(); }
|
||||||
|
|
||||||
|
// Cegah hapus admin utama (id=1)
|
||||||
|
if ($id === 1) { echo json_encode(['status'=>'error','message'=>'Akun admin utama tidak dapat dihapus']); exit(); }
|
||||||
|
|
||||||
|
$stmt = $conn->prepare("DELETE FROM users WHERE id = ?");
|
||||||
|
$stmt->bind_param('i', $id);
|
||||||
|
|
||||||
|
echo $stmt->execute()
|
||||||
|
? json_encode(['status'=>'success','message'=>'Akun berhasil dihapus'])
|
||||||
|
: json_encode(['status'=>'error','message'=>'Gagal menghapus akun']);
|
||||||
|
|
||||||
|
$stmt->close();
|
||||||
|
$conn->close();
|
||||||
|
?>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db_config.php';
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents('php://input'), true);
|
||||||
|
|
||||||
|
if (!$data || !isset($data['id'])) {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'ID tidak ditemukan']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = intval($data['id']);
|
||||||
|
|
||||||
|
$stmt = $conn->prepare("DELETE FROM warga WHERE id = ?");
|
||||||
|
$stmt->bind_param("i", $id);
|
||||||
|
|
||||||
|
if ($stmt->execute()) {
|
||||||
|
echo json_encode(['status' => 'success']);
|
||||||
|
} else {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => $stmt->error]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt->close();
|
||||||
|
$conn->close();
|
||||||
|
?>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
require_once 'db_config.php';
|
||||||
|
|
||||||
|
$result = $conn->query("SELECT id, username, nama_lengkap, role, created_at FROM users ORDER BY created_at DESC");
|
||||||
|
$users = [];
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
$users[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($users);
|
||||||
|
$conn->close();
|
||||||
|
?>
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
header('Access-Control-Allow-Origin: *');
|
||||||
|
header('Access-Control-Allow-Methods: POST, OPTIONS');
|
||||||
|
header('Access-Control-Allow-Headers: Content-Type');
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
||||||
|
http_response_code(200);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'Metode tidak diizinkan']);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once 'db_config.php';
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents('php://input'), true);
|
||||||
|
$username = isset($data['username']) ? trim($data['username']) : '';
|
||||||
|
$password = isset($data['password']) ? $data['password'] : '';
|
||||||
|
|
||||||
|
if (empty($username) || empty($password)) {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'Username dan password wajib diisi']);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt = $conn->prepare("SELECT id, username, password, nama_lengkap, role FROM users WHERE username = ?");
|
||||||
|
$stmt->bind_param('s', $username);
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
|
if ($result->num_rows === 0) {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'Username atau password salah']);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $result->fetch_assoc();
|
||||||
|
|
||||||
|
if (!password_verify($password, $user['password'])) {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'Username atau password salah']);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set session
|
||||||
|
$_SESSION['gis_logged_in'] = true;
|
||||||
|
$_SESSION['user_id'] = $user['id'];
|
||||||
|
$_SESSION['username'] = $user['username'];
|
||||||
|
$_SESSION['nama_lengkap'] = $user['nama_lengkap'];
|
||||||
|
$_SESSION['role'] = $user['role'];
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'Login berhasil',
|
||||||
|
'user' => [
|
||||||
|
'username' => $user['username'],
|
||||||
|
'nama_lengkap' => $user['nama_lengkap'],
|
||||||
|
'role' => $user['role']
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$stmt->close();
|
||||||
|
$conn->close();
|
||||||
|
?>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$_SESSION = [];
|
||||||
|
session_destroy();
|
||||||
|
|
||||||
|
echo json_encode(['status' => 'success', 'message' => 'Logout berhasil']);
|
||||||
|
?>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
include 'db_config.php';
|
||||||
|
|
||||||
|
// Fungsi Ambil Data
|
||||||
|
function getAllSPBU($conn) {
|
||||||
|
$sql = "SELECT * FROM spbu ORDER BY id DESC";
|
||||||
|
return $conn->query($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fungsi Simpan Data
|
||||||
|
function insertSPBU($conn, $nama, $no_spbu, $status, $lat, $lng) {
|
||||||
|
$nama_clean = $conn->real_escape_string($nama);
|
||||||
|
$no_spbu_clean = $conn->real_escape_string($no_spbu);
|
||||||
|
$status_clean = $conn->real_escape_string($status);
|
||||||
|
$lat_clean = (float)$lat;
|
||||||
|
$lng_clean = (float)$lng;
|
||||||
|
|
||||||
|
$sql = "INSERT INTO spbu (nama, no_spbu, status_24jam, lat, lng)
|
||||||
|
VALUES ('$nama_clean', '$no_spbu_clean', '$status_clean', $lat_clean, $lng_clean)";
|
||||||
|
|
||||||
|
return $conn->query($sql);
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
include "db_config.php";
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$kemiskinan_id = intval($_GET['kemiskinan_id'] ?? 0);
|
||||||
|
|
||||||
|
if ($kemiskinan_id <= 0) {
|
||||||
|
echo json_encode(["status" => "error", "message" => "kemiskinan_id tidak valid"]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT * FROM histori_bantuan WHERE kemiskinan_id=$kemiskinan_id ORDER BY tanggal DESC";
|
||||||
|
$result = $conn->query($sql);
|
||||||
|
|
||||||
|
if (!$result) {
|
||||||
|
echo json_encode(["status" => "error", "message" => $conn->error]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
$data[] = $row;
|
||||||
|
}
|
||||||
|
echo json_encode($data);
|
||||||
|
?>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
include "db_config.php";
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$sql = "SELECT * FROM kemiskinan";
|
||||||
|
$result = $conn->query($sql);
|
||||||
|
|
||||||
|
if (!$result) {
|
||||||
|
echo json_encode([
|
||||||
|
"status" => "error",
|
||||||
|
"message" => "Gagal membaca tabel kemiskinan",
|
||||||
|
"detail" => $conn->error
|
||||||
|
]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
while($row = $result->fetch_assoc()){
|
||||||
|
$data[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($data);
|
||||||
|
?>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
include "db_config.php";
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$sql = "SELECT * FROM laporan_masyarakat ORDER BY created_at DESC";
|
||||||
|
$result = $conn->query($sql);
|
||||||
|
|
||||||
|
if (!$result) {
|
||||||
|
echo json_encode(["status" => "error", "message" => "Gagal membaca tabel laporan_masyarakat", "detail" => $conn->error]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
$data[] = $row;
|
||||||
|
}
|
||||||
|
echo json_encode($data);
|
||||||
|
?>
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
include "db_config.php";
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
id,
|
||||||
|
nama_rumah_ibadah AS nama_masjid,
|
||||||
|
penanggung_jawab AS pic_masjid,
|
||||||
|
alamat AS alamat_masjid,
|
||||||
|
radius,
|
||||||
|
lat,
|
||||||
|
lng,
|
||||||
|
created_at,
|
||||||
|
updated_at
|
||||||
|
FROM rumah_ibadah";
|
||||||
|
$result = $conn->query($sql);
|
||||||
|
|
||||||
|
if (!$result) {
|
||||||
|
echo json_encode([
|
||||||
|
"status" => "error",
|
||||||
|
"message" => "Gagal membaca tabel rumah ibadah",
|
||||||
|
"detail" => $conn->error
|
||||||
|
]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
while($row = $result->fetch_assoc()){
|
||||||
|
$data[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($data);
|
||||||
|
?>
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
require_once 'db_config.php';
|
||||||
|
|
||||||
|
$sql = "
|
||||||
|
SELECT
|
||||||
|
w.id as warga_id,
|
||||||
|
w.kemiskinan_id,
|
||||||
|
w.nik,
|
||||||
|
w.nama_warga,
|
||||||
|
w.hubungan_keluarga,
|
||||||
|
w.tanggal_lahir,
|
||||||
|
w.pendidikan,
|
||||||
|
w.riwayat_penyakit,
|
||||||
|
k.nama_kk,
|
||||||
|
k.alamat,
|
||||||
|
k.jumlah_kk,
|
||||||
|
(SELECT COUNT(*) FROM histori_bantuan hb WHERE hb.kemiskinan_id = k.id) as jumlah_bantuan
|
||||||
|
FROM warga w
|
||||||
|
LEFT JOIN kemiskinan k ON w.kemiskinan_id = k.id
|
||||||
|
ORDER BY w.updated_at DESC
|
||||||
|
";
|
||||||
|
|
||||||
|
$result = $conn->query($sql);
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
while($row = $result->fetch_assoc()) {
|
||||||
|
// Hitung kategori berdasarkan jumlah_kk dari tabel kemiskinan
|
||||||
|
$jumlah = intval($row['jumlah_kk'] ?? 1);
|
||||||
|
$kategori = 'Hampir Miskin';
|
||||||
|
$badge_color = '#3b82f6'; // Blue
|
||||||
|
|
||||||
|
if($jumlah >= 5) {
|
||||||
|
$kategori = 'Sangat Miskin';
|
||||||
|
$badge_color = '#dc2626'; // Red
|
||||||
|
} else if($jumlah >= 3) {
|
||||||
|
$kategori = 'Miskin';
|
||||||
|
$badge_color = '#ea580c'; // Orange
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hitung umur
|
||||||
|
$usia = '-';
|
||||||
|
if (!empty($row['tanggal_lahir'])) {
|
||||||
|
$bday = new DateTime($row['tanggal_lahir']);
|
||||||
|
$today = new DateTime('today');
|
||||||
|
$usia = $bday->diff($today)->y . ' thn';
|
||||||
|
$tgl_format = $bday->format('d M Y');
|
||||||
|
} else {
|
||||||
|
$tgl_format = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
$row['kategori_label'] = $kategori;
|
||||||
|
$row['kategori_color'] = $badge_color;
|
||||||
|
$row['usia_label'] = $usia;
|
||||||
|
$row['tgl_lahir_format'] = $tgl_format;
|
||||||
|
|
||||||
|
$data[] = $row;
|
||||||
|
}
|
||||||
|
echo json_encode(["status" => "success", "data" => $data]);
|
||||||
|
} else {
|
||||||
|
echo json_encode(["status" => "error", "message" => $conn->error]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$conn->close();
|
||||||
|
?>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db_config.php';
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$kemiskinan_id = isset($_GET['kemiskinan_id']) ? intval($_GET['kemiskinan_id']) : 0;
|
||||||
|
|
||||||
|
if ($kemiskinan_id <= 0) {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'Invalid ID']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt = $conn->prepare("SELECT * FROM warga WHERE kemiskinan_id = ? ORDER BY id ASC");
|
||||||
|
$stmt->bind_param("i", $kemiskinan_id);
|
||||||
|
$stmt->execute();
|
||||||
|
$res = $stmt->get_result();
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
while ($row = $res->fetch_assoc()) {
|
||||||
|
$data[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode(['status' => 'success', 'data' => $data]);
|
||||||
|
$stmt->close();
|
||||||
|
$conn->close();
|
||||||
|
?>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
include "db_config.php";
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents("php://input"), true);
|
||||||
|
|
||||||
|
$kemiskinan_id = intval($data['kemiskinan_id'] ?? 0);
|
||||||
|
$jenis_bantuan = $conn->real_escape_string($data['jenis_bantuan'] ?? '');
|
||||||
|
$tanggal = $conn->real_escape_string($data['tanggal'] ?? '');
|
||||||
|
$keterangan = $conn->real_escape_string($data['keterangan'] ?? '');
|
||||||
|
|
||||||
|
if ($kemiskinan_id <= 0 || empty($jenis_bantuan) || empty($tanggal)) {
|
||||||
|
echo json_encode(["status" => "error", "message" => "Data tidak valid. Kemiskinan ID, jenis bantuan, dan tanggal wajib diisi."]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "INSERT INTO histori_bantuan (kemiskinan_id, jenis_bantuan, tanggal, keterangan)
|
||||||
|
VALUES ($kemiskinan_id, '$jenis_bantuan', '$tanggal', '$keterangan')";
|
||||||
|
|
||||||
|
if ($conn->query($sql)) {
|
||||||
|
echo json_encode(["status" => "success", "id" => $conn->insert_id]);
|
||||||
|
} else {
|
||||||
|
echo json_encode(["status" => "error", "message" => $conn->error]);
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
include "db_config.php";
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents("php://input"), true);
|
||||||
|
|
||||||
|
$nama_kk = $conn->real_escape_string($data['nama_kk'] ?? '');
|
||||||
|
$jumlah_kk = intval($data['jumlah_kk'] ?? 1);
|
||||||
|
$alamat = $conn->real_escape_string($data['alamat'] ?? '');
|
||||||
|
$lat = floatval($data['lat'] ?? 0);
|
||||||
|
$lng = floatval($data['lng'] ?? 0);
|
||||||
|
$kondisi_rumah = $conn->real_escape_string($data['kondisi_rumah'] ?? 'Sedang');
|
||||||
|
$akses_air = intval($data['akses_air_bersih'] ?? 0);
|
||||||
|
$akses_listrik = intval($data['akses_listrik'] ?? 0);
|
||||||
|
$akses_kesehatan = intval($data['akses_kesehatan'] ?? 0);
|
||||||
|
$anak_putus = intval($data['anak_putus_sekolah'] ?? 0);
|
||||||
|
$surveyor = $conn->real_escape_string($data['surveyor'] ?? '');
|
||||||
|
$keterangan = $conn->real_escape_string($data['keterangan'] ?? '');
|
||||||
|
// Kolom baru
|
||||||
|
$tanggal_lahir = $conn->real_escape_string($data['tanggal_lahir'] ?? '');
|
||||||
|
$pendidikan = $conn->real_escape_string($data['pendidikan'] ?? '');
|
||||||
|
$riwayat_penyakit = $conn->real_escape_string($data['riwayat_penyakit'] ?? '');
|
||||||
|
|
||||||
|
$tgl_val = !empty($tanggal_lahir) ? "'$tanggal_lahir'" : "NULL";
|
||||||
|
|
||||||
|
$sql = "INSERT INTO kemiskinan
|
||||||
|
(nama_kk, jumlah_kk, alamat, lat, lng,
|
||||||
|
kondisi_rumah, akses_air_bersih, akses_listrik, akses_kesehatan,
|
||||||
|
anak_putus_sekolah, surveyor, keterangan,
|
||||||
|
tanggal_lahir, pendidikan, riwayat_penyakit)
|
||||||
|
VALUES
|
||||||
|
('$nama_kk', $jumlah_kk, '$alamat', '$lat', '$lng',
|
||||||
|
'$kondisi_rumah', $akses_air, $akses_listrik, $akses_kesehatan,
|
||||||
|
$anak_putus, '$surveyor', '$keterangan',
|
||||||
|
$tgl_val, '$pendidikan', '$riwayat_penyakit')";
|
||||||
|
|
||||||
|
if ($conn->query($sql)) {
|
||||||
|
$new_id = $conn->insert_id;
|
||||||
|
// Otomatis masukkan Kepala Keluarga ke tabel warga
|
||||||
|
$sql_warga = "INSERT INTO warga (kemiskinan_id, nama_warga, hubungan_keluarga, tanggal_lahir, pendidikan, riwayat_penyakit)
|
||||||
|
VALUES ($new_id, '$nama_kk', 'Kepala Keluarga', $tgl_val, '$pendidikan', '$riwayat_penyakit')";
|
||||||
|
$conn->query($sql_warga);
|
||||||
|
|
||||||
|
echo json_encode(["status" => "success", "id" => $new_id]);
|
||||||
|
} else {
|
||||||
|
echo json_encode(["status" => "error", "message" => $conn->error]);
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
include "db_config.php";
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents("php://input"), true);
|
||||||
|
|
||||||
|
$nama_pelapor = $conn->real_escape_string($data['nama_pelapor'] ?? '');
|
||||||
|
$kontak = $conn->real_escape_string($data['kontak'] ?? '');
|
||||||
|
$deskripsi_laporan = $conn->real_escape_string($data['deskripsi_laporan'] ?? '');
|
||||||
|
$alamat = $conn->real_escape_string($data['alamat'] ?? '');
|
||||||
|
$foto = $conn->real_escape_string($data['foto'] ?? '');
|
||||||
|
|
||||||
|
if (empty($nama_pelapor) || empty($deskripsi_laporan)) {
|
||||||
|
echo json_encode(["status" => "error", "message" => "Nama pelapor dan deskripsi wajib diisi"]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "INSERT INTO laporan_masyarakat (nama_pelapor, kontak, deskripsi_laporan, alamat, foto, status)
|
||||||
|
VALUES ('$nama_pelapor', '$kontak', '$deskripsi_laporan', '$alamat', '$foto', 'menunggu')";
|
||||||
|
|
||||||
|
if ($conn->query($sql)) {
|
||||||
|
echo json_encode(["status" => "success", "id" => $conn->insert_id]);
|
||||||
|
} else {
|
||||||
|
echo json_encode(["status" => "error", "message" => $conn->error]);
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
include "db_config.php";
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents("php://input"), true);
|
||||||
|
|
||||||
|
$nama_masjid = $conn->real_escape_string($data['nama_masjid'] ?? '');
|
||||||
|
$pic_masjid = $conn->real_escape_string($data['pic_masjid'] ?? '');
|
||||||
|
$alamat_masjid = $conn->real_escape_string($data['alamat_masjid'] ?? '');
|
||||||
|
$radius = isset($data['radius']) ? intval($data['radius']) : 500;
|
||||||
|
$lat = $data['lat'];
|
||||||
|
$lng = $data['lng'];
|
||||||
|
|
||||||
|
$sql = "INSERT INTO rumah_ibadah (nama_rumah_ibadah, penanggung_jawab, alamat, radius, lat, lng)
|
||||||
|
VALUES ('$nama_masjid', '$pic_masjid', '$alamat_masjid', $radius, '$lat', '$lng')";
|
||||||
|
|
||||||
|
if($conn->query($sql)){
|
||||||
|
echo json_encode([
|
||||||
|
"status"=>"success",
|
||||||
|
"id"=>$conn->insert_id
|
||||||
|
]);
|
||||||
|
}else{
|
||||||
|
echo json_encode(["status"=>"error", "message"=>$conn->error]);
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db_config.php';
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents('php://input'), true);
|
||||||
|
|
||||||
|
if (!$data || !isset($data['kemiskinan_id']) || !isset($data['nama_warga'])) {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'Data tidak lengkap']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$kemiskinan_id = intval($data['kemiskinan_id']);
|
||||||
|
$nik = $data['nik'] ?? '';
|
||||||
|
$nama_warga = $data['nama_warga'];
|
||||||
|
$hubungan = $data['hubungan_keluarga'] ?? '';
|
||||||
|
$tanggal_lahir = empty($data['tanggal_lahir']) ? null : $data['tanggal_lahir'];
|
||||||
|
$pendidikan = $data['pendidikan'] ?? '';
|
||||||
|
$riwayat = $data['riwayat_penyakit'] ?? '';
|
||||||
|
|
||||||
|
$stmt = $conn->prepare("INSERT INTO warga (kemiskinan_id, nik, nama_warga, hubungan_keluarga, tanggal_lahir, pendidikan, riwayat_penyakit) VALUES (?, ?, ?, ?, ?, ?, ?)");
|
||||||
|
$stmt->bind_param("issssss", $kemiskinan_id, $nik, $nama_warga, $hubungan, $tanggal_lahir, $pendidikan, $riwayat);
|
||||||
|
|
||||||
|
if ($stmt->execute()) {
|
||||||
|
echo json_encode(['status' => 'success', 'id' => $stmt->insert_id]);
|
||||||
|
} else {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => $stmt->error]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt->close();
|
||||||
|
$conn->close();
|
||||||
|
?>
|
||||||
Binary file not shown.
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
include "db_config.php";
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents("php://input"), true);
|
||||||
|
|
||||||
|
$id = isset($data['id']) ? intval($data['id']) : 0;
|
||||||
|
$nama_kk = $conn->real_escape_string($data['nama_kk'] ?? '');
|
||||||
|
$jumlah_kk = isset($data['jumlah_kk']) ? intval($data['jumlah_kk']) : 1;
|
||||||
|
$alamat = $conn->real_escape_string($data['alamat'] ?? '');
|
||||||
|
$lat = isset($data['lat']) ? floatval($data['lat']) : 0;
|
||||||
|
$lng = isset($data['lng']) ? floatval($data['lng']) : 0;
|
||||||
|
$tanggal_lahir = $conn->real_escape_string($data['tanggal_lahir'] ?? '');
|
||||||
|
$pendidikan = $conn->real_escape_string($data['pendidikan'] ?? '');
|
||||||
|
$riwayat_penyakit = $conn->real_escape_string($data['riwayat_penyakit'] ?? '');
|
||||||
|
|
||||||
|
if ($id <= 0 || $nama_kk === '') {
|
||||||
|
echo json_encode(["status" => "error", "message" => "Data tidak valid"]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tgl_val = !empty($tanggal_lahir) ? "'$tanggal_lahir'" : "NULL";
|
||||||
|
|
||||||
|
// 1. Update tabel kemiskinan
|
||||||
|
$sql = "UPDATE kemiskinan SET
|
||||||
|
nama_kk='$nama_kk',
|
||||||
|
jumlah_kk=$jumlah_kk,
|
||||||
|
alamat='$alamat',
|
||||||
|
lat='$lat',
|
||||||
|
lng='$lng',
|
||||||
|
tanggal_lahir=$tgl_val,
|
||||||
|
pendidikan='$pendidikan',
|
||||||
|
riwayat_penyakit='$riwayat_penyakit'
|
||||||
|
WHERE id=$id";
|
||||||
|
|
||||||
|
if ($conn->query($sql)) {
|
||||||
|
// 2. Sync data ke tabel warga (baris Kepala Keluarga)
|
||||||
|
$sql_warga = "UPDATE warga SET
|
||||||
|
nama_warga='$nama_kk',
|
||||||
|
tanggal_lahir=$tgl_val,
|
||||||
|
pendidikan='$pendidikan',
|
||||||
|
riwayat_penyakit='$riwayat_penyakit'
|
||||||
|
WHERE kemiskinan_id=$id AND hubungan_keluarga='Kepala Keluarga'";
|
||||||
|
$conn->query($sql_warga);
|
||||||
|
|
||||||
|
echo json_encode(["status" => "success"]);
|
||||||
|
} else {
|
||||||
|
echo json_encode(["status" => "error", "message" => $conn->error]);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
include "db_config.php";
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents("php://input"), true);
|
||||||
|
|
||||||
|
$id = intval($data['id'] ?? 0);
|
||||||
|
$status = $conn->real_escape_string($data['status'] ?? '');
|
||||||
|
|
||||||
|
if ($id <= 0 || !in_array($status, ['menunggu', 'diproses', 'selesai'])) {
|
||||||
|
echo json_encode(["status" => "error", "message" => "Data tidak valid"]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "UPDATE laporan_masyarakat SET status='$status' WHERE id=$id";
|
||||||
|
|
||||||
|
if ($conn->query($sql)) {
|
||||||
|
echo json_encode(["status" => "success"]);
|
||||||
|
} else {
|
||||||
|
echo json_encode(["status" => "error", "message" => $conn->error]);
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
include "db_config.php";
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents("php://input"), true);
|
||||||
|
|
||||||
|
$id = isset($data['id']) ? intval($data['id']) : 0;
|
||||||
|
$nama_masjid = $conn->real_escape_string($data['nama_masjid'] ?? '');
|
||||||
|
$pic_masjid = $conn->real_escape_string($data['pic_masjid'] ?? '');
|
||||||
|
$alamat_masjid = $conn->real_escape_string($data['alamat_masjid'] ?? '');
|
||||||
|
$radius = isset($data['radius']) ? intval($data['radius']) : 500;
|
||||||
|
$lat = isset($data['lat']) ? floatval($data['lat']) : 0;
|
||||||
|
$lng = isset($data['lng']) ? floatval($data['lng']) : 0;
|
||||||
|
|
||||||
|
if ($id <= 0 || $nama_masjid === '') {
|
||||||
|
echo json_encode(["status" => "error", "message" => "Data tidak valid"]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "UPDATE rumah_ibadah SET nama_rumah_ibadah='$nama_masjid', penanggung_jawab='$pic_masjid', alamat='$alamat_masjid', radius=$radius, lat='$lat', lng='$lng' WHERE id=$id";
|
||||||
|
|
||||||
|
if ($conn->query($sql)) {
|
||||||
|
echo json_encode(["status" => "success"]);
|
||||||
|
} else {
|
||||||
|
echo json_encode(["status" => "error", "message" => $conn->error]);
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') { echo json_encode(['status'=>'error']); exit(); }
|
||||||
|
require_once 'db_config.php';
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents('php://input'), true);
|
||||||
|
$username = trim($data['username'] ?? '');
|
||||||
|
$nama = trim($data['nama_lengkap'] ?? '');
|
||||||
|
|
||||||
|
if (!$username || !$nama) {
|
||||||
|
echo json_encode(['status'=>'error','message'=>'Data tidak valid']);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt = $conn->prepare("UPDATE users SET nama_lengkap=? WHERE username=?");
|
||||||
|
$stmt->bind_param('ss', $nama, $username);
|
||||||
|
|
||||||
|
if ($stmt->execute()) {
|
||||||
|
echo json_encode(['status'=>'success','message'=>'Profil berhasil diperbarui']);
|
||||||
|
} else {
|
||||||
|
echo json_encode(['status'=>'error','message'=>'Gagal memperbarui profil']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt->close();
|
||||||
|
$conn->close();
|
||||||
|
?>
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
include "db_config.php";
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents("php://input"), true);
|
||||||
|
$id = isset($data['id']) ? intval($data['id']) : 0;
|
||||||
|
$status = isset($data['status']) ? $conn->real_escape_string($data['status']) : '';
|
||||||
|
|
||||||
|
$allowed = ['Belum Ditangani', 'Diproses', 'Sudah Ditangani'];
|
||||||
|
if ($id <= 0 || !in_array($status, $allowed)) {
|
||||||
|
echo json_encode(["status" => "error", "message" => "Data tidak valid"]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "UPDATE kemiskinan SET status_penanganan='$status', updated_at=NOW() WHERE id=$id";
|
||||||
|
|
||||||
|
if ($conn->query($sql)) {
|
||||||
|
echo json_encode(["status" => "success"]);
|
||||||
|
} else {
|
||||||
|
echo json_encode(["status" => "error", "message" => $conn->error]);
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') { echo json_encode(['status'=>'error']); exit(); }
|
||||||
|
require_once 'db_config.php';
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents('php://input'), true);
|
||||||
|
$id = intval($data['id'] ?? 0);
|
||||||
|
$nama = trim($data['nama_lengkap'] ?? '');
|
||||||
|
$role = trim($data['role'] ?? '');
|
||||||
|
$pass = $data['password'] ?? '';
|
||||||
|
|
||||||
|
if (!$id || !$nama || !in_array($role, ['admin','operator'])) {
|
||||||
|
echo json_encode(['status'=>'error','message'=>'Data tidak valid']);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($pass) {
|
||||||
|
if (strlen($pass) < 6) { echo json_encode(['status'=>'error','message'=>'Password minimal 6 karakter']); exit(); }
|
||||||
|
$hashed = password_hash($pass, PASSWORD_DEFAULT);
|
||||||
|
$stmt = $conn->prepare("UPDATE users SET nama_lengkap=?, role=?, password=? WHERE id=?");
|
||||||
|
$stmt->bind_param('sssi', $nama, $role, $hashed, $id);
|
||||||
|
} else {
|
||||||
|
$stmt = $conn->prepare("UPDATE users SET nama_lengkap=?, role=? WHERE id=?");
|
||||||
|
$stmt->bind_param('ssi', $nama, $role, $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $stmt->execute()
|
||||||
|
? json_encode(['status'=>'success','message'=>'Akun berhasil diperbarui'])
|
||||||
|
: json_encode(['status'=>'error','message'=>'Gagal memperbarui akun']);
|
||||||
|
|
||||||
|
$stmt->close();
|
||||||
|
$conn->close();
|
||||||
|
?>
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db_config.php';
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$data = json_decode(file_get_contents('php://input'), true);
|
||||||
|
|
||||||
|
if (!$data || !isset($data['id']) || !isset($data['nama_warga'])) {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'Data tidak lengkap']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = intval($data['id']);
|
||||||
|
$nik = $data['nik'] ?? '';
|
||||||
|
$nama_warga = $data['nama_warga'];
|
||||||
|
$hubungan = $data['hubungan_keluarga'] ?? '';
|
||||||
|
$tanggal_lahir = empty($data['tanggal_lahir']) ? null : $data['tanggal_lahir'];
|
||||||
|
$pendidikan = $data['pendidikan'] ?? '';
|
||||||
|
$riwayat = $data['riwayat_penyakit'] ?? '';
|
||||||
|
|
||||||
|
$stmt = $conn->prepare("UPDATE warga SET nik=?, nama_warga=?, hubungan_keluarga=?, tanggal_lahir=?, pendidikan=?, riwayat_penyakit=? WHERE id=?");
|
||||||
|
$stmt->bind_param("ssssssi", $nik, $nama_warga, $hubungan, $tanggal_lahir, $pendidikan, $riwayat, $id);
|
||||||
|
|
||||||
|
if ($stmt->execute()) {
|
||||||
|
echo json_encode(['status' => 'success']);
|
||||||
|
} else {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => $stmt->error]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt->close();
|
||||||
|
$conn->close();
|
||||||
|
?>
|
||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Reference in New Issue
Block a user