Example #1
0
            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>";
                for ($i = 1; $i < count($checkLines); $i++) {
 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
 }
Example #3
0
 function fromSyncArray($sArr)
 {
     /*
     	echo "<pre>";
     	print_r($flightScore->scores);
     	echo "</pre>";
     */
     /* Array   (
     	[0] => Array
     		(	[XCtype] => FreeFlight3TP
     			[XCdistance] => 36.482
     			[turnpoints] => Array(
     					[0] => Array([id] => 1,[lat] => 36.761466,[lon] => -119.09663,[UTCsecs] => 70730 )
     					[1] => Array([id] =>2 ,[lat] => 36.7794333, [lon] => -119.117866,[UTCsecs] => 71966)
     */
     global $CONF;
     $this->scores = array();
     foreach ($sArr as $i => $score) {
         //$mID=$score['XCscoreMethod'];
         $type = $this->flightTypesID[$this->syncTypesNames[$score['XCtype']]];
         //$bestScore=0;
         //$bestScoreType='';
         foreach ($CONF['scoring']['sets'] as $mID => $mArray) {
             $thisScore = $score['XCdistance'] * $mArray['types'][$type];
             if ($thisScore >= $this->scores[$mID]['bestScore']) {
                 $this->scores[$mID]['bestScoreType'] = $type;
                 $this->scores[$mID]['bestScore'] = $thisScore;
                 $this->scores[$mID]['bestDistance'] = $score['XCdistance'];
             }
             $this->scores[$mID][$type]['distance'] = $score['XCdistance'];
             $this->scores[$mID][$type]['score'] = $thisScore;
             $this->scores[$mID][$type]['isBest'] = 0;
             // will update later
             $tpNum = 1;
             foreach ($score['turnpoints'] as $j => $tp) {
                 $thisTP = new gpsPoint();
                 $thisTP->setLat($tp['lat']);
                 $thisTP->setLon($tp['lon']);
                 $thisTP->gpsTime = $tp['UTCsecs'];
                 $this->scores[$mID][$type]['tp'][$tpNum] = $thisTP->to_IGC_Record();
                 $tpNum++;
             }
         }
     }
     // now iterate through $this->scores and update best values
     foreach ($this->scores as $mID => $score) {
         $bestType = $this->scores[$mID]['bestScoreType'];
         $this->scores[$mID][$bestType]['isBest'] = 1;
     }
     $defaultMethodID = $CONF['scoring']['default_set'];
     $defaultScore = $this->scores[$defaultMethodID];
     $this->bestScoreType = $this->scores[$defaultMethodID]['bestScoreType'];
     $this->bestScore = $this->scores[$defaultMethodID]['bestScore'];
     $this->bestDistance = $this->scores[$defaultMethodID]['bestDistance'];
     //echo "<pre>";
     //print_r($this->scores);
     //echo "</pre>";
     $this->gotValues = 1;
 }
Example #4
0
 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;
 }
Example #5
0
		$query="SELECT * from $flightsTable WHERE batchOpProcessed=0 AND serverID=8  AND LINEAR_DISTANCE=0 ";
		$res= $db->sql_query($query);

		$files_total=0;
		
		if($res > 0){
			 while ($row = mysql_fetch_assoc($res)) { 
				$files_total++;

				if (! $row['firstLat'] || ! $row['firstLon']) {
					$not_set++;
					continue;
				}
				
				$firstPoint=new gpsPoint();
				$firstPoint->setLat($row['firstLat']);
				$firstPoint->setLon($row['firstLon']);
	
				$flightScore=new flightScore($row['ID']);
				$flightScore->getFromDB();	
				$lDistance=$flightScore->computeMaxTakeoffDistance($firstPoint);
						
				$query2="UPDATE $flightsTable SET LINEAR_DISTANCE=$lDistance , 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>";