85 lines
2.7 KiB
PHP
85 lines
2.7 KiB
PHP
<?php
|
|
header("Access-Control-Allow-Origin: *");
|
|
header("Content-Type: application/json; charset=UTF-8");
|
|
header("Access-Control-Allow-Methods: DELETE");
|
|
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)) {
|
|
try {
|
|
$query = "DELETE FROM spbu WHERE id = :id";
|
|
$stmt = $db->prepare($query);
|
|
$stmt->bindParam(":id", $data->id);
|
|
|
|
if ($stmt->execute()) {
|
|
http_response_code(200);
|
|
echo json_encode(array("message" => "SPBU berhasil dihapus"));
|
|
} else {
|
|
http_response_code(503);
|
|
echo json_encode(array("message" => "Gagal menghapus SPBU"));
|
|
}
|
|
} 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" => "ID tidak ditemukan"));
|
|
}
|
|
?><?php
|
|
header("Access-Control-Allow-Origin: *");
|
|
header("Content-Type: application/json; charset=UTF-8");
|
|
header("Access-Control-Allow-Methods: DELETE");
|
|
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)) {
|
|
try {
|
|
$query = "DELETE FROM spbu WHERE id = :id";
|
|
$stmt = $db->prepare($query);
|
|
$stmt->bindParam(":id", $data->id);
|
|
|
|
if ($stmt->execute()) {
|
|
http_response_code(200);
|
|
echo json_encode(array("message" => "SPBU berhasil dihapus"));
|
|
} else {
|
|
http_response_code(503);
|
|
echo json_encode(array("message" => "Gagal menghapus SPBU"));
|
|
}
|
|
} 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" => "ID tidak ditemukan"));
|
|
}
|
|
?>
|