34 lines
1.2 KiB
PHP
34 lines
1.2 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
require_once __DIR__ . '/class/db-functions.php';
|
|
|
|
try {
|
|
$db = DBHandlerSelect::getInstance();
|
|
$pdo = $db->getConnection();
|
|
|
|
$lineNumber = $_POST['lineNumber'] ?? null;
|
|
$name = $_POST['lineName'] ?? '';
|
|
$model = $_POST['model'] ?? '';
|
|
$brand = $_POST['brand'] ?? '';
|
|
$status = $_POST['status'] ?? 'active';
|
|
$color = $_POST['color'] ?? '#dc2626';
|
|
$maxHours = isset($_POST['max_hours_per_day']) ? (float)$_POST['max_hours_per_day'] : 24;
|
|
if ($maxHours < 0) $maxHours = 0;
|
|
if ($maxHours > 24) $maxHours = 24;
|
|
|
|
if (!$lineNumber || !$name) {
|
|
echo json_encode(['success' => false, 'message' => 'Numero linea e nome sono obbligatori.']);
|
|
exit;
|
|
}
|
|
|
|
$stmt = $pdo->prepare("
|
|
INSERT INTO production_lines (line_number, name, model, brand, status, color, max_hours_per_day)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
");
|
|
$stmt->execute([$lineNumber, $name, $model, $brand, $status, $color, $maxHours]);
|
|
|
|
echo json_encode(['success' => true]);
|
|
} catch (Exception $e) {
|
|
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
|
}
|