'Personal Background', 'household_family' => 'Household & Family', 'shopping_lifestyle' => 'Shopping & Lifestyle', 'technology_digital' => 'Technology & Digital', 'travel_transportation' => 'Travel & Transportation', 'health_fitness' => 'Health & Fitness', 'entertainment_media' => 'Entertainment & Media', 'food_dining' => 'Food & Dining', 'financial_services' => 'Financial Services', 'communication_payments' => 'Communication & Payments' ]; // Get available question IDs and their response options from existing user_profiler data $profilerQuestions = []; $profilerResponses = []; try { $panelPdo = getPanelDBConnection(); // Get all sections and questions $stmt = $panelPdo->query(" SELECT DISTINCT section, question_id FROM user_profiler ORDER BY section, question_id "); while ($row = $stmt->fetch()) { if (!isset($profilerQuestions[$row['section']])) { $profilerQuestions[$row['section']] = []; } $profilerQuestions[$row['section']][] = $row['question_id']; // Get distinct responses for this question $respStmt = $panelPdo->prepare(" SELECT DISTINCT response FROM user_profiler WHERE section = ? AND question_id = ? ORDER BY response "); $respStmt->execute([$row['section'], $row['question_id']]); $responses = []; while ($respRow = $respStmt->fetch()) { // Parse JSON response $decoded = json_decode($respRow['response'], true); if (is_array($decoded)) { // Multiple choice response foreach ($decoded as $value) { if (!in_array($value, $responses)) { $responses[] = $value; } } } else { // Single choice response - remove quotes $value = trim($respRow['response'], '"'); if (!in_array($value, $responses)) { $responses[] = $value; } } } sort($responses); $profilerResponses[$row['section']][$row['question_id']] = $responses; } $hasProfiler = !empty($profilerQuestions); } catch (Exception $e) { error_log("Profiler data load error: " . $e->getMessage()); $hasProfiler = false; } // Initialize filter values $filterValues = [ 'age_min' => '', 'age_max' => '', 'gender' => [], 'postcode' => '', 'profiler_filters' => [], 'previous_projects' => [], 'previous_statuses' => [], 'previous_mode' => 'exclude' ]; // Editing existing selection if ($selection_id) { try { $stmt = $pdo->prepare("SELECT * FROM project_selections WHERE id = ? AND client_id = ?"); $stmt->execute([$selection_id, $_SESSION['client_id']]); $selection = $stmt->fetch(); if (!$selection) { header('Location: projects-list.php'); exit; } $project_id = $selection['project_id']; $page_title = 'Edit Selection'; if ($selection['status'] !== 'draft') { header('Location: view-project.php?id=' . $project_id); exit; } // Load existing criteria $stmt = $pdo->prepare("SELECT * FROM selection_criteria WHERE selection_id = ?"); $stmt->execute([$selection_id]); $criteria = $stmt->fetchAll(); foreach ($criteria as $criterion) { $field = $criterion['filter_field']; $operator = $criterion['filter_operator']; $value = $criterion['filter_value']; if ($criterion['filter_type'] === 'demographic') { if ($field === 'age') { if ($operator === 'greater_than') { $filterValues['age_min'] = $value; } elseif ($operator === 'less_than') { $filterValues['age_max'] = $value; } } elseif ($field === 'gender' && $operator === 'in') { $filterValues['gender'] = json_decode($value, true) ?: []; } elseif ($field === 'postcode') { $filterValues['postcode'] = $value; } } elseif ($criterion['filter_type'] === 'profiler') { // Extract section and question_id from field name // Format: section:question_id (e.g., "personal_background:education_level") if (strpos($field, ':') !== false) { list($section, $question) = explode(':', $field, 2); $filterValues['profiler_filters'][] = [ 'section' => $section, 'question_id' => $question, 'response' => $value ]; } } elseif ($criterion['filter_type'] === 'previous_project') { if ($field === 'project_ids') { $filterValues['previous_projects'] = json_decode($value, true) ?: []; } elseif ($field === 'statuses') { $filterValues['previous_statuses'] = json_decode($value, true) ?: []; } elseif ($field === 'mode') { $filterValues['previous_mode'] = $value; } } } } catch (Exception $e) { error_log("Selection load error: " . $e->getMessage()); header('Location: projects-list.php?error=db'); exit; } } // Get project details $stmt = $pdo->prepare("SELECT * FROM projects WHERE id = ? AND client_id = ?"); $stmt->execute([$project_id, $_SESSION['client_id']]); $project = $stmt->fetch(); if (!$project) { header('Location: projects-list.php'); exit; } // Get client's other projects for previous project filter $stmt = $pdo->prepare("SELECT id, project_id, project_name FROM projects WHERE client_id = ? AND id != ? ORDER BY created_at DESC"); $stmt->execute([$_SESSION['client_id'], $project_id]); $otherProjects = $stmt->fetchAll(); include 'client-portal-header.php'; ?>
Project:
✓ Only email-verified members will be included