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

$myJSON['message'] = "کمبود منابع";
$myJSON['mmm'] = array();

if( isset($_POST["an1d"]) && isset($_POST["nekot"])
&& isset($_POST["rnd"])&& isset($_POST["sid"]))
{


	$sid = $_POST["sid"];
	$user_id = $_POST["an1d"];
	$toke =  $_POST["nekot"];

	


    $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{
				
				$qimg = "SELECT value FROM tbl_slider_meta WHERE s_id = '".$sid."' AND tag ='img' LIMIT 1";
				$imgres=@mysqli_query($connect,$qimg);
				if($imgres){
					while($row = @mysqli_fetch_assoc($imgres)){
						$img = $row['img'];
						if (file_exists($img))
							unlink($img);
					}
					$qrem = "DELETE FROM tbl_slider WHERE id = '".$sid."'";
					$remres=@mysqli_query($connect,$qrem);
					if($remres){
						$qrem = "DELETE FROM tbl_slider_meta WHERE s_id = '".$sid."'";
						@mysqli_query($connect,$qrem);
						$myJSON['message']="200";
					}
					else{
						$myJSON['message']="خطایی رخ داد\n".@mysqli_error($connect);
					}
				}
				else{
					$myJSON['message']="خطایی رخ داد\n".@mysqli_error($connect);
				}
			}
		}
	}
	 else
		 $myJSON['message']="402";
}
    echo json_encode($myJSON);
?>
