<?php 
	define('SERVER_API_KEY', 'AIzaSyBLCzBOK4sp3qbjnAOVnKbn0UjV9ZWuDKM');

	include_once "../actions/dbPDO.php";
        $tok = $db->prepare("SELECT token FROM loginhistory where default_user = 3");
        $tok->execute();
        $tokens = $tok->fetchAll(PDO::FETCH_ASSOC);
	foreach ($tokens as $token) {
		$registrationIds[] = $token['token'];
	}
	$url = 'https://fcm.googleapis.com/fcm/send';
	$headers = array(
		'Authorization:key=AAAAsBL6lsg:APA91bHym5fpyS4QWc2ds4c6XdWs2ZXeyXz1b9JfC0GJ8d5hRAcGmvqUFFEgSuRDN5CVyj5l8bu5nrMRJAMZ6K-BrMxTfKWMbdxen5FlJjVailhRUTEvNJpduvn6StXdmf0FCRZpLh5g',
		'Content-Type:application/json'
	);

	$msg = [
		'title' => 'Testing Notification',
		'body' 	=> 'Testing Notification from Sameh Test',
		'icon' 	=> 'img/icon.png',
		'image' => 'img/d.png',	
	];
	 $notification = [
            'title' => 'Just test',
			'body' 	=> 'Open my web site just test',
			"click_action"=>"https://www.alwessam.bdr14.com"
			];
	$fields = array (
		"registration_ids" =>$registrationIds,
		'notification'     => $notification,
		'data'             => $msg,
		 'vibrate'=>'1',
		'sound'=>'default',
	);
	$fields = json_encode ( $fields );

$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_SSL_VERIFYPEER, false );
        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );
        $result = curl_exec ( $ch );
        curl_close ( $ch );
        echo $result;
 ?>