Пример #1
0
    function toXML($forceProtocol = '')
    {
        /*	maybe also include these
        		"forceBounds"		"autoScore"
        		*/
        global $CONF_server_id, $CONF_photosPerFlight, $CONF;
        if ($CONF['sync']['protocol']['format'] == 'JSON' && $forceProtocol != 'XML' || $forceProtocol == 'JSON') {
            $useJSON = 1;
            require_once dirname(__FILE__) . '/lib/json/CL_json.php';
        } else {
            $useJSON = 0;
        }
        if ($this->flightScore) {
            $flightScore =& $this->flightScore;
            if (!$flightScore->gotValues) {
                $flightScore->getFromDB();
            }
        } else {
            $flightScore = new flightScore($this->flightID);
            $flightScore->getFromDB();
        }
        $defaultMethodID = $CONF['scoring']['default_set'];
        $scoreDetails = $flightScore->scores[$defaultMethodID][$flightScore->bestScoreType];
        $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++;
            }
        }
        $takeoff = new waypoint($this->takeoffID);
        $takeoff->getFromDB();
        //		$firstPoint=new gpsPoint($this->FIRST_POINT,$this->timezone);
        //		$lastPoint=new gpsPoint($this->LAST_POINT,$this->timezone);
        $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;
        list($lastName, $firstName, $lastNameEn, $firstNameEn, $pilotCountry, $Sex, $Birthdate, $CIVL_ID) = getPilotInfoEn($this->userID, $this->userServerID);
        $userServerID = $this->userServerID;
        if ($userServerID == 0) {
            $userServerID = $CONF_server_id;
        }
        // will be changed when dateAdded will be UTC
        $dateAdded = $this->dateAdded;
        // We changed this, dateAdded is in UTC from now on !!!!
        // So the conversion is not needed
        //$dateAdded=tm2fulldate(fulldate2tm($dateAdded)-date('Z')); // convert to UTC
        if ($this->serverID == 0 || $this->serverID == $CONF_server_id) {
            $isLocal = 1;
        } else {
            $isLocal = 0;
        }
        if (!$useJSON) {
            $resStr = "<flight>\n<serverID>{$CONF_server_id}</serverID>\n<id>{$this->flightID}</id>\n<dateAdded>{$dateAdded}</dateAdded>\n<filename>{$this->filename}</filename>\n<linkIGC>" . $this->getIGC_URL() . "</linkIGC>\n<linkIGCzip>" . $this->getZippedIGC_URL() . "</linkIGCzip>\n<linkDisplay>" . htmlspecialchars($this->getFlightLinkURL()) . "</linkDisplay>\n<linkGE>" . htmlspecialchars($this->getFlightKML(0)) . "</linkGE>\n\n<info>\n\t<glider>{$this->glider}</glider>\n\t<gliderBrandID>{$this->gliderBrandID}</gliderBrandID>\n\t<gliderCat>{$this->cat}</gliderCat>\n\t<cat>{$this->category}</cat>\n\t<linkURL>{$this->linkURL}</linkURL>\n\t<private>{$this->private}</private>\n\t<comments>{$this->comments}</comments>\n</info>\n\n<time>\n\t<date>{$this->DATE}</date>\n\t<Timezone>{$this->timezone}</Timezone>\n\t<StartTime>{$this->START_TIME}</StartTime>\n\t<Duration>{$this->DURATION}</Duration>\n</time>\n\n<pilot>\n\t<userID>{$this->userID}</userID>\n\t<serverID>{$userServerID}</serverID>\n\t<civlID>{$CIVL_ID}</civlID>\n\t<userName>{$this->userName}</userName>\n\t<pilotFirstName>{$firstName}</pilotFirstName>\n\t<pilotLastName>{$lastName}</pilotLastName>\n\t<pilotFirstNameEn>{$firstNameEn}</pilotFirstNameEn>\n\t<pilotLastNameEn>{$lastNameEn}</pilotLastNameEn>\n\t<pilotCountry>{$pilotCountry}</pilotCountry>\n\t<pilotBirthdate>{$Birthdate}</pilotBirthdate>\n\t<pilotSex>{$Sex}</pilotSex>\n</pilot>\n\n<location>\n\t<firstLat>{$firstPoint->lat}</firstLat>\n\t<firstLon>" . $firstPoint->lon() . "</firstLon>\n\t<takeoffID>{$this->takeoffID}</takeoffID>\n\t<serverID>{$CONF_server_id}</serverID>\n\t<takeoffVinicity>{$this->takeoffVinicity}</takeoffVinicity>\n\t<takeoffName>{$takeoff->name}</takeoffName>\n\t<takeoffNameInt>{$takeoff->intName}</takeoffNameInt>\n\t<takeoffCountry>{$takeoff->countryCode}</takeoffCountry>\n\t<takeoffLocation>{$takeoff->location}</takeoffLocation>\n\t<takeoffLocationInt>{$takeoff->intlocation}</takeoffLocationInt>\n\t<takeoffLat>{$takeoff->lat}</takeoffLat>\n\t<takeoffLon>" . $takeoff->lon() . "</takeoffLon>\n</location>\n\n<stats>\n\t<FlightType>{$this->BEST_FLIGHT_TYPE}</FlightType>\n\t<StraightDistance>{$this->MAX_LINEAR_DISTANCE}</StraightDistance>\n\t<XCdistance>{$this->FLIGHT_KM}</XCdistance>\n\t<XCscore>{$this->FLIGHT_POINTS}</XCscore>\n\t<MaxSpeed>{$this->MAX_SPEED}</MaxSpeed>\n\t<MaxVario>{$this->MAX_VARIO}</MaxVario>\n\t<MinVario>{$this->MIN_VARIO}</MinVario>\n\t<MaxAltASL>{$this->MAX_ALT}</MaxAltASL>\n\t<MinAltASL>{$this->MIN_ALT}</MinAltASL>\n\t<TakeoffAlt>{$this->TAKEOFF_ALT}</TakeoffAlt>\n</stats>\n\n<validation>\n\t<validated>{$this->validated}</validated>\n\t<grecord>{$this->grecord}</grecord>\n\t<hash>{$this->hash}</hash>\n\t<validationMessage>{$this->validationMessage}</validationMessage>\n\t<airspaceCheck>{$this->airspaceCheck}</airspaceCheck>\n\t<airspaceCheckFinal>{$this->airspaceCheckFinal}</airspaceCheckFinal>\n\t<airspaceCheckMsg>{$this->airspaceCheckMsg}</airspaceCheckMsg>\n</validation>\n\n\n</flight>\n";
        } else {
            $resStr = '{
"flight": {
	"serverID": ' . ($this->serverID ? $this->serverID : $CONF_server_id) . ',
	"id": ' . ($isLocal ? $this->flightID : $this->original_ID) . ',
	"dateAdded": "' . $dateAdded . '",
	"filename": "' . json::prepStr($this->filename) . '",
	"linkIGC": "' . json::prepStr($this->getIGC_URL()) . '",
	"linkIGCzip": "' . json::prepStr($this->getZippedIGC_URL()) . '",
	"linkDisplay": "' . ($isLocal ? json::prepStr($this->getFlightLinkURL()) : json::prepStr($this->getOriginalURL())) . '",
	"linkGE": "' . ($isLocal ? json::prepStr($this->getFlightKML(0)) : json::prepStr($this->getOriginalKML())) . '",
	"isLive": ' . $this->isLive . ',

	"info": {
		"glider": "' . json::prepStr($this->glider) . '",
		"gliderBrandID": ' . $this->gliderBrandID . ',
		"gliderBrand": "' . json::prepStr($CONF['brands']['list'][$this->gliderBrandID]) . '",
		"gliderCat": ' . $this->cat . ',
		"cat": ' . $this->category . ',
		"linkURL": "' . json::prepStr($this->linkURL) . '",
		"private": ' . $this->private . ',
		"comments": "' . json::prepStr($this->comments) . '"
	},

	"time": {
		"date": "' . json::prepStr($this->DATE) . '",
		"Timezone": "' . $this->timezone . '",
		"StartTime": "' . $this->START_TIME . '",
		"Duration": "' . $this->DURATION . '"
	},

	"bounds": {
		"forceBounds": ' . $this->forceBounds . ',
		"firstLat": ' . $firstPoint->lat() . ',
		"firstLon": ' . $firstPoint->lon() . ',
		"firstTM": ' . ($firstPoint->gpsTime + 0) . ',
		"lastLat": ' . $lastPoint->lat() . ',
		"lastLon": ' . $lastPoint->lon() . ',
		"lastTM": ' . ($lastPoint->gpsTime + 0) . '
	},

	"pilot": {
		"userID": "' . $this->userID . '",
		"serverID": "' . $userServerID . '",
		"civlID": "' . $CIVL_ID . '",
		"userName": "******",
		"pilotFirstName": "' . json::prepStr($firstName) . '",
		"pilotLastName": "' . json::prepStr($lastName) . '",
		"pilotFirstNameEn": "' . json::prepStr($firstNameEn) . '",
		"pilotLastNameEn": "' . json::prepStr($lastNameEn) . '",
		"pilotCountry": "' . $pilotCountry . '",
		"pilotBirthdate": "' . json::prepStr($Birthdate) . '",
		"pilotSex": "' . $Sex . '"
	},

	"location": {
		"takeoffID": "' . ($this->takeoffID + 0) . '",
		"serverID": "' . $CONF_server_id . '",
		"takeoffVinicity": "' . $this->takeoffVinicity . '",
		"takeoffName": "' . json::prepStr($takeoff->name) . '",
		"takeoffNameInt": "' . json::prepStr($takeoff->intName) . '",
		"takeoffCountry": "' . $takeoff->countryCode . '",
		"takeoffLocation": "' . json::prepStr($takeoff->location) . '",
		"takeoffLocationInt": "' . json::prepStr($takeoff->intlocation) . '",
		"takeoffLat": "' . $takeoff->lat() . '",
		"takeoffLon": "' . $takeoff->lon() . '"
	},

	"stats":  {
		"FlightType": "' . $this->BEST_FLIGHT_TYPE . '",
		"MaxStraightDistance": ' . ($this->MAX_LINEAR_DISTANCE + 0) . ',
		"StraightDistance": ' . $this->LINEAR_DISTANCE . ',
		"XCdistance": "' . ($this->FLIGHT_KM + 0) . '",
		"XCscore": "' . ($this->FLIGHT_POINTS + 0) . '",

		"MaxSpeed": "' . $this->MAX_SPEED . '",
		"MeanGliderSpeed": "' . $this->MEAN_SPEED . '",
		"MaxVario": "' . $this->MAX_VARIO . '",
		"MinVario": "' . $this->MIN_VARIO . '",
		"MaxAltASL": "' . $this->MAX_ALT . '",
		"MinAltASL": "' . $this->MIN_ALT . '",
		"TakeoffAlt": "' . $this->TAKEOFF_ALT . '"
	},

	' . $flightScore->toSyncJSON() . ' ,


	"turnpoints": [
		' . $tpStr . '
	] ,

	"validation": {
		"validated": "' . $this->validated . '",
		"grecord": "' . $this->grecord . '",
		"hash": "' . $this->hash . '",
		"validationMessage": "' . json::prepStr($this->validationMessage) . '",
		"airspaceCheck": "' . json::prepStr($this->airspaceCheck) . '",
		"airspaceCheckFinal": "' . json::prepStr($this->airspaceCheckFinal) . '",
		"airspaceCheckMsg": "' . json::prepStr($this->airspaceCheckMsg) . '"
	}


}
}';
        }
        return $resStr;
    }