32 lines
871 B
PHP
32 lines
871 B
PHP
<?php
|
|
require_once __DIR__ . '/class/db-functions.php';
|
|
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
|
|
$name = trim($_POST['name'] ?? '');
|
|
$description = trim($_POST['description'] ?? '');
|
|
$is_problem = isset($_POST['is_problem']) ? (int)$_POST['is_problem'] : 0;
|
|
|
|
if ($name === '') {
|
|
echo json_encode(['success' => false, 'message' => 'Il nome è obbligatorio.']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$stmt = $pdo->prepare("
|
|
INSERT INTO pause_reasons (name, description, is_problem)
|
|
VALUES (:name, :description, :is_problem)
|
|
");
|
|
|
|
$stmt->execute([
|
|
':name' => $name,
|
|
':description' => $description !== '' ? $description : null,
|
|
':is_problem' => $is_problem
|
|
]);
|
|
|
|
echo json_encode(['success' => true]);
|
|
} catch (Exception $e) {
|
|
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
|
}
|