redirectToLogin('Session expired. Please log in again.'); } $userId = $user['id']; // Shop DB (survey data) - second connection $surveys = []; try { $shopPdo = new PDO( "mysql:host=localhost;dbname=u752449863_rrshop;charset=utf8mb4", "u752449863_rradmin", "S@n@h2016", [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC] ); // Check which columns exist (defensive - works before and after migration) $cols = []; $colCheck = $shopPdo->query("SHOW COLUMNS FROM survey_urls"); foreach ($colCheck->fetchAll() as $c) { $cols[] = $c['Field']; } $hasQualityFlag = in_array('quality_flag', $cols); $hasActualLoi = in_array('actual_loi_seconds', $cols); $hasCompletedAt = in_array('completed_at', $cols); // Check projects columns $projCols = []; $projColCheck = $shopPdo->query("SHOW COLUMNS FROM projects"); foreach ($projColCheck->fetchAll() as $c) { $projCols[] = $c['Field']; } $hasClosureStatus = in_array('closure_status', $projCols); $hasSpeedsterPct = in_array('speedster_threshold_pct', $projCols); // Build query dynamically based on available columns $qualityFlagCol = $hasQualityFlag ? "su.quality_flag" : "'valid' as quality_flag"; $qualityNotesCol = $hasQualityFlag ? "su.quality_notes" : "NULL as quality_notes"; $actualLoiCol = $hasActualLoi ? "su.actual_loi_seconds" : "NULL as actual_loi_seconds"; $completedAtCol = $hasCompletedAt ? "su.completed_at" : "NULL as completed_at"; $closureStatusCol = $hasClosureStatus ? "p.closure_status" : "'none' as closure_status"; $speedsterPctCol = $hasSpeedsterPct ? "p.speedster_threshold_pct" : "33.33 as speedster_threshold_pct"; $stmt = $shopPdo->prepare(" SELECT su.unique_identifier, su.status as url_status, $qualityFlagCol, $qualityNotesCol, su.clicked_at, $completedAtCol, $actualLoiCol, su.created_at as sent_at, su.batch_number, p.project_id, p.project_name, p.eloi, p.status as project_status, $closureStatusCol, p.closed_at, $speedsterPctCol FROM survey_urls su INNER JOIN projects p ON su.project_id = p.project_id WHERE su.sent_to_user_id = ? AND su.status NOT IN ('available') ORDER BY su.created_at DESC "); $stmt->execute([$userId]); $surveys = $stmt->fetchAll(); } catch (Exception $e) { error_log("My Surveys error: " . $e->getMessage()); } // Determine display status for each survey function getSurveyDisplayStatus($survey) { $urlStatus = $survey['url_status']; $qualityFlag = $survey['quality_flag'] ?? 'valid'; $projectStatus = $survey['project_status']; $closureStatus = $survey['closure_status'] ?? 'none'; if ($urlStatus === 'sent') { return ['label' => 'Invitation Sent', 'class' => 'status-sent', 'desc' => 'You have been invited to this survey. Click the link in your email to participate.']; } if ($urlStatus === 'clicked') { return ['label' => 'In Progress', 'class' => 'status-progress', 'desc' => 'You started this survey. Please complete it before it times out.']; } if (in_array($urlStatus, ['earlyscreenout', 'latescreenout'])) { return ['label' => 'Screened Out', 'class' => 'status-screenout', 'desc' => 'You did not qualify for this survey based on the screening criteria.']; } if ($urlStatus === 'quotafull') { return ['label' => 'Quota Full', 'class' => 'status-quotafull', 'desc' => 'The survey reached its quota before your response was recorded.']; } if ($urlStatus === 'timeout') { return ['label' => 'Timed Out', 'class' => 'status-timeout', 'desc' => 'The survey session expired.']; } if ($urlStatus === 'partial') { return ['label' => 'Partial Complete', 'class' => 'status-partial', 'desc' => 'Your response was partially recorded.']; } // Complete status - check quality and project closure if ($urlStatus === 'complete') { if ($qualityFlag === 'speedster') { return ['label' => 'Under Review - Possible Speedster', 'class' => 'status-review', 'desc' => 'Your completion time was below the minimum threshold. This is under review and pending project closure.']; } if ($qualityFlag === 'ip_duplicate') { return ['label' => 'Under Review - Duplicate Detected', 'class' => 'status-review', 'desc' => 'A duplicate response was detected from your connection. This is under review.']; } if ($qualityFlag === 'client_flagged') { return ['label' => 'Under Review - Flagged by Client', 'class' => 'status-review', 'desc' => 'This response has been flagged for review by the research client. Pending admin approval.']; } // Valid complete if ($projectStatus === 'Closed') { return ['label' => 'Approved - Points Credited', 'class' => 'status-approved', 'desc' => 'Survey completed and approved. Points have been credited to your account.']; } if ($closureStatus === 'pending_review') { return ['label' => 'Completed - Pending Approval', 'class' => 'status-pending', 'desc' => 'Survey completed. The project is under review. Points will be credited once approved.']; } return ['label' => 'Completed - Pending Project Closure', 'class' => 'status-pending', 'desc' => 'Survey completed successfully. Points will be credited when the project is closed by the client.']; } return ['label' => ucfirst($urlStatus), 'class' => 'status-default', 'desc' => '']; } function formatLoi($seconds) { if (!$seconds) return '-'; $min = floor($seconds / 60); $sec = $seconds % 60; return ($min > 0 ? $min . 'm ' : '') . $sec . 's'; } // Count stats $totalSurveys = count($surveys); $completes = 0; $pending = 0; $flagged = 0; foreach ($surveys as $s) { if ($s['url_status'] === 'complete') { $completes++; $qf = $s['quality_flag'] ?? 'valid'; if (in_array($qf, ['speedster', 'ip_duplicate', 'client_flagged'])) { $flagged++; } elseif ($s['project_status'] !== 'Closed') { $pending++; } } } ?> My Surveys - Relevant Reflex

My Survey Participations

Track all your survey invitations, completions, and reward status.

Total Surveys
Completed
Pending Approval
0): ?>
Under Review

No Survey Participations Yet

Once you receive and participate in surveys, your history will appear here.

Complete your profile to start receiving survey invitations.

$survey): $displayStatus = getSurveyDisplayStatus($survey); $eloiSec = intval($survey['eloi'] ?? 0) * 60; $thresholdPct = floatval($survey['speedster_threshold_pct'] ?? 33.33); $thresholdSec = $eloiSec > 0 ? $eloiSec * ($thresholdPct / 100) : 0; $loiPct = ($eloiSec > 0 && $survey['actual_loi_seconds']) ? min(100, round(($survey['actual_loi_seconds'] / $eloiSec) * 100)) : 0; $loiClass = 'loi-green'; if ($survey['actual_loi_seconds'] && $thresholdSec > 0 && $survey['actual_loi_seconds'] < $thresholdSec) $loiClass = 'loi-red'; elseif ($loiPct > 150) $loiClass = 'loi-yellow'; ?>
• LOI:
Expected LOI
minutes
Your LOI
Min Required LOI
0 ? formatLoi(round($thresholdSec)) . ' (' . $thresholdPct . '% of ELOI)' : '-'; ?>
Project Status