2012-01-30 07:57:17 -05:00
|
|
|
<?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
|
|
|
|
*/
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Window controlling addtion of database connections
|
|
|
|
*/
|
|
|
|
class Add_DB extends GtkWindow {
|
2012-01-31 16:19:34 -05:00
|
|
|
|
|
|
|
var $dbtype, $host, $user, $password, $database;
|
2012-01-30 07:57:17 -05:00
|
|
|
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
2012-01-31 12:42:38 -05:00
|
|
|
|
|
|
|
$this->set_title("OpenSQLManager - Add Database Connection");
|
|
|
|
|
|
|
|
// Add the Vbox, and show the window
|
|
|
|
$this->add($this->_layout());
|
|
|
|
$this->show_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Window layout
|
|
|
|
*
|
|
|
|
* @return GtkVBox
|
|
|
|
*/
|
|
|
|
private function _layout()
|
|
|
|
{
|
|
|
|
$table = new GtkTable();
|
|
|
|
|
2012-01-31 16:29:48 -05:00
|
|
|
$db_types = $this->get_available_dbs();
|
2012-01-31 12:42:38 -05:00
|
|
|
|
2012-01-31 16:19:34 -05:00
|
|
|
//Table attach
|
|
|
|
//$tbl->attach(left_start, right_stop, top_start, bottom_stop)
|
|
|
|
|
2012-02-01 10:51:06 -05:00
|
|
|
// Placeholder vars for y values, so that rows can be
|
|
|
|
// easily moved
|
|
|
|
$y1 = -1;
|
|
|
|
$y2 = 0;
|
|
|
|
|
|
|
|
// Database type
|
2012-01-31 16:19:34 -05:00
|
|
|
{
|
|
|
|
$dbtypelbl = new GtkLabel("Database Type");
|
|
|
|
$this->dbtype = GtkComboBox::new_text();
|
|
|
|
$typealign = new GtkAlignment(0, 0.5, 0, 0);
|
|
|
|
$typealign->add($dbtypelbl);
|
|
|
|
|
|
|
|
foreach($db_types as $t)
|
|
|
|
{
|
|
|
|
$this->dbtype->append_text($t);
|
|
|
|
}
|
|
|
|
|
2012-02-01 10:51:06 -05:00
|
|
|
$table->attach($typealign, 0, 1, ++$y1, ++$y2);
|
|
|
|
$table->attach($this->dbtype, 1, 2, $y1, $y2);
|
2012-01-31 16:19:34 -05:00
|
|
|
|
|
|
|
}
|
2012-01-31 12:42:38 -05:00
|
|
|
|
2012-02-01 10:51:06 -05:00
|
|
|
// Host
|
2012-01-31 12:42:38 -05:00
|
|
|
{
|
2012-01-31 16:19:34 -05:00
|
|
|
$hostlbl = new GtkLabel("DB Host");
|
|
|
|
$this->host = new GtkEntry();
|
|
|
|
$hostalign = new GtkAlignment(0, 0.5, 0, 0);
|
|
|
|
$hostalign->add($hostlbl);
|
|
|
|
|
2012-02-01 10:51:06 -05:00
|
|
|
$table->attach($hostalign, 0, 1, ++$y1, ++$y2);
|
|
|
|
$table->attach($this->host, 1, 2, $y1, $y2);
|
2012-01-31 16:19:34 -05:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:51:06 -05:00
|
|
|
// Username
|
2012-01-31 16:19:34 -05:00
|
|
|
{
|
|
|
|
$userlbl = new GtkLabel("DB User");
|
|
|
|
$this->user = new GtkEntry();
|
|
|
|
$useralign = new GtkAlignment(0, 0.5, 0, 0);
|
|
|
|
$useralign->add($userlbl);
|
|
|
|
|
2012-02-01 10:51:06 -05:00
|
|
|
$table->attach($useralign, 0, 1, ++$y1, ++$y2);
|
|
|
|
$table->attach($this->user, 1, 2, $y1, $y2);
|
2012-01-31 12:42:38 -05:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:51:06 -05:00
|
|
|
// Password
|
2012-01-31 16:19:34 -05:00
|
|
|
{
|
|
|
|
$passlbl = new GtkLabel("DB Password");
|
|
|
|
$this->pass = new GtkEntry();
|
|
|
|
$passalign = new GtkAlignment(0, 0.5, 0, 0);
|
|
|
|
$passalign->add($passlbl);
|
|
|
|
|
2012-02-01 10:51:06 -05:00
|
|
|
$table->attach($passalign, 0, 1, ++$y1, ++$y2);
|
|
|
|
$table->attach($this->pass, 1, 2, $y1, $y2);
|
2012-01-31 16:19:34 -05:00
|
|
|
}
|
2012-01-31 12:42:38 -05:00
|
|
|
|
|
|
|
|
|
|
|
return $table;
|
2012-01-30 07:57:17 -05:00
|
|
|
}
|
2012-01-31 16:29:48 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks what database drivers are available
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function get_available_dbs()
|
|
|
|
{
|
|
|
|
$drivers = array();
|
|
|
|
|
|
|
|
// Check if there is pdo support
|
|
|
|
if( ! function_exists('pdo_drivers'))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-01-31 17:52:46 -05:00
|
|
|
// Add PDO drivers
|
|
|
|
foreach(pdo_drivers() as $d)
|
|
|
|
{
|
|
|
|
// Skip sqlite2
|
|
|
|
if($d === 'sqlite2')
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$drivers[] = $d;
|
|
|
|
}
|
2012-01-31 16:29:48 -05:00
|
|
|
|
2012-01-31 17:52:46 -05:00
|
|
|
// Add firebird support, if exists
|
2012-01-31 16:29:48 -05:00
|
|
|
if(function_exists('ibase_connect'))
|
|
|
|
{
|
|
|
|
$drivers[] = "Firebird";
|
|
|
|
}
|
|
|
|
|
|
|
|
sort($drivers);
|
|
|
|
|
|
|
|
return $drivers;
|
|
|
|
}
|
2012-01-30 07:57:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// End of add_db.php
|