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

	//$curr_season = $_SESSION['curr_season'];
	//$curr_season = '2018-2019';
    
    //echo $_GET['del'];

    //$editDeleteAction = $_SERVER['PHP_SELF'];
    if (isset($_GET['del'])) {
        // echo 'asdfdasf';
        $deleteID = $_GET['del'];
        
        //echo $deleteID;

        
            $deleteSql = "DELETE FROM newsarticles WHERE ah = '".$deleteID."'";
            $query_result = mysqli_query($conn_ama,$deleteSql) or die(mysqli_error($conn_ama));
            //$affectedRows = mysqli_affected_rows($conn_ama,$query_result);
                
            if($query_result ){
                //$msg[] = '<p style="font-family: Tahoma, Geneva, sans-serif; font-size:12px; color: #060; border: 1px solid #ACDFB0; background-color: #EFF8F0;">'.$affectedRows.' News item has been deleted</p>';	
                //$deleteRidirect = $_SERVER['PHP_SELF'];
                // header("Location: ".$deleteRidirect);
                echo "deleted";
                
                $query_rsForDel ="SELECT imageID, image, thumbnail FROM articleimages WHERE ah = '".$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);
         
                do{
                    // assign all the names of the image files to variable
                    $mainImage = $row_rsForDel['image'];
                    $thumbnail = $row_rsForDel['thumbnail'];
                                    
                    //Deleting the main Image
                    $mainfolder = "../articles-images/news/";
                    $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>";}
            
            
        
                } while($row_rsForDel = mysqli_fetch_assoc($rsForDel));  
            
            }
        

        
        
        //echo "deleted";
            
        

} 


?>
