63 lines
2.1 KiB
PHP
63 lines
2.1 KiB
PHP
<?php
|
|
ini_set('display_errors', 1);
|
|
error_reporting(E_ALL);
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
require_once 'include/headscript.php';
|
|
|
|
try {
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
|
|
$id = (int)($_POST['id'] ?? 0);
|
|
$name = trim($_POST['name'] ?? '');
|
|
$registrationNumber = trim($_POST['registration_number'] ?? '');
|
|
$serialNumber = trim($_POST['serial_number'] ?? '');
|
|
$toolType = trim($_POST['tool_type'] ?? '');
|
|
$manufacturer = trim($_POST['manufacturer'] ?? '');
|
|
$description = trim($_POST['description'] ?? '');
|
|
$status = (string)($_POST['status'] ?? 'active');
|
|
|
|
if ($id <= 0) {
|
|
echo json_encode(['success' => false, 'message' => 'Invalid ID.']);
|
|
exit;
|
|
}
|
|
|
|
if ($name === '') {
|
|
echo json_encode(['success' => false, 'message' => 'Name is required.']);
|
|
exit;
|
|
}
|
|
|
|
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,
|
|
status = :status
|
|
WHERE id = :id";
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute([
|
|
'name' => $name,
|
|
'registration_number' => $registrationNumber ?: null,
|
|
'serial_number' => $serialNumber ?: null,
|
|
'tool_type' => $toolType ?: null,
|
|
'manufacturer' => $manufacturer ?: null,
|
|
'description' => $description ?: null,
|
|
'status' => $status,
|
|
'id' => $id
|
|
]);
|
|
|
|
echo json_encode(['success' => true]);
|
|
} catch (Exception $e) {
|
|
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
|
}
|