diff --git a/index.php b/index.php
index 159d68860..b9fe44ebf 100644
--- a/index.php
+++ b/index.php
@@ -26,7 +26,7 @@
* @uses PMA_VERSION
* @uses session_write_close()
* @uses time()
- * @uses getenv()
+ * @uses PMA_getenv()
* @uses header() to send charset
*/
@@ -46,8 +46,8 @@ session_write_close();
// Gets the host name
// loic1 - 2001/25/11: use the new globals arrays defined with php 4.1+
if (empty($HTTP_HOST)) {
- if (getenv('HTTP_HOST')) {
- $HTTP_HOST = getenv('HTTP_HOST');
+ if (PMA_getenv('HTTP_HOST')) {
+ $HTTP_HOST = PMA_getenv('HTTP_HOST');
} else {
$HTTP_HOST = '';
}
diff --git a/libraries/Table.class.php b/libraries/Table.class.php
index 686db7221..ee6ad22d5 100644
--- a/libraries/Table.class.php
+++ b/libraries/Table.class.php
@@ -1,6 +1,25 @@
getName();
}
+ function getOptions($engine = null)
+ {
+ if (null === $engine) {
+ $engine = $this->getEnginge();
+ }
+
+ $options = array();
+ $all_options = PMA_Table::getAlterOptions();
+
+ if (($engine === 'myisam' || $engine === 'isam')) {
+ $options['KEYS'] = $all_options['KEYS'];
+ }
+
+ if (($engine === 'myisam')) {
+ $options['checksum'] = $all_options['KEYS'];
+ $options['delay_key_write'] = $all_options['KEYS'];
+ }
+
+ if (($engine === 'myisam' || $engine === 'innodb')) {
+ $options['auto_increment'] = $all_options['KEYS'];
+ }
+ }
+
+ /**
+ * returns all available options for any table engine
+ *
+ * @todo update with mysql manual, last: ???
+ * @static
+ */
+ function getAlterOptions()
+ {
+ static $options = null;
+
+ if (null === $options) {
+ $options = array(
+ // ENABLE/DISABLE KEY
+ // skipped, makes no sense here
+ 'COMMENT' => array(
+ 'type' => 'string',
+ 'name' => 'strTableComment',
+ ),
+ 'TYPE' => array(
+ 'type' => 'string',
+ 'values' => array('PMA_Table', 'getEngines'),
+ 'name' => 'strTableEngine',
+ ),
+ 'DEFAULT_CHARSET_COLLATION' => array(
+ 'type' => 'string',
+ 'desc' => 'strTableCharset',
+ ),
+ 'pack_keys' => array(
+ 'type' => 'string',
+ 'name' => 'pack_keys',
+ 'desc' => '',
+ 'engines' => array(
+ PMA_DBI_ENGINE_MYISAM,
+ PMA_DBI_ENGINE_ISAM,
+ ),
+ ),
+ 'checksum' => array(
+ 'type' => 'string',
+ 'name' => 'checksum',
+ 'engines' => array(
+ PMA_DBI_ENGINE_MYISAM,
+ ),
+ ),
+ 'delay_key_write' => array(
+ 'type' => 'string',
+ 'name' => 'delay_key_write',
+ 'engines' => array(
+ PMA_DBI_ENGINE_MYISAM,
+ ),
+ ),
+ 'auto_increment' => array(
+ 'type' => 'int',
+ 'name' => 'auto_increment',
+ 'engines' => array(
+ PMA_DBI_ENGINE_MYISAM,
+ PMA_DBI_ENGINE_INNODB,
+ ),
+ ),
+ );
+ }
+
+ return $options;
+ }
+
+ function setEngine($engine)
+ {
+ $this->set('ENGINE', $engine);
+ }
+
+ function getEngine()
+ {
+ return $this->get('ENGINE');
+ }
+
+ /**
+ * @todo update with mysql manual, last: ???
+ */
+ function getEngineName($engine = null)
+ {
+ if (null === $engine) {
+ $engine = $this->getEngine();
+ }
+
+ switch ($engine) {
+ case PMA_DBI_ENGINE_MYISAM :
+ return 'MyISAM';
+ break;
+ case PMA_DBI_ENGINE_ISAM :
+ return 'ISAM';
+ break;
+ case PMA_DBI_ENGINE_INNODB :
+ return 'InnoDB';
+ break;
+ case PMA_DBI_ENGINE_MERGE :
+ return 'Merge';
+ break;
+ case PMA_DBI_ENGINE_MEMORY :
+ return 'MEMORY';
+ break;
+ case PMA_DBI_ENGINE_HEAP :
+ return 'HEAP';
+ break;
+ case PMA_DBI_ENGINE_BDB :
+ return 'BerkeleyDB';
+ break;
+ default :
+ return 'UNKNOWN';
+ }
+ }
+
function getLastError()
{
return end($this->errors);
@@ -144,33 +296,203 @@ class PMA_Table {
}
/**
- * sets given $value for given $param
+ * sets given $value for given $option
*
- * @uses $this->settings to add or change value
- * @param string param name
- * @param mixed param value
+ * @uses $this->options to add or change value
+ * @param string $option option name
+ * @param mixed $value option value
*/
- function set($param, $value)
+ function set($option, $value)
{
- $this->settings[$param] = $value;
+ $this->options[$option]->value = $value;
+ }
+
+ /**
+ * @static
+ * @param string $option
+ * @param mixed $value
+ * @return string
+ */
+ function getAlterOption($option, $value) {
+ switch ($option) {
+ case 'KEYS' :
+ return ($value ? 'ENABLE' : 'DISABLE') . ' KEYS';
+ break;
+ case 'TABLESPACE' :
+ return ($value ? 'IMPORT' : 'DISCARD') . ' TABLESPACE';
+ break;
+ case 'RENAME TO' :
+ case 'RENAME' :
+ case 'CHECK' :
+ case 'ORDER BY' :
+ return $option . ' ' . $value;
+ break;
+ case 'PACK_KEYS' :
+ //{0 | 1 | DEFAULT}
+ case 'CHECKSUM' :
+ case 'DELAY_KEY_WRITE' :
+ return $option . ' = ' . (int) (bool) $value;
+ break;
+ case 'CONVERT CHARACTER SET' :
+ return 'CONVERT ' . PMA_generateCharsetQueryPart($value);
+ break;
+ case 'TABLE_COLLATION' :
+ case 'DEFAULT CHARACTER SET' :
+ return 'DEFAULT ' . PMA_generateCharsetQueryPart($value);
+ break;
+ case 'CHARACTER SET' :
+ return PMA_generateCharsetQueryPart($value);
+ break;
+ case 'INSERT_METHOD' :
+ //{ NO | FIRST | LAST }
+ case 'UNION' :
+ case 'ROW_FORMAT' :
+ //{DEFAULT|DYNAMIC|FIXED|COMPRESSED|REDUNDANT|COMPACT}
+ case 'MIN_ROWS' :
+ case 'MAX_ROWS' :
+ case 'AVG_ROW_LENGTH' :
+ case 'ENGINE' :
+ case 'TYPE' :
+ case 'AUTO_INCREMENT' :
+ return $option . ' = ' . $value;
+ break;
+ case 'CONNECTION' :
+ case 'INDEX DIRECTORY' :
+ case 'DATA DIRECTORY' :
+ case 'CONNECTION' :
+ return $option . ' = \'' . PMA_sqlAddslashes($value) . '\'';
+ break;
+ case 'TABLE_COMMENT' :
+ case 'COMMENT' :
+ return 'COMMENT = \'' . PMA_sqlAddslashes($value) . '\'';
+ break;
+ default :
+ return '-- UNKNOWN OPTION: ' . $option . ' = \'' . PMA_sqlAddslashes($value) . '\'';
+ }
+ }
+
+ /**
+ * set options from given array of options
+ *
+ * @param array $options
+ * @return boolean success
+ */
+ function setOptions($options, $bc = false)
+ {
+ if ($bc) {
+ // backward compatibility
+ $new_engine = strtolower($this->get('ENGINE'));
+ $bc_options = $options;
+ $options = array();
+ if (null !== $this->get('TABLE_COMMENT')
+ && isset($bc_options['comment'])) {
+ $options['TABLE_COMMENT'] = $bc_options['comment'];
+ }
+ if (isset($bc_options['new_tbl_type'])
+ && ! $this->isEngineOneOf($bc_options['new_tbl_type'])) {
+ $options['ENGINE'] = $bc_options['new_tbl_type'];
+ $new_engine = strtolower($options['ENGINE']);
+ } elseif (null !== $this->get('TYPE')
+ && isset($bc_options['new_tbl_type'])) {
+ $options['TYPE'] = $bc_options['new_tbl_type'];
+ }
+ if (null !== $this->get('TABLE_COLLATION')
+ && isset($bc_options['tbl_collation'])) {
+ $options['TABLE_COLLATION'] = $bc_options['tbl_collation'];
+ }
+
+ //if (null !== $this->get('PACK_KEYS')) {
+ if ($new_engine === 'myisam' || $new_engine === 'isam') {
+ $options['PACK_KEYS'] = (int) !empty($bc_options['new_pack_keys']);
+ }
+ //if (null !== $this->get('CHECKSUM')) {
+ if ($new_engine === 'myisam') {
+ $options['CHECKSUM'] = (int) !empty($bc_options['new_checksum']);
+ }
+ //if (null !== $this->get('DELAY_KEY_WRITE')) {
+ if ($new_engine === 'myisam') {
+ $options['DELAY_KEY_WRITE'] = (int) !empty($bc_options['new_delay_key_write']);
+ }
+ //if (null !== $this->get('AUTO_INCREMENT')
+ // && isset($bc_options['new_auto_increment'])) {
+ if (isset($bc_options['new_auto_increment'])
+ && ($new_engine === 'myisam'
+ // MEMORY in 4.1.0
+ || ($new_engine === 'memory' && PMA_MYSQL_INT_VERSION >= 40100)
+ // InnoDB in 4.1.2 and 5.0.3
+ || ($new_engine === 'innodb' && PMA_MYSQL_INT_VERSION >= 40102))) {
+ $options['AUTO_INCREMENT'] = (int) $bc_options['new_auto_increment'];
+ }
+ }
+
+ $table_alters = array();
+
+ foreach ($options as $option => $value) {
+ if ($this->get($option) != $value) {
+ $table_alters[] = PMA_Table::getAlterOption($option, $value);
+ }
+ }
+
+ if (count($table_alters)) {
+ $sql_query = '
+ ALTER TABLE ' . $this->getFullName(true) . '
+ ' . implode("\r\n", $table_alters);
+ if (! PMA_DBI_try_query($sql_query)) {
+ $this->errors[] = $GLOBALS['strError'];
+ return false;
+ }
+
+ // display executed query in user interface
+ if (! isset($GLOBALS['sql_query'])) {
+ $GLOBALS['sql_query'] = '';
+ }
+ $GLOBALS['sql_query'] .= "\r\n" . $sql_query . ';';
+ $this->messages[] = $GLOBALS['strSuccess'];
+ }
+
+ return true;
}
/**
* returns value for given setting/param
*
- * @uses $this->settings to return value
- * @param string name for value to return
- * @return mixed value for $param
+ * @uses $this->options to return value
+ * @param string $option name for value to return
+ * @return mixed value for $option
*/
- function get($param)
+ function get($option)
{
- if (isset($this->settings[$param])) {
- return $this->settings[$param];
+ if (isset($this->options[$option])) {
+ return $this->options[$option]->value;
}
return null;
}
+ /**
+ * cleans 'InnoDB free'-string from table comment
+ */
+ function cleanInnodbComment($comment = null)
+ {
+ $return = true;
+
+ if (null === $comment) {
+ if (! $this->isEngineOneOf('innodb')) {
+ return;
+ }
+ $comment = $this->get('TABLE_COMMENT');
+ $return = false;
+ }
+
+ $comment = preg_replace('/(; InnoDB free: .*$)/i', '', $comment);
+
+ if ($return) {
+ return $comment;
+ } else {
+ $this->set('TABLE_COMMENT', $comment);
+ }
+ }
+
/**
* loads structure data
*/
@@ -182,25 +504,96 @@ class PMA_Table {
return false;
}
- $this->settings = $table_info;
+ foreach ($table_info[$this->getName()] as $key => $value) {
+ $this->options[$key]->value = $value;
+ }
+ $this->cleanInnodbComment();
+
+ /**
+ * init some values, check if they exists, if not create them with
+ * standard values
+ */
if ($this->get('TABLE_ROWS') === null) {
$this->set('TABLE_ROWS', PMA_Table::countRecords($this->getDbName(),
$this->getName(), true, true));
}
- $create_options = explode(' ', $this->get('TABLE_ROWS'));
+ /*
+ if (null === $this->get('AUTO_INCREMENT')
+ && ($this->isEngineOneOf('myisam')
+ // MEMORY in 4.1.0
+ || ($this->isEngineOneOf('memory') && PMA_MYSQL_INT_VERSION >= 40100)
+ // InnoDB in 4.1.2 and 5.0.3
+ || ($this->isEngineOneOf('innodb') && PMA_MYSQL_INT_VERSION >= 40102))) {
+ $this->set('AUTO_INCREMENT', 0);
+ } else {
+ // do not support this option on others than MyISAM or ISAM
+ $this->removeOption('AUTO_INCREMENT');
+ }
+
+ if (null === $this->get('PACK_KEYS')
+ && $this->isEngineOneOf('myisam', 'isam')) {
+ $this->set('PACK_KEYS', 'DEFAULT');
+ echo __LINE__;
+ } elseif (null !== $this->get('PACK_KEYS')) {
+ // do not support this option on others than MyISAM or ISAM
+ $this->removeOption('PACK_KEYS');
+ echo __LINE__;
+ }
+
+ if (null === $this->get('CHECKSUM')
+ && $this->isEngineOneOf('myisam')) {
+ $this->set('CHECKSUM', 0);
+ } else {
+ // do not support this option on others than MyISAM
+ $this->removeOption('CHECKSUM');
+ }
+
+ if (null === $this->get('DELAY_KEY_WRITE')
+ && $this->isEngineOneOf('myisam')) {
+ $this->set('DELAY_KEY_WRITE', 0);
+ } else {
+ // do not support this option on others than MyISAM
+ $this->removeOption('DELAY_KEY_WRITE');
+ }
+ */
+
+ $create_options = explode(' ', $this->get('CREATE_OPTIONS'));
// export create options by its name as variables into gloabel namespace
// f.e. pack_keys=1 becomes available as $pack_keys with value of '1'
foreach ($create_options as $each_create_option) {
$each_create_option = explode('=', $each_create_option);
if (isset($each_create_option[1])) {
- $this->set($$each_create_option[0], $each_create_option[1]);
+ $this->set(strtoupper($each_create_option[0]), $each_create_option[1]);
}
}
}
+ function removeOption($option)
+ {
+ if (isset($this->options[$option])) {
+ unset($this->options[$option]);
+ }
+ }
+
+ /**
+ *
+ * @param string $engine,... engine
+ * @return boolean whether one of the given engines is equal with current engine
+ */
+ function isEngineOneOf()
+ {
+ foreach (func_get_args() as $engine) {
+ if (strtolower($this->getEngine()) === strtolower($engine)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
/**
* old PHP 4style constructor
*
@@ -496,7 +889,6 @@ class PMA_Table {
return true;
} // end of 'PMA_Table::duplicateInfo()' function
-
/**
* Copies or renames table
* FIXME: use RENAME
@@ -868,15 +1260,21 @@ class PMA_Table {
return false;
}
- $GLOBALS['sql_query'] = '
+ $sql_query = '
RENAME TABLE ' . $this->getFullName(true) . '
TO ' . $new_table->getFullName(true) . ';';
- if (! PMA_DBI_query($GLOBALS['sql_query'])) {
+ if (! PMA_DBI_query($sql_query)) {
// TODO add $GLOBALS['strErrorRenamingTable'];
$this->errors[] = $GLOBALS['strError'] . ': ' . $new_table->getFullName();
return false;
}
+ // display executed query in user interface
+ if (! isset( $GLOBALS['sql_query'])) {
+ $GLOBALS['sql_query'] = '';
+ }
+ $GLOBALS['sql_query'] .= "\n\n" . $sql_query;
+
$old_name = $this->getName();
$old_db = $this->getDbName();
$this->setName($new_name);
diff --git a/libraries/auth/cookie.auth.lib.php b/libraries/auth/cookie.auth.lib.php
index 18a732858..cae57bbe7 100644
--- a/libraries/auth/cookie.auth.lib.php
+++ b/libraries/auth/cookie.auth.lib.php
@@ -504,8 +504,8 @@ function PMA_auth_fails()
} elseif (isset($GLOBALS['no_activity']) && $GLOBALS['no_activity']) {
$conn_error = sprintf($GLOBALS['strNoActivity'], $GLOBALS['cfg']['LoginCookieValidity']);
// Remember where we got timeout to return on same place
- if (getenv('SCRIPT_NAME')) {
- $GLOBALS['target'] = basename(getenv('SCRIPT_NAME'));
+ if (PMA_getenv('SCRIPT_NAME')) {
+ $GLOBALS['target'] = basename(PMA_getenv('SCRIPT_NAME'));
}
} elseif (PMA_DBI_getError()) {
$conn_error = PMA_sanitize(PMA_DBI_getError());
diff --git a/libraries/auth/http.auth.lib.php b/libraries/auth/http.auth.lib.php
index 210ced80f..33f015662 100644
--- a/libraries/auth/http.auth.lib.php
+++ b/libraries/auth/http.auth.lib.php
@@ -79,38 +79,34 @@ function PMA_auth_check()
// 'register_globals' and the 'variables_order' directives
// loic1 - 2001/25/11: use the new globals arrays defined with php 4.1+
if (empty($PHP_AUTH_USER)) {
- if (isset($_SERVER['PHP_AUTH_USER'])) {
- $PHP_AUTH_USER = $_SERVER['PHP_AUTH_USER'];
- } elseif (getenv('PHP_AUTH_USER')) {
- $PHP_AUTH_USER = getenv('PHP_AUTH_USER');
- } elseif (getenv('REMOTE_USER')) {
+ if (PMA_getenv('PHP_AUTH_USER')) {
+ $PHP_AUTH_USER = PMA_getenv('PHP_AUTH_USER');
+ } elseif (PMA_getenv('REMOTE_USER')) {
// CGI, might be encoded, see bellow
- $PHP_AUTH_USER = getenv('REMOTE_USER');
- } elseif (getenv('AUTH_USER')) {
+ $PHP_AUTH_USER = PMA_getenv('REMOTE_USER');
+ } elseif (PMA_getenv('AUTH_USER')) {
// WebSite Professional
- $PHP_AUTH_USER = getenv('AUTH_USER');
- } elseif (getenv('HTTP_AUTHORIZATION')) {
+ $PHP_AUTH_USER = PMA_getenv('AUTH_USER');
+ } elseif (PMA_getenv('HTTP_AUTHORIZATION')) {
// IIS, might be encoded, see bellow
- $PHP_AUTH_USER = getenv('HTTP_AUTHORIZATION');
- } elseif (getenv('Authorization')) {
+ $PHP_AUTH_USER = PMA_getenv('HTTP_AUTHORIZATION');
+ } elseif (PMA_getenv('Authorization')) {
// FastCGI, might be encoded, see bellow
- $PHP_AUTH_USER = getenv('Authorization');
+ $PHP_AUTH_USER = PMA_getenv('Authorization');
}
}
// Grabs the $PHP_AUTH_PW variable whatever are the values of the
// 'register_globals' and the 'variables_order' directives
// loic1 - 2001/25/11: use the new globals arrays defined with php 4.1+
if (empty($PHP_AUTH_PW)) {
- if (isset($_SERVER['PHP_AUTH_PW'])) {
- $PHP_AUTH_PW = $_SERVER['PHP_AUTH_PW'];
- } elseif (getenv('PHP_AUTH_PW')) {
- $PHP_AUTH_PW = getenv('PHP_AUTH_PW');
- } elseif (getenv('REMOTE_PASSWORD')) {
+ if (PMA_getenv('PHP_AUTH_PW')) {
+ $PHP_AUTH_PW = PMA_getenv('PHP_AUTH_PW');
+ } elseif (PMA_getenv('REMOTE_PASSWORD')) {
// Apache/CGI
- $PHP_AUTH_PW = getenv('REMOTE_PASSWORD');
- } elseif (getenv('AUTH_PASSWORD')) {
+ $PHP_AUTH_PW = PMA_getenv('REMOTE_PASSWORD');
+ } elseif (PMA_getenv('AUTH_PASSWORD')) {
// WebSite Professional
- $PHP_AUTH_PW = getenv('AUTH_PASSWORD');
+ $PHP_AUTH_PW = PMA_getenv('AUTH_PASSWORD');
}
}
diff --git a/libraries/common.lib.php b/libraries/common.lib.php
index 4ec057708..408d20f92 100644
--- a/libraries/common.lib.php
+++ b/libraries/common.lib.php
@@ -1911,7 +1911,7 @@ window.parent.updateTableTitle('', '' . "\n";
- $url_params['target'] = basename(getenv('SCRIPT_NAME'));
+ $url_params['target'] = basename(PMA_getenv('SCRIPT_NAME'));
echo '';
/*
- echo '' . "\n"
. ($GLOBALS['cfg']['MainPageIconic'] ? '
' : '')
. $GLOBALS['strPrivileges'] . "\n"
. '' . "\n"
. $GLOBALS['strNoPrivileges'] . "\n";
- require_once('./libraries/footer.inc.php');
+ require_once './libraries/footer.inc.php';
+}
+
+
+/**
+ * Checks if a dropdown box has been used for selecting a database / table
+ */
+if (isset($_REQUEST['pred_dbname']) && strlen($_REQUEST['pred_dbname'])) {
+ $dbname = $_REQUEST['pred_dbname'];
+ unset($_REQUEST['pred_dbname']);
+} elseif (isset($_REQUEST['dbname']) && strlen($_REQUEST['dbname'])) {
+ $dbname = $_REQUEST['dbname'];
+ unset($_REQUEST['dbname']);
+} else {
+ $dbname = '';
+}
+
+if (isset($_REQUEST['pred_tablename']) && strlen($_REQUEST['pred_tablename'])) {
+ $tablename = $_REQUEST['pred_tablename'];
+ unset($_REQUEST['pred_tablename']);
+} else {
+ $tablename = '';
+}
+
+/**
+ * check if given $dbname is a wildcard or not
+ */
+//if (preg_match('/\\\\(?:_|%)/i', $dbname)) {
+//if (preg_match('/(?' . "\n"
+ . $spaces . ' ' . "\n"
+ . $spaces . ' ' . "\n"
+ . $spaces . ' ' . $GLOBALS['strOr'] . '' . "\n"
+ . $spaces . ' ' . "\n"
+ . $spaces . '' . "\n";
} // end function
/**
@@ -208,54 +263,50 @@ function PMA_display_column_privs($spaces, $columns, $row, $name_for_select, $pr
*
* @return void
*/
-function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent = 0)
+function PMA_displayPrivTable($db = '*', $table = '*', $submit = true, $indent = 0)
{
if ($db == '*') {
$table = '*';
}
- $spaces = str_repeat( ' ', $indent );
+ $spaces = str_repeat(' ', $indent);
- if (isset($GLOBALS['username'])) {
- $username = $GLOBALS['username'];
- $hostname = $GLOBALS['hostname'];
+ if (isset($_REQUEST['username'])) {
if ($db == '*') {
$sql_query =
'SELECT * FROM `mysql`.`user`'
.' WHERE ' . PMA_convert_using('User')
- .' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted')
+ .' = ' . PMA_convert_using(PMA_sqlAddslashes($_REQUEST['username']), 'quoted')
.' AND ' . PMA_convert_using('Host')
- .' = ' . PMA_convert_using($hostname, 'quoted') . ';';
+ .' = ' . PMA_convert_using($_REQUEST['hostname'], 'quoted') . ';';
} elseif ($table == '*') {
$sql_query =
'SELECT * FROM `mysql`.`db`'
.' WHERE ' . PMA_convert_using('`User`')
- .' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted')
+ .' = ' . PMA_convert_using(PMA_sqlAddslashes($_REQUEST['username']), 'quoted')
.' AND ' . PMA_convert_using('`Host`')
- .' = ' . PMA_convert_using($hostname, 'quoted')
- .' AND ' . PMA_convert_using( PMA_unescape_mysql_wildcards( $db ), 'quoted' )
- .' LIKE ' . PMA_convert_using( '`Db`' ) . ';';
+ .' = ' . PMA_convert_using($_REQUEST['hostname'], 'quoted')
+ .' AND ' . PMA_convert_using(PMA_unescape_mysql_wildcards($db), 'quoted')
+ .' LIKE ' . PMA_convert_using('`Db`') . ';';
} else {
$sql_query =
'SELECT `Table_priv`'
.' FROM `mysql`.`tables_priv`'
.' WHERE ' . PMA_convert_using('`User`')
- .' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted')
+ .' = ' . PMA_convert_using(PMA_sqlAddslashes($_REQUEST['username']), 'quoted')
.' AND ' .PMA_convert_using('`Host`')
- .' = ' . PMA_convert_using( $hostname, 'quoted' )
+ .' = ' . PMA_convert_using($_REQUEST['hostname'], 'quoted')
.' AND ' .PMA_convert_using('`Db`')
- .' = ' . PMA_convert_using( PMA_unescape_mysql_wildcards( $db ), 'quoted' )
+ .' = ' . PMA_convert_using(PMA_unescape_mysql_wildcards($db), 'quoted')
.' AND ' . PMA_convert_using('`Table_name`')
.' = ' . PMA_convert_using($table, 'quoted') . ';';
}
- $res = PMA_DBI_query($sql_query);
- $row = PMA_DBI_fetch_assoc($res);
- PMA_DBI_free_result($res);
+ $row = PMA_DBI_fetch_single_row($sql_query);
}
if (empty($row)) {
if ($table == '*') {
if ($db == '*') {
$sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;';
- } elseif ($table == '*') {
+ } else {
$sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;';
}
$res = PMA_DBI_query($sql_query);
@@ -272,35 +323,18 @@ function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent =
}
}
if (isset($row['Table_priv'])) {
- $res = PMA_DBI_query(
- 'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';',
- $GLOBALS['userlink'] );
- // note: in MySQL 5.0.3 we get "Create View', 'Show view';
- // the View for Create is spelled with uppercase V
- // the view for Show is spelled with lowercase v
- // and there is a space between the words
-
- $row1 = PMA_DBI_fetch_assoc($res);
- PMA_DBI_free_result($res);
- $av_grants = explode ('\',\'', substr($row1['Type'], strpos($row1['Type'], '(') + 2, strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3));
- unset($res, $row1);
- $users_grants = explode(',', $row['Table_priv']);
-
- foreach ($av_grants as $current_grant) {
- $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N';
- }
- unset($row['Table_priv'], $current_grant, $av_grants, $users_grants);
+ PMA_addUSerTablePrivs($row);
// get collumns
- $res = PMA_DBI_try_query('SHOW COLUMNS FROM `' . PMA_unescape_mysql_wildcards( $db ) . '`.`' . $table . '`;');
+ $res = PMA_DBI_try_query('SHOW COLUMNS FROM `' . PMA_unescape_mysql_wildcards($db) . '`.`' . $table . '`;');
$columns = array();
- if ( $res ) {
+ if ($res) {
while ($row1 = PMA_DBI_fetch_row($res)) {
$columns[$row1[0]] = array(
- 'Select' => FALSE,
- 'Insert' => FALSE,
- 'Update' => FALSE,
- 'References' => FALSE
+ 'Select' => false,
+ 'Insert' => false,
+ 'Update' => false,
+ 'References' => false
);
}
PMA_DBI_free_result($res);
@@ -308,27 +342,27 @@ function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent =
unset($res, $row1);
}
// t a b l e - s p e c i f i c p r i v i l e g e s
- if ( ! empty( $columns ) ) {
+ if (! empty($columns)) {
$res = PMA_DBI_query(
'SELECT `Column_name`, `Column_priv`'
.' FROM `mysql`.`columns_priv`'
.' WHERE ' . PMA_convert_using('`User`')
- .' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted')
+ .' = ' . PMA_convert_using(PMA_sqlAddslashes($_REQUEST['username']), 'quoted')
.' AND ' . PMA_convert_using('`Host`')
- .' = ' . PMA_convert_using($hostname, 'quoted')
+ .' = ' . PMA_convert_using($_REQUEST['hostname'], 'quoted')
.' AND ' . PMA_convert_using('`Db`')
- .' = ' . PMA_convert_using( PMA_unescape_mysql_wildcards( $db ), 'quoted')
+ .' = ' . PMA_convert_using(PMA_unescape_mysql_wildcards($db), 'quoted')
.' AND ' . PMA_convert_using('`Table_name`')
.' = ' . PMA_convert_using($table, 'quoted') . ';');
while ($row1 = PMA_DBI_fetch_row($res)) {
$row1[1] = explode(',', $row1[1]);
foreach ($row1[1] as $current) {
- $columns[$row1[0]][$current] = TRUE;
+ $columns[$row1[0]][$current] = true;
}
}
PMA_DBI_free_result($res);
- unset( $res, $row1, $current );
+ unset($res, $row1, $current);
echo $spaces . '' . "\n"
. $spaces . '' . "\n"
@@ -476,7 +510,7 @@ function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent =
. $spaces . ' ' . $GLOBALS['strEnglishPrivileges'] . '
' . "\n"
. $spaces . '