<?php
session_start();

if (!isset($_SESSION["login"])) {
    header("Location: login.php");
    exit;
}

require 'functions.php';

$id = $_GET["id"];

$mhs = query("SELECT * FROM keluhan WHERE id_keluhan= $id")[0];
$nama = $mhs["gambar1"];
$nama2 = $mhs["gambar2"];
$gambar = "imgKeluhan/$nama";
$gambar2 = "imgKeluhan/$nama2";

if (file_exists($gambar)) {
    unlink($gambar); // Delete now
}
$aa = file_exists($gambar);
if (file_exists($gambar2)) {
    unlink($gambar2); // Delete now
}
$aa2 = file_exists($gambar2);

if (hapuskeluhan($id) > 0) {
    echo "
            <script>
            alert('data berhasil dihapus!');
            document.location.href = 'Admin_KeluhanMasuk.php';
            </script>
        ";
} else {
    echo "
            <script>
            alert('data gagal dihapus!!');
            document.location.href = 'Admin_KeluhanMasuk.php';
            </script>
        ";
}
