Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/portal/modules/membership/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/portal/modules/membership/add.php

<?php
require_once '../../config/config.php';
checkLogin();

$pageTitle = "Add Member - " . APP_NAME;
$db = Database::getInstance()->getConnection();
$error = '';
$success = '';

// Get areas, districts, assemblies based on access
$accessLevel = $_SESSION['access_level'] ?? 'assembly';
$userAreaId = $_SESSION['area_id'] ?? null;
$userDistrictId = $_SESSION['district_id'] ?? null;
$userAssemblyId = $_SESSION['assembly_id'] ?? null;

// Get areas
$areas = [];
try {
    $areasQuery = "SELECT * FROM areas WHERE is_active = 1";
    if ($accessLevel === 'area') {
        $areasQuery .= " AND id = $userAreaId";
    }
    $areas = $db->query($areasQuery)->fetchAll();
} catch (PDOException $e) {
    $error = "Database not set up properly. Please run the installer at: <a href='" . BASE_URL . "install.php' class='underline'>install.php</a>";
}

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    try {
        $areaId = $_POST['area_id'];
        $districtId = $_POST['district_id'];
        $assemblyId = $_POST['assembly_id'];
        
        // Generate membership card number (we'll create the actual card after member creation)
        $membershipCard = new MembershipCard();
        $membershipCardId = $membershipCard->generateCardNumber();
        
        // Ensure card number is unique and not empty
        if (empty($membershipCardId)) {
            throw new Exception("Failed to generate membership card number");
        }
        
        $attempts = 0;
        $maxAttempts = 10;
        while ($attempts < $maxAttempts) {
            // Check if card number exists in membership_cards table
            $checkStmt = $db->prepare("SELECT id FROM membership_cards WHERE card_number = :card_number");
            $checkStmt->execute(['card_number' => $membershipCardId]);
            $existsInCards = $checkStmt->fetch();
            
            // Also check if membershipcard_id exists in members table
            $checkStmt2 = $db->prepare("SELECT id FROM members WHERE membershipcard_id = :card_number");
            $checkStmt2->execute(['card_number' => $membershipCardId]);
            $existsInMembers = $checkStmt2->fetch();
            
            if (!$existsInCards && !$existsInMembers) {
                // Card number is unique in both tables
                break;
            }
            
            // Generate a new card number
            $membershipCardId = $membershipCard->generateCardNumber();
            $attempts++;
        }
        
        if ($attempts >= $maxAttempts) {
            throw new Exception("Failed to generate unique membership card number after $maxAttempts attempts");
        }
        
        // Check if membershipcard_id column exists (it should always exist)
        $columnExists = false;
        try {
            $checkStmt = $db->query("SHOW COLUMNS FROM members LIKE 'membershipcard_id'");
            $columnExists = $checkStmt->fetch() !== false;
        } catch (PDOException $e) {
            throw new Exception("Database error checking membershipcard_id column: " . $e->getMessage());
        }
        
        if (!$columnExists) {
            throw new Exception("Database schema error: membershipcard_id column does not exist in members table. Please run the database setup.");
        }
        
        // Build INSERT query (membershipcard_id is required)
        $insertColumns = "area_id, district_id, assembly_id, membershipcard_id, family_id, title, first_name, middle_name, last_name,";
        $insertValues = ":area_id, :district_id, :assembly_id, :membershipcard_id, :family_id, :title, :first_name, :middle_name, :last_name,";
        
        $stmt = $db->prepare("
            INSERT INTO members (
                {$insertColumns}
                gender, date_of_birth, place_of_birth, phone, email, member_type, marital_status,
                address_line1, gps_address, hometown, street_name, city, parent_name, parent_relationship,
                holyghost_baptism, date_of_holyspirit_baptism, water_baptism, date_of_baptism,
                date_of_conversion, date_of_joining, place_of_baptism, officiating_minister_baptism,
                officiating_ministers_district, communicant, occupation, level_of_education,
                dedicated, dedication_date, name_of_officiating_minister, church_where_dedication_done,
                created_by
            ) VALUES (
                {$insertValues}
                :gender, :date_of_birth, :place_of_birth, :phone, :email, :member_type, :marital_status,
                :address_line1, :gps_address, :hometown, :street_name, :city, :parent_name, :parent_relationship,
                :holyghost_baptism, :date_of_holyspirit_baptism, :water_baptism, :date_of_baptism,
                :date_of_conversion, :date_of_joining, :place_of_baptism, :officiating_minister_baptism,
                :officiating_ministers_district, :communicant, :occupation, :level_of_education,
                :dedicated, :dedication_date, :name_of_officiating_minister, :church_where_dedication_done,
                :created_by
            )
        ");
        
        // Build execute parameters (membershipcard_id is required)
        $executeParams = [
            'area_id' => $areaId,
            'district_id' => $districtId,
            'assembly_id' => $assemblyId,
            'membershipcard_id' => $membershipCardId,
            'family_id' => $_POST['family_id'] ?: null,
            'title' => $_POST['title'],
            'first_name' => $_POST['first_name'],
            'middle_name' => $_POST['middle_name'] ?: null,
            'last_name' => $_POST['last_name'],
            'gender' => $_POST['gender'],
            'date_of_birth' => $_POST['date_of_birth'] ?: null,
            'place_of_birth' => $_POST['place_of_birth'] ?: null,
            'phone' => $_POST['phone'] ?: null,
            'email' => $_POST['email'] ?: null,
            'member_type' => $_POST['member_type'],
            'marital_status' => $_POST['marital_status'] ?: null,
            'address_line1' => $_POST['address_line1'] ?: null,
            'gps_address' => $_POST['gps_address'] ?: null,
            'hometown' => $_POST['hometown'] ?: null,
            'street_name' => $_POST['street_name'] ?: null,
            'city' => $_POST['city'] ?: null,
            'parent_name' => $_POST['parent_name'] ?: null,
            'parent_relationship' => $_POST['parent_relationship'] ?: null,
            'holyghost_baptism' => isset($_POST['holyghost_baptism']) ? 1 : 0,
            'date_of_holyspirit_baptism' => $_POST['date_of_holyspirit_baptism'] ?: null,
            'water_baptism' => isset($_POST['water_baptism']) ? 1 : 0,
            'date_of_baptism' => $_POST['date_of_baptism'] ?: null,
            'date_of_conversion' => $_POST['date_of_conversion'] ?: null,
            'date_of_joining' => $_POST['date_of_joining'] ?: null,
            'place_of_baptism' => $_POST['place_of_baptism'] ?: null,
            'officiating_minister_baptism' => $_POST['officiating_minister_baptism'] ?: null,
            'officiating_ministers_district' => $_POST['officiating_ministers_district'] ?: null,
            'communicant' => isset($_POST['communicant']) ? 1 : 0,
            'occupation' => $_POST['occupation'] ?: null,
            'level_of_education' => $_POST['level_of_education'] ?: null,
            'dedicated' => isset($_POST['dedicated']) ? 1 : 0,
            'dedication_date' => $_POST['dedication_date'] ?: null,
            'name_of_officiating_minister' => $_POST['name_of_officiating_minister'] ?: null,
            'church_where_dedication_done' => $_POST['church_where_dedication_done'] ?: null,
            'created_by' => $_SESSION['user_id']
        ];
        
        $stmt->execute($executeParams);
        
        $newMemberId = $db->lastInsertId();
        
        // Create the actual membership card now that we have the member ID
        $cardResult = $membershipCard->createCard($newMemberId);
        $cardMessage = '';
        if ($cardResult['success']) {
            $actualCardNumber = $cardResult['card_number'];
            $cardMessage = "Membership Card ID: <strong>$actualCardNumber</strong> generated!";
        } else {
            $cardMessage = "<span class='text-yellow-600'>Warning: Membership card creation failed - " . $cardResult['message'] . "</span>";
        }
        
        // Auto-generate member tracking code
        $codeMessage = '';
        try {
            // Function to generate unique tracking code
            function generateTrackingCode($type = 'member') {
                $prefix = $type === 'member' ? 'MEM' : 'USR';
                return $prefix . date('Y') . str_pad(mt_rand(1, 999999), 6, '0', STR_PAD_LEFT);
            }
            
            // Function to generate barcode (Code 128)
            function generateBarcode($code) {
                // Create PNG image using GD
                $width = 200;
                $height = 50;
                $image = imagecreate($width, $height);
                
                // Colors
                $white = imagecolorallocate($image, 255, 255, 255);
                $black = imagecolorallocate($image, 0, 0, 0);
                
                // Fill background
                imagefill($image, 0, 0, $white);
                
                // Generate barcode pattern based on code
                $codeLength = strlen($code);
                $barWidth = 2;
                $x = 10;
                
                for ($i = 0; $i < $codeLength; $i++) {
                    $char = ord($code[$i]);
                    $pattern = $char % 4; // Simple pattern based on character
                    
                    for ($j = 0; $j < 3; $j++) {
                        $width = ($pattern & (1 << $j)) ? 3 : 1;
                        imagefilledrectangle($image, $x, 5, $x + $width, 35, $black);
                        $x += $width + 1;
                    }
                }
                
                // Add text
                imagestring($image, 2, 10, 37, substr($code, 0, 20), $black);
                
                // Convert to base64
                ob_start();
                imagepng($image);
                $imageData = ob_get_contents();
                ob_end_clean();
                imagedestroy($image);
                
                return "data:image/png;base64," . base64_encode($imageData);
            }
            
            // Function to generate QR code (placeholder)
            function generateQRCode($code) {
                // Create PNG image using GD
                $size = 100;
                $image = imagecreate($size, $size);
                
                // Colors
                $white = imagecolorallocate($image, 255, 255, 255);
                $black = imagecolorallocate($image, 0, 0, 0);
                
                // Fill background
                imagefill($image, 0, 0, $white);
                
                // Generate QR-like pattern based on code
                $codeHash = md5($code);
                $blockSize = 5;
                
                // Corner markers
                imagefilledrectangle($image, 5, 5, 30, 30, $black);
                imagefilledrectangle($image, 70, 5, 95, 30, $black);
                imagefilledrectangle($image, 5, 70, 30, 95, $black);
                
                // Inner corner markers (white)
                imagefilledrectangle($image, 10, 10, 25, 25, $white);
                imagefilledrectangle($image, 75, 10, 90, 25, $white);
                imagefilledrectangle($image, 10, 75, 25, 90, $white);
                
                // Center dots
                imagefilledrectangle($image, 15, 15, 20, 20, $black);
                imagefilledrectangle($image, 80, 15, 85, 20, $black);
                imagefilledrectangle($image, 15, 80, 20, 85, $black);
                
                // Data pattern based on hash
                for ($i = 0; $i < 32; $i++) {
                    $hexChar = hexdec($codeHash[$i]);
                    for ($bit = 0; $bit < 4; $bit++) {
                        if ($hexChar & (1 << $bit)) {
                            $x = 35 + (($i * 2 + $bit) % 6) * $blockSize;
                            $y = 35 + floor(($i * 2 + $bit) / 6) * $blockSize;
                            if ($x < 95 && $y < 95) {
                                imagefilledrectangle($image, $x, $y, $x + $blockSize - 1, $y + $blockSize - 1, $black);
                            }
                        }
                    }
                }
                
                // Convert to base64
                ob_start();
                imagepng($image);
                $imageData = ob_get_contents();
                ob_end_clean();
                imagedestroy($image);
                
                return "data:image/png;base64," . base64_encode($imageData);
            }
            
            // Generate unique tracking code
            do {
                $trackingCode = generateTrackingCode('member');
                $checkStmt = $db->prepare("SELECT id FROM memberuser_codes WHERE tracking_code = :code");
                $checkStmt->execute(['code' => $trackingCode]);
            } while ($checkStmt->fetch());
            
            $code = 'MC' . date('Ymd') . str_pad($newMemberId, 4, '0', STR_PAD_LEFT) . mt_rand(100, 999);
            $barcode = generateBarcode($trackingCode);
            $qrcode = generateQRCode($trackingCode);
            
            // Get default attendance event
            $eventStmt = $db->prepare("SELECT id FROM events WHERE name = 'Attendance' AND is_active = 1 LIMIT 1");
            $eventStmt->execute();
            $defaultEvent = $eventStmt->fetch();
            $eventId = $defaultEvent ? $defaultEvent['id'] : null;
            
            // Insert auto-generated member code
            $codeStmt = $db->prepare("
                INSERT INTO memberuser_codes (
                    code, description, member_id, event_id, code_type, tracking_code,
                    barcode, qrcode, created_by, is_active
                ) VALUES (
                    :code, :description, :member_id, :event_id, 'member', :tracking_code,
                    :barcode, :qrcode, :created_by, 1
                )
            ");
            
            $codeStmt->execute([
                'code' => $code,
                'description' => 'Auto-generated member tracking code',
                'member_id' => $newMemberId,
                'event_id' => $eventId,
                'tracking_code' => $trackingCode,
                'barcode' => $barcode,
                'qrcode' => $qrcode,
                'created_by' => $_SESSION['user_id']
            ]);
            
            $codeMessage = "<br>Tracking Code: <strong>$trackingCode</strong> generated!";
            
        } catch (Exception $e) {
            $codeMessage = "<br><span class='text-yellow-600'>Warning: Auto-code generation failed - " . $e->getMessage() . "</span>";
        }
        
        // Create member account if email is provided
        $accountMessage = '';
        if (!empty($_POST['email'])) {
            try {
                require_once '../../classes/MemberAuth.php';
                $memberAuth = new MemberAuth();
                $accountResult = $memberAuth->createMemberAccount([
                    'member_id' => $newMemberId,
                    'first_name' => $_POST['first_name'],
                    'last_name' => $_POST['last_name'],
                    'email' => $_POST['email'],
                    'phone' => $_POST['phone'] ?? null,
                    'area_id' => $areaId,
                    'district_id' => $districtId,
                    'assembly_id' => $assemblyId
                ]);
                
                if ($accountResult['success']) {
                    $accountMessage = "<br>Member Account Created!<br>Username: <strong>{$accountResult['username']}</strong><br>Password: <strong>{$accountResult['password']}</strong>";
                }
            } catch (Exception $e) {
                error_log("Member account creation error: " . $e->getMessage());
            }
            
            // Send welcome email if enabled and email provided
            try {
                require_once '../../classes/EmailService.php';
                $emailService = new EmailService();
                $emailService->sendWelcomeMemberEmail([
                    'first_name' => $_POST['first_name'],
                    'last_name' => $_POST['last_name'],
                    'email' => $_POST['email'],
                    'membershipcard_id' => $actualCardNumber ?? $membershipCardId,
                    'phone' => $_POST['phone'] ?? ''
                ]);
            } catch (Exception $e) {
                error_log("Welcome member email error: " . $e->getMessage());
            }
        }
        
        // Build success message after all operations
        $success = "Member added successfully!<br>$cardMessage$codeMessage$accountMessage";
        
        // Log the action
        $auditLog = new AuditLog();
        $auditLog->log($_SESSION['user_id'], 'create', 'members', $newMemberId);
        
    } catch (PDOException $e) {
        $error = "Error adding member: " . $e->getMessage();
    }
}

include '../../includes/header.php';
?>

<?php include '../../includes/sidebar.php'; ?>

<!-- Main Content -->
<main class="flex-1 md:ml-64 mt-16">
<div class="container mx-auto px-4 py-8">
    <div class="max-w-5xl mx-auto">
        <!-- Page Header -->
        <div class="mb-6">
            <h1 class="text-3xl font-bold text-gray-800">
                <i class="fas fa-user-plus mr-2 text-blue-500"></i>Add New Member
            </h1>
            <p class="text-gray-600 mt-2">Fill in the details to register a new church member</p>
        </div>
        
        <!-- Messages -->
        <?php if ($success): ?>
            <div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded-lg mb-6">
                <i class="fas fa-check-circle mr-2"></i><?php echo $success; ?>
                <a href="index.php" class="float-right text-green-800 hover:text-green-900">View Members →</a>
            </div>
        <?php endif; ?>
        
        <?php if ($error): ?>
            <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded-lg mb-6">
                <i class="fas fa-exclamation-circle mr-2"></i><?php echo $error; ?>
            </div>
        <?php endif; ?>
        
        <!-- Form -->
        <form method="POST" class="bg-white rounded-xl shadow-lg">
            <!-- Personal Information -->
            <div class="p-6 border-b border-gray-200">
                <h3 class="text-xl font-bold text-gray-800 mb-4">
                    <i class="fas fa-user mr-2 text-blue-500"></i>Personal Information
                </h3>
                
                <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Title</label>
                        <select name="title" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                            <option value="">Select</option>
                            <option value="Mr">Mr</option>
                            <option value="Mrs">Mrs</option>
                            <option value="Miss">Miss</option>
                            <option value="Dr">Dr</option>
                            <option value="Rev">Rev</option>
                            <option value="Pastor">Pastor</option>
                            <option value="Deacon">Deacon</option>
                            <option value="Deaconess">Deaconess</option>
                            <option value="Elder">Elder</option>
                            <option value="Evangelist">Evangelist</option>
                            <option value="Prophet">Prophet</option>
                            <option value="Apostle">Apostle</option>
                        </select>
                    </div>
                    
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">First Name *</label>
                        <input type="text" name="first_name" required 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">Middle Name</label>
                        <input type="text" name="middle_name" 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">Last Name *</label>
                        <input type="text" name="last_name" required 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">Gender *</label>
                        <select name="gender" required class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                            <option value="">Select</option>
                            <option value="Male">Male</option>
                            <option value="Female">Female</option>
                        </select>
                    </div>
                    
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Date of Birth</label>
                        <input type="date" name="date_of_birth" 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">Place of Birth</label>
                        <input type="text" name="place_of_birth" 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">Marital Status</label>
                        <select name="marital_status" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                            <option value="">Select</option>
                            <option value="Single">Single</option>
                            <option value="Married">Married</option>
                            <option value="Divorced">Divorced</option>
                            <option value="Widowed">Widowed</option>
                        </select>
                    </div>
                    
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Member Type</label>
                        <select name="member_type" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                            <option value="Full Member">Full Member</option>
                            <option value="Associate Member">Associate Member</option>
                            <option value="Youth">Youth</option>
                            <option value="Children">Children</option>
                        </select>
                    </div>
                </div>
            </div>
            
            <!-- Contact Information -->
            <div class="p-6 border-b border-gray-200">
                <h3 class="text-xl font-bold text-gray-800 mb-4">
                    <i class="fas fa-address-book mr-2 text-blue-500"></i>Contact Information
                </h3>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Phone</label>
                        <input type="tel" name="phone" 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">Email</label>
                        <input type="email" name="email" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                    </div>
                    
                    <div class="md:col-span-2">
                        <label class="block text-sm font-medium text-gray-700 mb-2">Address Line 1</label>
                        <textarea name="address_line1" rows="2" 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">GPS Address</label>
                        <input type="text" name="gps_address" 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">Street Name</label>
                        <input type="text" name="street_name" 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">City</label>
                        <input type="text" name="city" 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">Hometown</label>
                        <input type="text" name="hometown" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                    </div>
                </div>
            </div>
            
            <!-- Church Location -->
            <div class="p-6 border-b border-gray-200">
                <h3 class="text-xl font-bold text-gray-800 mb-4">
                    <i class="fas fa-church mr-2 text-blue-500"></i>Church Location
                </h3>
                
                <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Area *</label>
                        <select name="area_id" id="areaSelect" required class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500" onchange="loadDistricts(this.value)">
                            <option value="">Select Area</option>
                            <?php foreach ($areas as $area): ?>
                                <option value="<?php echo $area['id']; ?>"><?php echo htmlspecialchars($area['area_name']); ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">District *</label>
                        <select name="district_id" id="districtSelect" required class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500" onchange="loadAssemblies(this.value)">
                            <option value="">Select District</option>
                        </select>
                    </div>
                    
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Assembly *</label>
                        <select name="assembly_id" id="assemblySelect" required class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                            <option value="">Select Assembly</option>
                        </select>
                    </div>
                    
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Family ID (Optional)</label>
                        <input type="text" name="family_id" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500" placeholder="Link to family">
                    </div>
                </div>
            </div>
            
            <!-- Spiritual Information -->
            <div class="p-6 border-b border-gray-200">
                <h3 class="text-xl font-bold text-gray-800 mb-4">
                    <i class="fas fa-cross mr-2 text-blue-500"></i>Spiritual Information
                </h3>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <div class="flex items-center space-x-6">
                        <label class="flex items-center">
                            <input type="checkbox" name="water_baptism" class="mr-2 rounded">
                            <span class="text-sm font-medium text-gray-700">Water Baptism</span>
                        </label>
                        
                        <label class="flex items-center">
                            <input type="checkbox" name="holyghost_baptism" class="mr-2 rounded">
                            <span class="text-sm font-medium text-gray-700">Holy Ghost Baptism</span>
                        </label>
                    </div>
                    
                    <div class="flex items-center space-x-6">
                        <label class="flex items-center">
                            <input type="checkbox" name="communicant" class="mr-2 rounded">
                            <span class="text-sm font-medium text-gray-700">Communicant</span>
                        </label>
                        
                        <label class="flex items-center">
                            <input type="checkbox" name="dedicated" class="mr-2 rounded">
                            <span class="text-sm font-medium text-gray-700">Dedicated</span>
                        </label>
                    </div>
                    
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Date of Baptism</label>
                        <input type="date" name="date_of_baptism" 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">Date of Holy Spirit Baptism</label>
                        <input type="date" name="date_of_holyspirit_baptism" 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">Date of Conversion</label>
                        <input type="date" name="date_of_conversion" 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">Date of Joining</label>
                        <input type="date" name="date_of_joining" 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">Dedication Date</label>
                        <input type="date" name="dedication_date" 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">Place of Baptism</label>
                        <input type="text" name="place_of_baptism" 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">Officiating Minister (Baptism)</label>
                        <input type="text" name="officiating_minister_baptism" 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">Minister's District/Church</label>
                        <input type="text" name="officiating_ministers_district" 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">Officiating Minister (Dedication)</label>
                        <input type="text" name="name_of_officiating_minister" 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">Church Where Dedication Done</label>
                        <input type="text" name="church_where_dedication_done" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                    </div>
                </div>
            </div>
            
            <!-- Other Information -->
            <div class="p-6 border-b border-gray-200">
                <h3 class="text-xl font-bold text-gray-800 mb-4">
                    <i class="fas fa-info-circle mr-2 text-blue-500"></i>Other Information
                </h3>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Occupation</label>
                        <input type="text" name="occupation" 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">Level of Education</label>
                        <select name="level_of_education" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                            <option value="">Select</option>
                            <option value="Primary">Primary</option>
                            <option value="JHS">JHS</option>
                            <option value="SHS">SHS</option>
                            <option value="Tertiary">Tertiary</option>
                            <option value="Postgraduate">Postgraduate</option>
                        </select>
                    </div>
                    
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Parent Name</label>
                        <input type="text" name="parent_name" 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">Parent Relationship</label>
                        <input type="text" name="parent_relationship" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500" placeholder="e.g., Father, Mother, Guardian">
                    </div>
                </div>
            </div>
            
            <!-- Action Buttons -->
            <div class="p-6 bg-gray-50 flex justify-end space-x-4">
                <a href="index.php" class="px-6 py-2 border border-gray-300 rounded-lg hover:bg-gray-100 transition">
                    <i class="fas fa-times mr-2"></i>Cancel
                </a>
                <button type="submit" class="bg-gradient-to-r from-blue-500 to-blue-600 text-white px-6 py-2 rounded-lg hover:from-blue-600 hover:to-blue-700 transition">
                    <i class="fas fa-save mr-2"></i>Save Member
                </button>
            </div>
        </form>
    </div>
</div>

<script>
    function loadDistricts(areaId) {
        if (!areaId) {
            document.getElementById('districtSelect').innerHTML = '<option value="">Select District</option>';
            document.getElementById('assemblySelect').innerHTML = '<option value="">Select Assembly</option>';
            return;
        }
        
        fetch('<?php echo BASE_URL; ?>api/get-districts.php?area_id=' + areaId)
            .then(response => response.json())
            .then(data => {
                let html = '<option value="">Select District</option>';
                data.forEach(district => {
                    html += `<option value="${district.id}">${district.district_name}</option>`;
                });
                document.getElementById('districtSelect').innerHTML = html;
                document.getElementById('assemblySelect').innerHTML = '<option value="">Select Assembly</option>';
            });
    }
    
    function loadAssemblies(districtId) {
        if (!districtId) {
            document.getElementById('assemblySelect').innerHTML = '<option value="">Select Assembly</option>';
            return;
        }
        
        fetch('<?php echo BASE_URL; ?>api/get-assemblies.php?district_id=' + districtId)
            .then(response => response.json())
            .then(data => {
                let html = '<option value="">Select Assembly</option>';
                data.forEach(assembly => {
                    html += `<option value="${assembly.id}">${assembly.assembly_name}</option>`;
                });
                document.getElementById('assemblySelect').innerHTML = html;
            });
    }
</script>
</main>

<?php include '../../includes/footer.php'; ?>

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