2 hours ago * and still has 'clicked' status, it gets marked as 'timeout'. */ error_reporting(E_ALL); ini_set('display_errors', 0); ini_set('log_errors', 1); // Load client session for database connection require_once __DIR__ . '/../clients/client-session.php'; // Get the path parts $request_uri = $_SERVER['REQUEST_URI']; $path = parse_url($request_uri, PHP_URL_PATH); $parts = explode('/', trim($path, '/')); // Expected: ['r', project_id, status] if (count($parts) < 3 || $parts[0] !== 'r') { header('HTTP/1.0 404 Not Found'); echo "Invalid redirect URL"; exit; } $project_id = $parts[1]; $status = strtolower($parts[2]); // Get unique_id from query string (if provided by client) $unique_id = $_GET['uid'] ?? $_GET['id'] ?? $_GET['user'] ?? null; // Valid status values (no quality_term - use latescreenout instead) $valid_statuses = [ 'complete', 'partial', 'earlyscreenout', 'latescreenout', 'quotafull', 'timeout' ]; if (!in_array($status, $valid_statuses)) { $status = 'partial'; // Default to partial if unknown } try { $pdo = getClientDBConnection(); // If we have unique_id, update specific URL if ($unique_id) { $stmt = $pdo->prepare(" UPDATE survey_urls SET status = ? WHERE project_id = ? AND unique_identifier = ? AND status NOT IN ('complete') "); $stmt->execute([$status, $project_id, $unique_id]); $updated = $stmt->rowCount(); if ($updated > 0) { error_log("Survey status updated: Project=$project_id, UniqueID=$unique_id, Status=$status"); } } else { // No unique_id provided - try to find most recent clicked URL for this project $stmt = $pdo->prepare(" UPDATE survey_urls SET status = ? WHERE project_id = ? AND status = 'clicked' ORDER BY clicked_at DESC LIMIT 1 "); $stmt->execute([$status, $project_id]); error_log("Survey status updated (no UID): Project=$project_id, Status=$status"); } // Also mark any URLs that were clicked > 2 hours ago and still 'clicked' as timeout $stmt = $pdo->prepare(" UPDATE survey_urls SET status = 'timeout' WHERE project_id = ? AND status = 'clicked' AND clicked_at < DATE_SUB(NOW(), INTERVAL 2 HOUR) "); $stmt->execute([$project_id]); } catch (Exception $e) { error_log("Redirect status error: " . $e->getMessage()); // Continue to show the landing page even if DB update fails } // Set variables for the landing pages $current_project_id = $project_id; $current_status = $status; $current_user_id = $unique_id ?? ''; // Map status to landing page file $page_map = [ 'complete' => 'complete.php', 'partial' => 'partial.php', 'earlyscreenout' => 'earlyscreenout.php', 'latescreenout' => 'latescreenout.php', 'quotafull' => 'quotafull.php', 'timeout' => 'timeout.php' ]; $page_file = __DIR__ . '/pages/' . ($page_map[$status] ?? 'partial.php'); if (file_exists($page_file)) { include $page_file; } else { // Fallback if page file doesn't exist echo ' Survey Response Recorded - Relevant Reflex

Thank You

Your survey response has been recorded.

Project: ' . htmlspecialchars($project_id) . '

Return to Dashboard

'; } ?>