/**
 * Get table body for 'tableuserrights' table in userform
 *
 * @param array $db_rights user's database rights array
 *
 * @return string HTML snippet
 */
function PMA_getHtmlTableBodyForUserRights($db_rights)
{
    if ($GLOBALS['cfgRelation']['menuswork']) {
        $users_table = PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . "." . PMA_Util::backquote($GLOBALS['cfg']['Server']['users']);
        $sql_query = 'SELECT * FROM ' . $users_table;
        $result = PMA_queryAsControlUser($sql_query, false);
        $group_assignment = array();
        if ($result) {
            while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
                $group_assignment[$row['username']] = $row['usergroup'];
            }
        }
        $GLOBALS['dbi']->freeResult($result);
        $user_group_count = PMA_getUserGroupCount();
    }
    $odd_row = true;
    $index_checkbox = 0;
    $html_output = '';
    foreach ($db_rights as $user) {
        ksort($user);
        foreach ($user as $host) {
            $index_checkbox++;
            $html_output .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n";
            $html_output .= '<td>' . '<input type="checkbox" class="checkall" name="selected_usr[]" ' . 'id="checkbox_sel_users_' . $index_checkbox . '" value="' . htmlspecialchars($host['User'] . '&amp;#27;' . $host['Host']) . '"' . ' /></td>' . "\n";
            $html_output .= '<td><label ' . 'for="checkbox_sel_users_' . $index_checkbox . '">' . (empty($host['User']) ? '<span style="color: #FF0000">' . __('Any') . '</span>' : htmlspecialchars($host['User'])) . '</label></td>' . "\n" . '<td>' . htmlspecialchars($host['Host']) . '</td>' . "\n";
            $html_output .= '<td>';
            switch ($host['Password']) {
                case 'Y':
                    $html_output .= __('Yes');
                    break;
                case 'N':
                    $html_output .= '<span style="color: #FF0000">' . __('No') . '</span>';
                    break;
                    // this happens if this is a definition not coming from mysql.user
                // this happens if this is a definition not coming from mysql.user
                default:
                    $html_output .= '--';
                    // in future version, replace by "not present"
                    break;
            }
            // end switch
            $html_output .= '</td>' . "\n";
            $html_output .= '<td><code>' . "\n" . '' . implode(',' . "\n" . '            ', $host['privs']) . "\n" . '</code></td>' . "\n";
            if ($GLOBALS['cfgRelation']['menuswork']) {
                $html_output .= '<td class="usrGroup">' . "\n" . (isset($group_assignment[$host['User']]) ? $group_assignment[$host['User']] : '') . '</td>' . "\n";
            }
            $html_output .= '<td>' . ($host['Grant_priv'] == 'Y' ? __('Yes') : __('No')) . '</td>' . "\n";
            $html_output .= '<td class="center">' . PMA_getUserEditLink($host['User'], $host['Host']) . '</td>';
            if ($GLOBALS['cfgRelation']['menuswork'] && $user_group_count > 0) {
                if (empty($host['User'])) {
                    $html_output .= '<td class="center"></td>';
                } else {
                    $html_output .= '<td class="center">' . PMA_getUserGroupEditLink($host['User']) . '</td>';
                }
            }
            $html_output .= '<td class="center">' . PMA_getUserExportLink($host['User'], $host['Host'], isset($_GET['initial']) ? $_GET['initial'] : '') . '</td>';
            $html_output .= '</tr>';
            $odd_row = !$odd_row;
        }
    }
    return $html_output;
}
 /**
  * Test for PMA_getUserEditLink
  *
  * @return void
  */
 public function testPMAGetUserEditLink()
 {
     $username = "******";
     $hostname = "pma_hostname";
     $dbname = "pma_dbname";
     $tablename = "pma_tablename";
     //PMA_getUserEditLink
     $html = PMA_getUserEditLink($username, $hostname, $dbname, $tablename);
     $url_html = PMA_URL_getCommon(array('username' => $username, 'hostname' => $hostname, 'dbname' => $dbname, 'tablename' => $tablename));
     $this->assertContains($url_html, $html);
     $this->assertContains(__('Edit Privileges'), $html);
     //PMA_getUserRevokeLink
     $html = PMA_getUserRevokeLink($username, $hostname, $dbname, $tablename);
     $url_html = PMA_URL_getCommon(array('username' => $username, 'hostname' => $hostname, 'dbname' => $dbname, 'tablename' => $tablename, 'revokeall' => 1));
     $this->assertContains($url_html, $html);
     $this->assertContains(__('Revoke'), $html);
     //PMA_getUserExportLink
     $html = PMA_getUserExportLink($username, $hostname);
     $url_html = PMA_URL_getCommon(array('username' => $username, 'hostname' => $hostname, 'initial' => "", 'export' => 1));
     $this->assertContains($url_html, $html);
     $this->assertContains(__('Export'), $html);
 }