pdoOpen(); $sql = "SELECT id FROM ".$settings::db_prefix."flights WHERE flight = :flight"; $sth = $dbh->prepare($sql); $sth->bindParam(':flight', $_GET['flight'], PDO::PARAM_STR, 50); $sth->execute(); $row = $sth->fetch(); $sth = NULL; $dbh = NULL; $flightId = $row['id']; $dbh = $common->pdoOpen(); $sql = "SELECT * FROM ".$settings::db_prefix."positions WHERE flight = :flight ORDER BY time"; $sth = $dbh->prepare($sql); $sth->bindParam(':flight', $flightId, PDO::PARAM_STR, 50); $sth->execute(); $positions = $sth->fetchAll(); $sth = NULL; $dbh = NULL; $thisPath = array(); $flightPath = array(); $flightPaths = array(); $lastMessage = 0; $firstPass = TRUE; $firstPosition = TRUE; $totalPositions = count($positions); $counter = 0; $id = 1; $pathsSeen = 0; foreach ($positions as $position) { $counter++; if ($position["message"] < $lastMessage || $counter == $totalPositions) { $flightPath["finishingId"] = $lastId; $flightPath["finishingTime"] = $lastTime; $flightPath["finishingSquawk"] = $lastSquawk; $flightPath["finishingLatitude"] = $lastLatitude; $flightPath["finishingLongitude"] = $lastLongitude; $flightPath["finishingTrack"] = $lastTrack; $flightPath["finishingAltitude"] = $lastAltitude; $flightPath["finishingVerticleRate"] = $lastVerticleRate; $flightPath["finishingSpeed"] = $lastSpeed; $flightPath["positions"] = json_encode($thisPath); $flightPaths[] = $flightPath; unset($thisPath); unset($flightPath); $thisPath = array(); $flightPath = array(); $pathsSeen++; $firstPosition = TRUE; } if ($firstPosition == TRUE) { $flightPath["id"] = $id++; $flightPath["startingId"] = $position["id"]; $flightPath["startingTime"] = $position["time"]; $flightPath["startingSquawk"] = $position["squawk"]; $flightPath["startingLatitude"] = $position["latitude"]; $flightPath["startingLongitude"] = $position["longitude"]; $flightPath["startingTrack"] = $position["track"]; $flightPath["startingAltitude"] = $position["altitude"]; $flightPath["startingVerticleRate"] = $position["verticleRate"]; $flightPath["startingSpeed"] = $position["speed"]; $firstPosition = FALSE; } $thisPosition["id"] = $position["id"]; $thisPosition["time"] = $position["time"]; $thisPosition["latitude"] = $position["latitude"]; $thisPosition["longitude"] = $position["longitude"]; $thisPosition["track"] = $position["track"]; $thisPosition["message"] = $position["message"]; $thisPath[] = $thisPosition; $lastId = $position["id"]; $lastMessage = $position["message"]; $lastTime = $position["time"]; $lastSquawk = $position["squawk"]; $lastLatitude = $position["latitude"]; $lastLongitude = $position["longitude"]; $lastTrack = $position["track"]; $lastAltitude = $position["altitude"]; $lastVerticleRate = $position["verticleRate"]; $lastSpeed = $position["speed"]; } // Pass the number of seen paths which is equal to the last flight ID. $pageData['pathsSeen'] = $pathsSeen; $countFlightPaths = count($flightPaths); if ($countFlightPaths > 0) { $pageData['flightPathsAvailable'] = "TRUE"; $selectedFlightPath = $flightPaths; if (isset($_GET["index"])) { switch ($_GET["index"]) { case "first": $selectedFlightPath = [$flightPaths[0]]; break; case "last": $selectedFlightPath = [$flightPaths[$countFlightPaths - 1]]; break; default: if (is_numeric($_GET["index"])) { $selectedFlightPath = [$flightPaths[$_GET["index"]]]; } break; } } $pageData['flightPaths'] = $selectedFlightPath; } else { $pageData['flightPathsAvailable'] = "FALSE"; } $template->display($pageData); ?>