.*? |',$data,$result); $result=$result[0]; if (count($result)>0) { date_default_timezone_set("GMT"); $date1=date("Y-m-d H:i:s", time()); date_default_timezone_set("Europe/Rome"); $date2=date("Y-m-d H:i:s", time()); $hourdiff = round((strtotime($date2) - strtotime($date1))/3600, 1); $delta='+'.$hourdiff.' hour'; for ($i=0;$i"); $result[$i]=substr($result[$i],$idx+20,strlen($result[$i])); } preg_match_all('|.*?|',$result[$i],$result2); $result2=$result2[0]; $code=substr($result2[0],4,strlen($result2[0])-9); $date=substr($result2[1],4,strlen($result2[1])-9); $date=substr($date,6,4).'-'.substr($date,3,2).'-'.substr($date,0,2); $time=substr($result2[2],4,strlen($result2[2])-9); preg_match_all('|=5.5){ if ($magnitude>=5.5 and $magnitude<6.0) { $max_distance=40; } else{ if ($magnitude>=6.0 and $magnitude<6.5){ $max_distance=100; } else{ if ($magnitude>=6.5 and $magnitude<7.0){ $max_distance=200; } else{ if ($magnitude>=7.0 and $magnitude<7.5){ $max_distance=500; } else{ if ($magnitude>=7.5 and $magnitude<8.0){ $max_distance=800; } else{ if ($magnitude>=8.0 and $magnitude<8.5){ $max_distance=1000; } else{ if ($magnitude>=8.5 and $magnitude<9.0){ $max_distance=2000; } else{ if ($magnitude>=9.0){ $max_distance=3000; } } } } } } } } $max_distance_deg=$max_distance/111; $sql=mysql_query("select count(*) as count from manual_picture where abs(latitude-$lat)<$max_distance_deg and abs(longitude-$lon)<$max_distance_deg and abs(TIMESTAMPDIFF(MINUTE,date,'$stamp'))<1440"); if (mysql_num_rows($sql)){ $picture_count=mysql_result($sql,0,"count"); } else{ $picture_count=0; } } else{ $picture_count=0; } if ($ok==1){ $sql=mysql_query("insert into automatic_ign_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,weather_code,temperature,humidity,pressure,wind_speed,wind_dir,clouds,icon,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'IGN',$weather_code,$temperature,$humidity,$pressure,$wind_speed,$wind_dir,$clouds,'$icon',$picture_count)"); } else{ $sql=mysql_query("insert into automatic_ign_temp (latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,place,data,code,tsunami,provider,picture_count) values ($lat,$lon,$depth,$magnitude,'$magnitude_type',$pop25,$pop100,$pop200,'$place','$stamp','$code',$tsunami,'IGN',$picture_count)"); } } } //empty the table $sql=mysql_query("TRUNCATE automatic_ign"); $sql=mysql_query("INSERT INTO automatic_ign SELECT * FROM automatic_ign_temp"); $sql=mysql_query("DELETE from automatic_all WHERE provider like 'IGN'"); $sql=mysql_query("INSERT INTO automatic_all (latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count) SELECT latitude, longitude, depth, magnitude, magnitude_type, felt, cdi, pop25, pop100, pop200, data, code, place, tsunami, url, provider, weather_code, temperature, humidity, pressure, wind_speed, wind_dir, clouds, icon, picture_count FROM automatic_ign_temp"); //generate the file $filename="seismic_free.txt"; $sql=mysql_query('SET CHARACTER SET utf8'); $sql=mysql_query("SELECT latitude,longitude,depth,magnitude,magnitude_type,pop25,pop100,pop200,cdi AS intensity,place,tsunami,url,provider,data,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference FROM (select * from automatic_all) as a WHERE a.data > date_sub(NOW(), interval 1440 minute) AND a.magnitude>=2 ORDER BY a.data DESC"); if (mysql_num_rows($sql)){ while($e=mysql_fetch_assoc($sql)) $output_file[]=$e; $json_file = json_encode($output_file); file_put_contents($filename,$json_file); } //extract the new earthquakes $sql=mysql_query("select latitude,longitude,magnitude,magnitude_type,place,provider,depth,data,pop100,TIMESTAMPDIFF(MINUTE,data,NOW()) AS difference from automatic_ign_temp where TIMESTAMPDIFF(MINUTE,'$max_date',data)>1 and TIMESTAMPDIFF(MINUTE,data,NOW())<120 order by TIMESTAMPDIFF(MINUTE,data,NOW()) desc"); if (mysql_num_rows($sql)) { $num_rows = mysql_num_rows($sql); for ($j = 0; $j < $num_rows; $j++) { $delay=mysql_result($sql,$j,"difference"); $sql_z=mysql_query("INSERT INTO delay_ign (delay) values ($delay)"); $dataArray = array('latitude'=>mysql_result($sql,$j,"latitude"), 'longitude'=>mysql_result($sql,$j,"longitude"), 'magnitude'=>mysql_result($sql,$j,"magnitude"), 'magnitude_type'=>mysql_result($sql,$j,"magnitude_type"), 'place'=>mysql_result($sql,$j,"place"), 'provider'=>mysql_result($sql,$j,"provider"), 'depth'=>mysql_result($sql,$j,"depth"), 'data'=>mysql_result($sql,$j,"data"), 'difference'=>mysql_result($sql,$j,"difference"), 'pop100'=>mysql_result($sql,$j,"pop100"), 'type'=>'official'); //extract users for notifications $magnitude_notification=mysql_result($sql,$j,"magnitude"); $current_date=mysql_result($sql,$j,"data"); $sql2=mysql_query("select user_id from gcm order by user_id limit 1"); $user_id_ref = mysql_result($sql2, 0, "user_id"); $user_id_ref=$user_id_ref-1; $row_limit=250000; $keep_going=1; while ($keep_going){ $sql2=mysql_query("SELECT user_id,reg_id FROM gcm where gcm.reg_id<>'' and gcm.notification_official_ign=1 and ($magnitude_notification>=gcm.notification_official_minmag or gcm.notification_near=1) and gcm.notification_official=1 and user_id>$user_id_ref order by user_id limit $row_limit"); $num_rows2 = mysql_num_rows($sql2); if ($num_rows2>0){ while($data = mysql_fetch_assoc($sql2)){ $regidArray[] = $data['reg_id']; $IDArray[] = $data['user_id']; } $user_id_ref=end($IDArray); $block_size=999; $iter=ceil($num_rows2/$block_size); $folder_eqn=uniqid(); mkdir($folder_eqn); $filename_data=$folder_eqn."/dataarray.json"; file_put_contents($filename_data,json_encode($dataArray)); for ($i=0; $i<$iter; $i++){ $index_start=$i*$block_size; $index_end=($i+1)*$block_size-1; if ($index_end>$num_rows2-1){ $index_end=$num_rows2-1; } $regidArrayGCM = array_slice($regidArray,$index_start,$index_end-$index_start+1); $filename=$folder_eqn."/gcmid".$i.".json"; file_put_contents($filename,json_encode($regidArrayGCM)); exec("php /var/www/earthquakenetwork.it/mysql/distquake_gcm_official_call.php $filename_data $filename"."> /dev/null 2>/dev/null &"); sleep(0.1); } sleep(1); $files = glob($folder_eqn.'/*',GLOB_MARK); foreach ($files as $file) { unlink($file); } rmdir($folder_eqn.'/'); unset($regidArray); unset($IDArray); } else{ $keep_going=0; } } $sql_z=mysql_query("select date FROM last_notifications where provider='IGN'"); $last_date=mysql_result($sql_z,0,"date"); if ($current_date>$last_date){ $sql_z=mysql_query("update last_notifications set date='$current_date' where provider='IGN'"); } } $sql_z=mysql_query("select max(ID) as max_id FROM delay_ign"); $max_id=mysql_result($sql_z,0,"max_id"); $sql_z=mysql_query("delete from delay_ign where ID<$max_id-40"); } mysql_close(); ?>