Files
trf_certest/public/userarea/delete_binding.php
T
2026-06-13 20:19:36 +03:00

41 lines
1.1 KiB
PHP

<?php
// Elimina un binding JSON -> LIMS. Ritorna JSON.
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
require_once __DIR__ . '/class/db-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;
}
$id = intval($_POST['id'] ?? 0);
if ($id <= 0) {
http_response_code(422);
echo json_encode(['success' => false, 'error' => 'Missing id']);
exit;
}
try {
$pdo = DBHandlerSelect::getInstance()->getConnection();
$stmt = $pdo->prepare("DELETE FROM json_lims_binding WHERE id = ?");
$stmt->execute([$id]);
echo json_encode(['success' => true, 'deleted' => $stmt->rowCount()]);
} catch (Exception $e) {
http_response_code(500);
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}