diff --git a/build/portal/html/classes/common.class.php b/build/portal/html/classes/common.class.php index 3f13f32..681c739 100644 --- a/build/portal/html/classes/common.class.php +++ b/build/portal/html/classes/common.class.php @@ -30,9 +30,84 @@ class common { - //////////////////////////////////////// - // Check if page load is a post back. + // PDO Database Access + ///////////////////////// + + // Open a connection to the database. + function pdoOpen() { + switch(setting::database->driver) { + case 'mysql': + $dsn = "mysql:host=".settings::database->host.";dbname=".settings::database->database; + break; + case 'sqlsrv': + $dsn = "sqlsrv:server=".settings::database->host.";database=".settings::database->database; + break; + case 'pgsql': + $dsn = "pgsql:host=".settings::database->host.";dbname=".settings::database->database; + break; + case 'sqlite': + $dsn = "sqlite:".settings::database->database; + break; + } + $dbh = new PDO($dsn, settings::database->username, settings::database->password); + if (setting::database->driver = 'sqlite') + $dbh = new PDO($dsn); + if (settings::pdoDebug == TRUE) + $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + return $dbh; + } + // Returns the value for the specified setting name. + public static function pdoGetSetting($name, $dbh) { + global $dbh; + $sql = "SELECT value FROM ".settings::database->prefix."settings WHERE name = :name"; + $sth = $dbh->prepare($sql); + $sth->bindParam(':name', $name, PDO::PARAM_STR); + $sth->execute(); + $row = $sth->fetch(); + $sth = NULL; + return $row['value']; + } + + // Updates the value for the specified setting name. + function pdoUpdateSetting($name, $value, $dbh) { + global $dbh; + $sql = "UPDATE ".settings::database->prefix."settings SET value = :value WHERE name = :name"; + $sth = $dbh->prepare($sql); + $sth->bindParam(':value', $value, PDO::PARAM_STR, 20000); + $sth->bindParam(':name', $name, PDO::PARAM_STR, 50); + $sth->execute(); + $sth = NULL; + return; + } + + // XML Data Storage + ////////////////////// + + // Returns the value for the specified setting name. + function getSetting($name) { + $settings = simplexml_load_file($_SERVER['DOCUMENT_ROOT']."/data/settings.xml") or die("Error: Cannot create settings object"); + foreach ($settings as $setting) { + if ($setting->name == $name) { + return $setting->value; + } + } + return ""; + } + + // Updates the value for the specified setting name. + function updateSetting($name, $value) { + $settings = simplexml_load_file("../data/settings.xml") or die("Error: Cannot create settings object"); + foreach ($settings->xpath("setting[name='".$name."']") as $setting) { + $setting->value = $value; + } + file_put_contents("../data/settings.xml", $settings->asXML()); + } + + // Functions Not Related To Data Retrieval + ///////////////////////////////////////////// + + // Check if page load is a post back. function postBack() { if (empty($_SERVER['HTTP_REFERER'])) { return FALSE; @@ -46,9 +121,7 @@ return FALSE; } - ///////////////////////////////////// // Return a boolean from a string. - function stringToBoolean($value) { switch(strtoupper($value)) { case 'TRUE': return TRUE; @@ -57,37 +130,12 @@ } } - /////////////////////////////////////////////////////// - // Returns the value for the specified setting name. - - function getSetting($name) { - $settings = simplexml_load_file($_SERVER['DOCUMENT_ROOT']."/data/settings.xml") or die("Error: Cannot create settings object"); - foreach ($settings as $setting) { - if ($setting->name == $name) { - return $setting->value; - } - } - return ""; - } - - /////////////////////////////////////////////////////// - // Updates the value for the specified setting name. - - function updateSetting($name, $value) { - $settings = simplexml_load_file("../data/settings.xml") or die("Error: Cannot create settings object"); - foreach ($settings->xpath("setting[name='".$name."']") as $setting) { - $setting->value = $value; - } - file_put_contents("../data/settings.xml", $settings->asXML()); - } - - ////////////////////////////////////////////////////////// // Returns the supplied file name without an extension. - function removeExtension($fileName) { return pathinfo($fileName, PATHINFO_FILENAME); } + // Remove all HTML tags from a string. function removeHtmlTags($string) { $string = preg_replace ('/<[^>]*>/', ' ', $string); $string = str_replace("\r", '', $string); @@ -97,6 +145,11 @@ return $string; } + // Remove HTML from a string and shorten to the specified length. + function cleanAndShortenString($string, $length) { + return substr($this->removeHtmlTags($string), 0, $length); + } + // Pagination. function paginateArray($inArray, $page, $itemsPerPage) { $page = $page < 1 ? 1 : $page; @@ -115,11 +168,6 @@ return substr($string, $ini, $len); } - // Remove/clean HTML from a string and shorten to the specified length. - function cleanAndShortenString($string, $length) { - return substr($this->removeHtmlTags($string), 0, $length); - } - // Returns the base URL from the requested URL. function getBaseUrl(){ if(isset($_SERVER['HTTPS'])){ diff --git a/build/portal/html/classes/settings.class.php b/build/portal/html/classes/settings.class.php new file mode 100644 index 0000000..0731993 --- /dev/null +++ b/build/portal/html/classes/settings.class.php @@ -0,0 +1,49 @@ + 'xml', + 'database' => 'data/adsb-receiver.db', + 'username' => NULL, + 'password' => NULL, + 'host' => NULL, + 'prefix' => NULL, + ); + + // PDO Settings + const pdoDebug = TRUE; + + // Release Information + const thisRelease = '2016-02-18'; + } +?> \ No newline at end of file diff --git a/build/portal/html/install/index.php b/build/portal/html/install/index.php new file mode 100644 index 0000000..c2e7124 --- /dev/null +++ b/build/portal/html/install/index.php @@ -0,0 +1,96 @@ + settings::thisRelease) { + header ("Location: upgrade.php"); + } + + // Begin Installation + //////////////////////// + + $applicationDirectory = preg_replace( '~[/\\\\][^/\\\\]*$~', DIRECTORY_SEPARATOR, getcwd()); + + if (is_writable($applicationDirectory.'data')) { + + } +?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build/portal/html/install/upgrade.php b/build/portal/html/install/upgrade.php new file mode 100644 index 0000000..b06ca12 --- /dev/null +++ b/build/portal/html/install/upgrade.php @@ -0,0 +1,31 @@ + \ No newline at end of file