update sistem proyek menjadi lebih struktural. dimulai dengan memisahkan dashboard publik dan administrator pada setiap proyek, membuat dockerfile untuk setup environment docker, dan merapikan database serta membuat file migration.

This commit is contained in:
2026-06-10 17:44:46 +07:00
parent c6087ed7dd
commit e98a8ecec9
34 changed files with 963 additions and 211 deletions
+45
View File
@@ -0,0 +1,45 @@
<?php
function start_app_session()
{
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start();
}
}
function current_user_role()
{
start_app_session();
return $_SESSION['role'] ?? null;
}
function user_has_role(array $allowed_roles)
{
$role = current_user_role();
return $role !== null && in_array($role, $allowed_roles, true);
}
function require_roles_json(array $allowed_roles)
{
if (!user_has_role($allowed_roles)) {
http_response_code(401);
header('Content-Type: application/json');
echo json_encode([
"message" => "Akses ditolak. Silakan login dengan akun yang berwenang."
]);
exit;
}
}
function require_write_access_json()
{
require_roles_json(['admin']);
}
function require_roles_page(array $allowed_roles, $login_path = 'login.php')
{
if (!user_has_role($allowed_roles)) {
header('Location: ' . $login_path);
exit;
}
}
?>
+20 -2
View File
@@ -1,7 +1,25 @@
<?php
$conn = new mysqli("localhost", "root", "bobbyandreanjapri", "webgis_spbu");
function env_value($keys, $default = '')
{
foreach ($keys as $key) {
$value = getenv($key);
if ($value !== false && $value !== '') {
return $value;
}
}
return $default;
}
$db_host = env_value(['DB_HOST', 'MYSQL_HOST', 'MYSQL_SERVER'], 'localhost');
$db_port = intval(env_value(['DB_PORT', 'MYSQL_PORT'], 3306));
$db_name = env_value(['DB_DATABASE', 'MYSQL_DATABASE', 'MYSQL_DB'], 'webgis_spbu');
$db_user = env_value(['DB_USERNAME', 'MYSQL_USER'], 'root');
$db_pass = env_value(['DB_PASSWORD', 'MYSQL_PASSWORD', 'MYSQL_ROOT_PASSWORD'], '');
$conn = new mysqli($db_host, $db_user, $db_pass, $db_name, $db_port);
if ($conn->connect_error) {
die(json_encode(["error" => "Koneksi gagal: " . $conn->connect_error]));
}
$conn->set_charset("utf8");
$conn->set_charset("utf8mb4");
?>
+5 -2
View File
@@ -1,4 +1,6 @@
<?php
require_once 'auth.php';
require_write_access_json();
header('Content-Type: application/json');
include 'db.php';
@@ -11,7 +13,8 @@ if ($id == 0 || $type == '') {
}
$table = '';
if ($type == 'point') $table = 'spbu';
if ($type == 'point') $table = 'points';
if ($type == 'spbu') $table = 'spbu';
if ($type == 'line') $table = 'jalan';
if ($type == 'polygon') $table = 'parsil';
if ($type == 'masjid') $table = 'masjid';
@@ -30,4 +33,4 @@ if ($stmt->execute()) {
} else {
echo json_encode(["message" => "Gagal hapus", "error" => $stmt->error]);
}
?>
?>
+2
View File
@@ -1,4 +1,6 @@
<?php
require_once 'auth.php';
require_write_access_json();
header('Content-Type: application/json');
include 'db.php';
+2
View File
@@ -1,4 +1,6 @@
<?php
require_once 'auth.php';
require_write_access_json();
header('Content-Type: application/json');
include 'db.php';
+3 -1
View File
@@ -1,4 +1,6 @@
<?php
require_once 'auth.php';
require_write_access_json();
header('Content-Type: application/json');
include 'db.php';
@@ -22,4 +24,4 @@ if ($stmt->execute()) {
echo json_encode(["message"=>"Gagal", "error"=>$stmt->error]);
}
$stmt->close(); $conn->close();
?>
?>
+3 -1
View File
@@ -1,4 +1,6 @@
<?php
require_once 'auth.php';
require_write_access_json();
header('Content-Type: application/json');
include 'db.php';
@@ -48,4 +50,4 @@ if ($stmt->execute()) {
echo json_encode(["message"=>"Gagal", "error"=>$stmt->error]);
}
$stmt->close(); $conn->close();
?>
?>
+35
View File
@@ -0,0 +1,35 @@
<?php
require_once 'auth.php';
require_write_access_json();
header('Content-Type: application/json');
include 'db.php';
$data = json_decode(file_get_contents("php://input"), true);
if (!$data) {
echo json_encode(["message" => "Data tidak diterima"]);
exit;
}
$nama = $data['nama'] ?? '';
$kode = $data['no'] ?? '';
$lat = $data['lat'] ?? '';
$lng = $data['lng'] ?? '';
if ($nama === '' || $kode === '' || $lat === '' || $lng === '') {
echo json_encode(["message" => "Field tidak lengkap"]);
exit;
}
$stmt = $conn->prepare("INSERT INTO points (nama, kode_point, latitude, longitude) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssdd", $nama, $kode, $lat, $lng);
if ($stmt->execute()) {
echo json_encode(["message" => "Data berhasil disimpan", "id" => $stmt->insert_id]);
} else {
echo json_encode(["message" => "Gagal simpan", "error" => $stmt->error]);
}
$stmt->close();
$conn->close();
?>
+2
View File
@@ -1,4 +1,6 @@
<?php
require_once 'auth.php';
require_write_access_json();
header('Content-Type: application/json');
include 'db.php';
+1 -1
View File
@@ -5,7 +5,7 @@ include 'db.php';
$data = [];
/* POINT */
$res = $conn->query("SELECT * FROM spbu");
$res = $conn->query("SELECT id, nama, kode_point AS no_spbu, latitude, longitude FROM points");
if ($res) {
while ($r = $res->fetch_assoc()) {
$r['type'] = 'point';
+2
View File
@@ -1,4 +1,6 @@
<?php
require_once 'auth.php';
require_write_access_json();
header('Content-Type: application/json');
include 'db.php';
+2
View File
@@ -1,4 +1,6 @@
<?php
require_once 'auth.php';
require_write_access_json();
header('Content-Type: application/json');
include 'db.php';
+2
View File
@@ -1,4 +1,6 @@
<?php
require_once 'auth.php';
require_write_access_json();
header('Content-Type: application/json');
include 'db.php';
+2
View File
@@ -1,4 +1,6 @@
<?php
require_once 'auth.php';
require_write_access_json();
header('Content-Type: application/json');
include 'db.php';