mengubah sistem menjadi lebih terfokus ke poverty

This commit is contained in:
Abimanyu Ridho
2026-06-11 01:50:37 +07:00
parent 739e360018
commit 468541b1c8
46 changed files with 5753 additions and 2805 deletions
+4 -2
View File
@@ -6,10 +6,11 @@ mysqli_report(MYSQLI_REPORT_OFF);
if (!function_exists('loadDatabaseConfig')) {
function loadDatabaseConfig(): array {
$config = [
'host' => getenv('DB_HOST') ?: 'localhost',
'host' => getenv('DB_HOST') ?: '127.0.0.1',
'user' => getenv('DB_USER') ?: 'root',
'pass' => getenv('DB_PASS') ?: '',
'name' => getenv('DB_NAME') ?: 'webgis_poverty',
'port' => (int)(getenv('DB_PORT') ?: 3306),
'charset' => getenv('DB_CHARSET') ?: 'utf8mb4',
];
@@ -31,12 +32,13 @@ define('DB_HOST', $dbConfig['host']);
define('DB_USER', $dbConfig['user']);
define('DB_PASS', $dbConfig['pass']);
define('DB_NAME', $dbConfig['name']);
define('DB_PORT', (int)$dbConfig['port']);
define('DB_CHARSET', $dbConfig['charset']);
function getDB(): mysqli {
static $conn = null;
if ($conn === null) {
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT);
if ($conn->connect_error) {
error_log('DB connection failed: ' . $conn->connect_error);
http_response_code(500);
+51
View File
@@ -0,0 +1,51 @@
<?php
// api/config/setup_users.php
require_once __DIR__ . '/database.php';
$db = getDB();
// Create users table
$sql = "CREATE TABLE IF NOT EXISTS `users` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`username` VARCHAR(50) NOT NULL UNIQUE,
`password` VARCHAR(255) NOT NULL,
`role` ENUM('admin', 'petugas_lapangan', 'guest') NOT NULL,
`rumah_ibadah_id` INT DEFAULT NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`rumah_ibadah_id`) REFERENCES `rumah_ibadah` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
if ($db->query($sql)) {
echo "Tabel 'users' berhasil dibuat atau sudah ada.\n";
} else {
echo "Gagal membuat tabel 'users': " . $db->error . "\n";
exit(1);
}
// Insert default users if they don't exist
$defaultUsers = [
[
'username' => 'admin',
'password' => password_hash('admin123', PASSWORD_BCRYPT),
'role' => 'admin'
]
];
foreach ($defaultUsers as $user) {
$stmt = $db->prepare("SELECT id FROM users WHERE username = ?");
$stmt->bind_param('s', $user['username']);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows === 0) {
$stmtInsert = $db->prepare("INSERT INTO users (username, password, role) VALUES (?, ?, ?)");
$stmtInsert->bind_param('sss', $user['username'], $user['password'], $user['role']);
if ($stmtInsert->execute()) {
echo "User '" . $user['username'] . "' berhasil ditambahkan.\n";
} else {
echo "Gagal menambahkan user '" . $user['username'] . "': " . $stmtInsert->error . "\n";
}
} else {
echo "User '" . $user['username'] . "' sudah ada.\n";
}
}
echo "Setup database selesai.\n";