false, 'message' => 'ID non valido.']); exit; } $id = (int)$_GET['id']; $db = DBHandlerSelect::getInstance(); $pdo = $db->getConnection(); $stmt = $pdo->prepare(" SELECT h.*, au.first_name as user_first_name, au.last_name as user_last_name FROM scad_deadline_histories h LEFT JOIN auth_users au ON au.id = h.user_id WHERE h.deadline_id = ? ORDER BY h.created_at DESC "); $stmt->execute([$id]); $history = $stmt->fetchAll(PDO::FETCH_ASSOC); // Format for display $actionLabels = [ 'created' => 'Creata', 'updated' => 'Modificata', 'completed' => 'Completata', 'attachment_added' => 'Allegato aggiunto', 'attachment_removed' => 'Allegato rimosso', 'notification_sent' => 'Notifica inviata' ]; foreach ($history as &$h) { $h['action_label'] = $actionLabels[$h['action']] ?? $h['action']; $h['user_name'] = trim(($h['user_first_name'] ?? '') . ' ' . ($h['user_last_name'] ?? '')) ?: 'Sistema'; $h['changes'] = $h['changes'] ? json_decode($h['changes'], true) : null; unset($h['user_first_name'], $h['user_last_name']); } echo json_encode(['success' => true, 'data' => $history]); } catch (Exception $e) { echo json_encode(['success' => false, 'message' => 'Errore: ' . $e->getMessage()]); }