<?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'];


$sqlx="SELECT * FROM notifications WHERE user_id = '$user_id' ORDER BY id DESC LIMIT 0, 50";
$resultx=$con->query($sqlx) or die ("error: Server error ".mysqli_error($con));




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

     while($rowsx=mysqli_fetch_assoc($resultx))
   {
    $data[] = $rowsx;
    $suc="Success";
 
   }
   if($data == null)
   {
      $suc="No Notifications";
       $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);
?>

