<?php include "head.php"; ?>
<h2>r/TeenGovernment Laws</h2>
<?php
$db = new PDO('sqlite:lawsite.db');
$laws = $db->query("SELECT * FROM laws ORDER BY created_at DESC")->fetchAll(PDO::FETCH_ASSOC);

foreach ($laws as $law) {
    $statusClass = strtolower($law['status']);
    echo "<div class='law'>
        <h3><a href='view.php?id={$law['id']}'>" . htmlspecialchars($law['title']) . "</a></h3>
        <p>" . htmlspecialchars($law['summary']) . "</p>
        <p>Added by: " . htmlspecialchars($law['proposer']) . "</p>
        <p>Status: <span class='status $statusClass'>" . htmlspecialchars($law['status']) . "</span></p>
    </div>";
}
?>
<?php include "foot.php"; ?>
