tag with tooltips
*
* @global resource $user_link the database connection
*
* @return array
*/
function PMA_extractPrivInfo($row = '', $enableHTML = false)
{
$grants = PMA_getGrantsArray();
if (! empty($row) && isset($row['Table_priv'])) {
$row1 = PMA_DBI_fetch_single_row(
'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';',
'ASSOC', $GLOBALS['userlink']
);
$av_grants = explode(
'\',\'',
substr($row1['Type'], 5, strlen($row1['Type']) - 7)
);
unset($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($current_grant);
}
$privs = array();
$allPrivileges = true;
foreach ($grants as $current_grant) {
if ((! empty($row) && isset($row[$current_grant[0]]))
|| (empty($row) && isset($GLOBALS[$current_grant[0]]))
) {
if ((! empty($row) && $row[$current_grant[0]] == 'Y')
|| (empty($row)
&& ($GLOBALS[$current_grant[0]] == 'Y'
|| (is_array($GLOBALS[$current_grant[0]])
&& count($GLOBALS[$current_grant[0]]) == $_REQUEST['column_count']
&& empty($GLOBALS[$current_grant[0] . '_none']))))
) {
if ($enableHTML) {
$privs[] = ''
. $current_grant[1] . '';
} else {
$privs[] = $current_grant[1];
}
} elseif (! empty($GLOBALS[$current_grant[0]])
&& is_array($GLOBALS[$current_grant[0]])
&& empty($GLOBALS[$current_grant[0] . '_none'])) {
if ($enableHTML) {
$priv_string = ''
. $current_grant[1] . '';
} else {
$priv_string = $current_grant[1];
}
$privs[] = $priv_string . ' (`'
. join('`, `', $GLOBALS[$current_grant[0]]) . '`)';
} else {
$allPrivileges = false;
}
}
}
if (empty($privs)) {
if ($enableHTML) {
$privs[] = 'USAGE';
} else {
$privs[] = 'USAGE';
}
} elseif ($allPrivileges
&& (! isset($_POST['grant_count'])
|| count($privs) == $_POST['grant_count'])
) {
if ($enableHTML) {
$privs = array('ALL PRIVILEGES'
);
} else {
$privs = array('ALL PRIVILEGES');
}
}
return $privs;
} // end of the 'PMA_extractPrivInfo()' function
/**
* Get the grants array which contains all the privilege types
* and relevent grant messages
*
* @return array
*/
function PMA_getGrantsArray()
{
return array(
array(
'Select_priv',
'SELECT',
__('Allows reading data.')),
array(
'Insert_priv',
'INSERT',
__('Allows inserting and replacing data.')),
array(
'Update_priv',
'UPDATE',
__('Allows changing data.')),
array(
'Delete_priv',
'DELETE',
__('Allows deleting data.')),
array(
'Create_priv',
'CREATE',
__('Allows creating new databases and tables.')),
array(
'Drop_priv',
'DROP',
__('Allows dropping databases and tables.')),
array(
'Reload_priv',
'RELOAD',
__('Allows reloading server settings and flushing the server\'s caches.')),
array(
'Shutdown_priv',
'SHUTDOWN',
__('Allows shutting down the server.')),
array(
'Process_priv',
'PROCESS',
__('Allows viewing processes of all users')),
array(
'File_priv',
'FILE',
__('Allows importing data from and exporting data into files.')),
array(
'References_priv',
'REFERENCES',
__('Has no effect in this MySQL version.')),
array(
'Index_priv',
'INDEX',
__('Allows creating and dropping indexes.')),
array(
'Alter_priv',
'ALTER',
__('Allows altering the structure of existing tables.')),
array(
'Show_db_priv',
'SHOW DATABASES',
__('Gives access to the complete list of databases.')),
array(
'Super_priv',
'SUPER',
__('Allows connecting, even if maximum number of connections is reached; required for most administrative operations like setting global variables or killing threads of other users.')),
array(
'Create_tmp_table_priv',
'CREATE TEMPORARY TABLES',
__('Allows creating temporary tables.')),
array(
'Lock_tables_priv',
'LOCK TABLES',
__('Allows locking tables for the current thread.')),
array(
'Repl_slave_priv',
'REPLICATION SLAVE',
__('Needed for the replication slaves.')),
array(
'Repl_client_priv',
'REPLICATION CLIENT',
__('Allows the user to ask where the slaves / masters are.')),
array(
'Create_view_priv',
'CREATE VIEW',
__('Allows creating new views.')),
array(
'Event_priv',
'EVENT',
__('Allows to set up events for the event scheduler')),
array(
'Trigger_priv',
'TRIGGER',
__('Allows creating and dropping triggers')),
// for table privs:
array(
'Create View_priv',
'CREATE VIEW',
__('Allows creating new views.')),
array(
'Show_view_priv',
'SHOW VIEW',
__('Allows performing SHOW CREATE VIEW queries.')),
// for table privs:
array(
'Show view_priv',
'SHOW VIEW',
__('Allows performing SHOW CREATE VIEW queries.')),
array(
'Create_routine_priv',
'CREATE ROUTINE',
__('Allows creating stored routines.')),
array(
'Alter_routine_priv',
'ALTER ROUTINE',
__('Allows altering and dropping stored routines.')),
array(
'Create_user_priv',
'CREATE USER',
__('Allows creating, dropping and renaming user accounts.')),
array(
'Execute_priv',
'EXECUTE',
__('Allows executing stored routines.')),
);
}
/**
* Displays on which column(s) a table-specific privilege is granted
*
* @param array $columns columns array
* @param array $row first row from result or boolean false
* @param string $name_for_select privilege types - Select_priv, Insert_priv
* Update_priv, References_priv
* @param string $priv_for_header privilege for header
* @param string $name privilege name: insert, select, update, references
* @param string $name_for_dfn name for dfn
* @param string $name_for_current name for current
*
* @return $html_output html snippet
*/
function PMA_getHtmlForDisplayColumnPrivileges($columns, $row, $name_for_select,
$priv_for_header, $name, $name_for_dfn, $name_for_current
) {
$html_output = '
' . "\n"
. '
' . "\n"
. '' . "\n"
. '' . __('Or') . '' . "\n"
. '' . "\n"
. '
' . "\n";
return $html_output;
} // end function
/**
* Get sql query for display privileges table
*
* @param string $db the database
* @param string $table the table
* @param string $username username for database connection
* @param string $hostname hostname for database connection
*
* @return string sql query
*/
function PMA_getSqlQueryForDisplayPrivTable($db, $table, $username, $hostname)
{
if ($db == '*') {
return "SELECT * FROM `mysql`.`user`"
." WHERE `User` = '" . PMA_Util::sqlAddSlashes($username) . "'"
." AND `Host` = '" . PMA_Util::sqlAddSlashes($hostname) . "';";
} elseif ($table == '*') {
return "SELECT * FROM `mysql`.`db`"
." WHERE `User` = '" . PMA_Util::sqlAddSlashes($username) . "'"
." AND `Host` = '" . PMA_Util::sqlAddSlashes($hostname) . "'"
." AND '" . PMA_Util::unescapeMysqlWildcards($db) . "'"
." LIKE `Db`;";
}
return "SELECT `Table_priv`"
." FROM `mysql`.`tables_priv`"
." WHERE `User` = '" . PMA_Util::sqlAddSlashes($username) . "'"
." AND `Host` = '" . PMA_Util::sqlAddSlashes($hostname) . "'"
." AND `Db` = '" . PMA_Util::unescapeMysqlWildcards($db) . "'"
." AND `Table_name` = '" . PMA_Util::sqlAddSlashes($table) . "';";
}
/**
* Displays the privileges form table
*
* @param string $db the database
* @param string $table the table
* @param boolean $submit wheather to display the submit button or not
*
* @global array $cfg the phpMyAdmin configuration
* @global ressource $user_link the database connection
*
* @return string html snippet
*/
function PMA_getHtmlToDisplayPrivilegesTable($db = '*',
$table = '*', $submit = true
) {
$html_output = '';
if ($db == '*') {
$table = '*';
}
if (isset($GLOBALS['username'])) {
$username = $GLOBALS['username'];
$hostname = $GLOBALS['hostname'];
$sql_query = PMA_getSqlQueryForDisplayPrivTable(
$db, $table, $username, $hostname
);
$row = PMA_DBI_fetch_single_row($sql_query);
}
if (empty($row)) {
if ($table == '*') {
if ($db == '*') {
$sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;';
} elseif ($table == '*') {
$sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;';
}
$res = PMA_DBI_query($sql_query);
while ($row1 = PMA_DBI_fetch_row($res)) {
if (substr($row1[0], 0, 4) == 'max_') {
$row[$row1[0]] = 0;
} else {
$row[$row1[0]] = 'N';
}
}
PMA_DBI_free_result($res);
} else {
$row = array('Table_priv' => '');
}
}
if (isset($row['Table_priv'])) {
$row1 = PMA_DBI_fetch_single_row(
'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';',
'ASSOC', $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
$av_grants = explode(
'\',\'',
substr(
$row1['Type'],
strpos($row1['Type'], '(') + 2,
strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3
)
);
unset($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);
// get columns
$res = PMA_DBI_try_query(
'SHOW COLUMNS FROM '
. PMA_Util::backquote(
PMA_Util::unescapeMysqlWildcards($db)
)
. '.' . PMA_Util::backquote($table) . ';'
);
$columns = array();
if ($res) {
while ($row1 = PMA_DBI_fetch_row($res)) {
$columns[$row1[0]] = array(
'Select' => false,
'Insert' => false,
'Update' => false,
'References' => false
);
}
PMA_DBI_free_result($res);
}
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)) {
$html_output .= PMA_getHtmlForTableSpecificPrivileges(
$username, $hostname, $db, $table, $columns, $row
);
} else {
// g l o b a l o r d b - s p e c i f i c
$html_output .= PMA_getHtmlForGlobalOrDbSpecificPrivs($db, $table, $row);
}
$html_output .= '' . "\n";
if ($submit) {
$html_output .= '' . "\n";
}
return $html_output;
} // end of the 'PMA_displayPrivTable()' function
/**
* Get HTML for "Resource limits"
*
* @param array $row first row from result or boolean false
*
* @return string html snippet
*/
function PMA_getHtmlForDisplayResourceLimits($row)
{
$html_output = '' . "\n";
return $html_output;
}
/**
* Get the HTML snippet for table specific privileges
*
* @param string $username username for database connection
* @param string $hostname hostname for database connection
* @param string $db the database
* @param string $table the table
* @param boolean $columns columns array
* @param $row
*
* @return string $html_output
*/
function PMA_getHtmlForTableSpecificPrivileges($username, $hostname, $db,
$table, $columns, $row
) {
$res = PMA_DBI_query(
'SELECT `Column_name`, `Column_priv`'
.' FROM `mysql`.`columns_priv`'
.' WHERE `User`'
.' = \'' . PMA_Util::sqlAddSlashes($username) . "'"
.' AND `Host`'
.' = \'' . PMA_Util::sqlAddSlashes($hostname) . "'"
.' AND `Db`'
.' = \'' . PMA_Util::sqlAddSlashes(
PMA_Util::unescapeMysqlWildcards($db)
) . "'"
.' AND `Table_name`'
.' = \'' . PMA_Util::sqlAddSlashes($table) . '\';'
);
while ($row1 = PMA_DBI_fetch_row($res)) {
$row1[1] = explode(',', $row1[1]);
foreach ($row1[1] as $current) {
$columns[$row1[0]][$current] = true;
}
}
PMA_DBI_free_result($res);
unset($res, $row1, $current);
$html_output = '' . "\n"
. '' . "\n"
. '