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

$myJSON['message'] = "0";
$myJSON['mmm'] = array();
if(isset($_POST["an1d"]) && isset($_POST["nekot"])&& isset($_POST["pId"]))
{
	

	$toke = str_replace('"',"", $_POST["nekot"]);
	$user_id =str_replace('"',"", $_POST["an1d"]);
	$pid =str_replace('"',"", $_POST["pId"]);

    $connect = @mysqli_connect($hostname,$username,$password,$database);
    if($connect)
    {
        @mysqli_query($connect,"SET CHARACTER SET utf8;");
        $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{
				$iamgename =  md5($pid . getdate() .time());
				$target_file_name = $target_dir . $iamgename;
				$quer = "SELECT img FROM tbl_pAlbums WHERE id = '".$pid."'";
				$selres=@mysqli_query($connect,$quer);
						if($selres){
							$rowp = @mysqli_fetch_assoc($selres);
							$file = $rowp["img"];
							if (file_exists($file))
							if(unlink($file)){
								$quer = "DELETE FROM tbl_pAlbums WHERE id = '".$pid."'";	
								$selres=@mysqli_query($connect,$quer);
								$myJSON['message']="200";
							}			 
						}
					}
		}
	}
	 else
		 $myJSON['message']="402";
}
    echo json_encode($myJSON);

?>
