Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/portal/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/portal/program-activity-report.php

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

$pageTitle = "Program Activity Report - " . APP_NAME;

$db = Database::getInstance()->getConnection();
$stmt = $db->query("SELECT * FROM general_settings ORDER BY id DESC LIMIT 1");
$settings = $stmt->fetch();

$settings = array_merge([
    'site_title' => 'Church Membership System',
    'theme_primary_color' => '#1E40AF',
    'theme_secondary_color' => '#F97316',
], $settings ?: []);

$error = '';
$success = '';
$step = 'select_program';
$selectedProgram = null;
$reportData = null;

// Check for admin session
$adminId = $_SESSION['temp_ministry_admin_id'] ?? $_SESSION['user_id'] ?? null;

// Get programs for selection
$programs = $db->query("
    SELECT p.*, a.assembly_name 
    FROM programs p 
    LEFT JOIN assemblies a ON p.assembly_id = a.id 
    WHERE p.is_active = 1 
    ORDER BY p.program_name
")->fetchAll();

// Get existing reports
$existingReports = $db->query("
    SELECT par.*, p.program_name, u.full_name as created_by_name
    FROM program_activity_reports par
    JOIN programs p ON par.program_id = p.id
    LEFT JOIN users u ON par.created_by = u.id
    ORDER BY par.activity_date DESC
    LIMIT 20
")->fetchAll();

// Handle form submission - Create Report
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['create_report'])) {
    try {
        $programId = intval($_POST['program_id']);
        $activityDate = $_POST['activity_date'];
        $programTitle = trim($_POST['program_title']);
        $facilitatorName = trim($_POST['facilitator_name'] ?? '');
        $maleAttendance = intval($_POST['male_attendance'] ?? 0);
        $femaleAttendance = intval($_POST['female_attendance'] ?? 0);
        $childrenAttendance = intval($_POST['children_attendance'] ?? 0);
        $totalAttendance = $maleAttendance + $femaleAttendance + $childrenAttendance;
        $financeCollected = floatval($_POST['finance_collected'] ?? 0);
        $bibleQuotes = trim($_POST['bible_quotes'] ?? '');
        $specialEvent = trim($_POST['special_event'] ?? '');
        $soulsWon = intval($_POST['souls_won'] ?? 0);
        $holySpiritBaptism = intval($_POST['holy_spirit_baptism'] ?? 0);
        $executivesAttended = trim($_POST['executives_attended'] ?? '');
        $otherActivities = trim($_POST['other_activities'] ?? '');
        $notes = trim($_POST['notes'] ?? '');
        
        if (empty($programId) || empty($activityDate)) {
            throw new Exception("Program and activity date are required.");
        }
        
        $insertStmt = $db->prepare("
            INSERT INTO program_activity_reports (
                program_id, activity_date, program_title, facilitator_name,
                male_attendance, female_attendance, total_attendance, children_attendance,
                finance_collected, bible_quotes, special_event, souls_won,
                holy_spirit_baptism, executives_attended, other_activities, notes, created_by
            ) VALUES (
                :program_id, :activity_date, :program_title, :facilitator_name,
                :male_attendance, :female_attendance, :total_attendance, :children_attendance,
                :finance_collected, :bible_quotes, :special_event, :souls_won,
                :holy_spirit_baptism, :executives_attended, :other_activities, :notes, :created_by
            )
        ");
        
        $insertStmt->execute([
            'program_id' => $programId,
            'activity_date' => $activityDate,
            'program_title' => $programTitle ?: null,
            'facilitator_name' => $facilitatorName ?: null,
            'male_attendance' => $maleAttendance,
            'female_attendance' => $femaleAttendance,
            'total_attendance' => $totalAttendance,
            'children_attendance' => $childrenAttendance,
            'finance_collected' => $financeCollected,
            'bible_quotes' => $bibleQuotes ?: null,
            'special_event' => $specialEvent ?: null,
            'souls_won' => $soulsWon,
            'holy_spirit_baptism' => $holySpiritBaptism,
            'executives_attended' => $executivesAttended ?: null,
            'other_activities' => $otherActivities ?: null,
            'notes' => $notes ?: null,
            'created_by' => $adminId
        ]);
        
        $success = "Activity report created successfully!";
        
        // Refresh existing reports
        $existingReports = $db->query("
            SELECT par.*, p.program_name, u.full_name as created_by_name
            FROM program_activity_reports par
            JOIN programs p ON par.program_id = p.id
            LEFT JOIN users u ON par.created_by = u.id
            ORDER BY par.activity_date DESC
            LIMIT 20
        ")->fetchAll();
        
    } catch (Exception $e) {
        $error = $e->getMessage();
    }
}

// Handle report view
if (isset($_GET['view_report'])) {
    $reportId = intval($_GET['view_report']);
    $reportStmt = $db->prepare("
        SELECT par.*, p.program_name, p.program_type, a.assembly_name, u.full_name as created_by_name
        FROM program_activity_reports par
        JOIN programs p ON par.program_id = p.id
        LEFT JOIN assemblies a ON p.assembly_id = a.id
        LEFT JOIN users u ON par.created_by = u.id
        WHERE par.id = :id
    ");
    $reportStmt->execute(['id' => $reportId]);
    $reportData = $reportStmt->fetch();
    
    if ($reportData) {
        $step = 'view_report';
    }
}

// Handle CSV Export
if (isset($_GET['export']) && $_GET['export'] === 'csv') {
    $dateFrom = $_GET['date_from'] ?? date('Y-m-01');
    $dateTo = $_GET['date_to'] ?? date('Y-m-d');
    
    $exportStmt = $db->prepare("
        SELECT par.*, p.program_name
        FROM program_activity_reports par
        JOIN programs p ON par.program_id = p.id
        WHERE par.activity_date BETWEEN :date_from AND :date_to
        ORDER BY par.activity_date DESC
    ");
    $exportStmt->execute(['date_from' => $dateFrom, 'date_to' => $dateTo]);
    $exportData = $exportStmt->fetchAll();
    
    header('Content-Type: text/csv');
    header('Content-Disposition: attachment; filename="program_activity_reports_' . date('Y-m-d') . '.csv"');
    
    $output = fopen('php://output', 'w');
    fputcsv($output, ['Program Activity Reports']);
    fputcsv($output, ['Date Range:', $dateFrom . ' to ' . $dateTo]);
    fputcsv($output, ['Generated:', date('Y-m-d H:i:s')]);
    fputcsv($output, []);
    fputcsv($output, [
        'Date', 'Program', 'Title', 'Facilitator', 'Male', 'Female', 'Children', 'Total',
        'Finance', 'Souls Won', 'Holy Spirit Baptism', 'Bible Quotes', 'Special Event',
        'Executives', 'Other Activities', 'Notes'
    ]);
    
    foreach ($exportData as $record) {
        fputcsv($output, [
            $record['activity_date'],
            $record['program_name'],
            $record['program_title'],
            $record['facilitator_name'],
            $record['male_attendance'],
            $record['female_attendance'],
            $record['children_attendance'],
            $record['total_attendance'],
            $record['finance_collected'],
            $record['souls_won'],
            $record['holy_spirit_baptism'],
            $record['bible_quotes'],
            $record['special_event'],
            $record['executives_attended'],
            $record['other_activities'],
            $record['notes']
        ]);
    }
    
    fclose($output);
    exit;
}

// Handle HTML Report Generation
if (isset($_GET['print_report']) && isset($_GET['view_report'])) {
    $reportId = intval($_GET['view_report']);
    $reportStmt = $db->prepare("
        SELECT par.*, p.program_name, p.program_type, a.assembly_name, u.full_name as created_by_name
        FROM program_activity_reports par
        JOIN programs p ON par.program_id = p.id
        LEFT JOIN assemblies a ON p.assembly_id = a.id
        LEFT JOIN users u ON par.created_by = u.id
        WHERE par.id = :id
    ");
    $reportStmt->execute(['id' => $reportId]);
    $report = $reportStmt->fetch();
    
    if ($report):
    ?>
    <!DOCTYPE html>
    <html>
    <head>
        <title>Program Activity Report - <?php echo htmlspecialchars($report['program_name']); ?></title>
        <style>
            body { font-family: Arial, sans-serif; margin: 20px; max-width: 800px; margin: 0 auto; padding: 20px; }
            .header { text-align: center; margin-bottom: 30px; border-bottom: 2px solid #1E40AF; padding-bottom: 20px; }
            .header h1 { color: #1E40AF; margin-bottom: 5px; }
            .header h2 { color: #666; font-weight: normal; margin: 5px 0; }
            .section { margin: 20px 0; padding: 15px; background: #f9fafb; border-radius: 8px; }
            .section h3 { color: #1E40AF; margin-top: 0; border-bottom: 1px solid #ddd; padding-bottom: 10px; }
            .grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; }
            .grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; }
            .stat-box { text-align: center; padding: 15px; background: white; border-radius: 8px; border: 1px solid #e5e7eb; }
            .stat-box h4 { margin: 0; font-size: 28px; color: #1E40AF; }
            .stat-box p { margin: 5px 0 0; color: #666; font-size: 14px; }
            .field { margin-bottom: 10px; }
            .field label { font-weight: bold; color: #374151; }
            .field p { margin: 5px 0 0; color: #1f2937; }
            .footer { margin-top: 30px; text-align: center; color: #666; font-size: 12px; border-top: 1px solid #ddd; padding-top: 20px; }
            @media print { .no-print { display: none; } body { margin: 0; padding: 10px; } }
        </style>
    </head>
    <body>
        <div class="header">
            <h1><?php echo htmlspecialchars($settings['site_title']); ?></h1>
            <h2>Program Activity Report</h2>
            <p><strong><?php echo htmlspecialchars($report['program_name']); ?></strong></p>
            <p><?php echo date('l, F j, Y', strtotime($report['activity_date'])); ?></p>
            <?php if ($report['assembly_name']): ?>
            <p><?php echo htmlspecialchars($report['assembly_name']); ?></p>
            <?php endif; ?>
        </div>
        
        <?php if ($report['program_title'] || $report['facilitator_name']): ?>
        <div class="section">
            <h3>Program Details</h3>
            <div class="grid">
                <?php if ($report['program_title']): ?>
                <div class="field">
                    <label>Program Title:</label>
                    <p><?php echo htmlspecialchars($report['program_title']); ?></p>
                </div>
                <?php endif; ?>
                <?php if ($report['facilitator_name']): ?>
                <div class="field">
                    <label>Facilitator:</label>
                    <p><?php echo htmlspecialchars($report['facilitator_name']); ?></p>
                </div>
                <?php endif; ?>
            </div>
        </div>
        <?php endif; ?>
        
        <div class="section">
            <h3>Attendance Summary</h3>
            <div class="grid-3">
                <div class="stat-box">
                    <h4><?php echo $report['male_attendance']; ?></h4>
                    <p>Male</p>
                </div>
                <div class="stat-box">
                    <h4><?php echo $report['female_attendance']; ?></h4>
                    <p>Female</p>
                </div>
                <div class="stat-box">
                    <h4><?php echo $report['children_attendance']; ?></h4>
                    <p>Children</p>
                </div>
            </div>
            <div style="text-align: center; margin-top: 15px;">
                <div class="stat-box" style="display: inline-block; min-width: 150px;">
                    <h4 style="color: #059669;"><?php echo $report['total_attendance']; ?></h4>
                    <p>Total Attendance</p>
                </div>
            </div>
        </div>
        
        <div class="section">
            <h3>Spiritual Highlights</h3>
            <div class="grid">
                <div class="stat-box">
                    <h4 style="color: #F97316;"><?php echo $report['souls_won']; ?></h4>
                    <p>Souls Won</p>
                </div>
                <div class="stat-box">
                    <h4 style="color: #9333EA;"><?php echo $report['holy_spirit_baptism']; ?></h4>
                    <p>Holy Spirit Baptism</p>
                </div>
            </div>
            <?php if ($report['bible_quotes']): ?>
            <div class="field" style="margin-top: 15px;">
                <label>Bible Quotes/References:</label>
                <p><?php echo nl2br(htmlspecialchars($report['bible_quotes'])); ?></p>
            </div>
            <?php endif; ?>
        </div>
        
        <?php if ($report['finance_collected'] > 0): ?>
        <div class="section">
            <h3>Finance</h3>
            <div class="stat-box" style="display: inline-block;">
                <h4 style="color: #059669;">GH₵ <?php echo number_format($report['finance_collected'], 2); ?></h4>
                <p>Total Collection</p>
            </div>
        </div>
        <?php endif; ?>
        
        <?php if ($report['special_event'] || $report['executives_attended'] || $report['other_activities']): ?>
        <div class="section">
            <h3>Additional Information</h3>
            <?php if ($report['special_event']): ?>
            <div class="field">
                <label>Special Event:</label>
                <p><?php echo nl2br(htmlspecialchars($report['special_event'])); ?></p>
            </div>
            <?php endif; ?>
            <?php if ($report['executives_attended']): ?>
            <div class="field">
                <label>Executives Who Attended:</label>
                <p><?php echo nl2br(htmlspecialchars($report['executives_attended'])); ?></p>
            </div>
            <?php endif; ?>
            <?php if ($report['other_activities']): ?>
            <div class="field">
                <label>Other Activities:</label>
                <p><?php echo nl2br(htmlspecialchars($report['other_activities'])); ?></p>
            </div>
            <?php endif; ?>
        </div>
        <?php endif; ?>
        
        <?php if ($report['notes']): ?>
        <div class="section">
            <h3>Notes</h3>
            <p><?php echo nl2br(htmlspecialchars($report['notes'])); ?></p>
        </div>
        <?php endif; ?>
        
        <div class="footer">
            <p>Report created by: <?php echo htmlspecialchars($report['created_by_name'] ?? 'System'); ?></p>
            <p>Generated on <?php echo date('F j, Y \a\t g:i A'); ?></p>
            <p><?php echo htmlspecialchars($settings['site_title']); ?></p>
        </div>
        
        <div class="no-print" style="text-align: center; margin-top: 20px;">
            <button onclick="window.print()" style="padding: 10px 20px; background: #1E40AF; color: white; border: none; border-radius: 5px; cursor: pointer;">
                Print Report
            </button>
            <button onclick="window.close()" style="padding: 10px 20px; background: #666; color: white; border: none; border-radius: 5px; cursor: pointer; margin-left: 10px;">
                Close
            </button>
        </div>
    </body>
    </html>
    <?php
    exit;
    endif;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo $pageTitle; ?></title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        .hero-gradient { background: linear-gradient(135deg, #1E40AF 0%, #9333EA 100%); }
        .btn-gradient { background: linear-gradient(135deg, #1E40AF 0%, #9333EA 100%); }
    </style>
</head>
<body class="bg-gray-50 min-h-screen">
    <!-- Header -->
    <header class="bg-white shadow-lg sticky top-0 z-50">
        <div class="container mx-auto px-4">
            <div class="flex items-center justify-between h-16">
                <div class="flex items-center space-x-3">
                    <div class="w-12 h-12 rounded-xl flex items-center justify-center hero-gradient">
                        <i class="fas fa-church text-white text-xl"></i>
                    </div>
                    <div>
                        <h1 class="text-xl font-bold text-blue-800"><?php echo htmlspecialchars($settings['site_title']); ?></h1>
                        <p class="text-xs text-gray-500">Program Activity Report</p>
                    </div>
                </div>
                
                <nav class="flex items-center space-x-4">
                    <a href="ministry-attendance.php" class="text-gray-700 hover:text-blue-600 font-medium transition">
                        <i class="fas fa-arrow-left mr-1"></i>Back
                    </a>
                    <a href="index.php" class="text-gray-700 hover:text-blue-600 font-medium transition">
                        <i class="fas fa-home mr-1"></i>Home
                    </a>
                </nav>
            </div>
        </div>
    </header>

    <!-- Hero Section -->
    <section class="hero-gradient text-white py-8">
        <div class="container mx-auto px-4 text-center">
            <i class="fas fa-file-alt text-5xl mb-3 opacity-90"></i>
            <h1 class="text-3xl font-bold mb-2">Program Activity Report</h1>
            <p class="text-white/90">Create and manage activity reports for church programs</p>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-4 py-8">
        <div class="max-w-5xl mx-auto">
            
            <?php if ($error): ?>
            <div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 rounded mb-6">
                <p class="font-bold"><i class="fas fa-exclamation-circle mr-2"></i>Error</p>
                <p><?php echo htmlspecialchars($error); ?></p>
            </div>
            <?php endif; ?>
            
            <?php if ($success): ?>
            <div class="bg-green-100 border-l-4 border-green-500 text-green-700 p-4 rounded mb-6">
                <p class="font-bold"><i class="fas fa-check-circle mr-2"></i>Success</p>
                <p><?php echo htmlspecialchars($success); ?></p>
            </div>
            <?php endif; ?>
            
            <?php if ($step === 'view_report' && $reportData): ?>
            <!-- View Report -->
            <div class="bg-white rounded-xl shadow-lg overflow-hidden mb-6">
                <div class="bg-gradient-to-r from-blue-500 to-purple-600 text-white p-6">
                    <div class="flex items-center justify-between">
                        <div>
                            <h2 class="text-2xl font-bold"><?php echo htmlspecialchars($reportData['program_name']); ?></h2>
                            <p class="text-white/80"><?php echo date('l, F j, Y', strtotime($reportData['activity_date'])); ?></p>
                        </div>
                        <a href="?view_report=<?php echo $reportData['id']; ?>&print_report=1" target="_blank"
                           class="px-4 py-2 bg-white/20 hover:bg-white/30 rounded-lg">
                            <i class="fas fa-print mr-2"></i>Print
                        </a>
                    </div>
                </div>
                
                <div class="p-6">
                    <!-- Attendance Stats -->
                    <div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
                        <div class="bg-blue-50 rounded-lg p-4 text-center">
                            <p class="text-2xl font-bold text-blue-600"><?php echo $reportData['male_attendance']; ?></p>
                            <p class="text-sm text-gray-500">Male</p>
                        </div>
                        <div class="bg-pink-50 rounded-lg p-4 text-center">
                            <p class="text-2xl font-bold text-pink-600"><?php echo $reportData['female_attendance']; ?></p>
                            <p class="text-sm text-gray-500">Female</p>
                        </div>
                        <div class="bg-yellow-50 rounded-lg p-4 text-center">
                            <p class="text-2xl font-bold text-yellow-600"><?php echo $reportData['children_attendance']; ?></p>
                            <p class="text-sm text-gray-500">Children</p>
                        </div>
                        <div class="bg-green-50 rounded-lg p-4 text-center">
                            <p class="text-2xl font-bold text-green-600"><?php echo $reportData['total_attendance']; ?></p>
                            <p class="text-sm text-gray-500">Total</p>
                        </div>
                    </div>
                    
                    <!-- Spiritual Stats -->
                    <div class="grid grid-cols-2 md:grid-cols-3 gap-4 mb-6">
                        <div class="bg-orange-50 rounded-lg p-4 text-center">
                            <p class="text-2xl font-bold text-orange-600"><?php echo $reportData['souls_won']; ?></p>
                            <p class="text-sm text-gray-500">Souls Won</p>
                        </div>
                        <div class="bg-purple-50 rounded-lg p-4 text-center">
                            <p class="text-2xl font-bold text-purple-600"><?php echo $reportData['holy_spirit_baptism']; ?></p>
                            <p class="text-sm text-gray-500">Holy Spirit Baptism</p>
                        </div>
                        <div class="bg-emerald-50 rounded-lg p-4 text-center">
                            <p class="text-2xl font-bold text-emerald-600">GH₵ <?php echo number_format($reportData['finance_collected'], 2); ?></p>
                            <p class="text-sm text-gray-500">Finance Collected</p>
                        </div>
                    </div>
                    
                    <!-- Details -->
                    <div class="space-y-4">
                        <?php if ($reportData['program_title']): ?>
                        <div class="bg-gray-50 rounded-lg p-4">
                            <p class="text-sm text-gray-500 mb-1">Program Title</p>
                            <p class="font-medium"><?php echo htmlspecialchars($reportData['program_title']); ?></p>
                        </div>
                        <?php endif; ?>
                        
                        <?php if ($reportData['facilitator_name']): ?>
                        <div class="bg-gray-50 rounded-lg p-4">
                            <p class="text-sm text-gray-500 mb-1">Facilitator</p>
                            <p class="font-medium"><?php echo htmlspecialchars($reportData['facilitator_name']); ?></p>
                        </div>
                        <?php endif; ?>
                        
                        <?php if ($reportData['bible_quotes']): ?>
                        <div class="bg-gray-50 rounded-lg p-4">
                            <p class="text-sm text-gray-500 mb-1">Bible Quotes</p>
                            <p class="font-medium"><?php echo nl2br(htmlspecialchars($reportData['bible_quotes'])); ?></p>
                        </div>
                        <?php endif; ?>
                        
                        <?php if ($reportData['special_event']): ?>
                        <div class="bg-gray-50 rounded-lg p-4">
                            <p class="text-sm text-gray-500 mb-1">Special Event</p>
                            <p class="font-medium"><?php echo nl2br(htmlspecialchars($reportData['special_event'])); ?></p>
                        </div>
                        <?php endif; ?>
                        
                        <?php if ($reportData['executives_attended']): ?>
                        <div class="bg-gray-50 rounded-lg p-4">
                            <p class="text-sm text-gray-500 mb-1">Executives Who Attended</p>
                            <p class="font-medium"><?php echo nl2br(htmlspecialchars($reportData['executives_attended'])); ?></p>
                        </div>
                        <?php endif; ?>
                        
                        <?php if ($reportData['other_activities']): ?>
                        <div class="bg-gray-50 rounded-lg p-4">
                            <p class="text-sm text-gray-500 mb-1">Other Activities</p>
                            <p class="font-medium"><?php echo nl2br(htmlspecialchars($reportData['other_activities'])); ?></p>
                        </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
            
            <div class="text-center">
                <a href="program-activity-report.php" class="text-gray-500 hover:text-gray-700">
                    <i class="fas fa-arrow-left mr-1"></i>Back to Reports
                </a>
            </div>
            
            <?php else: ?>
            
            <div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
                <!-- Create Report Form -->
                <div class="bg-white rounded-xl shadow-lg p-6">
                    <h3 class="text-lg font-bold text-gray-800 mb-4">
                        <i class="fas fa-plus-circle mr-2 text-blue-500"></i>Create New Report
                    </h3>
                    
                    <form method="POST" class="space-y-4">
                        <div class="grid grid-cols-2 gap-4">
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">Program *</label>
                                <select name="program_id" required class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                                    <option value="">Select Program</option>
                                    <?php foreach ($programs as $program): ?>
                                    <option value="<?php echo $program['id']; ?>"><?php echo htmlspecialchars($program['program_name']); ?></option>
                                    <?php endforeach; ?>
                                </select>
                            </div>
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">Activity Date *</label>
                                <input type="date" name="activity_date" required value="<?php echo date('Y-m-d'); ?>"
                                       class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                            </div>
                        </div>
                        
                        <div class="grid grid-cols-2 gap-4">
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">Program Title</label>
                                <input type="text" name="program_title" placeholder="e.g., Sunday Worship Service"
                                       class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                            </div>
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">Facilitator Name</label>
                                <input type="text" name="facilitator_name" placeholder="e.g., Pastor John"
                                       class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                            </div>
                        </div>
                        
                        <div class="border-t pt-4">
                            <h4 class="font-medium text-gray-700 mb-3">Attendance</h4>
                            <div class="grid grid-cols-3 gap-4">
                                <div>
                                    <label class="block text-sm text-gray-600 mb-1">Male</label>
                                    <input type="number" name="male_attendance" min="0" value="0"
                                           class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                                </div>
                                <div>
                                    <label class="block text-sm text-gray-600 mb-1">Female</label>
                                    <input type="number" name="female_attendance" min="0" value="0"
                                           class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                                </div>
                                <div>
                                    <label class="block text-sm text-gray-600 mb-1">Children</label>
                                    <input type="number" name="children_attendance" min="0" value="0"
                                           class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                                </div>
                            </div>
                        </div>
                        
                        <div class="grid grid-cols-2 gap-4">
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">Finance Collected (GH₵)</label>
                                <input type="number" name="finance_collected" min="0" step="0.01" value="0"
                                       class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                            </div>
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">Souls Won</label>
                                <input type="number" name="souls_won" min="0" value="0"
                                       class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                            </div>
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Holy Spirit Baptism</label>
                            <input type="number" name="holy_spirit_baptism" min="0" value="0"
                                   class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Bible Quotes/References</label>
                            <textarea name="bible_quotes" rows="2" placeholder="e.g., John 3:16, Romans 8:28"
                                      class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"></textarea>
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Special Event</label>
                            <textarea name="special_event" rows="2" placeholder="Any special events or announcements"
                                      class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"></textarea>
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Executives Who Attended</label>
                            <textarea name="executives_attended" rows="2" placeholder="List of executives present"
                                      class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"></textarea>
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Other Activities</label>
                            <textarea name="other_activities" rows="2" placeholder="Any other activities"
                                      class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"></textarea>
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Notes</label>
                            <textarea name="notes" rows="2" placeholder="Additional notes"
                                      class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"></textarea>
                        </div>
                        
                        <button type="submit" name="create_report" class="w-full py-3 btn-gradient text-white rounded-lg font-semibold">
                            <i class="fas fa-save mr-2"></i>Save Report
                        </button>
                    </form>
                </div>
                
                <!-- Recent Reports -->
                <div class="bg-white rounded-xl shadow-lg p-6">
                    <div class="flex items-center justify-between mb-4">
                        <h3 class="text-lg font-bold text-gray-800">
                            <i class="fas fa-history mr-2 text-purple-500"></i>Recent Reports
                        </h3>
                    </div>
                    
                    <!-- Quick Export Filters -->
                    <div class="bg-gray-50 rounded-lg p-4 mb-4">
                        <p class="text-sm font-medium text-gray-700 mb-2">Export Reports:</p>
                        <div class="flex flex-wrap gap-2">
                            <a href="?export=csv&date_from=<?php echo date('Y-m-d'); ?>&date_to=<?php echo date('Y-m-d'); ?>" 
                               class="px-3 py-1 text-xs bg-green-100 text-green-700 rounded-full hover:bg-green-200">
                                <i class="fas fa-download mr-1"></i>Today
                            </a>
                            <a href="?export=csv&date_from=<?php echo date('Y-m-d', strtotime('monday this week')); ?>&date_to=<?php echo date('Y-m-d'); ?>" 
                               class="px-3 py-1 text-xs bg-green-100 text-green-700 rounded-full hover:bg-green-200">
                                <i class="fas fa-download mr-1"></i>This Week
                            </a>
                            <a href="?export=csv&date_from=<?php echo date('Y-m-01'); ?>&date_to=<?php echo date('Y-m-d'); ?>" 
                               class="px-3 py-1 text-xs bg-green-100 text-green-700 rounded-full hover:bg-green-200">
                                <i class="fas fa-download mr-1"></i>This Month
                            </a>
                            <a href="?export=csv&date_from=<?php echo date('Y-' . (date('n') <= 6 ? '01' : '07') . '-01'); ?>&date_to=<?php echo date('Y-m-d'); ?>" 
                               class="px-3 py-1 text-xs bg-green-100 text-green-700 rounded-full hover:bg-green-200">
                                <i class="fas fa-download mr-1"></i>Half Year
                            </a>
                            <a href="?export=csv&date_from=<?php echo date('Y-01-01'); ?>&date_to=<?php echo date('Y-m-d'); ?>" 
                               class="px-3 py-1 text-xs bg-green-100 text-green-700 rounded-full hover:bg-green-200">
                                <i class="fas fa-download mr-1"></i>Full Year
                            </a>
                        </div>
                    </div>
                    
                    <?php if (count($existingReports) > 0): ?>
                    <div class="space-y-3 max-h-[600px] overflow-y-auto">
                        <?php foreach ($existingReports as $report): ?>
                        <a href="?view_report=<?php echo $report['id']; ?>" 
                           class="block bg-gray-50 rounded-lg p-4 hover:bg-gray-100 transition">
                            <div class="flex items-center justify-between">
                                <div>
                                    <h4 class="font-medium text-gray-800"><?php echo htmlspecialchars($report['program_name']); ?></h4>
                                    <p class="text-sm text-gray-500"><?php echo date('M j, Y', strtotime($report['activity_date'])); ?></p>
                                </div>
                                <div class="text-right">
                                    <p class="text-lg font-bold text-blue-600"><?php echo $report['total_attendance']; ?></p>
                                    <p class="text-xs text-gray-500">Attendance</p>
                                </div>
                            </div>
                        </a>
                        <?php endforeach; ?>
                    </div>
                    <?php else: ?>
                    <div class="text-center py-8 text-gray-500">
                        <i class="fas fa-folder-open text-4xl mb-3"></i>
                        <p>No reports created yet.</p>
                    </div>
                    <?php endif; ?>
                </div>
            </div>
            
            <?php endif; ?>
            
        </div>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-800 text-white py-6 mt-auto">
        <div class="container mx-auto px-4 text-center">
            <p class="text-gray-400 text-sm">
                © <?php echo date('Y'); ?> <?php echo htmlspecialchars($settings['site_title']); ?>
            </p>
        </div>
    </footer>
</body>
</html>

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