Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/portal/modules/membership-issues/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/portal/modules/membership-issues/index.php

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

// Check if user is logged in
if (!isLoggedIn()) {
    redirect('login.php');
}

// Check module access based on module_access_levels table
if (!canAccessModule('Membership Issues')) {
    $_SESSION['error'] = 'You do not have permission to access this module.';
    redirect('dashboard.php');
}

$db = Database::getInstance()->getConnection();

// Handle actions
$successMessage = '';
$errorMessage = '';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    try {
        $action = $_POST['action'] ?? '';
        $issueId = intval($_POST['issue_id'] ?? 0);
        
        if ($action == 'update_status') {
            $status = $_POST['status'];
            $adminNotes = $_POST['admin_notes'] ?? '';
            
            $stmt = $db->prepare("
                UPDATE membership_issues 
                SET status = :status,
                    admin_notes = :admin_notes,
                    updated_at = NOW()
                WHERE id = :id
            ");
            $stmt->execute([
                'status' => $status,
                'admin_notes' => $adminNotes,
                'id' => $issueId
            ]);
            
            $successMessage = "Issue status updated successfully!";
            
        } elseif ($action == 'assign') {
            $assignedTo = intval($_POST['assigned_to']);
            
            $stmt = $db->prepare("
                UPDATE membership_issues 
                SET assigned_to = :assigned_to,
                    status = 'in_progress',
                    updated_at = NOW()
                WHERE id = :id
            ");
            $stmt->execute([
                'assigned_to' => $assignedTo,
                'id' => $issueId
            ]);
            
            $successMessage = "Issue assigned successfully!";
            
        } elseif ($action == 'resolve') {
            $stmt = $db->prepare("UPDATE membership_issues SET status = 'resolved', resolved_by = :resolved_by, resolved_at = NOW(), updated_at = NOW() WHERE id = :id");
            $stmt->execute([
                'resolved_by' => $currentUserId,
                'id' => $issueId
            ]);
            
            $successMessage = "Issue marked as resolved!";
            
        } elseif ($action == 'approve_membership') {
            // Get the membership form data
            $stmt = $db->prepare("SELECT membership_form_data FROM membership_issues WHERE id = :id");
            $stmt->execute(['id' => $issueId]);
            $issue = $stmt->fetch(PDO::FETCH_ASSOC);
            
            if ($issue && $issue['membership_form_data']) {
                $formData = json_decode($issue['membership_form_data'], true);
                
                // Generate membership card number
                require_once '../../classes/MembershipCard.php';
                $membershipCard = new MembershipCard();
                $membershipCardId = $membershipCard->generateCardNumber();
                
                // Insert as new member with comprehensive fields
                $insertStmt = $db->prepare("
                    INSERT INTO members (
                        area_id, district_id, assembly_id, membershipcard_id, family_id,
                        title, first_name, middle_name, last_name, gender, 
                        date_of_birth, place_of_birth, phone, email, member_type, 
                        marital_status, address_line1, gps_address, hometown, street_name, city,
                        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, parent_name, parent_relationship,
                        is_active, created_at, created_by
                    ) VALUES (
                        :area_id, :district_id, :assembly_id, :membershipcard_id, :family_id,
                        :title, :first_name, :middle_name, :last_name, :gender,
                        :date_of_birth, :place_of_birth, :phone, :email, :member_type,
                        :marital_status, :address_line1, :gps_address, :hometown, :street_name, :city,
                        :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, :parent_name, :parent_relationship,
                        1, NOW(), :created_by
                    )
                ");
                
                $insertStmt->execute([
                    'area_id' => $formData['area_id'] ?: null,
                    'district_id' => $formData['district_id'] ?: null,
                    'assembly_id' => $formData['assembly_id'] ?: null,
                    'membershipcard_id' => $membershipCardId,
                    'family_id' => $formData['family_id'] ?: null,
                    'title' => $formData['title'] ?? '',
                    'first_name' => $formData['first_name'] ?? '',
                    'middle_name' => $formData['middle_name'] ?? '',
                    'last_name' => $formData['last_name'] ?? '',
                    'gender' => $formData['gender'] ?? '',
                    'date_of_birth' => $formData['date_of_birth'] ?: null,
                    'place_of_birth' => $formData['place_of_birth'] ?: null,
                    'phone' => $formData['phone'] ?: null,
                    'email' => $formData['email'] ?: null,
                    'member_type' => $formData['member_type'] ?? 'Full Member',
                    'marital_status' => $formData['marital_status'] ?: null,
                    'address_line1' => $formData['address_line1'] ?: null,
                    'gps_address' => $formData['gps_address'] ?: null,
                    'hometown' => $formData['hometown'] ?: null,
                    'street_name' => $formData['street_name'] ?: null,
                    'city' => $formData['city'] ?: null,
                    'holyghost_baptism' => $formData['holyghost_baptism'] ?? 0,
                    'date_of_holyspirit_baptism' => $formData['date_of_holyspirit_baptism'] ?: null,
                    'water_baptism' => $formData['water_baptism'] ?? 0,
                    'date_of_baptism' => $formData['date_of_baptism'] ?: null,
                    'date_of_conversion' => $formData['date_of_conversion'] ?: null,
                    'date_of_joining' => $formData['date_of_joining'] ?: null,
                    'place_of_baptism' => $formData['place_of_baptism'] ?: null,
                    'officiating_minister_baptism' => $formData['officiating_minister_baptism'] ?: null,
                    'officiating_ministers_district' => $formData['officiating_ministers_district'] ?: null,
                    'communicant' => $formData['communicant'] ?? 0,
                    'occupation' => $formData['occupation'] ?: null,
                    'level_of_education' => $formData['level_of_education'] ?: null,
                    'dedicated' => $formData['dedicated'] ?? 0,
                    'dedication_date' => $formData['dedication_date'] ?: null,
                    'name_of_officiating_minister' => $formData['name_of_officiating_minister'] ?: null,
                    'church_where_dedication_done' => $formData['church_where_dedication_done'] ?: null,
                    'parent_name' => $formData['parent_name'] ?: null,
                    'parent_relationship' => $formData['parent_relationship'] ?: null,
                    'created_by' => $currentUserId
                ]);
                
                $newMemberId = $db->lastInsertId();
                
                // Create the actual membership card
                $cardResult = $membershipCard->createCard($newMemberId);
                $cardMessage = '';
                if ($cardResult['success']) {
                    $actualCardNumber = $cardResult['card_number'];
                    $cardMessage = " Membership Card: {$actualCardNumber}";
                }
                
                // Mark issue as resolved
                $updateStmt = $db->prepare("
                    UPDATE membership_issues 
                    SET status = 'resolved',
                        resolved_by = :resolved_by,
                        resolved_at = NOW(),
                        admin_notes = CONCAT(COALESCE(admin_notes, ''), '\n[APPROVED] Membership form approved and member created.'),
                        updated_at = NOW()
                    WHERE id = :id
                ");
                $updateStmt->execute([
                    'resolved_by' => $currentUserId,
                    'id' => $issueId
                ]);
                
                $successMessage = "Membership form approved! New member created with ID: {$newMemberId}.{$cardMessage}";
            }
        }
        
    } catch (Exception $e) {
        $errorMessage = "Error: " . $e->getMessage();
    }
}

// Get filter parameters
$filterStatus = $_GET['status'] ?? 'all';
$filterType = $_GET['type'] ?? 'all';

// Build query
$whereConditions = [];
$params = [];

if ($filterStatus != 'all') {
    $whereConditions[] = "mi.status = :status";
    $params['status'] = $filterStatus;
}

if ($filterType != 'all') {
    $whereConditions[] = "mi.issue_type = :type";
    $params['type'] = $filterType;
}

$whereClause = !empty($whereConditions) ? 'WHERE ' . implode(' AND ', $whereConditions) : '';

// Get issues
$sql = "SELECT mi.*,
               m.first_name as member_first_name,
               m.last_name as member_last_name,
               m.membershipcard_id,
               u.full_name as assigned_to_name,
               r.full_name as resolved_by_name
        FROM membership_issues mi
        LEFT JOIN members m ON mi.member_id = m.id
        LEFT JOIN users u ON mi.assigned_to = u.id
        LEFT JOIN users r ON mi.resolved_by = r.id
        {$whereClause}
        ORDER BY 
            CASE mi.status
                WHEN 'pending' THEN 1
                WHEN 'in_progress' THEN 2
                WHEN 'resolved' THEN 3
                WHEN 'rejected' THEN 4
            END,
            mi.created_at DESC";

$stmt = $db->prepare($sql);
$stmt->execute($params);
$issues = $stmt->fetchAll(PDO::FETCH_ASSOC);

// Get users for assignment dropdown
$usersStmt = $db->query("SELECT id, full_name FROM users WHERE is_active = 1 ORDER BY full_name");
$users = $usersStmt->fetchAll(PDO::FETCH_ASSOC);

// Get statistics
$statsStmt = $db->query("
    SELECT 
        COUNT(*) as total,
        SUM(CASE WHEN status = 'pending' THEN 1 ELSE 0 END) as pending,
        SUM(CASE WHEN status = 'in_progress' THEN 1 ELSE 0 END) as in_progress,
        SUM(CASE WHEN status = 'resolved' THEN 1 ELSE 0 END) as resolved,
        SUM(CASE WHEN status = 'rejected' THEN 1 ELSE 0 END) as rejected
    FROM membership_issues
");
$stats = $statsStmt->fetch(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Membership Issues - <?php echo APP_NAME; ?></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">
</head>
<body class="bg-gray-100">
    <?php include '../../includes/header.php'; ?>
    
    <div class="flex">
        <?php include '../../includes/sidebar.php'; ?>
        
        <main class="flex-1 p-8">
            <div class="max-w-7xl mx-auto">
                <!-- Header -->
                <div class="mb-8">
                    <h1 class="text-3xl font-bold text-gray-800 mb-2">
                        <i class="fas fa-exclamation-circle text-blue-600 mr-2"></i>
                        Membership Issues
                    </h1>
                    <p class="text-gray-600">Manage and resolve membership complaints and issues</p>
                </div>

                <!-- Success/Error Messages -->
                <?php if (!empty($successMessage)): ?>
                    <div class="bg-green-100 border-l-4 border-green-500 text-green-700 p-4 rounded-lg mb-6">
                        <p><i class="fas fa-check-circle mr-2"></i><?php echo htmlspecialchars($successMessage); ?></p>
                    </div>
                <?php endif; ?>
                <?php if (!empty($errorMessage)): ?>
                    <div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 rounded-lg mb-6">
                        <p><i class="fas fa-exclamation-circle mr-2"></i><?php echo htmlspecialchars($errorMessage); ?></p>
                    </div>
                <?php endif; ?>

                <!-- Statistics Cards -->
                <div class="grid grid-cols-1 md:grid-cols-5 gap-6 mb-8">
                    <div class="bg-white rounded-lg shadow-md p-6">
                        <div class="flex items-center justify-between">
                            <div>
                                <p class="text-gray-500 text-sm font-semibold uppercase">Total Issues</p>
                                <p class="text-3xl font-bold text-gray-800 mt-2"><?php echo $stats['total']; ?></p>
                            </div>
                            <i class="fas fa-list text-gray-400 text-3xl"></i>
                        </div>
                    </div>
                    <div class="bg-white rounded-lg shadow-md p-6">
                        <div class="flex items-center justify-between">
                            <div>
                                <p class="text-yellow-600 text-sm font-semibold uppercase">Pending</p>
                                <p class="text-3xl font-bold text-yellow-600 mt-2"><?php echo $stats['pending']; ?></p>
                            </div>
                            <i class="fas fa-clock text-yellow-400 text-3xl"></i>
                        </div>
                    </div>
                    <div class="bg-white rounded-lg shadow-md p-6">
                        <div class="flex items-center justify-between">
                            <div>
                                <p class="text-blue-600 text-sm font-semibold uppercase">In Progress</p>
                                <p class="text-3xl font-bold text-blue-600 mt-2"><?php echo $stats['in_progress']; ?></p>
                            </div>
                            <i class="fas fa-spinner text-blue-400 text-3xl"></i>
                        </div>
                    </div>
                    <div class="bg-white rounded-lg shadow-md p-6">
                        <div class="flex items-center justify-between">
                            <div>
                                <p class="text-green-600 text-sm font-semibold uppercase">Resolved</p>
                                <p class="text-3xl font-bold text-green-600 mt-2"><?php echo $stats['resolved']; ?></p>
                            </div>
                            <i class="fas fa-check-circle text-green-400 text-3xl"></i>
                        </div>
                    </div>
                    <div class="bg-white rounded-lg shadow-md p-6">
                        <div class="flex items-center justify-between">
                            <div>
                                <p class="text-red-600 text-sm font-semibold uppercase">Rejected</p>
                                <p class="text-3xl font-bold text-red-600 mt-2"><?php echo $stats['rejected']; ?></p>
                            </div>
                            <i class="fas fa-times-circle text-red-400 text-3xl"></i>
                        </div>
                    </div>
                </div>

                <!-- Filters -->
                <div class="bg-white rounded-lg shadow-md p-6 mb-8">
                    <form method="GET" class="flex flex-wrap gap-4 items-end">
                        <div class="flex-1 min-w-[200px]">
                            <label class="block text-sm font-semibold text-gray-700 mb-2">Status</label>
                            <select name="status" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
                                <option value="all" <?php echo $filterStatus == 'all' ? 'selected' : ''; ?>>All Statuses</option>
                                <option value="pending" <?php echo $filterStatus == 'pending' ? 'selected' : ''; ?>>Pending</option>
                                <option value="in_progress" <?php echo $filterStatus == 'in_progress' ? 'selected' : ''; ?>>In Progress</option>
                                <option value="resolved" <?php echo $filterStatus == 'resolved' ? 'selected' : ''; ?>>Resolved</option>
                                <option value="rejected" <?php echo $filterStatus == 'rejected' ? 'selected' : ''; ?>>Rejected</option>
                            </select>
                        </div>
                        <div class="flex-1 min-w-[200px]">
                            <label class="block text-sm font-semibold text-gray-700 mb-2">Type</label>
                            <select name="type" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
                                <option value="all" <?php echo $filterType == 'all' ? 'selected' : ''; ?>>All Types</option>
                                <option value="not_found" <?php echo $filterType == 'not_found' ? 'selected' : ''; ?>>Member Not Found</option>
                                <option value="incorrect_details" <?php echo $filterType == 'incorrect_details' ? 'selected' : ''; ?>>Incorrect Details</option>
                            </select>
                        </div>
                        <button type="submit" class="bg-blue-600 text-white px-6 py-2 rounded-lg hover:bg-blue-700 transition">
                            <i class="fas fa-filter mr-2"></i>Filter
                        </button>
                        <a href="?" class="bg-gray-500 text-white px-6 py-2 rounded-lg hover:bg-gray-600 transition">
                            <i class="fas fa-redo mr-2"></i>Reset
                        </a>
                    </form>
                </div>

                <!-- Issues List -->
                <div class="bg-white rounded-lg shadow-md overflow-hidden">
                    <?php if (empty($issues)): ?>
                        <div class="p-12 text-center">
                            <i class="fas fa-inbox text-gray-300 text-6xl mb-4"></i>
                            <p class="text-gray-600 text-lg">No issues found.</p>
                        </div>
                    <?php else: ?>
                        <div class="overflow-x-auto">
                            <table class="w-full">
                                <thead class="bg-gray-50 border-b border-gray-200">
                                    <tr>
                                        <th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">ID</th>
                                        <th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Type</th>
                                        <th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Complainant</th>
                                        <th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Member</th>
                                        <th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Status</th>
                                        <th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Created</th>
                                        <th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Actions</th>
                                    </tr>
                                </thead>
                                <tbody class="divide-y divide-gray-200">
                                    <?php foreach ($issues as $issue): ?>
                                        <tr class="hover:bg-gray-50">
                                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
                                                #<?php echo $issue['id']; ?>
                                            </td>
                                            <td class="px-6 py-4 whitespace-nowrap">
                                                <?php if ($issue['issue_type'] == 'not_found'): ?>
                                                    <span class="px-3 py-1 rounded-full text-xs font-semibold bg-red-100 text-red-800">
                                                        <i class="fas fa-user-slash mr-1"></i>Not Found
                                                    </span>
                                                <?php else: ?>
                                                    <span class="px-3 py-1 rounded-full text-xs font-semibold bg-yellow-100 text-yellow-800">
                                                        <i class="fas fa-exclamation-triangle mr-1"></i>Incorrect
                                                    </span>
                                                <?php endif; ?>
                                                <?php if ($issue['has_membership_form']): ?>
                                                    <br><span class="px-2 py-1 rounded-full text-xs font-semibold bg-blue-100 text-blue-800 mt-1 inline-block">
                                                        <i class="fas fa-file-alt mr-1"></i>Has Form
                                                    </span>
                                                <?php endif; ?>
                                            </td>
                                            <td class="px-6 py-4">
                                                <div class="text-sm">
                                                    <p class="font-medium text-gray-900"><?php echo htmlspecialchars($issue['complainant_name']); ?></p>
                                                    <?php if ($issue['complainant_email']): ?>
                                                        <p class="text-gray-500 text-xs"><?php echo htmlspecialchars($issue['complainant_email']); ?></p>
                                                    <?php endif; ?>
                                                    <?php if ($issue['search_query']): ?>
                                                        <p class="text-gray-500 text-xs">Searched: "<?php echo htmlspecialchars($issue['search_query']); ?>"</p>
                                                    <?php endif; ?>
                                                </div>
                                            </td>
                                            <td class="px-6 py-4">
                                                <?php if ($issue['member_id']): ?>
                                                    <div class="text-sm">
                                                        <p class="font-medium text-gray-900"><?php echo htmlspecialchars($issue['member_first_name'] . ' ' . $issue['member_last_name']); ?></p>
                                                        <p class="text-gray-500 text-xs"><?php echo htmlspecialchars($issue['membershipcard_id']); ?></p>
                                                    </div>
                                                <?php else: ?>
                                                    <span class="text-gray-400 text-sm">N/A</span>
                                                <?php endif; ?>
                                            </td>
                                            <td class="px-6 py-4 whitespace-nowrap">
                                                <?php
                                                $statusColors = [
                                                    'pending' => 'bg-yellow-100 text-yellow-800',
                                                    'in_progress' => 'bg-blue-100 text-blue-800',
                                                    'resolved' => 'bg-green-100 text-green-800',
                                                    'rejected' => 'bg-red-100 text-red-800'
                                                ];
                                                $color = $statusColors[$issue['status']] ?? 'bg-gray-100 text-gray-800';
                                                ?>
                                                <span class="px-3 py-1 rounded-full text-xs font-semibold <?php echo $color; ?>">
                                                    <?php echo ucfirst(str_replace('_', ' ', $issue['status'])); ?>
                                                </span>
                                                <?php if ($issue['assigned_to_name']): ?>
                                                    <p class="text-xs text-gray-500 mt-1">→ <?php echo htmlspecialchars($issue['assigned_to_name']); ?></p>
                                                <?php endif; ?>
                                            </td>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                                <?php echo date('M d, Y', strtotime($issue['created_at'])); ?>
                                            </td>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm">
                                                <button onclick="viewIssue(<?php echo $issue['id']; ?>)" 
                                                        class="text-blue-600 hover:text-blue-800 mr-3">
                                                    <i class="fas fa-eye"></i>
                                                </button>
                                                <button onclick="manageIssue(<?php echo $issue['id']; ?>)" 
                                                        class="text-green-600 hover:text-green-800">
                                                    <i class="fas fa-cog"></i>
                                                </button>
                                            </td>
                                        </tr>
                                        
                                        <!-- Expandable Detail Row (Hidden by default) -->
                                        <tr id="detail-<?php echo $issue['id']; ?>" class="hidden bg-gray-50">
                                            <td colspan="7" class="px-6 py-4">
                                                <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                                                    <div>
                                                        <h4 class="font-bold text-gray-800 mb-2">Complaint Details:</h4>
                                                        <p class="text-sm text-gray-700 mb-4"><?php echo nl2br(htmlspecialchars($issue['complaint_details'])); ?></p>
                                                        
                                                        <?php if ($issue['proposed_data']): ?>
                                                            <?php $proposed = json_decode($issue['proposed_data'], true); ?>
                                                            <h4 class="font-bold text-gray-800 mb-2">Proposed Corrections:</h4>
                                                            <div class="text-sm space-y-1">
                                                                <?php foreach ($proposed as $key => $value): ?>
                                                                    <?php if (!empty($value)): ?>
                                                                        <p><span class="font-semibold"><?php echo ucfirst(str_replace('_', ' ', $key)); ?>:</span> <?php echo htmlspecialchars($value); ?></p>
                                                                    <?php endif; ?>
                                                                <?php endforeach; ?>
                                                            </div>
                                                        <?php endif; ?>
                                                        
                                                        <?php if ($issue['has_membership_form'] && $issue['membership_form_data']): ?>
                                                            <?php $formData = json_decode($issue['membership_form_data'], true); ?>
                                                            <h4 class="font-bold text-gray-800 mb-2 mt-4">Membership Application:</h4>
                                                            <div class="text-sm bg-white p-4 rounded border space-y-1">
                                                                <?php foreach ($formData as $key => $value): ?>
                                                                    <?php if (!empty($value)): ?>
                                                                        <p><span class="font-semibold"><?php echo ucfirst(str_replace('_', ' ', $key)); ?>:</span> <?php echo htmlspecialchars($value); ?></p>
                                                                    <?php endif; ?>
                                                                <?php endforeach; ?>
                                                            </div>
                                                            <form method="POST" class="mt-4">
                                                                <input type="hidden" name="action" value="approve_membership">
                                                                <input type="hidden" name="issue_id" value="<?php echo $issue['id']; ?>">
                                                                <button type="submit" class="bg-green-600 text-white px-4 py-2 rounded hover:bg-green-700">
                                                                    <i class="fas fa-check mr-2"></i>Approve & Create Member
                                                                </button>
                                                            </form>
                                                        <?php endif; ?>
                                                    </div>
                                                    
                                                    <div>
                                                        <h4 class="font-bold text-gray-800 mb-2">Manage Issue:</h4>
                                                        
                                                        <!-- Update Status Form -->
                                                        <form method="POST" class="mb-4">
                                                            <input type="hidden" name="action" value="update_status">
                                                            <input type="hidden" name="issue_id" value="<?php echo $issue['id']; ?>">
                                                            <div class="mb-3">
                                                                <label class="block text-sm font-semibold mb-1">Status:</label>
                                                                <select name="status" class="w-full px-3 py-2 border rounded text-sm">
                                                                    <option value="pending" <?php echo $issue['status']=='pending'?'selected':''; ?>>Pending</option>
                                                                    <option value="in_progress" <?php echo $issue['status']=='in_progress'?'selected':''; ?>>In Progress</option>
                                                                    <option value="resolved" <?php echo $issue['status']=='resolved'?'selected':''; ?>>Resolved</option>
                                                                    <option value="rejected" <?php echo $issue['status']=='rejected'?'selected':''; ?>>Rejected</option>
                                                                </select>
                                                            </div>
                                                            <div class="mb-3">
                                                                <label class="block text-sm font-semibold mb-1">Admin Notes:</label>
                                                                <textarea name="admin_notes" rows="3" class="w-full px-3 py-2 border rounded text-sm"><?php echo htmlspecialchars($issue['admin_notes'] ?? ''); ?></textarea>
                                                            </div>
                                                            <button type="submit" class="bg-blue-600 text-white px-4 py-2 rounded text-sm hover:bg-blue-700">
                                                                <i class="fas fa-save mr-2"></i>Update
                                                            </button>
                                                        </form>
                                                        
                                                        <!-- Assign Form -->
                                                        <form method="POST" class="mb-4">
                                                            <input type="hidden" name="action" value="assign">
                                                            <input type="hidden" name="issue_id" value="<?php echo $issue['id']; ?>">
                                                            <div class="mb-3">
                                                                <label class="block text-sm font-semibold mb-1">Assign To:</label>
                                                                <select name="assigned_to" class="w-full px-3 py-2 border rounded text-sm">
                                                                    <option value="">Select User</option>
                                                                    <?php foreach ($users as $user): ?>
                                                                        <option value="<?php echo $user['id']; ?>" <?php echo $issue['assigned_to']==$user['id']?'selected':''; ?>>
                                                                            <?php echo htmlspecialchars($user['full_name']); ?>
                                                                        </option>
                                                                    <?php endforeach; ?>
                                                                </select>
                                                            </div>
                                                            <button type="submit" class="bg-purple-600 text-white px-4 py-2 rounded text-sm hover:bg-purple-700">
                                                                <i class="fas fa-user-plus mr-2"></i>Assign
                                                            </button>
                                                        </form>
                                                        
                                                        <!-- Quick Resolve -->
                                                        <?php if ($issue['status'] != 'resolved'): ?>
                                                        <form method="POST">
                                                            <input type="hidden" name="action" value="resolve">
                                                            <input type="hidden" name="issue_id" value="<?php echo $issue['id']; ?>">
                                                            <button type="submit" class="bg-green-600 text-white px-4 py-2 rounded text-sm hover:bg-green-700">
                                                                <i class="fas fa-check-circle mr-2"></i>Mark as Resolved
                                                            </button>
                                                        </form>
                                                        <?php endif; ?>
                                                    </div>
                                                </div>
                                            </td>
                                        </tr>
                                    <?php endforeach; ?>
                                </tbody>
                            </table>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </main>
    </div>

    <script>
        function viewIssue(id) {
            const detailRow = document.getElementById('detail-' + id);
            detailRow.classList.toggle('hidden');
        }
        
        function manageIssue(id) {
            viewIssue(id);
        }
    </script>
</body>
</html>

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