36459-vm/download.php
2025-11-29 17:28:26 +00:00

28 lines
706 B
PHP

<?php
session_start();
// Check if admin is logged in
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
header('Location: admin.php');
exit;
}
require_once 'db/config.php';
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=quiz_attempts.csv');
$output = fopen('php://output', 'w');
fputcsv($output, array('ID', 'Visual Score', 'Auditory Score', 'Read/Write Score', 'Kinesthetic Score', 'Primary Style', 'Date'));
$pdo = db();
$stmt = $pdo->query("SELECT * FROM quiz_attempts ORDER BY created_at DESC");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
fputcsv($output, $row);
}
fclose($output);
exit;
?>