/**
 * Get HTML snippet for display user properties
 *
 * @param boolean $dbname_is_wildcard whether database name is wildcard or not
 * @param type    $url_dbname         url database name that urlencode() string
 * @param string  $username           username
 * @param string  $hostname           host name
 * @param string  $link_edit          standard link to edit privileges
 * @param string  $link_revoke        standard link to revoke
 * @param string  $dbname             database name
 * @param string  $tablename          table name
 *
 * @return string $html_output
 */
function PMA_getHtmlForDisplayUserProperties($dbname_is_wildcard, $url_dbname, $username, $hostname, $link_edit, $link_revoke, $dbname, $tablename)
{
    $html_output = PMA_getHtmlHeaderForDisplayUserProperties($dbname_is_wildcard, $url_dbname, $dbname, $username, $hostname, $tablename);
    $sql = "SELECT '1' FROM `mysql`.`user`" . " WHERE `User` = '" . PMA_Util::sqlAddSlashes($username) . "'" . " AND `Host` = '" . PMA_Util::sqlAddSlashes($hostname) . "';";
    $user_does_not_exists = (bool) (!PMA_DBI_fetch_value($sql));
    if ($user_does_not_exists) {
        $html_output .= PMA_Message::error(__('The selected user was not found in the privilege table.'))->getDisplay();
        $html_output .= PMA_getHtmlForDisplayLoginInformationFields();
        //exit;
    }
    $class = ' class="ajax"';
    $html_output .= '<form' . $class . ' name="usersForm" id="addUsersForm"' . ' action="server_privileges.php" method="post">' . "\n";
    $_params = array('username' => $username, 'hostname' => $hostname);
    if (strlen($dbname)) {
        $_params['dbname'] = $dbname;
        if (strlen($tablename)) {
            $_params['tablename'] = $tablename;
        }
    }
    $html_output .= PMA_generate_common_hidden_inputs($_params);
    $html_output .= PMA_getHtmlToDisplayPrivilegesTable(PMA_ifSetOr($dbname, '*', 'length'), PMA_ifSetOr($tablename, '*', 'length'));
    $html_output .= '</form>' . "\n";
    if (!strlen($tablename) && empty($dbname_is_wildcard)) {
        // no table name was given, display all table specific rights
        // but only if $dbname contains no wildcards
        $html_output .= '<form action="server_privileges.php" ' . 'id="db_or_table_specific_priv" method="post">' . "\n";
        list($html_rightsTable, $found_rows) = PMA_getTableForDisplayAllTableSpecificRights($username, $hostname, $link_edit, $link_revoke, $dbname);
        $html_output .= $html_rightsTable;
        if (!strlen($dbname)) {
            // no database name was given, display select db
            $html_output .= PMA_getHtmlForDisplaySelectDbInEditPrivs($found_rows);
        } else {
            $html_output .= PMA_displayTablesInEditPrivs($dbname, $found_rows);
        }
        $html_output .= '</fieldset>' . "\n";
        $html_output .= '<fieldset class="tblFooters">' . "\n" . '    <input type="submit" value="' . __('Go') . '" />' . '</fieldset>' . "\n" . '</form>' . "\n";
    }
    // Provide a line with links to the relevant database and table
    if (strlen($dbname) && empty($dbname_is_wildcard)) {
        $html_output .= PMA_getLinkToDbAndTable($url_dbname, $dbname, $tablename);
    }
    if (!strlen($dbname) && !$user_does_not_exists) {
        //change login information
        $html_output .= PMA_getHtmlForChangePassword($username, $hostname);
        $html_output .= PMA_getChangeLoginInformationHtmlForm($username, $hostname);
    }
    return $html_output;
}
    /**
     * Test for PMA_getHtmlHeaderForDisplayUserProperties
     *
     * @return void
     */
    public function testPMAGetHtmlHeaderForDisplayUserProperties()
    {
        $dbname_is_wildcard = true;
        $url_dbname = "url_dbname";
        $dbname = "dbname";
        $username = "******";
        $hostname = "hostname";
        $tablename = "tablename";
        $_REQUEST['tablename'] = "tablename";

        $html = PMA_getHtmlHeaderForDisplayUserProperties(
            $dbname_is_wildcard, $url_dbname, $dbname,
            $username, $hostname, $tablename
        );

        //title
        $this->assertContains(
            __('Edit Privileges:'),
            $html
        );
        $this->assertContains(
            __('User'),
            $html
        );

        //PMA_URL_getCommon
        $item = PMA_URL_getCommon(
            array(
                'username' => $username,
                'hostname' => $hostname,
                'dbname' => '',
                'tablename' => '',
            )
        );
        $this->assertContains(
            $item,
            $html
        );

        //$username & $hostname
        $this->assertContains(
            htmlspecialchars($username),
            $html
        );
        $this->assertContains(
            htmlspecialchars($hostname),
            $html
        );

        //$dbname_is_wildcard = true
        $this->assertContains(
            __('Databases'),
            $html
        );

        //$dbname_is_wildcard = true
        $this->assertContains(
            __('Databases'),
            $html
        );

        //PMA_URL_getCommone
        $item = PMA_URL_getCommon(
            array(
                'username' => $username,
                'hostname' => $hostname,
                'dbname' => $url_dbname,
                'tablename' => '',
            )
        );
        $this->assertContains(
            $item,
            $html
        );
        $this->assertContains(
            $dbname,
            $html
        );
    }