Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/attendance/admin/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/attendance/admin/seed_data.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();

echo "<h2>Seeding Test Data</h2>";

try {
    // Get existing programs
    $query = "SELECT id, name FROM programs WHERE is_active = 1 LIMIT 3";
    $stmt = $conn->prepare($query);
    $stmt->execute();
    $programs = $stmt->fetchAll();
    
    if (empty($programs)) {
        echo "<p style='color: red;'>No active programs found. Please create some programs first.</p>";
        exit;
    }
    
    echo "<p>Found " . count($programs) . " programs to use for test data.</p>";
    
    // Sample names and data
    $names = [
        'John Smith', 'Mary Johnson', 'David Brown', 'Sarah Davis', 'Michael Wilson',
        'Jennifer Garcia', 'Christopher Martinez', 'Amanda Anderson', 'Matthew Taylor', 'Ashley Thomas',
        'Joshua Jackson', 'Jessica White', 'Andrew Harris', 'Sarah Martin', 'Daniel Thompson',
        'Melissa Garcia', 'Anthony Martinez', 'Kimberly Robinson', 'Mark Clark', 'Donna Rodriguez',
        'Steven Lewis', 'Carol Lee', 'Kenneth Walker', 'Ruth Hall', 'Paul Allen',
        'Sharon Young', 'Edward Hernandez', 'Lisa King', 'Brian Wright', 'Nancy Lopez'
    ];
    
    $districts = ['Central District', 'North District', 'South District', 'East District', 'West District'];
    $assemblies = ['Main Assembly', 'Youth Assembly', 'Family Assembly', 'Community Assembly'];
    
    $inserted = 0;
    
    // Insert 50 test records
    for ($i = 0; $i < 50; $i++) {
        $program = $programs[array_rand($programs)];
        $name = $names[array_rand($names)];
        $district = $districts[array_rand($districts)];
        $assembly = $assemblies[array_rand($assemblies)];
        $email = strtolower(str_replace(' ', '.', $name)) . '@example.com';
        $phone = '555-' . str_pad(rand(1000, 9999), 4, '0', STR_PAD_LEFT);
        
        // Random date within last 30 days
        $days_ago = rand(0, 30);
        $hours_ago = rand(0, 23);
        $minutes_ago = rand(0, 59);
        $submitted_at = date('Y-m-d H:i:s', strtotime("-$days_ago days -$hours_ago hours -$minutes_ago minutes"));
        
        $query = "INSERT INTO attendance_records (program_id, district_name, assembly_name, full_name, email, telephone, submitted_at, ip_address, user_agent) 
                  VALUES (?, ?, ?, ?, ?, ?, ?, '127.0.0.1', 'Test Data Seeder')";
        
        $stmt = $conn->prepare($query);
        $stmt->execute([
            $program['id'],
            $district,
            $assembly,
            $name,
            $email,
            $phone,
            $submitted_at
        ]);
        
        $inserted++;
    }
    
    echo "<p style='color: green;'>Successfully inserted $inserted test attendance records!</p>";
    echo "<p><a href='dashboard.php'>Go to Dashboard</a> to test infinite scrolling.</p>";
    echo "<p><a href='test_api.php'>Test API Endpoint</a></p>";
    
} catch (Exception $e) {
    echo "<p style='color: red;'>Error: " . $e->getMessage() . "</p>";
}
?>

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