diff --git a/public/userarea/delete_tool.php b/public/userarea/delete_tool.php index 662c85e..0d83c77 100644 --- a/public/userarea/delete_tool.php +++ b/public/userarea/delete_tool.php @@ -6,40 +6,37 @@ 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'] ?? 0); - $name = trim($_POST['name'] ?? ''); - $tool_type = trim($_POST['tool_type'] ?? ''); - $description = trim($_POST['description'] ?? ''); - $is_active = isset($_POST['is_active']) ? (int)$_POST['is_active'] : 1; + $id = (int)($_POST['id'] ?? $_GET['id'] ?? 0); if ($id <= 0) { echo json_encode(['success' => false, 'message' => 'Invalid ID.']); exit; } - if ($name === '') { - echo json_encode(['success' => false, 'message' => 'Name is required.']); + $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; } - $sql = "UPDATE production_tools - SET name = :name, - tool_type = :tool_type, - description = :description, - is_active = :is_active - WHERE id = :id"; - $stmt = $pdo->prepare($sql); - $stmt->execute([ - 'name' => $name, - 'tool_type' => $tool_type ?: null, - 'description' => $description ?: null, - 'is_active' => $is_active, - 'id' => $id - ]); + $stmt = $pdo->prepare("UPDATE inv_equipment SET status = 'decommissioned' WHERE id = ?"); + $stmt->execute([$id]); echo json_encode(['success' => true]); } catch (Exception $e) { diff --git a/public/userarea/edit_tool.php b/public/userarea/edit_tool.php index ef65b01..7908b89 100644 --- a/public/userarea/edit_tool.php +++ b/public/userarea/edit_tool.php @@ -17,7 +17,7 @@ try { $toolType = trim($_POST['tool_type'] ?? ''); $manufacturer = trim($_POST['manufacturer'] ?? ''); $description = trim($_POST['description'] ?? ''); - $isActive = isset($_POST['is_active']) ? (int)$_POST['is_active'] : 1; + $status = (string)($_POST['status'] ?? 'active'); if ($id <= 0) { echo json_encode(['success' => false, 'message' => 'Invalid ID.']); @@ -29,14 +29,19 @@ try { exit; } - $sql = "UPDATE production_tools + if (!in_array($status, ['active', 'out_of_service', 'decommissioned'], true)) { + $status = 'active'; + } + + // production_tools is now inv_equipment (see manutenzioni/sql) + $sql = "UPDATE inv_equipment SET name = :name, registration_number = :registration_number, serial_number = :serial_number, tool_type = :tool_type, manufacturer = :manufacturer, description = :description, - is_active = :is_active + status = :status WHERE id = :id"; $stmt = $pdo->prepare($sql); @@ -47,7 +52,7 @@ try { 'tool_type' => $toolType ?: null, 'manufacturer' => $manufacturer ?: null, 'description' => $description ?: null, - 'is_active' => $isActive, + 'status' => $status, 'id' => $id ]); diff --git a/public/userarea/include/navbar.php b/public/userarea/include/navbar.php index e40ed10..9c52b92 100644 --- a/public/userarea/include/navbar.php +++ b/public/userarea/include/navbar.php @@ -346,6 +346,66 @@ + + + + +
Nessuna categoria definita.
+| Colore | +Nome | +Codice | +Richiede linea | +Ordine | +Attrezzature | +Stato | +Azioni | +
|---|---|---|---|---|---|---|---|
| + | = mnt_h($category['name']) ?> | += mnt_h($category['code'] ?: '—') ?> | ++ = (int)$category['requires_line'] === 1 + ? 'Richiede linea' + : '—' ?> + | += (int)$category['sort_order'] ?> | += (int)$category['equipment_count'] ?> | ++ + = (int)$category['is_active'] === 1 ? 'Attiva' : 'Disattivata' ?> + + | + +
+
+
+
+
+ |
+
+