<?php require_once('../../Connections/conn_ama.php'); 
include("../../../../../../../functions/functions.php"); 
    
if (!isset($_SESSION)) {
  session_start();
}
    
    if (isset($_GET['del'])) {

        $deleteID = $_GET['del'];
        
                    
        $query_rsForDel ="SELECT officerID, image, thumbnail FROM deptsub2officers WHERE officerID = ".$deleteID;
        $rsForDel = mysqli_query($conn_ama, $query_rsForDel ) or die(mysqli_error($conn_ama));
        $row_rsForDel = mysqli_fetch_assoc($rsForDel);
        $totalRows_rsForDel = mysqli_num_rows($rsForDel);
        
        $msg=NULL;
        //do{
            // assign all the names of the image files to variable
            $mainImage = $row_rsForDel['image'];
            $thumbnail = $row_rsForDel['thumbnail'];
                            
            //Deleting the main Image
            $mainfolder = "../subunitsofficers/";
            $filename = $mainfolder.$mainImage;
            // @chmod($filename,0700);
            $delete_main = @unlink($filename);
            if($delete_main){$msg[] = "<p class ='green'>".$mainImage." has been deleted</p>";} else{ $msg[] = $mainImage." <p class='red'>could not be deleted</p>";}
        
            //Deleting the thumbnail Image
            $thumbfolder = $mainfolder."thumbs/";
            $filename_1 = $thumbfolder.$thumbnail;
            //@chmod($filename_1,0700); 
            $delete_thumb = @unlink($filename_1);
            if($delete_thumb){$msg[] = "<p class ='green'>".$thumbnail." has been deleted</p>";} else{ $msg[] = $thumbnail."<p class='red'>could not be deleted</p>";}
            
            if(isset($msg) && $msg!=NULL)
            {
                $deleteSql = "DELETE FROM deptsub2officers WHERE officerID = ".$deleteID;
                $query_result = mysqli_query($conn_ama,$deleteSql) or die(mysqli_error($conn_ama));
                
                if($query_result)
                {
                    echo 'deleted';
                }
            }     

} 


?>
