function CheckLocation($db, $aps, $tid = '') { require 'geoext.php'; /* Модуль получения координат */ $query_bssid = "SELECT `BSSID` FROM `free` WHERE `latitude`='none' AND `BSSID` LIKE '__:__:__:__:__:__'"; $query_update = "UPDATE `free` SET `latitude`=?,`longitude`=? WHERE `BSSID`=?"; $stmt_upd = $db->prepare($query_update); $not_found = "not found"; $i = 0; // TODO: Лучше переделать в отдельные запросы по BSSID if (count($aps) > 0 && ($res_bssid = $db->query($query_bssid))) { set_time_limit(0); ignore_user_abort(true); $hangcheck = 5; $time = microtime(true); while ($row = $res_bssid->fetch_row()) { $bssid = $row[0]; if (!in_array($bssid, $aps)) { continue; } $coords = GeoLocateAP($bssid); if ($coords != '') { $coords = explode(';', $coords); $latitude = $coords[0]; $longitude = $coords[1]; if (strlen($latitude) > 11) { $latitude = substr($latitude, 0, 11); } if (strlen($longitude) > 11) { $longitude = substr($longitude, 0, 11); } $stmt_upd->bind_param("sss", $latitude, $longitude, $bssid); $stmt_upd->execute(); $i++; } else { $stmt_upd->bind_param("sss", $not_found, $not_found, $bssid); $stmt_upd->execute(); } if ($tid != '' && microtime(true) - $time > $hangcheck) { $db->query("UPDATE `tasks` SET `onmap`='{$i}' WHERE `tid`='{$tid}'"); $time = microtime(true); } } $res_bssid->close(); } $stmt_upd->close(); return $i; }
$res = QuerySql('SELECT `BSSID` FROM GEO_TABLE WHERE `latitude` IS NULL'); $total = $res->num_rows; if ($total == 0) { logt('No new BSSIDs was fetched.'); } else { $done = 0; $found = 0; $hangcheck = 5; $time = microtime(true); while ($row = $res->fetch_row()) { $done++; $bssid = $row[0]; $latitude = 0; $longitude = 0; $quadkey = 'NULL'; $coords = GeoLocateAP(dec2mac($bssid)); if ($coords != '') { $found++; $coords = explode(';', $coords); $latitude = (double) $coords[0]; $longitude = (double) $coords[1]; $quadkey = base_convert(latlon_to_quadkey($latitude, $longitude, MAX_ZOOM_LEVEL), 2, 10); } QuerySql("UPDATE GEO_TABLE SET `latitude`={$latitude},`longitude`={$longitude}, `quadkey`={$quadkey} WHERE `BSSID`={$bssid}"); if (microtime(true) - $time > $hangcheck && $done < $total) { logt("Status: {$done} of {$total}, {$found} found on map (Working)"); $time = microtime(true); } } logt("Status: {$done} of {$total}, {$found} found on map (Done!)"); }
require 'con_db.php'; /* Коннектор MySQL */ require 'geoext.php'; /* Модуль получения координат */ if (!db_connect()) { die('Database connection error'); } $query_bssid = "SELECT DISTINCT `BSSID` FROM `free` WHERE `BSSID` LIKE '__:__:__:__:__:__' AND `latitude` = 'not found' LIMIY"; $query_update = "UPDATE `free` SET `latitude`=?,`longitude`=? WHERE `BSSID`=?"; $stmt_upd = $db->prepare($query_update); $not_found = "not found"; $i = 0; if ($res_bssid = $db->query($query_bssid)) { while ($row = $res_bssid->fetch_row()) { $bssid = $row[0]; $coords = GeoLocateAP($bssid); if ($coords != '') { $coords = explode(';', $coords); $latitude = $coords[0]; $longitude = $coords[1]; if (strlen($latitude) > 11) { $latitude = substr($latitude, 0, 11); } if (strlen($longitude) > 11) { $longitude = substr($longitude, 0, 11); } $stmt_upd->bind_param("sss", $latitude, $longitude, $bssid); $stmt_upd->execute(); $i++; } else { $stmt_upd->bind_param("sss", $not_found, $not_found, $bssid);