<?php

include "../../config/master.php";
allowRoles([1,5]);

$id = intval($_GET['id'] ?? 0);

/* FETCH IMAGE BEFORE DELETE */
$q = mysqli_query($conn,"SELECT image FROM village_temples WHERE id='$id'");
$data = mysqli_fetch_assoc($q);

if($data){

    /* DELETE IMAGE FILE */
    if(!empty($data['image'])){
        $file_path = "../../uploads/temples/".$data['image'];

        if(file_exists($file_path)){
            unlink($file_path);
        }
    }

    /* DELETE RECORD */
    mysqli_query($conn,"DELETE FROM village_temples WHERE id='$id'");

}

echo "<script>
alert('Temple Deleted Successfully');
window.location='temples_list.php';
</script>";

?>