function pilots_getPilots($args) { $sitePass = $args[0]; if (!securityCheck($sitePass)) { return new IXR_Error(4000, 'Access Denied'); } $pilotsList = array(0); for ($i = 1; $i < count($args); $i++) { $getPilotID = $args[$i]; $pilotsList[$i] = getPilotInfo($getPilotID, 0); } return $pilotsList; }
if (!$CONF_use_utf) { require_once dirname(__FILE__) . '/lib/ConvertCharset/ConvertCharset.class.php'; } $format = 'JSON'; $query = "SELECT ID, userID, serverID,hash, userServerID,originalUserID ,original_ID FROM {$flightsTable} WHERE hash<>'' "; //$query.=" LIMIT 1000 "; $res = $db->sql_query($query); if ($res <= 0) { $RSS_str = '{ "error": "Error in query!" }'; } else { $RSS_str = ''; $item_num = 0; while ($row = mysql_fetch_assoc($res)) { $pilotID = $row['userID'] . '_' . $row['userServerID']; if (!$pilotNames[$pilotID]) { $pilotInfo = getPilotInfo($row['userID'], $row['userServerID']); if (!$CONF_use_utf) { $NewEncoding = new ConvertCharset(); $lName = $NewEncoding->Convert($pilotInfo[0], $langEncodings[$nativeLanguage], "utf-8", $Entities); $fName = $NewEncoding->Convert($pilotInfo[1], $langEncodings[$nativeLanguage], "utf-8", $Entities); } else { $lName = $pilotInfo[0]; $fName = $pilotInfo[1]; } $pilotNames[$pilotID]['lname'] = $lName; $pilotNames[$pilotID]['fname'] = $fName; $pilotNames[$pilotID]['country'] = $pilotInfo[2]; $pilotNames[$pilotID]['sex'] = $pilotInfo[3]; $pilotNames[$pilotID]['birthdate'] = $pilotInfo[4]; $pilotNames[$pilotID]['CIVL_ID'] = $pilotInfo[5]; }
function fillPilotInfo($pilotID, $userServerID, $userID) { global $pilotNames, $CONF_use_utf; if (!$pilotNames[$pilotID]) { $pilotInfo = getPilotInfo($userID, $userServerID); if (!$CONF_use_utf) { $NewEncoding = new ConvertCharset(); $lName = $NewEncoding->Convert($pilotInfo[0], $langEncodings[$nativeLanguage], "utf-8", $Entities); $fName = $NewEncoding->Convert($pilotInfo[1], $langEncodings[$nativeLanguage], "utf-8", $Entities); } else { $lName = $pilotInfo[0]; $fName = $pilotInfo[1]; } $pilotNames[$pilotID]['lname'] = $lName; $pilotNames[$pilotID]['fname'] = $fName; $pilotNames[$pilotID]['country'] = $pilotInfo[2]; $pilotNames[$pilotID]['sex'] = $pilotInfo[3]; $pilotNames[$pilotID]['birthdate'] = $pilotInfo[4]; $pilotNames[$pilotID]['CIVL_ID'] = $pilotInfo[5]; if ($pilotInfo[5] == -1) { $pilotNames[$pilotID]['lname'] = "ERROR:NOT IN THE DB !!!"; } } }
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 "; $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,$pilotCountry,$Sex,$Birthdate,$CIVL_ID)=getPilotInfo($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> <serverID>$CONF_server_id</serverID> <id>$this->flightID</id> <dateAdded>$dateAdded</dateAdded> <filename>$this->filename</filename> <linkIGC>".$this->getIGC_URL()."</linkIGC> <linkIGCzip>".$this->getZippedIGC_URL()."</linkIGCzip> <linkDisplay>".htmlspecialchars($this->getFlightLinkURL())."</linkDisplay> <linkGE>".htmlspecialchars($this->getFlightKML(0))."</linkGE> <info> <glider>$this->glider</glider> <gliderBrandID>$this->gliderBrandID</gliderBrandID> <gliderCat>$this->cat</gliderCat> <cat>$this->category</cat> <linkURL>$this->linkURL</linkURL> <private>$this->private</private> <comments>$this->comments</comments> </info> <time> <date>$this->DATE</date> <Timezone>$this->timezone</Timezone> <StartTime>$this->START_TIME</StartTime> <Duration>$this->DURATION</Duration> </time> <pilot> <userID>$this->userID</userID> <serverID>$userServerID</serverID> <civlID>$CIVL_ID</civlID> <userName>$this->userName</userName> <pilotFirstName>$firstName</pilotFirstName> <pilotLastName>$lastName</pilotLastName> <pilotCountry>$pilotCountry</pilotCountry> <pilotBirthdate>$Birthdate</pilotBirthdate> <pilotSex>$Sex</pilotSex> </pilot> <location> <firstLat>$firstPoint->lat</firstLat> <firstLon>".$firstPoint->lon()."</firstLon> <takeoffID>$this->takeoffID</takeoffID> <serverID>$CONF_server_id</serverID> <takeoffVinicity>$this->takeoffVinicity</takeoffVinicity> <takeoffName>$takeoff->name</takeoffName> <takeoffNameInt>$takeoff->intName</takeoffNameInt> <takeoffCountry>$takeoff->countryCode</takeoffCountry> <takeoffLocation>$takeoff->location</takeoffLocation> <takeoffLocationInt>$takeoff->intlocation</takeoffLocationInt> <takeoffLat>$takeoff->lat</takeoffLat> <takeoffLon>".$takeoff->lon()."</takeoffLon> </location> <stats> <FlightType>$this->BEST_FLIGHT_TYPE</FlightType> <StraightDistance>$this->MAX_LINEAR_DISTANCE</StraightDistance> <XCdistance>$this->FLIGHT_KM</XCdistance> <XCscore>$this->FLIGHT_POINTS</XCscore> <MaxSpeed>$this->MAX_SPEED</MaxSpeed> <MaxVario>$this->MAX_VARIO</MaxVario> <MinVario>$this->MIN_VARIO</MinVario> <MaxAltASL>$this->MAX_ALT</MaxAltASL> <MinAltASL>$this->MIN_ALT</MinAltASL> <TakeoffAlt>$this->TAKEOFF_ALT</TakeoffAlt> </stats> <validation> <validated>$this->validated</validated> <grecord>$this->grecord</grecord> <hash>$this->hash</hash> <validationMessage>$this->validationMessage</validationMessage> <airspaceCheck>$this->airspaceCheck</airspaceCheck> <airspaceCheckFinal>$this->airspaceCheckFinal</airspaceCheckFinal> <airspaceCheckMsg>$this->airspaceCheckMsg</airspaceCheckMsg> </validation> </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).'", "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; }
function guessPilots($chunkSize = 5) { // we pull data from this server global $CONF_server_id, $CONF_tmp_path, $db, $flightsTable; $urlToPull = 'http://' . $this->data['url_base'] . '/sync.php?type=1&version=' . $this->getProtocolVersion(); $urlToPull .= "&op=get_hash&format=" . $this->data['sync_format']; $urlToPull .= "&clientID={$CONF_server_id}&clientPass="******"&use_zip=" . $this->data['use_zip']; echo "Getting flight hashes from {$urlToPull} ... "; flush2Browser(); $rssStr = fetchURL($urlToPull, 60 + floor($chunkSize / 5)); if (!$rssStr) { echo "<div class='error'>Cannot get data from server</div><BR>"; return 0; } echo " <div class='ok'>DONE</div><br>"; flush2Browser(); echo "Decoding log from JSON format ..."; flush2Browser(); require_once dirname(__FILE__) . '/lib/json/CL_json.php'; $arr = json::decode($rssStr); echo " <div class='ok'>DONE</div><br>"; flush2Browser(); //print_r($arr); //exit; $entriesNum = 0; $entriesNumOK = 0; if (count($arr['log'])) { $item_num = $arr['log_item_num']; echo "<div class='ok'>GOT {$item_num} entries</div><br>"; foreach ($arr['log'] as $i => $logItem) { if (!is_numeric($i)) { echo "{$i} not numeric "; continue; } // echo ($entriesNum+1)." / $item_num "; if (is_array($hashRemote[$logItem['item']['hash']])) { echo " <div class='error'>WARNING found hash from flight " . $logItem['item']['ID'] . " which already existed in flight " . $hashRemote[$logItem['item']['hash']]['ID'] . " </div><br>"; } $hashRemote[$logItem['item']['hash']] = array('ID' => $logItem['item']['ID'], 'pilot' => $logItem['item']['pilot']); //$entryResult=$this->processSyncEntry($this->ID,$logItem['item']) ; //if ( $entryResult <= -128 ) { // if we got an error break the loop, the admin must solve the error // echo "<div class'error'>Got fatal Error, will exit</div>"; // break; // } if ($entryResult > 0) { $entriesNumOK++; } $entriesNum++; } // now get the local hashes $query = "SELECT ID, userID, serverID,hash, userServerID,originalUserID ,original_ID FROM {$flightsTable} WHERE hash<>'' "; $res = $db->sql_query($query); if ($res <= 0) { echo "Error in query!"; } else { while ($row = mysql_fetch_assoc($res)) { $hashLocal[$row['hash']] = array('userID' => $row['userID'], 'userServerID' => $row['userServerID']); } } // now compare them //print_r($hashLocal); //echo "<hr><HR><HR>"; // print_r($hashRemote); foreach ($hashRemote as $testHash => $remoteInfo) { if (is_array($hashLocal[$testHash])) { // if we have this user in the local db continue if ($hashRemote[$testHash]['pilot']['userID'] == $hashLocal[$testHash]['userID'] && $hashLocal[$testHash]['userServerID'] == $this->ID) { continue; } $samePilots[$hashRemote[$testHash]['pilot']['userID']][$hashRemote[$testHash]['pilot']['userServerID']][$hashLocal[$testHash]['userID']][$hashLocal[$testHash]['userServerID']]++; $remotePilotNames[$hashRemote[$testHash]['pilot']['userID']][$hashRemote[$testHash]['pilot']['userServerID']] = $hashRemote[$testHash]['pilot']; //echo "match REMOTE ".$hashRemote[$testHash]['userID']." [ ".$hashRemote[$testHash]['userServerID']." ] <=> ".$hashLocal[$testHash]['userID']." [ ".$hashLocal[$testHash]['userServerID']." ] LOCAL<BR>"; } } } else { echo "The sync-log returned error. Error: <br />"; print_r($arr); echo "<hr><pre>{$rssStr}</pre>"; } // print_r($samePilots); echo "<hr><pre>"; echo "# ------------------------------------\n"; echo "DELETE FROM leonardo_remote_pilots WHERE remoteServerID=" . $this->ID . "; \n"; foreach ($samePilots as $remoteUserID => $arr1) { foreach ($arr1 as $remoteUserServerID => $arr2) { foreach ($arr2 as $localUserID => $arr3) { foreach ($arr3 as $localUserServerID => $arr4) { $counts = $arr4; $pilotInfo = getPilotInfo($localUserID, $localUserServerID); $remotePilotInfo = $remotePilotNames[$remoteUserID][$remoteUserServerID]; if ($remoteUserServerID == 0) { $remoteUserServerID = $this->ID; } echo "# ------------------------------------\n"; echo "# REMOTE [ " . $remotePilotInfo['lName'] . " " . $remotePilotInfo['fName'] . " country: " . $remotePilotInfo['country'] . " sex: " . $remotePilotInfo['sex'] . " birthdate: " . $remotePilotInfo['birthdate'] . " CIVL ID: " . $remotePilotInfo['CIVL_ID'] . " ] \n"; echo "# LOCAL [ " . $pilotInfo['0'] . " " . $pilotInfo['1'] . " country: " . $pilotInfo['2'] . " sex: " . $pilotInfo['3'] . " birthdate: " . $pilotInfo['4'] . " CIVL ID: " . $pilotInfo['5'] . " ] \n"; echo "# {$remoteUserServerID}" . "_{$remoteUserID} {$localUserServerID}" . "_{$localUserID} = {$counts} \n"; echo "INSERT INTO leonardo_remote_pilots VALUES ( {$remoteUserServerID},{$remoteUserID},{$localUserServerID},{$localUserID});\n"; } } } } echo "</pre>"; echo "<div class='ok'>Finished guessing pilots</div><br>"; echo "Proccessed {$entriesNum} flight's hashes out of {$item_num}<br>"; }