Czech translation update.
[phpmyadmin/last10db.git] / libraries / common.lib.php
blob293809584c2938ebedffaf1735839ccbc42b3cc7
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Misc functions used all over the scripts.
6 * @version $Id$
7 */
9 /**
10 * Exponential expression / raise number into power
12 * @uses function_exists()
13 * @uses bcpow()
14 * @uses gmp_pow()
15 * @uses gmp_strval()
16 * @uses pow()
17 * @param number $base
18 * @param number $exp
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;
26 if ($exp < 0) {
27 return false;
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')) {
35 // GMP Function
36 $pow_function = 'gmp_pow';
37 } else {
38 // PHP function
39 $pow_function = 'pow';
43 if (! $use_function) {
44 $use_function = $pow_function;
47 switch ($use_function) {
48 case 'bcpow' :
49 //bcscale(10);
50 $pow = bcpow($base, $exp);
51 break;
52 case 'gmp_pow' :
53 $pow = gmp_strval(gmp_pow($base, $exp));
54 break;
55 case 'pow' :
56 $base = (float) $base;
57 $exp = (int) $exp;
58 $pow = pow($base, $exp);
59 break;
60 default:
61 $pow = $use_function($base, $exp);
64 return $pow;
67 /**
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;
83 $include_box = false;
84 $alternate = htmlspecialchars($alternate);
85 $button = '';
87 if ($GLOBALS['cfg']['PropertiesIconic']) {
88 $include_icon = true;
91 if ($force_text
92 || ! (true === $GLOBALS['cfg']['PropertiesIconic'])
93 || ! $include_icon) {
94 // $cfg['PropertiesIconic'] is false or both
95 // OR we have no $include_icon
96 $include_text = true;
99 if ($include_text && $include_icon && $container) {
100 // we have icon, text and request for container
101 $include_box = true;
104 if ($include_box) {
105 $button .= '<div class="nowrap">';
108 if ($include_icon) {
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) {
115 $button .= ' ';
118 if ($include_text) {
119 $button .= $alternate;
122 if ($include_box) {
123 $button .= '</div>';
126 return $button;
130 * Displays the maximum size for an upload
132 * @uses $GLOBALS['strMaximumSize']
133 * @uses PMA_formatByteDown()
134 * @uses sprintf()
135 * @param integer the size
137 * @return string the message
139 * @access public
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
155 * @access public
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
178 * @access public
180 function PMA_sqlAddslashes($a_string = '', $is_like = false, $crlf = false, $php_code = false)
182 if ($is_like) {
183 $a_string = str_replace('\\', '\\\\\\\\', $a_string);
184 } else {
185 $a_string = str_replace('\\', '\\\\', $a_string);
188 if ($crlf) {
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);
194 if ($php_code) {
195 $a_string = str_replace('\'', '\\\'', $a_string);
196 } else {
197 $a_string = str_replace('\'', '\'\'', $a_string);
200 return $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
214 * @access public
216 function PMA_escape_mysql_wildcards($name)
218 $name = str_replace('_', '\\_', $name);
219 $name = str_replace('%', '\\%', $name);
221 return $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
231 * @access public
233 function PMA_unescape_mysql_wildcards($name)
235 $name = str_replace('\\_', '_', $name);
236 $name = str_replace('\\%', '%', $name);
238 return $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()
247 * @uses substr()
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)
254 $quotes = array();
256 if (null === $quote) {
257 $quotes[] = '`';
258 $quotes[] = '"';
259 $quotes[] = "'";
260 } else {
261 $quotes[] = $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;
278 * format sql strings
280 * @todo move into PMA_Sql
281 * @uses PMA_SQP_isError()
282 * @uses PMA_SQP_formatHtml()
283 * @uses PMA_SQP_formatNone()
284 * @uses is_array()
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
292 * @access public
294 * @author Robin Johnson <robbat2@users.sourceforge.net>
296 function PMA_formatSql($parsed_sql, $unparsed_sql = '')
298 global $cfg;
300 // Check that we actually have a valid set of parsed data
301 // well, not quite
302 // first check for the SQL parser having hit an error
303 if (PMA_SQP_isError()) {
304 return $parsed_sql;
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"
312 . '</pre>';
313 return $formatted_sql;
316 $formatted_sql = '';
318 switch ($cfg['SQP']['fmtType']) {
319 case 'none':
320 if ($unparsed_sql != '') {
321 $formatted_sql = "<pre>\n" . PMA_SQP_formatNone(array('raw' => $unparsed_sql)) . "\n</pre>";
322 } else {
323 $formatted_sql = PMA_SQP_formatNone($parsed_sql);
325 break;
326 case 'html':
327 $formatted_sql = PMA_SQP_formatHtml($parsed_sql, 'color');
328 break;
329 case 'text':
330 //$formatted_sql = PMA_SQP_formatText($parsed_sql);
331 $formatted_sql = PMA_SQP_formatHtml($parsed_sql, 'text');
332 break;
333 default:
334 break;
335 } // end switch
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
353 * @uses strtolower()
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
361 * @access public
363 function PMA_showMySQLDocu($chapter, $link, $big_icon = false)
365 global $cfg;
367 if ($cfg['MySQLManualType'] == 'none' || empty($cfg['MySQLManualBase'])) {
368 return '';
371 // Fixup for newly used names:
372 $chapter = str_replace('_', '-', strtolower($chapter));
373 $link = str_replace('_', '-', strtolower($link));
375 switch ($cfg['MySQLManualType']) {
376 case 'chapters':
377 if (empty($chapter)) {
378 $chapter = 'index';
380 $url = $cfg['MySQLManualBase'] . '/' . $chapter . '.html#' . $link;
381 break;
382 case 'big':
383 $url = $cfg['MySQLManualBase'] . '#' . $link;
384 break;
385 case 'searchable':
386 if (empty($link)) {
387 $link = 'index';
389 $url = $cfg['MySQLManualBase'] . '/' . $link . '.html';
390 break;
391 case 'viewable':
392 default:
393 if (empty($link)) {
394 $link = 'index';
396 $mysql = '5.0';
397 $lang = 'en';
398 if (defined('PMA_MYSQL_INT_VERSION')) {
399 if (PMA_MYSQL_INT_VERSION >= 50100) {
400 $mysql = '5.1';
401 if (!empty($GLOBALS['mysql_5_1_doc_lang'])) {
402 $lang = $GLOBALS['mysql_5_1_doc_lang'];
404 } elseif (PMA_MYSQL_INT_VERSION >= 50000) {
405 $mysql = '5.0';
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';
412 break;
415 if ($big_icon) {
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>';
419 } else {
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
430 * @access public
432 function PMA_showHint($message, $bbcode = false, $type = 'notice')
434 if ($message instanceof PMA_Message) {
435 $key = $message->getHash();
436 $type = $message->getLevel();
437 } else {
438 $key = md5($message);
441 if (! isset($GLOBALS['footnotes'][$key])) {
442 $nr = count($GLOBALS['footnotes']) + 1;
443 $GLOBALS['footnotes'][$key] = array(
444 'note' => $message,
445 'type' => $type,
446 'nr' => $nr,
448 } else {
449 $nr = $GLOBALS['footnotes'][$key]['nr'];
452 if ($bbcode) {
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 $cfg['PropertiesIconic']
471 * @uses PMA_backquote()
472 * @uses PMA_DBI_getError()
473 * @uses PMA_formatSql()
474 * @uses PMA_generate_common_hidden_inputs()
475 * @uses PMA_generate_common_url()
476 * @uses PMA_showMySQLDocu()
477 * @uses PMA_sqlAddslashes()
478 * @uses PMA_SQP_isError()
479 * @uses PMA_SQP_parse()
480 * @uses PMA_SQP_getErrorString()
481 * @uses strtolower()
482 * @uses urlencode()
483 * @uses str_replace()
484 * @uses nl2br()
485 * @uses substr()
486 * @uses preg_replace()
487 * @uses preg_match()
488 * @uses explode()
489 * @uses implode()
490 * @uses is_array()
491 * @uses function_exists()
492 * @uses htmlspecialchars()
493 * @uses trim()
494 * @uses strstr()
495 * @param string the error message
496 * @param string the sql query that failed
497 * @param boolean whether to show a "modify" link or not
498 * @param string the "back" link url (full path is not required)
499 * @param boolean EXIT the page?
501 * @global string the curent table
502 * @global string the current db
504 * @access public
506 function PMA_mysqlDie($error_message = '', $the_query = '',
507 $is_modify_link = true, $back_url = '', $exit = true)
509 global $table, $db;
512 * start http output, display html headers
514 require_once './libraries/header.inc.php';
516 if (!$error_message) {
517 $error_message = PMA_DBI_getError();
519 if (!$the_query && !empty($GLOBALS['sql_query'])) {
520 $the_query = $GLOBALS['sql_query'];
523 // --- Added to solve bug #641765
524 // Robbat2 - 12 January 2003, 9:46PM
525 // Revised, Robbat2 - 13 January 2003, 2:59PM
526 if (!function_exists('PMA_SQP_isError') || PMA_SQP_isError()) {
527 $formatted_sql = htmlspecialchars($the_query);
528 } elseif (empty($the_query) || trim($the_query) == '') {
529 $formatted_sql = '';
530 } else {
531 $formatted_sql = PMA_formatSql(PMA_SQP_parse($the_query), $the_query);
533 // ---
534 echo "\n" . '<!-- PMA-SQL-ERROR -->' . "\n";
535 echo ' <div class="error"><h1>' . $GLOBALS['strError'] . '</h1>' . "\n";
536 // if the config password is wrong, or the MySQL server does not
537 // respond, do not show the query that would reveal the
538 // username/password
539 if (!empty($the_query) && !strstr($the_query, 'connect')) {
540 // --- Added to solve bug #641765
541 // Robbat2 - 12 January 2003, 9:46PM
542 // Revised, Robbat2 - 13 January 2003, 2:59PM
543 if (function_exists('PMA_SQP_isError') && PMA_SQP_isError()) {
544 echo PMA_SQP_getErrorString() . "\n";
545 echo '<br />' . "\n";
547 // ---
548 // modified to show me the help on sql errors (Michael Keck)
549 echo ' <p><strong>' . $GLOBALS['strSQLQuery'] . ':</strong>' . "\n";
550 if (strstr(strtolower($formatted_sql), 'select')) { // please show me help to the error on select
551 echo PMA_showMySQLDocu('SQL-Syntax', 'SELECT');
553 if ($is_modify_link) {
554 $_url_params = array(
555 'sql_query' => $the_query,
556 'show_query' => 1,
558 if (strlen($table)) {
559 $_url_params['db'] = $db;
560 $_url_params['table'] = $table;
561 $doedit_goto = '<a href="tbl_sql.php?' . PMA_generate_common_url($_url_params) . '">';
562 } elseif (strlen($db)) {
563 $_url_params['db'] = $db;
564 $doedit_goto = '<a href="db_sql.php?' . PMA_generate_common_url($_url_params) . '">';
565 } else {
566 $doedit_goto = '<a href="server_sql.php?' . PMA_generate_common_url($_url_params) . '">';
569 echo $doedit_goto
570 . PMA_getIcon('b_edit.png', $GLOBALS['strEdit'])
571 . '</a>';
572 } // end if
573 echo ' </p>' . "\n"
574 .' <p>' . "\n"
575 .' ' . $formatted_sql . "\n"
576 .' </p>' . "\n";
577 } // end if
579 $tmp_mysql_error = ''; // for saving the original $error_message
580 if (!empty($error_message)) {
581 $tmp_mysql_error = strtolower($error_message); // save the original $error_message
582 $error_message = htmlspecialchars($error_message);
583 $error_message = preg_replace("@((\015\012)|(\015)|(\012)){3,}@", "\n\n", $error_message);
585 // modified to show me the help on error-returns (Michael Keck)
586 // (now error-messages-server)
587 echo '<p>' . "\n"
588 . ' <strong>' . $GLOBALS['strMySQLSaid'] . '</strong>'
589 . PMA_showMySQLDocu('Error-messages-server', 'Error-messages-server')
590 . "\n"
591 . '</p>' . "\n";
593 // The error message will be displayed within a CODE segment.
594 // To preserve original formatting, but allow wordwrapping, we do a couple of replacements
596 // Replace all non-single blanks with their HTML-counterpart
597 $error_message = str_replace(' ', '&nbsp;&nbsp;', $error_message);
598 // Replace TAB-characters with their HTML-counterpart
599 $error_message = str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', $error_message);
600 // Replace linebreaks
601 $error_message = nl2br($error_message);
603 echo '<code>' . "\n"
604 . $error_message . "\n"
605 . '</code><br />' . "\n";
606 echo '</div>';
608 if ($exit) {
609 if (! empty($back_url)) {
610 if (strstr($back_url, '?')) {
611 $back_url .= '&amp;no_history=true';
612 } else {
613 $back_url .= '?no_history=true';
615 echo '<fieldset class="tblFooters">';
616 echo '[ <a href="' . $back_url . '">' . $GLOBALS['strBack'] . '</a> ]';
617 echo '</fieldset>' . "\n\n";
620 * display footer and exit
622 require_once './libraries/footer.inc.php';
624 } // end of the 'PMA_mysqlDie()' function
627 * Send HTTP header, taking IIS limits into account (600 seems ok)
629 * @uses PMA_IS_IIS
630 * @uses PMA_COMING_FROM_COOKIE_LOGIN
631 * @uses PMA_get_arg_separator()
632 * @uses SID
633 * @uses strlen()
634 * @uses strpos()
635 * @uses header()
636 * @uses session_write_close()
637 * @uses headers_sent()
638 * @uses function_exists()
639 * @uses debug_print_backtrace()
640 * @uses trigger_error()
641 * @uses defined()
642 * @param string $uri the header to send
643 * @return boolean always true
645 function PMA_sendHeaderLocation($uri)
647 if (PMA_IS_IIS && strlen($uri) > 600) {
649 echo '<html><head><title>- - -</title>' . "\n";
650 echo '<meta http-equiv="expires" content="0">' . "\n";
651 echo '<meta http-equiv="Pragma" content="no-cache">' . "\n";
652 echo '<meta http-equiv="Cache-Control" content="no-cache">' . "\n";
653 echo '<meta http-equiv="Refresh" content="0;url=' .$uri . '">' . "\n";
654 echo '<script type="text/javascript">' . "\n";
655 echo '//<![CDATA[' . "\n";
656 echo 'setTimeout("window.location = unescape(\'"' . $uri . '"\')", 2000);' . "\n";
657 echo '//]]>' . "\n";
658 echo '</script>' . "\n";
659 echo '</head>' . "\n";
660 echo '<body>' . "\n";
661 echo '<script type="text/javascript">' . "\n";
662 echo '//<![CDATA[' . "\n";
663 echo 'document.write(\'<p><a href="' . $uri . '">' . $GLOBALS['strGo'] . '</a></p>\');' . "\n";
664 echo '//]]>' . "\n";
665 echo '</script></body></html>' . "\n";
667 } else {
668 if (SID) {
669 if (strpos($uri, '?') === false) {
670 header('Location: ' . $uri . '?' . SID);
671 } else {
672 $separator = PMA_get_arg_separator();
673 header('Location: ' . $uri . $separator . SID);
675 } else {
676 session_write_close();
677 if (headers_sent()) {
678 if (function_exists('debug_print_backtrace')) {
679 echo '<pre>';
680 debug_print_backtrace();
681 echo '</pre>';
683 trigger_error('PMA_sendHeaderLocation called when headers are already sent!', E_USER_ERROR);
685 // bug #1523784: IE6 does not like 'Refresh: 0', it
686 // results in a blank page
687 // but we need it when coming from the cookie login panel)
688 if (PMA_IS_IIS && defined('PMA_COMING_FROM_COOKIE_LOGIN')) {
689 header('Refresh: 0; ' . $uri);
690 } else {
691 header('Location: ' . $uri);
698 * returns array with tables of given db with extended information and grouped
700 * @uses $cfg['LeftFrameTableSeparator']
701 * @uses $cfg['LeftFrameTableLevel']
702 * @uses $cfg['ShowTooltipAliasTB']
703 * @uses $cfg['NaturalOrder']
704 * @uses PMA_backquote()
705 * @uses count()
706 * @uses array_merge
707 * @uses uksort()
708 * @uses strstr()
709 * @uses explode()
710 * @param string $db name of db
711 * @param string $tables name of tables
712 * return array (recursive) grouped table list
714 function PMA_getTableList($db, $tables = null, $limit_offset = 0, $limit_count = false)
716 $sep = $GLOBALS['cfg']['LeftFrameTableSeparator'];
718 if (null === $tables) {
719 $tables = PMA_DBI_get_tables_full($db, false, false, null, $limit_offset, $limit_count);
720 if ($GLOBALS['cfg']['NaturalOrder']) {
721 uksort($tables, 'strnatcasecmp');
725 if (count($tables) < 1) {
726 return $tables;
729 $default = array(
730 'Name' => '',
731 'Rows' => 0,
732 'Comment' => '',
733 'disp_name' => '',
736 $table_groups = array();
738 foreach ($tables as $table_name => $table) {
740 // check for correct row count
741 if (null === $table['Rows']) {
742 // Do not check exact row count here,
743 // if row count is invalid possibly the table is defect
744 // and this would break left frame;
745 // but we can check row count if this is a view,
746 // since PMA_Table::countRecords() returns a limited row count
747 // in this case.
749 // set this because PMA_Table::countRecords() can use it
750 $tbl_is_view = PMA_Table::isView($db, $table['Name']);
752 if ($tbl_is_view) {
753 $table['Rows'] = PMA_Table::countRecords($db, $table['Name'],
754 $return = true);
758 // in $group we save the reference to the place in $table_groups
759 // where to store the table info
760 if ($GLOBALS['cfg']['LeftFrameDBTree']
761 && $sep && strstr($table_name, $sep))
763 $parts = explode($sep, $table_name);
765 $group =& $table_groups;
766 $i = 0;
767 $group_name_full = '';
768 while ($i < count($parts) - 1
769 && $i < $GLOBALS['cfg']['LeftFrameTableLevel']) {
770 $group_name = $parts[$i] . $sep;
771 $group_name_full .= $group_name;
773 if (!isset($group[$group_name])) {
774 $group[$group_name] = array();
775 $group[$group_name]['is' . $sep . 'group'] = true;
776 $group[$group_name]['tab' . $sep . 'count'] = 1;
777 $group[$group_name]['tab' . $sep . 'group'] = $group_name_full;
778 } elseif (!isset($group[$group_name]['is' . $sep . 'group'])) {
779 $table = $group[$group_name];
780 $group[$group_name] = array();
781 $group[$group_name][$group_name] = $table;
782 unset($table);
783 $group[$group_name]['is' . $sep . 'group'] = true;
784 $group[$group_name]['tab' . $sep . 'count'] = 1;
785 $group[$group_name]['tab' . $sep . 'group'] = $group_name_full;
786 } else {
787 $group[$group_name]['tab' . $sep . 'count']++;
789 $group =& $group[$group_name];
790 $i++;
792 } else {
793 if (!isset($table_groups[$table_name])) {
794 $table_groups[$table_name] = array();
796 $group =& $table_groups;
800 if ($GLOBALS['cfg']['ShowTooltipAliasTB']
801 && $GLOBALS['cfg']['ShowTooltipAliasTB'] !== 'nested') {
802 // switch tooltip and name
803 $table['Comment'] = $table['Name'];
804 $table['disp_name'] = $table['Comment'];
805 } else {
806 $table['disp_name'] = $table['Name'];
809 $group[$table_name] = array_merge($default, $table);
812 return $table_groups;
815 /* ----------------------- Set of misc functions ----------------------- */
819 * Adds backquotes on both sides of a database, table or field name.
820 * and escapes backquotes inside the name with another backquote
822 * example:
823 * <code>
824 * echo PMA_backquote('owner`s db'); // `owner``s db`
826 * </code>
828 * @uses PMA_backquote()
829 * @uses is_array()
830 * @uses strlen()
831 * @uses str_replace()
832 * @param mixed $a_name the database, table or field name to "backquote"
833 * or array of it
834 * @param boolean $do_it a flag to bypass this function (used by dump
835 * functions)
836 * @return mixed the "backquoted" database, table or field name if the
837 * current MySQL release is >= 3.23.6, the original one
838 * else
839 * @access public
841 function PMA_backquote($a_name, $do_it = true)
843 if (! $do_it) {
844 return $a_name;
847 if (is_array($a_name)) {
848 $result = array();
849 foreach ($a_name as $key => $val) {
850 $result[$key] = PMA_backquote($val);
852 return $result;
855 // '0' is also empty for php :-(
856 if (strlen($a_name) && $a_name !== '*') {
857 return '`' . str_replace('`', '``', $a_name) . '`';
858 } else {
859 return $a_name;
861 } // end of the 'PMA_backquote()' function
865 * Defines the <CR><LF> value depending on the user OS.
867 * @uses PMA_USR_OS
868 * @return string the <CR><LF> value to use
870 * @access public
872 function PMA_whichCrlf()
874 $the_crlf = "\n";
876 // The 'PMA_USR_OS' constant is defined in "./libraries/Config.class.php"
877 // Win case
878 if (PMA_USR_OS == 'Win') {
879 $the_crlf = "\r\n";
881 // Others
882 else {
883 $the_crlf = "\n";
886 return $the_crlf;
887 } // end of the 'PMA_whichCrlf()' function
890 * Reloads navigation if needed.
892 * @uses $GLOBALS['reload']
893 * @uses $GLOBALS['db']
894 * @uses PMA_generate_common_url()
895 * @global array configuration
897 * @access public
899 function PMA_reloadNavigation()
901 global $cfg;
903 // Reloads the navigation frame via JavaScript if required
904 if (isset($GLOBALS['reload']) && $GLOBALS['reload']) {
905 // one of the reasons for a reload is when a table is dropped
906 // in this case, get rid of the table limit offset, otherwise
907 // we have a problem when dropping a table on the last page
908 // and the offset becomes greater than the total number of tables
909 unset($_SESSION['userconf']['table_limit_offset']);
910 echo "\n";
911 $reload_url = './navigation.php?' . PMA_generate_common_url($GLOBALS['db'], '', '&');
913 <script type="text/javascript">
914 //<![CDATA[
915 if (typeof(window.parent) != 'undefined'
916 && typeof(window.parent.frame_navigation) != 'undefined') {
917 window.parent.goTo('<?php echo $reload_url; ?>');
919 //]]>
920 </script>
921 <?php
922 unset($GLOBALS['reload']);
927 * displays the message and the query
928 * usually the message is the result of the query executed
930 * @param string $message the message to display
931 * @param string $sql_query the query to display
932 * @global array the configuration array
933 * @uses $cfg
934 * @access public
936 function PMA_showMessage($message, $sql_query = null, $type = 'notice')
938 global $cfg;
940 if (null === $sql_query) {
941 if (! empty($GLOBALS['display_query'])) {
942 $sql_query = $GLOBALS['display_query'];
943 } elseif ($cfg['SQP']['fmtType'] == 'none' && ! empty($GLOBALS['unparsed_sql'])) {
944 $sql_query = $GLOBALS['unparsed_sql'];
945 } elseif (! empty($GLOBALS['sql_query'])) {
946 $sql_query = $GLOBALS['sql_query'];
947 } else {
948 $sql_query = '';
952 // Corrects the tooltip text via JS if required
953 // @todo this is REALLY the wrong place to do this - very unexpected here
954 if (strlen($GLOBALS['table']) && $cfg['ShowTooltip']) {
955 $result = PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], true) . '\'');
956 if ($result) {
957 $tbl_status = PMA_DBI_fetch_assoc($result);
958 $tooltip = (empty($tbl_status['Comment']))
959 ? ''
960 : $tbl_status['Comment'] . ' ';
961 $tooltip .= '(' . PMA_formatNumber($tbl_status['Rows'], 0) . ' ' . $GLOBALS['strRows'] . ')';
962 PMA_DBI_free_result($result);
963 $uni_tbl = PMA_jsFormat($GLOBALS['db'] . '.' . $GLOBALS['table'], false);
964 echo "\n";
965 echo '<script type="text/javascript">' . "\n";
966 echo '//<![CDATA[' . "\n";
967 echo "window.parent.updateTableTitle('" . $uni_tbl . "', '" . PMA_jsFormat($tooltip, false) . "');" . "\n";
968 echo '//]]>' . "\n";
969 echo '</script>' . "\n";
970 } // end if
971 } // end if ... elseif
973 // Checks if the table needs to be repaired after a TRUNCATE query.
974 // @todo what about $GLOBALS['display_query']???
975 // @todo this is REALLY the wrong place to do this - very unexpected here
976 if (strlen($GLOBALS['table'])
977 && $GLOBALS['sql_query'] == 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table'])) {
978 if (!isset($tbl_status)) {
979 $result = @PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], true) . '\'');
980 if ($result) {
981 $tbl_status = PMA_DBI_fetch_assoc($result);
982 PMA_DBI_free_result($result);
985 if (isset($tbl_status) && (int) $tbl_status['Index_length'] > 1024) {
986 PMA_DBI_try_query('REPAIR TABLE ' . PMA_backquote($GLOBALS['table']));
989 unset($tbl_status);
991 echo '<div align="' . $GLOBALS['cell_align_left'] . '">' . "\n";
993 if ($message instanceof PMA_Message) {
994 $message->display();
995 $type = $message->getLevel();
996 } else {
997 echo '<div class="' . $type . '">';
998 echo PMA_sanitize($message);
999 if (isset($GLOBALS['special_message'])) {
1000 echo PMA_sanitize($GLOBALS['special_message']);
1001 unset($GLOBALS['special_message']);
1003 echo '</div>';
1006 if ($cfg['ShowSQL'] == true && ! empty($sql_query)) {
1007 // Html format the query to be displayed
1008 // If we want to show some sql code it is easiest to create it here
1009 /* SQL-Parser-Analyzer */
1011 if (! empty($GLOBALS['show_as_php'])) {
1012 $new_line = '\\n"<br />' . "\n"
1013 . '&nbsp;&nbsp;&nbsp;&nbsp;. "';
1014 $query_base = htmlspecialchars(addslashes($sql_query));
1015 $query_base = preg_replace('/((\015\012)|(\015)|(\012))/', $new_line, $query_base);
1016 } else {
1017 $query_base = $sql_query;
1020 $query_too_big = false;
1022 if (strlen($query_base) > $cfg['MaxCharactersInDisplayedSQL']) {
1023 // when the query is large (for example an INSERT of binary
1024 // data), the parser chokes; so avoid parsing the query
1025 $query_too_big = true;
1026 $query_base = nl2br(htmlspecialchars($sql_query));
1027 } elseif (! empty($GLOBALS['parsed_sql'])
1028 && $query_base == $GLOBALS['parsed_sql']['raw']) {
1029 // (here, use "! empty" because when deleting a bookmark,
1030 // $GLOBALS['parsed_sql'] is set but empty
1031 $parsed_sql = $GLOBALS['parsed_sql'];
1032 } else {
1033 // Parse SQL if needed
1034 $parsed_sql = PMA_SQP_parse($query_base);
1037 // Analyze it
1038 if (isset($parsed_sql)) {
1039 $analyzed_display_query = PMA_SQP_analyze($parsed_sql);
1040 // Here we append the LIMIT added for navigation, to
1041 // enable its display. Adding it higher in the code
1042 // to $sql_query would create a problem when
1043 // using the Refresh or Edit links.
1045 // Only append it on SELECTs.
1048 * @todo what would be the best to do when someone hits Refresh:
1049 * use the current LIMITs ?
1052 if (isset($analyzed_display_query[0]['queryflags']['select_from'])
1053 && isset($GLOBALS['sql_limit_to_append'])) {
1054 $query_base = $analyzed_display_query[0]['section_before_limit']
1055 . "\n" . $GLOBALS['sql_limit_to_append']
1056 . $analyzed_display_query[0]['section_after_limit'];
1057 // Need to reparse query
1058 $parsed_sql = PMA_SQP_parse($query_base);
1062 if (! empty($GLOBALS['show_as_php'])) {
1063 $query_base = '$sql = "' . $query_base;
1064 } elseif (! empty($GLOBALS['validatequery'])) {
1065 $query_base = PMA_validateSQL($query_base);
1066 } elseif (isset($parsed_sql)) {
1067 $query_base = PMA_formatSql($parsed_sql, $query_base);
1070 // Prepares links that may be displayed to edit/explain the query
1071 // (don't go to default pages, we must go to the page
1072 // where the query box is available)
1074 // Basic url query part
1075 $url_params = array();
1076 if (strlen($GLOBALS['db'])) {
1077 $url_params['db'] = $GLOBALS['db'];
1078 if (strlen($GLOBALS['table'])) {
1079 $url_params['table'] = $GLOBALS['table'];
1080 $edit_link = 'tbl_sql.php';
1081 } else {
1082 $edit_link = 'db_sql.php';
1084 } else {
1085 $edit_link = 'server_sql.php';
1088 // Want to have the query explained (Mike Beck 2002-05-22)
1089 // but only explain a SELECT (that has not been explained)
1090 /* SQL-Parser-Analyzer */
1091 $explain_link = '';
1092 if (! empty($cfg['SQLQuery']['Explain']) && ! $query_too_big) {
1093 $explain_params = $url_params;
1094 // Detect if we are validating as well
1095 // To preserve the validate uRL data
1096 if (! empty($GLOBALS['validatequery'])) {
1097 $explain_params['validatequery'] = 1;
1100 if (preg_match('@^SELECT[[:space:]]+@i', $sql_query)) {
1101 $explain_params['sql_query'] = 'EXPLAIN ' . $sql_query;
1102 $_message = $GLOBALS['strExplain'];
1103 } elseif (preg_match('@^EXPLAIN[[:space:]]+SELECT[[:space:]]+@i', $sql_query)) {
1104 $explain_params['sql_query'] = substr($sql_query, 8);
1105 $_message = $GLOBALS['strNoExplain'];
1107 if (isset($explain_params['sql_query'])) {
1108 $explain_link = 'import.php' . PMA_generate_common_url($explain_params);
1109 $explain_link = ' [' . PMA_linkOrButton($explain_link, $_message) . ']';
1111 } //show explain
1113 $url_params['sql_query'] = $sql_query;
1114 $url_params['show_query'] = 1;
1116 if (! empty($cfg['SQLQuery']['Edit']) && ! $query_too_big) {
1117 if ($cfg['EditInWindow'] == true) {
1118 $onclick = 'window.parent.focus_querywindow(\'' . PMA_jsFormat($sql_query, false) . '\'); return false;';
1119 } else {
1120 $onclick = '';
1123 $edit_link .= PMA_generate_common_url($url_params) . '#querybox';
1124 $edit_link = ' [' . PMA_linkOrButton($edit_link, $GLOBALS['strEdit'], array('onclick' => $onclick)) . ']';
1125 } else {
1126 $edit_link = '';
1129 $url_qpart = PMA_generate_common_url($url_params);
1131 // Also we would like to get the SQL formed in some nice
1132 // php-code (Mike Beck 2002-05-22)
1133 if (! empty($cfg['SQLQuery']['ShowAsPHP']) && ! $query_too_big) {
1134 $php_params = $url_params;
1136 if (! empty($GLOBALS['show_as_php'])) {
1137 $_message = $GLOBALS['strNoPhp'];
1138 } else {
1139 $php_params['show_as_php'] = 1;
1140 $_message = $GLOBALS['strPhp'];
1143 $php_link = 'import.php' . PMA_generate_common_url($php_params);
1144 $php_link = ' [' . PMA_linkOrButton($php_link, $_message) . ']';
1146 if (isset($GLOBALS['show_as_php'])) {
1147 $runquery_link = 'import.php' . PMA_generate_common_url($url_params);
1148 $php_link .= ' [' . PMA_linkOrButton($runquery_link, $GLOBALS['strRunQuery']) . ']';
1150 } else {
1151 $php_link = '';
1152 } //show as php
1154 // Refresh query
1155 if (! empty($cfg['SQLQuery']['Refresh'])
1156 && preg_match('@^(SELECT|SHOW)[[:space:]]+@i', $sql_query)) {
1157 $refresh_link = 'import.php' . PMA_generate_common_url($url_params);
1158 $refresh_link = ' [' . PMA_linkOrButton($refresh_link, $GLOBALS['strRefresh']) . ']';
1159 } else {
1160 $refresh_link = '';
1161 } //show as php
1163 if (! empty($cfg['SQLValidator']['use'])
1164 && ! empty($cfg['SQLQuery']['Validate'])) {
1165 $validate_params = $url_params;
1166 if (!empty($GLOBALS['validatequery'])) {
1167 $validate_message = $GLOBALS['strNoValidateSQL'] ;
1168 } else {
1169 $validate_params['validatequery'] = 1;
1170 $validate_message = $GLOBALS['strValidateSQL'] ;
1173 $validate_link = 'import.php' . PMA_generate_common_url($validate_params);
1174 $validate_link = ' [' . PMA_linkOrButton($validate_link, $validate_message) . ']';
1175 } else {
1176 $validate_link = '';
1177 } //validator
1179 echo '<code class="sql">';
1180 if ($query_too_big) {
1181 echo substr($query_base, 0, $cfg['MaxCharactersInDisplayedSQL']) . '[...]';
1182 } else {
1183 echo $query_base;
1186 //Clean up the end of the PHP
1187 if (! empty($GLOBALS['show_as_php'])) {
1188 echo '";';
1190 echo '</code>';
1192 echo '<div class="tools">';
1193 PMA_profilingCheckbox($sql_query);
1194 echo $edit_link . $explain_link . $php_link . $refresh_link . $validate_link;
1195 echo '</div>';
1197 echo '</div><br />' . "\n";
1198 } // end of the 'PMA_showMessage()' function
1201 * Verifies if current MySQL server supports profiling
1203 * @uses $_SESSION['profiling_supported'] for caching
1204 * @uses $GLOBALS['server']
1205 * @uses PMA_DBI_fetch_value()
1206 * @uses PMA_MYSQL_INT_VERSION
1207 * @uses defined()
1208 * @access public
1209 * @return boolean whether profiling is supported
1211 * @author Marc Delisle
1213 function PMA_profilingSupported()
1215 if (! PMA_cacheExists('profiling_supported', true)) {
1216 // 5.0.37 has profiling but for example, 5.1.20 does not
1217 // (avoid a trip to the server for MySQL before 5.0.37)
1218 // and do not set a constant as we might be switching servers
1219 if (defined('PMA_MYSQL_INT_VERSION')
1220 && PMA_MYSQL_INT_VERSION >= 50037
1221 && PMA_DBI_fetch_value("SHOW VARIABLES LIKE 'profiling'")) {
1222 PMA_cacheSet('profiling_supported', true, true);
1223 } else {
1224 PMA_cacheSet('profiling_supported', false, true);
1228 return PMA_cacheGet('profiling_supported', true);
1232 * Displays a form with the Profiling checkbox
1234 * @param string $sql_query
1235 * @access public
1237 * @author Marc Delisle
1239 function PMA_profilingCheckbox($sql_query)
1241 if (PMA_profilingSupported()) {
1242 echo '<form action="sql.php" method="post">' . "\n";
1243 echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']);
1244 echo '<input type="hidden" name="sql_query" value="' . htmlspecialchars($sql_query) . '" />' . "\n";
1245 echo '<input type="hidden" name="profiling_form" value="1" />' . "\n";
1246 echo '<input type="checkbox" name="profiling" id="profiling"' . (isset($_SESSION['profiling']) ? ' checked="checked"' : '') . ' onclick="this.form.submit();" /><label for="profiling">' . $GLOBALS['strProfiling'] . '</label>' . "\n";
1247 echo '<noscript><input type="submit" value="' . $GLOBALS['strGo'] . '" /></noscript>' . "\n";
1248 echo '</form>' . "\n";
1253 * Displays the results of SHOW PROFILE
1255 * @param array the results
1256 * @access public
1258 * @author Marc Delisle
1260 function PMA_profilingResults($profiling_results)
1262 echo '<fieldset><legend>' . $GLOBALS['strProfiling'] . '</legend>' . "\n";
1263 echo '<table>' . "\n";
1264 echo ' <tr>' . "\n";
1265 echo ' <th>' . $GLOBALS['strStatus'] . '</th>' . "\n";
1266 echo ' <th>' . $GLOBALS['strTime'] . '</th>' . "\n";
1267 echo ' </tr>' . "\n";
1269 foreach($profiling_results as $one_result) {
1270 echo ' <tr>' . "\n";
1271 echo '<td>' . $one_result['Status'] . '</td>' . "\n";
1272 echo '<td>' . $one_result['Duration'] . '</td>' . "\n";
1274 echo '</table>' . "\n";
1275 echo '</fieldset>' . "\n";
1279 * Formats $value to byte view
1281 * @param double the value to format
1282 * @param integer the sensitiveness
1283 * @param integer the number of decimals to retain
1285 * @return array the formatted value and its unit
1287 * @access public
1289 * @author staybyte
1290 * @version 1.2 - 18 July 2002
1292 function PMA_formatByteDown($value, $limes = 6, $comma = 0)
1294 $dh = PMA_pow(10, $comma);
1295 $li = PMA_pow(10, $limes);
1296 $return_value = $value;
1297 $unit = $GLOBALS['byteUnits'][0];
1299 for ($d = 6, $ex = 15; $d >= 1; $d--, $ex-=3) {
1300 if (isset($GLOBALS['byteUnits'][$d]) && $value >= $li * PMA_pow(10, $ex)) {
1301 // use 1024.0 to avoid integer overflow on 64-bit machines
1302 $value = round($value / (PMA_pow(1024, $d) / $dh)) /$dh;
1303 $unit = $GLOBALS['byteUnits'][$d];
1304 break 1;
1305 } // end if
1306 } // end for
1308 if ($unit != $GLOBALS['byteUnits'][0]) {
1309 // if the unit is not bytes (as represented in current language)
1310 // reformat with max length of 5
1311 // 4th parameter=true means do not reformat if value < 1
1312 $return_value = PMA_formatNumber($value, 5, $comma, true);
1313 } else {
1314 // do not reformat, just handle the locale
1315 $return_value = PMA_formatNumber($value, 0);
1318 return array($return_value, $unit);
1319 } // end of the 'PMA_formatByteDown' function
1322 * Formats $value to the given length and appends SI prefixes
1323 * $comma is not substracted from the length
1324 * with a $length of 0 no truncation occurs, number is only formated
1325 * to the current locale
1327 * examples:
1328 * <code>
1329 * echo PMA_formatNumber(123456789, 6); // 123,457 k
1330 * echo PMA_formatNumber(-123456789, 4, 2); // -123.46 M
1331 * echo PMA_formatNumber(-0.003, 6); // -3 m
1332 * echo PMA_formatNumber(0.003, 3, 3); // 0.003
1333 * echo PMA_formatNumber(0.00003, 3, 2); // 0.03 m
1334 * echo PMA_formatNumber(0, 6); // 0
1336 * </code>
1337 * @param double $value the value to format
1338 * @param integer $length the max length
1339 * @param integer $comma the number of decimals to retain
1340 * @param boolean $only_down do not reformat numbers below 1
1342 * @return string the formatted value and its unit
1344 * @access public
1346 * @author staybyte, sebastian mendel
1347 * @version 1.1.0 - 2005-10-27
1349 function PMA_formatNumber($value, $length = 3, $comma = 0, $only_down = false)
1351 //number_format is not multibyte safe, str_replace is safe
1352 if ($length === 0) {
1353 return str_replace(array(',', '.'),
1354 array($GLOBALS['number_thousands_separator'], $GLOBALS['number_decimal_separator']),
1355 number_format($value, $comma));
1358 // this units needs no translation, ISO
1359 $units = array(
1360 -8 => 'y',
1361 -7 => 'z',
1362 -6 => 'a',
1363 -5 => 'f',
1364 -4 => 'p',
1365 -3 => 'n',
1366 -2 => '&micro;',
1367 -1 => 'm',
1368 0 => ' ',
1369 1 => 'k',
1370 2 => 'M',
1371 3 => 'G',
1372 4 => 'T',
1373 5 => 'P',
1374 6 => 'E',
1375 7 => 'Z',
1376 8 => 'Y'
1379 // we need at least 3 digits to be displayed
1380 if (3 > $length + $comma) {
1381 $length = 3 - $comma;
1384 // check for negative value to retain sign
1385 if ($value < 0) {
1386 $sign = '-';
1387 $value = abs($value);
1388 } else {
1389 $sign = '';
1392 $dh = PMA_pow(10, $comma);
1393 $li = PMA_pow(10, $length);
1394 $unit = $units[0];
1396 if ($value >= 1) {
1397 for ($d = 8; $d >= 0; $d--) {
1398 if (isset($units[$d]) && $value >= $li * PMA_pow(1000, $d-1)) {
1399 $value = round($value / (PMA_pow(1000, $d) / $dh)) /$dh;
1400 $unit = $units[$d];
1401 break 1;
1402 } // end if
1403 } // end for
1404 } elseif (!$only_down && (float) $value !== 0.0) {
1405 for ($d = -8; $d <= 8; $d++) {
1406 if (isset($units[$d]) && $value <= $li * PMA_pow(1000, $d-1)) {
1407 $value = round($value / (PMA_pow(1000, $d) / $dh)) /$dh;
1408 $unit = $units[$d];
1409 break 1;
1410 } // end if
1411 } // end for
1412 } // end if ($value >= 1) elseif (!$only_down && (float) $value !== 0.0)
1414 //number_format is not multibyte safe, str_replace is safe
1415 $value = str_replace(array(',', '.'),
1416 array($GLOBALS['number_thousands_separator'], $GLOBALS['number_decimal_separator']),
1417 number_format($value, $comma));
1419 return $sign . $value . ' ' . $unit;
1420 } // end of the 'PMA_formatNumber' function
1423 * Extracts ENUM / SET options from a type definition string
1425 * @param string The column type definition
1427 * @return array The options or
1428 * boolean false in case of an error.
1430 * @author rabus
1432 function PMA_getEnumSetOptions($type_def)
1434 $open = strpos($type_def, '(');
1435 $close = strrpos($type_def, ')');
1436 if (!$open || !$close) {
1437 return false;
1439 $options = substr($type_def, $open + 2, $close - $open - 3);
1440 $options = explode('\',\'', $options);
1441 return $options;
1442 } // end of the 'PMA_getEnumSetOptions' function
1445 * Writes localised date
1447 * @param string the current timestamp
1449 * @return string the formatted date
1451 * @access public
1453 function PMA_localisedDate($timestamp = -1, $format = '')
1455 global $datefmt, $month, $day_of_week;
1457 if ($format == '') {
1458 $format = $datefmt;
1461 if ($timestamp == -1) {
1462 $timestamp = time();
1465 $date = preg_replace('@%[aA]@', $day_of_week[(int)strftime('%w', $timestamp)], $format);
1466 $date = preg_replace('@%[bB]@', $month[(int)strftime('%m', $timestamp)-1], $date);
1468 return strftime($date, $timestamp);
1469 } // end of the 'PMA_localisedDate()' function
1473 * returns a tab for tabbed navigation.
1474 * If the variables $link and $args ar left empty, an inactive tab is created
1476 * @uses $GLOBALS['PMA_PHP_SELF']
1477 * @uses $GLOBALS['strEmpty']
1478 * @uses $GLOBALS['strDrop']
1479 * @uses $GLOBALS['active_page']
1480 * @uses $GLOBALS['url_query']
1481 * @uses $cfg['MainPageIconic']
1482 * @uses $GLOBALS['pmaThemeImage']
1483 * @uses PMA_generate_common_url()
1484 * @uses E_USER_NOTICE
1485 * @uses htmlentities()
1486 * @uses urlencode()
1487 * @uses sprintf()
1488 * @uses trigger_error()
1489 * @uses array_merge()
1490 * @uses basename()
1491 * @param array $tab array with all options
1492 * @return string html code for one tab, a link if valid otherwise a span
1493 * @access public
1495 function PMA_getTab($tab)
1497 // default values
1498 $defaults = array(
1499 'text' => '',
1500 'class' => '',
1501 'active' => false,
1502 'link' => '',
1503 'sep' => '?',
1504 'attr' => '',
1505 'args' => '',
1506 'warning' => '',
1507 'fragment' => '',
1510 $tab = array_merge($defaults, $tab);
1512 // determine additionnal style-class
1513 if (empty($tab['class'])) {
1514 if ($tab['text'] == $GLOBALS['strEmpty']
1515 || $tab['text'] == $GLOBALS['strDrop']) {
1516 $tab['class'] = 'caution';
1517 } elseif (! empty($tab['active'])
1518 || PMA_isValid($GLOBALS['active_page'], 'identical', $tab['link'])) {
1519 $tab['class'] = 'active';
1520 } elseif (empty($GLOBALS['active_page'])
1521 && basename($GLOBALS['PMA_PHP_SELF']) == $tab['link']
1522 && empty($tab['warning'])) {
1523 $tab['class'] = 'active';
1527 if (!empty($tab['warning'])) {
1528 $tab['class'] .= ' warning';
1529 $tab['attr'] .= ' title="' . htmlspecialchars($tab['warning']) . '"';
1532 // build the link
1533 if (!empty($tab['link'])) {
1534 $tab['link'] = htmlentities($tab['link']);
1535 $tab['link'] = $tab['link'] . $tab['sep']
1536 .(empty($GLOBALS['url_query']) ?
1537 PMA_generate_common_url() : $GLOBALS['url_query']);
1538 if (! empty($tab['args'])) {
1539 foreach ($tab['args'] as $param => $value) {
1540 $tab['link'] .= PMA_get_arg_separator('html') . urlencode($param) . '='
1541 . urlencode($value);
1546 if (! empty($tab['fragment'])) {
1547 $tab['link'] .= $tab['fragment'];
1550 // display icon, even if iconic is disabled but the link-text is missing
1551 if (($GLOBALS['cfg']['MainPageIconic'] || empty($tab['text']))
1552 && isset($tab['icon'])) {
1553 $image = '<img class="icon" src="' . htmlentities($GLOBALS['pmaThemeImage'])
1554 .'%1$s" width="16" height="16" alt="%2$s" />%2$s';
1555 $tab['text'] = sprintf($image, htmlentities($tab['icon']), $tab['text']);
1557 // check to not display an empty link-text
1558 elseif (empty($tab['text'])) {
1559 $tab['text'] = '?';
1560 trigger_error('empty linktext in function ' . __FUNCTION__ . '()',
1561 E_USER_NOTICE);
1564 $out = '<li' . ($tab['class'] == 'active' ? ' class="active"' : '') . '>';
1566 if (!empty($tab['link'])) {
1567 $out .= '<a class="tab' . htmlentities($tab['class']) . '"'
1568 .' href="' . $tab['link'] . '" ' . $tab['attr'] . '>'
1569 . $tab['text'] . '</a>';
1570 } else {
1571 $out .= '<span class="tab' . htmlentities($tab['class']) . '">'
1572 . $tab['text'] . '</span>';
1575 $out .= '</li>';
1576 return $out;
1577 } // end of the 'PMA_getTab()' function
1580 * returns html-code for a tab navigation
1582 * @uses PMA_getTab()
1583 * @uses htmlentities()
1584 * @param array $tabs one element per tab
1585 * @param string $tag_id id used for the html-tag
1586 * @return string html-code for tab-navigation
1588 function PMA_getTabs($tabs, $tag_id = 'topmenu')
1590 $tab_navigation =
1591 '<div id="' . htmlentities($tag_id) . 'container">' . "\n"
1592 .'<ul id="' . htmlentities($tag_id) . '">' . "\n";
1594 foreach ($tabs as $tab) {
1595 $tab_navigation .= PMA_getTab($tab) . "\n";
1598 $tab_navigation .=
1599 '</ul>' . "\n"
1600 .'<div class="clearfloat"></div>'
1601 .'</div>' . "\n";
1603 return $tab_navigation;
1608 * Displays a link, or a button if the link's URL is too large, to
1609 * accommodate some browsers' limitations
1611 * @param string the URL
1612 * @param string the link message
1613 * @param mixed $tag_params string: js confirmation
1614 * array: additional tag params (f.e. style="")
1615 * @param boolean $new_form we set this to false when we are already in
1616 * a form, to avoid generating nested forms
1618 * @return string the results to be echoed or saved in an array
1620 function PMA_linkOrButton($url, $message, $tag_params = array(),
1621 $new_form = true, $strip_img = false, $target = '')
1623 if (! is_array($tag_params)) {
1624 $tmp = $tag_params;
1625 $tag_params = array();
1626 if (!empty($tmp)) {
1627 $tag_params['onclick'] = 'return confirmLink(this, \'' . $tmp . '\')';
1629 unset($tmp);
1631 if (! empty($target)) {
1632 $tag_params['target'] = htmlentities($target);
1635 $tag_params_strings = array();
1636 foreach ($tag_params as $par_name => $par_value) {
1637 // htmlspecialchars() only on non javascript
1638 $par_value = substr($par_name, 0, 2) == 'on'
1639 ? $par_value
1640 : htmlspecialchars($par_value);
1641 $tag_params_strings[] = $par_name . '="' . $par_value . '"';
1644 // previously the limit was set to 2047, it seems 1000 is better
1645 if (strlen($url) <= 1000) {
1646 // no whitespace within an <a> else Safari will make it part of the link
1647 $ret = "\n" . '<a href="' . $url . '" '
1648 . implode(' ', $tag_params_strings) . '>'
1649 . $message . '</a>' . "\n";
1650 } else {
1651 // no spaces (linebreaks) at all
1652 // or after the hidden fields
1653 // IE will display them all
1655 // add class=link to submit button
1656 if (empty($tag_params['class'])) {
1657 $tag_params['class'] = 'link';
1660 // decode encoded url separators
1661 $separator = PMA_get_arg_separator();
1662 // on most places separator is still hard coded ...
1663 if ($separator !== '&') {
1664 // ... so always replace & with $separator
1665 $url = str_replace(htmlentities('&'), $separator, $url);
1666 $url = str_replace('&', $separator, $url);
1668 $url = str_replace(htmlentities($separator), $separator, $url);
1669 // end decode
1671 $url_parts = parse_url($url);
1672 $query_parts = explode($separator, $url_parts['query']);
1673 if ($new_form) {
1674 $ret = '<form action="' . $url_parts['path'] . '" class="link"'
1675 . ' method="post"' . $target . ' style="display: inline;">';
1676 $subname_open = '';
1677 $subname_close = '';
1678 $submit_name = '';
1679 } else {
1680 $query_parts[] = 'redirect=' . $url_parts['path'];
1681 if (empty($GLOBALS['subform_counter'])) {
1682 $GLOBALS['subform_counter'] = 0;
1684 $GLOBALS['subform_counter']++;
1685 $ret = '';
1686 $subname_open = 'subform[' . $GLOBALS['subform_counter'] . '][';
1687 $subname_close = ']';
1688 $submit_name = ' name="usesubform[' . $GLOBALS['subform_counter'] . ']"';
1690 foreach ($query_parts as $query_pair) {
1691 list($eachvar, $eachval) = explode('=', $query_pair);
1692 $ret .= '<input type="hidden" name="' . $subname_open . $eachvar
1693 . $subname_close . '" value="'
1694 . htmlspecialchars(urldecode($eachval)) . '" />';
1695 } // end while
1697 if (stristr($message, '<img')) {
1698 if ($strip_img) {
1699 $message = trim(strip_tags($message));
1700 $ret .= '<input type="submit"' . $submit_name . ' '
1701 . implode(' ', $tag_params_strings)
1702 . ' value="' . htmlspecialchars($message) . '" />';
1703 } else {
1704 $ret .= '<input type="image"' . $submit_name . ' '
1705 . implode(' ', $tag_params_strings)
1706 . ' src="' . preg_replace(
1707 '/^.*\ssrc="([^"]*)".*$/si', '\1', $message) . '"'
1708 . ' value="' . htmlspecialchars(
1709 preg_replace('/^.*\salt="([^"]*)".*$/si', '\1',
1710 $message))
1711 . '" />';
1713 } else {
1714 $message = trim(strip_tags($message));
1715 $ret .= '<input type="submit"' . $submit_name . ' '
1716 . implode(' ', $tag_params_strings)
1717 . ' value="' . htmlspecialchars($message) . '" />';
1719 if ($new_form) {
1720 $ret .= '</form>';
1722 } // end if... else...
1724 return $ret;
1725 } // end of the 'PMA_linkOrButton()' function
1729 * Returns a given timespan value in a readable format.
1731 * @uses $GLOBALS['timespanfmt']
1732 * @uses sprintf()
1733 * @uses floor()
1734 * @param int the timespan
1736 * @return string the formatted value
1738 function PMA_timespanFormat($seconds)
1740 $return_string = '';
1741 $days = floor($seconds / 86400);
1742 if ($days > 0) {
1743 $seconds -= $days * 86400;
1745 $hours = floor($seconds / 3600);
1746 if ($days > 0 || $hours > 0) {
1747 $seconds -= $hours * 3600;
1749 $minutes = floor($seconds / 60);
1750 if ($days > 0 || $hours > 0 || $minutes > 0) {
1751 $seconds -= $minutes * 60;
1753 return sprintf($GLOBALS['timespanfmt'], (string)$days, (string)$hours, (string)$minutes, (string)$seconds);
1757 * Takes a string and outputs each character on a line for itself. Used
1758 * mainly for horizontalflipped display mode.
1759 * Takes care of special html-characters.
1760 * Fulfills todo-item
1761 * http://sf.net/tracker/?func=detail&aid=544361&group_id=23067&atid=377411
1763 * @todo add a multibyte safe function PMA_STR_split()
1764 * @uses strlen
1765 * @param string The string
1766 * @param string The Separator (defaults to "<br />\n")
1768 * @access public
1769 * @author Garvin Hicking <me@supergarv.de>
1770 * @return string The flipped string
1772 function PMA_flipstring($string, $Separator = "<br />\n")
1774 $format_string = '';
1775 $charbuff = false;
1777 for ($i = 0; $i < strlen($string); $i++) {
1778 $char = $string{$i};
1779 $append = false;
1781 if ($char == '&') {
1782 $format_string .= $charbuff;
1783 $charbuff = $char;
1784 $append = true;
1785 } elseif (!empty($charbuff)) {
1786 $charbuff .= $char;
1787 } elseif ($char == ';' && !empty($charbuff)) {
1788 $format_string .= $charbuff;
1789 $charbuff = false;
1790 $append = true;
1791 } else {
1792 $format_string .= $char;
1793 $append = true;
1796 if ($append && ($i != strlen($string))) {
1797 $format_string .= $Separator;
1801 return $format_string;
1806 * Function added to avoid path disclosures.
1807 * Called by each script that needs parameters, it displays
1808 * an error message and, by default, stops the execution.
1810 * Not sure we could use a strMissingParameter message here,
1811 * would have to check if the error message file is always available
1813 * @todo localize error message
1814 * @todo use PMA_fatalError() if $die === true?
1815 * @uses PMA_getenv()
1816 * @uses header_meta_style.inc.php
1817 * @uses $GLOBALS['PMA_PHP_SELF']
1818 * basename
1819 * @param array The names of the parameters needed by the calling
1820 * script.
1821 * @param boolean Stop the execution?
1822 * (Set this manually to false in the calling script
1823 * until you know all needed parameters to check).
1824 * @param boolean Whether to include this list in checking for special params.
1825 * @global string path to current script
1826 * @global boolean flag whether any special variable was required
1828 * @access public
1829 * @author Marc Delisle (lem9@users.sourceforge.net)
1831 function PMA_checkParameters($params, $die = true, $request = true)
1833 global $checked_special;
1835 if (!isset($checked_special)) {
1836 $checked_special = false;
1839 $reported_script_name = basename($GLOBALS['PMA_PHP_SELF']);
1840 $found_error = false;
1841 $error_message = '';
1843 foreach ($params as $param) {
1844 if ($request && $param != 'db' && $param != 'table') {
1845 $checked_special = true;
1848 if (!isset($GLOBALS[$param])) {
1849 $error_message .= $reported_script_name
1850 . ': Missing parameter: ' . $param
1851 . ' <a href="./Documentation.html#faqmissingparameters"'
1852 . ' target="documentation"> (FAQ 2.8)</a><br />';
1853 $found_error = true;
1856 if ($found_error) {
1858 * display html meta tags
1860 require_once './libraries/header_meta_style.inc.php';
1861 echo '</head><body><p>' . $error_message . '</p></body></html>';
1862 if ($die) {
1863 exit();
1866 } // end function
1869 * Function to generate unique condition for specified row.
1871 * @uses $GLOBALS['analyzed_sql'][0]
1872 * @uses PMA_DBI_field_flags()
1873 * @uses PMA_backquote()
1874 * @uses PMA_sqlAddslashes()
1875 * @uses stristr()
1876 * @uses bin2hex()
1877 * @uses preg_replace()
1878 * @param resource $handle current query result
1879 * @param integer $fields_cnt number of fields
1880 * @param array $fields_meta meta information about fields
1881 * @param array $row current row
1882 * @param boolean $force_unique generate condition only on pk or unique
1884 * @access public
1885 * @author Michal Cihar (michal@cihar.com) and others...
1886 * @return string calculated condition
1888 function PMA_getUniqueCondition($handle, $fields_cnt, $fields_meta, $row, $force_unique=false)
1890 $primary_key = '';
1891 $unique_key = '';
1892 $nonprimary_condition = '';
1893 $preferred_condition = '';
1895 for ($i = 0; $i < $fields_cnt; ++$i) {
1896 $condition = '';
1897 $field_flags = PMA_DBI_field_flags($handle, $i);
1898 $meta = $fields_meta[$i];
1900 // do not use a column alias in a condition
1901 if (! isset($meta->orgname) || ! strlen($meta->orgname)) {
1902 $meta->orgname = $meta->name;
1904 if (isset($GLOBALS['analyzed_sql'][0]['select_expr'])
1905 && is_array($GLOBALS['analyzed_sql'][0]['select_expr'])) {
1906 foreach ($GLOBALS['analyzed_sql'][0]['select_expr']
1907 as $select_expr) {
1908 // need (string) === (string)
1909 // '' !== 0 but '' == 0
1910 if ((string) $select_expr['alias'] === (string) $meta->name) {
1911 $meta->orgname = $select_expr['column'];
1912 break;
1913 } // end if
1914 } // end foreach
1918 // Do not use a table alias in a condition.
1919 // Test case is:
1920 // select * from galerie x WHERE
1921 //(select count(*) from galerie y where y.datum=x.datum)>1
1923 // But orgtable is present only with mysqli extension so the
1924 // fix is only for mysqli.
1925 if (isset($meta->orgtable) && $meta->table != $meta->orgtable) {
1926 $meta->table = $meta->orgtable;
1929 // to fix the bug where float fields (primary or not)
1930 // can't be matched because of the imprecision of
1931 // floating comparison, use CONCAT
1932 // (also, the syntax "CONCAT(field) IS NULL"
1933 // that we need on the next "if" will work)
1934 if ($meta->type == 'real') {
1935 $condition = ' CONCAT(' . PMA_backquote($meta->table) . '.'
1936 . PMA_backquote($meta->orgname) . ') ';
1937 } else {
1938 $condition = ' ' . PMA_backquote($meta->table) . '.'
1939 . PMA_backquote($meta->orgname) . ' ';
1940 } // end if... else...
1942 if (!isset($row[$i]) || is_null($row[$i])) {
1943 $condition .= 'IS NULL AND';
1944 } else {
1945 // timestamp is numeric on some MySQL 4.1
1946 if ($meta->numeric && $meta->type != 'timestamp') {
1947 $condition .= '= ' . $row[$i] . ' AND';
1948 } elseif ($meta->type == 'blob'
1949 // hexify only if this is a true not empty BLOB
1950 && stristr($field_flags, 'BINARY')
1951 && !empty($row[$i])) {
1952 // do not waste memory building a too big condition
1953 if (strlen($row[$i]) < 1000) {
1954 // use a CAST if possible, to avoid problems
1955 // if the field contains wildcard characters % or _
1956 $condition .= '= CAST(0x' . bin2hex($row[$i])
1957 . ' AS BINARY) AND';
1958 } else {
1959 // this blob won't be part of the final condition
1960 $condition = '';
1962 } else {
1963 $condition .= '= \''
1964 . PMA_sqlAddslashes($row[$i], false, true) . '\' AND';
1967 if ($meta->primary_key > 0) {
1968 $primary_key .= $condition;
1969 } elseif ($meta->unique_key > 0) {
1970 $unique_key .= $condition;
1972 $nonprimary_condition .= $condition;
1973 } // end for
1975 // Correction University of Virginia 19991216:
1976 // prefer primary or unique keys for condition,
1977 // but use conjunction of all values if no primary key
1978 if ($primary_key) {
1979 $preferred_condition = $primary_key;
1980 } elseif ($unique_key) {
1981 $preferred_condition = $unique_key;
1982 } elseif (! $force_unique) {
1983 $preferred_condition = $nonprimary_condition;
1986 return preg_replace('|\s?AND$|', '', $preferred_condition);
1987 } // end function
1990 * Generate a button or image tag
1992 * @uses PMA_USR_BROWSER_AGENT
1993 * @uses $GLOBALS['pmaThemeImage']
1994 * @uses $GLOBALS['cfg']['PropertiesIconic']
1995 * @param string name of button element
1996 * @param string class of button element
1997 * @param string name of image element
1998 * @param string text to display
1999 * @param string image to display
2001 * @access public
2002 * @author Michal Cihar (michal@cihar.com)
2004 function PMA_buttonOrImage($button_name, $button_class, $image_name, $text,
2005 $image)
2007 if (false === $GLOBALS['cfg']['PropertiesIconic']) {
2008 echo ' <input type="submit" name="' . $button_name . '"'
2009 .' value="' . htmlspecialchars($text) . '"'
2010 .' title="' . htmlspecialchars($text) . '" />' . "\n";
2011 return;
2014 /* Opera has trouble with <input type="image"> */
2015 /* IE has trouble with <button> */
2016 if (PMA_USR_BROWSER_AGENT != 'IE') {
2017 echo '<button class="' . $button_class . '" type="submit"'
2018 .' name="' . $button_name . '" value="' . htmlspecialchars($text) . '"'
2019 .' title="' . htmlspecialchars($text) . '">' . "\n"
2020 . PMA_getIcon($image, $text)
2021 .'</button>' . "\n";
2022 } else {
2023 echo '<input type="image" name="' . $image_name . '" value="'
2024 . htmlspecialchars($text) . '" title="' . htmlspecialchars($text) . '" src="' . $GLOBALS['pmaThemeImage']
2025 . $image . '" />'
2026 . ($GLOBALS['cfg']['PropertiesIconic'] === 'both' ? '&nbsp;' . htmlspecialchars($text) : '') . "\n";
2028 } // end function
2031 * Generate a pagination selector for browsing resultsets
2033 * @todo $url is not javascript escaped!?
2034 * @uses $GLOBALS['strPageNumber']
2035 * @uses range()
2036 * @param string URL for the JavaScript
2037 * @param string Number of rows in the pagination set
2038 * @param string current page number
2039 * @param string number of total pages
2040 * @param string If the number of pages is lower than this
2041 * variable, no pages will be ommitted in
2042 * pagination
2043 * @param string How many rows at the beginning should always
2044 * be shown?
2045 * @param string How many rows at the end should always
2046 * be shown?
2047 * @param string Percentage of calculation page offsets to
2048 * hop to a next page
2049 * @param string Near the current page, how many pages should
2050 * be considered "nearby" and displayed as
2051 * well?
2052 * @param string The prompt to display (sometimes empty)
2054 * @access public
2055 * @author Garvin Hicking (pma@supergarv.de)
2057 function PMA_pageselector($url, $rows, $pageNow = 1, $nbTotalPage = 1,
2058 $showAll = 200, $sliceStart = 5, $sliceEnd = 5, $percent = 20,
2059 $range = 10, $prompt = '')
2061 $gotopage = $prompt
2062 . ' <select name="pos" onchange="goToUrl(this, \''
2063 . $url . '\');">' . "\n";
2064 if ($nbTotalPage < $showAll) {
2065 $pages = range(1, $nbTotalPage);
2066 } else {
2067 $pages = array();
2069 // Always show first X pages
2070 for ($i = 1; $i <= $sliceStart; $i++) {
2071 $pages[] = $i;
2074 // Always show last X pages
2075 for ($i = $nbTotalPage - $sliceEnd; $i <= $nbTotalPage; $i++) {
2076 $pages[] = $i;
2079 // garvin: Based on the number of results we add the specified
2080 // $percent percentate to each page number,
2081 // so that we have a representing page number every now and then to
2082 // immideately jump to specific pages.
2083 // As soon as we get near our currently chosen page ($pageNow -
2084 // $range), every page number will be
2085 // shown.
2086 $i = $sliceStart;
2087 $x = $nbTotalPage - $sliceEnd;
2088 $met_boundary = false;
2089 while ($i <= $x) {
2090 if ($i >= ($pageNow - $range) && $i <= ($pageNow + $range)) {
2091 // If our pageselector comes near the current page, we use 1
2092 // counter increments
2093 $i++;
2094 $met_boundary = true;
2095 } else {
2096 // We add the percentate increment to our current page to
2097 // hop to the next one in range
2098 $i = $i + floor($nbTotalPage / $percent);
2100 // Make sure that we do not cross our boundaries.
2101 if ($i > ($pageNow - $range) && !$met_boundary) {
2102 $i = $pageNow - $range;
2106 if ($i > 0 && $i <= $x) {
2107 $pages[] = $i;
2111 // Since because of ellipsing of the current page some numbers may be double,
2112 // we unify our array:
2113 sort($pages);
2114 $pages = array_unique($pages);
2117 foreach ($pages as $i) {
2118 if ($i == $pageNow) {
2119 $selected = 'selected="selected" style="font-weight: bold"';
2120 } else {
2121 $selected = '';
2123 $gotopage .= ' <option ' . $selected . ' value="' . (($i - 1) * $rows) . '">' . $i . '</option>' . "\n";
2126 $gotopage .= ' </select><noscript><input type="submit" value="' . $GLOBALS['strGo'] . '" /></noscript>';
2128 return $gotopage;
2129 } // end function
2133 * Generate navigation for a list
2135 * @todo use $pos from $_url_params
2136 * @uses $GLOBALS['strPageNumber']
2137 * @uses range()
2138 * @param integer number of elements in the list
2139 * @param integer current position in the list
2140 * @param array url parameters
2141 * @param string script name for form target
2142 * @param string target frame
2143 * @param integer maximum number of elements to display from the list
2145 * @access public
2147 function PMA_listNavigator($count, $pos, $_url_params, $script, $frame, $max_count) {
2149 if ($max_count < $count) {
2150 echo 'frame_navigation' == $frame ? '<div id="navidbpageselector">' . "\n" : '';
2151 echo $GLOBALS['strPageNumber'];
2152 echo 'frame_navigation' == $frame ? '<br />' : ' ';
2154 // Move to the beginning or to the previous page
2155 if ($pos > 0) {
2156 // loic1: patch #474210 from Gosha Sakovich - part 1
2157 if ($GLOBALS['cfg']['NavigationBarIconic']) {
2158 $caption1 = '&lt;&lt;';
2159 $caption2 = ' &lt; ';
2160 $title1 = ' title="' . $GLOBALS['strPos1'] . '"';
2161 $title2 = ' title="' . $GLOBALS['strPrevious'] . '"';
2162 } else {
2163 $caption1 = $GLOBALS['strPos1'] . ' &lt;&lt;';
2164 $caption2 = $GLOBALS['strPrevious'] . ' &lt;';
2165 $title1 = '';
2166 $title2 = '';
2167 } // end if... else...
2168 $_url_params['pos'] = 0;
2169 echo '<a' . $title1 . ' href="' . $script
2170 . PMA_generate_common_url($_url_params) . '" target="' . $frame . '">'
2171 . $caption1 . '</a>';
2172 $_url_params['pos'] = $pos - $max_count;
2173 echo '<a' . $title2 . ' href="' . $script
2174 . PMA_generate_common_url($_url_params) . '" target="' . $frame . '">'
2175 . $caption2 . '</a>';
2178 echo "\n", '<form action="./', basename($script), '" method="post" target="', $frame, '">', "\n";
2179 echo PMA_generate_common_hidden_inputs($_url_params);
2180 echo PMA_pageselector(
2181 $script . PMA_generate_common_url($_url_params) . '&',
2182 $max_count,
2183 floor(($pos + 1) / $max_count) + 1,
2184 ceil($count / $max_count));
2185 echo '</form>';
2187 if ($pos + $max_count < $count) {
2188 if ($GLOBALS['cfg']['NavigationBarIconic']) {
2189 $caption3 = ' &gt; ';
2190 $caption4 = '&gt;&gt;';
2191 $title3 = ' title="' . $GLOBALS['strNext'] . '"';
2192 $title4 = ' title="' . $GLOBALS['strEnd'] . '"';
2193 } else {
2194 $caption3 = '&gt; ' . $GLOBALS['strNext'];
2195 $caption4 = '&gt;&gt; ' . $GLOBALS['strEnd'];
2196 $title3 = '';
2197 $title4 = '';
2198 } // end if... else...
2199 $_url_params['pos'] = $pos + $max_count;
2200 echo '<a' . $title3 . ' href="' . $script
2201 . PMA_generate_common_url($_url_params) . '" target="' . $frame . '">'
2202 . $caption3 . '</a>';
2203 $_url_params['pos'] = floor($count / $max_count) * $max_count;
2204 if ($_url_params['pos'] == $count) {
2205 $_url_params['pos'] = $count - $max_count;
2207 echo '<a' . $title4 . ' href="' . $script
2208 . PMA_generate_common_url($_url_params) . '" target="' . $frame . '">'
2209 . $caption4 . '</a>';
2211 echo "\n";
2212 if ('frame_navigation' == $frame) {
2213 echo '</div>' . "\n";
2219 * replaces %u in given path with current user name
2221 * example:
2222 * <code>
2223 * $user_dir = PMA_userDir('/var/pma_tmp/%u/'); // '/var/pma_tmp/root/'
2225 * </code>
2226 * @uses $cfg['Server']['user']
2227 * @uses substr()
2228 * @uses str_replace()
2229 * @param string $dir with wildcard for user
2230 * @return string per user directory
2232 function PMA_userDir($dir)
2234 // add trailing slash
2235 if (substr($dir, -1) != '/') {
2236 $dir .= '/';
2239 return str_replace('%u', $GLOBALS['cfg']['Server']['user'], $dir);
2243 * returns html code for db link to default db page
2245 * @uses $cfg['DefaultTabDatabase']
2246 * @uses $GLOBALS['db']
2247 * @uses $GLOBALS['strJumpToDB']
2248 * @uses PMA_generate_common_url()
2249 * @uses PMA_unescape_mysql_wildcards()
2250 * @uses strlen()
2251 * @uses sprintf()
2252 * @uses htmlspecialchars()
2253 * @param string $database
2254 * @return string html link to default db page
2256 function PMA_getDbLink($database = null)
2258 if (!strlen($database)) {
2259 if (!strlen($GLOBALS['db'])) {
2260 return '';
2262 $database = $GLOBALS['db'];
2263 } else {
2264 $database = PMA_unescape_mysql_wildcards($database);
2267 return '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . PMA_generate_common_url($database) . '"'
2268 .' title="' . sprintf($GLOBALS['strJumpToDB'], htmlspecialchars($database)) . '">'
2269 .htmlspecialchars($database) . '</a>';
2273 * Displays a lightbulb hint explaining a known external bug
2274 * that affects a functionality
2276 * @uses PMA_MYSQL_INT_VERSION
2277 * @uses $GLOBALS['strKnownExternalBug']
2278 * @uses PMA_showHint()
2279 * @uses sprintf()
2280 * @param string $functionality localized message explaining the func.
2281 * @param string $component 'mysql' (eventually, 'php')
2282 * @param string $minimum_version of this component
2283 * @param string $bugref bug reference for this component
2285 function PMA_externalBug($functionality, $component, $minimum_version, $bugref)
2287 if ($component == 'mysql' && PMA_MYSQL_INT_VERSION < $minimum_version) {
2288 echo PMA_showHint(sprintf($GLOBALS['strKnownExternalBug'], $functionality, 'http://bugs.mysql.com/' . $bugref));
2294 * Generates and echoes a set of radio HTML fields
2296 * @uses htmlspecialchars()
2297 * @param string $html_field_name the radio HTML field
2298 * @param array $choices the choices values and labels
2299 * @param string $checked_choice the choice to check by default
2300 * @param boolean $line_break whether to add an HTML line break after a choice
2301 * @param boolean $escape_label whether to use htmlspecialchars() on label
2302 * @param string $class enclose each choice with a div of this class
2304 function PMA_generate_html_radio($html_field_name, $choices, $checked_choice = '', $line_break = true, $escape_label = true, $class='') {
2305 foreach ($choices as $choice_value => $choice_label) {
2306 if (! empty($class)) {
2307 echo '<div class="' . $class . '">';
2309 $html_field_id = $html_field_name . '_' . $choice_value;
2310 echo '<input type="radio" name="' . $html_field_name . '" id="' . $html_field_id . '" value="' . htmlspecialchars($choice_value) . '"';
2311 if ($choice_value == $checked_choice) {
2312 echo ' checked="checked"';
2314 echo ' />' . "\n";
2315 echo '<label for="' . $html_field_id . '">' . ($escape_label ? htmlspecialchars($choice_label) : $choice_label) . '</label>';
2316 if ($line_break) {
2317 echo '<br />';
2319 if (! empty($class)) {
2320 echo '</div>';
2322 echo "\n";
2327 * Generates a slider effect (Mootools)
2329 * @uses $GLOBALS['cfg']['InitialSlidersState']
2330 * @param string $id the id of the <div> on which to apply the effect
2331 * @param string $message the message to show as a link
2333 function PMA_generate_slider_effect($id, $message)
2336 <script type="text/javascript">
2337 // <![CDATA[
2338 window.addEvent('domready', function(){
2339 var anchor<?php echo $id; ?> = new Element('a', {
2340 'id': 'toggle_<?php echo $id; ?>',
2341 'href': '#',
2342 'events': {
2343 'click': function(){
2344 mySlide<?php echo $id; ?>.toggle();
2348 anchor<?php echo $id; ?>.appendText('<?php echo $message; ?>');
2349 anchor<?php echo $id; ?>.injectBefore('<?php echo $id; ?>');
2351 var mySlide<?php echo $id; ?> = new Fx.Slide('<?php echo $id; ?>');
2352 <?php
2353 if ($GLOBALS['cfg']['InitialSlidersState'] == 'closed') {
2355 mySlide<?php echo $id; ?>.hide();
2356 <?php
2360 // ]]>
2361 </script>
2362 <?php
2366 * Cache information in the session
2368 * @param unknown_type $var
2369 * @param unknown_type $val
2370 * @param unknown_type $server
2371 * @return mixed
2373 function PMA_cacheExists($var, $server = 0)
2375 if (true === $server) {
2376 $server = $GLOBALS['server'];
2378 return isset($_SESSION['cache']['server_' . $server][$var]);
2382 * Cache information in the session
2384 * @param unknown_type $var
2385 * @param unknown_type $val
2386 * @param unknown_type $server
2387 * @return mixed
2389 function PMA_cacheGet($var, $server = 0)
2391 if (true === $server) {
2392 $server = $GLOBALS['server'];
2394 if (isset($_SESSION['cache']['server_' . $server][$var])) {
2395 return $_SESSION['cache']['server_' . $server][$var];
2396 } else {
2397 return null;
2402 * Cache information in the session
2404 * @param unknown_type $var
2405 * @param unknown_type $val
2406 * @param unknown_type $server
2407 * @return mixed
2409 function PMA_cacheSet($var, $val = null, $server = 0)
2411 if (true === $server) {
2412 $server = $GLOBALS['server'];
2414 $_SESSION['cache']['server_' . $server][$var] = $val;