48 lines
1.3 KiB
PHP
48 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';
|
|
|
|
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;
|
|
|
|
if ($id <= 0) {
|
|
echo json_encode(['success' => false, 'message' => 'Invalid ID.']);
|
|
exit;
|
|
}
|
|
|
|
if ($name === '') {
|
|
echo json_encode(['success' => false, 'message' => 'Name is required.']);
|
|
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
|
|
]);
|
|
|
|
echo json_encode(['success' => true]);
|
|
} catch (Exception $e) {
|
|
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
|
}
|