<?php
// ไม่มี include db
?>
<!DOCTYPE html>
<html>
<head>
    <title>วัดดวงดี</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>

<?php include "menu.php"; ?>

<h1>ยินดีต้อนรับ</h1>

</body>
</html>


<!-- แบนเนอร์หัวเว็บ -->
<div class="hero-banner">
    <div class="hero-text">
        <h1>วัดดวงดี จังหวัดเชียงใหม่</h1>
        <p>ศูนย์รวมศรัทธาและวัฒนธรรมล้านนา</p>
    </div>
</div>

<div class="container">

    <!-- ข่าวประชาสัมพันธ์ -->
    <h2 class="page-title">ข่าวประชาสัมพันธ์ล่าสุด</h2>

    <div class="content-box">
        <?php
        $result = $conn->query("SELECT * FROM news ORDER BY id DESC LIMIT 3");
        if($result->num_rows > 0){
            while($row = $result->fetch_assoc()){
                echo "<div class='news-item'>";
                echo "<h4>".$row['title']."</h4>";
                echo "<p>".$row['content']."</p>";
                echo "</div><hr>";
            }
        } else {
            echo "<p>ยังไม่มีข่าวประชาสัมพันธ์</p>";
        }
        ?>
    </div>

    <!-- แกลเลอรี่รูป -->
    <h2 class="page-title">ภาพบรรยากาศวัดดวงดี</h2>

    <div class="gallery">
        <?php
        $dir = "images/";
        $files = scandir($dir);

        foreach($files as $file){
            if($file != "." && $file != ".." && preg_match('/\.(jpg|jpeg|png)$/i', $file)){
                echo "<img src='".$dir.$file."' alt='gallery'>";
            }
        }
        ?>
    </div>

</div>

</body>
</html>
