Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/attendance/admin/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/attendance/admin/setup_locations.php

<?php
require_once '../config/config.php';

// Check if user is logged in and is superuser
if (!isLoggedIn() || !hasRole('superuser')) {
    die('Access denied. Superuser required.');
}

$db = new Database();
$conn = $db->getConnection();

$success_message = '';
$error_message = '';

// Handle form submission to add sample data
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['setup_sample_data'])) {
    try {
        // Sample districts
        $sample_districts = [
            ['name' => 'Central District', 'contact' => 'John Doe', 'phone' => '+1234567890', 'email' => 'central@church.org'],
            ['name' => 'North District', 'contact' => 'Jane Smith', 'phone' => '+1234567891', 'email' => 'north@church.org'],
            ['name' => 'South District', 'contact' => 'Bob Johnson', 'phone' => '+1234567892', 'email' => 'south@church.org'],
            ['name' => 'East District', 'contact' => 'Mary Wilson', 'phone' => '+1234567893', 'email' => 'east@church.org'],
            ['name' => 'West District', 'contact' => 'David Brown', 'phone' => '+1234567894', 'email' => 'west@church.org']
        ];
        
        $district_ids = [];
        
        // Insert districts
        foreach ($sample_districts as $district) {
            $query = "INSERT INTO locations (name, type, contact_person, contact_phone, contact_email, address) 
                      VALUES (?, 'district', ?, ?, ?, ?)";
            $stmt = $conn->prepare($query);
            $stmt->execute([
                $district['name'],
                $district['contact'],
                $district['phone'],
                $district['email'],
                '123 ' . $district['name'] . ' Street'
            ]);
            $district_ids[$district['name']] = $conn->lastInsertId();
        }
        
        // Sample assemblies for each district
        $sample_assemblies = [
            'Central District' => ['Central Main Assembly', 'Central Youth Assembly'],
            'North District' => ['North Main Assembly', 'North Community Assembly'],
            'South District' => ['South Main Assembly', 'South Family Assembly'],
            'East District' => ['East Main Assembly', 'East Worship Assembly'],
            'West District' => ['West Main Assembly', 'West Fellowship Assembly']
        ];
        
        // Insert assemblies
        foreach ($sample_assemblies as $district_name => $assemblies) {
            $district_id = $district_ids[$district_name];
            foreach ($assemblies as $assembly_name) {
                $query = "INSERT INTO locations (name, type, parent_id, contact_person, contact_phone, contact_email, address) 
                          VALUES (?, 'assembly', ?, ?, ?, ?, ?)";
                $stmt = $conn->prepare($query);
                $stmt->execute([
                    $assembly_name,
                    $district_id,
                    'Pastor ' . explode(' ', $assembly_name)[0],
                    '+1234567' . rand(800, 999),
                    strtolower(str_replace(' ', '', $assembly_name)) . '@church.org',
                    '456 ' . $assembly_name . ' Avenue'
                ]);
            }
        }
        
        logActivity($_SESSION['user_id'], 'setup_locations', 'Added sample location data');
        $success_message = 'Sample location data added successfully!';
        
    } catch (Exception $e) {
        $error_message = 'Error adding sample data: ' . $e->getMessage();
    }
}

// Get current location counts
$stats_query = "SELECT 
                    COUNT(CASE WHEN type = 'district' THEN 1 END) as districts,
                    COUNT(CASE WHEN type = 'assembly' THEN 1 END) as assemblies,
                    COUNT(*) as total
                FROM locations 
                WHERE is_active = 1";
$stmt = $conn->prepare($stats_query);
$stmt->execute();
$stats = $stmt->fetch();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Location System Setup - Admin Panel</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#3B82F6',
                        secondary: '#F59E0B',
                        accent: '#6B7280'
                    }
                }
            }
        }
    </script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        .gradient-bg {
            background: linear-gradient(135deg, #3B82F6 0%, #F59E0B 50%, #6B7280 100%);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Include Sidebar -->
    <?php include 'includes/sidebar.php'; ?>

    <!-- Main Content -->
    <div class="md:ml-64">
        <!-- Header -->
        <header class="bg-white shadow-sm border-b">
            <div class="px-6 py-4">
                <h1 class="text-2xl font-bold text-gray-900">
                    <i class="fas fa-map-marker-alt mr-3 text-primary"></i>
                    Location System Setup
                </h1>
            </div>
        </header>

        <!-- Content -->
        <main class="p-6">
            <!-- Success/Error Messages -->
            <?php if ($success_message): ?>
                <div class="bg-green-50 border border-green-200 rounded-lg p-4 mb-6">
                    <div class="flex">
                        <i class="fas fa-check-circle text-green-400 mr-3 mt-0.5"></i>
                        <p class="text-green-800"><?php echo htmlspecialchars($success_message); ?></p>
                    </div>
                </div>
            <?php endif; ?>

            <?php if ($error_message): ?>
                <div class="bg-red-50 border border-red-200 rounded-lg p-4 mb-6">
                    <div class="flex">
                        <i class="fas fa-exclamation-triangle text-red-400 mr-3 mt-0.5"></i>
                        <p class="text-red-800"><?php echo htmlspecialchars($error_message); ?></p>
                    </div>
                </div>
            <?php endif; ?>

            <!-- Current Status -->
            <div class="bg-white rounded-lg shadow p-6 mb-8">
                <h2 class="text-xl font-bold text-gray-900 mb-4">
                    <i class="fas fa-chart-bar mr-2 text-primary"></i>
                    Current Location Status
                </h2>
                
                <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                    <div class="bg-blue-50 rounded-lg p-4 text-center">
                        <div class="text-3xl font-bold text-blue-600"><?php echo $stats['districts']; ?></div>
                        <div class="text-blue-800 font-medium">Districts</div>
                        <div class="text-blue-600 text-sm mt-1">
                            <i class="fas fa-building mr-1"></i>Parent Locations
                        </div>
                    </div>
                    
                    <div class="bg-purple-50 rounded-lg p-4 text-center">
                        <div class="text-3xl font-bold text-purple-600"><?php echo $stats['assemblies']; ?></div>
                        <div class="text-purple-800 font-medium">Assemblies</div>
                        <div class="text-purple-600 text-sm mt-1">
                            <i class="fas fa-church mr-1"></i>Child Locations
                        </div>
                    </div>
                    
                    <div class="bg-green-50 rounded-lg p-4 text-center">
                        <div class="text-3xl font-bold text-green-600"><?php echo $stats['total']; ?></div>
                        <div class="text-green-800 font-medium">Total Locations</div>
                        <div class="text-green-600 text-sm mt-1">
                            <i class="fas fa-map-marker-alt mr-1"></i>All Active
                        </div>
                    </div>
                </div>
            </div>

            <!-- Setup Options -->
            <div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
                <!-- Quick Setup -->
                <div class="bg-white rounded-lg shadow p-6">
                    <h2 class="text-xl font-bold text-gray-900 mb-4">
                        <i class="fas fa-rocket mr-2 text-green-600"></i>
                        Quick Setup
                    </h2>
                    
                    <p class="text-gray-600 mb-6">
                        Get started quickly with sample districts and assemblies. This will create 5 districts, 
                        each with 2 assemblies (10 assemblies total).
                    </p>
                    
                    <div class="bg-yellow-50 border border-yellow-200 rounded p-4 mb-6">
                        <div class="flex">
                            <i class="fas fa-info-circle text-yellow-600 mr-2 mt-0.5"></i>
                            <div class="text-yellow-800 text-sm">
                                <strong>Note:</strong> This will add sample data to your database. 
                                You can edit or delete these locations later.
                            </div>
                        </div>
                    </div>
                    
                    <form method="POST">
                        <button type="submit" name="setup_sample_data" 
                                class="w-full bg-green-600 text-white font-bold py-3 px-4 rounded-lg hover:bg-green-700 transition duration-300"
                                onclick="return confirm('This will add sample location data. Continue?')">
                            <i class="fas fa-plus mr-2"></i>
                            Add Sample Location Data
                        </button>
                    </form>
                </div>

                <!-- Manual Setup -->
                <div class="bg-white rounded-lg shadow p-6">
                    <h2 class="text-xl font-bold text-gray-900 mb-4">
                        <i class="fas fa-cog mr-2 text-blue-600"></i>
                        Manual Setup
                    </h2>
                    
                    <p class="text-gray-600 mb-6">
                        Set up your locations manually for complete control over your church's 
                        organizational structure.
                    </p>
                    
                    <div class="space-y-4">
                        <a href="locations.php" 
                           class="block w-full bg-blue-600 text-white text-center font-bold py-3 px-4 rounded-lg hover:bg-blue-700 transition duration-300">
                            <i class="fas fa-edit mr-2"></i>
                            Manage Locations
                        </a>
                        
                        <a href="test_locations.php" 
                           class="block w-full bg-gray-600 text-white text-center font-bold py-3 px-4 rounded-lg hover:bg-gray-700 transition duration-300">
                            <i class="fas fa-flask mr-2"></i>
                            Test Location System
                        </a>
                    </div>
                </div>
            </div>

            <!-- Setup Steps -->
            <div class="bg-white rounded-lg shadow p-6 mt-8">
                <h2 class="text-xl font-bold text-gray-900 mb-4">
                    <i class="fas fa-list-ol mr-2 text-purple-600"></i>
                    Setup Steps
                </h2>
                
                <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
                    <div class="text-center">
                        <div class="w-12 h-12 bg-blue-100 rounded-full flex items-center justify-center mx-auto mb-3">
                            <span class="text-blue-600 font-bold text-lg">1</span>
                        </div>
                        <h3 class="font-semibold text-gray-900 mb-2">Setup Locations</h3>
                        <p class="text-gray-600 text-sm">Add districts and assemblies to organize your church structure</p>
                    </div>
                    
                    <div class="text-center">
                        <div class="w-12 h-12 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-3">
                            <span class="text-green-600 font-bold text-lg">2</span>
                        </div>
                        <h3 class="font-semibold text-gray-900 mb-2">Create Programs</h3>
                        <p class="text-gray-600 text-sm">Link programs to specific locations for better organization</p>
                    </div>
                    
                    <div class="text-center">
                        <div class="w-12 h-12 bg-yellow-100 rounded-full flex items-center justify-center mx-auto mb-3">
                            <span class="text-yellow-600 font-bold text-lg">3</span>
                        </div>
                        <h3 class="font-semibold text-gray-900 mb-2">Test Forms</h3>
                        <p class="text-gray-600 text-sm">Verify attendance forms work with the new location system</p>
                    </div>
                    
                    <div class="text-center">
                        <div class="w-12 h-12 bg-purple-100 rounded-full flex items-center justify-center mx-auto mb-3">
                            <span class="text-purple-600 font-bold text-lg">4</span>
                        </div>
                        <h3 class="font-semibold text-gray-900 mb-2">Go Live</h3>
                        <p class="text-gray-600 text-sm">Start collecting attendance with the improved system</p>
                    </div>
                </div>
            </div>

            <!-- Quick Links -->
            <div class="bg-white rounded-lg shadow p-6 mt-8">
                <h2 class="text-xl font-bold text-gray-900 mb-4">
                    <i class="fas fa-external-link-alt mr-2 text-gray-600"></i>
                    Quick Links
                </h2>
                
                <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
                    <a href="../LOCATION_SYSTEM.md" target="_blank" 
                       class="flex items-center p-3 bg-gray-50 rounded-lg hover:bg-gray-100 transition-colors">
                        <i class="fas fa-book text-blue-600 mr-3"></i>
                        <span class="font-medium">Documentation</span>
                    </a>
                    
                    <a href="migrate_database.php" 
                       class="flex items-center p-3 bg-gray-50 rounded-lg hover:bg-gray-100 transition-colors">
                        <i class="fas fa-database text-green-600 mr-3"></i>
                        <span class="font-medium">Database Migration</span>
                    </a>
                    
                    <a href="../attendance/form.php?program=1" target="_blank" 
                       class="flex items-center p-3 bg-gray-50 rounded-lg hover:bg-gray-100 transition-colors">
                        <i class="fas fa-clipboard-check text-purple-600 mr-3"></i>
                        <span class="font-medium">Test Attendance Form</span>
                    </a>
                </div>
            </div>
        </main>
    </div>
</body>
</html>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists