31 lines
913 B
PHP
31 lines
913 B
PHP
<?php
|
|
include 'koneksi.php';
|
|
header('Content-Type: application/json');
|
|
|
|
if (!isset($_POST['id_account'])) {
|
|
echo json_encode(["status" => "error", "message" => "ID tidak valid"]);
|
|
exit;
|
|
}
|
|
|
|
$id = $_POST['id_account'];
|
|
|
|
try {
|
|
$stmt = $pdo->prepare("SELECT status FROM account WHERE id_account = ?");
|
|
$stmt->execute([$id]);
|
|
$currentStatus = $stmt->fetchColumn();
|
|
|
|
if ($currentStatus) {
|
|
$newStatus = ($currentStatus === 'approved') ? 'rejected' : 'approved';
|
|
$update = $pdo->prepare("UPDATE account SET status = ? WHERE id_account = ?");
|
|
$update->execute([$newStatus, $id]);
|
|
echo json_encode(["status" => "success", "new_status" => $newStatus]);
|
|
}
|
|
else {
|
|
echo json_encode(["status" => "error", "message" => "Data tidak ditemukan"]);
|
|
}
|
|
}
|
|
catch (Exception $e) {
|
|
echo json_encode(["status" => "error", "message" => $e->getMessage()]);
|
|
}
|
|
?>
|