isAuthenticated()) { // The user is not logged in so forward them to the login page. header ("Location: login.php"); } // Set updated variable to FALSE. $updated = FALSE; if ($common->postBack()) { // Flight notifications $notificationArray = explode(',', $_POST['notifications']); if ($settings::db_driver == "xml") { // XML $notifications = simplexml_load_file($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR."data".DIRECTORY_SEPARATOR."notifications.xml"); unset($notifications->flight); foreach ($notificationArray as $notification) { $flight = $notifications->addChild('flight', ''); $flight->addChild('name', $notification); $flight->addChild('lastMessageCount', -1); $dom = dom_import_simplexml($notifications)->ownerDocument; $dom->preserveWhiteSpace = FALSE; $dom->formatOutput = TRUE; file_put_contents($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR."data".DIRECTORY_SEPARATOR."notifications.xml", $dom->saveXML()); } } else { // PDO $dbh = $common->pdoOpen(); $sql = "SELECT * FROM ".$settings::db_prefix."notifications"; $sth = $dbh->prepare($sql); $sth->execute(); $savedFlights = $sth->fetchAll(); $sth = NULL; $dbh = NULL; foreach ($savedFlights as $flight) { // Remove flight if not in list. if (!in_array($flight, $notificationArray)) { $dbh = $common->pdoOpen(); $sql = "DELETE FROM ".$settings::db_prefix."notifications WHERE flight = :flight"; $sth = $dbh->prepare($sql); $sth->bindParam(':flight', $flight['flight'], PDO::PARAM_STR, 10); $sth->execute(); $sth = NULL; $dbh = NULL; } } foreach ($notificationArray as $flight) { // Add flight if not saved already. if (!in_array($flight, $savedFlights)) { $dbh = $common->pdoOpen(); $sql = "INSERT INTO ".$settings::db_prefix."notifications (flight) VALUES (:flight)"; $sth = $dbh->prepare($sql); $sth->bindParam(':flight', $flight, PDO::PARAM_STR, 10); $sth->execute(); $sth = NULL; $dbh = NULL; } } } // Set TRUE or FALSE for checkbox items. $enableNotifications = FALSE; if (isset($_POST['enableNotifications']) && $_POST['enableNotifications'] == "TRUE") $enableNotifications = TRUE; $enableFlights = FALSE; if (isset($_POST['enableFlights']) && $_POST['enableFlights'] == "TRUE") $enableFlights = TRUE; $enableBlog = FALSE; if (isset($_POST['enableBlog']) && $_POST['enableBlog'] == "TRUE") $enableBlog = TRUE; $enableInfo = FALSE; if (isset($_POST['enableInfo']) && $_POST['enableInfo'] == "TRUE") $enableInfo = TRUE; $enableGraphs = FALSE; if (isset($_POST['enableGraphs']) && $_POST['enableGraphs'] == "TRUE") $enableGraphs = TRUE; $enableDump1090 = FALSE; if (isset($_POST['enableDump1090']) && $_POST['enableDump1090'] == "TRUE") $enableDump1090 = TRUE; $enableDump978 = FALSE; if (isset($_POST['enableDump978']) && $_POST['enableDump978'] == "TRUE") $enableDump978 = TRUE; $enablePfclient = FALSE; if (isset($_POST['enablePfclient']) && $_POST['enablePfclient'] == "TRUE") $enablePfclient = TRUE; $enableFlightAwareLink = FALSE; if (isset($_POST['enableFlightAwareLink']) && $_POST['enableFlightAwareLink'] == "TRUE") $enableFlightAwareLink = TRUE; $enablePlaneFinderLink = FALSE; if (isset($_POST['enablePlaneFinderLink']) && $_POST['enablePlaneFinderLink'] == "TRUE") $enablePlaneFinderLink = TRUE; $enableFlightRadar24Link = FALSE; if (isset($_POST['enableFlightRadar24Link']) && $_POST['enableFlightRadar24Link'] == "TRUE") $enableFlightRadar24Link = TRUE; $enableAdsbExchangeLink = FALSE; if (isset($_POST['enableAdsbExchangeLink']) && $_POST['enableAdsbExchangeLink'] == "TRUE") $enableAdsbExchangeLink = TRUE; $useDump1090FaMap = FALSE; if (isset($_POST['useDump1090FaMap']) && $_POST['useDump1090FaMap'] == "TRUE") $useDump1090FaMap = TRUE; $enableTwitterNotifications = FALSE; if (isset($_POST['enableTwitterNotifications']) && $_POST['enableTwitterNotifications'] == "TRUE") $enableTwitterNotifications = TRUE; // Update settings using those supplied by the form. $common->updateSetting("siteName", $_POST['siteName']); $common->updateSetting("template", $_POST['template']); $common->updateSetting("defaultPage", $_POST['defaultPage']); $common->updateSetting("dateFormat", $_POST['dateFormat']); $common->updateSetting("enableNotifications", $enableNotifications); $common->updateSetting("enableFlights", $enableFlights); $common->updateSetting("enableBlog", $enableBlog); $common->updateSetting("enableInfo", $enableInfo); $common->updateSetting("enableGraphs", $enableGraphs); $common->updateSetting("enableDump1090", $enableDump1090); $common->updateSetting("enableDump978", $enableDump978); $common->updateSetting("enablePfclient", $enablePfclient); $common->updateSetting("enableFlightAwareLink", $enableFlightAwareLink); $common->updateSetting("flightAwareLogin", $_POST['flightAwareLogin']); $common->updateSetting("flightAwareSite", $_POST['flightAwareSite']); $common->updateSetting("enablePlaneFinderLink", $enablePlaneFinderLink); $common->updateSetting("planeFinderReceiver", $_POST['planeFinderReceiver']); $common->updateSetting("enableFlightRadar24Link", $enableFlightRadar24Link); $common->updateSetting("flightRadar24Id", $_POST['flightRadar24Id']); $common->updateSetting("enableAdsbExchangeLink", $enableAdsbExchangeLink); $common->updateSetting("measurementRange", $_POST['measurementRange']); $common->updateSetting("measurementTemperature", $_POST['measurementTemperature']); $common->updateSetting("measurementBandwidth", $_POST['measurementBandwidth']); $common->updateSetting("networkInterface", $_POST['networkInterface']); $common->updateSetting("timeZone", $_POST['timeZone']); $common->updateSetting("useDump1090FaMap", $useDump1090FaMap); $common->updateSetting("enableTwitterNotifications", $enableTwitterNotifications); $common->updateSetting("twitterUserName", $_POST['twitterUserName']); $common->updateSetting("twitterConsumerKey", $_POST['twitterConsumerKey']); $common->updateSetting("twitterConsumerSecret", $_POST['twitterConsumerSecret']); $common->updateSetting("twitterAccessToken", $_POST['twitterAccessToken']); $common->updateSetting("twitterAccessTokenSecret", $_POST['twitterAccessTokenSecret']); // Purge older flight positions. if (isset($_POST['purgepositions'])) { $dbh = $common->pdoOpen(); $sql = "DELETE FROM ".$settings::db_prefix."positions WHERE time < :purgeDate"; $sth = $dbh->prepare($sql); $sth->bindParam(':purgeDate', $_POST['purgepositionspicker'], PDO::PARAM_STR, 100); $sth->execute(); $sth = NULL; $dbh = NULL; } // Set updated to TRUE since settings were updated. $updated = TRUE; } // Get notification settings. $notifications = NULL; $savedFlights = array(); if ($settings::db_driver == "xml") { // XML $savedFlights = simplexml_load_file($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR."data".DIRECTORY_SEPARATOR."notifications.xml"); foreach ($savedFlights as $savedFlight) { $notifications = ltrim($notifications.",".$savedFlight->name, ','); } } else { //PDO $dbh = $common->pdoOpen(); $sql = "SELECT * FROM ".$settings::db_prefix."notifications"; $sth = $dbh->prepare($sql); $sth->execute(); $savedFlights = $sth->fetchAll(); $sth = NULL; $dbh = NULL; foreach ($savedFlights as $savedFlight) { $notifications = ltrim($notifications.",".$savedFlight['flight'], ','); } } $enableNotifications = $common->getSetting("enableNotifications"); $enableTwitterNotifications = $common->getSetting("enableTwitterNotifications"); $twitterUserName = $common->getSetting("twitterUserName"); $twitterConsumerKey = $common->getSetting("twitterConsumerKey"); $twitterConsumerSecret = $common->getSetting("twitterConsumerSecret "); $twitterAccessToken = $common->getSetting("twitterAccessToken"); $twitterAccessTokenSecret = $common->getSetting("twitterAccessTokenSecret"); // Get general settings from settings.xml. $siteName = $common->getSetting("siteName"); $currentTemplate = $common->getSetting("template"); $defaultPage = $common->getSetting("defaultPage"); $dateFormat = $common->getSetting("dateFormat"); $timeZone = $common->getSetting("timeZone"); // Get navigation settings from settings.xml. $enableFlights = $common->getSetting("enableFlights"); $enableBlog = $common->getSetting("enableBlog"); $enableInfo = $common->getSetting("enableInfo"); $enableGraphs = $common->getSetting("enableGraphs"); $enableDump1090 = $common->getSetting("enableDump1090"); $enableDump978 = $common->getSetting("enableDump978"); $enablePfclient = $common->getSetting("enablePfclient"); $useDump1090FaMap = $common->getSetting("useDump1090FaMap"); // Get aggregate site settings from settings.xml. $enableFlightAwareLink = $common->getSetting("enableFlightAwareLink"); $flightAwareLogin = $common->getSetting("flightAwareLogin"); $flightAwareSite = $common->getSetting("flightAwareSite"); $enablePlaneFinderLink = $common->getSetting("enablePlaneFinderLink"); $planeFinderReceiver = $common->getSetting("planeFinderReceiver"); $enableFlightRadar24Link = $common->getSetting("enableFlightRadar24Link"); $flightRadar24Id = $common->getSetting("flightRadar24Id"); $enableAdsbExchangeLink = $common->getSetting("enableAdsbExchangeLink"); // Get units of measurement setting from settings.xml. $measurementRange = $common->getSetting("measurementRange"); $measurementTemperature = $common->getSetting("measurementTemperature"); $measurementBandwidth = $common->getSetting("measurementBandwidth"); // Get the network interface from settings.xml. $networkInterface = $common->getSetting("networkInterface"); // Create an array of all directories in the template folder. $templates = array(); $path = "../templates/"; $directoryHandle = @opendir($path) or die('Unable to open directory "'.$path.'".'); while($templateDirectory = readdir($directoryHandle)) { if (is_dir($path."/".$templateDirectory)) { if ($templateDirectory != "." && $templateDirectory != "..") { array_push($templates, $templateDirectory); } } } closedir($directoryHandle); // Function used to format offsets of timezones. function formatOffset($offset) { return sprintf('%+03d:%02u', floor($offset / 3600), floor(abs($offset) % 3600 / 60)); } $utc = new DateTimeZone('UTC'); $dt = new DateTime('now', $utc); //////////////// // BEGIN HTML require_once('includes/header.inc.php'); // Display the updated message if settings were updated. if ($updated) { ?>