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' ] ], 'languages_spoken' => [ 'question' => 'Which languages can you speak fluently? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'hindi' => 'Hindi', 'english' => 'English', 'bengali' => 'Bengali', 'marathi' => 'Marathi', 'tamil' => 'Tamil', 'telugu' => 'Telugu', 'gujarati' => 'Gujarati', 'kannada' => 'Kannada', 'punjabi' => 'Punjabi', 'malayalam' => 'Malayalam', 'other' => 'Other Regional Language' ] ], 'city_type' => [ 'question' => 'What type of area do you live in?', 'type' => 'single', 'options' => [ 'metro_city' => 'Metro City (Mumbai, Delhi, Bangalore, etc.)', 'tier2_city' => 'Tier 2 City (Pune, Jaipur, Lucknow, etc.)', 'tier3_city' => 'Tier 3 City', 'town' => 'Small Town', 'village' => 'Village/Rural Area' ] ] ] ], 'household_family' => [ 'name' => 'Household & Family', 'description' => 'Information about your family and household', 'questions' => [ 'marital_status' => [ 'question' => 'What is your marital status?', 'type' => 'single', 'options' => [ 'single' => 'Single/Unmarried', 'married' => 'Married', 'divorced' => 'Divorced', 'widowed' => 'Widowed', 'separated' => 'Separated' ] ], 'family_type' => [ 'question' => 'What type of family do you live in?', 'type' => 'single', 'options' => [ 'nuclear' => 'Nuclear Family (Parents + Children)', 'joint' => 'Joint Family (Extended Family)', 'single_parent' => 'Single Parent Family', 'alone' => 'Living Alone', 'with_friends' => 'Living with Friends/Roommates' ] ], 'household_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' ] ], 'children_count' => [ 'question' => 'How many children (under 18) are in your household?', 'type' => 'single', 'options' => [ '0' => 'No children', '1' => '1 child', '2' => '2 children', '3' => '3 children', '4_plus' => '4 or more children' ] ], 'household_income' => [ 'question' => 'What is your total household monthly income?', 'type' => 'single', 'options' => [ 'below_25k' => 'Below ₹25,000', '25k_50k' => '₹25,000 - ₹50,000', '50k_75k' => '₹50,000 - ₹75,000', '75k_1l' => '₹75,000 - ₹1,00,000', '1l_2l' => '₹1,00,000 - ₹2,00,000', '2l_3l' => '₹2,00,000 - ₹3,00,000', 'above_3l' => 'Above ₹3,00,000' ] ], 'housing_type' => [ 'question' => 'What type of housing do you live in?', 'type' => 'single', 'options' => [ 'own_house' => 'Own House', 'rented_house' => 'Rented House/Independent', 'rented_apartment' => 'Rented Apartment/Flat', 'own_apartment' => 'Own Apartment/Flat', 'family_house' => 'Family Owned House', 'pg_hostel' => 'PG/Hostel' ] ], 'decision_maker' => [ 'question' => 'Who is the primary decision maker for major purchases in your household?', 'type' => 'single', 'options' => [ 'self' => 'I make the decisions', 'spouse' => 'My spouse', 'parents' => 'Parents/Elders', 'joint' => 'Joint decision with family', 'others' => 'Other family members' ] ] ] ], 'shopping_lifestyle' => [ 'name' => 'Shopping & Lifestyle', 'description' => 'Your shopping habits and lifestyle preferences', 'questions' => [ 'shopping_frequency' => [ 'question' => 'How often do you go shopping for personal items?', 'type' => 'single', 'options' => [ 'daily' => 'Daily', 'weekly' => 'Weekly', 'bi_weekly' => 'Bi-weekly', 'monthly' => 'Monthly', 'quarterly' => 'Every 3-4 months', 'rarely' => 'Very rarely' ] ], 'preferred_shopping_method' => [ 'question' => 'How do you prefer to shop? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'online' => 'Online (E-commerce)', 'local_stores' => 'Local/Neighborhood stores', 'malls' => 'Shopping Malls', 'brand_stores' => 'Brand Outlets', 'wholesale_markets' => 'Wholesale Markets', 'street_vendors' => 'Street Vendors/Local Markets' ] ], 'online_platforms' => [ 'question' => 'Which online platforms do you use for shopping? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'amazon' => 'Amazon', 'flipkart' => 'Flipkart', 'myntra' => 'Myntra', 'nykaa' => 'Nykaa', 'ajio' => 'Ajio', 'meesho' => 'Meesho', 'jiomart' => 'JioMart', 'bigbasket' => 'BigBasket', 'swiggy_instamart' => 'Swiggy Instamart', 'none' => 'I don\'t shop online' ] ], 'spending_categories' => [ 'question' => 'Which categories do you spend most on? (Select top 3)', 'type' => 'multiple', 'options' => [ 'food_groceries' => 'Food & Groceries', 'clothing_fashion' => 'Clothing & Fashion', 'electronics' => 'Electronics & Gadgets', 'health_beauty' => 'Health & Beauty', 'home_furniture' => 'Home & Furniture', 'education' => 'Education/Books', 'travel' => 'Travel & Transportation', 'entertainment' => 'Entertainment', 'utilities' => 'Utilities & Bills', 'savings_investment' => 'Savings & Investment' ] ], 'brand_preference' => [ 'question' => 'When shopping, do you prefer branded products?', 'type' => 'single', 'options' => [ 'always_branded' => 'Always prefer branded products', 'mostly_branded' => 'Mostly branded, sometimes local', 'mixed' => 'Mix of branded and local products', 'mostly_local' => 'Mostly local, sometimes branded', 'price_focused' => 'Price matters more than brand' ] ], 'payment_methods' => [ 'question' => 'Which payment methods do you use regularly? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'cash' => 'Cash', 'debit_card' => 'Debit Card', 'credit_card' => 'Credit Card', 'upi' => 'UPI (PhonePe, Google Pay, Paytm)', 'net_banking' => 'Net Banking', 'wallets' => 'Digital Wallets', 'emi' => 'EMI/Buy Now Pay Later', 'cod' => 'Cash on Delivery' ] ], 'lifestyle_interests' => [ 'question' => 'What are your main lifestyle interests? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'fitness_health' => 'Fitness & Health', 'fashion_beauty' => 'Fashion & Beauty', 'cooking_food' => 'Cooking & Food', 'travel_adventure' => 'Travel & Adventure', 'technology' => 'Technology & Gadgets', 'reading_books' => 'Reading & Books', 'movies_entertainment' => 'Movies & Entertainment', 'sports' => 'Sports', 'music_arts' => 'Music & Arts', 'home_decor' => 'Home Decoration' ] ] ] ], 'technology_digital' => [ 'name' => 'Technology & Digital', 'description' => 'Your technology usage and digital habits', 'questions' => [ 'devices_owned' => [ 'question' => 'Which devices do you own? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'smartphone' => 'Smartphone', 'laptop' => 'Laptop', 'desktop' => 'Desktop Computer', 'tablet' => 'Tablet', 'smart_tv' => 'Smart TV', 'smartwatch' => 'Smartwatch', 'earbuds' => 'Wireless Earbuds', 'gaming_console' => 'Gaming Console', 'smart_speaker' => 'Smart Speaker (Alexa, Google Home)' ] ], 'smartphone_brand' => [ 'question' => 'Which smartphone brand do you currently use?', 'type' => 'single', 'options' => [ 'samsung' => 'Samsung', 'xiaomi' => 'Xiaomi/Mi/Redmi', 'apple' => 'Apple iPhone', 'vivo' => 'Vivo', 'oppo' => 'Oppo', 'oneplus' => 'OnePlus', 'realme' => 'Realme', 'motorola' => 'Motorola', 'nokia' => 'Nokia', 'other' => 'Other brand' ] ], 'internet_usage_hours' => [ 'question' => 'How many hours do you spend on the internet daily?', 'type' => 'single', 'options' => [ '1_2' => '1-2 hours', '3_4' => '3-4 hours', '5_6' => '5-6 hours', '7_8' => '7-8 hours', '9_plus' => 'More than 8 hours' ] ], 'social_media_platforms' => [ 'question' => 'Which social media platforms do you use regularly? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'whatsapp' => 'WhatsApp', 'facebook' => 'Facebook', 'instagram' => 'Instagram', 'twitter' => 'Twitter/X', 'linkedin' => 'LinkedIn', 'youtube' => 'YouTube', 'telegram' => 'Telegram', 'snapchat' => 'Snapchat', 'tiktok' => 'TikTok/Instagram Reels', 'reddit' => 'Reddit', 'none' => 'I don\'t use social media' ] ], 'online_activities' => [ 'question' => 'What do you primarily use the internet for? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'communication' => 'Communication (calls, messages)', 'entertainment' => 'Entertainment (videos, music, games)', 'shopping' => 'Online Shopping', 'work_study' => 'Work/Study related', 'news_info' => 'News & Information', 'social_media' => 'Social Media', 'banking' => 'Online Banking/Payments', 'food_delivery' => 'Food Delivery Apps', 'navigation' => 'Maps & Navigation', 'learning' => 'Online Learning/Courses' ] ], 'app_categories' => [ 'question' => 'Which type of apps do you use most frequently? (Select top 3)', 'type' => 'multiple', 'options' => [ 'messaging' => 'Messaging & Communication', 'social_media' => 'Social Media', 'entertainment' => 'Entertainment (Video, Music)', 'shopping' => 'Shopping & E-commerce', 'food_delivery' => 'Food Delivery', 'banking_finance' => 'Banking & Finance', 'news' => 'News & Information', 'productivity' => 'Productivity & Work', 'gaming' => 'Gaming', 'health_fitness' => 'Health & Fitness' ] ], 'technology_adoption' => [ 'question' => 'How would you describe yourself regarding new technology?', 'type' => 'single', 'options' => [ 'early_adopter' => 'Early adopter - I try new tech first', 'quick_follower' => 'Quick follower - I adopt after initial reviews', 'mainstream' => 'Mainstream - I wait for technology to become popular', 'late_adopter' => 'Late adopter - I prefer proven, established technology', 'reluctant' => 'Reluctant - I only adopt when necessary' ] ] ] ], 'travel_transportation' => [ 'name' => 'Travel & Transportation', 'description' => 'Your travel habits and transportation preferences', 'questions' => [ 'primary_transport' => [ 'question' => 'What is your primary mode of daily transportation?', 'type' => 'single', 'options' => [ 'own_car' => 'Own Car', 'own_bike' => 'Own Two-wheeler (Bike/Scooter)', 'public_bus' => 'Public Bus', 'metro_train' => 'Metro/Local Train', 'auto_rickshaw' => 'Auto Rickshaw', 'taxi_cab' => 'Taxi/Cab Services', 'ride_sharing' => 'Ride Sharing (Ola/Uber)', 'walking_cycling' => 'Walking/Cycling', 'work_from_home' => 'Work from Home (No commute)' ] ], 'vehicle_ownership' => [ 'question' => 'Which vehicles does your household own? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'car' => 'Car', 'motorcycle' => 'Motorcycle', 'scooter' => 'Scooter', 'bicycle' => 'Bicycle', 'none' => 'No vehicles owned' ] ], 'travel_frequency' => [ 'question' => 'How often do you travel outside your city for leisure?', 'type' => 'single', 'options' => [ 'monthly' => 'Monthly or more', 'quarterly' => 'Once every 2-3 months', 'bi_annually' => 'Twice a year', 'annually' => 'Once a year', 'rarely' => 'Very rarely', 'never' => 'Never' ] ], 'preferred_travel_mode' => [ 'question' => 'For long-distance travel, what do you prefer? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'train' => 'Train', 'bus' => 'Bus', 'flight' => 'Flight', 'own_vehicle' => 'Own Vehicle', 'taxi_cab' => 'Taxi/Cab' ] ], 'travel_booking_method' => [ 'question' => 'How do you usually book your travel?', 'type' => 'single', 'options' => [ 'online_apps' => 'Online Travel Apps (MakeMyTrip, etc.)', 'travel_agent' => 'Through Travel Agent', 'direct_booking' => 'Direct booking (Railway/Airline websites)', 'offline_counter' => 'Offline counters', 'dont_travel' => 'I don\'t travel much' ] ], 'fuel_type' => [ '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', 'no_vehicle' => 'I don\'t own a vehicle' ] ], 'ride_sharing_usage' => [ 'question' => 'How often do you use ride-sharing services (Ola/Uber)?', 'type' => 'single', 'options' => [ 'daily' => 'Daily', 'weekly' => 'Few times a week', 'monthly' => 'Few times a month', 'occasionally' => 'Occasionally', 'never' => 'Never use' ] ] ] ], 'health_fitness' => [ 'name' => 'Health & Fitness', 'description' => 'Your health, fitness, and wellness habits', 'questions' => [ 'health_insurance' => [ 'question' => 'Do you have health insurance coverage?', 'type' => 'single', 'options' => [ 'employer_provided' => 'Yes, through employer', 'self_purchased' => 'Yes, self-purchased policy', 'family_plan' => 'Yes, covered under family plan', 'government_scheme' => 'Yes, government scheme (Ayushman Bharat, etc.)', 'no_insurance' => 'No health insurance' ] ], 'fitness_activities' => [ 'question' => 'Which fitness activities do you regularly engage in? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'walking' => 'Walking/Jogging', 'gym' => 'Gym/Weight Training', 'yoga' => 'Yoga', 'cycling' => 'Cycling', 'swimming' => 'Swimming', 'sports' => 'Sports (Cricket, Badminton, etc.)', 'dancing' => 'Dancing', 'home_workout' => 'Home Workouts', 'martial_arts' => 'Martial Arts', 'none' => 'No regular fitness activity' ] ], 'exercise_frequency' => [ 'question' => 'How often do you exercise or engage in physical activity?', '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' ] ], 'diet_type' => [ 'question' => 'What type of diet do you follow?', 'type' => 'single', 'options' => [ 'vegetarian' => 'Vegetarian', 'non_vegetarian' => 'Non-vegetarian', 'vegan' => 'Vegan', 'eggetarian' => 'Eggetarian (Vegetarian + Eggs)', 'jain_vegetarian' => 'Jain Vegetarian', 'pescatarian' => 'Pescatarian (Fish only)', 'no_restriction' => 'No dietary restrictions' ] ], 'health_concerns' => [ 'question' => 'Which health concerns are you most conscious about? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'weight_management' => 'Weight Management', 'diabetes' => 'Diabetes', 'heart_health' => 'Heart Health', 'blood_pressure' => 'Blood Pressure', 'stress_anxiety' => 'Stress & Anxiety', 'immunity' => 'Immunity Boosting', 'bone_joint_health' => 'Bone & Joint Health', 'digestive_health' => 'Digestive Health', 'skin_hair' => 'Skin & Hair Care', 'none' => 'No specific health concerns' ] ], 'wellness_products' => [ 'question' => 'Which wellness products do you use? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'vitamins_supplements' => 'Vitamins & Supplements', 'protein_powder' => 'Protein Powder/Shakes', 'herbal_products' => 'Herbal/Ayurvedic Products', 'organic_foods' => 'Organic Foods', 'fitness_tracker' => 'Fitness Tracker/Smartwatch', 'health_apps' => 'Health & Fitness Mobile Apps', 'meditation_apps' => 'Meditation/Mental Health Apps', 'none' => 'None of the above' ] ], 'healthcare_preference' => [ 'question' => 'What type of healthcare do you prefer?', 'type' => 'single', 'options' => [ 'allopathic' => 'Allopathic (Modern Medicine)', 'ayurvedic' => 'Ayurvedic', 'homeopathic' => 'Homeopathic', 'combination' => 'Combination of different systems', 'home_remedies' => 'Prefer home remedies first' ] ] ] ], 'entertainment_media' => [ 'name' => 'Entertainment & Media', 'description' => 'Your entertainment preferences and media consumption', 'questions' => [ 'tv_viewing_time' => [ 'question' => 'How much time do you spend watching TV/videos daily?', 'type' => 'single', 'options' => [ 'less_1_hour' => 'Less than 1 hour', '1_2_hours' => '1-2 hours', '3_4_hours' => '3-4 hours', '5_plus_hours' => '5+ hours', 'no_tv' => 'I don\'t watch TV/videos' ] ], 'streaming_platforms' => [ 'question' => 'Which streaming platforms do you use? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'youtube' => 'YouTube', 'netflix' => 'Netflix', 'amazon_prime' => 'Amazon Prime Video', 'hotstar' => 'Disney+ Hotstar', 'zee5' => 'ZEE5', 'sony_liv' => 'SonyLIV', 'voot' => 'Voot', 'mx_player' => 'MX Player', 'alt_balaji' => 'ALTBalaji', 'none' => 'I don\'t use streaming platforms' ] ], 'content_preferences' => [ 'question' => 'What type of content do you prefer? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'bollywood_movies' => 'Bollywood Movies', 'regional_movies' => 'Regional Movies', 'hollywood_movies' => 'Hollywood Movies', 'tv_serials' => 'TV Serials/Soap Operas', 'web_series' => 'Web Series', 'documentaries' => 'Documentaries', 'reality_shows' => 'Reality Shows', 'comedy_shows' => 'Comedy Shows', 'news' => 'News Programs', 'sports' => 'Sports' ] ], 'music_preferences' => [ 'question' => 'What type of music do you listen to? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'bollywood' => 'Bollywood', 'regional' => 'Regional (Tamil, Telugu, Punjabi, etc.)', 'classical' => 'Classical Indian', 'western_pop' => 'Western Pop/Rock', 'devotional' => 'Devotional/Religious', 'folk' => 'Folk Music', 'instrumental' => 'Instrumental', 'indie' => 'Independent/Indie', 'no_music' => 'I don\'t listen to music much' ] ], 'music_platforms' => [ 'question' => 'Which music platforms do you use? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'youtube_music' => 'YouTube Music', 'spotify' => 'Spotify', 'gaana' => 'Gaana', 'jiosaavn' => 'JioSaavn', 'amazon_music' => 'Amazon Music', 'wynk' => 'Wynk Music', 'apple_music' => 'Apple Music', 'radio' => 'FM Radio', 'none' => 'I don\'t use music platforms' ] ], 'gaming_interest' => [ 'question' => 'How interested are you in gaming?', 'type' => 'single', 'options' => [ 'very_interested' => 'Very interested - I game daily', 'somewhat_interested' => 'Somewhat interested - I game occasionally', 'casual' => 'Casual - Only simple mobile games', 'not_interested' => 'Not interested in gaming' ] ], 'news_sources' => [ 'question' => 'Where do you primarily get your news from? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'tv_news' => 'TV News Channels', 'newspapers' => 'Newspapers', 'news_websites' => 'News Websites', 'social_media' => 'Social Media', 'news_apps' => 'News Apps', 'whatsapp' => 'WhatsApp forwards', 'radio' => 'Radio', 'word_of_mouth' => 'Word of mouth', 'no_news' => 'I don\'t follow news regularly' ] ], 'reading_habits' => [ 'question' => 'What do you like to read? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'fiction_books' => 'Fiction Books', 'non_fiction' => 'Non-fiction Books', 'magazines' => 'Magazines', 'newspapers' => 'Newspapers', 'blogs' => 'Online Blogs/Articles', 'comics' => 'Comics/Graphic Novels', 'religious_texts' => 'Religious/Spiritual Texts', 'no_reading' => 'I don\'t read much' ] ] ] ], 'food_dining' => [ 'name' => 'Food & Dining', 'description' => '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' => 'Once a week', 'monthly' => 'Few times a month', 'rarely' => 'Rarely', 'never' => 'Never - someone else cooks' ] ], 'cuisine_preferences' => [ 'question' => 'Which cuisines do you enjoy? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'north_indian' => 'North Indian', 'south_indian' => 'South Indian', 'gujarati' => 'Gujarati', 'punjabi' => 'Punjabi', 'bengali' => 'Bengali', 'maharashtrian' => 'Maharashtrian', 'chinese' => 'Chinese', 'continental' => 'Continental', 'italian' => 'Italian', 'fast_food' => 'Fast Food', 'street_food' => 'Street Food' ] ], 'dining_out_frequency' => [ 'question' => 'How often do you dine out at restaurants?', 'type' => 'single', 'options' => [ 'multiple_times_week' => 'Multiple times a week', 'weekly' => 'Once a week', 'bi_weekly' => 'Once in 2 weeks', 'monthly' => 'Once a month', 'occasionally' => 'Only on special occasions', 'rarely' => 'Rarely/Never' ] ], 'food_delivery_usage' => [ 'question' => 'How often do you order food online?', 'type' => 'single', 'options' => [ 'daily' => 'Daily', 'few_times_week' => 'Few times a week', 'weekly' => 'Once a week', 'monthly' => 'Few times a month', 'occasionally' => 'Occasionally', 'never' => 'Never' ] ], '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', 'food_panda' => 'Foodpanda', 'dominos' => 'Domino\'s App', 'restaurant_direct' => 'Restaurant direct delivery', 'none' => 'I don\'t use food delivery apps' ] ], 'snacking_preferences' => [ 'question' => 'What type of snacks do you prefer? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'traditional_indian' => 'Traditional Indian snacks', 'western_snacks' => 'Western snacks (chips, cookies)', 'healthy_snacks' => 'Healthy snacks (nuts, fruits)', 'sweets' => 'Sweets/Desserts', 'bakery_items' => 'Bakery items', 'beverages' => 'Beverages (tea, coffee, juices)', 'ice_cream' => 'Ice cream', 'no_snacking' => 'I don\'t snack much' ] ], 'grocery_shopping' => [ 'question' => 'Where do you primarily buy groceries? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'local_stores' => 'Local grocery stores', 'supermarkets' => 'Supermarkets (Big Bazaar, etc.)', 'online_grocery' => 'Online grocery (BigBasket, Grofers)', 'wholesale_markets' => 'Wholesale markets', 'convenience_stores' => 'Convenience stores', 'organic_stores' => 'Organic food stores' ] ], 'food_consciousness' => [ 'question' => 'How conscious are you about your food choices?', 'type' => 'single', 'options' => [ 'very_conscious' => 'Very conscious - I read labels and choose carefully', 'somewhat_conscious' => 'Somewhat conscious - I try to eat healthy', 'moderately_conscious' => 'Moderately conscious - Balance of health and taste', 'not_very_conscious' => 'Not very conscious - Taste is priority', 'not_conscious' => 'Not conscious at all' ] ] ] ], 'financial_services' => [ 'name' => 'Financial Services', 'description' => 'Your financial habits and service usage', 'questions' => [ 'primary_bank' => [ 'question' => 'Which is your primary bank for savings account?', 'type' => 'single', 'options' => [ 'sbi' => 'State Bank of India (SBI)', 'hdfc' => 'HDFC Bank', 'icici' => 'ICICI Bank', 'axis' => 'Axis Bank', 'pnb' => 'Punjab National Bank', 'bob' => 'Bank of Baroda', 'kotak' => 'Kotak Mahindra Bank', 'idfc' => 'IDFC First Bank', 'yes_bank' => 'Yes Bank', 'other' => 'Other bank' ] ], 'banking_services' => [ 'question' => 'Which banking services do you use? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'savings_account' => 'Savings Account', 'current_account' => 'Current Account', 'fixed_deposit' => 'Fixed Deposit', 'recurring_deposit' => 'Recurring Deposit', 'personal_loan' => 'Personal Loan', 'home_loan' => 'Home Loan', 'credit_card' => 'Credit Card', 'demat_account' => 'Demat Account for investments', 'insurance' => 'Insurance policies' ] ], 'investment_experience' => [ 'question' => 'What is your experience with investments?', 'type' => 'single', 'options' => [ 'experienced' => 'Experienced investor', 'moderate' => 'Some experience with basic investments', 'beginner' => 'Beginner - just started investing', 'planning' => 'Planning to start investing', 'no_interest' => 'Not interested in investing' ] ], 'investment_types' => [ 'question' => 'Which investment options have you used? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'mutual_funds' => 'Mutual Funds', 'stocks' => 'Direct Stock Market', 'fixed_deposits' => 'Fixed Deposits', 'ppf' => 'Public Provident Fund (PPF)', 'nsc' => 'National Savings Certificate', 'gold' => 'Gold/Gold ETFs', 'real_estate' => 'Real Estate', 'sip' => 'SIP (Systematic Investment Plan)', 'cryptocurrency' => 'Cryptocurrency', 'none' => 'No investments yet' ] ], 'financial_goals' => [ 'question' => 'What are your primary financial goals? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'emergency_fund' => 'Building emergency fund', 'retirement' => 'Retirement planning', 'home_purchase' => 'Buying a home', 'child_education' => 'Child\'s education', 'child_marriage' => 'Child\'s marriage', 'business' => 'Starting a business', 'travel' => 'Travel & vacation', 'debt_repayment' => 'Debt repayment', 'wealth_creation' => 'Wealth creation', 'no_specific_goals' => 'No specific financial goals' ] ], 'insurance_types' => [ 'question' => 'What type of insurance 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' ] ], 'financial_planning' => [ 'question' => 'How do you manage your financial planning?', 'type' => 'single', 'options' => [ 'self_managed' => 'Self-managed', 'financial_advisor' => 'Through financial advisor', 'bank_advisor' => 'Bank relationship manager', 'family_guidance' => 'Family guidance', 'no_planning' => 'No formal financial planning' ] ], 'spending_tracking' => [ 'question' => 'How do you track your expenses?', 'type' => 'single', 'options' => [ 'mobile_apps' => 'Mobile apps', 'excel_sheets' => 'Excel/Google sheets', 'notebook' => 'Written notebook', 'bank_statements' => 'Bank statements only', 'mental_tracking' => 'Mental tracking', 'no_tracking' => 'I don\'t track expenses' ] ] ] ], 'communication_payments' => [ 'name' => 'Communication & Payments', 'description' => 'Mobile verification and payment preferences', 'questions' => [ 'mobile_number' => [ 'question' => 'Please enter your mobile number for verification', 'type' => 'mobile_verification', 'validation' => 'required|mobile' ], 'preferred_upi_app' => [ 'question' => 'Which UPI app do you use most frequently?', 'type' => 'single', 'options' => [ 'phonepe' => 'PhonePe', 'google_pay' => 'Google Pay', 'paytm' => 'Paytm', 'amazon_pay' => 'Amazon Pay', 'bhim' => 'BHIM', 'bank_upi' => 'Bank UPI app', 'other' => 'Other UPI app', 'no_upi' => 'I don\'t use UPI' ] ], 'upi_id' => [ 'question' => 'Please enter your UPI ID for reward payments (e.g., yourname@paytm)', 'type' => 'text', 'validation' => 'required|upi', 'placeholder' => 'yourname@paytm' ], 'digital_payment_frequency' => [ 'question' => 'How often do you use digital payments?', 'type' => 'single', 'options' => [ 'daily' => 'Daily', 'few_times_week' => 'Few times a week', 'weekly' => 'Once a week', 'monthly' => 'Few times a month', 'occasionally' => 'Occasionally', 'rarely' => 'Rarely' ] ], 'payment_categories' => [ 'question' => 'For which purposes do you use digital payments? (Select all that apply)', 'type' => 'multiple', 'options' => [ 'utilities' => 'Utility bills (electricity, water, gas)', 'mobile_recharge' => 'Mobile recharge', 'shopping' => 'Online shopping', 'food_delivery' => 'Food delivery', 'transport' => 'Transportation (cab, bus, metro)', 'petrol' => 'Petrol/fuel payments', 'groceries' => 'Grocery stores', 'restaurants' => 'Restaurants', 'peer_transfer' => 'Money transfer to friends/family', 'loan_emi' => 'Loan EMI payments' ] ], 'communication_preference' => [ 'question' => 'How would you prefer to receive survey invitations?', 'type' => 'multiple', 'options' => [ 'email' => 'Email', 'sms' => 'SMS', 'whatsapp' => 'WhatsApp', 'app_notification' => 'Mobile app notifications', 'phone_call' => 'Phone call' ] ], 'survey_availability' => [ 'question' => 'When are you usually available to take 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'] === 'mobile_verification') { // Handle mobile verification separately $mobileNumber = isset($_POST[$questionId]) ? sanitize($_POST[$questionId]) : ''; if (!empty($mobileNumber) && preg_match('/^[6-9]\d{9}$/', $mobileNumber)) { // Store mobile number for verification try { $stmt = $pdo->prepare("INSERT INTO mobile_verifications (user_id, mobile_number) VALUES (?, ?) ON DUPLICATE KEY UPDATE mobile_number = ?, updated_at = NOW()"); $stmt->execute([$user['id'], $mobileNumber, $mobileNumber]); $responses[$questionId] = $mobileNumber; } catch (Exception $e) { $errorMessages[] = "Error saving mobile number."; $hasErrors = true; } } else { $errorMessages[] = "Please enter a valid 10-digit mobile number."; $hasErrors = true; } } elseif ($questionData['type'] === 'text') { $value = isset($_POST[$questionId]) ? sanitize($_POST[$questionId]) : ''; if ($questionId === 'upi_id') { if (!empty($value) && preg_match('/^[\w\.-]+@[\w\.-]+$/', $value)) { $responses[$questionId] = $value; } else { $errorMessages[] = "Please enter a valid UPI ID (e.g., yourname@paytm)."; $hasErrors = true; } } else { $responses[$questionId] = $value; } } elseif ($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']) { // Determine points to award $pointsToAward = ($currentSection === 'communication_payments') ? 10 : 5; // 10 for mobile/UPI, 5 for others $pointsDescription = ($currentSection === 'communication_payments') ? 'Mobile verification and UPI details completion' : '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.'; } } } ?>