$j = 1; echo "<table border=1 class='stripeMe'>"; echo "<tr ><td>#</td><td>Takeoff ID</td><td>Country</td><td># of flights</td><td>Takeoff name</td><td>Int name</td><td>lat</td><td>lon</td><td>Distance in m</td><td>Select</td><td>Metric 1</td><td>Metric 2</td></tr>\n"; $query2 = "SELECT {$waypointsTable}.*, count({$flightsTable}.ID) as flightsNum FROM {$waypointsTable} LEFT JOIN {$flightsTable} ON ( {$flightsTable}.takeoffID={$waypointsTable}.ID ) \n\t\t\t\tWHERE {$groupStr}='" . $row['nameSoundex'] . "' {$countryCodeWhere}\n\t\t\t\tgroup by {$waypointsTable}.ID\n\t\t\t\torder by lat , lon "; $lastLat = 0; $lastLon = 0; $lastName = ''; $res2 = $db->sql_query($query2); if ($res2 == 0) { echo "Error in query : {$query2}<BR>"; return; } while ($row2 = mysql_fetch_assoc($res2)) { // compute distance from previous if ($lastLat && $lastLon) { $distanceFromPrevious = gpsPoint::calc_distance($lastLat, $lastLon, $row2['lat'], $row2['lon']); } else { $distanceFromPrevious = 0; } $lastLat = $row2['lat']; $lastLon = $row2['lon']; if ($lastName) { $nameDistanceFromPrevious1 = levenshtein(strtolower($lastIntName), strtolower($row2['intName'])); similar_text(strtolower($lastIntName), strtolower($row2['intName']), &$nameDistanceFromPrevious2); } else { $nameDistanceFromPrevious1 = 0; $nameDistanceFromPrevious2 = 0; } $lastName = $row2['name']; $lastIntName = $row2['intName']; if ($j == 1) {
function getTZ($lat, $lon, $theDate) { global $db, $waypointsTable; global $CONF_use_date_for_TZ_detection; // fall back to simple lon method in case of old php (4.4.1) if (!$CONF_use_date_for_TZ_detection) { return getUTMtimeOffset($lat, $lon, $theDate); } $query = "SELECT lat,lon,ABS({$lat}-lat) as dlat , ABS({$lon}- lon ) as dlon ,countryCode from {$waypointsTable} \n\t\t\t\tWHERE ABS({$lat}-lat) < 1 AND ABS({$lon}- lon ) < 1\n\t\t\t\tORDER BY dlat,dlon ASC"; DEBUG('getTZ', 128, "getTZ: {$query}<BR>"); $res = $db->sql_query($query); if ($res <= 0) { DEBUG('getTZ', 128, "getTZ: no waypont near by will try rough method<BR>"); return getUTMtimeOffset($lat, $lon, $theDate); } $i = 0; $minTakeoffDistance = 1000000; while ($row = mysql_fetch_assoc($res)) { $i++; $this_distance = gpsPoint::calc_distance($row["lat"], $row["lon"], $lat, $lon); DEBUG('getTZ', 128, "getTZ: " . $row["lat"] . " , " . $row["lon"] . " country-> " . $row["countryCode"] . " distance-> {$this_distance} <BR>"); if ($this_distance < $minTakeoffDistance) { $minTakeoffDistance = $this_distance; $countryCode = $row["countryCode"]; } } if (!$i) { DEBUG('getTZ', 128, "getTZ: No waypont near by #2. Will try rough method<BR>"); return getUTMtimeOffset($lat, $lon, $theDate); } DEBUG('getTZ', 128, "getTZ: Min dist: {$minTakeoffDistance} , country: {$countryCode} <BR>"); if ($minTakeoffDistance > 50000) { DEBUG('getTZ', 128, "getTZ: Nearest waypoint is too far. Will try rough method<BR>"); return getUTMtimeOffset($lat, $lon, $theDate); } // now we will try the getTZoffset() // make $tm from YYYY-MM-DD $tm = gmmktime(1, 0, 0, substr($theDate, 5, 2), substr($theDate, 8, 2), substr($theDate, 0, 4)); // this will return good results only for countries that have ONE timezone // else '' will be returned require_once dirname(__FILE__) . '/FN_timezones.php'; // $TZone=getTZforCountry($countryCode); global $Countries2timeZones; $TZone = $Countries2timeZones[strtoupper($countryCode)]; if (strtoupper($countryCode) == 'AU') { DEBUG('getTZ', 128, "getTZ: Australia timezones<BR>"); /* australia http://www.statoids.com/tau.html central - west is on 129E central - east is on lon > 141E for lat < -26 (S) lon > 138E for lat > -26 (S) east - > Australia/Sydney west central */ if ($lon > -129) { $TZone = 'Australia/Perth'; } else { if ($lon > -138 && $lat > -26) { $TZone = 'Australia/Darwin'; } else { if ($lon > -141 && $lat < -26) { $TZone = 'Australia/Adelaide'; } else { if ($lat > -29) { $TZone = 'Australia/Brisbane'; } else { $TZone = 'Australia/Sydney'; } } } } // South-East } if ($TZone == '') { DEBUG('getTZ', 128, "getTZ: Country {$countryCode} has more than one timezones.. Back to rough method<BR>"); return getUTMtimeOffset($lat, $lon, $theDate); } return getTZoffset($TZone, $tm) / 3600; }