71 lines
1.7 KiB
PHP
71 lines
1.7 KiB
PHP
<?php
|
|
$ini = parse_ini_file("conf.ini", true);
|
|
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
|
|
mysql_select_db($ini['db']['db']);
|
|
|
|
$user_id=$_REQUEST['u_id'];
|
|
$radius=$_REQUEST['radius'];
|
|
$lat=$_REQUEST['lat'];
|
|
$lon=$_REQUEST['lon'];
|
|
|
|
if ($radius>150){
|
|
$distance=150;
|
|
}
|
|
else{
|
|
$distance=$radius*0.8;
|
|
}
|
|
|
|
$distance_deg=$distance*0.009;
|
|
|
|
$datetime = date('Y-m-d H:i:s');
|
|
$a=$lat+$distance_deg;
|
|
$b=$lon;
|
|
$c=$lat+$distance_deg;
|
|
$d=$lon;
|
|
$dataArray = array('latitude'=>number_format((float)$a, 2, '.', ''),
|
|
'longitude'=>number_format((float)$b, 2, '.', ''),
|
|
'detection_latitude'=>number_format((float)$c, 2, '.', ''),
|
|
'detection_longitude'=>number_format((float)$d, 2, '.', ''),
|
|
'wave_speed'=>8,
|
|
'counter'=>1,
|
|
'intensity'=>2,
|
|
'datetime'=>$datetime,
|
|
'type'=>'eqn');
|
|
|
|
//extract users for notifications
|
|
$sql2=mysql_query("select reg_id from gcm where user_id=$user_id"); //1323571444
|
|
$counter=0;
|
|
$num_rows2 = mysql_num_rows($sql2);
|
|
if ($num_rows2>0){
|
|
for ($i = 0; $i < $num_rows2; $i++)
|
|
{
|
|
$regidArray[$counter]=mysql_result($sql2,$i,"reg_id");
|
|
$counter=$counter+1;
|
|
if ($counter==999 or $i==($num_rows2-1))
|
|
{
|
|
$headers = array(
|
|
'Authorization: key=AIzaSyAYaXDEapyd-mF9V9LNW1dmuoS-ea9GwWI',
|
|
'Content-Type: application/json');
|
|
$fields = array(
|
|
'registration_ids' => $regidArray,
|
|
'data' => $dataArray);
|
|
|
|
$context = stream_context_create(array(
|
|
'http' => array(
|
|
'method' => 'POST',
|
|
'header' => $headers,
|
|
'content' => json_encode($fields))));
|
|
$response = file_get_contents('https://android.googleapis.com/gcm/send', FALSE, $context);
|
|
$counter=0;
|
|
$regidArray=array();
|
|
}
|
|
}
|
|
print("ok");
|
|
}
|
|
else{
|
|
print("notregistered");
|
|
}
|
|
|
|
mysql_close();
|
|
?>
|