41 lines
1.0 KiB
PHP
41 lines
1.0 KiB
PHP
<?php
|
|
require_once __DIR__ . '/class/db-functions.php';
|
|
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
|
|
$id = (int)($_POST['id'] ?? 0);
|
|
$name = trim($_POST['name'] ?? '');
|
|
$description = trim($_POST['description'] ?? '');
|
|
$is_problem = isset($_POST['is_problem']) ? (int)$_POST['is_problem'] : 0;
|
|
|
|
if ($id <= 0) {
|
|
echo json_encode(['success' => false, 'message' => 'ID non valido.']);
|
|
exit;
|
|
}
|
|
if ($name === '') {
|
|
echo json_encode(['success' => false, 'message' => 'Il nome è obbligatorio.']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$stmt = $pdo->prepare("
|
|
UPDATE pause_reasons
|
|
SET name = :name,
|
|
description = :description,
|
|
is_problem = :is_problem
|
|
WHERE id = :id
|
|
");
|
|
|
|
$stmt->execute([
|
|
':name' => $name,
|
|
':description' => $description !== '' ? $description : null,
|
|
':is_problem' => $is_problem,
|
|
':id' => $id
|
|
]);
|
|
|
|
echo json_encode(['success' => true]);
|
|
} catch (Exception $e) {
|
|
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
|
}
|