/** * 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 . '&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 . '&db=' . urlencode($current['SCHEMA_NAME']) . '&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); }
/** * 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); }
/** * 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\libraries\Util::formatByteDown($a, $b, $c); $result[0] = trim($result[0]); $this->assertEquals($e, $result); }
/** * 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\libraries\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 . '/> '; 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; }
/** * Test for PMA_getHtmlForColumnOrder * * @return void */ public function testPMAGetHtmlForColumnOrder() { //Mock DBI $dbi = $this->getMockBuilder('PMA\\libraries\\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\libraries\Util::formatByteDown($stat['footer'], 3, 1); $this->assertContains($value, $html); $this->assertContains($unit, $html); }
/** * Prints server state traffic information * * @param 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>'; $retval .= __('Traffic') . ' '; $retval .= PMA\libraries\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>#</th>'; $retval .= '<th>ø ' . __('per hour') . '</th>'; $retval .= '</tr>'; $retval .= '</thead>'; $retval .= '<tbody>'; $retval .= '<tr>'; $retval .= '<th class="name">' . __('Received') . '</th>'; $retval .= '<td class="value">'; $retval .= implode(' ', PMA\libraries\Util::formatByteDown($ServerStatusData->status['Bytes_received'], 3, 1)); $retval .= '</td>'; $retval .= '<td class="value">'; $retval .= implode(' ', PMA\libraries\Util::formatByteDown($ServerStatusData->status['Bytes_received'] * $hour_factor, 3, 1)); $retval .= '</td>'; $retval .= '</tr>'; $retval .= '<tr>'; $retval .= '<th class="name">' . __('Sent') . '</th>'; $retval .= '<td class="value">'; $retval .= implode(' ', PMA\libraries\Util::formatByteDown($ServerStatusData->status['Bytes_sent'], 3, 1)); $retval .= '</td>'; $retval .= '<td class="value">'; $retval .= implode(' ', PMA\libraries\Util::formatByteDown($ServerStatusData->status['Bytes_sent'] * $hour_factor, 3, 1)); $retval .= '</td>'; $retval .= '</tr>'; $retval .= '<tr>'; $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\libraries\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\libraries\Util::formatByteDown(($bytes_received + $bytes_sent) * $hour_factor, 3, 1)); $retval .= '</td>'; $retval .= '</tr>'; $retval .= '</tbody>'; $retval .= '</table>'; return $retval; }
/** * Wrapper around PMA\libraries\Util::formatByteDown * * This function is used when evaluating advisory_rules.txt * * @param double $value the value to format * @param int $limes the sensitiveness * @param int $comma the number of decimals to retain * * @return string the formatted value with unit */ function ADVISOR_formatByteDown($value, $limes = 6, $comma = 0) { return implode(' ', PMA\libraries\Util::formatByteDown($value, $limes, $comma)); }
/** * 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; }