From 634a5b92a25a2f51495c02954cf2f61378fb16a2 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 30 Mar 2012 09:58:41 -0400 Subject: [PATCH] Dynamically add connections --- index.php | 25 ++++++++++++++++++++++ sys/windows/widgets/connection_sidebar.php | 12 +++++++++++ sys/windows/widgets/db_info_widget.php | 6 +++--- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 8243bb6..4494595 100644 --- a/index.php +++ b/index.php @@ -122,6 +122,31 @@ if(function_exists('fbird_connect')) // ! 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 * diff --git a/sys/windows/widgets/connection_sidebar.php b/sys/windows/widgets/connection_sidebar.php index 03f218f..e5d207f 100644 --- a/sys/windows/widgets/connection_sidebar.php +++ b/sys/windows/widgets/connection_sidebar.php @@ -96,6 +96,11 @@ class Connection_Sidebar extends GtkVBox { { foreach($db_conns as $name => $props) { + if (is_array($props)) + { + $props = array_to_object($props); + } + $db = $props; $db->name = $name; @@ -247,6 +252,13 @@ class Connection_Sidebar extends GtkVBox { */ public function refresh() { + $cols = $this->treeview->get_columns(); + + foreach($cols as $c) + { + $this->treeview->remove_column($c); + } + $this->_render(); } diff --git a/sys/windows/widgets/db_info_widget.php b/sys/windows/widgets/db_info_widget.php index b41b64b..bf842a5 100644 --- a/sys/windows/widgets/db_info_widget.php +++ b/sys/windows/widgets/db_info_widget.php @@ -39,7 +39,7 @@ class DB_Info_Widget extends GtkTable { $db->port = ''; $db->conn_db = ''; $db->dbtype = ''; - $db->db_file = NULL; + $db->file = NULL; } // Set up the form elements, with default values @@ -153,7 +153,7 @@ class DB_Info_Widget extends GtkTable { { $add_button->connect_simple("clicked", array($this, 'db_add')); } - + } // Test connection button @@ -279,7 +279,7 @@ class DB_Info_Widget extends GtkTable { // Pass to connection sidebar to update Connection_Sidebar::get_instance()->refresh(); - + // Let the user know the connection has been updated alert("Changes to database connection have been saved");