redirectToLogin('Session expired. Please log in again.'); } // Initialize database try { $db = new Database(); $pdo = $db->getConnection(); } catch (Exception $e) { logError('Database connection failed in profiler.php: ' . $e->getMessage()); die('System error. Please try again later.'); } // Define all profiler sections with their questions $profilerSections = [ 'personal_background' => [ 'name' => 'Personal Background', 'description' => 'Tell us about your education, work, and personal details', 'questions' => [ 'education_level' => [ 'question' => 'What is your highest level of education?', 'type' => 'single', 'options' => [ 'below_10th' => 'Below 10th Standard', '10th_pass' => '10th Standard', '12th_pass' => '12th Standard/Intermediate', 'diploma' => 'Diploma/ITI', 'graduation' => 'Graduation (Bachelor\'s)', 'post_graduation' => 'Post Graduation (Master\'s)', 'professional' => 'Professional Degree (CA/CS/Engineering/Medical)', 'doctorate' => 'Doctorate/PhD' ] ], 'employment_status' => [ 'question' => 'What is your current employment status?', 'type' => 'single', 'options' => [ 'student' => 'Student', 'employed_private' => 'Employed - Private Sector', 'employed_government' => 'Employed - Government/Public Sector', 'self_employed' => 'Self Employed/Business Owner', 'freelancer' => 'Freelancer/Consultant', 'homemaker' => 'Homemaker', 'retired' => 'Retired', 'unemployed' => 'Currently Unemployed' ] ], 'occupation_sector' => [ 'question' => 'Which sector do you work in? (Skip if not applicable)', 'type' => 'single', 'options' => [ 'it_software' => 'IT/Software', 'banking_finance' => 'Banking/Finance', 'healthcare' => 'Healthcare/Medical', 'education' => 'Education/Teaching', 'manufacturing' => 'Manufacturing', 'retail_sales' => 'Retail/Sales', 'government' => 'Government Services', 'agriculture' => 'Agriculture/Farming', 'media_entertainment' => 'Media/Entertainment', 'other' => 'Other' ] ], 'monthly_income' => [ 'question' => 'What is your monthly personal income range?', 'type' => 'single', 'options' => [ 'no_income' => 'No Income', 'below_15k' => 'Below ₹15,000', '15k_30k' => '₹15,000 - ₹30,000', '30k_50k' => '₹30,000 - ₹50,000', '50k_75k' => '₹50,000 - ₹75,000', '75k_1l' => '₹75,000 - ₹1,00,000', '1l_2l' => '₹1,00,000 - ₹2,00,000', 'above_2l' => 'Above ₹2,00,000' ] ], 'work_experience' => [ 'question' => 'How many years of work experience do you have?', 'type' => 'single', 'options' => [ 'fresher' => 'Fresher (0 years)', '1_2_years' => '1-2 years', '3_5_years' => '3-5 years', '6_10_years' => '6-10 years', '11_15_years' => '11-15 years', 'above_15_years' => 'More than 15 years' ] ], 'language_preference' => [ 'question' => 'Which languages are you comfortable with? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'hindi' => 'Hindi', 'english' => 'English', 'tamil' => 'Tamil', 'telugu' => 'Telugu', 'bengali' => 'Bengali', 'marathi' => 'Marathi', 'gujarati' => 'Gujarati', 'kannada' => 'Kannada', 'malayalam' => 'Malayalam', 'punjabi' => 'Punjabi', 'other' => 'Other' ] ] ] ], 'household_family' => [ 'name' => 'Household & Family', 'description' => 'Share information about your household and family', 'questions' => [ 'family_size' => [ 'question' => 'How many people live in your household?', 'type' => 'single', 'options' => [ '1' => '1 (Just me)', '2' => '2 people', '3' => '3 people', '4' => '4 people', '5' => '5 people', '6_plus' => '6 or more people' ] ], 'marital_status' => [ 'question' => 'What is your marital status?', 'type' => 'single', 'options' => [ 'single' => 'Single', 'married' => 'Married', 'divorced' => 'Divorced', 'widowed' => 'Widowed', 'in_relationship' => 'In a relationship' ] ], 'children' => [ 'question' => 'Do you have children?', 'type' => 'single', 'options' => [ 'no_children' => 'No children', 'expecting' => 'Expecting first child', '1_child' => '1 child', '2_children' => '2 children', '3_children' => '3 children', '4_plus_children' => '4 or more children' ] ], 'children_age_groups' => [ 'question' => 'If you have children, what are their age groups? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'infant' => 'Infant (0-2 years)', 'toddler' => 'Toddler (3-5 years)', 'child' => 'Child (6-12 years)', 'teenager' => 'Teenager (13-18 years)', 'adult' => 'Adult (18+ years)', 'not_applicable' => 'Not applicable' ] ], 'house_type' => [ 'question' => 'What type of housing do you live in?', 'type' => 'single', 'options' => [ 'apartment' => 'Apartment/Flat', 'independent_house' => 'Independent House', 'villa' => 'Villa', 'row_house' => 'Row House/Townhouse', 'rented_room' => 'Rented Room', 'hostel_pg' => 'Hostel/PG', 'other' => 'Other' ] ], 'house_ownership' => [ 'question' => 'Is your house?', 'type' => 'single', 'options' => [ 'owned' => 'Owned by family', 'rented' => 'Rented', 'company_provided' => 'Company provided', 'family_owned' => 'Joint family property', 'other' => 'Other' ] ], 'pet_ownership' => [ 'question' => 'Do you have any pets?', 'type' => 'multiple', 'options' => [ 'dog' => 'Dog', 'cat' => 'Cat', 'bird' => 'Birds', 'fish' => 'Fish', 'other_pet' => 'Other pets', 'no_pets' => 'No pets' ] ] ] ], 'shopping_lifestyle' => [ 'name' => 'Shopping & Lifestyle', 'description' => 'Tell us about your shopping habits and lifestyle preferences', 'questions' => [ 'shopping_frequency' => [ 'question' => 'How often do you shop for non-essential items?', 'type' => 'single', 'options' => [ 'daily' => 'Daily', 'weekly' => 'Weekly', 'bi_weekly' => 'Bi-weekly', 'monthly' => 'Monthly', 'occasionally' => 'Occasionally', 'rarely' => 'Rarely' ] ], 'shopping_preference' => [ 'question' => 'Where do you prefer to shop? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'online' => 'Online (e-commerce websites)', 'malls' => 'Shopping malls', 'local_stores' => 'Local stores/markets', 'supermarkets' => 'Supermarkets', 'brand_stores' => 'Brand exclusive stores', 'wholesale_markets' => 'Wholesale markets' ] ], 'monthly_shopping_budget' => [ 'question' => 'What is your monthly shopping budget for non-essential items?', 'type' => 'single', 'options' => [ 'below_2k' => 'Below ₹2,000', '2k_5k' => '₹2,000 - ₹5,000', '5k_10k' => '₹5,000 - ₹10,000', '10k_20k' => '₹10,000 - ₹20,000', '20k_50k' => '₹20,000 - ₹50,000', 'above_50k' => 'Above ₹50,000' ] ], 'brand_consciousness' => [ 'question' => 'How important are brands to you when making purchase decisions?', 'type' => 'single', 'options' => [ 'very_important' => 'Very important - I only buy branded products', 'somewhat_important' => 'Somewhat important - I prefer brands but consider alternatives', 'neutral' => 'Neutral - Brand doesn\'t matter much', 'not_important' => 'Not important - I focus on value and quality', 'avoid_brands' => 'I actively avoid expensive brands' ] ], 'online_shopping_frequency' => [ 'question' => 'How often do you shop online?', 'type' => 'single', 'options' => [ 'daily' => 'Daily', 'weekly' => 'Weekly', 'monthly' => 'Monthly', 'quarterly' => 'Quarterly', 'rarely' => 'Rarely', 'never' => 'Never' ] ], 'lifestyle_interests' => [ 'question' => 'What are your main lifestyle interests? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'fitness' => 'Fitness and health', 'cooking' => 'Cooking and food', 'travel' => 'Travel and exploration', 'fashion' => 'Fashion and style', 'home_decor' => 'Home decoration', 'gadgets' => 'Technology and gadgets', 'books' => 'Reading and books', 'movies' => 'Movies and entertainment', 'music' => 'Music', 'sports' => 'Sports', 'art' => 'Art and culture' ] ], 'social_media_usage' => [ 'question' => 'Which social media platforms do you actively use? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'facebook' => 'Facebook', 'instagram' => 'Instagram', 'twitter' => 'Twitter/X', 'linkedin' => 'LinkedIn', 'youtube' => 'YouTube', 'whatsapp' => 'WhatsApp', 'telegram' => 'Telegram', 'snapchat' => 'Snapchat', 'tiktok' => 'TikTok/Reels', 'none' => 'I don\'t use social media' ] ] ] ], 'technology_digital' => [ 'name' => 'Technology & Digital', 'description' => 'Share your technology usage and digital preferences', 'questions' => [ 'smartphone_brand' => [ 'question' => 'Which smartphone brand do you currently use?', 'type' => 'single', 'options' => [ 'samsung' => 'Samsung', 'apple' => 'Apple iPhone', 'xiaomi' => 'Xiaomi/Mi/Redmi', 'oneplus' => 'OnePlus', 'oppo' => 'Oppo', 'vivo' => 'Vivo', 'realme' => 'Realme', 'google' => 'Google Pixel', 'motorola' => 'Motorola', 'other' => 'Other' ] ], 'internet_usage_hours' => [ 'question' => 'How many hours do you spend on the internet daily?', 'type' => 'single', 'options' => [ '1_2_hours' => '1-2 hours', '3_4_hours' => '3-4 hours', '5_6_hours' => '5-6 hours', '7_8_hours' => '7-8 hours', '9_10_hours' => '9-10 hours', 'more_than_10' => 'More than 10 hours' ] ], 'primary_internet_activity' => [ 'question' => 'What do you primarily use the internet for? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'social_media' => 'Social media', 'entertainment' => 'Entertainment (videos, music)', 'work' => 'Work/Professional', 'shopping' => 'Online shopping', 'news' => 'News and information', 'education' => 'Learning and education', 'gaming' => 'Gaming', 'communication' => 'Communication (calls, messages)', 'banking' => 'Banking and financial services' ] ], 'streaming_services' => [ 'question' => 'Which streaming services do you use? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'netflix' => 'Netflix', 'amazon_prime' => 'Amazon Prime Video', 'hotstar' => 'Disney+ Hotstar', 'youtube_premium' => 'YouTube Premium', 'sony_liv' => 'Sony LIV', 'zee5' => 'ZEE5', 'voot' => 'Voot', 'mx_player' => 'MX Player', 'spotify' => 'Spotify', 'none' => 'None of these' ] ], 'online_payment_methods' => [ 'question' => 'Which online payment methods do you use? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'upi' => 'UPI (PhonePe, GooglePay, Paytm)', 'credit_card' => 'Credit Card', 'debit_card' => 'Debit Card', 'net_banking' => 'Net Banking', 'digital_wallet' => 'Digital Wallets', 'cod' => 'Cash on Delivery', 'bank_transfer' => 'Bank Transfer' ] ], 'tech_comfort_level' => [ 'question' => 'How would you rate your comfort level with technology?', 'type' => 'single', 'options' => [ 'expert' => 'Expert - I\'m very tech-savvy', 'advanced' => 'Advanced - I\'m comfortable with most tech', 'intermediate' => 'Intermediate - I can handle basic to moderate tech tasks', 'beginner' => 'Beginner - I use basic features only', 'minimal' => 'Minimal - I struggle with technology' ] ], 'smart_devices_owned' => [ 'question' => 'Which smart devices do you own? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'smart_tv' => 'Smart TV', 'smart_speaker' => 'Smart Speaker (Alexa, Google Home)', 'smartwatch' => 'Smartwatch/Fitness Tracker', 'laptop' => 'Laptop', 'tablet' => 'Tablet', 'gaming_console' => 'Gaming Console', 'smart_home' => 'Smart Home Devices', 'none' => 'None of these' ] ] ] ], 'travel_transportation' => [ 'name' => 'Travel & Transportation', 'description' => 'Tell us about your travel habits and transportation preferences', 'questions' => [ 'travel_frequency' => [ 'question' => 'How often do you travel for leisure/vacation?', 'type' => 'single', 'options' => [ 'monthly' => 'Monthly', 'quarterly' => 'Every 3-4 months', 'twice_yearly' => 'Twice a year', 'annually' => 'Once a year', 'rarely' => 'Rarely (once in 2-3 years)', 'never' => 'Never' ] ], 'travel_destinations' => [ 'question' => 'What type of destinations do you prefer? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'domestic_cities' => 'Domestic cities', 'hill_stations' => 'Hill stations', 'beaches' => 'Beaches', 'historical_places' => 'Historical places', 'religious_places' => 'Religious places', 'international' => 'International destinations', 'adventure_spots' => 'Adventure destinations', 'family_spots' => 'Family-friendly places' ] ], 'accommodation_preference' => [ 'question' => 'What type of accommodation do you prefer while traveling?', 'type' => 'single', 'options' => [ 'luxury_hotels' => 'Luxury hotels (5-star)', 'mid_range_hotels' => 'Mid-range hotels (3-4 star)', 'budget_hotels' => 'Budget hotels', 'resorts' => 'Resorts', 'homestays' => 'Homestays', 'hostels' => 'Hostels', 'airbnb' => 'Airbnb/Rental apartments', 'family_friends' => 'Stay with family/friends' ] ], 'daily_commute_mode' => [ 'question' => 'What is your primary mode of daily transportation?', 'type' => 'single', 'options' => [ 'own_car' => 'Own car', 'own_bike' => 'Own bike/scooter', 'public_transport' => 'Public transport (bus, metro)', 'auto_rickshaw' => 'Auto rickshaw', 'taxi_cab' => 'Taxi/Cab services', 'ride_sharing' => 'Ride sharing (Ola, Uber)', 'walking' => 'Walking', 'cycling' => 'Cycling', 'work_from_home' => 'Work from home (no commute)' ] ], 'vehicle_ownership' => [ 'question' => 'Which vehicles do you own? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'car' => 'Car', 'motorcycle' => 'Motorcycle', 'scooter' => 'Scooter', 'bicycle' => 'Bicycle', 'electric_vehicle' => 'Electric vehicle', 'none' => 'None' ] ], 'fuel_type_preference' => [ 'question' => 'If you own a vehicle, what fuel type do you prefer?', 'type' => 'single', 'options' => [ 'petrol' => 'Petrol', 'diesel' => 'Diesel', 'cng' => 'CNG', 'electric' => 'Electric', 'hybrid' => 'Hybrid', 'not_applicable' => 'Not applicable (don\'t own vehicle)' ] ], 'ride_sharing_usage' => [ 'question' => 'How often do you use ride-sharing services (Ola, Uber)?', 'type' => 'single', 'options' => [ 'daily' => 'Daily', 'weekly' => 'Weekly', 'monthly' => 'Monthly', 'occasionally' => 'Occasionally', 'rarely' => 'Rarely', 'never' => 'Never' ] ] ] ], 'health_fitness' => [ 'name' => 'Health & Fitness', 'description' => 'Share your health and fitness preferences and habits', 'questions' => [ 'exercise_frequency' => [ 'question' => 'How often do you exercise or engage in physical activities?', 'type' => 'single', 'options' => [ 'daily' => 'Daily', 'few_times_week' => 'Few times a week', 'weekly' => 'Once a week', 'monthly' => 'Few times a month', 'rarely' => 'Rarely', 'never' => 'Never' ] ], 'exercise_types' => [ 'question' => 'What types of physical activities do you engage in? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'gym' => 'Gym workouts', 'running' => 'Running/Jogging', 'walking' => 'Walking', 'yoga' => 'Yoga', 'cycling' => 'Cycling', 'swimming' => 'Swimming', 'sports' => 'Sports (cricket, football, etc.)', 'dancing' => 'Dancing', 'home_workouts' => 'Home workouts', 'none' => 'None' ] ], 'diet_preference' => [ 'question' => 'What is your dietary preference?', 'type' => 'single', 'options' => [ 'vegetarian' => 'Vegetarian', 'non_vegetarian' => 'Non-vegetarian', 'vegan' => 'Vegan', 'jain_vegetarian' => 'Jain vegetarian', 'eggetarian' => 'Eggetarian', 'flexitarian' => 'Flexitarian (mostly vegetarian)', 'no_preference' => 'No specific preference' ] ], 'health_concerns' => [ 'question' => 'Do you have any of these health concerns? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'diabetes' => 'Diabetes', 'hypertension' => 'High blood pressure', 'heart_disease' => 'Heart disease', 'obesity' => 'Weight management issues', 'allergies' => 'Allergies', 'digestive_issues' => 'Digestive issues', 'mental_health' => 'Mental health concerns', 'none' => 'None', 'prefer_not_say' => 'Prefer not to say' ] ], 'healthcare_spending' => [ 'question' => 'How much do you spend on healthcare annually?', 'type' => 'single', 'options' => [ 'below_10k' => 'Below ₹10,000', '10k_25k' => '₹10,000 - ₹25,000', '25k_50k' => '₹25,000 - ₹50,000', '50k_1l' => '₹50,000 - ₹1,00,000', 'above_1l' => 'Above ₹1,00,000', 'not_sure' => 'Not sure' ] ], 'health_insurance' => [ 'question' => 'Do you have health insurance?', 'type' => 'single', 'options' => [ 'employer_provided' => 'Yes, provided by employer', 'personal_policy' => 'Yes, personal policy', 'family_floater' => 'Yes, family floater policy', 'government_scheme' => 'Yes, government scheme', 'no_insurance' => 'No health insurance', 'not_sure' => 'Not sure' ] ], 'wellness_interests' => [ 'question' => 'Which wellness activities interest you? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'meditation' => 'Meditation', 'spa_treatments' => 'Spa treatments', 'nutrition_counseling' => 'Nutrition counseling', 'fitness_training' => 'Personal fitness training', 'alternative_medicine' => 'Alternative medicine', 'mental_health_support' => 'Mental health support', 'wellness_retreats' => 'Wellness retreats', 'none' => 'None of these' ] ] ] ], 'entertainment_media' => [ 'name' => 'Entertainment & Media', 'description' => 'Tell us about your entertainment preferences and media consumption', 'questions' => [ 'tv_watching_hours' => [ 'question' => 'How many hours do you watch TV/streaming content daily?', 'type' => 'single', 'options' => [ 'none' => 'I don\'t watch TV', '1_hour' => 'Less than 1 hour', '1_2_hours' => '1-2 hours', '2_3_hours' => '2-3 hours', '3_5_hours' => '3-5 hours', 'more_than_5' => 'More than 5 hours' ] ], 'content_preferences' => [ 'question' => 'What type of content do you prefer? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'bollywood_movies' => 'Bollywood movies', 'hollywood_movies' => 'Hollywood movies', 'regional_movies' => 'Regional movies', 'tv_serials' => 'TV serials/shows', 'reality_shows' => 'Reality shows', 'news' => 'News', 'documentaries' => 'Documentaries', 'comedy_shows' => 'Comedy shows', 'sports' => 'Sports', 'music_videos' => 'Music videos' ] ], 'movie_genres' => [ 'question' => 'Which movie genres do you enjoy? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'action' => 'Action', 'comedy' => 'Comedy', 'drama' => 'Drama', 'romance' => 'Romance', 'thriller' => 'Thriller', 'horror' => 'Horror', 'sci_fi' => 'Science Fiction', 'documentary' => 'Documentary', 'biography' => 'Biography', 'animation' => 'Animation' ] ], 'music_preferences' => [ 'question' => 'What type of music do you listen to? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'bollywood' => 'Bollywood', 'classical_indian' => 'Classical Indian', 'devotional' => 'Devotional/Religious', 'pop' => 'Pop', 'rock' => 'Rock', 'hip_hop' => 'Hip Hop', 'electronic' => 'Electronic/EDM', 'folk' => 'Folk', 'international' => 'International', 'regional' => 'Regional' ] ], 'gaming_habits' => [ 'question' => 'How often do you play games (mobile, PC, console)?', 'type' => 'single', 'options' => [ 'daily' => 'Daily', 'few_times_week' => 'Few times a week', 'weekly' => 'Weekly', 'monthly' => 'Monthly', 'rarely' => 'Rarely', 'never' => 'Never' ] ], 'reading_habits' => [ 'question' => 'How often do you read books, magazines, or blogs?', 'type' => 'single', 'options' => [ 'daily' => 'Daily', 'few_times_week' => 'Few times a week', 'weekly' => 'Weekly', 'monthly' => 'Monthly', 'rarely' => 'Rarely', 'never' => 'Never' ] ], 'content_consumption_device' => [ 'question' => 'Which device do you primarily use for entertainment? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'smartphone' => 'Smartphone', 'smart_tv' => 'Smart TV', 'laptop' => 'Laptop', 'tablet' => 'Tablet', 'desktop' => 'Desktop computer', 'gaming_console' => 'Gaming console', 'traditional_tv' => 'Traditional TV' ] ], 'entertainment_spending' => [ 'question' => 'How much do you spend on entertainment monthly?', 'type' => 'single', 'options' => [ 'below_500' => 'Below ₹500', '500_1000' => '₹500 - ₹1,000', '1000_2000' => '₹1,000 - ₹2,000', '2000_5000' => '₹2,000 - ₹5,000', 'above_5000' => 'Above ₹5,000', 'not_sure' => 'Not sure' ] ] ] ], 'food_dining' => [ 'name' => 'Food & Dining', 'description' => 'Share your food preferences and dining habits', 'questions' => [ 'cooking_frequency' => [ 'question' => 'How often do you cook at home?', 'type' => 'single', 'options' => [ 'daily' => 'Daily', 'few_times_week' => 'Few times a week', 'weekly' => 'Weekly', 'monthly' => 'Monthly', 'rarely' => 'Rarely', 'never' => 'Never - I don\'t cook' ] ], 'cuisine_preferences' => [ 'question' => 'Which cuisines do you enjoy? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'north_indian' => 'North Indian', 'south_indian' => 'South Indian', 'regional_local' => 'Regional/Local cuisine', 'chinese' => 'Chinese', 'italian' => 'Italian', 'continental' => 'Continental', 'mexican' => 'Mexican', 'thai' => 'Thai', 'japanese' => 'Japanese', 'fast_food' => 'Fast food' ] ], 'dining_out_frequency' => [ 'question' => 'How often do you dine out or order food?', 'type' => 'single', 'options' => [ 'daily' => 'Daily', 'few_times_week' => 'Few times a week', 'weekly' => 'Weekly', 'monthly' => 'Monthly', 'occasionally' => 'Occasionally', 'rarely' => 'Rarely' ] ], 'food_delivery_apps' => [ 'question' => 'Which food delivery apps do you use? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'zomato' => 'Zomato', 'swiggy' => 'Swiggy', 'uber_eats' => 'Uber Eats', 'dominos' => 'Domino\'s', 'pizza_hut' => 'Pizza Hut', 'restaurant_direct' => 'Restaurant direct delivery', 'none' => 'None - I don\'t use food delivery' ] ], 'food_spending_monthly' => [ 'question' => 'How much do you spend on food (including dining out) monthly?', 'type' => 'single', 'options' => [ 'below_3k' => 'Below ₹3,000', '3k_5k' => '₹3,000 - ₹5,000', '5k_8k' => '₹5,000 - ₹8,000', '8k_12k' => '₹8,000 - ₹12,000', '12k_20k' => '₹12,000 - ₹20,000', 'above_20k' => 'Above ₹20,000' ] ], 'special_dietary_requirements' => [ 'question' => 'Do you have any special dietary requirements? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'gluten_free' => 'Gluten-free', 'dairy_free' => 'Dairy-free', 'sugar_free' => 'Sugar-free/Low sugar', 'low_sodium' => 'Low sodium', 'organic_only' => 'Organic food only', 'weight_management' => 'Weight management diet', 'diabetic_friendly' => 'Diabetic-friendly', 'none' => 'No special requirements' ] ], 'grocery_shopping_preference' => [ 'question' => 'Where do you prefer to buy groceries? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'local_stores' => 'Local grocery stores', 'supermarkets' => 'Supermarkets', 'online_delivery' => 'Online grocery delivery', 'wholesale_markets' => 'Wholesale markets', 'organic_stores' => 'Organic/specialty stores', 'convenience_stores' => 'Convenience stores' ] ], 'beverage_preferences' => [ 'question' => 'What beverages do you regularly consume? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'tea' => 'Tea', 'coffee' => 'Coffee', 'soft_drinks' => 'Soft drinks', 'juices' => 'Fruit juices', 'energy_drinks' => 'Energy drinks', 'health_drinks' => 'Health drinks/Protein shakes', 'alcohol' => 'Alcoholic beverages', 'water_only' => 'Mostly just water' ] ] ] ], 'financial_services' => [ 'name' => 'Financial Services', 'description' => 'Tell us about your financial preferences and banking habits', 'questions' => [ 'primary_bank' => [ 'question' => 'Which is your primary bank?', 'type' => 'single', 'options' => [ 'sbi' => 'State Bank of India (SBI)', 'hdfc' => 'HDFC Bank', 'icici' => 'ICICI Bank', 'axis' => 'Axis Bank', 'pnb' => 'Punjab National Bank', 'canara' => 'Canara Bank', 'bob' => 'Bank of Baroda', 'kotak' => 'Kotak Mahindra Bank', 'yes_bank' => 'Yes Bank', 'other' => 'Other' ] ], 'banking_frequency' => [ 'question' => 'How often do you visit bank branches?', 'type' => 'single', 'options' => [ 'weekly' => 'Weekly', 'monthly' => 'Monthly', 'quarterly' => 'Quarterly', 'rarely' => 'Rarely', 'never' => 'Never - I use only digital banking' ] ], 'investment_products' => [ 'question' => 'Which investment products do you currently use? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'savings_account' => 'Savings account', 'fixed_deposits' => 'Fixed deposits', 'mutual_funds' => 'Mutual funds', 'stocks' => 'Stocks/Shares', 'ppf' => 'PPF (Public Provident Fund)', 'nps' => 'NPS (National Pension System)', 'life_insurance' => 'Life insurance', 'gold' => 'Gold investments', 'real_estate' => 'Real estate', 'none' => 'None of these' ] ], 'credit_products' => [ 'question' => 'Which credit products do you use? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'credit_card' => 'Credit card', 'personal_loan' => 'Personal loan', 'home_loan' => 'Home loan', 'car_loan' => 'Car loan', 'education_loan' => 'Education loan', 'business_loan' => 'Business loan', 'overdraft' => 'Overdraft facility', 'none' => 'None' ] ], 'financial_planning' => [ 'question' => 'Do you engage in financial planning?', 'type' => 'single', 'options' => [ 'professional_advisor' => 'Yes, with a professional financial advisor', 'self_planned' => 'Yes, I plan myself', 'family_guidance' => 'Yes, with family guidance', 'basic_planning' => 'Basic planning only', 'no_planning' => 'No, I don\'t plan financially', 'want_to_start' => 'No, but I want to start' ] ], 'insurance_products' => [ 'question' => 'What insurance products do you have? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'life_insurance' => 'Life insurance', 'health_insurance' => 'Health insurance', 'vehicle_insurance' => 'Vehicle insurance', 'home_insurance' => 'Home insurance', 'travel_insurance' => 'Travel insurance', 'term_insurance' => 'Term insurance', 'none' => 'No insurance' ] ], 'digital_payment_comfort' => [ 'question' => 'How comfortable are you with digital payments?', 'type' => 'single', 'options' => [ 'very_comfortable' => 'Very comfortable - I use for all transactions', 'mostly_comfortable' => 'Mostly comfortable - I use for most transactions', 'somewhat_comfortable' => 'Somewhat comfortable - I use for small amounts', 'limited_use' => 'Limited use - Only when necessary', 'prefer_cash' => 'I prefer cash transactions' ] ], 'financial_goals' => [ 'question' => 'What are your main financial goals? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'emergency_fund' => 'Building emergency fund', 'retirement_planning' => 'Retirement planning', 'home_purchase' => 'Buying a home', 'child_education' => 'Children\'s education', 'wealth_creation' => 'Wealth creation', 'debt_reduction' => 'Reducing debt', 'travel_fund' => 'Travel fund', 'business_investment' => 'Starting/expanding business', 'no_specific_goals' => 'No specific goals' ] ] ] ], 'communication_payments' => [ 'name' => 'Communication & Payments', 'description' => 'Share your communication preferences and survey availability', 'questions' => [ 'preferred_communication_time' => [ 'question' => 'When would you prefer to receive survey invitations?', 'type' => 'multiple', 'options' => [ 'morning' => 'Morning (6 AM - 12 PM)', 'afternoon' => 'Afternoon (12 PM - 6 PM)', 'evening' => 'Evening (6 PM - 10 PM)', 'night' => 'Night (10 PM - 12 AM)', 'weekends' => 'Weekends only', 'anytime' => 'Anytime when free' ] ], 'notification_preferences' => [ 'question' => 'How would you like to receive survey notifications? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'sms' => 'SMS', 'email' => 'Email', 'whatsapp' => 'WhatsApp', 'app_notification' => 'App notification', 'phone_call' => 'Phone call' ] ], 'primary_communication_language' => [ 'question' => 'What is your preferred language for communication?', 'type' => 'single', 'options' => [ 'english' => 'English', 'hindi' => 'Hindi', 'tamil' => 'Tamil', 'telugu' => 'Telugu', 'bengali' => 'Bengali', 'marathi' => 'Marathi', 'gujarati' => 'Gujarati', 'kannada' => 'Kannada', 'malayalam' => 'Malayalam', 'punjabi' => 'Punjabi', 'other' => 'Other' ] ], 'survey_participation_availability' => [ 'question' => 'When are you typically available to participate in surveys?', 'type' => 'multiple', 'options' => [ 'morning' => 'Morning (6 AM - 12 PM)', 'afternoon' => 'Afternoon (12 PM - 6 PM)', 'evening' => 'Evening (6 PM - 10 PM)', 'night' => 'Night (10 PM - 12 AM)', 'weekends' => 'Weekends only', 'anytime' => 'Anytime when free' ] ], 'survey_types_interest' => [ 'question' => 'What types of surveys interest you most? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'products' => 'Product reviews and feedback', 'brands' => 'Brand awareness surveys', 'lifestyle' => 'Lifestyle and habits', 'technology' => 'Technology and gadgets', 'entertainment' => 'Entertainment and media', 'politics' => 'Political opinions', 'social_issues' => 'Social issues', 'health' => 'Health and wellness', 'finance' => 'Financial products and services', 'all_types' => 'All types of surveys' ] ] ] ] ]; // Get the requested section $currentSection = isset($_GET['section']) ? $_GET['section'] : null; if (!$currentSection || !isset($profilerSections[$currentSection])) { header('Location: dashboard.php#profiler'); exit; } $section = $profilerSections[$currentSection]; // Get existing responses for this section $existingResponses = []; try { $stmt = $pdo->prepare("SELECT question_id, response FROM user_profiler WHERE user_id = ? AND section = ?"); $stmt->execute([$user['id'], $currentSection]); while ($row = $stmt->fetch()) { $existingResponses[$row['question_id']] = json_decode($row['response'], true); } } catch (Exception $e) { logError('Error fetching existing responses', ['user_id' => $user['id'], 'section' => $currentSection, 'error' => $e->getMessage()]); } // Handle form submission if ($_SERVER['REQUEST_METHOD'] === 'POST') { $responses = []; $hasErrors = false; $errorMessages = []; foreach ($section['questions'] as $questionId => $questionData) { if ($questionData['type'] === 'single') { $value = isset($_POST[$questionId]) ? sanitize($_POST[$questionId]) : ''; if (!empty($value)) { $responses[$questionId] = $value; } } elseif ($questionData['type'] === 'multiple') { $values = isset($_POST[$questionId]) ? $_POST[$questionId] : []; if (is_array($values)) { $cleanValues = array_map('sanitize', $values); $responses[$questionId] = $cleanValues; } } } if (!$hasErrors) { try { $pdo->beginTransaction(); // Save all responses foreach ($responses as $questionId => $response) { $stmt = $pdo->prepare("INSERT INTO user_profiler (user_id, section, question_id, response) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE response = ?, updated_at = NOW()"); $responseJson = json_encode($response); $stmt->execute([$user['id'], $currentSection, $questionId, $responseJson, $responseJson]); } // Calculate completion percentage $totalQuestions = count($section['questions']); $answeredQuestions = count($responses); $completionPercentage = ($answeredQuestions / $totalQuestions) * 100; $isCompleted = $completionPercentage >= 100; // Update completion status $stmt = $pdo->prepare("INSERT INTO profiler_completion (user_id, section, total_questions, answered_questions, completion_percentage, is_completed, completed_at) VALUES (?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE answered_questions = ?, completion_percentage = ?, is_completed = ?, completed_at = CASE WHEN ? = 1 THEN NOW() ELSE completed_at END, updated_at = NOW()"); $completedAt = $isCompleted ? date('Y-m-d H:i:s') : null; $stmt->execute([$user['id'], $currentSection, $totalQuestions, $answeredQuestions, $completionPercentage, $isCompleted, $completedAt, $answeredQuestions, $completionPercentage, $isCompleted, $isCompleted]); // Award points if section is completed and not already awarded if ($isCompleted) { $stmt = $pdo->prepare("SELECT points_awarded FROM profiler_completion WHERE user_id = ? AND section = ?"); $stmt->execute([$user['id'], $currentSection]); $completion = $stmt->fetch(); if ($completion && !$completion['points_awarded']) { // Award 5 points for all sections (removed mobile/UPI bonus) $pointsToAward = 5; $pointsDescription = 'Profiler section completion: ' . $section['name']; // Award points $stmt = $pdo->prepare("INSERT INTO user_points (user_id, points, total_earned) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE points = points + ?, total_earned = total_earned + ?"); $stmt->execute([$user['id'], $pointsToAward, $pointsToAward, $pointsToAward, $pointsToAward]); // Add transaction record $stmt = $pdo->prepare("INSERT INTO point_transactions (user_id, transaction_type, points, source, description) VALUES (?, 'earned', ?, ?, ?)"); $stmt->execute([$user['id'], $pointsToAward, 'profiler_' . $currentSection, $pointsDescription]); // Mark points as awarded $stmt = $pdo->prepare("UPDATE profiler_completion SET points_awarded = 1 WHERE user_id = ? AND section = ?"); $stmt->execute([$user['id'], $currentSection]); logError('Profiler points awarded', ['user_id' => $user['id'], 'section' => $currentSection, 'points' => $pointsToAward]); } } $pdo->commit(); // Redirect back to dashboard with success header('Location: dashboard.php#profiler&success=1'); exit; } catch (Exception $e) { $pdo->rollback(); logError('Error saving profiler responses', ['user_id' => $user['id'], 'section' => $currentSection, 'error' => $e->getMessage()]); $errorMessages[] = 'Error saving your responses. Please try again.'; } } } ?>