2016-04-02 09:31:15 +00:00
< ? php
// Start session
session_start ();
// Load the common PHP classes.
require_once ( $_SERVER [ 'DOCUMENT_ROOT' ] . DIRECTORY_SEPARATOR . " classes " . DIRECTORY_SEPARATOR . " common.class.php " );
require_once ( $_SERVER [ 'DOCUMENT_ROOT' ] . DIRECTORY_SEPARATOR . " classes " . DIRECTORY_SEPARATOR . " settings.class.php " );
require_once ( $_SERVER [ 'DOCUMENT_ROOT' ] . DIRECTORY_SEPARATOR . " classes " . DIRECTORY_SEPARATOR . " template.class.php " );
$common = new common ();
$settings = new settings ();
$template = new template ();
$pageData = array ();
2016-10-17 15:58:38 +00:00
// Items per page.
$itemsPerPage = 25 ;
2016-04-02 09:31:15 +00:00
// The title of this page.
$pageData [ 'title' ] = " Flights Seen " ;
2016-04-27 23:09:49 +00:00
// Add flight data to the $pageData array using the search string if available.
if ( isset ( $_POST [ 'flight' ])) {
$searchString = $_POST [ 'flight' ];
} else {
$searchString = " " ;
}
2016-10-17 15:58:38 +00:00
// Set the start stop positions to be used in the query.
2017-10-11 22:22:28 +00:00
$start = 0 ;
2016-10-17 15:58:38 +00:00
if ( isset ( $_GET [ 'page' ])) {
$start = $_GET [ 'page' ] * $itemsPerPage ;
}
$dbh = $common -> pdoOpen ();
2024-07-13 04:04:48 +00:00
$sql = " SELECT COUNT(*) FROM " . $settings :: db_prefix . " flights WHERE flight LIKE :like AND EXISTS (SELECT * FROM " . $settings :: db_prefix . " positions WHERE " . $settings :: db_prefix . " positions.flight = " . $settings :: db_prefix . " flights.id) " ;
2016-10-17 15:58:38 +00:00
$sth = $dbh -> prepare ( $sql );
$sth -> bindValue ( ':like' , " % " . $searchString . " % " , PDO :: PARAM_STR );
$sth -> execute ();
$totalFlights = $sth -> fetchColumn ();
$sth = NULL ;
$dbh = NULL ;
2016-04-02 09:31:15 +00:00
$dbh = $common -> pdoOpen ();
2024-07-13 04:04:48 +00:00
$sql = " SELECT * FROM " . $settings :: db_prefix . " flights WHERE flight LIKE :like AND EXISTS (SELECT * FROM " . $settings :: db_prefix . " positions WHERE " . $settings :: db_prefix . " positions.flight = " . $settings :: db_prefix . " flights.id) ORDER BY lastSeen DESC, flight LIMIT :start, :items " ;
2016-04-02 09:31:15 +00:00
$sth = $dbh -> prepare ( $sql );
2016-10-17 15:58:38 +00:00
$sth -> bindValue ( ':like' , " % " . $searchString . " % " , PDO :: PARAM_STR );
$sth -> bindValue ( ':start' , $start , PDO :: PARAM_INT );
$sth -> bindValue ( ':items' , $itemsPerPage , PDO :: PARAM_INT );
2016-04-02 09:31:15 +00:00
$sth -> execute ();
2016-10-17 15:58:38 +00:00
$flights = $sth -> fetchAll ( PDO :: FETCH_ASSOC );
2016-04-02 09:31:15 +00:00
$sth = NULL ;
$dbh = NULL ;
2016-04-27 21:01:54 +00:00
// Change dates to the proper timezone and format.
foreach ( $flights as & $flight ) {
$date = new DateTime ( $flight [ 'firstSeen' ], new DateTimeZone ( 'UTC' ));
$date -> setTimezone ( new DateTimeZone ( $common -> getSetting ( 'timeZone' )));
$flight [ 'firstSeen' ] = $date -> format ( $common -> getSetting ( 'dateFormat' ));
$date = new DateTime ( $flight [ 'lastSeen' ], new DateTimeZone ( 'UTC' ));
$date -> setTimezone ( new DateTimeZone ( $common -> getSetting ( 'timeZone' )));
$flight [ 'lastSeen' ] = $date -> format ( $common -> getSetting ( 'dateFormat' ));
}
2016-04-02 09:31:15 +00:00
2016-10-17 15:58:38 +00:00
$pageData [ 'flights' ] = $flights ;
2016-04-02 09:31:15 +00:00
// Calculate the number of pagination links to show.
2017-10-02 19:36:29 +00:00
$pageData [ 'pageLinks' ] = ceil ( $totalFlights / $itemsPerPage - 1 );
// Pass the current page number being viewed to the template.
$pageData [ 'pageNumber' ] = 1 ;
if ( isset ( $_GET [ 'page' ])) {
$pageData [ 'pageNumber' ] = $_GET [ 'page' ];
}
2016-04-02 09:31:15 +00:00
$template -> display ( $pageData );
?>