' . "\n" . (($cfg['SQP']['fmtType'] == 'none' && $unparsed_sql != '') ? $unparsed_sql : $parsed_sql) . "\n" . ''; return $formatted_sql; } $formatted_sql = ''; switch ($cfg['SQP']['fmtType']) { case 'none': if ($unparsed_sql != '') { $formatted_sql = "
\n" . PMA_SQP_formatNone(array('raw' => $unparsed_sql)) . "\n"; } else { $formatted_sql = PMA_SQP_formatNone($parsed_sql); } break; case 'html': $formatted_sql = PMA_SQP_formatHtml($parsed_sql,'color'); break; case 'text': //$formatted_sql = PMA_SQP_formatText($parsed_sql); $formatted_sql = PMA_SQP_formatHtml($parsed_sql,'text'); break; default: break; } // end switch return $formatted_sql; } // end of the "PMA_formatSql()" function /** * Displays a link to the official MySQL documentation * * @param chapter of "HTML, one page per chapter" documentation * @param contains name of page/anchor that is being linked * * @return string the html link * * @access public */ // 2004-05-04: replaced with a modified function from Michael Keck (mkkeck) function PMA_showMySQLDocu($chapter, $link) { if (!empty($GLOBALS['cfg']['MySQLManualBase'])) { if (!empty($GLOBALS['cfg']['MySQLManualType'])) { switch ($GLOBALS['cfg']['MySQLManualType']) { case 'old': if ($GLOBALS['cfg']['ReplaceHelpImg']) { return '
' . $GLOBALS['strError'] . ' | ' . "\n"
. '
---|
';
// if the config password is wrong, or the MySQL server does not
// respond, do not show the query that would reveal the
// username/password
if (!empty($the_query) && !strstr($the_query, 'connect')) {
// --- Added to solve bug #641765
// Robbat2 - 12 January 2003, 9:46PM
// Revised, Robbat2 - 13 January 2003, 2:59PM
if (function_exists('PMA_SQP_isError') && PMA_SQP_isError()) {
echo PMA_SQP_getErrorString();
}
// ---
// modified to show me the help on sql errors (Michael Keck)
echo ' ' . "\n";
echo ' ' . $GLOBALS['strSQLQuery'] . ':' . "\n";
if (strstr(strtolower($formatted_sql),'select')) { // please show me help to the error on select
echo PMA_showMySQLDocu('Reference', 'SELECT');
}
if ($is_modify_link && isset($db)) {
if (isset($table)) {
$doedit_goto = '';
} else {
$doedit_goto = '';
}
if ($GLOBALS['cfg']['PropertiesIconic']) {
echo $doedit_goto
. ' ' . "\n" . ' ' . $formatted_sql . "\n" . ' ' . "\n" . ' ' . $GLOBALS['strMySQLSaid'] . '' . PMA_showMySQLDocu('Error-returns', 'Error-returns') . "\n" . ' ' . "\n"; // The error message will be displayed within a CODE segment. // To preserve original formatting, but allow wordwrapping, we do a couple of replacements // Replace all non-single blanks with their HTML-counterpart $error_message = str_replace(' ', ' ', $error_message); // Replace TAB-characters with their HTML-counterpart $error_message = str_replace("\t", ' ', $error_message); // Replace linebreaks $error_message = nl2br($error_message); echo '' . "\n"
. $error_message . "\n"
. ' ' . "\n"; // feature request #1036254: // Add a link by MySQL-Error #1062 - Duplicate entry // 2004-10-20 by mkkeck // 2005-01-17 modified by mkkeck bugfix if (substr($error_message, 1, 4) == '1062') { // get the duplicate entry $mysql_error_values = array(); $mysql_error_words = explode(' ',$tmp_mysql_error); foreach ($mysql_error_words as $mysql_error_word) { if (strstr($mysql_error_word, "'")) { $mysql_error_values = explode('-', preg_replace("/'/", "", $mysql_error_word)); break; // exit 'foreach' } } $duplicate_sql_query = ''; if (isset($mysql_error_values[0])) { $tmp_fields = PMA_DBI_get_fields($db, $table, NULL); if ($tmp_fields) { foreach ($tmp_fields as $tmp_field) { $duplicate_sql_query .= (($duplicate_sql_query!='') ? ' OR ' : '') . PMA_backquote($tmp_field['Field']) . " LIKE '" . $mysql_error_values[0] . "'"; } } } if ($duplicate_sql_query!='') { $duplicate_sql_query = "SELECT * FROM " . PMA_backquote($table) . " WHERE (" . $duplicate_sql_query . ")"; } else { $duplicate_sql_query = "SELECT * FROM " . PMA_backquote($table) . ""; } echo ' ' . "\n"; } // end of show duplicate entry echo ' | ' . "\n"
. '
'; echo '[' . $goto_back_url . $GLOBALS['strBack'] . ' ]'; } echo ' | ' . "\n" . '
> |
---|
" and not " ") // If we want to show some sql code it is easiest to create it here /* SQL-Parser-Analyzer */ if (!empty($GLOBALS['show_as_php'])) { $new_line = '\' ' . "\n" . ' . \' '; } if (isset($new_line)) { /* SQL-Parser-Analyzer */ $query_base = PMA_sqlAddslashes(htmlspecialchars($local_query), FALSE, FALSE, TRUE); /* SQL-Parser-Analyzer */ $query_base = preg_replace("@((\015\012)|(\015)|(\012))+@", $new_line, $query_base); } else { $query_base = $local_query; } // Here we append the LIMIT added for navigation, to // enable its display. Adding it higher in the code // to $local_query would create a problem when // using the Refresh or Edit links. // Only append it on SELECTs. // FIXME: what would be the best to do when someone // hits Refresh: use the current LIMITs ? // TODO: use the parser instead of preg_match() if (preg_match('@^SELECT[[:space:]]+@i', $query_base) && isset($GLOBALS['sql_limit_to_append'])) { $query_base .= $GLOBALS['sql_limit_to_append']; } if (!empty($GLOBALS['show_as_php'])) { $query_base = '$sql = \'' . $query_base; } else if (!empty($GLOBALS['validatequery'])) { $query_base = PMA_validateSQL($query_base); } else { // avoid reparsing query: if (isset($GLOBALS['parsed_sql']) && $query_base == $GLOBALS['parsed_sql']['raw']) { $parsed_sql = $GLOBALS['parsed_sql']; } else { $parsed_sql = PMA_SQP_parse($query_base); } $query_base = PMA_formatSql($parsed_sql, $query_base); } // Prepares links that may be displayed to edit/explain the query // (don't go to default pages, we must go to the page // where the query box is available) // (also, I don't see why we should check the goto variable) //if (!isset($GLOBALS['goto'])) { //$edit_target = (isset($GLOBALS['table'])) ? $cfg['DefaultTabTable'] : $cfg['DefaultTabDatabase']; $edit_target = isset($GLOBALS['db']) ? (isset($GLOBALS['table']) ? 'tbl_properties.php' : 'db_details.php') : ''; //} else if ($GLOBALS['goto'] != 'main.php') { // $edit_target = $GLOBALS['goto']; //} else { // $edit_target = ''; //} if (isset($cfg['SQLQuery']['Edit']) && ($cfg['SQLQuery']['Edit'] == TRUE ) && (!empty($edit_target))) { $onclick = ''; if ($cfg['QueryFrameJS'] && $cfg['QueryFrame']) { $onclick = 'focus_querywindow(\'' . urlencode($local_query) . '\'); return false;'; } $edit_link = $edit_target . $url_qpart . '&sql_query=' . urlencode($local_query) . '&show_query=1#querybox"'; $edit_link = ' [' . PMA_linkOrButton( $edit_link, $GLOBALS['strEdit'], array( 'onclick' => $onclick ) ) . ']'; } else { $edit_link = ''; } // Want to have the query explained (Mike Beck 2002-05-22) // but only explain a SELECT (that has not been explained) /* SQL-Parser-Analyzer */ if (isset($cfg['SQLQuery']['Explain']) && $cfg['SQLQuery']['Explain'] == TRUE) { // Detect if we are validating as well // To preserve the validate uRL data if (!empty($GLOBALS['validatequery'])) { $explain_link_validate = '&validatequery=1'; } else { $explain_link_validate = ''; } $explain_link = 'import.php' . $url_qpart . $explain_link_validate . '&sql_query='; if (preg_match('@^SELECT[[:space:]]+@i', $local_query)) { $explain_link .= urlencode('EXPLAIN ' . $local_query); $message = $GLOBALS['strExplain']; } else if (preg_match('@^EXPLAIN[[:space:]]+SELECT[[:space:]]+@i', $local_query)) { $explain_link .= urlencode(substr($local_query, 8)); $message = $GLOBALS['strNoExplain']; } else { $explain_link = ''; } if (!empty($explain_link)) { $explain_link = ' [' . PMA_linkOrButton( $explain_link, $message ) . ']'; } } else { $explain_link = ''; } //show explain // Also we would like to get the SQL formed in some nice // php-code (Mike Beck 2002-05-22) if (isset($cfg['SQLQuery']['ShowAsPHP']) && $cfg['SQLQuery']['ShowAsPHP'] == TRUE) { $php_link = 'import.php' . $url_qpart . '&show_query=1' . '&sql_query=' . urlencode($local_query) . '&show_as_php='; if (!empty($GLOBALS['show_as_php'])) { $php_link .= '0'; $message = $GLOBALS['strNoPhp']; } else { $php_link .= '1'; $message = $GLOBALS['strPhp']; } $php_link = ' [' . PMA_linkOrButton( $php_link, $message ) . ']'; if (isset($GLOBALS['show_as_php']) && $GLOBALS['show_as_php'] == '1') { $runquery_link = 'import.php' . $url_qpart . '&show_query=1' . '&sql_query=' . urlencode($local_query); $php_link .= ' [' . PMA_linkOrButton( $runquery_link, $GLOBALS['strRunQuery'] ) . ']'; } } else { $php_link = ''; } //show as php // Refresh query if (isset($cfg['SQLQuery']['Refresh']) && $cfg['SQLQuery']['Refresh'] && preg_match('@^(SELECT|SHOW)[[:space:]]+@i', $local_query)) { $refresh_link = 'import.php' . $url_qpart . '&show_query=1' . '&sql_query=' . urlencode($local_query); $refresh_link = ' [' . PMA_linkOrButton( $refresh_link, $GLOBALS['strRefresh'] ) . ']'; } else { $refresh_link = ''; } //show as php if (isset($cfg['SQLValidator']['use']) && $cfg['SQLValidator']['use'] == TRUE && isset($cfg['SQLQuery']['Validate']) && $cfg['SQLQuery']['Validate'] == TRUE) { $validate_link = 'import.php' . $url_qpart . '&show_query=1' . '&sql_query=' . urlencode($local_query) . '&validatequery='; if (!empty($GLOBALS['validatequery'])) { $validate_link .= '0'; $message = $GLOBALS['strNoValidateSQL'] ; } else { $validate_link .= '1'; $message = $GLOBALS['strValidateSQL'] ; } $validate_link = ' [' . PMA_linkOrButton( $validate_link, $GLOBALS['strRefresh'] ) . ']'; } else { $validate_link = ''; } //validator // Displays the message echo ' ' . $GLOBALS['strSQLQuery'] . ': '; echo ' ' . "\n"; echo ' ' . $query_base; unset($local_query); //Clean up the end of the PHP if (!empty($GLOBALS['show_as_php'])) { echo '\';'; } echo "\n"; ?> |
'; echo $edit_link . $explain_link . $php_link . $refresh_link . $validate_link; echo ' | ' . "\n"; } } echo "\n"; ?>
* echo PMA_formatNumber( 123456789, 6 ); // 123,457 k
* echo PMA_formatNumber( -123456789, 4, 2 ); // -123.46 M
* echo PMA_formatNumber( -0.003, 6 ); // -3 m
* echo PMA_formatNumber( 0.003, 3, 3 ); // 0.003
* echo PMA_formatNumber( 0.00003, 3, 2 ); // 0.03 m
* echo PMA_formatNumber( 0, 6 ); // 0
*
* @param double $value the value to format
* @param integer $length the max length
* @param integer $comma the number of decimals to retain
* @param boolean $only_down do not reformat numbers below 1
*
* @return string the formatted value and its unit
*
* @access public
*
* @author staybyte, sebastian mendel
* @version 1.0.3 - 2005-09-16
*/
function PMA_formatNumber( $value, $length = 3, $comma = 0, $only_down = false ) {
// this units needs no translation, ISO
$units = array(
-8 => 'y',
-7 => 'z',
-6 => 'a',
-5 => 'f',
-4 => 'p',
-3 => 'n',
-2 => 'µ',
-1 => 'm',
0 => ' ',
1 => 'k',
2 => 'M',
3 => 'G',
4 => 'T',
5 => 'P',
6 => 'E',
7 => 'Z',
8 => 'Y'
);
// we need at least 3 digits to be displayed
if ( 3 > $length + $comma ) {
$length = 3 - $comma;
}
// check for negativ value to retain sign
if ( $value < 0 ) {
$sign = '-';
$value = abs( $value );
} else {
$sign = '';
}
$dh = pow(10, $comma);
$li = pow(10, $length);
$unit = $units[0];
if ( $value >= 1 ) {
for ( $d = 8; $d >= 0; $d-- ) {
if (isset($units[$d]) && $value >= $li * pow(1000, $d-1)) {
$value = round($value / ( pow(1000, $d) / $dh) ) /$dh;
$unit = $units[$d];
break 1;
} // end if
} // end for
} elseif ( ! $only_down && (float) $value !== 0.0 ) {
for ( $d = -8; $d <= 8; $d++ ) {
if (isset($units[$d]) && $value <= $li * pow(1000, $d-1)) {
$value = round($value / ( pow(1000, $d) / $dh) ) /$dh;
$unit = $units[$d];
break 1;
} // end if
} // end for
} // end if ( $value >= 1 ) elseif ( ! $only_down && (float) $value !== 0.0 )
$value = number_format( $value,
$comma,
$GLOBALS['number_decimal_separator'],
$GLOBALS['number_thousands_separator'] );
return $sign . $value . ' ' . $unit;
} // end of the 'PMA_formatNumber' function
/**
* Extracts ENUM / SET options from a type definition string
*
* @param string The column type definition
*
* @return array The options or
* boolean FALSE in case of an error.
*
* @author rabus
*/
function PMA_getEnumSetOptions($type_def) {
$open = strpos($type_def, '(');
$close = strrpos($type_def, ')');
if (!$open || !$close) {
return FALSE;
}
$options = substr($type_def, $open + 2, $close - $open - 3);
$options = explode('\',\'', $options);
return $options;
} // end of the 'PMA_getEnumSetOptions' function
/**
* Writes localised date
*
* @param string the current timestamp
*
* @return string the formatted date
*
* @access public
*/
function PMA_localisedDate($timestamp = -1, $format = '')
{
global $datefmt, $month, $day_of_week;
if ($format == '') {
$format = $datefmt;
}
if ($timestamp == -1) {
$timestamp = time();
}
$date = preg_replace('@%[aA]@', $day_of_week[(int)strftime('%w', $timestamp)], $format);
$date = preg_replace('@%[bB]@', $month[(int)strftime('%m', $timestamp)-1], $date);
return strftime($date, $timestamp);
} // end of the 'PMA_localisedDate()' function
/**
* returns a tab for tabbed navigation.
* If the variables $link and $args ar left empty, an inactive tab is created
*
* @param array $tab array with all options
*
* @return string html code for one tab, a link if valid otherwise a span
*
* @access public
*/
function PMA_getTab( $tab )
{
// default values
$defaults = array(
'text' => '',
'class' => '',
'active' => false,
'link' => '',
'sep' => '?',
'attr' => '',
'args' => '',
);
$tab = array_merge( $defaults, $tab );
// determine aditional style-class
if ( empty( $tab['class'] ) ) {
if ($tab['text'] == $GLOBALS['strEmpty'] || $tab['text'] == $GLOBALS['strDrop']) {
$tab['class'] = 'caution';
}
elseif ( isset( $tab['active'] ) && $tab['active']
|| isset($GLOBALS['active_page']) && $GLOBALS['active_page'] == $tab['link']
|| basename($_SERVER['PHP_SELF']) == $tab['link'] )
{
$tab['class'] = 'active';
}
}
// build the link
if ( ! empty( $tab['link'] ) ) {
$tab['link'] = htmlentities( $tab['link'] );
$tab['link'] = $tab['link'] . $tab['sep'] . ( empty( $GLOBALS['url_query'] ) ? PMA_generate_common_url() : $GLOBALS['url_query'] );
if ( ! empty( $tab['args'] ) ) {
foreach( $tab['args'] as $param => $value ) {
$tab['link'] .= '&' . urlencode( $param ) . '=' . urlencode( $value );
}
}
}
// display icon, even if iconic is disabled but the link-text is missing
if ( ( $GLOBALS['cfg']['MainPageIconic'] || empty( $tab['text'] ) )
&& isset( $tab['icon'] ) ) {
$image = '' . $error_message . '