/**
 * Prints server state traffic information
 *
 * @param PMA_ServerStatusData $ServerStatusData Server status data
 *
 * @return string
 */
function PMA_getHtmlForServerStateTraffic($ServerStatusData)
{
    $hour_factor = 3600 / $ServerStatusData->status['Uptime'];
    $retval = '<table id="serverstatustraffic" class="data noclick">';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th colspan="2">';
    $retval .= __('Traffic') . '&nbsp;';
    $retval .= PMA_Util::showHint(__('On a busy server, the byte counters may overrun, so those statistics ' . 'as reported by the MySQL server may be incorrect.'));
    $retval .= '</th>';
    $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('Received') . '</th>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'], 3, 1));
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'] * $hour_factor, 3, 1));
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="even">';
    $retval .= '<th class="name">' . __('Sent') . '</th>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_sent'], 3, 1));
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_sent'] * $hour_factor, 3, 1));
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('Total') . '</th>';
    $retval .= '<td class="value">';
    $bytes_received = $ServerStatusData->status['Bytes_received'];
    $bytes_sent = $ServerStatusData->status['Bytes_sent'];
    $retval .= implode(' ', PMA_Util::formatByteDown($bytes_received + $bytes_sent, 3, 1));
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $bytes_received = $ServerStatusData->status['Bytes_received'];
    $bytes_sent = $ServerStatusData->status['Bytes_sent'];
    $retval .= implode(' ', PMA_Util::formatByteDown(($bytes_received + $bytes_sent) * $hour_factor, 3, 1));
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '</tbody>';
    $retval .= '</table>';
    return $retval;
}
/**
 * Returns the html for log selector.
 *
 * @param Array $binary_logs Binary logs file names
 * @param Array $url_params  links parameters
 *
 * @return string
 */
function PMA_getLogSelector($binary_logs, $url_params)
{
    $html = "";
    if (count($binary_logs) > 1) {
        $html .= '<form action="server_binlog.php" method="get">';
        $html .= PMA_URL_getHiddenInputs($url_params);
        $html .= '<fieldset><legend>';
        $html .= __('Select binary log to view');
        $html .= '</legend><select name="log">';
        $full_size = 0;
        foreach ($binary_logs as $each_log) {
            $html .= '<option value="' . $each_log['Log_name'] . '"';
            if ($each_log['Log_name'] == $_REQUEST['log']) {
                $html .= ' selected="selected"';
            }
            $html .= '>' . $each_log['Log_name'];
            if (isset($each_log['File_size'])) {
                $full_size += $each_log['File_size'];
                $html .= ' (' . implode(' ', PMA_Util::formatByteDown($each_log['File_size'], 3, 2)) . ')';
            }
            $html .= '</option>';
        }
        $html .= '</select> ';
        $html .= count($binary_logs) . ' ' . __('Files') . ', ';
        if ($full_size > 0) {
            $html .= implode(' ', PMA_Util::formatByteDown($full_size));
        }
        $html .= '</fieldset>';
        $html .= '<fieldset class="tblFooters">';
        $html .= '<input type="submit" value="' . __('Go') . '" />';
        $html .= '</fieldset>';
        $html .= '</form>';
    }
    return $html;
}
/**
 * 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_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_Util::formatByteDown($current[$stat_name], 3, 1);
            } elseif ($stat['format'] === 'number') {
                $value = PMA_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_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_Util::getIcon('s_success.png', __('Replicated'));
                }
            }
            $out .= '</td>';
        }
    }
    if ($is_superuser && !PMA_DRIZZLE) {
        $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_Util::getIcon('s_rights.png', __('Check Privileges')) . '</a></td>';
    }
    return array($column_order, $out);
}
Beispiel #4
0
 /**
  * returns the pbxt engine specific handling for
  * PMA_ENGINE_DETAILS_TYPE_SIZE variables.
  *
  * @param string $formatted_size the size expression (for example 8MB)
  *
  * @return string the formatted value and its unit
  */
 public function resolveTypeSize($formatted_size)
 {
     if (preg_match('/^[0-9]+[a-zA-Z]+$/', $formatted_size)) {
         $value = PMA_Util::extractValueFromFormattedSize($formatted_size);
     } else {
         $value = $formatted_size;
     }
     return PMA_Util::formatByteDown($value);
 }
/**
 * 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_Util::formatNumber($value, 0) . '">' . implode(' ', PMA_Util::formatByteDown($value, 3, 3)) . '</abbr>';
        } else {
            return PMA_Util::formatNumber($value, 0);
        }
    }
    return htmlspecialchars($value);
}
 /**
  * returns html tables with stats over inno db buffer pool
  *
  * @return string  html table with stats
  */
 public function getPageBufferpool()
 {
     // The following query is only possible because we know
     // that we are on MySQL 5 here (checked above)!
     // side note: I love MySQL 5 for this. :-)
     $sql = '
          SHOW STATUS
         WHERE Variable_name LIKE \'Innodb\\_buffer\\_pool\\_%\'
            OR Variable_name = \'Innodb_page_size\';';
     $status = $GLOBALS['dbi']->fetchResult($sql, 0, 1);
     $output = '<table class="data" id="table_innodb_bufferpool_usage">' . "\n" . '    <caption class="tblHeaders">' . "\n" . '        ' . __('Buffer Pool Usage') . "\n" . '    </caption>' . "\n" . '    <tfoot>' . "\n" . '        <tr>' . "\n" . '            <th colspan="2">' . "\n" . '                ' . __('Total') . "\n" . '                : ' . PMA_Util::formatNumber($status['Innodb_buffer_pool_pages_total'], 0) . '&nbsp;' . __('pages') . ' / ' . join('&nbsp;', PMA_Util::formatByteDown($status['Innodb_buffer_pool_pages_total'] * $status['Innodb_page_size'])) . "\n" . '            </th>' . "\n" . '        </tr>' . "\n" . '    </tfoot>' . "\n" . '    <tbody>' . "\n" . '        <tr class="odd">' . "\n" . '            <th>' . __('Free pages') . '</th>' . "\n" . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_pages_free'], 0) . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="even">' . "\n" . '            <th>' . __('Dirty pages') . '</th>' . "\n" . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_pages_dirty'], 0) . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="odd">' . "\n" . '            <th>' . __('Pages containing data') . '</th>' . "\n" . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_pages_data'], 0) . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="even">' . "\n" . '            <th>' . __('Pages to be flushed') . '</th>' . "\n" . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_pages_flushed'], 0) . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="odd">' . "\n" . '            <th>' . __('Busy pages') . '</th>' . "\n" . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_pages_misc'], 0) . "\n" . '</td>' . "\n" . '        </tr>';
     // not present at least since MySQL 5.1.40
     if (isset($status['Innodb_buffer_pool_pages_latched'])) {
         $output .= '        <tr class="even">' . '            <th>' . __('Latched pages') . '</th>' . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_pages_latched'], 0) . '</td>' . '        </tr>';
     }
     $output .= '    </tbody>' . "\n" . '</table>' . "\n\n" . '<table class="data" id="table_innodb_bufferpool_activity">' . "\n" . '    <caption class="tblHeaders">' . "\n" . '        ' . __('Buffer Pool Activity') . "\n" . '    </caption>' . "\n" . '    <tbody>' . "\n" . '        <tr class="odd">' . "\n" . '            <th>' . __('Read requests') . '</th>' . "\n" . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_read_requests'], 0) . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="even">' . "\n" . '            <th>' . __('Write requests') . '</th>' . "\n" . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_write_requests'], 0) . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="odd">' . "\n" . '            <th>' . __('Read misses') . '</th>' . "\n" . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_reads'], 0) . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="even">' . "\n" . '            <th>' . __('Write waits') . '</th>' . "\n" . '            <td class="value">' . PMA_Util::formatNumber($status['Innodb_buffer_pool_wait_free'], 0) . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="odd">' . "\n" . '            <th>' . __('Read misses in %') . '</th>' . "\n" . '            <td class="value">' . ($status['Innodb_buffer_pool_read_requests'] == 0 ? '---' : htmlspecialchars(PMA_Util::formatNumber($status['Innodb_buffer_pool_reads'] * 100 / $status['Innodb_buffer_pool_read_requests'], 3, 2)) . ' %') . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '        <tr class="even">' . "\n" . '            <th>' . __('Write waits in %') . '</th>' . "\n" . '            <td class="value">' . ($status['Innodb_buffer_pool_write_requests'] == 0 ? '---' : htmlspecialchars(PMA_Util::formatNumber($status['Innodb_buffer_pool_wait_free'] * 100 / $status['Innodb_buffer_pool_write_requests'], 3, 2)) . ' %') . "\n" . '</td>' . "\n" . '        </tr>' . "\n" . '    </tbody>' . "\n" . '</table>' . "\n";
     return $output;
 }
/**
 * Get HTML snippet for display table statistics
 *
 * @param array   $showtable           full table status info
 * @param integer $table_info_num_rows table info number of rows
 * @param boolean $tbl_is_view         whether table is view or not
 * @param boolean $db_is_system_schema whether db is information schema or not
 * @param string  $tbl_storage_engine  table storage engine
 * @param string  $url_query           url query
 * @param string  $tbl_collation       table collation
 *
 * @return string $html_output
 */
function PMA_getHtmlForDisplayTableStats($showtable, $table_info_num_rows, $tbl_is_view, $db_is_system_schema, $tbl_storage_engine, $url_query, $tbl_collation)
{
    if (empty($showtable)) {
        $showtable = $GLOBALS['dbi']->getTable($GLOBALS['db'], $GLOBALS['table'])->sGetStatusInfo(null, true);
    }
    if (empty($showtable['Data_length'])) {
        $showtable['Data_length'] = 0;
    }
    if (empty($showtable['Index_length'])) {
        $showtable['Index_length'] = 0;
    }
    $is_innodb = isset($showtable['Type']) && $showtable['Type'] == 'InnoDB';
    // Gets some sizes
    $table = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
    $mergetable = $table->isMerge();
    // this is to display for example 261.2 MiB instead of 268k KiB
    $max_digits = 3;
    $decimals = 1;
    list($data_size, $data_unit) = PMA_Util::formatByteDown($showtable['Data_length'], $max_digits, $decimals);
    if ($mergetable == false) {
        list($index_size, $index_unit) = PMA_Util::formatByteDown($showtable['Index_length'], $max_digits, $decimals);
    }
    // InnoDB returns a huge value in Data_free, do not use it
    if (!$is_innodb && isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
        list($free_size, $free_unit) = PMA_Util::formatByteDown($showtable['Data_free'], $max_digits, $decimals);
        list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free'], $max_digits, $decimals);
    } else {
        list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
    }
    list($tot_size, $tot_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
    if ($table_info_num_rows > 0) {
        list($avg_size, $avg_unit) = PMA_Util::formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
    }
    return PMA\Template::get('structure/display_table_stats')->render(array('showtable' => $showtable, 'table_info_num_rows' => $table_info_num_rows, 'tbl_is_view' => $tbl_is_view, 'db_is_system_schema' => $db_is_system_schema, 'tbl_storage_engine' => $tbl_storage_engine, 'url_query' => $url_query, 'tbl_collation' => $tbl_collation, 'is_innodb' => $is_innodb, 'mergetable' => $mergetable, 'avg_size' => $avg_size, 'avg_unit' => $avg_unit, 'data_size' => $data_size, 'data_unit' => $data_unit, 'index_size' => $index_size, 'index_unit' => $index_unit, 'free_size' => isset($free_size) ? $free_size : null, 'free_unit' => isset($free_unit) ? $free_unit : null, 'effect_size' => $effect_size, 'effect_unit' => $effect_unit, 'tot_size' => $tot_size, 'tot_unit' => $tot_unit));
}
Beispiel #8
0
            echo ' ('
                . implode(
                    ' ',
                    PMA_Util::formatByteDown(
                        $each_log['File_size'], 3, 2
                    )
                )
                . ')';
        }
        echo '</option>';
    }
    echo '</select> ';
    echo count($binary_logs) . ' ' . __('Files') . ', ';
    if ($full_size > 0) {
        echo implode(
            ' ', PMA_Util::formatByteDown($full_size)
        );
    }
    echo '</fieldset>';
    echo '<fieldset class="tblFooters">';
    echo '<input type="submit" value="' . __('Go') . '" />';
    echo '</fieldset>';
    echo '</form>';
}

echo PMA_Util::getMessage(PMA_Message::success());

/**
 * Displays the page
 */
echo '<table cellpadding="2" cellspacing="1">'
/**
 * Returns JSon for log data with type: general
 *
 * @param int $start Unix Time: Start time for query
 * @param int $end   Unix Time: End time for query
 *
 * @return Array
 */
function PMA_getJsonForLogDataTypeGeneral($start, $end)
{
    $limitTypes = '';
    if (isset($_REQUEST['limitTypes']) && $_REQUEST['limitTypes']) {
        $limitTypes = 'AND argument REGEXP \'^(INSERT|SELECT|UPDATE|DELETE)\' ';
    }
    $query = 'SELECT TIME(event_time) as event_time, user_host, thread_id, ';
    $query .= 'server_id, argument, count(argument) as \'#\' ';
    $query .= 'FROM `mysql`.`general_log` ';
    $query .= 'WHERE command_type=\'Query\' ';
    $query .= 'AND event_time > FROM_UNIXTIME(' . $start . ') ';
    $query .= 'AND event_time < FROM_UNIXTIME(' . $end . ') ';
    $query .= $limitTypes . 'GROUP by argument';
    // HAVING count > 1';
    $result = $GLOBALS['dbi']->tryQuery($query);
    $return = array('rows' => array(), 'sum' => array());
    $insertTables = array();
    $insertTablesFirst = -1;
    $i = 0;
    $removeVars = isset($_REQUEST['removeVariables']) && $_REQUEST['removeVariables'];
    while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
        preg_match('/^(\\w+)\\s/', $row['argument'], $match);
        $type = strtolower($match[1]);
        if (!isset($return['sum'][$type])) {
            $return['sum'][$type] = 0;
        }
        $return['sum'][$type] += $row['#'];
        switch ($type) {
            case 'insert':
                // Group inserts if selected
                if ($removeVars && preg_match('/^INSERT INTO (`|\'|"|)([^\\s\\1]+)\\1/i', $row['argument'], $matches)) {
                    $insertTables[$matches[2]]++;
                    if ($insertTables[$matches[2]] > 1) {
                        $return['rows'][$insertTablesFirst]['#'] = $insertTables[$matches[2]];
                        // Add a ... to the end of this query to indicate that
                        // there's been other queries
                        $temp = $return['rows'][$insertTablesFirst]['argument'];
                        if ($temp[strlen($temp) - 1] != '.') {
                            $return['rows'][$insertTablesFirst]['argument'] .= '<br/>...';
                        }
                        // Group this value, thus do not add to the result list
                        continue 2;
                    } else {
                        $insertTablesFirst = $i;
                        $insertTables[$matches[2]] += $row['#'] - 1;
                    }
                }
                // No break here
            // No break here
            case 'update':
                // Cut off big inserts and updates,
                // but append byte count therefor
                if (strlen($row['argument']) > 220) {
                    $row['argument'] = substr($row['argument'], 0, 200) . '... [' . implode(' ', PMA_Util::formatByteDown(strlen($row['argument']), 2, 2)) . ']';
                }
                break;
            default:
                break;
        }
        $return['rows'][] = $row;
        $i++;
    }
    $return['sum']['TOTAL'] = array_sum($return['sum']);
    $return['numRows'] = count($return['rows']);
    $GLOBALS['dbi']->freeResult($result);
    return $return;
}
/**
 * Get HTML for binary and blob column
 *
 * @param array   $column                description of column in given table
 * @param string  $data                  data to edit
 * @param string  $special_chars         special characters
 * @param integer $biggest_max_file_size biggest max file size for uploading
 * @param string  $backup_field          hidden input field
 * @param string  $column_name_appendix  the name attribute
 * @param string  $onChangeClause        onchange clause for fields
 * @param integer $tabindex              tab index
 * @param integer $tabindex_for_value    offset for the values tabindex
 * @param integer $idindex               id index
 * @param string  $text_dir              text direction
 * @param string  $special_chars_encoded replaced char if the string starts
 *                                       with a \r\n pair (0x0d0a) add an extra \n
 * @param string  $vkey                  [multi_edit]['row_id']
 * @param boolean $is_upload             is upload or not
 *
 * @return string                           an html snippet
 */
function PMA_getBinaryAndBlobColumn($column, $data, $special_chars, $biggest_max_file_size, $backup_field, $column_name_appendix, $onChangeClause, $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded, $vkey, $is_upload)
{
    $html_output = '';
    // Add field type : Protected or Hexadecimal
    $fields_type_html = '<input type="hidden" name="fields_type' . $column_name_appendix . '" value="%s" />';
    // Default value : hex
    $fields_type_val = 'hex';
    if ($GLOBALS['cfg']['ProtectBinary'] === 'blob' && $column['is_blob'] || $GLOBALS['cfg']['ProtectBinary'] === 'all' || $GLOBALS['cfg']['ProtectBinary'] === 'noblob' && !$column['is_blob']) {
        $html_output .= __('Binary - do not edit');
        if (isset($data)) {
            $data_size = PMA_Util::formatByteDown(mb_strlen(stripslashes($data)), 3, 1);
            $html_output .= ' (' . $data_size[0] . ' ' . $data_size[1] . ')';
            unset($data_size);
        }
        $fields_type_val = 'protected';
        $html_output .= '<input type="hidden" name="fields' . $column_name_appendix . '" value="" />';
    } elseif ($column['is_blob'] || $column['len'] > $GLOBALS['cfg']['LimitChars']) {
        $html_output .= "\n" . PMA_getTextarea($column, $backup_field, $column_name_appendix, $onChangeClause, $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded, 'HEX');
    } else {
        // field size should be at least 4 and max $GLOBALS['cfg']['LimitChars']
        $fieldsize = min(max($column['len'], 4), $GLOBALS['cfg']['LimitChars']);
        $html_output .= "\n" . $backup_field . "\n" . PMA_getHTMLinput($column, $column_name_appendix, $special_chars, $fieldsize, $onChangeClause, $tabindex, $tabindex_for_value, $idindex, 'HEX');
    }
    $html_output .= sprintf($fields_type_html, $fields_type_val);
    if ($is_upload && $column['is_blob']) {
        $html_output .= '<br />' . '<input type="file"' . ' name="fields_upload' . $vkey . '[' . $column['Field_md5'] . ']"' . ' class="textfield" id="field_' . $idindex . '_3" size="10"' . ' ' . $onChangeClause . '/>&nbsp;';
        list($html_out, ) = PMA_getMaxUploadSize($column, $biggest_max_file_size);
        $html_output .= $html_out;
    }
    if (!empty($GLOBALS['cfg']['UploadDir'])) {
        $html_output .= PMA_getSelectOptionForUpload($vkey, $column);
    }
    return $html_output;
}
Beispiel #11
0
/**
 * Get HTML snippet for display table statistics
 *
 * @param array   $showtable           full table status info
 * @param integer $table_info_num_rows table info number of rows
 * @param boolean $tbl_is_view         whether table is view or not
 * @param boolean $db_is_system_schema whether db is information schema or not
 * @param string  $tbl_storage_engine  table storage engine
 * @param string  $url_query           url query
 * @param string  $tbl_collation       table collation
 *
 * @return string $html_output
 */
function PMA_getHtmlForDisplayTableStats($showtable, $table_info_num_rows, $tbl_is_view, $db_is_system_schema, $tbl_storage_engine, $url_query, $tbl_collation)
{
    $html_output = '<div id="tablestatistics">';
    if (empty($showtable)) {
        $showtable = PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], null, true);
    }
    $nonisam = false;
    $is_innodb = isset($showtable['Type']) && $showtable['Type'] == 'InnoDB';
    if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
        $nonisam = true;
    }
    // Gets some sizes
    $mergetable = PMA_Table::isMerge($GLOBALS['db'], $GLOBALS['table']);
    // this is to display for example 261.2 MiB instead of 268k KiB
    $max_digits = 3;
    $decimals = 1;
    list($data_size, $data_unit) = PMA_Util::formatByteDown($showtable['Data_length'], $max_digits, $decimals);
    if ($mergetable == false) {
        list($index_size, $index_unit) = PMA_Util::formatByteDown($showtable['Index_length'], $max_digits, $decimals);
    }
    // InnoDB returns a huge value in Data_free, do not use it
    if (!$is_innodb && isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
        list($free_size, $free_unit) = PMA_Util::formatByteDown($showtable['Data_free'], $max_digits, $decimals);
        list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free'], $max_digits, $decimals);
    } else {
        list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
    }
    list($tot_size, $tot_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
    if ($table_info_num_rows > 0) {
        list($avg_size, $avg_unit) = PMA_Util::formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
    }
    // Displays them
    $odd_row = false;
    $html_output .= '<fieldset>' . '<legend>' . __('Information') . '</legend>' . '<a id="showusage"></a>';
    if (!$tbl_is_view && !$db_is_system_schema) {
        $html_output .= '<table id="tablespaceusage" class="data">' . '<caption class="tblHeaders">' . __('Space usage') . '</caption>' . '<tbody>';
        $html_output .= PMA_getHtmlForSpaceUsageTableRow($odd_row, __('Data'), $data_size, $data_unit);
        $odd_row = !$odd_row;
        if (isset($index_size)) {
            $html_output .= PMA_getHtmlForSpaceUsageTableRow($odd_row, __('Index'), $index_size, $index_unit);
            $odd_row = !$odd_row;
        }
        if (isset($free_size)) {
            $html_output .= PMA_getHtmlForSpaceUsageTableRow($odd_row, __('Overhead'), $free_size, $free_unit);
            $html_output .= PMA_getHtmlForSpaceUsageTableRow($odd_row, __('Effective'), $effect_size, $effect_unit);
            $odd_row = !$odd_row;
        }
        if (isset($tot_size) && $mergetable == false) {
            $html_output .= PMA_getHtmlForSpaceUsageTableRow($odd_row, __('Total'), $tot_size, $tot_unit);
            $odd_row = !$odd_row;
        }
        // Optimize link if overhead
        if (isset($free_size) && !PMA_DRIZZLE && ($tbl_storage_engine == 'MYISAM' || $tbl_storage_engine == 'ARIA' || $tbl_storage_engine == 'MARIA' || $tbl_storage_engine == 'BDB')) {
            $html_output .= PMA_getHtmlForOptimizeLink($url_query);
        }
        $html_output .= '</tbody>' . '</table>';
    }
    $html_output .= getHtmlForRowStatsTable($showtable, $tbl_collation, $is_innodb, $mergetable, isset($avg_size) ? $avg_size : '', isset($avg_unit) ? $avg_unit : '');
    $html_output .= '</fieldset>' . '</div>';
    return $html_output;
}
Beispiel #12
0
        echo $generated_html;

        echo '</tr>' . "\n";
    } // end foreach ($databases as $key => $current)
    unset($current, $odd_row);

    echo '</tbody><tfoot><tr>' . "\n";
    if ($is_superuser || $cfg['AllowUserDropDatabase']) {
        echo '    <th></th>' . "\n";
    }
    echo '    <th>' . __('Total') . ': <span id="databases_count">' . $databases_count . '</span></th>' . "\n";
    foreach ($column_order as $stat_name => $stat) {
        if (array_key_exists($stat_name, $first_database)) {
            if ($stat['format'] === 'byte') {
                list($value, $unit) = PMA_Util::formatByteDown($stat['footer'], 3, 1);
            } elseif ($stat['format'] === 'number') {
                $value = PMA_Util::formatNumber($stat['footer'], 0);
            } else {
                $value = htmlentities($stat['footer'], 0);
            }
            echo '    <th class="value">';
            if (isset($stat['description_function'])) {
                echo '<dfn title="' . $stat['description_function']($stat['footer']) . '">';
            }
            echo $value;
            if (isset($stat['description_function'])) {
                echo '</dfn>';
            }
            echo '</th>' . "\n";
            if ($stat['format'] === 'byte') {
Beispiel #13
0
                } else {
                    unset($free_size);
                    unset($free_unit);
                    list($effect_size, $effect_unit)
                        = PMA_Util::formatByteDown(
                            $showtable['Data_length'] + $showtable['Index_length']
                        );
                }
                list($tot_size, $tot_unit) = PMA_Util::formatByteDown(
                    $showtable['Data_length'] + $showtable['Index_length']
                );
                if ($num_rows > 0) {
                    list($avg_size, $avg_unit)
                        = PMA_Util::formatByteDown(
                            ($showtable['Data_length'] + $showtable['Index_length'])
                            / $showtable['Rows'],
                            6,
                            1
                        );
                }

                // Displays them
                echo '<br /><br />';

                echo '<table cellspacing="0" cellpadding="0">';
                echo "\n";
                echo '<tr>';

                // Space usage
                echo '<td class="vtop">';
                echo '<big>' . __('Space usage') . ':</big>';
                echo '<table width="100%">';
 /**
  * Test for PMA_getHtmlForColumnOrder
  *
  * @return void
  */
 public function testPMAGetHtmlForColumnOrder()
 {
     //Mock DBI
     $dbi = $this->getMockBuilder('PMA_DatabaseInterface')->disableOriginalConstructor()->getMock();
     $GLOBALS['dbi'] = $dbi;
     $column_order = array("first_database" => array('format' => 'byte', 'footer' => '10333'));
     $first_database = array("first_database" => "db1");
     $html = PMA_getHtmlForColumnOrder($column_order, $first_database);
     $stat = $column_order["first_database"];
     list($value, $unit) = PMA_Util::formatByteDown($stat['footer'], 3, 1);
     $this->assertContains($value, $html);
     $this->assertContains($unit, $html);
 }
Beispiel #15
0
/**
 * Format Variable
 *
 * @param string  $name  variable name
 * @param numeric $value variable value
 *
 * @return formatted string
 */
function formatVariable($name, $value)
{
    global $VARIABLE_DOC_LINKS;
    if (is_numeric($value)) {
        if (isset($VARIABLE_DOC_LINKS[$name][3]) && $VARIABLE_DOC_LINKS[$name][3] == 'byte') {
            return '<abbr title="' . PMA_Util::formatNumber($value, 0) . '">' . implode(' ', PMA_Util::formatByteDown($value, 3, 3)) . '</abbr>';
        } else {
            return PMA_Util::formatNumber($value, 0);
        }
    }
    return htmlspecialchars($value);
}
Beispiel #16
0
    <th class="center">
        <?php 
    echo sprintf(_ngettext('%s table', '%s tables', $num_tables), PMA_Util::formatNumber($num_tables, 0));
    ?>
    </th>
    <th class="right nowrap">
        <?php 
    echo PMA_Util::formatNumber($sum_entries, 0);
    ?>
    </th>
    <th class="center">
        --
    </th>
    <?php 
    if ($cfg['ShowStats']) {
        list($sum_formated, $unit) = PMA_Util::formatByteDown($sum_size, 3, 1);
        ?>
    <th class="right nowrap">
        <?php 
        echo $sum_formated . ' ' . $unit;
        ?>
    </th>
        <?php 
    }
    ?>
    <th></th>
</tr>
</tbody>
</table>
    <?php 
}
/**
 * Prints server traffic information
 *
 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
 *
 * @return string
 */
function getServerTrafficHtml($ServerStatusData)
{
    $hour_factor = 3600 / $ServerStatusData->status['Uptime'];
    $start_time = PMA_DBI_fetch_value('SELECT UNIX_TIMESTAMP() - ' . $ServerStatusData->status['Uptime']);
    $retval = '<h3>';
    $retval .= sprintf(__('Network traffic since startup: %s'), implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'] + $ServerStatusData->status['Bytes_sent'], 3, 1)));
    $retval .= '</h3>';
    $retval .= '<p>';
    $retval .= sprintf(__('This MySQL server has been running for %1$s. It started up on %2$s.'), PMA_Util::timespanFormat($ServerStatusData->status['Uptime']), PMA_Util::localisedDate($start_time)) . "\n";
    $retval .= '</p>';
    if ($GLOBALS['server_master_status'] || $GLOBALS['server_slave_status']) {
        $retval .= '<p class="notice">';
        if ($GLOBALS['server_master_status'] && $GLOBALS['server_slave_status']) {
            $retval .= __('This MySQL server works as <b>master</b> and ' . '<b>slave</b> in <b>replication</b> process.');
        } elseif ($GLOBALS['server_master_status']) {
            $retval .= __('This MySQL server works as <b>master</b> ' . 'in <b>replication</b> process.');
        } elseif ($GLOBALS['server_slave_status']) {
            $retval .= __('This MySQL server works as <b>slave</b> ' . 'in <b>replication</b> process.');
        }
        $retval .= ' ';
        $retval .= __('For further information about replication status on the server, ' . 'please visit the <a href="#replication">replication section</a>.');
        $retval .= '</p>';
    }
    /*
     * if the server works as master or slave in replication process,
     * display useful information
     */
    if ($GLOBALS['server_master_status'] || $GLOBALS['server_slave_status']) {
        $retval .= '<hr class="clearfloat" />';
        $retval .= '<h3><a name="replication">';
        $retval .= __('Replication status');
        $retval .= '</a></h3>';
        foreach ($GLOBALS['replication_types'] as $type) {
            if (isset(${"server_{$type}_status"}) && ${"server_{$type}_status"}) {
                PMA_replication_print_status_table($type);
            }
        }
    }
    $retval .= '<table id="serverstatustraffic" class="data noclick">';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th colspan="2">';
    $retval .= __('Traffic') . '&nbsp;';
    $retval .= PMA_Util::showHint(__('On a busy server, the byte counters may overrun, so those statistics ' . 'as reported by the MySQL server may be incorrect.'));
    $retval .= '</th>';
    $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('Received') . '</th>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'], 3, 1));
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'] * $hour_factor, 3, 1));
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="even">';
    $retval .= '<th class="name">' . __('Sent') . '</th>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_sent'], 3, 1));
    $retval .= '</td>';
    $retval .= '<td class="value"><?php echo';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_sent'] * $hour_factor, 3, 1));
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('Total') . '</th>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'] + $ServerStatusData->status['Bytes_sent'], 3, 1));
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown(($ServerStatusData->status['Bytes_received'] + $ServerStatusData->status['Bytes_sent']) * $hour_factor, 3, 1));
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '</tbody>';
    $retval .= '</table>';
    $retval .= '<table id="serverstatusconnections" class="data noclick">';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th colspan="2">' . __('Connections') . '</th>';
    $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
    $retval .= '<th>%</th>';
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('max. concurrent connections') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Max_used_connections'], 0);
    $retval .= '</td>';
    $retval .= '<td class="value">--- </td>';
    $retval .= '<td class="value">--- </td>';
    $retval .= '</tr>';
    $retval .= '<tr class="even">';
    $retval .= '<th class="name">' . __('Failed attempts') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_connects'], 4, 1, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_connects'] * $hour_factor, 4, 2, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    if ($ServerStatusData->status['Connections'] > 0) {
        $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_connects'] * 100 / $ServerStatusData->status['Connections'], 0, 2, true);
        $retval .= '%';
    } else {
        $retval .= '--- ';
    }
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('Aborted') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_clients'], 4, 1, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_clients'] * $hour_factor, 4, 2, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    if ($ServerStatusData->status['Connections'] > 0) {
        $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_clients'] * 100 / $ServerStatusData->status['Connections'], 0, 2, true);
        $retval .= '%';
    } else {
        $retval .= '--- ';
    }
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="even">';
    $retval .= '<th class="name">' . __('Total') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Connections'], 4, 0);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Connections'] * $hour_factor, 4, 2);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber(100, 0, 2);
    $retval .= '%</td>';
    $retval .= '</tr>';
    $retval .= '</tbody>';
    $retval .= '</table>';
    $url_params = array();
    $show_full_sql = !empty($_REQUEST['full']);
    if ($show_full_sql) {
        $url_params['full'] = 1;
        $full_text_link = 'server_status.php' . PMA_generate_common_url(array(), 'html', '?');
    } else {
        $full_text_link = 'server_status.php' . PMA_generate_common_url(array('full' => 1));
    }
    // This array contains display name and real column name of each
    // sortable column in the table
    $sortable_columns = array(array('column_name' => __('ID'), 'order_by_field' => 'Id'), array('column_name' => __('User'), 'order_by_field' => 'User'), array('column_name' => __('Host'), 'order_by_field' => 'Host'), array('column_name' => __('Database'), 'order_by_field' => 'db'), array('column_name' => __('Command'), 'order_by_field' => 'Command'), array('column_name' => __('Time'), 'order_by_field' => 'Time'), array('column_name' => __('Status'), 'order_by_field' => 'State'), array('column_name' => __('SQL query'), 'order_by_field' => 'Info'));
    $sortable_columns_count = count($sortable_columns);
    if (PMA_DRIZZLE) {
        $sql_query = "SELECT\n                p.id       AS Id,\n                p.username AS User,\n                p.host     AS Host,\n                p.db       AS db,\n                p.command  AS Command,\n                p.time     AS Time,\n                p.state    AS State,\n                " . ($show_full_sql ? 's.query' : 'left(p.info, ' . (int) $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')') . " AS Info\n            FROM data_dictionary.PROCESSLIST p\n                " . ($show_full_sql ? 'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id' : '');
        if (!empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order'])) {
            $sql_query .= ' ORDER BY p.' . $_REQUEST['order_by_field'] . ' ' . $_REQUEST['sort_order'];
        }
    } else {
        $sql_query = $show_full_sql ? 'SHOW FULL PROCESSLIST' : 'SHOW PROCESSLIST';
        if (!empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order'])) {
            $sql_query = 'SELECT * FROM `INFORMATION_SCHEMA`.`PROCESSLIST` ORDER BY `' . $_REQUEST['order_by_field'] . '` ' . $_REQUEST['sort_order'];
        }
    }
    $result = PMA_DBI_query($sql_query);
    /**
     * Displays the page
     */
    $retval .= '<table id="tableprocesslist" class="data clearfloat noclick sortable">';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th>' . __('Processes') . '</th>';
    foreach ($sortable_columns as $column) {
        $is_sorted = !empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order']) && $_REQUEST['order_by_field'] == $column['order_by_field'];
        $column['sort_order'] = 'ASC';
        if ($is_sorted && $_REQUEST['sort_order'] === 'ASC') {
            $column['sort_order'] = 'DESC';
        }
        if ($is_sorted) {
            if ($_REQUEST['sort_order'] == 'ASC') {
                $asc_display_style = 'inline';
                $desc_display_style = 'none';
            } elseif ($_REQUEST['sort_order'] == 'DESC') {
                $desc_display_style = 'inline';
                $asc_display_style = 'none';
            }
        }
        $retval .= '<th>';
        $retval .= '<a href="server_status.php' . PMA_generate_common_url($column) . '" ';
        if ($is_sorted) {
            $retval .= 'onmouseout="$(\'.soimg\').toggle()" ' . 'onmouseover="$(\'.soimg\').toggle()"';
        }
        $retval .= '>';
        $retval .= $column['column_name'];
        if ($is_sorted) {
            $retval .= '<img class="icon ic_s_desc soimg" alt="' . __('Descending') . '" title="" src="themes/dot.gif" ' . 'style="display: ' . $desc_display_style . '" />';
            $retval .= '<img class="icon ic_s_asc soimg hide" alt="' . __('Ascending') . '" title="" src="themes/dot.gif" ' . 'style="display: ' . $asc_display_style . '" />';
        }
        $retval .= '</a>';
        if (!PMA_DRIZZLE && 0 === --$sortable_columns_count) {
            $retval .= '<a href="' . $full_text_link . '">';
            if ($show_full_sql) {
                $retval .= PMA_Util::getImage('s_partialtext.png', __('Truncate Shown Queries'));
            } else {
                $retval .= PMA_Util::getImage('s_fulltext.png', __('Show Full Queries'));
            }
            $retval .= '</a>';
        }
        $retval .= '</th>';
    }
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $odd_row = true;
    while ($process = PMA_DBI_fetch_assoc($result)) {
        // Array keys need to modify due to the way it has used
        // to display column values
        if (!empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order'])) {
            foreach (array_keys($process) as $key) {
                $new_key = ucfirst(strtolower($key));
                $process[$new_key] = $process[$key];
                unset($process[$key]);
            }
        }
        $url_params['kill'] = $process['Id'];
        $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
        $retval .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">';
        $retval .= '<td><a href="' . $kill_process . '">' . __('Kill') . '</a></td>';
        $retval .= '<td class="value">' . $process['Id'] . '</td>';
        $retval .= '<td>' . htmlspecialchars($process['User']) . '</td>';
        $retval .= '<td>' . htmlspecialchars($process['Host']) . '</td>';
        $retval .= '<td>' . (!isset($process['db']) || !strlen($process['db']) ? '<i>' . __('None') . '</i>' : htmlspecialchars($process['db'])) . '</td>';
        $retval .= '<td>' . htmlspecialchars($process['Command']) . '</td>';
        $retval .= '<td class="value">' . $process['Time'] . '</td>';
        $retval .= '<td>' . (empty($process['State']) ? '---' : $process['State']) . '</td>';
        $retval .= '<td>';
        if (empty($process['Info'])) {
            $retval .= '---';
        } else {
            if (!$show_full_sql && strlen($process['Info']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
                $retval .= htmlspecialchars(substr($process['Info'], 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'])) . '[...]';
            } else {
                $retval .= PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']));
            }
        }
        $retval .= '</td>';
        $retval .= '</tr>';
        $odd_row = !$odd_row;
    }
    $retval .= '</tbody>';
    $retval .= '</table>';
    return $retval;
}
 $mergetable = PMA_Table::isMerge($db, $table);
 list($data_size, $data_unit) = PMA_Util::formatByteDown($showtable['Data_length']);
 if ($mergetable == false) {
     list($index_size, $index_unit) = PMA_Util::formatByteDown($showtable['Index_length']);
 }
 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
     list($free_size, $free_unit) = PMA_Util::formatByteDown($showtable['Data_free']);
     list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
 } else {
     unset($free_size);
     unset($free_unit);
     list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
 }
 list($tot_size, $tot_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
 if ($num_rows > 0) {
     list($avg_size, $avg_unit) = PMA_Util::formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
 }
 // Displays them
 echo '<br /><br />';
 echo '<table cellspacing="0" cellpadding="0">';
 echo "\n";
 echo '<tr>';
 // Space usage
 echo '<td class="vtop">';
 echo '<big>' . __('Space usage') . ':</big>';
 echo '<table width="100%">';
 echo '<tr>';
 echo '<td style="padding-right: 10px">' . __('Data') . '</td>';
 echo '<td class="right">' . $data_size . '</td>';
 echo '<td>' . $data_unit . '</td>';
 echo '</tr>';
Beispiel #19
0
/**
 * Wrapper around PMA_Util::formatByteDown
 *
 * @param double $value the value to format
 * @param int    $limes the sensitiveness
 * @param int    $comma the number of decimals to retain
 *
 * @return array    the formatted value and its unit
 */
function ADVISOR_formatByteDown($value, $limes = 6, $comma = 0)
{
    return implode(' ', PMA_Util::formatByteDown($value, $limes, $comma));
}
Beispiel #20
0
                                 $return['rows'][$insertTablesFirst]['argument'] .= '<br/>...';
                             }
                             // Group this value, thus do not add to the result list
                             continue 2;
                         } else {
                             $insertTablesFirst = $i;
                             $insertTables[$matches[2]] += $row['#'] - 1;
                         }
                     }
                     // No break here
                 // No break here
                 case 'update':
                     // Cut off big inserts and updates,
                     // but append byte count therefor
                     if (strlen($row['argument']) > 220) {
                         $row['argument'] = substr($row['argument'], 0, 200) . '... [' . implode(' ', PMA_Util::formatByteDown(strlen($row['argument']), 2, 2)) . ']';
                     }
                     break;
                 default:
                     break;
             }
             $return['rows'][] = $row;
             $i++;
         }
         $return['sum']['TOTAL'] = array_sum($return['sum']);
         $return['numRows'] = count($return['rows']);
         PMA_DBI_free_result($result);
         PMA_Response::getInstance()->addJSON('message', $return);
         exit;
     }
 }
 /**
  * Returns the engine specific handling for
  * PMA_ENGINE_DETAILS_TYPE_SIZE type variables.
  *
  * This function should be overridden when
  * PMA_ENGINE_DETAILS_TYPE_SIZE type needs to be
  * handled differently for a particular engine.
  *
  * @param integer $value Value to format
  *
  * @return string the formatted value and its unit
  */
 function resolveTypeSize($value)
 {
     return PMA_Util::formatByteDown($value);
 }
Beispiel #22
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 = "";
    foreach ($column_order as $stat_name => $stat) {
        if (array_key_exists($stat_name, $first_database)) {
            if ($stat['format'] === 'byte') {
                list($value, $unit) = PMA_Util::formatByteDown($stat['footer'], 3, 1);
            } elseif ($stat['format'] === 'number') {
                $value = PMA_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;
}
 /**
  * Tests for PMA_getHtmlForSpaceUsageAndRowStatistics() method.
  *
  * @return void
  * @test
  */
 public function testPMAGetHtmlForSpaceUsageAndRowStatistics()
 {
     $showtable = array('Row_format' => "Fixed", 'Rows' => 10, 'Avg_row_length' => 123, 'Data_length' => 345, 'Auto_increment' => 1234, 'Create_time' => "today", 'Update_time' => "time2", 'Check_time' => "yesterday", 'Data_length' => 10, 'Index_length' => 12334, 'Data_length' => 4567, 'Data_free' => 3456, 'Check_time' => 1234);
     $db = "pma_db";
     $table = "pma_table";
     $cell_align_left = "cell_align_left";
     $html = PMA_getHtmlForSpaceUsageAndRowStatistics($showtable, $db, $table, $cell_align_left);
     //validation 1 : $data_size, $data_unit
     list($data_size, $data_unit) = PMA_Util::formatByteDown($showtable['Data_length']);
     $this->assertContains($data_size, $html);
     $this->assertContains($data_unit, $html);
     //validation 2 : $data_size, $data_unit
     list($index_size, $index_unit) = PMA_Util::formatByteDown($showtable['Index_length']);
     $this->assertContains($data_size, $html);
     $this->assertContains($data_unit, $html);
     //validation 3 : $free_size, $free_unit
     list($free_size, $free_unit) = PMA_Util::formatByteDown($showtable['Data_free']);
     $this->assertContains($free_size, $html);
     $this->assertContains($free_unit, $html);
     //validation 4 : $effect_size, $effect_unit
     list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
     $this->assertContains($effect_size, $html);
     $this->assertContains($effect_unit, $html);
     //validation 5 : $effect_size, $effect_unit
     list($tot_size, $tot_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
     $this->assertContains($tot_size, $html);
     $this->assertContains($tot_unit, $html);
 }
Beispiel #24
0
 /**
  * Verifies what to do with non-printable contents (binary or BLOB)
  * in Browse mode.
  *
  * @param string  $category              BLOB|BINARY|GEOMETRY
  * @param string  $content               the binary content
  * @param mixed   $transformation_plugin transformation plugin.
  *                                       Can also be the default function:
  *                                       PMA_mimeDefaultFunction
  * @param string  $transform_options     transformation parameters
  * @param string  $default_function      default transformation function
  * @param object  $meta                  the meta-information about the field
  * @param array   $url_params            parameters that should go to the
  *                                       download link
  * @param boolean &$is_truncated         the result is truncated or not
  *
  * @return mixed  string or float
  *
  * @access  private
  *
  * @see     _getDataCellForGeometryColumns(),
  *          _getDataCellForNonNumericColumns(),
  *          _getSortedColumnMessage()
  */
 private function _handleNonPrintableContents($category, $content, $transformation_plugin, $transform_options, $default_function, $meta, $url_params = array(), &$is_truncated = null)
 {
     $is_truncated = false;
     $result = '[' . $category;
     if (isset($content)) {
         $size = mb_strlen($content);
         $display_size = PMA_Util::formatByteDown($size, 3, 1);
         $result .= ' - ' . $display_size[0] . ' ' . $display_size[1];
     } else {
         $result .= ' - NULL';
         $size = 0;
     }
     $result .= ']';
     // if we want to use a text transformation on a BLOB column
     if (gettype($transformation_plugin) === "object") {
         $posMimeOctetstream = strpos($transformation_plugin->getMIMESubtype(), 'Octetstream');
         $posMimeText = strpos($transformation_plugin->getMIMEtype(), 'Text');
         if ($posMimeOctetstream || $posMimeText !== false) {
             // Applying Transformations on hex string of binary data
             // seems more appropriate
             $result = pack("H*", bin2hex($content));
         }
     }
     if ($size <= 0) {
         return $result;
     }
     if ($default_function != $transformation_plugin) {
         $result = $transformation_plugin->applyTransformation($result, $transform_options, $meta);
         return $result;
     }
     $result = $default_function($result, array(), $meta);
     if ($_SESSION['tmpval']['display_binary'] && $meta->type === self::STRING_FIELD || $_SESSION['tmpval']['display_blob'] && stristr($meta->type, self::BLOB_FIELD)) {
         // in this case, restart from the original $content
         $result = bin2hex($content);
         $is_truncated = $this->_getPartialText($result);
     }
     /* Create link to download */
     // in PHP < 5.5, empty() only checks variables
     $tmpdb = $this->__get('db');
     if (count($url_params) > 0 && (!empty($tmpdb) && !empty($meta->orgtable))) {
         $result = '<a href="tbl_get_field.php' . PMA_URL_getCommon($url_params) . '" class="disableAjax">' . $result . '</a>';
     }
     return $result;
 }
 /**
  * Verifies what to do with non-printable contents (binary or BLOB)
  * in Browse mode.
  *
  * @param string $category              BLOB|BINARY|GEOMETRY
  * @param string $content               the binary content
  * @param string $transformation_plugin transformation plugin.
  *                                      Can also be the default function:
  *                                      PMA_mimeDefaultFunction
  * @param string $transform_options     transformation parameters
  * @param string $default_function      default transformation function
  * @param object $meta                  the meta-information about the field
  * @param array  $url_params            parameters that should go to the
  *                                      download link
  *
  * @return mixed  string or float
  *
  * @access  private
  *
  * @see     _getDataCellForBlobColumns(),
  *          _getDataCellForGeometryColumns(),
  *          _getDataCellForNonNumericAndNonBlobColumns(),
  *          _getSortedColumnMessage()
  */
 private function _handleNonPrintableContents($category, $content, $transformation_plugin, $transform_options, $default_function, $meta, $url_params = array())
 {
     $result = '[' . $category;
     if (isset($content)) {
         $size = strlen($content);
         $display_size = PMA_Util::formatByteDown($size, 3, 1);
         $result .= ' - ' . $display_size[0] . ' ' . $display_size[1];
     } else {
         $result .= ' - NULL';
         $size = 0;
     }
     $result .= ']';
     // if we want to use a text transformation on a BLOB column
     if (gettype($transformation_plugin) == "object" && (strpos($transformation_plugin->getMIMESubtype(), 'Octetstream') || strpos($transformation_plugin->getMIMEtype(), 'Text') !== false)) {
         $result = $content;
     }
     if ($size > 0) {
         if ($default_function != $transformation_plugin) {
             $result = $transformation_plugin->applyTransformation($result, $transform_options, $meta);
         } else {
             $result = $this->{$default_function}($result, array(), $meta);
             if (stristr($meta->type, self::BLOB_FIELD) && $_SESSION['tmpval']['display_blob']) {
                 // in this case, restart from the original $content
                 $result = $this->_displayBinaryAsPrintable($content, 'blob');
             }
             /* Create link to download */
             if (count($url_params) > 0) {
                 $result = '<a href="tbl_get_field.php' . PMA_URL_getCommon($url_params) . '" class="disableAjax">' . $result . '</a>';
             }
         }
     }
     return $result;
 }
 /**
  * format byte test, globals are defined
  *
  * @param float $a Value to format
  * @param int   $b Sensitiveness
  * @param int   $c Number of decimals to retain
  * @param array $e Expected value
  *
  * @return void
  *
  * @dataProvider formatByteDownDataProvider
  */
 public function testFormatByteDown($a, $b, $c, $e)
 {
     $result = PMA_Util::formatByteDown($a, $b, $c);
     $result[0] = trim($result[0]);
     $this->assertEquals($e, $result);
 }
Beispiel #27
0
 $tbl_url_params['db'] = $db;
 $tbl_url_params['table'] = $table;
 $is_show_stats = $cfg['ShowStats'];
 $tbl_stats_result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_Util::backquote($db) . ' LIKE \'' . PMA_Util::sqlAddSlashes($table, true) . '\';');
 $tbl_stats = PMA_DBI_fetch_assoc($tbl_stats_result);
 PMA_DBI_free_result($tbl_stats_result);
 unset($tbl_stats_result);
 if ($is_show_stats) {
     $sum_size = (double) 0;
     $overhead_size = (double) 0;
     $overhead_check = '';
     $tblsize = doubleval($tbl_stats['Data_length']) + doubleval($tbl_stats['Index_length']);
     $sum_size += $tblsize;
     list($formatted_size, $unit) = PMA_Util::formatByteDown($tblsize, 3, $tblsize > 0 ? 1 : 0);
     if (isset($tbl_stats['Data_free']) && $tbl_stats['Data_free'] > 0) {
         list($formatted_overhead, $overhead_unit) = PMA_Util::formatByteDown($tbl_stats['Data_free'], 3, $tbl_stats['Data_free'] > 0 ? 1 : 0);
         $overhead_size += $tbl_stats['Data_free'];
     }
     if (isset($formatted_overhead)) {
         $overhead = '<span>' . $formatted_overhead . '</span>' . '<span class="unit">' . $overhead_unit . '</span>';
         unset($formatted_overhead);
     } else {
         $overhead = '-';
     }
 }
 $new_table_string = '<tr>' . "\n";
 $new_table_string .= '<td class="center">' . '<input type="checkbox" id="checkbox_tbl_"' . ' name="selected_tbl[]" value="' . htmlspecialchars($table) . '" />' . '</td>' . "\n";
 $new_table_string .= '<th>';
 $new_table_string .= '<a href="sql.php' . PMA_generate_common_url($tbl_url_params) . '">' . htmlspecialchars($table) . '</a>';
 if (PMA_Tracker::isActive()) {
     $truename = str_replace(' ', '&nbsp;', htmlspecialchars($table));
Beispiel #28
0
    foreach ($binary_logs as $each_log) {
        echo '<option value="' . $each_log['Log_name'] . '"';
        if ($each_log['Log_name'] == $_REQUEST['log']) {
            echo ' selected="selected"';
        }
        echo '>' . $each_log['Log_name'];
        if (isset($each_log['File_size'])) {
            $full_size += $each_log['File_size'];
            echo ' (' . implode(' ', PMA_Util::formatByteDown($each_log['File_size'], 3, 2)) . ')';
        }
        echo '</option>';
    }
    echo '</select> ';
    echo count($binary_logs) . ' ' . __('Files') . ', ';
    if ($full_size > 0) {
        echo implode(' ', PMA_Util::formatByteDown($full_size));
    }
    echo '</fieldset>';
    echo '<fieldset class="tblFooters">';
    echo '<input type="submit" value="' . __('Go') . '" />';
    echo '</fieldset>';
    echo '</form>';
}
echo PMA_Util::getMessage(PMA_Message::success());
/**
 * Displays the page
 */
echo '<table cellpadding="2" cellspacing="1">' . '<thead>' . '<tr>' . '<td colspan="6" class="center">';
// we do not now how much rows are in the binlog
// so we can just force 'NEXT' button
if ($pos > 0) {
/**
 * return html for Space Usage And Row Statistic
 *
 * @param array  $showtable       showing table information
 * @param string $db              database
 * @param string $table           table
 * @param int    $cell_align_left cell align left
 *
 * @return string
 */
function PMA_getHtmlForSpaceUsageAndRowStatistics($showtable, $db, $table, $cell_align_left)
{
    $html = '';
    $nonisam = false;
    if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
        $nonisam = true;
    }
    if ($nonisam == false) {
        // Gets some sizes
        $mergetable = PMA_Table::isMerge($db, $table);
        list($data_size, $data_unit) = PMA_Util::formatByteDown($showtable['Data_length']);
        if ($mergetable == false) {
            list($index_size, $index_unit) = PMA_Util::formatByteDown($showtable['Index_length']);
        }
        if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
            list($free_size, $free_unit) = PMA_Util::formatByteDown($showtable['Data_free']);
            list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
        } else {
            unset($free_size);
            unset($free_unit);
            list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
        }
        list($tot_size, $tot_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
        $num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
        if ($num_rows > 0) {
            list($avg_size, $avg_unit) = PMA_Util::formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
        }
        // Displays them
        $html .= '<br /><br />';
        $html .= PMA_getHtmlForSpaceUsage($data_size, $data_unit, isset($index_size) ? $index_size : null, isset($index_unit) ? $index_unit : null, isset($free_size) ? $free_size : null, isset($free_unit) ? $free_unit : null, isset($effect_size) ? $effect_size : null, isset($effect_unit) ? $effect_unit : null, isset($tot_size) ? $tot_size : null, isset($tot_unit) ? $tot_unit : null, $mergetable);
        $html .= '</td>';
        $html .= PMA_getHtmlForRowStatistics($showtable, $cell_align_left, isset($avg_size) ? $avg_size : 0, isset($avg_unit) ? $avg_unit : 0, $mergetable);
        $html .= "\n";
        $html .= '</table>';
        $html .= '</td>';
        $html .= '</tr>';
        $html .= '</table>';
    }
    // end if ($nonisam == false)
    return $html;
}
 /**
  * Verifies what to do with non-printable contents (binary or BLOB)
  * in Browse mode.
  *
  * @param string $category              BLOB|BINARY|GEOMETRY
  * @param string $content               the binary content
  * @param string $transformation_plugin transformation plugin.
  *                                      Can also be the default function:
  *                                      PMA_mimeDefaultFunction
  * @param string $transform_options     transformation parameters
  * @param string $default_function      default transformation function
  * @param object $meta                  the meta-information about the field
  * @param array  $url_params            parameters that should go to the
  *                                      download link
  *
  * @return mixed  string or float
  *
  * @access  private
  *
  * @see     _getDataCellForBlobColumns(),
  *          _getDataCellForGeometryColumns(),
  *          _getDataCellForNonNumericAndNonBlobColumns(),
  *          _getSortedColumnMessage()
  */
 private function _handleNonPrintableContents($category, $content, $transformation_plugin, $transform_options, $default_function, $meta, $url_params = array())
 {
     $result = '[' . $category;
     if (is_null($content)) {
         $result .= ' - NULL';
         $size = 0;
     } elseif (isset($content)) {
         $size = strlen($content);
         $display_size = PMA_Util::formatByteDown($size, 3, 1);
         $result .= ' - ' . $display_size[0] . ' ' . $display_size[1];
     }
     $result .= ']';
     if (gettype($transformation_plugin) == "object" && strpos($transformation_plugin::getMIMESubtype(), 'Octetstream')) {
         $result = $content;
     }
     if ($size > 0) {
         if ($default_function != $transformation_plugin) {
             $result = $transformation_plugin->applyTransformation($result, $transform_options, $meta);
         } else {
             $result = $this->{$default_function}($result, array(), $meta);
             if (stristr($meta->type, self::BLOB_FIELD) && $_SESSION['tmp_user_values']['display_blob']) {
                 // in this case, restart from the original $content
                 $result = htmlspecialchars(PMA_Util::replaceBinaryContents($content));
             }
             /* Create link to download */
             if (count($url_params) > 0) {
                 $result = '<a href="tbl_get_field.php' . PMA_generate_common_url($url_params) . '">' . $result . '</a>';
             }
         }
     }
     return $result;
 }