function findTakeoff($args) { $sitePass = $args[0]; $lat = $args[1]; $lon = $args[2]; if (!securityCheck($sitePass)) { return new IXR_Error(4000, 'Access Denied'); } $firstPoint = new gpsPoint(); $firstPoint->lat = $lat; $firstPoint->lon = $lon; // calc TAKEOFF - LANDING PLACES if (count($waypoints) == 0) { $waypoints = getWaypoints(); } $takeoffIDTmp = 0; $minTakeoffDistance = 10000000; $i = 0; foreach ($waypoints as $waypoint) { $takeoff_distance = $firstPoint->calcDistance($waypoint); if ($takeoff_distance < $minTakeoffDistance) { $minTakeoffDistance = $takeoff_distance; $takeoffIDTmp = $waypoint->waypointID; } $i++; } $nearestWaypoint = new waypoint($takeoffIDTmp); $nearestWaypoint->getFromDB(); // echo "&^".$nearestWaypoint->name."&"; return array($nearestWaypoint, $minTakeoffDistance); }
//print_r($row); //echo "<HR>"; //$resWaypoint=new waypoint($row["ID"]); //$resWaypoint->getFromDB(); //echo $resWaypoint->exportXML('XML'); $i++; } $res .= ' ] }'; echo $res; mysql_freeResult($dbres); // echo "</search>"; } else { if ($op == "find_wpt") { $lat = $_GET['lat'] + 0; $lon = $_GET['lon'] + 0; $firstPoint = new gpsPoint(); $firstPoint->lat = $lat; $firstPoint->lon = $lon; // calc TAKEOFF - LANDING PLACES if (count($waypoints) == 0) { $waypoints = getWaypoints(); } $takeoffIDTmp = 0; $minTakeoffDistance = 10000000; $i = 0; foreach ($waypoints as $waypoint) { $takeoff_distance = $firstPoint->calcDistance($waypoint); if ($takeoff_distance < $minTakeoffDistance) { $minTakeoffDistance = $takeoff_distance; $takeoffIDTmp = $waypoint->waypointID; }
document.getElementById('addTakeoffFrame').src='<?php echo $moduleRelPath; ?> /GUI_EXT_user_waypoint_add.php?refresh=0&lat='+lat+'&lon='+lon+'&takeoffID='+id; MWJ_changeSize('addTakeoffFrame',720,345); MWJ_changeSize( 'takeoffAddID', 725,365 ); toggleVisible('takeoffAddID','takeoffAddPos',-10,-50,725,435); } </script> <?php // $firstPoint=new gpsPoint($flight->FIRST_POINT,$flight->timezone); $firstPoint = new gpsPoint('', $flight->timezone); $firstPoint->setLat($flight->firstLat); $firstPoint->setLon($flight->firstLon); $firstPoint->gpsTime = $flight->firstPointTM; $takeoffLink = "<div align='center' id='attentionLinkPos' class='attentionLink box'><img src='{$moduleRelPath}/img/icon_att3.gif' border=0 align=absmiddle> \nThe takeoff/launch of your flight is not registered in Leonardo. <img src='{$moduleRelPath}/img/icon_att3.gif' border=0 align=absmiddle><br>\nThis is nothing to worry about, but you can easily provide this info <br>by clicking on the 'Register Takeoff' link below.\n<br> If you are not sure about some of the information is OK to skip this step. <br><BR> <a\n\t\t\t\t href=\"javascript:user_add_takeoff(" . $firstPoint->lat . "," . $firstPoint->lon . "," . $flight->takeoffID . ")\">Register Takeoff</a><div id='takeoffAddPos'></div></div>"; echo $takeoffLink; } //New 18.08.2013 P.Wild - Airspace warning before flight_show $flight->checkAirspace(1); if (strpos($flight->airspaceCheckMsg, "HorDist")) { // problem $checkLines = explode("\n", $flight->airspaceCheckMsg); //if (strrchr($flight->airspaceCheckMsg,"Punkte")){ // $adminPanel.="<br><strong>Deutschland Pokal</strong><BR>"; if (strpos($flight->airspaceCheckMsg, "HorDist")) { $adminPanel .= "<br><strong>Airspace PROBLEM</strong><BR>";
function kml2igc($filename) { $l = file($filename); for ($i = 0; $i < count($l); $i++) { $l[$i] = trim($l[$i]); } $lines = implode(" ", $l); //echo $lines; //exit; if (!preg_match("/<SecondsFromTimeOfFirstPoint>(.*)<\\/SecondsFromTimeOfFirstPoint>/", $lines, $matches)) { return 0; } // echo "match<BR>"; // echo $matches[1]; $tm = explode(" ", trim($matches[1])); // echo count($tm).'<br>'; // now search for this // <FsInfo time_of_first_point="2007-04-05T09:51:50Z" // hash="2E361EB937B9D7D6C92855F38D37B399B17292AD"> // if( ! preg_match("/<FsInfo *time_of_first_point=\"([^\"]+)\" *hash=\"(.*)\">/i",$lines,$matches) ) { // return 0; // } /* this is the new format from kml <FsInfo time_of_first_point="2007-04-22T13:42:06Z" civl_pilot_id="4" comp_pilot_id="4" instrument="GPS 72 Software Version 2.30" downloaded="2007-04-29T12:39:49Z" hash="80F1FAC5CFFE4B97E202371EF6303BFCF83A6D78"> I'm a zero at the left in regular expressions, then i change a litle to this one... */ if (!preg_match("/<FsInfo.*time_of_first_point=\"([^\"]+)\".*hash=\"([^\"]+)\">/i", $lines, $matches)) { return 0; } //echo "match start time<BR>"; // echo $matches[1]; $start_time_str = trim($matches[1]); $hash_str = trim($matches[2]); // echo "$start_time_str # $hash_str<BR>"; // now search for this /* <name>Tracklog</name> <LineString> <altitudeMode>absolute</altitudeMode> <coordinates> */ if (!preg_match("/<name>Tracklog<\\/name> *<LineString> *<altitudeMode>absolute<\\/altitudeMode> *<coordinates>(.*)<\\/coordinates>/", $lines, $matches)) { return 0; } //echo "match coordinates<BR>"; // echo $matches[1]; $coords = explode(" ", trim($matches[1])); //echo count($coords); // print_r($coords); require_once dirname(__FILE__) . '/CL_gpsPoint.php'; // now make the igc file for ($i = 0; $i < count($coords); $i++) { if ($i == 0) { // igc date-> ddmmyy // 01234567890123456789 // kml date -> "2007-04-05T09:51:50Z" $dateStr = substr($start_time_str, 8, 2) . substr($start_time_str, 5, 2) . substr($start_time_str, 2, 2); // echo substr($start_time_str,11,2)." ".substr($start_time_str,14,2)." ".substr($start_time_str,17,2); $startTimeSecs = substr($start_time_str, 11, 2) * 3600 + substr($start_time_str, 14, 2) * 60 + substr($start_time_str, 17, 2); $igc .= "HFDTE{$dateStr}\r\n" . "HFSITSite:\r\n" . "HPGTYGliderType:\r\n" . "HPGIDGliderID:\r\n" . "HFDTM100DATUM:WGS-1984\r\n" . "HFCIDCOMPETITIONID:\r\n" . "HFCCLCOMPETITIONCLASS:\r\n" . "HFFXA100\r\n" . "HFRHWHARDWAREVERSION:1.00\r\n" . "HFFTYFRTYPE:Convert from GPSDump KML\r\n"; } // echo $coords[$i].'<BR>'; $thisPoint = new gpsPoint(); list($lon, $lat, $alt) = explode(",", $coords[$i]); $thisPoint->lat = $lat + 0; $thisPoint->lon = -$lon + 0; $thisPoint->gpsAlt = $alt + 0; $thisPoint->gpsTime = ($startTimeSecs + $tm[$i]) % (3600 * 24); $igc .= $thisPoint->to_IGC_Record() . "\r\n"; } //echo $igc; // write the igc to disk // $igcfilename=substr($filename,0,-3).'igc'; // overwrite the original $igcfilename = $filename; if (!($handle = fopen($igcfilename, 'w'))) { print "Cannot open file ({$igcfilename})"; return 0; } // Write $somecontent to our opened file. if (!fwrite($handle, $igc)) { print "Cannot write to file ({$igcfilename})"; return 0; } fclose($handle); return 1; }
function checkAirspace($filename) { $lines = file($filename); if (!$lines) { echo "Cant read file"; return; } $i = 0; // find bounding box of flight $min_lat = 1000; $max_lat = -1000; $min_lon = 1000; $max_lon = -1000; foreach ($lines as $line) { $line = trim($line); if (strlen($line) == 0) { continue; } if ($line[0] == 'B') { if (strlen($line) < 23) { continue; } $thisPoint = new gpsPoint($line, 0); if ($thisPoint->lat > $max_lat) { $max_lat = $thisPoint->lat; } if ($thisPoint->lat < $min_lat) { $min_lat = $thisPoint->lat; } if (-$thisPoint->lon > $max_lon) { $max_lon = -$thisPoint->lon; } if (-$thisPoint->lon < $min_lon) { $min_lon = -$thisPoint->lon; } } } // echo "$min_lat, $max_lat,$min_lon, $max_lon<BR>"; // now find the bounding boxes that have common points // !( A1<X0 || A0>X1 ) && !( B1<Y0 || B0>Y1 ) // X,A -> lon // Y,B -> lat // X0 -> $min_lon A0-> $area->minx // X1 -> $max_lon A1-> $area->maxx // Y0 -> $min_lat B0-> $area->miny // Y1 -> $max_lat B1-> $area->maxy // !( $area->maxx<$min_lon || $area->minx>$max_lon ) && !( $area->maxx<$min_lat || $area->miny>$max_lat ) global $AirspaceArea, $NumberOfAirspaceAreas; getAirspaceFromDB($min_lon, $max_lon, $min_lat, $max_lat); $NumberOfAirspaceAreas = count($AirspaceArea); /* foreach($AirspaceArea as $i=>$area) { if ( !( $area->maxx<$min_lon || $area->minx>$max_lon ) && !( $area->maxy<$min_lat || $area->miny>$max_lat ) ) { if ($area->Shape==1) $shape="Area "; else $shape="Circle"; DEBUG("checkAirspace",1, "Found $shape [$i] => ".$area->Name.'<BR>'); // print_r($area); if ($area->Shape==1) { $area->Points[]=$area->Points[0]; // $area->NumPoints=count($area->Points); } $selAirspaceArea[]=$area; } } $AirspaceArea=$selAirspaceArea; $NumberOfAirspaceAreas=count($AirspaceArea); */ // echo '<HR>'; // print_r($AirspaceArea); // echo '<HR>'; // echo '<HR>'; $violations = array(); $i = 0; foreach ($lines as $line) { $line = trim($line); if (strlen($line) == 0) { continue; } if ($line[0] == 'B') { if (strlen($line) < 23) { continue; } $thisPoint = new gpsPoint($line, 0); $alt = $thisPoint->getAlt(1); // prefer vario alt // $insideArea=-1; $insideAreas = array(); $insideAreas = FindAirspaceArea(-$thisPoint->lon, $thisPoint->lat, $alt); if (count($insideAreas) > 0) { //echo "point [$i] INSIDE AIRSPACE areas: "; //foreach($insideAreas as $areaInfo) echo $AirspaceArea[$areaInfo[0]]->Name." areaID[$areaInfo[0]] disInside[$areaInfo[1]] altInside[$areaInfo[2]] "; foreach ($insideAreas as $areaInfo) { $areaID = $areaInfo[0]; $disInside = $areaInfo[1]; $altInside = $areaInfo[2]; if ($disInside > $violations[$areaID]['maxDistance']) { $violations[$areaID]['maxDistance'] = $disInside; } if ($altInside > $violations[$areaID]['maxAlt']) { $violations[$areaID]['maxAlt'] = $altInside; } } //echo "<BR>"; } else { // echo "OK<BR>"; } $i++; } } $resStr = ''; $resStr1 = ''; if (count($violations) > 0) { foreach ($violations as $i => $violatedArea) { $resStr1 .= $AirspaceArea[$i]->id . ","; $resStr .= "HorDist: " . floor($violatedArea['maxDistance']) . "m, VertDist:" . floor($violatedArea['maxAlt']) . "m, "; $resStr .= 'Airspace: ' . $AirspaceArea[$i]->Name . ' [' . $AirspaceArea[$i]->Type . '] ' . floor($AirspaceArea[$i]->Base->Altitude) . '-' . floor($AirspaceArea[$i]->Top->Altitude) . "m\n"; // COMMENT: '.$AirspaceArea[$i]->Comment."\n"; } if ($resStr1) { $resStr1 = substr($resStr1, 0, -1) . "\n"; $resStr = trim($resStr); } } //$m1=memory_get_usage(); //echo "ReadAltitude: mem usage: $m1 <BR>"; return $resStr1 . $resStr; }
function processEntry($serverID, $e, $sync_mode = SYNC_INSERT_FLIGHT_LINK) { global $CONF; global $DBGcat, $DBGlvl; if ($DBGlvl > 0) { echo "<PRE>"; print_r($e); echo "</PRE>"; } if (is_array($e['ActionXML'])) { $actionData =& $e['ActionXML']; } else { if (is_array($e['actionData'])) { $actionData =& $e['actionData']; } else { if (is_array($e['flight'])) { $actionData =& $e; } else { return array(0, "logReplicator::processEntry : actionData section not found"); } } } // if this log entry is not for a flight of the specific server // then check if we are allowesd to accpet these flights from this server if (isset($actionData['flight']['serverID'])) { $thisEntryServerID = $actionData['flight']['serverID']; } else { if (isset($e['serverID'])) { $thisEntryServerID = $e['serverID']; } else { return array(0, "logReplicator::processEntry : ServerID for Log entry could not be determined "); } } if ($thisEntryServerID != $serverID) { $wrongServer = 1; if (is_array($CONF['servers']['list'][$serverID]['accept_also_servers'])) { if (in_array($thisEntryServerID, $CONF['servers']['list'][$serverID]['accept_also_servers'])) { $wrongServer = 0; } } if ($wrongServer) { return array(0, "logReplicator::processEntry : We dont accept flights originally from server " . $thisEntryServerID); } } if ($e['type'] == '1') { // flight if ($e['action'] == 4) { // delete $flightIDlocal = logReplicator::findFlight($actionData['flight']['serverID'], $actionData['flight']['id']); if (!$flightIDlocal) { return array(0, "logReplicator::processEntry : Flight with serverID " . $actionData['flight']['serverID'] . " and original ID : " . $actionData['flight']['id'] . " is not found in the local DB -> Wont delete it"); } // echo "Will delete flight $flightIDlocal<BR>"; $extFlight = new flight(); $extFlight->getFlightFromDB($flightIDlocal, 0); $extFlight->deleteFlight(); return array(1, "Flight with local ID: {$flightIDlocal} DELETED"); } if ($e['action'] == 16) { // rename tracklog $flightIDlocal = logReplicator::findFlight($e['serverID'], $e['id']); if (!$flightIDlocal) { return array(0, "logReplicator::processEntry : Flight with serverID " . $e['serverID'] . " and original ID : " . $e['id'] . " is not found in the local DB -> Wont rename tracklog<BR>"); } $extFlight = new flight(); $extFlight->getFlightFromDB($flightIDlocal, 0); $extFlight->renameTracklog($actionData['newFilename'], $actionData['oldFilename']); return array(1, "Flight tracklog renamed for local ID {$flightIDlocal}"); } if ($e['action'] == 8) { // scoring info $flightIDlocal = logReplicator::findFlight($e['serverID'], $e['id']); if (!$flightIDlocal) { return array(0, "logReplicator::processEntry : Flight with serverID " . $e['serverID'] . " and original ID : " . $e['id'] . " is not found in the local DB -> Wont update scoring<BR>"); } // echo "Will update scoring info for flight $flightIDlocal<BR>"; // no need to pull flight info //$extFlight=new flight(); //$extFlight->getFlightFromDB($flightIDlocal,0); require_once dirname(__FILE__) . '/CL_flightScore.php'; $flightScore = new flightScore($flightIDlocal); // we have the score array in $actionData['score'] $sArr =& $actionData['score']; $flightScore->fromSyncArray($sArr); //put also in scores table, the flight is sure to be present in flights table $flightScore->putToDB(1, 1); return array(1, "Flight Score was *pulled* for local ID {$flightIDlocal}"); } // now deal with add/update $getValidationData = 1; $getScoreData = 1; // check 'alien' pilot and insert him or update him anyway $userServerID = $actionData['flight']['serverID']; if ($userServerID == 0) { $userServerID = $serverID; } // echo "logReplicator::checkPilot"; list($effectiveServerID, $effectiveUserID) = logReplicator::checkPilot($userServerID, $actionData['flight']['pilot']); //echo "effectiveServerID: $effectiveServerID, effectiveUserID: $effectiveUserID // userServerID: $userServerID, userID: ".$actionData['flight']['pilot']['userID']."<BR>"; // check if a maping took place and LOG it!! if ($effectiveServerID != $userServerID || $effectiveUserID != $actionData['flight']['pilot']['userID']) { $orgUserIDstr = $userServerID + 0 . '_' . $actionData['flight']['pilot']['userID']; } else { $orgUserIDstr = ''; } // $userIDstr=$userServerID.'_'.$actionData['flight']['pilot']['userID']; $userIDstr = $effectiveServerID . '_' . $effectiveUserID; list($nearestTakeoffID, $nearestDistance) = logReplicator::checkLocation($userServerID, $actionData['flight']['location'], $actionData['flight']['bounds']); list($nearestLandingID, $nearestLandingDistance) = findNearestWaypoint($actionData['flight']['bounds']['lastLat'], $actionData['flight']['bounds']['lastLon']); // get only the first 2 bits $externalFlightType = $sync_mode & 0x3; $addFlightNote = ''; // if action ==update check to see if the flight exists ! if ($e['action'] == 2) { $flightIDlocal = logReplicator::findFlight($actionData['flight']['serverID'], $actionData['flight']['id']); if (!$flightIDlocal) { // we then INSERT IT instead echo " [Not found,will insert] "; $e['action'] = 1; } } else { if ($e['action'] == 1) { // if action == insert we make an extra check to see if the fligh is there, if yes we UPDATE instead $flightIDlocal = logReplicator::findFlight($actionData['flight']['serverID'], $actionData['flight']['id']); if ($flightIDlocal) { // we then UPDATE IT instead echo " [Already here,will update] "; $e['action'] = 2; } } } if ($e['action'] == 1) { // add $igcFilename = $actionData['flight']['filename']; $igcFileURL = $actionData['flight']['linkIGC']; $igcZipFileURL = $actionData['flight']['linkIGCzip']; $tempFilename = LEONARDO_ABS_PATH . '/' . $CONF['paths']['tmpigc'] . '/' . $igcFilename; $hash = $actionData['flight']['validation']['hash']; $sameHashIDarray = flight::findSameHash($hash); if (count($sameHashIDarray) > 0) { $isFlightDup = 0; $markFlightAsDisabled = 1; $msg = ''; if ($CONF['servers']['list'][$actionData['flight']['serverID']]['allow_duplicate_flights']) { foreach ($sameHashIDarray as $sameHashFlightInfo) { if ($sameHashFlightInfo['serverID'] == $actionData['flight']['serverID']) { // from same server $isFlightDup = 1; $msg .= " local flight: " . $sameHashFlightInfo['serverID'] . '_' . $sameHashFlightInfo['ID'] . " , new entry:" . $actionData['flight']['serverID'] . '_' . $actionData['flight']['id']; break; } else { // we have a flight with same hash that is not from this specific server. // HERE we must make the decision whether to mark this flight as DISABLED // WE always mark this new flight as DISABLED because : // the local flight takes precedence anyway. // ONE case // we are DHV mirror , the new flight is from DHV and there is a dup from XContest // we should insert, // SO INSERT TAKES PRECEDENCE OVER LINKED FLIGHTS } } } else { $isFlightDup = 1; } if ($isFlightDup) { return array(-1, "Flight already exists : {$msg}"); } } /* if ($CONF['servers']['list'][$actionData['flight']['serverID']]['allow_duplicate_flights']) { $sameHashIDarray=flight::findSameHash( $hash , $actionData['flight']['serverID'] ); if (count($sameHashIDarray)>0 ) { return array(-1,"Flight already exists in local with ID: $sameHashID (dups allowed)"); continue; } else { // $addFlightNote="*(Duplicate Flight)*"; } } else { $sameHashIDarray=flight::findSameHash( $hash ); if (count($sameHashIDarray)>0 ) { return array(-1,"Flight already exists in local with ID: $sameHashID"); continue; } } */ } else { if ($e['action'] == 2) { // update // This is not needed , we have found $flightIDlocal earlier and if it didnt exist we will insert it instead /* $flightIDlocal=logReplicator::findFlight($actionData['flight']['serverID'],$actionData['flight']['id']); if (!$flightIDlocal) { return array(0,"logReplicator::processEntry : Flight with serverID ".$actionData['flight']['serverID']." and original ID : ". $actionData['flight']['id']." is not found in the local DB -> Wont update<BR>"); } */ // echo "Will update flight $flightIDlocal<BR>"; } } $thisCat = $actionData['flight']['info']['cat'] + 0; // when we get data from leonardo servers, we just ignore these fields // since they can be computed on the fly $originalURL = htmlDecode($actionData['flight']['linkDisplay']); $originalKML = htmlDecode($actionData['flight']['linkGE']); if ($actionData['flight']['serverID'] != 0) { global $CONF; if ($CONF['servers']['list'][$actionData['flight']['serverID']]['isLeo'] == 1) { $originalURL = ''; $originalKML = ''; } } $argArray = array("private" => $actionData['flight']['info']['private'] + 0, "cat" => $actionData['flight']['info']['gliderCat'] + 0, "linkURL" => $actionData['flight']['info']['linkURL'], "comments" => $actionData['flight']['info']['comments'], "glider" => $actionData['flight']['info']['glider'], "gliderBrandID" => $actionData['flight']['info']['gliderBrandID'] + 0, "category" => $thisCat >= 0 ? $thisCat : 0, "dateAdded" => $actionData['flight']['dateAdded'], "originalURL" => $originalURL, "originalKML" => $originalKML, "original_ID" => $actionData['flight']['id'], "serverID" => $actionData['flight']['serverID'], "userServerID" => $actionData['flight']['serverID'], "originalUserID" => $orgUserIDstr, "externalFlightType" => $externalFlightType, "allowDuplicates" => $CONF['servers']['list'][$actionData['flight']['serverID']]['allow_duplicate_flights'] + 0); // print_r($argArray); if ($e['action'] == 1 && $sync_mode & SYNC_INSERT_FLIGHT_LOCAL & SYNC_INSERT_FLIGHT_REPROCESS_LOCALLY) { if (!($igcFileStr = fetchURL($igcFileURL, 20))) { return array(0, "logReplicator::processEntry() : Cannot Fetch {$igcFileURL}"); } writeFile($tempFilename, $igcFileStr); list($res, $flightID) = addFlightFromFile($tempFilename, 0, $userIDstr, $argArray); if ($res != 1) { return array(-128, "Problem: " . getAddFlightErrMsg($res, $flightID)); } return array(1, "Flight *pulled* OK with local ID {$flightID}"); } else { // if ( ( $e['action']==1 && $sync_mode & SYNC_INSERT_FLIGHT_LINK ) || $e['action']==2 ){ // inserting in LINK / LOCAL mode or updates - NOT reproccess if ($e['action'] == 1) { $extFlight = new flight(); // get igc if required if ($sync_mode & SYNC_INSERT_FLIGHT_LOCAL) { echo " Geting IGC file : "; if (!$e['tmpDir']) { $e['tmpDir'] = '/tmp'; } $igcFileTmp = $e['tmpDir'] . '/' . $actionData['flight']['id'] . '.igc'; if (!is_file($igcFileTmp)) { echo "igc file: {$igcFileURL}<BR>\n"; echo "tmpfile: {$igcFileTmp}<BR>\n"; echo "NOT in zip -> will fetch ..."; if (!($igcFileStr = fetchURL($igcFileURL, 20))) { return array(0, "logReplicator::processEntry() : Cannot Fetch {$igcFileURL}"); } writeFile($igcFileTmp, $igcFileStr); } else { echo "IN zip -> will use that ..."; } } } else { $extFlight = new flight(); $extFlight->getFlightFromDB($flightIDlocal, 0); } $igcFilename = $actionData['flight']['filename']; $igcFileURL = $actionData['flight']['linkIGC']; if ($CONF['servers']['list'][$actionData['flight']['serverID']]['exclude_from_list']) { $extFlight->excludeFrom |= 3; } if ($CONF['servers']['list'][$actionData['flight']['serverID']]['exclude_from_league']) { $extFlight->excludeFrom |= 2; } foreach ($argArray as $fieldName => $fieldValue) { // if the flight is already present // we must tkae care to honor ONLY // the 1st bit of 'private' , the others are used locally !! if ($fieldName == 'private') { if ($fieldValue & 0x1) { $fieldValue = $extFlight->private | 0x1; } else { if ($fieldValue & 0x4) { // visible to friends $fieldValue = $extFlight->private | 0x4; } else { $fieldValue = $extFlight->private & 0xfa; } } } $extFlight->{$fieldName} = $fieldValue; } // echo " gliderBrandID : $extFlight->gliderBrandID #<BR>"; $extFlight->takeoffID = $nearestTakeoffID; $extFlight->takeoffVinicity = $nearestDistance; $extFlight->landingID = $nearestLandingID; $extFlight->landingVinicity = $nearestLandingDistance; // no userid will be assgined to this flight since it will not be inserted locally // so userID= userServerID; // $extFlight->userID=$extFlight->originalUserID; // now we take care of mapping between users $extFlight->userID = $effectiveUserID; $extFlight->userServerID = $effectiveServerID; $extFlight->dateAdded = $actionData['flight']['dateAdded']; $extFlight->DATE = $actionData['flight']['time']['date']; $extFlight->timezone = $actionData['flight']['time']['Timezone'] + 0; $extFlight->START_TIME = $actionData['flight']['time']['StartTime'] + 0; $extFlight->DURATION = $actionData['flight']['time']['Duration'] + 0; $extFlight->END_TIME = $extFlight->START_TIME + $extFlight->DURATION; $extFlight->forceBounds = $actionData['flight']['bounds']['forceBounds'] + 0; $extFlight->firstLon = $actionData['flight']['bounds']['firstLon'] + 0; $extFlight->firstLat = $actionData['flight']['bounds']['firstLat'] + 0; $extFlight->firstPointTM = $actionData['flight']['bounds']['firstTM'] + 0; $extFlight->lastLon = $actionData['flight']['bounds']['lastLon'] + 0; $extFlight->lastLat = $actionData['flight']['bounds']['lastLat'] + 0; $extFlight->lastPointTM = $actionData['flight']['bounds']['lastTM'] + 0; $firstPoint = new gpsPoint(); $firstPoint->setLon($actionData['flight']['bounds']['firstLon']); $firstPoint->setLat($actionData['flight']['bounds']['firstLat']); $firstPoint->gpsTime = $actionData['flight']['bounds']['firstTM'] % 86400; $lastPoint = new gpsPoint(); $lastPoint->setLon($actionData['flight']['bounds']['lastLon']); $lastPoint->setLat($actionData['flight']['bounds']['lastLat']); $lastPoint->gpsTime = $actionData['flight']['bounds']['lastTM'] % 86400; // $extFlight->FIRST_POINT=$firstPoint->to_IGC_Record(); // $extFlight->LAST_POINT=$lastPoint->to_IGC_Record(); // not used!! /* if ( is_array($actionData['flight']['turnpoints']) ) { foreach ($actionData['flight']['turnpoints'] as $i=>$tp){ $tpNum=$tp['id']; $tpPoint=new gpsPoint(); $tpPoint->setLon($tp['lon']); $tpPoint->setLat($tp['lat']); $varname="turnpoint$tpNum" ; $extFlight->$varname = $tpPoint->getLatMin().' '.$tpPoint->getLonMin() ; } } */ if ($getValidationData) { $extFlight->validated = $actionData['flight']['validation']['validated']; $extFlight->grecord = $actionData['flight']['validation']['grecord']; $extFlight->hash = $actionData['flight']['validation']['hash']; $extFlight->validationMessage = $actionData['flight']['validation']['validationMessage']; $extFlight->airspaceCheck = $actionData['flight']['validation']['airspaceCheck'] + 0; $extFlight->airspaceCheckFinal = $actionData['flight']['validation']['airspaceCheckFinal'] + 0; $extFlight->airspaceCheckMsg = $actionData['flight']['validation']['airspaceCheckMsg']; } $getScoreDataExtra = 0; $getScoreDataExtraMissing = 0; if ($getScoreData) { // we should get these from the [score] section also $extFlight->BEST_FLIGHT_TYPE = $actionData['flight']['stats']['FlightType']; $extFlight->FLIGHT_KM = $actionData['flight']['stats']['XCdistance']; $extFlight->FLIGHT_POINTS = $actionData['flight']['stats']['XCscore']; $extFlight->LINEAR_DISTANCE = $actionData['flight']['stats']['StraightDistance'] + 0; $extFlight->MAX_LINEAR_DISTANCE = $actionData['flight']['stats']['MaxStraightDistance'] + 0; $extFlight->MEAN_SPEED = $actionData['flight']['stats']['MeanGliderSpeed'] + 0; $extFlight->MAX_SPEED = $actionData['flight']['stats']['MaxSpeed'] + 0; $extFlight->MAX_VARIO = $actionData['flight']['stats']['MaxVario'] + 0; $extFlight->MIN_VARIO = $actionData['flight']['stats']['MinVario'] + 0; $extFlight->MAX_ALT = $actionData['flight']['stats']['MaxAltASL'] + 0; $extFlight->MIN_ALT = $actionData['flight']['stats']['MinAltASL'] + 0; $extFlight->TAKEOFF_ALT = $actionData['flight']['stats']['TakeoffAlt'] + 0; if (is_array($actionData['flight']['score']) && count($actionData['flight']['score']) > 0) { require_once dirname(__FILE__) . '/CL_flightScore.php'; $flightScore = new flightScore($extFlight->flightID); // we have the score array in $actionData['score'] $sArr =& $actionData['flight']['score']; $flightScore->fromSyncArray($sArr); $extFlight->flightScore = $flightScore; $getScoreDataExtra = 1; $extFlight->BEST_FLIGHT_TYPE = $flightScore->bestScoreType; $extFlight->FLIGHT_KM = $flightScore->bestDistance * 1000; $extFlight->FLIGHT_POINTS = $flightScore->bestScore; // check for missing linear distance if ($extFlight->LINEAR_DISTANCE == 0 && $extFlight->MAX_LINEAR_DISTANCE > 0) { // echo "compute MAxtakeoffDistance"; $extFlight->LINEAR_DISTANCE = $flightScore->computeMaxTakeoffDistance($firstPoint); } //put also in scores table, the flight is sure to be present in flights table if ($e['action'] == 2) { // update so we already know the flightID $flightScore->putToDB(1, 1); } } else { $getScoreDataExtraMissing = 1; } } // we also have [gliderBrand] => GRADIENT $extFlight->checkGliderBrand($actionData['flight']['info']['gliderBrand']); if ($e['action'] == 1) { if ($sync_mode & SYNC_INSERT_FLIGHT_LOCAL) { $tmpPilot = new pilot($effectiveServerID, $effectiveUserID); $tmpPilot->createDirs(); $extFlight->filename = $igcFilename; $extFlight->checkDirs(); if ($DBGlvl > 0) { echo "Moving file into place: " . $extFlight->getIGCFilename() . "<BR>"; } while (is_file($extFlight->getIGCFilename())) { if ($DBGlvl > 0) { echo "Same filename is already present<BR>"; } $extFlight->filename = '_' . $extFlight->filename; } @rename($igcFileTmp, $extFlight->getIGCFilename()); $opString = '*inserted*'; } else { $opString = '*linked*'; } // insert flight $extFlight->putFlightToDB(0); // take care of sme flights (hide /unhide) $extFlight->hideSameFlights(); if ($getScoreData && $getScoreDataExtra) { $flightScore->flightID = $extFlight->flightID; $flightScore->putToDB(1, 1); } else { if ($getScoreDataExtraMissing && $CONF['servers']['list'][$actionData['flight']['serverID']]['rescore_if_missing'] && $sync_mode & SYNC_INSERT_FLIGHT_LOCAL) { echo " [Re-score] "; $extFlight->computeScore(); } } return array(1, "Flight {$opString} OK {$addFlightNote} with local ID {$extFlight->flightID}"); } else { //update flight $extFlight->putFlightToDB(1); if ($getScoreDataExtraMissing && $CONF['servers']['list'][$actionData['flight']['serverID']]['rescore_if_missing'] && $sync_mode & SYNC_INSERT_FLIGHT_LOCAL) { echo " [Re-score] "; require_once dirname(__FILE__) . '/CL_flightScore.php'; $flightScore = new flightScore($extFlight->flightID); $flightScore->getFromDB(); if ($flightScore->gotValues) { echo "[not needed] "; } else { $extFlight->computeScore(); } } return array(1, "Flight with local ID {$flightIDlocal} UPDATED OK"); } } return array(0, "Unknown error, we should have returned by this far..."); } // if type==1 }
$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 updateTakeoffLanding() { global $db; global $flightsTable, $waypoints; $firstPoint = new gpsPoint('', $this->timezone); $firstPoint->setLat($this->firstLat); $firstPoint->setLon($this->firstLon); $firstPoint->gpsTime = $this->firstPointTM; $lastPoint = new gpsPoint('', $this->timezone); $lastPoint->setLat($this->lastLat); $lastPoint->setLon($this->lastLon); $lastPoint->gpsTime = $this->lastPointTM; //$firstPoint=new gpsPoint($this->FIRST_POINT,$this->timezone); //$lastPoint=new gpsPoint($this->LAST_POINT,$this->timezone); // calc TAKEOFF - LANDING PLACES if (count($waypoints) == 0) { $waypoints = getWaypoints(); } $takeoffIDTmp = 0; $minTakeoffDistance = 1000000; $landingIDTmp = 0; $minLandingDistance = 1000000; foreach ($waypoints as $waypoint) { $takeoff_distance = $firstPoint->calcDistance($waypoint); $landing_distance = $lastPoint->calcDistance($waypoint); if ($takeoff_distance < $minTakeoffDistance) { $minTakeoffDistance = $takeoff_distance; $takeoffIDTmp = $waypoint->waypointID; } if ($landing_distance < $minLandingDistance) { $minLandingDistance = $landing_distance; $landingIDTmp = $waypoint->waypointID; } } if ($this->takeoffID != $takeoffIDTmp || $this->takeoffVinicity != $minTakeoffDistance || $this->landingID != $landingIDTmp || $this->landingVinicity != $minLandingDistance) { $query = "UPDATE {$flightsTable} SET takeoffID='" . $takeoffIDTmp . "', takeoffVinicity=" . $minTakeoffDistance . ",\n\t\t\t\t\t landingID='" . $landingIDTmp . "', landingVinicity=" . $minLandingDistance . " WHERE ID=" . $this->flightID . " "; // echo $query; $res = $db->sql_query($query); # Error checking if ($res <= 0) { echo "<H3> Error in Update Takeoff - landing query! </H3>\n"; exit; } } $this->takeoffID = $takeoffIDTmp; $this->takeoffVinicity = $minTakeoffDistance; $this->landingID = $landingIDTmp; $this->landingVinicity = $minLandingDistance; }
function flights_find($arg) { global $db, $flightsTable; global $takeoffRadious, $CONF; require_once "FN_pilot.php"; $sitePass = $arg[0]; $lat = $arg[1]; $lon = -$arg[2]; $limit = $arg[3]; if (!securityCheck($sitePass)) { return new IXR_Error(4000, 'Access Denied'); } $firstPoint = new gpsPoint(); $firstPoint->lat = $lat; $firstPoint->lon = $lon; // calc TAKEOFF - LANDING PLACES if (count($waypoints) == 0) { $waypoints = getWaypoints(0, 1); } $takeoffIDTmp = 0; $minTakeoffDistance = 10000000; $i = 0; foreach ($waypoints as $waypoint) { $takeoff_distance = $firstPoint->calcDistance($waypoint); if ($takeoff_distance < $minTakeoffDistance) { $minTakeoffDistance = $takeoff_distance; $takeoffIDTmp = $waypoint->waypointID; } $i++; } $nearestWaypoint = new waypoint($takeoffIDTmp); $nearestWaypoint->getFromDB(); //$nearestWaypoint; //$minTakeoffDistance; if ($limit > 0) { $lim = "LIMIT {$limit}"; } else { $lim = ""; } $where_clause = "AND takeoffID={$nearestWaypoint->waypointID}"; $query = "SELECT * FROM {$flightsTable} WHERE private=0 {$where_clause} ORDER BY FLIGHT_POINTS DESC {$lim} "; //echo $query; $res = $db->sql_query($query); if ($res <= 0) { return new IXR_Error(4000, 'Error in query! ' . $query); } $flights = array(); $i = 0; while ($row = mysql_fetch_assoc($res)) { $name = getPilotRealName($row["userID"], $row["serverID"]); $link = htmlspecialchars("http://" . $_SERVER['SERVER_NAME'] . getLeonardoLink(array('op' => 'show_flight', 'flightID' => $row['ID']))); $this_year = substr($row['DATE'], 0, 4); $linkIGC = htmlspecialchars("http://" . $_SERVER['SERVER_NAME'] . getRelMainDir() . str_replace("%PILOTID%", getPilotID($row["userServerID"], $row["userID"]), str_replace("%YEAR%", $this_year, $CONF['paths']['igc'])) . '/' . $row['filename']); //$flightsRelPath."/".$row[userID]."/flights/".$this_year."/".$row[filename] ); if ($row['takeoffVinicity'] > $takeoffRadious) { $location = getWaypointName($row['takeoffID']) . " [~" . sprintf("%.1f", $row['takeoffVinicity'] / 1000) . " km]"; } else { $location = getWaypointName($row['takeoffID']); } $flights[$i]['pilot'] = htmlspecialchars($name); $flights[$i]['takeoff'] = htmlspecialchars($location); $flights[$i]['date'] = $row['DATE']; $flights[$i]['duration'] = $row['DURATION']; $flights[$i]['openDistance'] = $row['MAX_LINEAR_DISTANCE']; $flights[$i]['OLCkm'] = $row['FLIGHT_KM']; $flights[$i]['OLCScore'] = $row['FLIGHT_POINTS']; $flights[$i]['OLCtype'] = $row['BEST_FLIGHT_TYPE']; $flights[$i]['displayLink'] = $link; $i++; } return array($i, $flights); //return array($i,0); }
function toSyncJSON() { global $db, $scoresTable, $flightsTable, $CONF, $CONF_server_id; global $DBGcat, $DBGlvl; if (!$this->gotValues) { $this->getFromDB(); } $str = ''; $k = 0; if ($DBGlvl > 0) { echo "<PRE>"; print_r($this->scores); echo "</PRE>"; } // foreach ( $this->scores as $methodID=>$scoreForMethod) { $methodID = 1; $scoreForMethod =& $this->scores[$methodID]; $l = 0; if ($k != 0) { $str .= ",\n"; } if (is_array($scoreForMethod)) { foreach ($scoreForMethod as $scoreType => $scoreDetails) { if (!is_array($scoreDetails)) { continue; } if ($scoreType == $scoreForMethod['bestScoreType']) { $isBest = 1; } else { $isBest = 0; } if ($l != 0) { $str .= ",\n"; } $str .= "\t\t{ \"XCtype\": \"" . $this->syncTypesID[$this->flightTypes[$scoreType]] . "\",\n"; $str .= "\t\t\"XCdistance\" :\"" . $scoreDetails['distance'] . "\",\n"; $tpNum = 0; $tpStr = ''; for ($i = 1; $i <= 7; $i++) { if ($scoreDetails['tp'][$i]) { $newPoint = new gpsPoint($scoreDetails['tp'][$i]); if ($tpNum > 0) { $tpStr .= " ,\n\t\t"; } $tpStr .= ' {"id": ' . $i . ' , "lat": ' . $newPoint->lat() . ', "lon": ' . $newPoint->lon() . ', "UTCsecs": ' . ($newPoint->gpsTime + 0) . ' } '; $tpNum++; } } $str .= ' "turnpoints": [ ' . $tpStr . ' ] '; $str .= "\n\t\t}"; $l++; } } $k++; // } $str = '"score": [' . "\n" . $str . "\n\t]"; return $str; }
function drawFlight() { global $gradientMap, $gradient_colors_num; global $minAlt, $maxAlt; $size = 1; $startSize = 10; $pointColor = imagecolorallocate($this->img, 255, 0, 0); $startColor = imagecolorallocate($this->img, 0, 250, 0); $endColor = imagecolorallocate($this->img, 252, 250, 66); // yellow $shadowColor = imagecolorallocate($this->img, 0, 0, 0); $lines = file($this->IGCfilename); $points = 0; $minAlt = 10000; $maxAlt = 0; //first pass to find min/max foreach ($lines as $line) { $line = trim($line); if (strlen($line) == 0) { continue; } if ($line[0] == 'B') { $thisPoint = new gpsPoint($line); $thisAlt = $thisPoint->getAlt(); if ($thisAlt < $minAlt) { $minAlt = $thisAlt; } if ($thisAlt > $maxAlt) { $maxAlt = $thisAlt; } } } // Make shadow first foreach ($lines as $line) { // $line=trim($line); if (strlen($line) == 0) { continue; } if ($line[0] == 'B') { $thisPoint = new gpsPoint($line); $thisColor = $gradientMap[floor(($gradient_colors_num - 1) * $altRelPos)]; list($ptX, $ptY) = $this->lonlat2xy(-$thisPoint->lon, $thisPoint->lat); //DEBUG("MAP",8,"lon:".$thisPoint->lon." lat:".$thisPoint->lat." -> X:$ptX, Y:$ptY <br>"); $ptY = $this->pixelHeight - $ptY; if ($points == 0) { $firstPoint = new gpsPoint($line); } else { list($lastptX, $lastptY) = $this->lonlat2xy(-$lastPoint->lon, $lastPoint->lat); $lastptY = $this->pixelHeight - $lastptY; imageline($this->img, $lastptX - 1, $lastptY - 1, $ptX - 1, $ptY - 1, $shadowColor); imageline($this->img, $lastptX, $lastptY - 1, $ptX, $ptY - 1, $shadowColor); imageline($this->img, $lastptX + 1, $lastptY - 1, $ptX + 1, $ptY - 1, $shadowColor); imageline($this->img, $lastptX - 1, $lastptY, $ptX - 1, $ptY, $shadowColor); // imageline($this->img,$lastptX,$lastptY,$ptX,$ptY,$shadowColor); imageline($this->img, $lastptX + 1, $lastptY, $ptX + 1, $ptY, $shadowColor); imageline($this->img, $lastptX - 1, $lastptY + 1, $ptX - 1, $ptY + 1, $shadowColor); imageline($this->img, $lastptX, $lastptY + 1, $ptX, $ptY + 1, $shadowColor); imageline($this->img, $lastptX + 1, $lastptY + 1, $ptX + 1, $ptY + 1, $shadowColor); } $lastPoint = new gpsPoint($line); $points++; } } DEBUG("MAP", 8, "<hr>"); $points = 0; foreach ($lines as $line) { // $line=trim($line); if (strlen($line) == 0) { continue; } if ($line[0] == 'B') { $thisPoint = new gpsPoint($line); if ($maxAlt - $minAlt) { $altRelPos = ($thisPoint->getAlt() - $minAlt) / ($maxAlt - $minAlt); } else { $altRelPos = 0; } $thisColor = $gradientMap[floor(($gradient_colors_num - 1) * $altRelPos)]; list($ptX, $ptY) = $this->lonlat2xy(-$thisPoint->lon, $thisPoint->lat); $ptY = $this->pixelHeight - $ptY; if ($points == 0) { $firstPoint = new gpsPoint($line); } else { list($lastptX, $lastptY) = $this->lonlat2xy(-$lastPoint->lon, $lastPoint->lat); $lastptY = $this->pixelHeight - $lastptY; imageline($this->img, $lastptX, $lastptY, $ptX, $ptY, $thisColor); imageline($this->img, $lastptX, $lastptY + 1, $ptX, $ptY + 1, $thisColor); // leave this for extra line width + shadow // imageline($this->img,$lastptX+1,$lastptY,$ptX+1,$ptY,$shadowColor); } $lastPoint = new gpsPoint($line); $points++; } } list($ptX, $ptY) = $this->lonlat2xy(-$firstPoint->lon, $firstPoint->lat); $ptY = $this->pixelHeight - $ptY; imagearc($this->img, $ptX, $ptY, $startSize, $startSize, 0, 360, $startColor); imagearc($this->img, $ptX, $ptY, $startSize - 1, $startSize - 1, 0, 360, $startColor); list($ptX, $ptY) = $this->lonlat2xy(-$lastPoint->lon, $lastPoint->lat); $ptY = $this->pixelHeight - $ptY; imagearc($this->img, $ptX + 1, $ptY + 1, $startSize, $startSize, 0, 360, $shadowColor); imagearc($this->img, $ptX + 1, $ptY + 1, $startSize - 1, $startSize - 1, 0, 360, $shadowColor); imagearc($this->img, $ptX, $ptY, $startSize, $startSize, 0, 360, $endColor); imagearc($this->img, $ptX, $ptY, $startSize - 1, $startSize - 1, 0, 360, $endColor); }
$flight=new flight(); $flight->getFlightFromDB($row['ID']); echo $flight->getIGCFilename()."<br>"; $flight->getFlightFromIGC( $flight->getIGCFilename() ); $flight->updateTakeoffLanding(); //$flight->createEncodedPolyline(1); //$flight->makeJSON(1); $flight->putFlightToDB(1); // 1== UPDATE $not_set++; continue; } $firstPoint=new gpsPoint($row['FIRST_POINT'],$row['timezone']); $lastPoint=new gpsPoint($row['LAST_POINT'],$row['timezone']); $firstTime=$firstPoint->gpsTime+0; $lastTime=$lastPoint->gpsTime+0; $query2="UPDATE $flightsTable SET firstLat=".$firstPoint->lat().",firstLon=".$firstPoint->lon().", firstPointTM=".$firstTime.", lastLat=".$lastPoint->lat().",lastLon=".$lastPoint->lon().", lastPointTM=".$lastTime.", batchOpProcessed=1 WHERE ID=".$row['ID']." "; $res2= $db->sql_query($query2); if(!$res2){ echo "Problem in query:$query2<BR>"; exit; } }
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; }
$files_total++; if (!$row['FIRST_POINT'] || !$row['LAST_POINT']) { $flight = new flight(); $flight->getFlightFromDB($row['ID']); echo $flight->getIGCFilename() . "<br>"; $flight->getFlightFromIGC($flight->getIGCFilename()); $flight->updateTakeoffLanding(); //$flight->createEncodedPolyline(1); //$flight->makeJSON(1); $flight->putFlightToDB(1); // 1== UPDATE $not_set++; continue; } $firstPoint = new gpsPoint($row['FIRST_POINT'], $row['timezone']); $lastPoint = new gpsPoint($row['LAST_POINT'], $row['timezone']); $firstTime = $firstPoint->gpsTime + 0; $lastTime = $lastPoint->gpsTime + 0; $query2 = "UPDATE {$flightsTable} SET \n\t\t\t\t\t\t\tfirstLat=" . $firstPoint->lat() . ",firstLon=" . $firstPoint->lon() . ", firstPointTM=" . $firstTime . ",\n\t\t\t\t\t\t\tlastLat=" . $lastPoint->lat() . ",lastLon=" . $lastPoint->lon() . ", lastPointTM=" . $lastTime . ",\n\t\t\t\t\t\t\t batchOpProcessed=1 WHERE ID=" . $row['ID'] . " "; $res2 = $db->sql_query($query2); if (!$res2) { echo "Problem in query:{$query2}<BR>"; exit; } } } echo "<BR><br><br>DONE !!!<BR>"; echo "<BR><br>Flights total: {$files_total}, not proccessed: {$not_set}<BR>"; } else { if ($admin_op == "makehash") { // $query="SELECT ID, filename , userID , DATE from $flightsTable WHERE hash='' ";