getConnection();
// AJAX HANDLERS
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ajax']) && $_POST['ajax'] == '1') {
header('Content-Type: application/json');
$action = $_POST['action'] ?? '';
try {
if ($action === 'delete') {
$id = (int)($_POST['id'] ?? 0);
if ($id <= 0) {
echo json_encode(['success' => false, 'message' => 'ID non valido']);
exit;
}
// Delete header (rows will be deleted by FK cascade if constraints exist)
$stmt = $pdo->prepare("DELETE FROM work_sheets WHERE id = ?");
$stmt->execute([$id]);
echo json_encode(['success' => true]);
exit;
}
echo json_encode(['success' => false, 'message' => 'Azione sconosciuta']);
exit;
} catch (Exception $e) {
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
exit;
}
}
// Worksheets list + row count
$worksheets = $pdo->query("
SELECT
ws.id,
ws.worksheet_date,
ws.customer_name,
ws.profile_type_code,
ws.approved_by,
ws.created_at,
m.nome AS matrice_nome,
m.cliente AS matrice_cliente,
(SELECT COUNT(*) FROM work_sheet_mescole wsm WHERE wsm.worksheet_id = ws.id) AS mixes_count
FROM work_sheets ws
LEFT JOIN matrice m ON ws.idmatrice = m.id
ORDER BY ws.id DESC
")->fetchAll(PDO::FETCH_ASSOC);
?>
Fogli di Lavoro
Storico
| ID |
Data |
Matrice/Profilo |
Cliente |
Codice Profilo |
Mescole |
Visto |
Creato |
Azioni |
| = (int)$ws['id'] ?> |
= htmlspecialchars($ws['worksheet_date'] ?? '-') ?> |
= htmlspecialchars($ws['matrice_nome'] ?? '-') ?> |
= htmlspecialchars($ws['customer_name'] ?: ($ws['matrice_cliente'] ?? '-')) ?> |
= htmlspecialchars($ws['profile_type_code'] ?? '-') ?> |
= (int)$ws['mixes_count'] ?> |
= htmlspecialchars($ws['approved_by'] ?? '-') ?> |
= htmlspecialchars($ws['created_at'] ?? '-') ?> |
|