<?php
session_start();

header('Access-Control-Allow-Origin: *');

header('Access-Control-Allow-Methods: GET, POST');

header("Access-Control-Allow-Headers: X-Requested-With");


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']);
$lat=check_input($_POST['lat']);
$lng=check_input($_POST['lng']);
$content=check_input($_POST['content']);


$auth = mysqli_escape_string($con, $auth);
$user_id=mysqli_escape_string($con, $user_id);
$lat=mysqli_escape_string($con, $lat);
$lng=mysqli_escape_string($con, $lng);
$content=mysqli_escape_string($con, $content);




$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 == 1)
{
$rows = mysqli_fetch_array($result);
$phone = $rows['phone'];
$email = $rows['email'];
$firstname = $rows['firstname'];
$lastname = $rows['lastname'];

date_default_timezone_set("Africa/Lagos");

  $date_t = date("d-M-Y h:i:s a"); 
  
 
 include 'src/get_locality.php';
 $address= getaddress($lat,$lng);


  $sqlx=$con->query("INSERT INTO timeline  (user_id, user, firstname, lastname, lat, lng, location,  post, post_id, comments, likes, shares, views, image,  date_t) 
      VALUES ('$user_id', '$email', '$firstname', '$lastname', '$lat', '$lng', '$address', '$content', '$post_id', '0', '0', '0', '0', '',  '$date_t')") or die("Error: ".mysqli_error($con));
      
      
  
if($sqlx)
{

$suc = "Successful"; 
$status = true; 

}
}
else
{
         $suc = "User Does Not Exist"; 
         $status = false; 
}

$con->close();

$output = array('status' => $status, 'success'=>$suc);
echo json_encode($output); //output JSON data
}
?>
