diff --git a/src/common/settings.php b/src/common/settings.php index df5d6f7..2663272 100644 --- a/src/common/settings.php +++ b/src/common/settings.php @@ -19,7 +19,7 @@ */ class Settings { - protected $current; + private $current; /** * Load the settings file @@ -49,16 +49,6 @@ class Settings { // -------------------------------------------------------------------------- - /** - * Save the settings file on close, just to be safe - */ - public function __destruct() - { - file_put_contents(BASE_DIR.'/settings.json', json_encode($this->current)); - } - - // -------------------------------------------------------------------------- - /** * Magic method to simplify isset checking for config options * @@ -67,7 +57,9 @@ class Settings { */ public function __get($key) { - return (isset($this->current->{$key})) ? $this->current->{$key} : NULL; + return (isset($this->current->{$key}) && $key != "dbs") + ? $this->current->{$key} + : NULL; } // -------------------------------------------------------------------------- @@ -87,6 +79,7 @@ class Settings { } $this->current->{$key} = $val; + $this->write(); } // -------------------------------------------------------------------------- @@ -103,6 +96,29 @@ class Settings { { $this->current->dbs->{$name} = array(); $this->current->dbs->{$name} = $params; + + $this->write(); + } + else + { + return FALSE; + } + } + + // -------------------------------------------------------------------------- + + /** + * Edit a database connection + * + * @param string $name + * @param array $params + */ + public function edit_db($name, $params) + { + if(isset($this->current->dbs->{$name})) + { + $this->current->dbs->{$name} = $params; + $this->write(); } else { @@ -126,6 +142,7 @@ class Settings { // Remove the db name from the object unset($this->current->dbs->{$name}); + $this->write(); } // -------------------------------------------------------------------------- @@ -135,9 +152,19 @@ class Settings { * * @return array */ - public function get_dbs() - { - return $this->current->dbs; - } + public function get_dbs() + { + return $this->current->dbs; + } + + // -------------------------------------------------------------------------- + + /** + * Write the settings to the file + */ + public function write() + { + file_put_contents(BASE_DIR . '/settings.json', json_encode($this->current)); + } } // End of settings.php \ No newline at end of file diff --git a/src/databases/firebird.php b/src/databases/firebird.php index 7d87b62..b216980 100644 --- a/src/databases/firebird.php +++ b/src/databases/firebird.php @@ -254,6 +254,7 @@ SQL; /** * Run a prepared statement query + * * @param array $args * @return bool */ diff --git a/src/databases/firebird_manip.php b/src/databases/firebird_manip.php index e53b7d4..430ab50 100644 --- a/src/databases/firebird_manip.php +++ b/src/databases/firebird_manip.php @@ -17,7 +17,7 @@ * * PDO-firebird isn't stable, so this is a wrapper of the ibase_ public functions. */ -class firebird_manip extends db_manip{ +class firebird_manip extends db_manip { /** * Convienience public function to generate sql for creating a db table diff --git a/src/windows/add_db.php b/src/windows/add_db.php index 4f4bd4f..2babb07 100644 --- a/src/windows/add_db.php +++ b/src/windows/add_db.php @@ -77,13 +77,13 @@ class Add_DB extends GtkWindow { // DB File { $filelbl = new GtkLabel("Database file"); - $this->dbfile = new GtkFileChooserButton("Select a database file", + $this->db_file = new GtkFileChooserButton("Select a database file", Gtk::FILE_CHOOSER_ACTION_OPEN); $filealign = new GtkAlignment(0, 0.5, 0, 0); $filealign->add($filelbl); $table->attach($filealign, 0, 1, ++$y1, ++$y2); - $table->attach($this->dbfile, 1, 2, $y1, $y2); + $table->attach($this->db_file, 1, 2, $y1, $y2); } // Host @@ -185,10 +185,11 @@ class Add_DB extends GtkWindow { public function db_add() { $data = array( - 'type' => $this->dbtype->get_active_text(), + 'type' => strtolower($this->dbtype->get_active_text()), 'host' => $this->host->get_text(), 'user' => $this->user->get_text(), 'pass' => $this->pass->get_text(), + 'file' => $this->db_file->get_uri(), ); $this->settings->add_db($this->conn->get_text(), $data);