<?php
class notify{

function send($con,$email,$defectid,$message){

$type = "defect";

$sql = mysqli_query($con, "SELECT firebase_token FROM signupdetails WHERE emailid = '$email'");


  if (mysqli_num_rows($sql) > 0) {
		$row = mysqli_fetch_array($sql);
        $token = $row["firebase_token"];
  }
 
  $url = 'https://fcm.googleapis.com/fcm/send';

    $fields = array (
            
            /*'notification' => array (
                    "body" => $message
            ),*/
            'data' => array (
                    "id" => $defectid,
                    "type" => $type,
                    "body" => $message,
            ),
            'to' =>$token
    );
    $fields = json_encode ( $fields );

    $headers = array (
            'Authorization:key=AAAABd_t6Zc:APA91bEeWqoBNL4kKPeXdKQVApp1Ot_zdLj2U2Pt6GEAPzI8V2yLTKzFoBam0hGUyfFhwsxMYVrK9whBvPgNjwdMoLIKeNb-hsNgoHAB4yTZg58pX3_4h38Bxkp0Pvw46bRmp3QJUe0B',
            'Content-Type: application/json'
    );

    $ch = curl_init ();
    curl_setopt ( $ch, CURLOPT_URL, $url );
    curl_setopt ( $ch, CURLOPT_POST, true );
    curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
    curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );

    $result = curl_exec ( $ch );
    //echo $result ."&nbsp;".$id."<br>";
    curl_close ( $ch );
} 

}
?>