<?php
declare(strict_types=1);

require_once '../includes/auth.php';
require_once '../includes/security.php';
require_once '../includes/functions.php';
require_once '../config/database.php';

$pageTitle='Entries';
require_once '../includes/header.php';

$stmt=$pdo->query("SELECT e.id,e.pdf_name,e.created_at,u.university_name
FROM entries e
JOIN universities u ON u.id=e.university_id
ORDER BY e.id DESC");
$rows=$stmt->fetchAll();
?>

<section class="content-header">
<div class="container-fluid">
<h1>Entries</h1>
</div>
</section>

<section class="content">
<div class="container-fluid">

<div class="card">
<div class="card-header">
<h3 class="card-title">Uploaded PDFs</h3>
</div>

<div class="card-body table-responsive">

<table id="entryTable" class="table table-bordered table-hover">
<thead>
<tr>
<th>ID</th>
<th>University</th>
<th>PDF</th>
<th>Date</th>
<th>Action</th>
</tr>
</thead>

<tbody>

<?php foreach($rows as $r): ?>

<tr>

<td><?= (int)$r['id']; ?></td>

<td><?= e($r['university_name']); ?></td>

<td><?= e($r['pdf_name']); ?></td>

<td><?= e($r['created_at']); ?></td>

<td>

<a target="_blank"
class="btn btn-success btn-sm"
href="../../student/files/<?= rawurlencode($r['pdf_name']); ?>">
View
</a>

<a class="btn btn-danger btn-sm"
href="../actions/delete-entry.php?id=<?= (int)$r['id']; ?>"
onclick="return confirm('Delete this entry?');">
Delete
</a>

</td>

</tr>

<?php endforeach; ?>

</tbody>

</table>

</div>
</div>

</div>
</section>

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