$type, 'msg' => $message]; } function getFlash(): array { $msgs = $_SESSION['flash'] ?? []; unset($_SESSION['flash']); return $msgs; } function formatINR(float $amount): string { return '₹' . number_format($amount, 2); } function timeSince(string $datetime): string { $diff = time() - strtotime($datetime); if ($diff < 60) return 'just now'; if ($diff < 3600) return floor($diff/60) . 'm ago'; if ($diff < 86400) return floor($diff/3600) . 'h ago'; if ($diff < 604800) return floor($diff/86400) . 'd ago'; return date('d M Y', strtotime($datetime)); } function deviceType(string $ua = ''): string { $ua = $ua ?: ($_SERVER['HTTP_USER_AGENT'] ?? ''); if (preg_match('/Mobile|Android|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i', $ua)) return 'mobile'; if (preg_match('/Tablet|iPad/i', $ua)) return 'tablet'; return 'desktop'; } function isAjax(): bool { return !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'; } function getClientIP(): string { foreach (['HTTP_CF_CONNECTING_IP','HTTP_X_FORWARDED_FOR','REMOTE_ADDR'] as $key) { if (!empty($_SERVER[$key])) { return trim(explode(',', $_SERVER[$key])[0]); } } return '0.0.0.0'; } // Survey-specific helpers function surveyStatusBadge(string $status): string { $map = [ 'draft' => ['class' => 'badge-gray', 'label' => 'Draft'], 'active' => ['class' => 'badge-green', 'label' => 'Active'], 'paused' => ['class' => 'badge-yellow', 'label' => 'Paused'], 'closed' => ['class' => 'badge-red', 'label' => 'Closed'], 'archived' => ['class' => 'badge-dark', 'label' => 'Archived'], ]; $b = $map[$status] ?? ['class' => 'badge-gray', 'label' => ucfirst($status)]; return '' . $b['label'] . ''; } function planBadge(string $plan): string { $map = [ 'free' => 'badge-gray', 'starter' => 'badge-blue', 'growth' => 'badge-teal', 'scale' => 'badge-purple', ]; $class = $map[strtolower($plan)] ?? 'badge-gray'; return '' . ucfirst($plan) . ''; } function completionRate(int $started, int $completed): string { if ($started === 0) return '0%'; return round(($completed / $started) * 100) . '%'; } // Question type display names function questionTypeLabel(string $type): string { $labels = [ 'single_choice' => 'Single Choice', 'multi_choice' => 'Multiple Choice', 'dropdown' => 'Dropdown', 'text_short' => 'Short Text', 'text_long' => 'Long Text / Essay', 'rating_scale' => 'Rating Scale', 'star_rating' => 'Star Rating', 'likert_scale' => 'Likert Scale', 'matrix_single' => 'Matrix – Single', 'matrix_multi' => 'Matrix – Multiple', 'ranking' => 'Ranking', 'slider' => 'Slider', 'date_time' => 'Date / Time', 'number' => 'Number', 'yes_no' => 'Yes / No', 'image_choice' => 'Image Choice', 'file_upload' => 'File Upload', 'nps' => 'NPS Score', 'demographic' => 'Demographic', 'video_response' => 'Video Response', 'signature' => 'Signature', 'heatmap' => 'Heat Map Click', 'card_sort' => 'Card Sort', 'emoji_scale' => 'Emoji / Sentiment Scale', 'constant_sum' => 'Constant Sum', 'max_diff' => 'MaxDiff / Best-Worst', 'statement' => 'Statement / Display Text', 'section_break' => 'Section Break', ]; return $labels[$type] ?? ucwords(str_replace('_', ' ', $type)); } // Export format helpers function parseExportFormats(string $formats): array { return array_map('trim', explode(',', $formats)); } function exportFormatLabel(string $fmt): string { $map = [ 'csv' => 'CSV', 'xlsx' => 'Excel (XLSX)', 'pdf' => 'PDF Report', 'spss' => 'SPSS (.sav)', 'json' => 'JSON', ]; return $map[$fmt] ?? strtoupper($fmt); }