Initial Commit: Tugas Semua Pertemuan

This commit is contained in:
2026-06-08 22:49:54 +07:00
commit 51ea70b6ce
51 changed files with 6841 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: PUT");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
session_start();
require_once '../config/database.php';
if (!isset($_SESSION['is_admin']) || $_SESSION['is_admin'] !== true) {
http_response_code(401);
echo json_encode(array("message" => "Unauthorized"));
exit();
}
$database = new Database();
$db = $database->getConnection();
$data = json_decode(file_get_contents("php://input"));
if (!empty($data->id) && !empty($data->latitude) && !empty($data->longitude)) {
try {
$query = "UPDATE spbu SET latitude = :latitude, longitude = :longitude WHERE id = :id";
$stmt = $db->prepare($query);
$stmt->bindParam(":latitude", $data->latitude);
$stmt->bindParam(":longitude", $data->longitude);
$stmt->bindParam(":id", $data->id);
if ($stmt->execute()) {
http_response_code(200);
echo json_encode(array("message" => "Posisi SPBU berhasil diupdate"));
} else {
http_response_code(503);
echo json_encode(array("message" => "Gagal mengupdate posisi"));
}
} catch(PDOException $e) {
http_response_code(500);
echo json_encode(array("message" => "Error: " . $e->getMessage()));
}
} else {
http_response_code(400);
echo json_encode(array("message" => "Data tidak lengkap"));
}
?>