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

$myJSON['message'] = "خطای اعتبار سنجی";
$myJSON['mmm'] = array();
if(isset($_POST["nekot"]) && isset($_POST["an1d"]))
{
	$id =$_POST["an1d"];
    $connect = @mysqli_connect($hostname,$username,$password,$database);
    if($connect)
    {
		@mysqli_query($connect,"SET CHARACTER SET utf8;");
			$query_all = "UPDATE ".$tbl_visitors." SET V_name = 'ویزیتور حذف شده', username = '".md5($id . date("y-m-d"))."',pass='%TYD^&DSE*!',V_id='',V_Code='', deleted='1' WHERE id  = '".$id."'";
			$allres = @mysqli_query($connect,$query_all);
			if($allres){
				$myJSON['message'] = "200";
				$query = "SELECT * FROM ".$tbl_visitor_routs." WHERE V_id  = '".$id."'";
				$res = @mysqli_query($connect,$query);
				if($res)
			 while($row = @mysqli_fetch_assoc($res)){
			 $qd = "DELETE FROM ".$tbl_visitor_routs." WHERE vrid = '".$row['vrid']."'";
			 @mysqli_query($connect,$qd);
			 $qu = "UPDATE ".$tbl_routs." SET visitored = '0' WHERE id = '".$row['R_id']."'";
			 @mysqli_query($connect,$qu);
			 }
			 $qsd = "DELETE FROM ".$tbl_sessions." WHERE uid = '".$id."' AND type ='V'";
			 @mysqli_query($connect,$qsd);
			}
			else{
				$myJSON['message'] = @mysqli_error($connect);
			}
	}
	 else
	 $myJSON['message'] ="خطای پایگاه داده";
}
echo json_encode($myJSON);
?>
