function takeoffs_getTakeoffs($arg) { $sitePass = $arg[0]; $tm = $arg[1]; $onlyTakeoffs = $arg[2]; if (!securityCheck($sitePass)) { return new IXR_Error(4000, 'Access Denied'); } $waypoints = getWaypoints($tm, $onlyTakeoffs, 0); return array(count($waypoints), $waypoints); // return array(1,array($waypoints[0])); }
function findNearestWaypoint($lat, $lon) { global $waypoints; $point = new GpsPoint(); $point->setLat($lat); $point->setLon($lon); if (count($waypoints) == 0) { $waypoints = getWaypoints(); } $nearestID = 0; $minDistance = 1000000; foreach ($waypoints as $waypoint) { $distance = $point->calcDistance($waypoint); if ($distance < $minDistance) { $minDistance = $distance; $nearestID = $waypoint->waypointID; } } return array($nearestID, $minDistance); }
$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; } $i++; } $nearestWaypoint = new waypoint($takeoffIDTmp); $nearestWaypoint->getFromDB(); header('Content-Type: text/xml');
for ($i = 0; $i < mysql_num_rows($rspictures); $i++) { $tmpline = $i == 0 ? $pictureline0 : $pictureline; $pic_record = sql_fetch_array($rspictures); $tmpline = mb_ereg_replace('{link}', htmlspecialchars($pic_record['url'], ENT_COMPAT, 'UTF-8'), $tmpline); $tmpline = mb_ereg_replace('{title}', htmlspecialchars($pic_record['title'], ENT_COMPAT, 'UTF-8'), $tmpline); $tmpline = mb_ereg_replace('{uuid}', htmlspecialchars($pic_record['uuid'], ENT_COMPAT, 'UTF-8'), $tmpline); $pictures .= $tmpline; } $pictures = mb_ereg_replace('{lines}', $pictures, $picturelines); mysql_free_result($rspictures); tpl_set_var('pictures', $pictures); } else { tpl_set_var('pictures', $nopictures); } tpl_set_var('gc_com_msg2', mb_ereg_replace('%1', $opt['page']['sitename'], $gc_com_msg2)); tpl_set_var('waypoints', getWaypoints($cache_id)); tpl_set_var('cacheid', htmlspecialchars($cache_id, ENT_COMPAT, 'UTF-8')); tpl_set_var('name', htmlspecialchars($cache_name, ENT_COMPAT, 'UTF-8')); tpl_set_var('ownername', htmlspecialchars($cache_record['username'], ENT_COMPAT, 'UTF-8')); tpl_set_var('date_day', htmlspecialchars($cache_hidden_day, ENT_COMPAT, 'UTF-8')); tpl_set_var('date_month', htmlspecialchars($cache_hidden_month, ENT_COMPAT, 'UTF-8')); tpl_set_var('date_year', htmlspecialchars($cache_hidden_year, ENT_COMPAT, 'UTF-8')); tpl_set_var('selLatN', $coords_latNS == 'N' ? ' selected="selected"' : ''); tpl_set_var('selLatS', $coords_latNS == 'S' ? ' selected="selected"' : ''); tpl_set_var('selLonE', $coords_lonEW == 'E' ? ' selected="selected"' : ''); tpl_set_var('selLonW', $coords_lonEW == 'W' ? ' selected="selected"' : ''); tpl_set_var('lat_h', htmlspecialchars($coords_lat_h, ENT_COMPAT, 'UTF-8')); tpl_set_var('lat_min', htmlspecialchars($coords_lat_min, ENT_COMPAT, 'UTF-8')); tpl_set_var('lon_h', htmlspecialchars($coords_lon_h, ENT_COMPAT, 'UTF-8')); tpl_set_var('lon_min', htmlspecialchars($coords_lon_min, ENT_COMPAT, 'UTF-8')); tpl_set_var('name_message', $name_not_ok == true ? $name_message : '');
function delete() { global $userID, $CONF_server_id, $waypointsTable, $db, $flightsTable; // we get the info from db in order to log it if (!$this->name) { $this->getFromDB(); } $query = "DELETE from {$waypointsTable} WHERE ID=" . $this->waypointID . " "; $res = $db->sql_query($query); $log = new Logger(); $log->userID = $userID; $log->ItemType = 4; // waypoint; $log->ItemID = $this->waypointID; $log->ServerItemID = $CONF_server_id; $log->ActionID = 4; //4 =>delete $log->ActionXML = $this->exportXML(); $log->Modifier = 0; $log->ModifierID = 0; $log->ServerModifierID = 0; $log->Result = $res <= 0 ? 0 : 1; $log->ResultDescription = ""; if (!$log->put()) { echo "Problem in logger<BR>"; } if ($res <= 0) { echo "Error deleting waypoint from DB<BR>"; return 0; } $query = "SELECT ID FROM {$flightsTable} WHERE takeoffID=" . $this->waypointID . " OR landingID=" . $this->waypointID . " "; // echo $query; $res = $db->sql_query($query); if ($res <= 0) { echo "Error getting flights with deleted waypoint <BR>"; return 0; } global $waypoints; if (!$waypoints) { $waypoints = getWaypoints(); } while ($row = $db->sql_fetchrow($res)) { $flightID = $row['ID']; $flight = new flight(); $flight->getFlightFromDB($flightID, 1); // this computes takeoff/landing also //$flight->updateTakeoffLanding(); //$flight->putFlightToDB(1); unset($flight); } return 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 drawWaypoints() { $waypointSize = 3; $textwaypointColor = imagecolorallocate($this->img, 255, 255, 255); $textShadowCol = imagecolorallocate($this->img, 33, 33, 33); $waypoints = getWaypoints(); foreach ($waypoints as $waypoint) { list($UTMx, $UTMy, $zone, $UTMlatZone) = utm(-$waypoint->lon, $waypoint->lat); //x==lon //y==lat if ($zone == $this->UTMzoneUpLeft && $this->MAP_TOP >= $UTMy && $this->MAP_LEFT <= $UTMx && $this->MAP_BOTTOM <= $UTMy && $this->MAP_RIGHT >= $UTMx) { list($x, $y) = $this->UTM2xy($UTMx, $UTMy); $y = $this->pixelHeight - $y; $this->renderWaypoint($x, $y, $waypoint->type); // imagefilledrectangle($this->img,$x-$waypointSize,$y-$waypointSize,$x+$waypointSize,$y+$waypointSize,$waypointColor ); $this->putStringShadow(2, $x, $y + $waypointSize + 2, $waypoint->intName, $textwaypointColor, $textShadowCol); } } }
if (!$op) { $op = "list_flights"; } if (!in_array($op, array("flight_info", "find_flights", "list_flights", "submit_flight", "list_flights_json", "get_info", "polylineURL", "get_task_json"))) { return; } $encoding = "iso-8859-1"; if ($op == "find_flights") { $lat = makeSane($_GET['lat'], 1); $lon = -makeSane($_GET['lon'], 1); $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(); $XML_str = "<result>\n";