Fix loading of existing database info for editing
Move global function to their own file
This commit is contained in:
parent
96ada089ee
commit
f2191c9ae4
99
index.php
99
index.php
@ -29,6 +29,7 @@ date_default_timezone_set('GMT');
|
||||
// Set the current directory as the base for included files
|
||||
define('BASE_DIR', dirname(__FILE__).'/sys');
|
||||
define('SETTINGS_DIR', dirname(__FILE__));
|
||||
define('PROGRAM_NAME', 'OpenSQLManager');
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
@ -118,104 +119,6 @@ if(function_exists('fbird_connect'))
|
||||
require_once("{$path}firebird_sql.php");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// ! Global Functions
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Convert an array to an object
|
||||
*
|
||||
* @param array $array
|
||||
* @return object
|
||||
*/
|
||||
function array_to_object($array)
|
||||
{
|
||||
if (is_object($array))
|
||||
{
|
||||
return $array;
|
||||
}
|
||||
|
||||
$obj = new StdClass();
|
||||
|
||||
foreach($array as $k => $v)
|
||||
{
|
||||
$obj->$k = $v;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create info dialog to retun an informational message
|
||||
*
|
||||
* @param string $message
|
||||
* @return void
|
||||
*/
|
||||
function alert($message)
|
||||
{
|
||||
$dialog = new GTKMessageDialog(
|
||||
NULL,
|
||||
Gtk::DIALOG_MODAL,
|
||||
Gtk::MESSAGE_INFO,
|
||||
Gtk::BUTTONS_OK,
|
||||
$message
|
||||
);
|
||||
|
||||
$dialog->set_position(Gtk::WIN_POS_CENTER);
|
||||
$dialog->run();
|
||||
$dialog->destroy();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create info dialog to retun an informational message
|
||||
*
|
||||
* @param string $message
|
||||
* @return void
|
||||
*/
|
||||
function error($message)
|
||||
{
|
||||
$dialog = new GTKMessageDialog(
|
||||
NULL,
|
||||
Gtk::DIALOG_MODAL,
|
||||
Gtk::MESSAGE_ERROR,
|
||||
Gtk::BUTTONS_OK,
|
||||
$message
|
||||
);
|
||||
|
||||
$dialog->set_position(Gtk::WIN_POS_CENTER);
|
||||
$dialog->run();
|
||||
$dialog->destroy();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates a binary confirmation dialog
|
||||
*
|
||||
* @param string $message
|
||||
* @return bool
|
||||
*/
|
||||
function confirm($message)
|
||||
{
|
||||
$dialog = new GTKMessageDialog(
|
||||
NULL,
|
||||
Gtk::DIALOG_MODAL,
|
||||
Gtk::MESSAGE_QUESTION,
|
||||
Gtk::BUTTONS_YES_NO,
|
||||
$message
|
||||
);
|
||||
|
||||
$dialog->set_position(Gtk::WIN_POS_CENTER);
|
||||
$answer = $dialog->run();
|
||||
$dialog->destroy();
|
||||
|
||||
return ($answer === Gtk::RESPONSE_YES) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
// Create the main window
|
||||
|
146
sys/common/functions.php
Normal file
146
sys/common/functions.php
Normal file
@ -0,0 +1,146 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// ! Global Functions
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Convert an array to an object
|
||||
*
|
||||
* @param array $array
|
||||
* @return object
|
||||
*/
|
||||
function array_to_object($array)
|
||||
{
|
||||
if (is_object($array))
|
||||
{
|
||||
return $array;
|
||||
}
|
||||
|
||||
$obj = new StdClass();
|
||||
|
||||
foreach($array as $k => $v)
|
||||
{
|
||||
$obj->$k = $v;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create info dialog to retun an informational message
|
||||
*
|
||||
* @param string $message
|
||||
* @return void
|
||||
*/
|
||||
function alert($message)
|
||||
{
|
||||
$dialog = new GTKMessageDialog(
|
||||
NULL,
|
||||
Gtk::DIALOG_MODAL,
|
||||
Gtk::MESSAGE_INFO,
|
||||
Gtk::BUTTONS_OK,
|
||||
$message
|
||||
);
|
||||
|
||||
$dialog->set_position(Gtk::WIN_POS_CENTER);
|
||||
$dialog->run();
|
||||
$dialog->destroy();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create info dialog to retun an informational message
|
||||
*
|
||||
* @param string $message
|
||||
* @return void
|
||||
*/
|
||||
function error($message)
|
||||
{
|
||||
$dialog = new GTKMessageDialog(
|
||||
NULL,
|
||||
Gtk::DIALOG_MODAL,
|
||||
Gtk::MESSAGE_ERROR,
|
||||
Gtk::BUTTONS_OK,
|
||||
$message
|
||||
);
|
||||
|
||||
$dialog->set_position(Gtk::WIN_POS_CENTER);
|
||||
$dialog->run();
|
||||
$dialog->destroy();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates a binary confirmation dialog
|
||||
*
|
||||
* @param string $message
|
||||
* @return bool
|
||||
*/
|
||||
function confirm($message)
|
||||
{
|
||||
$dialog = new GTKMessageDialog(
|
||||
NULL,
|
||||
Gtk::DIALOG_MODAL,
|
||||
Gtk::MESSAGE_QUESTION,
|
||||
Gtk::BUTTONS_YES_NO,
|
||||
$message
|
||||
);
|
||||
|
||||
$dialog->set_position(Gtk::WIN_POS_CENTER);
|
||||
$answer = $dialog->run();
|
||||
$dialog->destroy();
|
||||
|
||||
return ($answer === Gtk::RESPONSE_YES) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Display About menu with version information
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function about()
|
||||
{
|
||||
$dlg = new GtkAboutDialog();
|
||||
|
||||
$dlg->set_program_name(PROGRAM_NAME);
|
||||
$dlg->set_version('0.1.0pre');
|
||||
|
||||
$dlg->set_copyright("Copyright (c) ".date('Y')." Timothy J. Warren");
|
||||
|
||||
$dlg->set_website('https://github.com/aviat4ion/OpenSQLManager');
|
||||
$dlg->set_website_label('Fork on Github');
|
||||
|
||||
$dlg->set_license(file_get_contents(BASE_DIR . "/LICENSE"));
|
||||
|
||||
$dlg->set_authors(array(
|
||||
'Timothy J. Warren',
|
||||
//'Nathan Dupuie',
|
||||
));
|
||||
|
||||
/*$dlg->set_artists(array(
|
||||
'Nathan Dupuie',
|
||||
));*/
|
||||
|
||||
$dlg->run();
|
||||
|
||||
$dlg->destroy();
|
||||
}
|
||||
|
||||
// End of functions.php
|
@ -77,42 +77,6 @@ class Main extends GtkWindow {
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Display About menu with version information
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function about()
|
||||
{
|
||||
$dlg = new GtkAboutDialog();
|
||||
$dlg->set_transient_for($this);
|
||||
|
||||
$dlg->set_program_name($this->get_title());
|
||||
$dlg->set_version('0.1.0pre');
|
||||
|
||||
$dlg->set_copyright("Copyright (c) ".date('Y')." Timothy J. Warren");
|
||||
|
||||
$dlg->set_website('https://github.com/aviat4ion/OpenSQLManager');
|
||||
$dlg->set_website_label('Fork on Github');
|
||||
|
||||
$dlg->set_license(file_get_contents(BASE_DIR . "/LICENSE"));
|
||||
|
||||
$dlg->set_authors(array(
|
||||
'Timothy J. Warren',
|
||||
//'Nathan Dupuie',
|
||||
));
|
||||
|
||||
/*$dlg->set_artists(array(
|
||||
'Nathan Dupuie',
|
||||
));*/
|
||||
|
||||
$dlg->run();
|
||||
|
||||
$dlg->destroy();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Quits the GTK loop
|
||||
*/
|
||||
@ -131,7 +95,7 @@ class Main extends GtkWindow {
|
||||
*/
|
||||
private function _main_layout()
|
||||
{
|
||||
$this->set_title('OpenSQLManager');
|
||||
$this->set_title(PROGRAM_NAME);
|
||||
|
||||
// Quit when this window is closed
|
||||
$this->connect_simple('destroy', array('gtk', 'main_quit'));
|
||||
@ -202,7 +166,7 @@ class Main extends GtkWindow {
|
||||
{
|
||||
// Set up the about item
|
||||
$about = new GtkImageMenuItem(GTK::STOCK_ABOUT);
|
||||
$about->connect_simple('activate', array($this, 'about'));
|
||||
$about->connect_simple('activate', 'about');
|
||||
$help_menu->append($about);
|
||||
|
||||
// Add the top level menu to the menubar
|
||||
|
@ -120,6 +120,9 @@ class DB_Info_Widget extends GtkTable {
|
||||
{
|
||||
$this->db_file->set_filename($db->file);
|
||||
}
|
||||
|
||||
$this->pass->set_text($db->pass);
|
||||
$this->conn_db->set_text($db->conn_db);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,39 @@ class DB_tabs extends GTKNotebook {
|
||||
*/
|
||||
public function get_db_tabs(&$conn)
|
||||
{
|
||||
print_r($conn->get_tables());
|
||||
$tables = new Data_Grid();
|
||||
$table_model = $tables->get_model();
|
||||
$table_data = $conn->get_tables();
|
||||
|
||||
foreach($table_data as $t)
|
||||
{
|
||||
$iter = $table_model->append();
|
||||
$table_model->set($iter, 0, $t);
|
||||
}
|
||||
|
||||
$cell_renderer = new GtkCellRendererText();
|
||||
$tables->insert_column_with_data_func(0, 'Table Name', $cell_renderer, array($this, 'add_data_col'));
|
||||
|
||||
$this->add_tab('Tables', $tables);
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Adds a column of data to the model
|
||||
*
|
||||
* @param GtkTreeViewColumn $col
|
||||
* @param GtkCellRenderer $cell
|
||||
* @param GtkTreeModel $model
|
||||
* @param GtkTreeIter $iter
|
||||
* @param int $i
|
||||
* @return void
|
||||
*/
|
||||
public function add_data_col($col, $cell, $model, $iter, $i=0)
|
||||
{
|
||||
$data = $model->get_value($iter, $i);
|
||||
$cell->set_property('text', $data);
|
||||
}
|
||||
}
|
||||
// End of db_tabs.php
|
||||
|
Reference in New Issue
Block a user