From 41210b37a9f8c17f89222d7b180772dbc5859579 Mon Sep 17 00:00:00 2001 From: Sebastian Mendel Date: Wed, 12 Apr 2006 15:26:25 +0000 Subject: [PATCH] cleanup - what a mess; fixed several undefined variables --- ChangeLog | 2 + libraries/db_table_exists.lib.php | 68 +++++++++++++++++++++---------- 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5052f64a9..8d20e0e62 100755 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ $Id$ $Source$ 2006-04-12 Sebastian Mendel + * libraries/db_table_exists.lib.php: + cleanup - what a mess; fixed several undefined variables * tbl_printview.php: fixed undefined variable by including libraries/tbl_properties_common.php * changelog.php: diff --git a/libraries/db_table_exists.lib.php b/libraries/db_table_exists.lib.php index a8897b218..e66135e6a 100644 --- a/libraries/db_table_exists.lib.php +++ b/libraries/db_table_exists.lib.php @@ -6,45 +6,69 @@ * Ensure the database and the table exist (else move to the "parent" script) * and display headers */ -if (!isset($is_db) || !$is_db) { - // Not a valid db name -> back to the welcome page +if (empty($is_db)) { if (isset($db) && strlen($db)) { $is_db = @PMA_DBI_select_db($db); + } else { + $is_db = false; } - if (!isset($db) || !strlen($db) || !$is_db) { - if (!defined('IS_TRANSFORMATION_WRAPPER')) { - PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . 'main.php?' . PMA_generate_common_url('', '', '&') . (isset($message) ? '&message=' . urlencode($message) : '') . '&reload=1'); + + if (! $is_db) { + // not a valid db name -> back to the welcome page + if (! defined('IS_TRANSFORMATION_WRAPPER')) { + $url_params = array('reload' => 1); + if (isset($message)) { + $url_params['message'] = $message; + } + PMA_sendHeaderLocation( + $cfg['PmaAbsoluteUri'] . 'main.php' + . PMA_generate_common_url($url_params, '&')); } exit; } } // end if (ensures db exists) -if (!isset($is_table) || !$is_table) { + +if (empty($is_table)) { // Not a valid table name -> back to the db_details.php if (isset($table) && strlen($table)) { - $is_table = PMA_DBI_try_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';', null, PMA_DBI_QUERY_STORE); + $result = PMA_DBI_try_query( + 'SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, true) . '\';', + null, PMA_DBI_QUERY_STORE); + $is_table = @PMA_DBI_num_rows($result); + PMA_DBI_free_result($result); + } else { + $is_table = false; } - if (! isset($table) && ! strlen($table) - || !($is_table && @PMA_DBI_num_rows($is_table))) { - $redirect = TRUE; - if (!defined('IS_TRANSFORMATION_WRAPPER')) { - $redirect = TRUE; + + if (! $is_table) { + if (! defined('IS_TRANSFORMATION_WRAPPER')) { if (isset($table) && strlen($table)) { - PMA_DBI_free_result($is_table); - // SHOW TABLES doesn't show temporary tables, so try select (as it can happen just in case temporary table, it should be fast): - $is_table2 = PMA_DBI_try_query('SELECT COUNT(*) FROM `' . PMA_sqlAddslashes($table, TRUE) . '`;', null, PMA_DBI_QUERY_STORE); - $redirect = !($is_table2 && @PMA_DBI_num_rows($is_table2)); - PMA_DBI_free_result($is_table2); + // SHOW TABLES doesn't show temporary tables, so try select + // (as it can happen just in case temporary table, it should be + // fast): + + // @todo should this check really only happen if IS_TRANSFORMATION_WRAPPER? + $result = PMA_DBI_try_query( + 'SELECT COUNT(*) FROM `' . PMA_sqlAddslashes($table, true) . '`;', + null, PMA_DBI_QUERY_STORE); + $is_table = ($result && @PMA_DBI_num_rows($result)); + PMA_DBI_free_result($result); } - if ($redirect) { - PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . 'db_details.php?' . PMA_generate_common_url($db, '', '&') . (isset($message) ? '&message=' . urlencode($message) : '') . '&reload=1'); + if (! $is_table) { + $url_params = array('reload' => 1, 'db' => $db); + if (isset($message)) { + $url_params['message'] = $message; + } + PMA_sendHeaderLocation( + $cfg['PmaAbsoluteUri'] . 'db_details.php' + . PMA_generate_common_url($url_params, '&')); } } - if ($redirect) { + + if (! $is_table) { exit; } - } elseif (isset($is_table)) { - PMA_DBI_free_result($is_table); } } // end if (ensures table exists) ?>