Various Updates
Added settings class, abstracted path, abstracted adding rows to db add table in add_db.php
This commit is contained in:
parent
4f49c8b9be
commit
d0c1810818
69
src/common/settings.php
Normal file
69
src/common/settings.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* OpenSQLManager
|
||||||
|
*
|
||||||
|
* Free Database manager for Open Source Databases
|
||||||
|
*
|
||||||
|
* @author Timothy J. Warren
|
||||||
|
* @copyright Copyright (c) 2012
|
||||||
|
* @link https://github.com/aviat4ion/OpenSQLManager
|
||||||
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for manipulating datbase connections, and program settings
|
||||||
|
*
|
||||||
|
* Use JSON for compatibility
|
||||||
|
*/
|
||||||
|
class Settings {
|
||||||
|
|
||||||
|
protected $current;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the settings file
|
||||||
|
*/
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
$path = BASE_DIR.'/settings.json';
|
||||||
|
|
||||||
|
if( ! is_file($path))
|
||||||
|
{
|
||||||
|
//Create the file!
|
||||||
|
touch($path);
|
||||||
|
$this->current = new stdClass();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->current = json_decode(file_get_contents($path));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the settings file on close, just to be safe
|
||||||
|
*/
|
||||||
|
function __destruct()
|
||||||
|
{
|
||||||
|
file_put_contents(json_encode($this->current), BASE_DIR.'/settings.json');
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a database connection
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param string $host
|
||||||
|
* @param string $user
|
||||||
|
* @param string $pass
|
||||||
|
*/
|
||||||
|
function add_db($type, $host, $user, $pass)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// End of settings.php
|
@ -46,4 +46,5 @@ class firebird {
|
|||||||
{
|
{
|
||||||
@ibase_close($this->conn);
|
@ibase_close($this->conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// End of firebird.php
|
@ -57,12 +57,14 @@ function do_include($path)
|
|||||||
require_once($path);
|
require_once($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
$dir = dirname(__FILE__);
|
define('BASE_DIR', dirname(__FILE__));
|
||||||
|
|
||||||
// Load modules
|
// Load modules
|
||||||
|
// Load everything so that we don't have to do requires later
|
||||||
{
|
{
|
||||||
array_map('do_include', glob("{$dir}/databases/*.php"));
|
array_map('do_include', glob(BASE_DIR . "/common/*.php"));
|
||||||
array_map('do_include', glob("{$dir}/windows/*.php"));
|
array_map('do_include', glob(BASE_DIR . "/databases/*.php"));
|
||||||
|
array_map('do_include', glob(BASE_DIR . "/windows/*.php"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the main window
|
// Create the main window
|
||||||
|
@ -44,7 +44,12 @@ class Add_DB extends GtkWindow {
|
|||||||
//Table attach
|
//Table attach
|
||||||
//$tbl->attach(left_start, right_stop, top_start, bottom_stop)
|
//$tbl->attach(left_start, right_stop, top_start, bottom_stop)
|
||||||
|
|
||||||
//Row 1 - Database type
|
// Placeholder vars for y values, so that rows can be
|
||||||
|
// easily moved
|
||||||
|
$y1 = -1;
|
||||||
|
$y2 = 0;
|
||||||
|
|
||||||
|
// Database type
|
||||||
{
|
{
|
||||||
$dbtypelbl = new GtkLabel("Database Type");
|
$dbtypelbl = new GtkLabel("Database Type");
|
||||||
$this->dbtype = GtkComboBox::new_text();
|
$this->dbtype = GtkComboBox::new_text();
|
||||||
@ -56,42 +61,42 @@ class Add_DB extends GtkWindow {
|
|||||||
$this->dbtype->append_text($t);
|
$this->dbtype->append_text($t);
|
||||||
}
|
}
|
||||||
|
|
||||||
$table->attach($typealign, 0, 1, 0, 1);
|
$table->attach($typealign, 0, 1, ++$y1, ++$y2);
|
||||||
$table->attach($this->dbtype, 1, 2, 0, 1);
|
$table->attach($this->dbtype, 1, 2, $y1, $y2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Row 2 - Host
|
// Host
|
||||||
{
|
{
|
||||||
$hostlbl = new GtkLabel("DB Host");
|
$hostlbl = new GtkLabel("DB Host");
|
||||||
$this->host = new GtkEntry();
|
$this->host = new GtkEntry();
|
||||||
$hostalign = new GtkAlignment(0, 0.5, 0, 0);
|
$hostalign = new GtkAlignment(0, 0.5, 0, 0);
|
||||||
$hostalign->add($hostlbl);
|
$hostalign->add($hostlbl);
|
||||||
|
|
||||||
$table->attach($hostalign, 0, 1, 1, 2);
|
$table->attach($hostalign, 0, 1, ++$y1, ++$y2);
|
||||||
$table->attach($this->host, 1, 2, 1, 2);
|
$table->attach($this->host, 1, 2, $y1, $y2);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Row 3 - Username
|
// Username
|
||||||
{
|
{
|
||||||
$userlbl = new GtkLabel("DB User");
|
$userlbl = new GtkLabel("DB User");
|
||||||
$this->user = new GtkEntry();
|
$this->user = new GtkEntry();
|
||||||
$useralign = new GtkAlignment(0, 0.5, 0, 0);
|
$useralign = new GtkAlignment(0, 0.5, 0, 0);
|
||||||
$useralign->add($userlbl);
|
$useralign->add($userlbl);
|
||||||
|
|
||||||
$table->attach($useralign, 0, 1, 2, 3);
|
$table->attach($useralign, 0, 1, ++$y1, ++$y2);
|
||||||
$table->attach($this->user, 1, 2, 2, 3);
|
$table->attach($this->user, 1, 2, $y1, $y2);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Row 4 - Password
|
// Password
|
||||||
{
|
{
|
||||||
$passlbl = new GtkLabel("DB Password");
|
$passlbl = new GtkLabel("DB Password");
|
||||||
$this->pass = new GtkEntry();
|
$this->pass = new GtkEntry();
|
||||||
$passalign = new GtkAlignment(0, 0.5, 0, 0);
|
$passalign = new GtkAlignment(0, 0.5, 0, 0);
|
||||||
$passalign->add($passlbl);
|
$passalign->add($passlbl);
|
||||||
|
|
||||||
$table->attach($passalign, 0, 1, 3, 4);
|
$table->attach($passalign, 0, 1, ++$y1, ++$y2);
|
||||||
$table->attach($this->pass, 1, 2, 3, 4);
|
$table->attach($this->pass, 1, 2, $y1, $y2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ class Main extends GtkWindow {
|
|||||||
$dlg->set_website('https://github.com/aviat4ion/OpenSQLManager');
|
$dlg->set_website('https://github.com/aviat4ion/OpenSQLManager');
|
||||||
$dlg->set_website_label('Fork on Github');
|
$dlg->set_website_label('Fork on Github');
|
||||||
|
|
||||||
$dlg->set_license(file_get_contents("LICENSE"));
|
$dlg->set_license(file_get_contents(BASE_DIR . "/LICENSE"));
|
||||||
|
|
||||||
$dlg->set_authors(array(
|
$dlg->set_authors(array(
|
||||||
'Timothy J. Warren',
|
'Timothy J. Warren',
|
||||||
@ -220,6 +220,13 @@ class Main extends GtkWindow {
|
|||||||
return $conn_vbox;
|
return $conn_vbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns window for creating a new database connection
|
||||||
|
*
|
||||||
|
* @return Add_DB object
|
||||||
|
*/
|
||||||
function new_conn()
|
function new_conn()
|
||||||
{
|
{
|
||||||
return new Add_DB();
|
return new Add_DB();
|
||||||
|
Reference in New Issue
Block a user