/** * Set up the various views: a site-wide template; and a per-action view. * Also deal with selecting (or issuing messages to the user) the current * database and table. * * @return void */ public function before() { parent::before(); $this->dbms = new WebDB_DBMS(); try { $this->dbms->connect(); $this->template->databases = $this->dbms->list_dbs(); $this->_set_database(); $this->_set_table(); } catch (Database_Exception $e) { if (!Auth::instance()->logged_in()) { $this->add_flash_message('Unable to connect. Please log in.'); $this->redirect('login'); } $this->template->databases = array(); $this->add_template_message('Initialisation error: ' . $e->getMessage()); } }
public function before() { $this->dbms = new WebDB_DBMS(); $this->dbms->connect(); $dbname = $this->request->param('dbname'); $this->database = $this->dbms->get_database($dbname); $this->selected_tables = array(); foreach ($this->database->get_tables() as $table) { // If any tables are requested, only show them if (count($_GET) > 0) { if (isset($_GET[$table->get_name()])) { $this->selected_tables[] = $table->get_name(); } } else { $referenced = count($table->get_referencing_tables()) > 0; $referencing = count($table->get_referenced_tables()) > 0; if ($referenced or $referencing) { $this->selected_tables[] = $table->get_name(); } } } }
public function action_login() { $this->template->set_global('database', FALSE); $this->template->set_global('table', FALSE); $this->template->set_global('databases', array()); $this->template->set_global('tables', array()); $this->view->return_to = Arr::get($_REQUEST, 'return_to', ''); if (Arr::get($_POST, 'login', FALSE)) { $username = trim(Arr::get($_POST, 'username', '')); $password = trim(Arr::get($_POST, 'password', '')); try { $this->dbms->username($username); $this->dbms->password(empty($password) ? NULL : $password); if ($this->dbms->connect()) { $this->add_flash_message('You are now logged in.', 'info'); $this->request->redirect($this->view->return_to); } else { $this->add_template_message('Login failed. Please try again.'); } } catch (Exception $e) { $this->add_template_message($e->getMessage()); } } }