2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Misc functions used all over the scripts.
10 * Exponential expression / raise number into power
12 * @uses function_exists()
19 * @param string pow function use, or false for auto-detect
20 * @return mixed string or float
22 function PMA_pow($base, $exp, $use_function = false)
24 static $pow_function = null;
30 if (null == $pow_function) {
31 if (function_exists('bcpow')) {
32 // BCMath Arbitrary Precision Mathematics Function
33 $pow_function = 'bcpow';
34 } elseif (function_exists('gmp_pow')) {
36 $pow_function = 'gmp_pow';
39 $pow_function = 'pow';
43 if (! $use_function) {
44 $use_function = $pow_function;
47 switch ($use_function) {
50 $pow = bcpow($base, $exp);
53 $pow = gmp_strval(gmp_pow($base, $exp));
56 $base = (float) $base;
58 $pow = pow($base, $exp);
61 $pow = $use_function($base, $exp);
68 * string PMA_getIcon(string $icon)
70 * @uses $GLOBALS['pmaThemeImage']
71 * @uses $GLOBALS['cfg']['PropertiesIconic']
72 * @uses htmlspecialchars()
73 * @param string $icon name of icon file
74 * @param string $alternate alternate text
75 * @param boolean $container include in container
76 * @param boolean $$force_text whether to force alternate text to be displayed
77 * @return html img tag
79 function PMA_getIcon($icon, $alternate = '', $container = false, $force_text = false)
81 $include_icon = false;
82 $include_text = false;
84 $alternate = htmlspecialchars($alternate);
87 if ($GLOBALS['cfg']['PropertiesIconic']) {
92 ||
! (true === $GLOBALS['cfg']['PropertiesIconic'])
94 // $cfg['PropertiesIconic'] is false or both
95 // OR we have no $include_icon
99 if ($include_text && $include_icon && $container) {
100 // we have icon, text and request for container
105 $button .= '<div class="nowrap">';
109 $button .= '<img src="' . $GLOBALS['pmaThemeImage'] . $icon . '"'
110 . ' title="' . $alternate . '" alt="' . $alternate . '"'
111 . ' class="icon" width="16" height="16" />';
114 if ($include_icon && $include_text) {
119 $button .= $alternate;
130 * Displays the maximum size for an upload
132 * @uses $GLOBALS['strMaximumSize']
133 * @uses PMA_formatByteDown()
135 * @param integer the size
137 * @return string the message
141 function PMA_displayMaximumUploadSize($max_upload_size)
143 list($max_size, $max_unit) = PMA_formatByteDown($max_upload_size);
144 return '(' . sprintf($GLOBALS['strMaximumSize'], $max_size, $max_unit) . ')';
148 * Generates a hidden field which should indicate to the browser
149 * the maximum size for upload
151 * @param integer the size
153 * @return string the INPUT field
157 function PMA_generateHiddenMaxFileSize($max_size)
159 return '<input type="hidden" name="MAX_FILE_SIZE" value="' .$max_size . '" />';
163 * Add slashes before "'" and "\" characters so a value containing them can
164 * be used in a sql comparison.
166 * @uses str_replace()
167 * @param string the string to slash
168 * @param boolean whether the string will be used in a 'LIKE' clause
169 * (it then requires two more escaped sequences) or not
170 * @param boolean whether to treat cr/lfs as escape-worthy entities
171 * (converts \n to \\n, \r to \\r)
173 * @param boolean whether this function is used as part of the
174 * "Create PHP code" dialog
176 * @return string the slashed string
180 function PMA_sqlAddslashes($a_string = '', $is_like = false, $crlf = false, $php_code = false)
183 $a_string = str_replace('\\', '\\\\\\\\', $a_string);
185 $a_string = str_replace('\\', '\\\\', $a_string);
189 $a_string = str_replace("\n", '\n', $a_string);
190 $a_string = str_replace("\r", '\r', $a_string);
191 $a_string = str_replace("\t", '\t', $a_string);
195 $a_string = str_replace('\'', '\\\'', $a_string);
197 $a_string = str_replace('\'', '\'\'', $a_string);
201 } // end of the 'PMA_sqlAddslashes()' function
205 * Add slashes before "_" and "%" characters for using them in MySQL
206 * database, table and field names.
207 * Note: This function does not escape backslashes!
209 * @uses str_replace()
210 * @param string the string to escape
212 * @return string the escaped string
216 function PMA_escape_mysql_wildcards($name)
218 $name = str_replace('_', '\\_', $name);
219 $name = str_replace('%', '\\%', $name);
222 } // end of the 'PMA_escape_mysql_wildcards()' function
225 * removes slashes before "_" and "%" characters
226 * Note: This function does not unescape backslashes!
228 * @uses str_replace()
229 * @param string $name the string to escape
230 * @return string the escaped string
233 function PMA_unescape_mysql_wildcards($name)
235 $name = str_replace('\\_', '_', $name);
236 $name = str_replace('\\%', '%', $name);
239 } // end of the 'PMA_unescape_mysql_wildcards()' function
242 * removes quotes (',",`) from a quoted string
244 * checks if the sting is quoted and removes this quotes
246 * @uses str_replace()
248 * @param string $quoted_string string to remove quotes from
249 * @param string $quote type of quote to remove
250 * @return string unqoted string
252 function PMA_unQuote($quoted_string, $quote = null)
256 if (null === $quote) {
264 foreach ($quotes as $quote) {
265 if (substr($quoted_string, 0, 1) === $quote
266 && substr($quoted_string, -1, 1) === $quote) {
267 $unquoted_string = substr($quoted_string, 1, -1);
268 // replace escaped quotes
269 $unquoted_string = str_replace($quote . $quote, $quote, $unquoted_string);
270 return $unquoted_string;
274 return $quoted_string;
280 * @todo move into PMA_Sql
281 * @uses PMA_SQP_isError()
282 * @uses PMA_SQP_formatHtml()
283 * @uses PMA_SQP_formatNone()
285 * @param mixed pre-parsed SQL structure
287 * @return string the formatted sql
289 * @global array the configuration array
290 * @global boolean whether the current statement is a multiple one or not
294 * @author Robin Johnson <robbat2@users.sourceforge.net>
296 function PMA_formatSql($parsed_sql, $unparsed_sql = '')
300 // Check that we actually have a valid set of parsed data
302 // first check for the SQL parser having hit an error
303 if (PMA_SQP_isError()) {
306 // then check for an array
307 if (!is_array($parsed_sql)) {
308 // We don't so just return the input directly
309 // This is intended to be used for when the SQL Parser is turned off
310 $formatted_sql = '<pre>' . "\n"
311 . (($cfg['SQP']['fmtType'] == 'none' && $unparsed_sql != '') ?
$unparsed_sql : $parsed_sql) . "\n"
313 return $formatted_sql;
318 switch ($cfg['SQP']['fmtType']) {
320 if ($unparsed_sql != '') {
321 $formatted_sql = "<pre>\n" . PMA_SQP_formatNone(array('raw' => $unparsed_sql)) . "\n</pre>";
323 $formatted_sql = PMA_SQP_formatNone($parsed_sql);
327 $formatted_sql = PMA_SQP_formatHtml($parsed_sql, 'color');
330 //$formatted_sql = PMA_SQP_formatText($parsed_sql);
331 $formatted_sql = PMA_SQP_formatHtml($parsed_sql, 'text');
337 return $formatted_sql;
338 } // end of the "PMA_formatSql()" function
342 * Displays a link to the official MySQL documentation
344 * @uses $cfg['MySQLManualType']
345 * @uses $cfg['MySQLManualBase']
346 * @uses $cfg['ReplaceHelpImg']
347 * @uses $GLOBALS['mysql_4_1_doc_lang']
348 * @uses $GLOBALS['mysql_5_1_doc_lang']
349 * @uses $GLOBALS['mysql_5_0_doc_lang']
350 * @uses $GLOBALS['strDocu']
351 * @uses $GLOBALS['pmaThemeImage']
352 * @uses PMA_MYSQL_INT_VERSION
354 * @uses str_replace()
355 * @param string chapter of "HTML, one page per chapter" documentation
356 * @param string contains name of page/anchor that is being linked
357 * @param bool whether to use big icon (like in left frame)
359 * @return string the html link
363 function PMA_showMySQLDocu($chapter, $link, $big_icon = false)
367 if ($cfg['MySQLManualType'] == 'none' ||
empty($cfg['MySQLManualBase'])) {
371 // Fixup for newly used names:
372 $chapter = str_replace('_', '-', strtolower($chapter));
373 $link = str_replace('_', '-', strtolower($link));
375 switch ($cfg['MySQLManualType']) {
377 if (empty($chapter)) {
380 $url = $cfg['MySQLManualBase'] . '/' . $chapter . '.html#' . $link;
383 $url = $cfg['MySQLManualBase'] . '#' . $link;
389 $url = $cfg['MySQLManualBase'] . '/' . $link . '.html';
398 if (defined('PMA_MYSQL_INT_VERSION')) {
399 if (PMA_MYSQL_INT_VERSION
>= 50100) {
401 if (!empty($GLOBALS['mysql_5_1_doc_lang'])) {
402 $lang = $GLOBALS['mysql_5_1_doc_lang'];
404 } elseif (PMA_MYSQL_INT_VERSION
>= 50000) {
406 if (!empty($GLOBALS['mysql_5_0_doc_lang'])) {
407 $lang = $GLOBALS['mysql_5_0_doc_lang'];
411 $url = $cfg['MySQLManualBase'] . '/' . $mysql . '/' . $lang . '/' . $link . '.html';
416 return '<a href="' . $url . '" target="mysql_doc"><img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_sqlhelp.png" width="16" height="16" alt="' . $GLOBALS['strDocu'] . '" title="' . $GLOBALS['strDocu'] . '" /></a>';
417 } elseif ($GLOBALS['cfg']['ReplaceHelpImg']) {
418 return '<a href="' . $url . '" target="mysql_doc"><img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_help.png" width="11" height="11" alt="' . $GLOBALS['strDocu'] . '" title="' . $GLOBALS['strDocu'] . '" /></a>';
420 return '[<a href="' . $url . '" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]';
422 } // end of the 'PMA_showMySQLDocu()' function
425 * returns HTML for a footnote marker and add the messsage to the footnotes
427 * @uses $GLOBALS['footnotes']
428 * @param string the error message
429 * @return string html code for a footnote marker
432 function PMA_showHint($message, $bbcode = false, $type = 'notice')
434 if ($message instanceof PMA_Message
) {
435 $key = $message->getHash();
436 $type = $message->getLevel();
438 $key = md5($message);
441 if (! isset($GLOBALS['footnotes'][$key])) {
442 $nr = count($GLOBALS['footnotes']) +
1;
443 $GLOBALS['footnotes'][$key] = array(
449 $nr = $GLOBALS['footnotes'][$key]['nr'];
453 return '[sup]' . $nr . '[/sup]';
456 return '<sup class="footnotemarker" name="footnote_' . $nr . '">' . $nr . '</sup>';
460 * Displays a MySQL error message in the right frame.
462 * @uses footer.inc.php
463 * @uses header.inc.php
464 * @uses $GLOBALS['sql_query']
465 * @uses $GLOBALS['strError']
466 * @uses $GLOBALS['strSQLQuery']
467 * @uses $GLOBALS['pmaThemeImage']
468 * @uses $GLOBALS['strEdit']
469 * @uses $GLOBALS['strMySQLSaid']
470 * @uses $GLOBALS['cfg']['PropertiesIconic']
471 * @uses $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']
472 * @uses PMA_backquote()
473 * @uses PMA_DBI_getError()
474 * @uses PMA_formatSql()
475 * @uses PMA_generate_common_hidden_inputs()
476 * @uses PMA_generate_common_url()
477 * @uses PMA_showMySQLDocu()
478 * @uses PMA_sqlAddslashes()
479 * @uses PMA_SQP_isError()
480 * @uses PMA_SQP_parse()
481 * @uses PMA_SQP_getErrorString()
484 * @uses str_replace()
487 * @uses preg_replace()
492 * @uses function_exists()
493 * @uses htmlspecialchars()
496 * @param string the error message
497 * @param string the sql query that failed
498 * @param boolean whether to show a "modify" link or not
499 * @param string the "back" link url (full path is not required)
500 * @param boolean EXIT the page?
502 * @global string the curent table
503 * @global string the current db
507 function PMA_mysqlDie($error_message = '', $the_query = '',
508 $is_modify_link = true, $back_url = '', $exit = true)
513 * start http output, display html headers
515 require_once './libraries/header.inc.php';
517 if (!$error_message) {
518 $error_message = PMA_DBI_getError();
520 if (!$the_query && !empty($GLOBALS['sql_query'])) {
521 $the_query = $GLOBALS['sql_query'];
524 // --- Added to solve bug #641765
525 // Robbat2 - 12 January 2003, 9:46PM
526 // Revised, Robbat2 - 13 January 2003, 2:59PM
527 if (!function_exists('PMA_SQP_isError') ||
PMA_SQP_isError()) {
528 $formatted_sql = htmlspecialchars($the_query);
529 } elseif (empty($the_query) ||
trim($the_query) == '') {
532 if (strlen($the_query) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
533 $formatted_sql = substr($the_query, 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) . '[...]';
535 $formatted_sql = PMA_formatSql(PMA_SQP_parse($the_query), $the_query);
539 echo "\n" . '<!-- PMA-SQL-ERROR -->' . "\n";
540 echo ' <div class="error"><h1>' . $GLOBALS['strError'] . '</h1>' . "\n";
541 // if the config password is wrong, or the MySQL server does not
542 // respond, do not show the query that would reveal the
544 if (!empty($the_query) && !strstr($the_query, 'connect')) {
545 // --- Added to solve bug #641765
546 // Robbat2 - 12 January 2003, 9:46PM
547 // Revised, Robbat2 - 13 January 2003, 2:59PM
548 if (function_exists('PMA_SQP_isError') && PMA_SQP_isError()) {
549 echo PMA_SQP_getErrorString() . "\n";
550 echo '<br />' . "\n";
553 // modified to show me the help on sql errors (Michael Keck)
554 echo ' <p><strong>' . $GLOBALS['strSQLQuery'] . ':</strong>' . "\n";
555 if (strstr(strtolower($formatted_sql), 'select')) { // please show me help to the error on select
556 echo PMA_showMySQLDocu('SQL-Syntax', 'SELECT');
558 if ($is_modify_link) {
559 $_url_params = array(
560 'sql_query' => $the_query,
563 if (strlen($table)) {
564 $_url_params['db'] = $db;
565 $_url_params['table'] = $table;
566 $doedit_goto = '<a href="tbl_sql.php?' . PMA_generate_common_url($_url_params) . '">';
567 } elseif (strlen($db)) {
568 $_url_params['db'] = $db;
569 $doedit_goto = '<a href="db_sql.php?' . PMA_generate_common_url($_url_params) . '">';
571 $doedit_goto = '<a href="server_sql.php?' . PMA_generate_common_url($_url_params) . '">';
575 . PMA_getIcon('b_edit.png', $GLOBALS['strEdit'])
580 .' ' . $formatted_sql . "\n"
584 $tmp_mysql_error = ''; // for saving the original $error_message
585 if (!empty($error_message)) {
586 $tmp_mysql_error = strtolower($error_message); // save the original $error_message
587 $error_message = htmlspecialchars($error_message);
588 $error_message = preg_replace("@((\015\012)|(\015)|(\012)){3,}@", "\n\n", $error_message);
590 // modified to show me the help on error-returns (Michael Keck)
591 // (now error-messages-server)
593 . ' <strong>' . $GLOBALS['strMySQLSaid'] . '</strong>'
594 . PMA_showMySQLDocu('Error-messages-server', 'Error-messages-server')
598 // The error message will be displayed within a CODE segment.
599 // To preserve original formatting, but allow wordwrapping, we do a couple of replacements
601 // Replace all non-single blanks with their HTML-counterpart
602 $error_message = str_replace(' ', ' ', $error_message);
603 // Replace TAB-characters with their HTML-counterpart
604 $error_message = str_replace("\t", ' ', $error_message);
605 // Replace linebreaks
606 $error_message = nl2br($error_message);
609 . $error_message . "\n"
610 . '</code><br />' . "\n";
614 if (! empty($back_url)) {
615 if (strstr($back_url, '?')) {
616 $back_url .= '&no_history=true';
618 $back_url .= '?no_history=true';
620 echo '<fieldset class="tblFooters">';
621 echo '[ <a href="' . $back_url . '">' . $GLOBALS['strBack'] . '</a> ]';
622 echo '</fieldset>' . "\n\n";
625 * display footer and exit
627 require_once './libraries/footer.inc.php';
629 } // end of the 'PMA_mysqlDie()' function
632 * Send HTTP header, taking IIS limits into account (600 seems ok)
635 * @uses PMA_COMING_FROM_COOKIE_LOGIN
636 * @uses PMA_get_arg_separator()
641 * @uses session_write_close()
642 * @uses headers_sent()
643 * @uses function_exists()
644 * @uses debug_print_backtrace()
645 * @uses trigger_error()
647 * @param string $uri the header to send
648 * @return boolean always true
650 function PMA_sendHeaderLocation($uri)
652 if (PMA_IS_IIS
&& strlen($uri) > 600) {
654 echo '<html><head><title>- - -</title>' . "\n";
655 echo '<meta http-equiv="expires" content="0">' . "\n";
656 echo '<meta http-equiv="Pragma" content="no-cache">' . "\n";
657 echo '<meta http-equiv="Cache-Control" content="no-cache">' . "\n";
658 echo '<meta http-equiv="Refresh" content="0;url=' .$uri . '">' . "\n";
659 echo '<script type="text/javascript">' . "\n";
660 echo '//<![CDATA[' . "\n";
661 echo 'setTimeout("window.location = unescape(\'"' . $uri . '"\')", 2000);' . "\n";
663 echo '</script>' . "\n";
664 echo '</head>' . "\n";
665 echo '<body>' . "\n";
666 echo '<script type="text/javascript">' . "\n";
667 echo '//<![CDATA[' . "\n";
668 echo 'document.write(\'<p><a href="' . $uri . '">' . $GLOBALS['strGo'] . '</a></p>\');' . "\n";
670 echo '</script></body></html>' . "\n";
674 if (strpos($uri, '?') === false) {
675 header('Location: ' . $uri . '?' . SID
);
677 $separator = PMA_get_arg_separator();
678 header('Location: ' . $uri . $separator . SID
);
681 session_write_close();
682 if (headers_sent()) {
683 if (function_exists('debug_print_backtrace')) {
685 debug_print_backtrace();
688 trigger_error('PMA_sendHeaderLocation called when headers are already sent!', E_USER_ERROR
);
690 // bug #1523784: IE6 does not like 'Refresh: 0', it
691 // results in a blank page
692 // but we need it when coming from the cookie login panel)
693 if (PMA_IS_IIS
&& defined('PMA_COMING_FROM_COOKIE_LOGIN')) {
694 header('Refresh: 0; ' . $uri);
696 header('Location: ' . $uri);
703 * returns array with tables of given db with extended information and grouped
705 * @uses $cfg['LeftFrameTableSeparator']
706 * @uses $cfg['LeftFrameTableLevel']
707 * @uses $cfg['ShowTooltipAliasTB']
708 * @uses $cfg['NaturalOrder']
709 * @uses PMA_backquote()
715 * @param string $db name of db
716 * @param string $tables name of tables
717 * return array (recursive) grouped table list
719 function PMA_getTableList($db, $tables = null, $limit_offset = 0, $limit_count = false)
721 $sep = $GLOBALS['cfg']['LeftFrameTableSeparator'];
723 if (null === $tables) {
724 $tables = PMA_DBI_get_tables_full($db, false, false, null, $limit_offset, $limit_count);
725 if ($GLOBALS['cfg']['NaturalOrder']) {
726 uksort($tables, 'strnatcasecmp');
730 if (count($tables) < 1) {
741 $table_groups = array();
743 foreach ($tables as $table_name => $table) {
745 // check for correct row count
746 if (null === $table['Rows']) {
747 // Do not check exact row count here,
748 // if row count is invalid possibly the table is defect
749 // and this would break left frame;
750 // but we can check row count if this is a view,
751 // since PMA_Table::countRecords() returns a limited row count
754 // set this because PMA_Table::countRecords() can use it
755 $tbl_is_view = PMA_Table
::isView($db, $table['Name']);
758 $table['Rows'] = PMA_Table
::countRecords($db, $table['Name'],
763 // in $group we save the reference to the place in $table_groups
764 // where to store the table info
765 if ($GLOBALS['cfg']['LeftFrameDBTree']
766 && $sep && strstr($table_name, $sep))
768 $parts = explode($sep, $table_name);
770 $group =& $table_groups;
772 $group_name_full = '';
773 while ($i < count($parts) - 1
774 && $i < $GLOBALS['cfg']['LeftFrameTableLevel']) {
775 $group_name = $parts[$i] . $sep;
776 $group_name_full .= $group_name;
778 if (!isset($group[$group_name])) {
779 $group[$group_name] = array();
780 $group[$group_name]['is' . $sep . 'group'] = true;
781 $group[$group_name]['tab' . $sep . 'count'] = 1;
782 $group[$group_name]['tab' . $sep . 'group'] = $group_name_full;
783 } elseif (!isset($group[$group_name]['is' . $sep . 'group'])) {
784 $table = $group[$group_name];
785 $group[$group_name] = array();
786 $group[$group_name][$group_name] = $table;
788 $group[$group_name]['is' . $sep . 'group'] = true;
789 $group[$group_name]['tab' . $sep . 'count'] = 1;
790 $group[$group_name]['tab' . $sep . 'group'] = $group_name_full;
792 $group[$group_name]['tab' . $sep . 'count']++
;
794 $group =& $group[$group_name];
798 if (!isset($table_groups[$table_name])) {
799 $table_groups[$table_name] = array();
801 $group =& $table_groups;
805 if ($GLOBALS['cfg']['ShowTooltipAliasTB']
806 && $GLOBALS['cfg']['ShowTooltipAliasTB'] !== 'nested') {
807 // switch tooltip and name
808 $table['Comment'] = $table['Name'];
809 $table['disp_name'] = $table['Comment'];
811 $table['disp_name'] = $table['Name'];
814 $group[$table_name] = array_merge($default, $table);
817 return $table_groups;
820 /* ----------------------- Set of misc functions ----------------------- */
824 * Adds backquotes on both sides of a database, table or field name.
825 * and escapes backquotes inside the name with another backquote
829 * echo PMA_backquote('owner`s db'); // `owner``s db`
833 * @uses PMA_backquote()
836 * @uses str_replace()
837 * @param mixed $a_name the database, table or field name to "backquote"
839 * @param boolean $do_it a flag to bypass this function (used by dump
841 * @return mixed the "backquoted" database, table or field name if the
842 * current MySQL release is >= 3.23.6, the original one
846 function PMA_backquote($a_name, $do_it = true)
852 if (is_array($a_name)) {
854 foreach ($a_name as $key => $val) {
855 $result[$key] = PMA_backquote($val);
860 // '0' is also empty for php :-(
861 if (strlen($a_name) && $a_name !== '*') {
862 return '`' . str_replace('`', '``', $a_name) . '`';
866 } // end of the 'PMA_backquote()' function
870 * Defines the <CR><LF> value depending on the user OS.
873 * @return string the <CR><LF> value to use
877 function PMA_whichCrlf()
881 // The 'PMA_USR_OS' constant is defined in "./libraries/Config.class.php"
883 if (PMA_USR_OS
== 'Win') {
892 } // end of the 'PMA_whichCrlf()' function
895 * Reloads navigation if needed.
897 * @uses $GLOBALS['reload']
898 * @uses $GLOBALS['db']
899 * @uses PMA_generate_common_url()
900 * @global array configuration
904 function PMA_reloadNavigation()
908 // Reloads the navigation frame via JavaScript if required
909 if (isset($GLOBALS['reload']) && $GLOBALS['reload']) {
910 // one of the reasons for a reload is when a table is dropped
911 // in this case, get rid of the table limit offset, otherwise
912 // we have a problem when dropping a table on the last page
913 // and the offset becomes greater than the total number of tables
914 unset($_SESSION['userconf']['table_limit_offset']);
916 $reload_url = './navigation.php?' . PMA_generate_common_url($GLOBALS['db'], '', '&');
918 <script type
="text/javascript">
920 if (typeof(window
.parent
) != 'undefined'
921 && typeof(window
.parent
.frame_navigation
) != 'undefined') {
922 window
.parent
.goTo('<?php echo $reload_url; ?>');
927 unset($GLOBALS['reload']);
932 * displays the message and the query
933 * usually the message is the result of the query executed
935 * @param string $message the message to display
936 * @param string $sql_query the query to display
937 * @global array the configuration array
941 function PMA_showMessage($message, $sql_query = null, $type = 'notice')
945 if (null === $sql_query) {
946 if (! empty($GLOBALS['display_query'])) {
947 $sql_query = $GLOBALS['display_query'];
948 } elseif ($cfg['SQP']['fmtType'] == 'none' && ! empty($GLOBALS['unparsed_sql'])) {
949 $sql_query = $GLOBALS['unparsed_sql'];
950 } elseif (! empty($GLOBALS['sql_query'])) {
951 $sql_query = $GLOBALS['sql_query'];
957 // Corrects the tooltip text via JS if required
958 // @todo this is REALLY the wrong place to do this - very unexpected here
959 if (strlen($GLOBALS['table']) && $cfg['ShowTooltip']) {
960 $result = PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], true) . '\'');
962 $tbl_status = PMA_DBI_fetch_assoc($result);
963 $tooltip = (empty($tbl_status['Comment']))
965 : $tbl_status['Comment'] . ' ';
966 $tooltip .= '(' . PMA_formatNumber($tbl_status['Rows'], 0) . ' ' . $GLOBALS['strRows'] . ')';
967 PMA_DBI_free_result($result);
968 $uni_tbl = PMA_jsFormat($GLOBALS['db'] . '.' . $GLOBALS['table'], false);
970 echo '<script type="text/javascript">' . "\n";
971 echo '//<![CDATA[' . "\n";
972 echo "window.parent.updateTableTitle('" . $uni_tbl . "', '" . PMA_jsFormat($tooltip, false) . "');" . "\n";
974 echo '</script>' . "\n";
976 } // end if ... elseif
978 // Checks if the table needs to be repaired after a TRUNCATE query.
979 // @todo what about $GLOBALS['display_query']???
980 // @todo this is REALLY the wrong place to do this - very unexpected here
981 if (strlen($GLOBALS['table'])
982 && $GLOBALS['sql_query'] == 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table'])) {
983 if (!isset($tbl_status)) {
984 $result = @PMA_DBI_try_query
('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], true) . '\'');
986 $tbl_status = PMA_DBI_fetch_assoc($result);
987 PMA_DBI_free_result($result);
990 if (isset($tbl_status) && (int) $tbl_status['Index_length'] > 1024) {
991 PMA_DBI_try_query('REPAIR TABLE ' . PMA_backquote($GLOBALS['table']));
996 echo '<div align="' . $GLOBALS['cell_align_left'] . '">' . "\n";
998 if ($message instanceof PMA_Message
) {
1000 $type = $message->getLevel();
1002 echo '<div class="' . $type . '">';
1003 echo PMA_sanitize($message);
1004 if (isset($GLOBALS['special_message'])) {
1005 echo PMA_sanitize($GLOBALS['special_message']);
1006 unset($GLOBALS['special_message']);
1011 if ($cfg['ShowSQL'] == true && ! empty($sql_query)) {
1012 // Html format the query to be displayed
1013 // If we want to show some sql code it is easiest to create it here
1014 /* SQL-Parser-Analyzer */
1016 if (! empty($GLOBALS['show_as_php'])) {
1017 $new_line = '\\n"<br />' . "\n"
1018 . ' . "';
1019 $query_base = htmlspecialchars(addslashes($sql_query));
1020 $query_base = preg_replace('/((\015\012)|(\015)|(\012))/', $new_line, $query_base);
1022 $query_base = $sql_query;
1025 $query_too_big = false;
1027 if (strlen($query_base) > $cfg['MaxCharactersInDisplayedSQL']) {
1028 // when the query is large (for example an INSERT of binary
1029 // data), the parser chokes; so avoid parsing the query
1030 $query_too_big = true;
1031 $query_base = nl2br(htmlspecialchars($sql_query));
1032 } elseif (! empty($GLOBALS['parsed_sql'])
1033 && $query_base == $GLOBALS['parsed_sql']['raw']) {
1034 // (here, use "! empty" because when deleting a bookmark,
1035 // $GLOBALS['parsed_sql'] is set but empty
1036 $parsed_sql = $GLOBALS['parsed_sql'];
1038 // Parse SQL if needed
1039 $parsed_sql = PMA_SQP_parse($query_base);
1043 if (isset($parsed_sql)) {
1044 $analyzed_display_query = PMA_SQP_analyze($parsed_sql);
1045 // Here we append the LIMIT added for navigation, to
1046 // enable its display. Adding it higher in the code
1047 // to $sql_query would create a problem when
1048 // using the Refresh or Edit links.
1050 // Only append it on SELECTs.
1053 * @todo what would be the best to do when someone hits Refresh:
1054 * use the current LIMITs ?
1057 if (isset($analyzed_display_query[0]['queryflags']['select_from'])
1058 && isset($GLOBALS['sql_limit_to_append'])) {
1059 $query_base = $analyzed_display_query[0]['section_before_limit']
1060 . "\n" . $GLOBALS['sql_limit_to_append']
1061 . $analyzed_display_query[0]['section_after_limit'];
1062 // Need to reparse query
1063 $parsed_sql = PMA_SQP_parse($query_base);
1067 if (! empty($GLOBALS['show_as_php'])) {
1068 $query_base = '$sql = "' . $query_base;
1069 } elseif (! empty($GLOBALS['validatequery'])) {
1070 $query_base = PMA_validateSQL($query_base);
1071 } elseif (isset($parsed_sql)) {
1072 $query_base = PMA_formatSql($parsed_sql, $query_base);
1075 // Prepares links that may be displayed to edit/explain the query
1076 // (don't go to default pages, we must go to the page
1077 // where the query box is available)
1079 // Basic url query part
1080 $url_params = array();
1081 if (strlen($GLOBALS['db'])) {
1082 $url_params['db'] = $GLOBALS['db'];
1083 if (strlen($GLOBALS['table'])) {
1084 $url_params['table'] = $GLOBALS['table'];
1085 $edit_link = 'tbl_sql.php';
1087 $edit_link = 'db_sql.php';
1090 $edit_link = 'server_sql.php';
1093 // Want to have the query explained (Mike Beck 2002-05-22)
1094 // but only explain a SELECT (that has not been explained)
1095 /* SQL-Parser-Analyzer */
1097 if (! empty($cfg['SQLQuery']['Explain']) && ! $query_too_big) {
1098 $explain_params = $url_params;
1099 // Detect if we are validating as well
1100 // To preserve the validate uRL data
1101 if (! empty($GLOBALS['validatequery'])) {
1102 $explain_params['validatequery'] = 1;
1105 if (preg_match('@^SELECT[[:space:]]+@i', $sql_query)) {
1106 $explain_params['sql_query'] = 'EXPLAIN ' . $sql_query;
1107 $_message = $GLOBALS['strExplain'];
1108 } elseif (preg_match('@^EXPLAIN[[:space:]]+SELECT[[:space:]]+@i', $sql_query)) {
1109 $explain_params['sql_query'] = substr($sql_query, 8);
1110 $_message = $GLOBALS['strNoExplain'];
1112 if (isset($explain_params['sql_query'])) {
1113 $explain_link = 'import.php' . PMA_generate_common_url($explain_params);
1114 $explain_link = ' [' . PMA_linkOrButton($explain_link, $_message) . ']';
1118 $url_params['sql_query'] = $sql_query;
1119 $url_params['show_query'] = 1;
1121 if (! empty($cfg['SQLQuery']['Edit']) && ! $query_too_big) {
1122 if ($cfg['EditInWindow'] == true) {
1123 $onclick = 'window.parent.focus_querywindow(\'' . PMA_jsFormat($sql_query, false) . '\'); return false;';
1128 $edit_link .= PMA_generate_common_url($url_params) . '#querybox';
1129 $edit_link = ' [' . PMA_linkOrButton($edit_link, $GLOBALS['strEdit'], array('onclick' => $onclick)) . ']';
1134 $url_qpart = PMA_generate_common_url($url_params);
1136 // Also we would like to get the SQL formed in some nice
1137 // php-code (Mike Beck 2002-05-22)
1138 if (! empty($cfg['SQLQuery']['ShowAsPHP']) && ! $query_too_big) {
1139 $php_params = $url_params;
1141 if (! empty($GLOBALS['show_as_php'])) {
1142 $_message = $GLOBALS['strNoPhp'];
1144 $php_params['show_as_php'] = 1;
1145 $_message = $GLOBALS['strPhp'];
1148 $php_link = 'import.php' . PMA_generate_common_url($php_params);
1149 $php_link = ' [' . PMA_linkOrButton($php_link, $_message) . ']';
1151 if (isset($GLOBALS['show_as_php'])) {
1152 $runquery_link = 'import.php' . PMA_generate_common_url($url_params);
1153 $php_link .= ' [' . PMA_linkOrButton($runquery_link, $GLOBALS['strRunQuery']) . ']';
1160 if (! empty($cfg['SQLQuery']['Refresh'])
1161 && preg_match('@^(SELECT|SHOW)[[:space:]]+@i', $sql_query)) {
1162 $refresh_link = 'import.php' . PMA_generate_common_url($url_params);
1163 $refresh_link = ' [' . PMA_linkOrButton($refresh_link, $GLOBALS['strRefresh']) . ']';
1168 if (! empty($cfg['SQLValidator']['use'])
1169 && ! empty($cfg['SQLQuery']['Validate'])) {
1170 $validate_params = $url_params;
1171 if (!empty($GLOBALS['validatequery'])) {
1172 $validate_message = $GLOBALS['strNoValidateSQL'] ;
1174 $validate_params['validatequery'] = 1;
1175 $validate_message = $GLOBALS['strValidateSQL'] ;
1178 $validate_link = 'import.php' . PMA_generate_common_url($validate_params);
1179 $validate_link = ' [' . PMA_linkOrButton($validate_link, $validate_message) . ']';
1181 $validate_link = '';
1184 echo '<code class="sql">';
1185 if ($query_too_big) {
1186 echo substr($query_base, 0, $cfg['MaxCharactersInDisplayedSQL']) . '[...]';
1191 //Clean up the end of the PHP
1192 if (! empty($GLOBALS['show_as_php'])) {
1197 echo '<div class="tools">';
1198 PMA_profilingCheckbox($sql_query);
1199 echo $edit_link . $explain_link . $php_link . $refresh_link . $validate_link;
1202 echo '</div><br />' . "\n";
1203 } // end of the 'PMA_showMessage()' function
1206 * Verifies if current MySQL server supports profiling
1208 * @uses $_SESSION['profiling_supported'] for caching
1209 * @uses $GLOBALS['server']
1210 * @uses PMA_DBI_fetch_value()
1211 * @uses PMA_MYSQL_INT_VERSION
1214 * @return boolean whether profiling is supported
1216 * @author Marc Delisle
1218 function PMA_profilingSupported()
1220 if (! PMA_cacheExists('profiling_supported', true)) {
1221 // 5.0.37 has profiling but for example, 5.1.20 does not
1222 // (avoid a trip to the server for MySQL before 5.0.37)
1223 // and do not set a constant as we might be switching servers
1224 if (defined('PMA_MYSQL_INT_VERSION')
1225 && PMA_MYSQL_INT_VERSION
>= 50037
1226 && PMA_DBI_fetch_value("SHOW VARIABLES LIKE 'profiling'")) {
1227 PMA_cacheSet('profiling_supported', true, true);
1229 PMA_cacheSet('profiling_supported', false, true);
1233 return PMA_cacheGet('profiling_supported', true);
1237 * Displays a form with the Profiling checkbox
1239 * @param string $sql_query
1242 * @author Marc Delisle
1244 function PMA_profilingCheckbox($sql_query)
1246 if (PMA_profilingSupported()) {
1247 echo '<form action="sql.php" method="post">' . "\n";
1248 echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']);
1249 echo '<input type="hidden" name="sql_query" value="' . htmlspecialchars($sql_query) . '" />' . "\n";
1250 echo '<input type="hidden" name="profiling_form" value="1" />' . "\n";
1251 echo '<input type="checkbox" name="profiling" id="profiling"' . (isset($_SESSION['profiling']) ?
' checked="checked"' : '') . ' onclick="this.form.submit();" /><label for="profiling">' . $GLOBALS['strProfiling'] . '</label>' . "\n";
1252 echo '<noscript><input type="submit" value="' . $GLOBALS['strGo'] . '" /></noscript>' . "\n";
1253 echo '</form>' . "\n";
1258 * Displays the results of SHOW PROFILE
1260 * @param array the results
1263 * @author Marc Delisle
1265 function PMA_profilingResults($profiling_results)
1267 echo '<fieldset><legend>' . $GLOBALS['strProfiling'] . '</legend>' . "\n";
1268 echo '<table>' . "\n";
1269 echo ' <tr>' . "\n";
1270 echo ' <th>' . $GLOBALS['strStatus'] . '</th>' . "\n";
1271 echo ' <th>' . $GLOBALS['strTime'] . '</th>' . "\n";
1272 echo ' </tr>' . "\n";
1274 foreach($profiling_results as $one_result) {
1275 echo ' <tr>' . "\n";
1276 echo '<td>' . $one_result['Status'] . '</td>' . "\n";
1277 echo '<td>' . $one_result['Duration'] . '</td>' . "\n";
1279 echo '</table>' . "\n";
1280 echo '</fieldset>' . "\n";
1284 * Formats $value to byte view
1286 * @param double the value to format
1287 * @param integer the sensitiveness
1288 * @param integer the number of decimals to retain
1290 * @return array the formatted value and its unit
1295 * @version 1.2 - 18 July 2002
1297 function PMA_formatByteDown($value, $limes = 6, $comma = 0)
1299 $dh = PMA_pow(10, $comma);
1300 $li = PMA_pow(10, $limes);
1301 $return_value = $value;
1302 $unit = $GLOBALS['byteUnits'][0];
1304 for ($d = 6, $ex = 15; $d >= 1; $d--, $ex-=3) {
1305 if (isset($GLOBALS['byteUnits'][$d]) && $value >= $li * PMA_pow(10, $ex)) {
1306 // use 1024.0 to avoid integer overflow on 64-bit machines
1307 $value = round($value / (PMA_pow(1024, $d) / $dh)) /$dh;
1308 $unit = $GLOBALS['byteUnits'][$d];
1313 if ($unit != $GLOBALS['byteUnits'][0]) {
1314 // if the unit is not bytes (as represented in current language)
1315 // reformat with max length of 5
1316 // 4th parameter=true means do not reformat if value < 1
1317 $return_value = PMA_formatNumber($value, 5, $comma, true);
1319 // do not reformat, just handle the locale
1320 $return_value = PMA_formatNumber($value, 0);
1323 return array($return_value, $unit);
1324 } // end of the 'PMA_formatByteDown' function
1327 * Formats $value to the given length and appends SI prefixes
1328 * $comma is not substracted from the length
1329 * with a $length of 0 no truncation occurs, number is only formated
1330 * to the current locale
1334 * echo PMA_formatNumber(123456789, 6); // 123,457 k
1335 * echo PMA_formatNumber(-123456789, 4, 2); // -123.46 M
1336 * echo PMA_formatNumber(-0.003, 6); // -3 m
1337 * echo PMA_formatNumber(0.003, 3, 3); // 0.003
1338 * echo PMA_formatNumber(0.00003, 3, 2); // 0.03 m
1339 * echo PMA_formatNumber(0, 6); // 0
1342 * @param double $value the value to format
1343 * @param integer $length the max length
1344 * @param integer $comma the number of decimals to retain
1345 * @param boolean $only_down do not reformat numbers below 1
1347 * @return string the formatted value and its unit
1351 * @author staybyte, sebastian mendel
1352 * @version 1.1.0 - 2005-10-27
1354 function PMA_formatNumber($value, $length = 3, $comma = 0, $only_down = false)
1356 //number_format is not multibyte safe, str_replace is safe
1357 if ($length === 0) {
1358 return str_replace(array(',', '.'),
1359 array($GLOBALS['number_thousands_separator'], $GLOBALS['number_decimal_separator']),
1360 number_format($value, $comma));
1363 // this units needs no translation, ISO
1384 // we need at least 3 digits to be displayed
1385 if (3 > $length +
$comma) {
1386 $length = 3 - $comma;
1389 // check for negative value to retain sign
1392 $value = abs($value);
1397 $dh = PMA_pow(10, $comma);
1398 $li = PMA_pow(10, $length);
1402 for ($d = 8; $d >= 0; $d--) {
1403 if (isset($units[$d]) && $value >= $li * PMA_pow(1000, $d-1)) {
1404 $value = round($value / (PMA_pow(1000, $d) / $dh)) /$dh;
1409 } elseif (!$only_down && (float) $value !== 0.0) {
1410 for ($d = -8; $d <= 8; $d++
) {
1411 if (isset($units[$d]) && $value <= $li * PMA_pow(1000, $d-1)) {
1412 $value = round($value / (PMA_pow(1000, $d) / $dh)) /$dh;
1417 } // end if ($value >= 1) elseif (!$only_down && (float) $value !== 0.0)
1419 //number_format is not multibyte safe, str_replace is safe
1420 $value = str_replace(array(',', '.'),
1421 array($GLOBALS['number_thousands_separator'], $GLOBALS['number_decimal_separator']),
1422 number_format($value, $comma));
1424 return $sign . $value . ' ' . $unit;
1425 } // end of the 'PMA_formatNumber' function
1428 * Extracts ENUM / SET options from a type definition string
1430 * @param string The column type definition
1432 * @return array The options or
1433 * boolean false in case of an error.
1437 function PMA_getEnumSetOptions($type_def)
1439 $open = strpos($type_def, '(');
1440 $close = strrpos($type_def, ')');
1441 if (!$open ||
!$close) {
1444 $options = substr($type_def, $open +
2, $close - $open - 3);
1445 $options = explode('\',\'', $options);
1447 } // end of the 'PMA_getEnumSetOptions' function
1450 * Writes localised date
1452 * @param string the current timestamp
1454 * @return string the formatted date
1458 function PMA_localisedDate($timestamp = -1, $format = '')
1460 global $datefmt, $month, $day_of_week;
1462 if ($format == '') {
1466 if ($timestamp == -1) {
1467 $timestamp = time();
1470 $date = preg_replace('@%[aA]@', $day_of_week[(int)strftime('%w', $timestamp)], $format);
1471 $date = preg_replace('@%[bB]@', $month[(int)strftime('%m', $timestamp)-1], $date);
1473 return strftime($date, $timestamp);
1474 } // end of the 'PMA_localisedDate()' function
1478 * returns a tab for tabbed navigation.
1479 * If the variables $link and $args ar left empty, an inactive tab is created
1481 * @uses $GLOBALS['PMA_PHP_SELF']
1482 * @uses $GLOBALS['strEmpty']
1483 * @uses $GLOBALS['strDrop']
1484 * @uses $GLOBALS['active_page']
1485 * @uses $GLOBALS['url_query']
1486 * @uses $cfg['MainPageIconic']
1487 * @uses $GLOBALS['pmaThemeImage']
1488 * @uses PMA_generate_common_url()
1489 * @uses E_USER_NOTICE
1490 * @uses htmlentities()
1493 * @uses trigger_error()
1494 * @uses array_merge()
1496 * @param array $tab array with all options
1497 * @return string html code for one tab, a link if valid otherwise a span
1500 function PMA_getTab($tab)
1515 $tab = array_merge($defaults, $tab);
1517 // determine additionnal style-class
1518 if (empty($tab['class'])) {
1519 if ($tab['text'] == $GLOBALS['strEmpty']
1520 ||
$tab['text'] == $GLOBALS['strDrop']) {
1521 $tab['class'] = 'caution';
1522 } elseif (! empty($tab['active'])
1523 ||
PMA_isValid($GLOBALS['active_page'], 'identical', $tab['link'])) {
1524 $tab['class'] = 'active';
1525 } elseif (empty($GLOBALS['active_page'])
1526 && basename($GLOBALS['PMA_PHP_SELF']) == $tab['link']
1527 && empty($tab['warning'])) {
1528 $tab['class'] = 'active';
1532 if (!empty($tab['warning'])) {
1533 $tab['class'] .= ' warning';
1534 $tab['attr'] .= ' title="' . htmlspecialchars($tab['warning']) . '"';
1538 if (!empty($tab['link'])) {
1539 $tab['link'] = htmlentities($tab['link']);
1540 $tab['link'] = $tab['link'] . $tab['sep']
1541 .(empty($GLOBALS['url_query']) ?
1542 PMA_generate_common_url() : $GLOBALS['url_query']);
1543 if (! empty($tab['args'])) {
1544 foreach ($tab['args'] as $param => $value) {
1545 $tab['link'] .= PMA_get_arg_separator('html') . urlencode($param) . '='
1546 . urlencode($value);
1551 if (! empty($tab['fragment'])) {
1552 $tab['link'] .= $tab['fragment'];
1555 // display icon, even if iconic is disabled but the link-text is missing
1556 if (($GLOBALS['cfg']['MainPageIconic'] ||
empty($tab['text']))
1557 && isset($tab['icon'])) {
1558 $image = '<img class="icon" src="' . htmlentities($GLOBALS['pmaThemeImage'])
1559 .'%1$s" width="16" height="16" alt="%2$s" />%2$s';
1560 $tab['text'] = sprintf($image, htmlentities($tab['icon']), $tab['text']);
1562 // check to not display an empty link-text
1563 elseif (empty($tab['text'])) {
1565 trigger_error('empty linktext in function ' . __FUNCTION__
. '()',
1569 $out = '<li' . ($tab['class'] == 'active' ?
' class="active"' : '') . '>';
1571 if (!empty($tab['link'])) {
1572 $out .= '<a class="tab' . htmlentities($tab['class']) . '"'
1573 .' href="' . $tab['link'] . '" ' . $tab['attr'] . '>'
1574 . $tab['text'] . '</a>';
1576 $out .= '<span class="tab' . htmlentities($tab['class']) . '">'
1577 . $tab['text'] . '</span>';
1582 } // end of the 'PMA_getTab()' function
1585 * returns html-code for a tab navigation
1587 * @uses PMA_getTab()
1588 * @uses htmlentities()
1589 * @param array $tabs one element per tab
1590 * @param string $tag_id id used for the html-tag
1591 * @return string html-code for tab-navigation
1593 function PMA_getTabs($tabs, $tag_id = 'topmenu')
1596 '<div id="' . htmlentities($tag_id) . 'container">' . "\n"
1597 .'<ul id="' . htmlentities($tag_id) . '">' . "\n";
1599 foreach ($tabs as $tab) {
1600 $tab_navigation .= PMA_getTab($tab) . "\n";
1605 .'<div class="clearfloat"></div>'
1608 return $tab_navigation;
1613 * Displays a link, or a button if the link's URL is too large, to
1614 * accommodate some browsers' limitations
1616 * @param string the URL
1617 * @param string the link message
1618 * @param mixed $tag_params string: js confirmation
1619 * array: additional tag params (f.e. style="")
1620 * @param boolean $new_form we set this to false when we are already in
1621 * a form, to avoid generating nested forms
1623 * @return string the results to be echoed or saved in an array
1625 function PMA_linkOrButton($url, $message, $tag_params = array(),
1626 $new_form = true, $strip_img = false, $target = '')
1628 if (! is_array($tag_params)) {
1630 $tag_params = array();
1632 $tag_params['onclick'] = 'return confirmLink(this, \'' . $tmp . '\')';
1636 if (! empty($target)) {
1637 $tag_params['target'] = htmlentities($target);
1640 $tag_params_strings = array();
1641 foreach ($tag_params as $par_name => $par_value) {
1642 // htmlspecialchars() only on non javascript
1643 $par_value = substr($par_name, 0, 2) == 'on'
1645 : htmlspecialchars($par_value);
1646 $tag_params_strings[] = $par_name . '="' . $par_value . '"';
1649 // previously the limit was set to 2047, it seems 1000 is better
1650 if (strlen($url) <= 1000) {
1651 // no whitespace within an <a> else Safari will make it part of the link
1652 $ret = "\n" . '<a href="' . $url . '" '
1653 . implode(' ', $tag_params_strings) . '>'
1654 . $message . '</a>' . "\n";
1656 // no spaces (linebreaks) at all
1657 // or after the hidden fields
1658 // IE will display them all
1660 // add class=link to submit button
1661 if (empty($tag_params['class'])) {
1662 $tag_params['class'] = 'link';
1665 // decode encoded url separators
1666 $separator = PMA_get_arg_separator();
1667 // on most places separator is still hard coded ...
1668 if ($separator !== '&') {
1669 // ... so always replace & with $separator
1670 $url = str_replace(htmlentities('&'), $separator, $url);
1671 $url = str_replace('&', $separator, $url);
1673 $url = str_replace(htmlentities($separator), $separator, $url);
1676 $url_parts = parse_url($url);
1677 $query_parts = explode($separator, $url_parts['query']);
1679 $ret = '<form action="' . $url_parts['path'] . '" class="link"'
1680 . ' method="post"' . $target . ' style="display: inline;">';
1682 $subname_close = '';
1685 $query_parts[] = 'redirect=' . $url_parts['path'];
1686 if (empty($GLOBALS['subform_counter'])) {
1687 $GLOBALS['subform_counter'] = 0;
1689 $GLOBALS['subform_counter']++
;
1691 $subname_open = 'subform[' . $GLOBALS['subform_counter'] . '][';
1692 $subname_close = ']';
1693 $submit_name = ' name="usesubform[' . $GLOBALS['subform_counter'] . ']"';
1695 foreach ($query_parts as $query_pair) {
1696 list($eachvar, $eachval) = explode('=', $query_pair);
1697 $ret .= '<input type="hidden" name="' . $subname_open . $eachvar
1698 . $subname_close . '" value="'
1699 . htmlspecialchars(urldecode($eachval)) . '" />';
1702 if (stristr($message, '<img')) {
1704 $message = trim(strip_tags($message));
1705 $ret .= '<input type="submit"' . $submit_name . ' '
1706 . implode(' ', $tag_params_strings)
1707 . ' value="' . htmlspecialchars($message) . '" />';
1709 $ret .= '<input type="image"' . $submit_name . ' '
1710 . implode(' ', $tag_params_strings)
1711 . ' src="' . preg_replace(
1712 '/^.*\ssrc="([^"]*)".*$/si', '\1', $message) . '"'
1713 . ' value="' . htmlspecialchars(
1714 preg_replace('/^.*\salt="([^"]*)".*$/si', '\1',
1719 $message = trim(strip_tags($message));
1720 $ret .= '<input type="submit"' . $submit_name . ' '
1721 . implode(' ', $tag_params_strings)
1722 . ' value="' . htmlspecialchars($message) . '" />';
1727 } // end if... else...
1730 } // end of the 'PMA_linkOrButton()' function
1734 * Returns a given timespan value in a readable format.
1736 * @uses $GLOBALS['timespanfmt']
1739 * @param int the timespan
1741 * @return string the formatted value
1743 function PMA_timespanFormat($seconds)
1745 $return_string = '';
1746 $days = floor($seconds / 86400);
1748 $seconds -= $days * 86400;
1750 $hours = floor($seconds / 3600);
1751 if ($days > 0 ||
$hours > 0) {
1752 $seconds -= $hours * 3600;
1754 $minutes = floor($seconds / 60);
1755 if ($days > 0 ||
$hours > 0 ||
$minutes > 0) {
1756 $seconds -= $minutes * 60;
1758 return sprintf($GLOBALS['timespanfmt'], (string)$days, (string)$hours, (string)$minutes, (string)$seconds);
1762 * Takes a string and outputs each character on a line for itself. Used
1763 * mainly for horizontalflipped display mode.
1764 * Takes care of special html-characters.
1765 * Fulfills todo-item
1766 * http://sf.net/tracker/?func=detail&aid=544361&group_id=23067&atid=377411
1768 * @todo add a multibyte safe function PMA_STR_split()
1770 * @param string The string
1771 * @param string The Separator (defaults to "<br />\n")
1774 * @author Garvin Hicking <me@supergarv.de>
1775 * @return string The flipped string
1777 function PMA_flipstring($string, $Separator = "<br />\n")
1779 $format_string = '';
1782 for ($i = 0; $i < strlen($string); $i++
) {
1783 $char = $string{$i};
1787 $format_string .= $charbuff;
1790 } elseif (!empty($charbuff)) {
1792 } elseif ($char == ';' && !empty($charbuff)) {
1793 $format_string .= $charbuff;
1797 $format_string .= $char;
1801 if ($append && ($i != strlen($string))) {
1802 $format_string .= $Separator;
1806 return $format_string;
1811 * Function added to avoid path disclosures.
1812 * Called by each script that needs parameters, it displays
1813 * an error message and, by default, stops the execution.
1815 * Not sure we could use a strMissingParameter message here,
1816 * would have to check if the error message file is always available
1818 * @todo localize error message
1819 * @todo use PMA_fatalError() if $die === true?
1820 * @uses PMA_getenv()
1821 * @uses header_meta_style.inc.php
1822 * @uses $GLOBALS['PMA_PHP_SELF']
1824 * @param array The names of the parameters needed by the calling
1826 * @param boolean Stop the execution?
1827 * (Set this manually to false in the calling script
1828 * until you know all needed parameters to check).
1829 * @param boolean Whether to include this list in checking for special params.
1830 * @global string path to current script
1831 * @global boolean flag whether any special variable was required
1834 * @author Marc Delisle (lem9@users.sourceforge.net)
1836 function PMA_checkParameters($params, $die = true, $request = true)
1838 global $checked_special;
1840 if (!isset($checked_special)) {
1841 $checked_special = false;
1844 $reported_script_name = basename($GLOBALS['PMA_PHP_SELF']);
1845 $found_error = false;
1846 $error_message = '';
1848 foreach ($params as $param) {
1849 if ($request && $param != 'db' && $param != 'table') {
1850 $checked_special = true;
1853 if (!isset($GLOBALS[$param])) {
1854 $error_message .= $reported_script_name
1855 . ': Missing parameter: ' . $param
1856 . ' <a href="./Documentation.html#faqmissingparameters"'
1857 . ' target="documentation"> (FAQ 2.8)</a><br />';
1858 $found_error = true;
1863 * display html meta tags
1865 require_once './libraries/header_meta_style.inc.php';
1866 echo '</head><body><p>' . $error_message . '</p></body></html>';
1874 * Function to generate unique condition for specified row.
1876 * @uses $GLOBALS['analyzed_sql'][0]
1877 * @uses PMA_DBI_field_flags()
1878 * @uses PMA_backquote()
1879 * @uses PMA_sqlAddslashes()
1882 * @uses preg_replace()
1883 * @param resource $handle current query result
1884 * @param integer $fields_cnt number of fields
1885 * @param array $fields_meta meta information about fields
1886 * @param array $row current row
1887 * @param boolean $force_unique generate condition only on pk or unique
1890 * @author Michal Cihar (michal@cihar.com) and others...
1891 * @return string calculated condition
1893 function PMA_getUniqueCondition($handle, $fields_cnt, $fields_meta, $row, $force_unique=false)
1897 $nonprimary_condition = '';
1898 $preferred_condition = '';
1900 for ($i = 0; $i < $fields_cnt; ++
$i) {
1902 $field_flags = PMA_DBI_field_flags($handle, $i);
1903 $meta = $fields_meta[$i];
1905 // do not use a column alias in a condition
1906 if (! isset($meta->orgname
) ||
! strlen($meta->orgname
)) {
1907 $meta->orgname
= $meta->name
;
1909 if (isset($GLOBALS['analyzed_sql'][0]['select_expr'])
1910 && is_array($GLOBALS['analyzed_sql'][0]['select_expr'])) {
1911 foreach ($GLOBALS['analyzed_sql'][0]['select_expr']
1913 // need (string) === (string)
1914 // '' !== 0 but '' == 0
1915 if ((string) $select_expr['alias'] === (string) $meta->name
) {
1916 $meta->orgname
= $select_expr['column'];
1923 // Do not use a table alias in a condition.
1925 // select * from galerie x WHERE
1926 //(select count(*) from galerie y where y.datum=x.datum)>1
1928 // But orgtable is present only with mysqli extension so the
1929 // fix is only for mysqli.
1930 if (isset($meta->orgtable
) && $meta->table
!= $meta->orgtable
) {
1931 $meta->table
= $meta->orgtable
;
1934 // to fix the bug where float fields (primary or not)
1935 // can't be matched because of the imprecision of
1936 // floating comparison, use CONCAT
1937 // (also, the syntax "CONCAT(field) IS NULL"
1938 // that we need on the next "if" will work)
1939 if ($meta->type
== 'real') {
1940 $condition = ' CONCAT(' . PMA_backquote($meta->table
) . '.'
1941 . PMA_backquote($meta->orgname
) . ') ';
1943 $condition = ' ' . PMA_backquote($meta->table
) . '.'
1944 . PMA_backquote($meta->orgname
) . ' ';
1945 } // end if... else...
1947 if (!isset($row[$i]) ||
is_null($row[$i])) {
1948 $condition .= 'IS NULL AND';
1950 // timestamp is numeric on some MySQL 4.1
1951 if ($meta->numeric && $meta->type
!= 'timestamp') {
1952 $condition .= '= ' . $row[$i] . ' AND';
1953 } elseif ($meta->type
== 'blob'
1954 // hexify only if this is a true not empty BLOB
1955 && stristr($field_flags, 'BINARY')
1956 && !empty($row[$i])) {
1957 // do not waste memory building a too big condition
1958 if (strlen($row[$i]) < 1000) {
1959 // use a CAST if possible, to avoid problems
1960 // if the field contains wildcard characters % or _
1961 $condition .= '= CAST(0x' . bin2hex($row[$i])
1962 . ' AS BINARY) AND';
1964 // this blob won't be part of the final condition
1968 $condition .= '= \''
1969 . PMA_sqlAddslashes($row[$i], false, true) . '\' AND';
1972 if ($meta->primary_key
> 0) {
1973 $primary_key .= $condition;
1974 } elseif ($meta->unique_key
> 0) {
1975 $unique_key .= $condition;
1977 $nonprimary_condition .= $condition;
1980 // Correction University of Virginia 19991216:
1981 // prefer primary or unique keys for condition,
1982 // but use conjunction of all values if no primary key
1984 $preferred_condition = $primary_key;
1985 } elseif ($unique_key) {
1986 $preferred_condition = $unique_key;
1987 } elseif (! $force_unique) {
1988 $preferred_condition = $nonprimary_condition;
1991 return preg_replace('|\s?AND$|', '', $preferred_condition);
1995 * Generate a button or image tag
1997 * @uses PMA_USR_BROWSER_AGENT
1998 * @uses $GLOBALS['pmaThemeImage']
1999 * @uses $GLOBALS['cfg']['PropertiesIconic']
2000 * @param string name of button element
2001 * @param string class of button element
2002 * @param string name of image element
2003 * @param string text to display
2004 * @param string image to display
2007 * @author Michal Cihar (michal@cihar.com)
2009 function PMA_buttonOrImage($button_name, $button_class, $image_name, $text,
2012 if (false === $GLOBALS['cfg']['PropertiesIconic']) {
2013 echo ' <input type="submit" name="' . $button_name . '"'
2014 .' value="' . htmlspecialchars($text) . '"'
2015 .' title="' . htmlspecialchars($text) . '" />' . "\n";
2019 /* Opera has trouble with <input type="image"> */
2020 /* IE has trouble with <button> */
2021 if (PMA_USR_BROWSER_AGENT
!= 'IE') {
2022 echo '<button class="' . $button_class . '" type="submit"'
2023 .' name="' . $button_name . '" value="' . htmlspecialchars($text) . '"'
2024 .' title="' . htmlspecialchars($text) . '">' . "\n"
2025 . PMA_getIcon($image, $text)
2026 .'</button>' . "\n";
2028 echo '<input type="image" name="' . $image_name . '" value="'
2029 . htmlspecialchars($text) . '" title="' . htmlspecialchars($text) . '" src="' . $GLOBALS['pmaThemeImage']
2031 . ($GLOBALS['cfg']['PropertiesIconic'] === 'both' ?
' ' . htmlspecialchars($text) : '') . "\n";
2036 * Generate a pagination selector for browsing resultsets
2038 * @todo $url is not javascript escaped!?
2039 * @uses $GLOBALS['strPageNumber']
2041 * @param string URL for the JavaScript
2042 * @param string Number of rows in the pagination set
2043 * @param string current page number
2044 * @param string number of total pages
2045 * @param string If the number of pages is lower than this
2046 * variable, no pages will be ommitted in
2048 * @param string How many rows at the beginning should always
2050 * @param string How many rows at the end should always
2052 * @param string Percentage of calculation page offsets to
2053 * hop to a next page
2054 * @param string Near the current page, how many pages should
2055 * be considered "nearby" and displayed as
2057 * @param string The prompt to display (sometimes empty)
2060 * @author Garvin Hicking (pma@supergarv.de)
2062 function PMA_pageselector($url, $rows, $pageNow = 1, $nbTotalPage = 1,
2063 $showAll = 200, $sliceStart = 5, $sliceEnd = 5, $percent = 20,
2064 $range = 10, $prompt = '')
2067 . ' <select name="pos" onchange="goToUrl(this, \''
2068 . $url . '\');">' . "\n";
2069 if ($nbTotalPage < $showAll) {
2070 $pages = range(1, $nbTotalPage);
2074 // Always show first X pages
2075 for ($i = 1; $i <= $sliceStart; $i++
) {
2079 // Always show last X pages
2080 for ($i = $nbTotalPage - $sliceEnd; $i <= $nbTotalPage; $i++
) {
2084 // garvin: Based on the number of results we add the specified
2085 // $percent percentate to each page number,
2086 // so that we have a representing page number every now and then to
2087 // immideately jump to specific pages.
2088 // As soon as we get near our currently chosen page ($pageNow -
2089 // $range), every page number will be
2092 $x = $nbTotalPage - $sliceEnd;
2093 $met_boundary = false;
2095 if ($i >= ($pageNow - $range) && $i <= ($pageNow +
$range)) {
2096 // If our pageselector comes near the current page, we use 1
2097 // counter increments
2099 $met_boundary = true;
2101 // We add the percentate increment to our current page to
2102 // hop to the next one in range
2103 $i = $i +
floor($nbTotalPage / $percent);
2105 // Make sure that we do not cross our boundaries.
2106 if ($i > ($pageNow - $range) && !$met_boundary) {
2107 $i = $pageNow - $range;
2111 if ($i > 0 && $i <= $x) {
2116 // Since because of ellipsing of the current page some numbers may be double,
2117 // we unify our array:
2119 $pages = array_unique($pages);
2122 foreach ($pages as $i) {
2123 if ($i == $pageNow) {
2124 $selected = 'selected="selected" style="font-weight: bold"';
2128 $gotopage .= ' <option ' . $selected . ' value="' . (($i - 1) * $rows) . '">' . $i . '</option>' . "\n";
2131 $gotopage .= ' </select><noscript><input type="submit" value="' . $GLOBALS['strGo'] . '" /></noscript>';
2138 * Generate navigation for a list
2140 * @todo use $pos from $_url_params
2141 * @uses $GLOBALS['strPageNumber']
2143 * @param integer number of elements in the list
2144 * @param integer current position in the list
2145 * @param array url parameters
2146 * @param string script name for form target
2147 * @param string target frame
2148 * @param integer maximum number of elements to display from the list
2152 function PMA_listNavigator($count, $pos, $_url_params, $script, $frame, $max_count) {
2154 if ($max_count < $count) {
2155 echo 'frame_navigation' == $frame ?
'<div id="navidbpageselector">' . "\n" : '';
2156 echo $GLOBALS['strPageNumber'];
2157 echo 'frame_navigation' == $frame ?
'<br />' : ' ';
2159 // Move to the beginning or to the previous page
2161 // loic1: patch #474210 from Gosha Sakovich - part 1
2162 if ($GLOBALS['cfg']['NavigationBarIconic']) {
2163 $caption1 = '<<';
2164 $caption2 = ' < ';
2165 $title1 = ' title="' . $GLOBALS['strPos1'] . '"';
2166 $title2 = ' title="' . $GLOBALS['strPrevious'] . '"';
2168 $caption1 = $GLOBALS['strPos1'] . ' <<';
2169 $caption2 = $GLOBALS['strPrevious'] . ' <';
2172 } // end if... else...
2173 $_url_params['pos'] = 0;
2174 echo '<a' . $title1 . ' href="' . $script
2175 . PMA_generate_common_url($_url_params) . '" target="' . $frame . '">'
2176 . $caption1 . '</a>';
2177 $_url_params['pos'] = $pos - $max_count;
2178 echo '<a' . $title2 . ' href="' . $script
2179 . PMA_generate_common_url($_url_params) . '" target="' . $frame . '">'
2180 . $caption2 . '</a>';
2183 echo "\n", '<form action="./', basename($script), '" method="post" target="', $frame, '">', "\n";
2184 echo PMA_generate_common_hidden_inputs($_url_params);
2185 echo PMA_pageselector(
2186 $script . PMA_generate_common_url($_url_params) . '&',
2188 floor(($pos +
1) / $max_count) +
1,
2189 ceil($count / $max_count));
2192 if ($pos +
$max_count < $count) {
2193 if ($GLOBALS['cfg']['NavigationBarIconic']) {
2194 $caption3 = ' > ';
2195 $caption4 = '>>';
2196 $title3 = ' title="' . $GLOBALS['strNext'] . '"';
2197 $title4 = ' title="' . $GLOBALS['strEnd'] . '"';
2199 $caption3 = '> ' . $GLOBALS['strNext'];
2200 $caption4 = '>> ' . $GLOBALS['strEnd'];
2203 } // end if... else...
2204 $_url_params['pos'] = $pos +
$max_count;
2205 echo '<a' . $title3 . ' href="' . $script
2206 . PMA_generate_common_url($_url_params) . '" target="' . $frame . '">'
2207 . $caption3 . '</a>';
2208 $_url_params['pos'] = floor($count / $max_count) * $max_count;
2209 if ($_url_params['pos'] == $count) {
2210 $_url_params['pos'] = $count - $max_count;
2212 echo '<a' . $title4 . ' href="' . $script
2213 . PMA_generate_common_url($_url_params) . '" target="' . $frame . '">'
2214 . $caption4 . '</a>';
2217 if ('frame_navigation' == $frame) {
2218 echo '</div>' . "\n";
2224 * replaces %u in given path with current user name
2228 * $user_dir = PMA_userDir('/var/pma_tmp/%u/'); // '/var/pma_tmp/root/'
2231 * @uses $cfg['Server']['user']
2233 * @uses str_replace()
2234 * @param string $dir with wildcard for user
2235 * @return string per user directory
2237 function PMA_userDir($dir)
2239 // add trailing slash
2240 if (substr($dir, -1) != '/') {
2244 return str_replace('%u', $GLOBALS['cfg']['Server']['user'], $dir);
2248 * returns html code for db link to default db page
2250 * @uses $cfg['DefaultTabDatabase']
2251 * @uses $GLOBALS['db']
2252 * @uses $GLOBALS['strJumpToDB']
2253 * @uses PMA_generate_common_url()
2254 * @uses PMA_unescape_mysql_wildcards()
2257 * @uses htmlspecialchars()
2258 * @param string $database
2259 * @return string html link to default db page
2261 function PMA_getDbLink($database = null)
2263 if (!strlen($database)) {
2264 if (!strlen($GLOBALS['db'])) {
2267 $database = $GLOBALS['db'];
2269 $database = PMA_unescape_mysql_wildcards($database);
2272 return '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . PMA_generate_common_url($database) . '"'
2273 .' title="' . sprintf($GLOBALS['strJumpToDB'], htmlspecialchars($database)) . '">'
2274 .htmlspecialchars($database) . '</a>';
2278 * Displays a lightbulb hint explaining a known external bug
2279 * that affects a functionality
2281 * @uses PMA_MYSQL_INT_VERSION
2282 * @uses $GLOBALS['strKnownExternalBug']
2283 * @uses PMA_showHint()
2285 * @param string $functionality localized message explaining the func.
2286 * @param string $component 'mysql' (eventually, 'php')
2287 * @param string $minimum_version of this component
2288 * @param string $bugref bug reference for this component
2290 function PMA_externalBug($functionality, $component, $minimum_version, $bugref)
2292 if ($component == 'mysql' && PMA_MYSQL_INT_VERSION
< $minimum_version) {
2293 echo PMA_showHint(sprintf($GLOBALS['strKnownExternalBug'], $functionality, 'http://bugs.mysql.com/' . $bugref));
2299 * Generates and echoes a set of radio HTML fields
2301 * @uses htmlspecialchars()
2302 * @param string $html_field_name the radio HTML field
2303 * @param array $choices the choices values and labels
2304 * @param string $checked_choice the choice to check by default
2305 * @param boolean $line_break whether to add an HTML line break after a choice
2306 * @param boolean $escape_label whether to use htmlspecialchars() on label
2307 * @param string $class enclose each choice with a div of this class
2309 function PMA_generate_html_radio($html_field_name, $choices, $checked_choice = '', $line_break = true, $escape_label = true, $class='') {
2310 foreach ($choices as $choice_value => $choice_label) {
2311 if (! empty($class)) {
2312 echo '<div class="' . $class . '">';
2314 $html_field_id = $html_field_name . '_' . $choice_value;
2315 echo '<input type="radio" name="' . $html_field_name . '" id="' . $html_field_id . '" value="' . htmlspecialchars($choice_value) . '"';
2316 if ($choice_value == $checked_choice) {
2317 echo ' checked="checked"';
2320 echo '<label for="' . $html_field_id . '">' . ($escape_label ?
htmlspecialchars($choice_label) : $choice_label) . '</label>';
2324 if (! empty($class)) {
2332 * Generates and echoes an HTML dropdown
2334 * @uses htmlspecialchars()
2335 * @param string $select_name
2336 * @param array $choices the choices values
2337 * @param string $active_choice the choice to select by default
2338 * @todo support titles
2340 function PMA_generate_html_dropdown($select_name, $choices, $active_choice)
2342 $result = '<select name="' . htmlspecialchars($select_name) . '" id="' . htmlspecialchars($select_name) . '">"' . "\n";
2343 foreach ($choices as $one_choice) {
2344 $result .= '<option value="' . htmlspecialchars($one_choice) . '"';
2345 if ($one_choice == $active_choice) {
2346 $result .= ' selected="selected"';
2348 $result .= '>' . htmlspecialchars($one_choice) . '</option>' . "\n";
2350 $result .= '</select>' . "\n";
2355 * Generates a slider effect (Mootools)
2357 * @uses $GLOBALS['cfg']['InitialSlidersState']
2358 * @param string $id the id of the <div> on which to apply the effect
2359 * @param string $message the message to show as a link
2361 function PMA_generate_slider_effect($id, $message)
2364 <script type
="text/javascript">
2366 window
.addEvent('domready', function(){
2367 var anchor
<?php
echo $id; ?
> = new Element('a', {
2368 'id': 'toggle_<?php echo $id; ?>',
2371 'click': function(){
2372 mySlide
<?php
echo $id; ?
>.toggle();
2376 anchor
<?php
echo $id; ?
>.appendText('<?php echo $message; ?>');
2377 anchor
<?php
echo $id; ?
>.injectBefore('<?php echo $id; ?>');
2379 var mySlide
<?php
echo $id; ?
> = new Fx
.Slide('<?php echo $id; ?>');
2381 if ($GLOBALS['cfg']['InitialSlidersState'] == 'closed') {
2383 mySlide
<?php
echo $id; ?
>.hide();
2394 * Cache information in the session
2396 * @param unknown_type $var
2397 * @param unknown_type $val
2398 * @param unknown_type $server
2401 function PMA_cacheExists($var, $server = 0)
2403 if (true === $server) {
2404 $server = $GLOBALS['server'];
2406 return isset($_SESSION['cache']['server_' . $server][$var]);
2410 * Cache information in the session
2412 * @param unknown_type $var
2413 * @param unknown_type $val
2414 * @param unknown_type $server
2417 function PMA_cacheGet($var, $server = 0)
2419 if (true === $server) {
2420 $server = $GLOBALS['server'];
2422 if (isset($_SESSION['cache']['server_' . $server][$var])) {
2423 return $_SESSION['cache']['server_' . $server][$var];
2430 * Cache information in the session
2432 * @param unknown_type $var
2433 * @param unknown_type $val
2434 * @param unknown_type $server
2437 function PMA_cacheSet($var, $val = null, $server = 0)
2439 if (true === $server) {
2440 $server = $GLOBALS['server'];
2442 $_SESSION['cache']['server_' . $server][$var] = $val;
2446 * Converts a bit value to printable format;
2447 * in MySQL a BIT field can be from 1 to 64 bits so we need this
2448 * function because in PHP, decbin() supports only 32 bits
2455 * @param numeric $value coming from a BIT field
2456 * @param integer $length
2457 * @return string the printable value
2459 function PMA_printable_bit_value($value, $length) {
2461 for ($i = 0; $i < ceil($length / 8); $i++
) {
2462 $printable .= sprintf('%08d', decbin(ord(substr($value, $i, 1))));
2464 $printable = substr($printable, -$length);
2469 * Extracts the true field type and length from a field type spec
2474 * @param string $fieldspec
2475 * @return array associative array containing the type and length
2477 function PMA_extract_type_length($fieldspec) {
2478 $first_bracket_pos = strpos($fieldspec, '(');
2479 if ($first_bracket_pos) {
2480 $length = chop(substr($fieldspec, $first_bracket_pos +
1, (strpos($fieldspec, ')') - $first_bracket_pos - 1)));
2481 $type = chop(substr($fieldspec, 0, $first_bracket_pos));