<?php
require_once 'includes/db.php';

echo "<h2>Database Synchronization</h2>";

try {
    $res = $conn->query("SELECT COUNT(*) as count FROM services");
    $row = $res->fetch_assoc();
    
    if ($row['count'] == 0) {
        echo "<p>Table 'services' is empty. Importing data...</p>";
        
        $queries = [
            "INSERT INTO `services` (`id`, `title`, `title_hi`, `description`, `description_hi`, `icon`, `section`, `sort_order`, `created_at`) VALUES (1, 'Education', 'शिक्षा', 'Education par work aur shiksha ka prasar.', 'शिक्षा पर कार्य और शिक्षा का प्रसार।', 'fas fa-book-reader', 'Standard', 0, '2026-05-06 14:59:52')",
            "INSERT INTO `services` (`id`, `title`, `title_hi`, `description`, `description_hi`, `icon`, `section`, `sort_order`, `created_at`) VALUES (2, 'Environment', 'पर्यावरण', 'Paryavaran sanrakshan aur vriksharopan abhiyan.', 'पर्यावरण संरक्षण और वृक्षारोपण अभियान।', 'fas fa-leaf', 'Standard', 0, '2026-05-06 14:59:52')",
            "INSERT INTO `services` (`id`, `title`, `title_hi`, `description`, `description_hi`, `icon`, `section`, `sort_order`, `created_at`) VALUES (3, 'Others Social Work', 'अन्य सामाजिक कार्य', 'Supporting various social causes.', 'विभिन्न सामाजिक कार्यों में सहायता।', 'fas fa-users', 'Others Social Work', 0, '2026-05-06 14:59:52')",
            "INSERT INTO `services` (`id`, `title`, `title_hi`, `description`, `description_hi`, `icon`, `section`, `sort_order`, `created_at`) VALUES (4, 'Shaaskt Bharat', 'सशक्त भारत', 'Working towards a stronger India.', 'एक मजबूत भारत की दिशा में काम करना।', 'fas fa-flag', 'Shaaskt Bharat', 0, '2026-05-06 14:59:52')",
            "INSERT INTO `service_gallery` (`id`, `service_id`, `image`, `title`, `subtitle`, `created_at`) VALUES (1, 1, 'https://images.unsplash.com/photo-1503676260728-1c00da094a0b?q=80&w=2022&auto=format&fit=crop', 'Digital Classroom', 'Empowering students with modern technology.', '2026-05-06 15:07:26')",
            "INSERT INTO `service_gallery` (`id`, `service_id`, `image`, `title`, `subtitle`, `created_at`) VALUES (2, 1, 'https://images.unsplash.com/photo-1497633762265-9d179a990aa6?q=80&w=2073&auto=format&fit=crop', 'Library Session', 'A world of knowledge at their fingertips.', '2026-05-06 15:07:26')",
            "INSERT INTO `service_gallery` (`id`, `service_id`, `image`, `title`, `subtitle`, `created_at`) VALUES (3, 1, 'https://images.unsplash.com/photo-1509062522246-3755977927d7?q=80&w=2104&auto=format&fit=crop', 'Rural Schooling', 'Bringing quality education to every village.', '2026-05-06 15:07:26')",
            "INSERT INTO `service_gallery` (`id`, `service_id`, `image`, `title`, `subtitle`, `created_at`) VALUES (4, 2, 'https://images.unsplash.com/photo-1542601906990-b4d3fb778b09?q=80&w=2013&auto=format&fit=crop', 'Tree Plantation', 'Making the world greener, one tree at a time.', '2026-05-06 15:07:26')",
            "INSERT INTO `service_gallery` (`id`, `service_id`, `image`, `title`, `subtitle`, `created_at`) VALUES (5, 2, 'https://images.unsplash.com/photo-1532996122724-e3c354a0b15b?q=80&w=2070&auto=format&fit=crop', 'Waste Management', 'Promoting clean and sustainable living.', '2026-05-06 15:07:26')",
            "INSERT INTO `service_gallery` (`id`, `service_id`, `image`, `title`, `subtitle`, `created_at`) VALUES (6, 2, 'https://images.unsplash.com/photo-1441974231531-c6227db76b6e?q=80&w=2071&auto=format&fit=crop', 'Forest Preservation', 'Protecting our natural heritage for future generations.', '2026-05-06 15:07:26')",
            "INSERT INTO `service_gallery` (`id`, `service_id`, `image`, `title`, `subtitle`, `created_at`) VALUES (7, 3, 'https://images.unsplash.com/photo-1488521787991-ed7bbaae773c?q=80&w=2070&auto=format&fit=crop', 'Food Distribution', 'Ensuring no one goes hungry in our community.', '2026-05-06 15:07:26')",
            "INSERT INTO `service_gallery` (`id`, `service_id`, `image`, `title`, `subtitle`, `created_at`) VALUES (8, 3, 'https://images.unsplash.com/photo-1593113589914-07599018dda0?q=80&w=2070&auto=format&fit=crop', 'Health Camp', 'Providing basic medical checkups to the needy.', '2026-05-06 15:07:26')",
            "INSERT INTO `service_gallery` (`id`, `service_id`, `image`, `title`, `subtitle`, `created_at`) VALUES (9, 3, 'https://images.unsplash.com/photo-1469571486292-0ba58a3f068b?q=80&w=2070&auto=format&fit=crop', 'Elderly Care', 'Supporting the senior citizens with love and respect.', '2026-05-06 15:07:26')",
            "INSERT INTO `service_gallery` (`id`, `service_id`, `image`, `title`, `subtitle`, `created_at`) VALUES (10, 4, 'https://images.unsplash.com/photo-1532375811400-d72522079093?q=80&w=2070&auto=format&fit=crop', 'Nation Building', 'Uniting the country for a stronger future.', '2026-05-06 15:07:26')",
            "INSERT INTO `service_gallery` (`id`, `service_id`, `image`, `title`, `subtitle`, `created_at`) VALUES (11, 4, 'https://images.unsplash.com/photo-1552664730-d307ca884978?q=80&w=2070&auto=format&fit=crop', 'Youth Empowerment', 'Training the next generation of leaders.', '2026-05-06 15:07:26')",
            "INSERT INTO `service_gallery` (`id`, `service_id`, `image`, `title`, `subtitle`, `created_at`) VALUES (12, 4, 'https://images.unsplash.com/photo-1517048676732-d65bc937f952?q=80&w=2070&auto=format&fit=crop', 'Skill Development', 'Creating opportunities through vocational training.', '2026-05-06 15:07:26')"];
            
        foreach($queries as $q) {
            $conn->query($q);
        }
        echo "<p style='color:green;'>Data imported successfully!</p>";
    } else {
        echo "<p>Table 'services' already has data.</p>";
    }
    
    echo "<br><a href='services.php'>Go back to Services Page</a>";
} catch (Exception $e) {
    echo "<p style='color:red;'>Error: " . $e->getMessage() . "</p>";
}
?>
