Sindbad~EG File Manager
<?php
require_once 'config/config.php';
// Check if user is logged in
if (!isLoggedIn()) {
redirect('admin/login.php');
}
$db = new Database();
$conn = $db->getConnection();
// Test data query
$query = "SELECT ar.full_name, ar.email, ar.telephone, ar.district_name, ar.assembly_name,
p.name as program_name, l.name as location_name, ar.submitted_at,
ar.latitude, ar.longitude, ar.location_accuracy, ar.location_address
FROM attendance_records ar
JOIN programs p ON ar.program_id = p.id
LEFT JOIN locations l ON p.location_id = l.id
ORDER BY ar.submitted_at DESC
LIMIT 5";
$stmt = $conn->prepare($query);
$stmt->execute();
$test_data = $stmt->fetchAll();
$export_working = [
'csv' => true,
'excel' => true,
'pdf' => true
];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Export Functions Test</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
</head>
<body class="bg-gray-50 min-h-screen">
<div class="max-w-6xl mx-auto py-8 px-4">
<div class="bg-white rounded-lg shadow-lg p-6">
<h1 class="text-3xl font-bold text-gray-900 mb-6">
<i class="fas fa-download text-blue-600 mr-3"></i>Export Functions Test
</h1>
<!-- Export Status -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8">
<div class="bg-blue-50 border border-blue-200 rounded-lg p-4">
<div class="flex items-center">
<i class="fas fa-file-csv text-blue-600 text-2xl mr-3"></i>
<div>
<h3 class="font-semibold text-blue-900">CSV Export</h3>
<p class="text-sm text-blue-700">
<?php echo $export_working['csv'] ? 'Working' : 'Not Working'; ?>
</p>
</div>
</div>
</div>
<div class="bg-green-50 border border-green-200 rounded-lg p-4">
<div class="flex items-center">
<i class="fas fa-file-excel text-green-600 text-2xl mr-3"></i>
<div>
<h3 class="font-semibold text-green-900">Excel Export</h3>
<p class="text-sm text-green-700">
<?php echo $export_working['excel'] ? 'Working' : 'Not Working'; ?>
</p>
</div>
</div>
</div>
<div class="bg-red-50 border border-red-200 rounded-lg p-4">
<div class="flex items-center">
<i class="fas fa-file-pdf text-red-600 text-2xl mr-3"></i>
<div>
<h3 class="font-semibold text-red-900">PDF Export</h3>
<p class="text-sm text-red-700">
<?php echo $export_working['pdf'] ? 'Working' : 'Not Working'; ?>
</p>
</div>
</div>
</div>
</div>
<!-- Test Export Buttons -->
<div class="bg-gray-50 rounded-lg p-6 mb-8">
<h2 class="text-xl font-semibold text-gray-900 mb-4">Test Export Functions</h2>
<p class="text-gray-600 mb-4">
Click the buttons below to test each export format with sample attendance data.
</p>
<div class="flex flex-wrap gap-4">
<a href="admin/reports.php?export=attendance&format=csv"
class="bg-blue-600 text-white px-6 py-3 rounded-lg hover:bg-blue-700 transition duration-300">
<i class="fas fa-file-csv mr-2"></i>Test CSV Export
</a>
<a href="admin/reports.php?export=attendance&format=excel"
class="bg-green-600 text-white px-6 py-3 rounded-lg hover:bg-green-700 transition duration-300">
<i class="fas fa-file-excel mr-2"></i>Test Excel Export
</a>
<a href="admin/reports.php?export=attendance&format=pdf"
class="bg-red-600 text-white px-6 py-3 rounded-lg hover:bg-red-700 transition duration-300">
<i class="fas fa-file-pdf mr-2"></i>Test PDF Export
</a>
</div>
</div>
<!-- Sample Data Preview -->
<div class="bg-white border rounded-lg overflow-hidden">
<div class="bg-gray-50 px-6 py-3 border-b">
<h3 class="text-lg font-semibold text-gray-900">Sample Data Preview</h3>
<p class="text-sm text-gray-600">This is the data that will be exported (showing first 5 records)</p>
</div>
<?php if (empty($test_data)): ?>
<div class="p-6 text-center">
<i class="fas fa-exclamation-triangle text-yellow-500 text-3xl mb-3"></i>
<h3 class="text-lg font-semibold text-gray-900 mb-2">No Data Available</h3>
<p class="text-gray-600">No attendance records found to export. Please add some attendance records first.</p>
</div>
<?php else: ?>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<?php foreach (array_keys($test_data[0]) as $header): ?>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
<?php echo ucwords(str_replace('_', ' ', $header)); ?>
</th>
<?php endforeach; ?>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
<?php foreach ($test_data as $row): ?>
<tr>
<?php foreach ($row as $key => $value): ?>
<td class="px-4 py-3 whitespace-nowrap text-sm text-gray-900">
<?php
if ($key === 'latitude' || $key === 'longitude') {
echo $value ? number_format($value, 4) : '-';
} elseif ($key === 'location_accuracy') {
echo $value ? '±' . round($value) . 'm' : '-';
} elseif ($key === 'submitted_at') {
echo date('M j, Y g:i A', strtotime($value));
} elseif ($key === 'location_address') {
echo $value ? htmlspecialchars(substr($value, 0, 30)) . (strlen($value) > 30 ? '...' : '') : 'No address';
} else {
echo htmlspecialchars($value ?? '');
}
?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
<!-- Instructions -->
<div class="mt-8 bg-blue-50 border border-blue-200 rounded-lg p-6">
<h3 class="text-lg font-semibold text-blue-900 mb-3">
<i class="fas fa-info-circle mr-2"></i>Export Instructions
</h3>
<div class="space-y-2 text-sm text-blue-800">
<p><strong>CSV Export:</strong> Downloads a comma-separated values file that can be opened in Excel or other spreadsheet applications.</p>
<p><strong>Excel Export:</strong> Downloads an Excel-compatible file (.xls) that opens directly in Microsoft Excel.</p>
<p><strong>PDF Export:</strong> Opens a print-friendly page. Use your browser's "Print" function and select "Save as PDF".</p>
</div>
</div>
<!-- Back to Admin -->
<div class="text-center mt-8">
<a href="admin/reports.php" class="text-blue-600 hover:text-blue-800 font-medium">
<i class="fas fa-arrow-left mr-2"></i>Back to Reports
</a>
</div>
</div>
</div>
</body>
</html>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists