Files
trf_certest/public/userarea/delete_binding.php
T
2026-09-23 15:50:03 +03:00

41 lines
1.1 KiB
PHP

<?php
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
require_once __DIR__ . '/class/db-functions.php';
require_once __DIR__ . '/class/binding-functions.php';
include dirname(__DIR__) . '/../extra/auth.php';
header('Content-Type: application/json');
ini_set('display_errors', '0');
error_reporting(E_ALL);
if (!Auth::check()) {
http_response_code(401);
echo json_encode(['success' => false, 'error' => 'Unauthorized']);
exit;
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
echo json_encode(['success' => false, 'error' => 'Method not allowed']);
exit;
}
$bindingId = intval($_POST['binding_id'] ?? 0);
if ($bindingId <= 0) {
http_response_code(422);
echo json_encode(['success' => false, 'error' => 'Missing binding_id']);
exit;
}
try {
$pdo = DBHandlerSelect::getInstance()->getConnection();
$deleted = binding_delete_by_id($pdo, $bindingId);
echo json_encode(['success' => $deleted > 0, 'deleted' => $deleted]);
} catch (Exception $e) {
http_response_code(500);
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}