Files
zibo-dashboard/public/userarea/delete_tool.php
T
2026-08-12 21:29:55 +03:00

45 lines
1.3 KiB
PHP

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
header('Content-Type: application/json');
require_once 'include/headscript.php';
/**
* Soft-deletes a tool: it is marked as decommissioned, not removed, because
* production records reference it (productiondata_tools.tool_id).
*
* production_tools is now the unified registry inv_equipment.
*
* Note: the page calls this endpoint with GET ?id=..., while the previous
* version only read $_POST['id'] and required a name — so deletion always
* failed with "Invalid ID.". Both methods are accepted now.
*/
try {
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
$id = (int)($_POST['id'] ?? $_GET['id'] ?? 0);
if ($id <= 0) {
echo json_encode(['success' => false, 'message' => 'Invalid ID.']);
exit;
}
$stmt = $pdo->prepare("SELECT id FROM inv_equipment WHERE id = ?");
$stmt->execute([$id]);
if (!$stmt->fetchColumn()) {
echo json_encode(['success' => false, 'message' => 'Strumento non trovato.']);
exit;
}
$stmt = $pdo->prepare("UPDATE inv_equipment SET status = 'decommissioned' WHERE id = ?");
$stmt->execute([$id]);
echo json_encode(['success' => true]);
} catch (Exception $e) {
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}