コード例 #1
0
/**
 * Builds the HTML td elements for one database to display in the list
 * of databases from server_databases.php (which can be modified by
 * db_create.php)
 *
 * @param array   $current           current database
 * @param boolean $is_superuser      user status
 * @param string  $url_query         url query
 * @param array   $column_order      column order
 * @param array   $replication_types replication types
 * @param array   $replication_info  replication info
 *
 * @return array $column_order, $out
 */
function PMA_buildHtmlForDb($current, $is_superuser, $url_query, $column_order, $replication_types, $replication_info)
{
    $out = '';
    if ($is_superuser || $GLOBALS['cfg']['AllowUserDropDatabase']) {
        $out .= '<td class="tool">';
        $out .= '<input type="checkbox" name="selected_dbs[]" class="checkall" ' . 'title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" ' . 'value="' . htmlspecialchars($current['SCHEMA_NAME']) . '"';
        if ($GLOBALS['dbi']->isSystemSchema($current['SCHEMA_NAME'], true)) {
            $out .= ' disabled="disabled"';
        }
        $out .= ' /></td>';
    }
    $out .= '<td class="name">' . '<a href="' . PMA\libraries\Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database') . $url_query . '&amp;db=' . urlencode($current['SCHEMA_NAME']) . '" title="' . sprintf(__('Jump to database'), htmlspecialchars($current['SCHEMA_NAME'])) . '">' . ' ' . htmlspecialchars($current['SCHEMA_NAME']) . '</a>' . '</td>';
    foreach ($column_order as $stat_name => $stat) {
        if (array_key_exists($stat_name, $current)) {
            $unit = '';
            if (is_numeric($stat['footer'])) {
                $column_order[$stat_name]['footer'] += $current[$stat_name];
            }
            if ($stat['format'] === 'byte') {
                list($value, $unit) = PMA\libraries\Util::formatByteDown($current[$stat_name], 3, 1);
            } elseif ($stat['format'] === 'number') {
                $value = PMA\libraries\Util::formatNumber($current[$stat_name], 0);
            } else {
                $value = htmlentities($current[$stat_name], 0);
            }
            $out .= '<td class="value">';
            if (isset($stat['description_function'])) {
                $out .= '<dfn title="' . $stat['description_function']($current[$stat_name]) . '">';
            }
            $out .= $value;
            if (isset($stat['description_function'])) {
                $out .= '</dfn>';
            }
            $out .= '</td>';
            if ($stat['format'] === 'byte') {
                $out .= '<td class="unit">' . $unit . '</td>';
            }
        }
    }
    foreach ($replication_types as $type) {
        if ($replication_info[$type]['status']) {
            $out .= '<td class="tool" style="text-align: center;">';
            $key = array_search($current["SCHEMA_NAME"], $replication_info[$type]['Ignore_DB']);
            if (mb_strlen($key) > 0) {
                $out .= PMA\libraries\Util::getIcon('s_cancel.png', __('Not replicated'));
            } else {
                $key = array_search($current["SCHEMA_NAME"], $replication_info[$type]['Do_DB']);
                if (mb_strlen($key) > 0 || isset($replication_info[$type]['Do_DB'][0]) && $replication_info[$type]['Do_DB'][0] == "" && count($replication_info[$type]['Do_DB']) == 1) {
                    // if ($key != null) did not work for index "0"
                    $out .= PMA\libraries\Util::getIcon('s_success.png', __('Replicated'));
                }
            }
            $out .= '</td>';
        }
    }
    if ($is_superuser) {
        $out .= '<td class="tool">' . '<a onclick="' . 'PMA_commonActions.setDb(\'' . PMA_jsFormat($current['SCHEMA_NAME']) . '\');' . '" href="server_privileges.php' . $url_query . '&amp;db=' . urlencode($current['SCHEMA_NAME']) . '&amp;checkprivsdb=' . urlencode($current['SCHEMA_NAME']) . '" title="' . sprintf(__('Check privileges for database "%s".'), htmlspecialchars($current['SCHEMA_NAME'])) . '">' . ' ' . PMA\libraries\Util::getIcon('s_rights.png', __('Check privileges')) . '</a></td>';
    }
    return array($column_order, $out);
}
コード例 #2
0
/**
 * Format Variable
 *
 * @param string $name               variable name
 * @param number $value              variable value
 * @param array  $variable_doc_links documentation links
 *
 * @return string formatted string
 */
function PMA_formatVariable($name, $value, $variable_doc_links)
{
    if (is_numeric($value)) {
        if (isset($variable_doc_links[$name][3]) && $variable_doc_links[$name][3] == 'byte') {
            return '<abbr title="' . PMA\libraries\Util::formatNumber($value, 0) . '">' . implode(' ', PMA\libraries\Util::formatByteDown($value, 3, 3)) . '</abbr>';
        } else {
            return PMA\libraries\Util::formatNumber($value, 0);
        }
    }
    return htmlspecialchars($value);
}
コード例 #3
0
 /**
  * Test for PMA_getHtmlForQueryStatistics
  *
  * @return void
  */
 public function testPMAGetHtmlForQueryStatistics()
 {
     //Call the test function
     $html = PMA_getHtmlForQueryStatistics($this->ServerStatusData);
     $hour_factor = 3600 / $this->ServerStatusData->status['Uptime'];
     $used_queries = $this->ServerStatusData->used_queries;
     $total_queries = array_sum($used_queries);
     $questions_from_start = sprintf(__('Questions since startup: %s'), PMA\libraries\Util::formatNumber($total_queries, 0));
     //validate 1: PMA_getHtmlForQueryStatistics
     $this->assertContains('<h3 id="serverstatusqueries">', $html);
     $this->assertContains($questions_from_start, $html);
     //validate 2: per hour
     $this->assertContains(__('per hour:'), $html);
     $this->assertContains(PMA\libraries\Util::formatNumber($total_queries * $hour_factor, 0), $html);
     //validate 3:per minute
     $value_per_minute = PMA\libraries\Util::formatNumber($total_queries * 60 / $this->ServerStatusData->status['Uptime'], 0);
     $this->assertContains(__('per minute:'), $html);
     $this->assertContains($value_per_minute, $html);
 }
 /**
  * format number test, globals are defined
  *
  * @param float $a Value to format
  * @param int   $b Sensitiveness
  * @param int   $c Number of decimals to retain
  * @param array $d Expected value
  *
  * @return void
  *
  * @dataProvider formatNumberDataProvider
  */
 public function testFormatNumber($a, $b, $c, $d)
 {
     $this->assertEquals($d, (string) PMA\libraries\Util::formatNumber($a, $b, $c, false));
 }
コード例 #5
0
ファイル: sql.lib.php プロジェクト: Devuiux/phpmyadmin
/**
 * Function to get HTML for summary by state table
 *
 * @param array $profiling_stats profiling stats
 *
 * @return string $table html for the table
 */
function PMA_getTableHtmlForProfilingSummaryByState($profiling_stats)
{
    $table = '';
    foreach ($profiling_stats['states'] as $name => $stats) {
        $table .= ' <tr>' . "\n";
        $table .= '<td>' . $name . '</td>' . "\n";
        $table .= '<td align="right">' . PMA\libraries\Util::formatNumber($stats['total_time'], 3, 1) . 's<span style="display:none;" class="rawvalue">' . $stats['total_time'] . '</span></td>' . "\n";
        $table .= '<td align="right">' . PMA\libraries\Util::formatNumber(100 * ($stats['total_time'] / $profiling_stats['total_time']), 0, 2) . '%</td>' . "\n";
        $table .= '<td align="right">' . $stats['calls'] . '</td>' . "\n";
        $table .= '<td align="right">' . PMA\libraries\Util::formatNumber($stats['total_time'] / $stats['calls'], 3, 1) . 's<span style="display:none;" class="rawvalue">' . number_format($stats['total_time'] / $stats['calls'], 8, '.', '') . '</span></td>' . "\n";
        $table .= ' </tr>' . "\n";
    }
    return $table;
}
コード例 #6
0
/**
 * Returns HTML for render variables list
 *
 * @param ServerStatusData $ServerStatusData Server status data
 * @param array            $alerts           Alert Array
 * @param array            $strShowStatus    Status Array
 *
 * @return string
 */
function PMA_getHtmlForRenderVariables($ServerStatusData, $alerts, $strShowStatus)
{
    $retval = '<table class="data noclick" id="serverstatusvariables">';
    $retval .= '<col class="namecol" />';
    $retval .= '<col class="valuecol" />';
    $retval .= '<col class="descrcol" />';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th>' . __('Variable') . '</th>';
    $retval .= '<th>' . __('Value') . '</th>';
    $retval .= '<th>' . __('Description') . '</th>';
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    foreach ($ServerStatusData->status as $name => $value) {
        $retval .= '<tr class="' . (isset($ServerStatusData->allocationMap[$name]) ? ' s_' . $ServerStatusData->allocationMap[$name] : '') . '">';
        $retval .= '<th class="name">';
        $retval .= htmlspecialchars(str_replace('_', ' ', $name));
        // Fields containing % are calculated,
        // they can not be described in MySQL documentation
        if (mb_strpos($name, '%') === false) {
            $retval .= PMA\libraries\Util::showMySQLDocu('server-status-variables', false, 'statvar_' . $name);
        }
        $retval .= '</th>';
        $retval .= '<td class="value"><span class="formatted">';
        if (isset($alerts[$name])) {
            if ($value > $alerts[$name]) {
                $retval .= '<span class="attention">';
            } else {
                $retval .= '<span class="allfine">';
            }
        }
        if (substr($name, -1) === '%') {
            $retval .= htmlspecialchars(PMA\libraries\Util::formatNumber($value, 0, 2)) . ' %';
        } elseif (strpos($name, 'Uptime') !== false) {
            $retval .= htmlspecialchars(PMA\libraries\Util::timespanFormat($value));
        } elseif (is_numeric($value) && $value > 1000) {
            $retval .= '<abbr title="' . htmlspecialchars(PMA\libraries\Util::formatNumber($value, 0)) . '">' . htmlspecialchars(PMA\libraries\Util::formatNumber($value, 3, 1)) . '</abbr>';
        } elseif (is_numeric($value)) {
            $retval .= htmlspecialchars(PMA\libraries\Util::formatNumber($value, 3, 1));
        } else {
            $retval .= htmlspecialchars($value);
        }
        if (isset($alerts[$name])) {
            $retval .= '</span>';
        }
        $retval .= '</span>';
        $retval .= '<span style="display:none;" class="original">';
        if (isset($alerts[$name])) {
            if ($value > $alerts[$name]) {
                $retval .= '<span class="attention">';
            } else {
                $retval .= '<span class="allfine">';
            }
        }
        $retval .= htmlspecialchars($value);
        if (isset($alerts[$name])) {
            $retval .= '</span>';
        }
        $retval .= '</span>';
        $retval .= '</td>';
        $retval .= '<td class="descr">';
        if (isset($strShowStatus[$name])) {
            $retval .= $strShowStatus[$name];
        }
        if (isset($ServerStatusData->links[$name])) {
            foreach ($ServerStatusData->links[$name] as $link_name => $link_url) {
                if ('doc' == $link_name) {
                    $retval .= PMA\libraries\Util::showMySQLDocu($link_url);
                } else {
                    $retval .= ' <a href="' . $link_url . '">' . $link_name . '</a>';
                }
            }
            unset($link_url, $link_name);
        }
        $retval .= '</td>';
        $retval .= '</tr>';
    }
    $retval .= '</tbody>';
    $retval .= '</table>';
    return $retval;
}
コード例 #7
0
/**
 * Returns the html content for the query details
 *
 * @param ServerStatusData $ServerStatusData Server status data
 *
 * @return string
 */
function PMA_getHtmlForServerStatusQueriesDetails($ServerStatusData)
{
    $hour_factor = 3600 / $ServerStatusData->status['Uptime'];
    $used_queries = $ServerStatusData->used_queries;
    $total_queries = array_sum($used_queries);
    // reverse sort by value to show most used statements first
    arsort($used_queries);
    $odd_row = true;
    //(- $ServerStatusData->status['Connections']);
    $perc_factor = 100 / $total_queries;
    $retval = '<table id="serverstatusqueriesdetails" ' . 'class="data sortable noclick">';
    $retval .= '<col class="namecol" />';
    $retval .= '<col class="valuecol" span="3" />';
    $retval .= '<thead>';
    $retval .= '<tr><th>' . __('Statements') . '</th>';
    $retval .= '<th>';
    /* l10n: # = Amount of queries */
    $retval .= __('#');
    $retval .= '</th>';
    $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
    $retval .= '<th>%</div></th>';
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $chart_json = array();
    $query_sum = array_sum($used_queries);
    $other_sum = 0;
    foreach ($used_queries as $name => $value) {
        $odd_row = !$odd_row;
        // For the percentage column, use Questions - Connections, because
        // the number of connections is not an item of the Query types
        // but is included in Questions. Then the total of the percentages is 100.
        $name = str_replace(array('Com_', '_'), array('', ' '), $name);
        // Group together values that make out less than 2% into "Other", but only
        // if we have more than 6 fractions already
        if ($value < $query_sum * 0.02 && count($chart_json) > 6) {
            $other_sum += $value;
        } else {
            $chart_json[$name] = $value;
        }
        $retval .= '<tr class="';
        $retval .= $odd_row ? 'odd' : 'even';
        $retval .= '">';
        $retval .= '<th class="name">' . htmlspecialchars($name) . '</th>';
        $retval .= '<td class="value">';
        $retval .= htmlspecialchars(PMA\libraries\Util::formatNumber($value, 5, 0, true));
        $retval .= '</td>';
        $retval .= '<td class="value">';
        $retval .= htmlspecialchars(PMA\libraries\Util::formatNumber($value * $hour_factor, 4, 1, true));
        $retval .= '</td>';
        $retval .= '<td class="value">';
        $retval .= htmlspecialchars(PMA\libraries\Util::formatNumber($value * $perc_factor, 0, 2));
        $retval .= '</td>';
        $retval .= '</tr>';
    }
    $retval .= '</tbody>';
    $retval .= '</table>';
    $retval .= '<div id="serverstatusquerieschart"></div>';
    $retval .= '<div id="serverstatusquerieschart_data" style="display:none;">';
    if ($other_sum > 0) {
        $chart_json[__('Other')] = $other_sum;
    }
    $retval .= htmlspecialchars(json_encode($chart_json));
    $retval .= '</div>';
    return $retval;
}
コード例 #8
0
/**
 * Prints server state connections information
 *
 * @param ServerStatusData $ServerStatusData Server status data
 *
 * @return string
 */
function PMA_getHtmlForServerStateConnections($ServerStatusData)
{
    $hour_factor = 3600 / $ServerStatusData->status['Uptime'];
    $retval = '<table id="serverstatusconnections" class="data noclick">';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th>' . __('Connections') . '</th>';
    $retval .= '<th>#</th>';
    $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
    $retval .= '<th>%</th>';
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $retval .= '<tr>';
    $retval .= '<th class="name">' . __('Max. concurrent connections') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA\libraries\Util::formatNumber($ServerStatusData->status['Max_used_connections'], 0);
    $retval .= '</td>';
    $retval .= '<td class="value">--- </td>';
    $retval .= '<td class="value">--- </td>';
    $retval .= '</tr>';
    $retval .= '<tr>';
    $retval .= '<th class="name">' . __('Failed attempts') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA\libraries\Util::formatNumber($ServerStatusData->status['Aborted_connects'], 4, 1, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA\libraries\Util::formatNumber($ServerStatusData->status['Aborted_connects'] * $hour_factor, 4, 2, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    if ($ServerStatusData->status['Connections'] > 0) {
        $abortNum = $ServerStatusData->status['Aborted_connects'];
        $connectNum = $ServerStatusData->status['Connections'];
        $retval .= PMA\libraries\Util::formatNumber($abortNum * 100 / $connectNum, 0, 2, true);
        $retval .= '%';
    } else {
        $retval .= '--- ';
    }
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr>';
    $retval .= '<th class="name">' . __('Aborted') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA\libraries\Util::formatNumber($ServerStatusData->status['Aborted_clients'], 4, 1, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA\libraries\Util::formatNumber($ServerStatusData->status['Aborted_clients'] * $hour_factor, 4, 2, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    if ($ServerStatusData->status['Connections'] > 0) {
        $abortNum = $ServerStatusData->status['Aborted_clients'];
        $connectNum = $ServerStatusData->status['Connections'];
        $retval .= PMA\libraries\Util::formatNumber($abortNum * 100 / $connectNum, 0, 2, true);
        $retval .= '%';
    } else {
        $retval .= '--- ';
    }
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr>';
    $retval .= '<th class="name">' . __('Total') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA\libraries\Util::formatNumber($ServerStatusData->status['Connections'], 4, 0);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA\libraries\Util::formatNumber($ServerStatusData->status['Connections'] * $hour_factor, 4, 2);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA\libraries\Util::formatNumber(100, 0, 2);
    $retval .= '%</td>';
    $retval .= '</tr>';
    $retval .= '</tbody>';
    $retval .= '</table>';
    return $retval;
}
コード例 #9
0
/**
 * Returns the html for Column Order
 *
 * @param array $column_order   Column order
 * @param array $first_database The first display database
 *
 * @return string
 */
function PMA_getHtmlForColumnOrder($column_order, $first_database)
{
    $html = "";
    // avoid execution path notice
    $unit = "";
    foreach ($column_order as $stat_name => $stat) {
        if (array_key_exists($stat_name, $first_database)) {
            if ($stat['format'] === 'byte') {
                list($value, $unit) = PMA\libraries\Util::formatByteDown($stat['footer'], 3, 1);
            } elseif ($stat['format'] === 'number') {
                $value = PMA\libraries\Util::formatNumber($stat['footer'], 0);
            } else {
                $value = htmlentities($stat['footer'], 0);
            }
            $html .= '    <th class="value">';
            if (isset($stat['description_function'])) {
                $html .= '<dfn title="' . $stat['description_function']($stat['footer']) . '">';
            }
            $html .= $value;
            if (isset($stat['description_function'])) {
                $html .= '</dfn>';
            }
            $html .= '</th>' . "\n";
            if ($stat['format'] === 'byte') {
                $html .= '    <th class="unit">' . $unit . '</th>' . "\n";
            }
        }
    }
    return $html;
}