Adding pdo support.

pull/113/head
Joe Prochazka 2016-02-22 16:56:26 -05:00
rodzic 6c435eb51f
commit fd142d14ce
4 zmienionych plików z 259 dodań i 35 usunięć

Wyświetl plik

@ -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'])){

Wyświetl plik

@ -0,0 +1,49 @@
<?php
/////////////////////////////////////////////////////////////////////////////////////
// ADS-B RECEIVER PORTAL //
// =============================================================================== //
// Copyright and Licensing Information: //
// //
// The MIT License (MIT) //
// //
// Copyright (c) 2015-2016 Joseph A. Prochazka //
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy //
// of this software and associated documentation files (the "Software"), to deal //
// in the Software without restriction, including without limitation the rights //
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell //
// copies of the Software, and to permit persons to whom the Software is //
// furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in all //
// copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE //
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //
// SOFTWARE. //
/////////////////////////////////////////////////////////////////////////////////////
class settings {
// Database Settings
const $database = array(
'driver' => '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';
}
?>

Wyświetl plik

@ -0,0 +1,96 @@
<?php
/////////////////////////////////////////////////////////////////////////////////////
// ADS-B RECEIVER PORTAL //
// =============================================================================== //
// Copyright and Licensing Information: //
// //
// The MIT License (MIT) //
// //
// Copyright (c) 2015-2016 Joseph A. Prochazka //
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy //
// of this software and associated documentation files (the "Software"), to deal //
// in the Software without restriction, including without limitation the rights //
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell //
// copies of the Software, and to permit persons to whom the Software is //
// furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in all //
// copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE //
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //
// SOFTWARE. //
/////////////////////////////////////////////////////////////////////////////////////
require_once('classes/settings.class.php');
$settings = new settings();
// The most current stable release.
$currentRelease = "2016-02-18";
// Begin the upgrade process if this release is newer than what is installed.
if ($currentRelease > settings::thisRelease) {
header ("Location: upgrade.php");
}
// Begin Installation
////////////////////////
$applicationDirectory = preg_replace( '~[/\\\\][^/\\\\]*$~', DIRECTORY_SEPARATOR, getcwd());
if (is_writable($applicationDirectory.'data')) {
}
?>
<!-- DATA STORAGE -->
<select name="databaseType">
<option value="xml">XML</option>
<option value="sqlite">SQLite</option>
<option value="mysql">MySQL</option>
<option value="pgsql">PostgreSQL</option>
<option value="sqlsrv">Microsoft SQL Server</option>
</select>
<label for="dbHost">Database Server</label>
<input type="text" name="dbHost">
<label for="dbUser">Database User</label>
<input type="text" name="dbUser">
<label for="dbPassword">Database Password</label>
<input type="password" name="dbPassword">
<label for="dbName">Database Name</label>
<input type="text" name="dbName">
<label for="dbPrefix">Database Prefix</label>
<input type="text" name="dbPrefix">
<input type="submit" name="testConnection" value="Test Connection">
<!-- ADMINISTRATOR -->
<label for="adminName">Administrator Name</label>
<input type="text" name="adminName">
<label for="adminEmail">Administrator Email Address</label>
<input type="text" name="adminEmail">
<label for="AdminLogin">Administrator Login</label>
<input type="text" name="AdminLogin">
<label for="adminPassword1">Administrator Password</label>
<input type="password" name="adminPassword1">
<label for="adminPassword2">Repeat Password</label>
<input type="password" name="adminPassword2">
<input type="submit" name="createAccount" value="Create Account">

Wyświetl plik

@ -0,0 +1,31 @@
<?php
/////////////////////////////////////////////////////////////////////////////////////
// ADS-B RECEIVER PORTAL //
// =============================================================================== //
// Copyright and Licensing Information: //
// //
// The MIT License (MIT) //
// //
// Copyright (c) 2015-2016 Joseph A. Prochazka //
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy //
// of this software and associated documentation files (the "Software"), to deal //
// in the Software without restriction, including without limitation the rights //
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell //
// copies of the Software, and to permit persons to whom the Software is //
// furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in all //
// copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE //
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //
// SOFTWARE. //
/////////////////////////////////////////////////////////////////////////////////////
?>