<?php
include '../../conn.php';
include 'message.php'; 
$email=$_GET['email'];
$password=$_GET['password'];
$fcmtoken=$_GET['fcmtoken'];

$resultdata =$con->query("select * from `users` where email='$email' AND password='$password'");
$id=null;
$name=null;
$adminbyname=null;
$email=null;


while($row = mysqli_fetch_array($resultdata)){
    $id=$row['id'];
    $name=$row['name'];
    $email=$row['email'];
}
if($id > 0)
{ 
    
$insert = $con->query("UPDATE `users` SET `fcmToken`='$fcmtoken' WHERE  id='$id'");
 
      
      $data = array("to" => $fcmtoken,
                  "notification" => array( "code"=> $logincodefcm,"title" => "$titlefcm", "body" => $loginmsg,"icon" => $logofcm));                                                                    
            $data_string = json_encode($data); 
            
             "The Json Data : ".$data_string; 
            
            $headers = array
            (
                 'Authorization: key=' . API_ACCESS_KEY, 
                 'Content-Type: application/json'
            );                                                                                 
                                                                                                                                 
            $ch = curl_init();  
            
            curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );                                                                  
            curl_setopt( $ch,CURLOPT_POST, true );  
            curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
            curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
            curl_setopt( $ch,CURLOPT_POSTFIELDS, $data_string);                                                                  
                                                                                                                                 
            $result = curl_exec($ch);
$j->status  = "101";
$j->message = "Success";
$j->id=$id;
$j->name=$name;
$j->email=$email;
}
else{
$j->status  = "104";
$j->message = "Email And Password wrong";
}
echo json_encode($j);         
?>