<?php

$day = date("j"); // Day of month
$chapter = $day;

if ($chapter > 31) {
    $chapter = ($chapter % 31);
    if ($chapter == 0) $chapter = 31;
}

$file = __DIR__ . "/proverbs/proverbs{$chapter}.txt";

$scripture = "File not found.";

if (file_exists($file)) {
    $scripture = nl2br(htmlspecialchars(file_get_contents($file)));
}

?>

<!DOCTYPE html>
<html>
<head>
<title>Daily Proverbs Devotional</title>
</head>
<body>

<h1>Proverbs Chapter <?php echo $chapter; ?></h1>

<h2>Scripture</h2>
<div>
<?php echo $scripture; ?>
</div>

<h2>Devotional Commentary</h2>
<div>

<?php

$commentaryFile = __DIR__ . "/commentary/chapter{$chapter}.txt";

if (file_exists($commentaryFile)) {
    echo nl2br(htmlspecialchars(file_get_contents($commentaryFile)));
} else {
    echo "No commentary written yet.";
}

?>

</div>



</body>
</html>
