<?php
require_once ("varables.php");

$myJSON['message'] = "کمبود منابع";
$myJSON['mmm'] = array();
$name="123";
if(isset($_POST["token"]) && isset($_POST["an1d"])
&& isset($_POST["bid"])&& isset($_POST["img"]))
{
	

	
	$user_id = $_POST["an1d"];
	$toke =  $_POST["token"];
	$bid = $_POST["bid"];
	$img = $_POST["img"];
	
    $connect = @mysqli_connect($hostname,$username,$password,$database);
    if($connect)
    {
        @mysqli_query($connect,"SET CHARACTER SET utf8mb4;");
        $query_token = "SELECT id FROM ".$tbl_sessions." WHERE token = '".$toke."' AND uid ='".$user_id."' AND type ='A' LIMIT 1";
		$tokres=@mysqli_query($connect,$query_token);
        if (!$tokres) {
            $myJSON['message']= "400" ;

        }
		else{
			$countoft = 0;
            while($rowt = @mysqli_fetch_assoc($tokres)){
				array_push($myJSON['mmm'], $rowt);
                $countoft++;
			}
			if($countoft == 0){
				$myJSON['message']= "405" ;
			}
			else{
				if (file_exists($img))
					unlink($img);
				$inser_q = "DELETE FROM tbl_banners WHERE bnrId = '".$bid."'";
				$insres=@mysqli_query($connect,$inser_q);
				if(!$insres)
					$myJSON['message']= "404" ;
				else{
					$myJSON['message']= "200" ;
				}
			}
		}
	}
	 else
		 $myJSON['message']="402";
}
    echo json_encode($myJSON);

?>
