function send_gcm_notify($Ticker, $message) {
global $db, $file_handle;
$url = 'https://android.googleapis.com/gcm/send';
$dbname = "xxxx"; $dbuser = "xxxx"; $dbpass = "xxxx"; $dbhost = "xxxxx";
$db2=new Database($dbhost,$dbname,$dbuser,$dbpass);
$regIDs = array();
$sql = "SELECT * FROM c2dm WHERE name<>'' AND notification=1;";
$queue = $db->getRows($sql);
if (sizeof($queue) > 0){
foreach($queue AS $q){
$regIDs[] = $q["id"];
}
}
$queue = $db->getRow($sql);
$fields = array(
'registration_ids' => $regIDs,
'data' => array( "message" => $message, 'tickerText' => $Ticker, 'contentTitle' => "Title", "contentText" => "ContentText" ),
);
$headers = array(
'Authorization: key=' . "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
'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_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
fwrite($file_handle, date("d.m.Y H:i:s", time()).": Curl-Result: ".$result."\r\n");
if ($result === FALSE) {
fwrite($file_handle, date("d.m.Y H:i:s", time()).": Error: ".curl_error($ch)."\r\n");
//die('Problem occurred: ' . curl_error($ch));
}
curl_close($ch);
}