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

$myJSON['message'] = "500";
$myJSON['slider'] = array();

if(isset($_POST["an1d"]) && isset($_POST["nekot"]) )
{
	
	$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)){
                $countoft++;
			}
			if($countoft == 0){
				$myJSON['message']= "405" ;
			}
			else{
				
				$q = "SELECT * FROM tbl_slider ORDER BY id DESC";
				$res=@mysqli_query($connect,$q);
				if(!$res)
					$myJSON['message']= "404" ;
				else{
					$i=0;
					while($row = @mysqli_fetch_assoc($res))
					{
						array_push($myJSON["slider"], $row);
						$myJSON["slider"][$i]["meta"] = array();
						$qm  = "SELECT tag,value FROM tbl_slider_meta WHERE s_id = '".$row["id"]."'";
						$resm=@mysqli_query($connect,$qm);
						if($resm){
							while($rowm = @mysqli_fetch_assoc($resm))
							array_push($myJSON["slider"][$i]["meta"], $rowm);
						}
						$i++;
					}
					$myJSON['message']= "200" ;
				}
				}	
		}	
	}
	 else
		 $myJSON['message']="402";
}
    echo json_encode($myJSON);
?>
