72 lines
1.5 KiB
PHP
72 lines
1.5 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
|
|
require_once(__DIR__ . '/include/headscript.php');
|
|
|
|
try {
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
|
|
$iduser = $iduserlogin ?? null;
|
|
|
|
$input = json_decode(file_get_contents('php://input'), true);
|
|
$id = (int)($input['id'] ?? 0);
|
|
|
|
if ($id <= 0) {
|
|
throw new Exception('ID non valido.');
|
|
}
|
|
|
|
if ($iduser === null) {
|
|
$stmt = $pdo->prepare("
|
|
SELECT *
|
|
FROM cad_area_jobs
|
|
WHERE id = :id
|
|
LIMIT 1
|
|
");
|
|
|
|
$stmt->execute([
|
|
':id' => $id
|
|
]);
|
|
} else {
|
|
$stmt = $pdo->prepare("
|
|
SELECT *
|
|
FROM cad_area_jobs
|
|
WHERE id = :id
|
|
AND iduser = :iduser
|
|
LIMIT 1
|
|
");
|
|
|
|
$stmt->execute([
|
|
':id' => $id,
|
|
':iduser' => $iduser
|
|
]);
|
|
}
|
|
|
|
$job = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$job) {
|
|
throw new Exception('Record non trovato.');
|
|
}
|
|
|
|
if (!empty($job['file_path']) && file_exists($job['file_path'])) {
|
|
unlink($job['file_path']);
|
|
}
|
|
|
|
$stmtDelete = $pdo->prepare("
|
|
DELETE FROM cad_area_jobs
|
|
WHERE id = :id
|
|
");
|
|
$stmtDelete->execute([':id' => $id]);
|
|
|
|
echo json_encode([
|
|
'success' => true
|
|
]);
|
|
} catch (Throwable $e) {
|
|
error_log('CAD area delete error: ' . $e->getMessage());
|
|
|
|
echo json_encode([
|
|
'success' => false,
|
|
'message' => $e->getMessage()
|
|
]);
|
|
}
|