<?php

include "config/db.php";
include "common.php";
include "header.php";

/* SESSION CHECK (EDIT BUTTON ONLY FOR ADMIN) */
$role_id = $_SESSION['role_id'] ?? 0;   // 1 = Super Admin (change if needed)

/* FETCH ALL SPECIAL THANKS */
$data = mysqli_query($conn,"
SELECT *
FROM special_thanks
WHERE village_id='$village_id'
ORDER BY display_order ASC, id DESC
");

?>

<div class="container">

<h2 class="section-title">विशेष धन्यवाद</h2>

<?php if(mysqli_num_rows($data) > 0){ ?>

<div class="special-thanks-section">

<?php while($row=mysqli_fetch_assoc($data)){ ?>

<div class="thanks-item">

    <div class="sarpanch-box" style="position:relative;">

        <!-- EDIT BUTTON -->
        <?php if($role_id == 1){ ?>
        <a href="/digital_panchayat/admin/special_thanks/edit.php?id=<?php echo $row['id']; ?>" 
           class="edit-btn">
           ✏️ Edit
        </a>
        <?php } ?>

        <!-- IMAGE -->
        <div class="sarpanch-image">
            <?php if(!empty($row['image'])){ ?>
            <img src="/digital_panchayat/uploads/special_thanks/<?php echo $row['image']; ?>">
            <?php } ?>
        </div>

        <!-- TEXT -->
        <div class="sarpanch-text">

            <h3><?php echo htmlspecialchars($row['name']); ?></h3>

            <p style="color:#777;">
                <?php echo htmlspecialchars($row['designation']); ?>
            </p>

            <p>
                <?php echo substr(strip_tags($row['description']),0,200); ?>...
                <br><br>

                <a href="special_thanks_detail.php?id=<?php echo $row['id']; ?>" class="view-btn">
                    पूरा पढ़ें →
                </a>
            </p>

        </div>

    </div>

</div>

<?php } ?>

</div>

<?php } else { ?>

<div style="padding:20px;">
कोई विशेष धन्यवाद उपलब्ध नहीं है
</div>

<?php } ?>

</div>

<!-- SIMPLE CSS -->
<style>
.edit-btn{
    position:absolute;
    top:10px;
    right:10px;
    background:#007bff;
    color:#fff;
    padding:5px 10px;
    font-size:12px;
    border-radius:4px;
    text-decoration:none;
}
.edit-btn:hover{
    background:#0056b3;
}
</style>

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