<?php
session_start();
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");
header('Content-Type: application/json; charset=utf-8');


if(isset($_POST['user_id']))
{
require 'config.php';


function check_input($par) {
  $par = trim($par);
  $par = stripslashes($par);
  $par = htmlspecialchars($par);
  return $par;
}



$auth=check_input($_POST['auth']);
$user_id=check_input($_POST['user_id']);


$auth = mysqli_escape_string($con, $auth);
$user_id=mysqli_escape_string($con, $user_id);



$sql="SELECT * FROM users WHERE user_id = '$user_id' AND auth = '$auth'";
$result=$con->query($sql) or die ("error: Server error ".mysqli_error($con));
$count=mysqli_num_rows($result);

if ($count == 0)
{
        $suc = "User Does Not Exist"; 
         $status = false; 


}
else
{

$rows = mysqli_fetch_array($result);
$phone = $rows['phone'];
$email = $rows['email'];


$sql="SELECT * FROM location_sharing WHERE user_id = '$user_id' AND user = '$email' ORDER BY id DESC LIMIT 0, 50";
$result=$con->query($sql) or die ("error: Server error ".mysqli_error($con));




if($result)
{
$data = array();

     while($rows=mysqli_fetch_assoc($result))
   {
    $data[] = $rows;
    $suc="Success";
 
   }
   if($data == null)
   {
      $suc="No Shared Location";
       $data = ''; 
   }



}
}
}

$con->close();

header('Content-Type: application/json; charset=utf-8');
$output = array('success'=>$suc, 'data'=> $data);
echo json_encode($output); //output JSON data
//mysql_close($con);
?>

