<?php
header("Content-type: application/json; charset=utf-8");
date_default_timezone_set('Asia/Jerusalem');
require_once('class.db.php');
require_once 'MyAPI.CLASS.php';
require 'fcm.class.php'; 

$user_id=$_GET['user_id'];
$type=$_GET['type'];
$device_id=$_GET['device_id'];
$title=$_GET['title'];
$body=$_GET['body'];
$data='';



  $device_fcm = $device_id;
  
 
  
  
  $FCMPushNotification = new \BD\FCMPushNotification('AAAAjX1lE1M:APA91bEi35IgXTOAqS_688vbU4qD68v1-omWsJVngdHsyAMaR82v8mK9TVqPjVtq5L2MLXRLiKn1-_9SMOnbbRORfKL1zziG6X6snuyhmwg4oMGkoerWiOAyh1-HplCDsBukYWob2HLb');
  
  $sDeviceToken = $device_fcm;
  
  $aPayload = array(
    'data' => $data,
    'notification' => array(
      'title' => $title,
      'body'=> $body,
      'sound'=> 'default'
    )
  );
  
  $aOptions = array(
    'time_to_live' => 0 //means messages that can't be delivered immediately are discarded. 
  );
  
  $aResult = $FCMPushNotification->sendToDevice(
    $sDeviceToken,		
    $aPayload,
    $aOptions // optional
  );



    $rrr = json_encode($aResult,JSON_UNESCAPED_UNICODE);

  $date=date("Y-m-d H:i:s");
  $db = new Db();
  $result1 = $db ->query("INSERT INTO `notifications`( `user_id`, `device_id`, `title`, `body`, `type`, `status`, `date`,`results`)
   VALUES ($user_id,'$device_id','$title','$body','$type',0,'$date','$rrr')");

  
  
 print $aResult;
      

