Sindbad~EG File Manager

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

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

// Check if user is logged in
if (!isLoggedIn()) {
    http_response_code(403);
    echo '<div class="text-center py-4 text-red-600"><p>Access denied</p></div>';
    exit;
}

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

$record_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;

if (!$record_id) {
    echo '<div class="text-center py-4 text-red-600"><p>Invalid record ID</p></div>';
    exit;
}

// Get attendance record with all details
$query = "SELECT ar.*, p.name as program_name, p.description as program_description,
                 p.start_date, p.end_date, l.name as location_name, l.address as location_address,
                 ld.name as district_name_full, la.name as assembly_name_full
          FROM attendance_records ar 
          JOIN programs p ON ar.program_id = p.id 
          LEFT JOIN locations l ON p.location_id = l.id 
          LEFT JOIN locations ld ON ar.district_id = ld.id 
          LEFT JOIN locations la ON ar.assembly_id = la.id 
          WHERE ar.id = ?";

// Location restriction for admin users
if (hasRole('admin') && isset($_SESSION['location_id']) && $_SESSION['location_id']) {
    $query .= " AND p.location_id = ?";
    $stmt = $conn->prepare($query);
    $stmt->execute([$record_id, $_SESSION['location_id']]);
} else {
    $stmt = $conn->prepare($query);
    $stmt->execute([$record_id]);
}

$record = $stmt->fetch();

if (!$record) {
    echo '<div class="text-center py-4 text-red-600"><p>Record not found</p></div>';
    exit;
}

// Parse additional data
$additional_data = [];
if ($record['additional_data'] && $record['additional_data'] !== 'null') {
    $additional_data = json_decode($record['additional_data'], true) ?: [];
}
?>

<div class="space-y-6">
    <!-- Basic Information -->
    <div class="bg-gray-50 rounded-lg p-4">
        <h4 class="font-semibold text-gray-900 mb-3 flex items-center">
            <i class="fas fa-user mr-2 text-blue-600"></i>Personal Information
        </h4>
        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
            <div>
                <label class="text-sm font-medium text-gray-500">Full Name</label>
                <p class="text-gray-900 font-medium"><?php echo htmlspecialchars($record['full_name']); ?></p>
            </div>
            <?php if ($record['email']): ?>
            <div>
                <label class="text-sm font-medium text-gray-500">Email</label>
                <p class="text-gray-900"><?php echo htmlspecialchars($record['email']); ?></p>
            </div>
            <?php endif; ?>
            <?php if ($record['telephone']): ?>
            <div>
                <label class="text-sm font-medium text-gray-500">Phone</label>
                <p class="text-gray-900"><?php echo htmlspecialchars($record['telephone']); ?></p>
            </div>
            <?php endif; ?>
            <?php if ($record['tracking_code']): ?>
            <div>
                <label class="text-sm font-medium text-gray-500">Tracking Code</label>
                <p class="text-gray-900 font-mono font-bold text-blue-600"><?php echo htmlspecialchars($record['tracking_code']); ?></p>
            </div>
            <?php endif; ?>
        </div>
    </div>

    <!-- Location Information -->
    <div class="bg-gray-50 rounded-lg p-4">
        <h4 class="font-semibold text-gray-900 mb-3 flex items-center">
            <i class="fas fa-map-marker-alt mr-2 text-green-600"></i>Location Information
        </h4>
        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
            <div>
                <label class="text-sm font-medium text-gray-500">District</label>
                <p class="text-gray-900"><?php echo htmlspecialchars($record['district_name_full'] ?: $record['district_name'] ?: 'N/A'); ?></p>
            </div>
            <div>
                <label class="text-sm font-medium text-gray-500">Assembly</label>
                <p class="text-gray-900"><?php echo htmlspecialchars($record['assembly_name_full'] ?: $record['assembly_name'] ?: 'N/A'); ?></p>
            </div>
        </div>
    </div>

    <!-- Program Information -->
    <div class="bg-gray-50 rounded-lg p-4">
        <h4 class="font-semibold text-gray-900 mb-3 flex items-center">
            <i class="fas fa-calendar mr-2 text-purple-600"></i>Program Information
        </h4>
        <div class="space-y-3">
            <div>
                <label class="text-sm font-medium text-gray-500">Program Name</label>
                <p class="text-gray-900 font-medium"><?php echo htmlspecialchars($record['program_name']); ?></p>
            </div>
            <?php if ($record['program_description']): ?>
            <div>
                <label class="text-sm font-medium text-gray-500">Description</label>
                <p class="text-gray-900"><?php echo htmlspecialchars($record['program_description']); ?></p>
            </div>
            <?php endif; ?>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                <?php if ($record['start_date']): ?>
                <div>
                    <label class="text-sm font-medium text-gray-500">Start Date</label>
                    <p class="text-gray-900"><?php echo date('F j, Y', strtotime($record['start_date'])); ?></p>
                </div>
                <?php endif; ?>
                <?php if ($record['end_date']): ?>
                <div>
                    <label class="text-sm font-medium text-gray-500">End Date</label>
                    <p class="text-gray-900"><?php echo date('F j, Y', strtotime($record['end_date'])); ?></p>
                </div>
                <?php endif; ?>
            </div>
            <?php if ($record['location_name']): ?>
            <div>
                <label class="text-sm font-medium text-gray-500">Program Location</label>
                <p class="text-gray-900"><?php echo htmlspecialchars($record['location_name']); ?></p>
                <?php if ($record['location_address']): ?>
                    <p class="text-sm text-gray-600"><?php echo htmlspecialchars($record['location_address']); ?></p>
                <?php endif; ?>
            </div>
            <?php endif; ?>
        </div>
    </div>

    <!-- Additional Information -->
    <?php if (!empty($additional_data)): ?>
    <div class="bg-gray-50 rounded-lg p-4">
        <h4 class="font-semibold text-gray-900 mb-3 flex items-center">
            <i class="fas fa-info-circle mr-2 text-orange-600"></i>Additional Information
        </h4>
        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
            <?php foreach ($additional_data as $key => $value): ?>
                <?php if (!empty($value)): ?>
                <div>
                    <label class="text-sm font-medium text-gray-500"><?php echo ucfirst(str_replace('_', ' ', $key)); ?></label>
                    <p class="text-gray-900"><?php echo htmlspecialchars($value); ?></p>
                </div>
                <?php endif; ?>
            <?php endforeach; ?>
        </div>
    </div>
    <?php endif; ?>

    <!-- GPS Location Details -->
    <?php if ($record['latitude'] && $record['longitude']): ?>
    <div class="bg-gray-50 rounded-lg p-4">
        <h4 class="font-semibold text-gray-900 mb-3 flex items-center">
            <i class="fas fa-map-marker-alt mr-2 text-blue-600"></i>GPS Location
        </h4>
        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
            <div>
                <label class="text-sm font-medium text-gray-500">Coordinates</label>
                <p class="text-gray-900 font-mono text-sm">
                    <?php echo number_format($record['latitude'], 6); ?>, <?php echo number_format($record['longitude'], 6); ?>
                </p>
            </div>
            <?php if ($record['location_accuracy']): ?>
            <div>
                <label class="text-sm font-medium text-gray-500">Accuracy</label>
                <p class="text-gray-900">±<?php echo round($record['location_accuracy']); ?> meters</p>
            </div>
            <?php endif; ?>
            <?php if ($record['location_address']): ?>
            <div class="md:col-span-2">
                <label class="text-sm font-medium text-gray-500">Address</label>
                <p class="text-gray-900"><?php echo htmlspecialchars($record['location_address']); ?></p>
            </div>
            <?php endif; ?>
            <?php if ($record['location_timestamp']): ?>
            <div>
                <label class="text-sm font-medium text-gray-500">Location Captured</label>
                <p class="text-gray-900"><?php echo date('F j, Y g:i A', strtotime($record['location_timestamp'])); ?></p>
            </div>
            <?php endif; ?>
        </div>
        
        <!-- Map Link -->
        <div class="mt-3 pt-3 border-t">
            <a href="https://www.google.com/maps?q=<?php echo $record['latitude']; ?>,<?php echo $record['longitude']; ?>" 
               target="_blank" 
               class="inline-flex items-center text-blue-600 hover:text-blue-800 text-sm">
                <i class="fas fa-external-link-alt mr-2"></i>View on Google Maps
            </a>
        </div>
    </div>
    <?php endif; ?>

    <!-- Submission Details -->
    <div class="bg-gray-50 rounded-lg p-4">
        <h4 class="font-semibold text-gray-900 mb-3 flex items-center">
            <i class="fas fa-clock mr-2 text-red-600"></i>Submission Details
        </h4>
        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
            <div>
                <label class="text-sm font-medium text-gray-500">Submission Date</label>
                <p class="text-gray-900"><?php echo date('F j, Y', strtotime($record['submitted_at'])); ?></p>
            </div>
            <div>
                <label class="text-sm font-medium text-gray-500">Submission Time</label>
                <p class="text-gray-900"><?php echo date('g:i A', strtotime($record['submitted_at'])); ?></p>
            </div>
            <?php if ($record['ip_address']): ?>
            <div>
                <label class="text-sm font-medium text-gray-500">IP Address</label>
                <p class="text-gray-900 font-mono text-sm"><?php echo htmlspecialchars($record['ip_address']); ?></p>
            </div>
            <?php endif; ?>
        </div>
    </div>

    <!-- Actions -->
    <div class="flex justify-end space-x-3 pt-4 border-t">
        <?php if ($record['tracking_code']): ?>
        <a href="../check_status.php?code=<?php echo urlencode($record['tracking_code']); ?>" 
           target="_blank"
           class="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition duration-300 text-sm">
            <i class="fas fa-external-link-alt mr-2"></i>View Public Status
        </a>
        <?php endif; ?>
        <button onclick="window.print()" 
                class="bg-gray-600 text-white px-4 py-2 rounded-lg hover:bg-gray-700 transition duration-300 text-sm">
            <i class="fas fa-print mr-2"></i>Print
        </button>
        <button onclick="closeViewModal()" 
                class="bg-gray-300 text-gray-700 px-4 py-2 rounded-lg hover:bg-gray-400 transition duration-300 text-sm">
            Close
        </button>
    </div>
</div>

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