/**
 * Get a HTML table for display user's tabel specific or database specific rights
 *
 * @param string $username username
 * @param string $hostname host name
 * @param string $dbname   database name
 *
 * @return array $html_output, $found_rows
 */
function PMA_getHtmlForAllTableSpecificRights($username, $hostname, $dbname)
{
    // table header
    $html_output = PMA_URL_getHiddenInputs('', '') . '<input type="hidden" name="username" ' . 'value="' . htmlspecialchars($username) . '" />' . "\n" . '<input type="hidden" name="hostname" ' . 'value="' . htmlspecialchars($hostname) . '" />' . "\n" . '<fieldset>' . "\n" . '<legend data-submenu-label="' . (!mb_strlen($dbname) ? __('Database') : __('Table')) . '">' . (!mb_strlen($dbname) ? __('Database-specific privileges') : __('Table-specific privileges')) . '</legend>' . "\n" . '<table class="data">' . "\n" . '<thead>' . "\n" . '<tr><th>' . (!mb_strlen($dbname) ? __('Database') : __('Table')) . '</th>' . "\n" . '<th>' . __('Privileges') . '</th>' . "\n" . '<th>' . __('Grant') . '</th>' . "\n" . '<th>' . (!mb_strlen($dbname) ? __('Table-specific privileges') : __('Column-specific privileges')) . '</th>' . "\n" . '<th colspan="2">' . __('Action') . '</th>' . "\n" . '</tr>' . "\n" . '</thead>' . "\n";
    $user_host_condition = ' WHERE `User`' . ' = \'' . PMA_Util::sqlAddSlashes($username) . "'" . ' AND `Host`' . ' = \'' . PMA_Util::sqlAddSlashes($hostname) . "'";
    // table body
    // get data
    // we also want privileges for this user not in table `db` but in other table
    $tables = $GLOBALS['dbi']->fetchResult('SHOW TABLES FROM `mysql`;');
    /**
     * no db name given, so we want all privs for the given user
     * db name was given, so we want all user specific rights for this db
     */
    $db_rights = PMA_getUserSpecificRights($tables, $user_host_condition, $dbname);
    ksort($db_rights);
    $html_output .= '<tbody>' . "\n";
    // display rows
    list($found_rows, $html_out) = PMA_getHtmlForUserRights($db_rights, $dbname, $hostname, $username);
    $html_output .= $html_out;
    $html_output .= '</tbody>' . "\n";
    $html_output .= '</table>' . "\n";
    return array($html_output, $found_rows);
}
 /**
  * Tests for PMA_getHtmlForUserRights
  *
  * @return void
  */
 function testPMAGetHtmlForUserRights()
 {
     // Test case 1
     $db_rights = array('y' => array('privs' => array('USAGE'), 'Db' => 'y', 'Grant_priv' => 'N', 'Column_priv' => true, 'can_delete' => true));
     $exp_found_rows = array('y');
     $actual = PMA_getHtmlForUserRights($db_rights, '', 'host', 'user');
     $this->assertArrayHasKey(0, $actual);
     $this->assertArrayHasKey(1, $actual);
     $this->assertEquals($exp_found_rows, $actual[0]);
     $this->assertContains('Edit Privileges', $actual[1]);
     $this->assertContains('Revoke', $actual[1]);
     $this->assertContains('<tr class="odd">', $actual[1]);
     $this->assertContains('<dfn title="No privileges.">USAGE</dfn>', $actual[1]);
     $this->assertContains('<img src="imageb_usredit.png" title="Edit Privileges" ' . 'alt="Edit Privileges" />', $actual[1]);
     $this->assertContains('<img src="imageb_usrdrop.png" title="Revoke" alt="Revoke" />', $actual[1]);
     // Test case 2
     $actual = PMA_getHtmlForUserRights(array(), '', '', '');
     $this->assertArrayHasKey(0, $actual);
     $this->assertArrayHasKey(1, $actual);
     $this->assertEquals(array(), $actual[0]);
     $this->assertEquals('<tr class="odd">' . "\n" . '<td colspan="6"><center><i>None</i></center></td>' . "\n" . '</tr>' . "\n", $actual[1]);
 }