tbl_move_copy
[phpmyadmin/crack.git] / libraries / common.lib.php3
blobc595d5555691c2639c66b3ff31909779086a989c
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 error_reporting(E_ALL);
6 /**
7 * Misc stuff and functions used by almost all the scripts.
8 * Among other things, it contains the advanced authentification work.
9 */
13 if (!defined('PMA_COMMON_LIB_INCLUDED')) {
14 define('PMA_COMMON_LIB_INCLUDED', 1);
16 /**
17 * Order of sections for common.lib.php3:
19 * in PHP3, functions and constants must be physically defined
20 * before they are referenced
22 * some functions need the constants of libraries/defines.lib.php3
23 * and defines_php.lib.php3
25 * the PMA_setFontSizes() function must be before the call to the
26 * libraries/auth/cookie.auth.lib.php3 library
28 * the include of libraries/defines.lib.php3 must be after the connection
29 * to db to get the MySql version
31 * the PMA_sqlAddslashes() function must be before the connection to db
33 * the authentication libraries must be before the connection to db but
34 * after the PMA_isInto() function
36 * the PMA_mysqlDie() function must be before the connection to db but
37 * after mysql extension has been loaded
39 * the PMA_mysqlDie() function needs the PMA_format_sql() Function
41 * ... so the required order is:
43 * - parsing of the configuration file
44 * - first load of the libraries/define.lib.php3 library (won't get the
45 * MySQL release number)
46 * - load of mysql extension (if necessary)
47 * - definition of PMA_sqlAddslashes()
48 * - definition of PMA_format_sql()
49 * - definition of PMA_mysqlDie()
50 * - definition of PMA_isInto()
51 * - definition of PMA_setFontSizes()
52 * - loading of an authentication library
53 * - db connection
54 * - authentication work
55 * - second load of the libraries/define.lib.php3 library to get the MySQL
56 * release number)
57 * - other functions, respecting dependencies
61 /**
62 * Avoids undefined variables in PHP3
64 if (!isset($use_backquotes)) {
65 $use_backquotes = 0;
67 if (!isset($pos)) {
68 $pos = 0;
71 /**
72 * Detects the config file we want to load
74 if (file_exists('./config.inc.developer.php3')) {
75 $cfgfile_to_load = './config.inc.developer.php3';
76 } else {
77 $cfgfile_to_load = './config.inc.php3';
80 /**
81 * Parses the configuration file and gets some constants used to define
82 * versions of phpMyAdmin/php/mysql...
84 $old_error_reporting = error_reporting(0);
85 include($cfgfile_to_load);
86 // Include failed
87 if (!isset($cfgServers) && !isset($cfg['Servers'])) {
88 // Creates fake settings
89 $cfg = array('DefaultLang' => 'en-iso-8859-1',
90 'AllowAnywhereRecoding' => FALSE);
91 // Loads the language file
92 include('./libraries/select_lang.lib.php3');
93 // Sends the Content-Type header
94 header('Content-Type: text/html; charset=' . $charset);
95 // Displays the error message
97 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
98 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
99 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $available_languages[$lang][2]; ?>" lang="<?php echo $available_languages[$lang][2]; ?>" dir="<?php echo $text_dir; ?>">
101 <head>
102 <title>phpMyAdmin</title>
103 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>" />
104 <style type="text/css">
105 <!--
106 body {font-family: sans-serif; font-size: small; color: #000000; background-color: #F5F5F5}
107 h1 {font-family: sans-serif; font-size: large; font-weight: bold}
108 //-->
109 </style>
110 </head>
113 <body bgcolor="#ffffff">
114 <h1>phpMyAdmin - <?php echo $strError; ?></h1>
116 <?php echo $strConfigFileError; ?><br /><br />
117 <a href="config.inc.php3" target="_blank">config.inc.php3</a>
118 </p>
119 </body>
121 </html>
122 <?php
123 exit();
125 error_reporting($old_error_reporting);
126 unset($old_error_reporting);
127 unset($cfgfile_to_load);
130 * Includes compatibility code for older config.inc.php3 revisions
131 * if necessary
133 if (!isset($cfg['FileRevision']) || (int) substr($cfg['FileRevision'], 13, 3) < 144) {
134 include('./libraries/config_import.lib.php3');
138 * Includes the language file if it hasn't been included yet
140 if (!defined('PMA_SELECT_LANG_LIB_INCLUDED')) {
141 include('./libraries/select_lang.lib.php3');
145 * Include MySQL wrappers.
147 include('./libraries/mysql_wrappers.lib.php3');
150 * Gets constants that defines the PHP version number.
151 * This include must be located physically before any code that needs to
152 * reference the constants, else PHP 3.0.16 won't be happy.
154 include('./libraries/defines_php.lib.php3');
157 * Charset conversion.
159 include('./libraries/charset_conversion.lib.php3');
162 * Gets constants that defines the MySQL version number.
163 * This include must be located physically before any code that needs to
164 * reference the constants, else PHP 3.0.16 won't be happy; and must be
165 * located after we are connected to db to get the MySql version (see
166 * below).
168 include('./libraries/defines.lib.php3');
171 * String handling
173 include('./libraries/string.lib.php3');
176 * SQL Parser data and code
178 include('./libraries/sqlparser.data.php3');
179 include('./libraries/sqlparser.lib.php3');
182 * SQL Validator interface code
184 include('./libraries/sqlvalidator.lib.php3');
186 // If zlib output compression is set in the php configuration file, no
187 // output buffering should be run
188 if (PMA_PHP_INT_VERSION < 40000
189 || (PMA_PHP_INT_VERSION >= 40005 && @ini_get('zlib.output_compression'))) {
190 $cfg['OBGzip'] = FALSE;
194 * Include URL/hidden inputs generating.
196 include('./libraries/url_generating.lib.php3');
200 * Loads the mysql extensions if it is not loaded yet
201 * staybyte - 26. June 2001
203 if (((PMA_PHP_INT_VERSION >= 40000 && !@ini_get('safe_mode') && @ini_get('enable_dl'))
204 || (PMA_PHP_INT_VERSION < 40000 && PMA_PHP_INT_VERSION > 30009 && !@get_cfg_var('safe_mode')))
205 && @function_exists('dl')) {
206 if (PMA_PHP_INT_VERSION < 40000) {
207 $extension = 'MySQL';
208 } else {
209 $extension = 'mysql';
211 if (PMA_IS_WINDOWS) {
212 $suffix = '.dll';
213 } else {
214 $suffix = '.so';
216 if (!@extension_loaded($extension)) {
217 @dl($extension . $suffix);
219 if (!@extension_loaded($extension)) {
220 echo $strCantLoadMySQL . '<br />' . "\n"
221 . '<a href="./Documentation.html#faqmysql" target="documentation">' . $GLOBALS['strDocu'] . '</a>' . "\n";
222 exit();
224 } // end load mysql extension
226 // check whether mysql is available
227 if (!@function_exists('mysql_connect')) {
228 echo $strCantLoadMySQL . '<br />' . "\n"
229 . '<a href="./Documentation.html#faqmysql" target="documentation">' . $GLOBALS['strDocu'] . '</a>' . "\n";
230 exit();
236 * Add slashes before "'" and "\" characters so a value containing them can
237 * be used in a sql comparison.
239 * @param string the string to slash
240 * @param boolean whether the string will be used in a 'LIKE' clause
241 * (it then requires two more escaped sequences) or not
243 * @return string the slashed string
245 * @access public
247 function PMA_sqlAddslashes($a_string = '', $is_like = FALSE)
249 if ($is_like) {
250 $a_string = str_replace('\\', '\\\\\\\\', $a_string);
251 } else {
252 $a_string = str_replace('\\', '\\\\', $a_string);
254 $a_string = str_replace('\'', '\\\'', $a_string);
256 return $a_string;
257 } // end of the 'PMA_sqlAddslashes()' function
261 * format sql strings
263 * @param mixed pre-parsed SQL structure
265 * @return string the formatted sql
267 * @global array the configuration array
268 * @global boolean whether the current statement is a multiple one or not
270 * @access public
272 * @author Robin Johnson <robbat2@users.sourceforge.net>
274 function PMA_formatSql($parsed_sql)
276 global $cfg;
278 // Check that we actually have a valid set of parsed data
279 // well, not quite
280 // first check for the SQL parser having hit an error
281 if (PMA_SQP_isError()) {
282 return $parsed_sql;
284 // then check for an array
285 if (!is_array($parsed_sql)) {
286 // We don't so just return the input directly
287 // This is intended to be used for when the SQL Parser is turned off
288 $formatted_sql = '<pre>' . "\n"
289 . $parsed_sql . "\n"
290 . '</pre>';
291 return $formatted_sql;
294 $formatted_sql = '';
296 switch ($cfg['SQP']['fmtType']) {
297 case 'none':
298 $formatted_sql = PMA_SQP_formatNone($parsed_sql);
299 break;
300 case 'html':
301 $formatted_sql = PMA_SQP_formatHtml($parsed_sql,'color');
302 break;
303 case 'text':
304 //$formatted_sql = PMA_SQP_formatText($parsed_sql);
305 $formatted_sql = PMA_SQP_formatHtml($parsed_sql,'text');
306 break;
307 default:
308 break;
309 } // end switch
311 return $formatted_sql;
312 } // end of the "PMA_formatSql()" function
316 * Displays a MySQL error message in the right frame.
318 * @param string the error mesage
319 * @param string the sql query that failed
320 * @param boolean whether to show a "modify" link or not
321 * @param string the "back" link url (full path is not required)
323 * @global array the configuration array
325 * @access public
327 function PMA_mysqlDie($error_message = '', $the_query = '',
328 $is_modify_link = TRUE, $back_url = '')
330 global $cfg;
332 if (empty($GLOBALS['is_header_sent'])) {
333 include('./header.inc.php3');
336 if (!$error_message) {
337 $error_message = PMA_mysql_error();
339 if (!$the_query && !empty($GLOBALS['sql_query'])) {
340 $the_query = $GLOBALS['sql_query'];
343 // --- Added to solve bug #641765
344 // Robbat2 - 12 January 2003, 9:46PM
345 // Revised, Robbat2 - 13 Janurary 2003, 2:59PM
346 if (PMA_SQP_isError()) {
347 $parsed_sql = $the_query;
348 } else {
349 $parsed_sql = PMA_SQP_parse($the_query);
351 // ---
353 echo '<p><b>'. $GLOBALS['strError'] . '</b></p>' . "\n";
354 // if the config password is wrong, or the MySQL server does not
355 // respond, do not show the query that would reveal the
356 // username/password
357 if (!empty($the_query) && !strstr($the_query, 'connect')) {
358 // --- Added to solve bug #641765
359 // Robbat2 - 12 January 2003, 9:46PM
360 // Revised, Robbat2 - 13 Janurary 2003, 2:59PM
361 if (PMA_SQP_isError()) {
362 echo PMA_SQP_getErrorString();
364 // ---
365 echo '<p>' . "\n";
366 echo ' ' . $GLOBALS['strSQLQuery'] . '&nbsp;:&nbsp;' . "\n";
367 if ($is_modify_link && isset($db)) {
368 echo ' ['
369 . '<a href="db_details.php3?' . PMA_generate_common_url($GLOBALS['db']) . '&amp;sql_query=' . urlencode($the_query) . '&amp;show_query=1">' . $GLOBALS['strEdit'] . '</a>'
370 . ']' . "\n";
371 } // end if
372 echo '</p>' . "\n"
373 . '<p>' . "\n"
374 . ' ' . PMA_formatSql($parsed_sql) . "\n"
375 . '</p>' . "\n";
376 } // end if
377 if (!empty($error_message)) {
378 $error_message = htmlspecialchars($error_message);
379 $error_message = ereg_replace("((\015\012)|(\015)|(\012)){3,}", "\n\n", $error_message);
381 echo '<p>' . "\n"
382 . ' ' . $GLOBALS['strMySQLSaid'] . '<br />' . "\n"
383 . '</p>' . "\n";
384 echo '<pre>' . "\n"
385 . $error_message . "\n"
386 . '</pre>' . "\n";
389 if (!empty($back_url)) {
390 echo '<a href="' . $back_url . '">' . $GLOBALS['strBack'] . '</a>';
392 echo "\n";
394 include('./footer.inc.php3');
395 exit();
396 } // end of the 'PMA_mysqlDie()' function
400 * Defines whether a string exists inside an array or not
402 * @param string string to search for
403 * @param mixed array to search into
405 * @return integer the rank of the $toFind string in the array or '-1' if
406 * it hasn't been found
408 * @access public
410 function PMA_isInto($toFind = '', &$in)
412 $max = count($in);
413 for ($i = 0; $i < $max && ($toFind != $in[$i]); $i++) {
414 // void();
417 return ($i < $max) ? $i : -1;
418 } // end of the 'PMA_isInto()' function
422 * Determines the font sizes to use depending on the os and browser of the
423 * user.
425 * This function is based on an article from phpBuilder (see
426 * http://www.phpbuilder.net/columns/tim20000821.php3).
428 * @return boolean always true
430 * @global string the standard font size
431 * @global string the font size for titles
432 * @global string the small font size
433 * @global string the smallest font size
435 * @access public
437 * @version 1.1
439 function PMA_setFontSizes()
441 global $font_size, $font_biggest, $font_bigger, $font_smaller, $font_smallest;
443 // IE (<6)/Opera for win case: needs smaller fonts than anyone else
444 if (PMA_USR_OS == 'Win'
445 && ((PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 6) || PMA_USR_BROWSER_AGENT == 'OPERA')) {
446 $font_size = 'x-small';
447 $font_biggest = 'large';
448 $font_bigger = 'medium';
449 $font_smaller = '90%';
450 $font_smallest = '7pt';
452 // IE6 and other browsers for win case
453 else if (PMA_USR_OS == 'Win') {
454 $font_size = 'small';
455 $font_biggest = 'large';
456 $font_bigger = 'medium';
457 $font_smaller = (PMA_USR_BROWSER_AGENT == 'IE')
458 ? '90%'
459 : 'x-small';
460 $font_smallest = 'x-small';
462 // Some mac browsers need also smaller default fonts size (OmniWeb &
463 // Opera)...
464 else if (PMA_USR_OS == 'Mac'
465 && (PMA_USR_BROWSER_AGENT == 'OMNIWEB' || PMA_USR_BROWSER_AGENT == 'OPERA')) {
466 $font_size = 'x-small';
467 $font_biggest = 'large';
468 $font_bigger = 'medium';
469 $font_smaller = '90%';
470 $font_smallest = '7pt';
472 // ... but most of them (except IE 5+ & NS 6+) need bigger fonts
473 else if (PMA_USR_OS == 'Mac'
474 && ((PMA_USR_BROWSER_AGENT != 'IE' && PMA_USR_BROWSER_AGENT != 'MOZILLA')
475 || PMA_USR_BROWSER_VER < 5)) {
476 $font_size = 'medium';
477 $font_biggest = 'x-large';
478 $font_bigger = 'large';
479 $font_smaller = 'small';
480 $font_smallest = 'x-small';
482 // OS/2 browser
483 else if (PMA_USR_OS == 'OS/2'
484 && PMA_USR_BROWSER_AGENT == 'OPERA') {
485 $font_size = 'small';
486 $font_biggest = 'medium';
487 $font_bigger = 'medium';
488 $font_smaller = 'x-small';
489 $font_smallest = 'x-small';
491 else {
492 $font_size = 'small';
493 $font_biggest = 'large';
494 $font_bigger = 'medium';
495 $font_smaller = 'x-small';
496 $font_smallest = 'x-small';
499 return TRUE;
500 } // end of the 'PMA_setFontSizes()' function
504 * $cfg['PmaAbsoluteUri'] is a required directive else cookies won't be
505 * set properly and, depending on browsers, inserting or updating a
506 * record might fail
508 $display_pmaAbsoluteUri_warning = 0;
510 // Olivier: Setup a default value to let the people and lazy syadmins
511 // work anyway, but display a big warning on the main.php3
512 // page.
513 if (empty($cfg['PmaAbsoluteUri'])) {
514 $port_in_HTTP_HOST = (strpos($HTTP_SERVER_VARS['HTTP_HOST'], ':') > 0);
515 $cfg['PmaAbsoluteUri'] = ((!empty($HTTP_SERVER_VARS['HTTPS']) && strtolower($HTTP_SERVER_VARS['HTTPS']) != 'off') ? 'https' : 'http') . '://'
516 . $HTTP_SERVER_VARS['HTTP_HOST']
517 . ((!empty($HTTP_SERVER_VARS['SERVER_PORT']) && !$port_in_HTTP_HOST) ? ':' . $HTTP_SERVER_VARS['SERVER_PORT'] : '')
518 . substr($PHP_SELF, 0, strrpos($PHP_SELF, '/') + 1);
519 // We display the warning by default, but not if it is disabled thru
520 // via the $cfg['PmaAbsoluteUri_DisableWarning'] variable.
521 // This is intended for sysadmins that actually want the default
522 // behaviour of auto-detection due to their setup.
523 // See the mailing list message:
524 // http://sourceforge.net/mailarchive/forum.php?thread_id=859093&forum_id=2141
525 if ($cfg['PmaAbsoluteUri_DisableWarning'] == FALSE) {
526 $display_pmaAbsoluteUri_warning = 1;
529 // Adds a trailing slash et the end of the phpMyAdmin uri if it does not
530 // exist
531 else if (substr($cfg['PmaAbsoluteUri'], -1) != '/') {
532 $cfg['PmaAbsoluteUri'] .= '/';
537 * Make sure $cfg['DefaultTabDatabase'] and $cfg['DefaultTabTable'] are set.
538 * Todo: check if it is set to a *valid* value.
540 if (empty($cfg['DefaultTabDatabase'])) {
541 $cfg['DefaultTabDatabase'] = 'db_details_structure.php3';
544 if (empty($cfg['DefaultTabTable'])) {
545 $cfg['DefaultTabTable'] = 'tbl_properties_structure.php3';
550 * Use mysql_connect() or mysql_pconnect()?
552 $connect_func = ($cfg['PersistentConnections']) ? 'mysql_pconnect' : 'mysql_connect';
553 $dblist = array();
557 * Gets the valid servers list and parameters
559 reset($cfg['Servers']);
560 while (list($key, $val) = each($cfg['Servers'])) {
561 // Don't use servers with no hostname
562 if ( ($val['connect_type'] == 'tcp') && empty($val['host']) ) {
563 unset($cfg['Servers'][$key]);
566 // Final solution to bug #582890
567 // If we are using a socket connection
568 // and there is nothing in the verbose server name
569 // or the host field, then generate a name for the server
570 // in the form of "Server 2", localized of course!
571 if ( ($val['connect_type'] == 'socket') && empty($val['host']) && empty($val['verbose']) ) {
572 $cfg['Servers'][$key]['verbose'] = sprintf($GLOBALS['strServer'], $key);
573 $val['verbose'] = sprintf($GLOBALS['strServer'],$key);
577 if (empty($server) || !isset($cfg['Servers'][$server]) || !is_array($cfg['Servers'][$server])) {
578 $server = $cfg['ServerDefault'];
583 * If no server is selected, make sure that $cfg['Server'] is empty (so
584 * that nothing will work), and skip server authentication.
585 * We do NOT exit here, but continue on without logging into any server.
586 * This way, the welcome page will still come up (with no server info) and
587 * present a choice of servers in the case that there are multiple servers
588 * and '$cfg['ServerDefault'] = 0' is set.
590 if ($server == 0) {
591 $cfg['Server'] = array();
595 * Otherwise, set up $cfg['Server'] and do the usual login stuff.
597 else if (isset($cfg['Servers'][$server])) {
598 $cfg['Server'] = $cfg['Servers'][$server];
600 // Check how the config says to connect to the server
601 $server_port = (empty($cfg['Server']['port']))
602 ? ''
603 : ':' . $cfg['Server']['port'];
604 if (strtolower($cfg['Server']['connect_type']) == 'tcp') {
605 $cfg['Server']['socket'] = '';
607 $server_socket = (empty($cfg['Server']['socket']) || PMA_PHP_INT_VERSION < 30010)
608 ? ''
609 : ':' . $cfg['Server']['socket'];
611 // Gets the authentication library that fits the $cfg['Server'] settings
612 // and run authentication
613 include('./libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php3');
614 if (!PMA_auth_check()) {
615 PMA_auth();
616 } else {
617 PMA_auth_set_user();
620 // Check IP-based Allow/Deny rules as soon as possible to reject the
621 // user
622 // Based on mod_access in Apache:
623 // http://cvs.apache.org/viewcvs.cgi/httpd-2.0/modules/aaa/mod_access.c?rev=1.37&content-type=text/vnd.viewcvs-markup
624 // Look at: "static int check_dir_access(request_rec *r)"
625 // Robbat2 - May 10, 2002
626 if (isset($cfg['Server']['AllowDeny']) && $cfg['Server']['AllowDeny']['order']) {
627 include('./libraries/ip_allow_deny.lib.php3');
629 $allowDeny_forbidden = FALSE; // default
630 if ($cfg['Server']['AllowDeny']['order'] == 'allow,deny') {
631 $allowDeny_forbidden = TRUE;
632 if (PMA_allowDeny('allow')) {
633 $allowDeny_forbidden = FALSE;
635 if (PMA_allowDeny('deny')) {
636 $allowDeny_forbidden = TRUE;
638 } else if ($cfg['Server']['AllowDeny']['order'] == 'deny,allow') {
639 if (PMA_allowDeny('deny')) {
640 $allowDeny_forbidden = TRUE;
642 if (PMA_allowDeny('allow')) {
643 $allowDeny_forbidden = FALSE;
645 } else if ($cfg['Server']['AllowDeny']['order'] == 'explicit') {
646 if (PMA_allowDeny('allow')
647 && !PMA_allowDeny('deny')) {
648 $allowDeny_forbidden = FALSE;
649 } else {
650 $allowDeny_forbidden = TRUE;
652 } // end if... else if... else if
654 // Ejects the user if banished
655 if ($allowDeny_forbidden) {
656 PMA_auth_fails();
658 unset($allowDeny_forbidden); //Clean up after you!
659 } // end if
661 // The user can work with only some databases
662 if (isset($cfg['Server']['only_db']) && $cfg['Server']['only_db'] != '') {
663 if (is_array($cfg['Server']['only_db'])) {
664 $dblist = $cfg['Server']['only_db'];
665 } else {
666 $dblist[] = $cfg['Server']['only_db'];
668 } // end if
670 if (PMA_PHP_INT_VERSION >= 40000) {
671 $bkp_track_err = @ini_set('track_errors', 1);
674 // Try to connect MySQL with the control user profile (will be used to
675 // get the privileges list for the current user but the true user link
676 // must be open after this one so it would be default one for all the
677 // scripts)
678 if ($cfg['Server']['controluser'] != '') {
679 $dbh = @$connect_func(
680 $cfg['Server']['host'] . $server_port . $server_socket,
681 $cfg['Server']['controluser'],
682 $cfg['Server']['controlpass']
684 if ($dbh == FALSE) {
685 if (PMA_mysql_error()) {
686 $conn_error = PMA_mysql_error();
687 } else if (isset($php_errormsg)) {
688 $conn_error = $php_errormsg;
689 } else {
690 $conn_error = 'Cannot connect: invalid settings.';
692 $local_query = $connect_func . '('
693 . $cfg['Server']['host'] . $server_port . $server_socket . ', '
694 . $cfg['Server']['controluser'] . ', '
695 . $cfg['Server']['controlpass'] . ')';
696 if (empty($GLOBALS['is_header_sent'])) {
697 include('./header.inc.php3');
699 //PMA_mysqlDie($conn_error, $local_query, FALSE);
700 PMA_mysqlDie($conn_error, '', FALSE);
701 } // end if
702 } // end if
704 // Pass #1 of DB-Config to read in master level DB-Config will go here
705 // Robbat2 - May 11, 2002
707 // Connects to the server (validates user's login)
708 $userlink = @$connect_func(
709 $cfg['Server']['host'] . $server_port . $server_socket,
710 $cfg['Server']['user'],
711 $cfg['Server']['password']
713 if ($userlink == FALSE) {
714 PMA_auth_fails();
715 } // end if
717 // Pass #2 of DB-Config to read in user level DB-Config will go here
718 // Robbat2 - May 11, 2002
720 if (PMA_PHP_INT_VERSION >= 40000) {
721 @ini_set('track_errors', $bkp_track_err);
724 // If controluser isn't defined, use the current user settings to get
725 // his rights
726 if ($cfg['Server']['controluser'] == '') {
727 $dbh = $userlink;
730 // Runs the "defines.lib.php3" for the second time to get the mysql
731 // release number
732 include('./libraries/defines.lib.php3');
734 // if 'only_db' is set for the current user, there is no need to check for
735 // available databases in the "mysql" db
736 $dblist_cnt = count($dblist);
737 if ($dblist_cnt) {
738 $true_dblist = array();
739 $is_show_dbs = TRUE;
740 for ($i = 0; $i < $dblist_cnt; $i++) {
741 if ($is_show_dbs && ereg('(^|[^\])(_|%)', $dblist[$i])) {
742 $local_query = 'SHOW DATABASES LIKE \'' . $dblist[$i] . '\'';
743 $rs = PMA_mysql_query($local_query, $dbh);
744 // "SHOW DATABASES" statement is disabled
745 if ($i == 0
746 && (PMA_mysql_error() && mysql_errno() == 1045)) {
747 $true_dblist[] = str_replace('\\_', '_', str_replace('\\%', '%', $dblist[$i]));
748 $is_show_dbs = FALSE;
750 // Debug
751 // else if (PMA_mysql_error()) {
752 // PMA_mysqlDie('', $local_query, FALSE);
753 // }
754 while ($row = @PMA_mysql_fetch_row($rs)) {
755 $true_dblist[] = $row[0];
756 } // end while
757 if ($rs) {
758 mysql_free_result($rs);
760 } else {
761 $true_dblist[] = str_replace('\\_', '_', str_replace('\\%', '%', $dblist[$i]));
762 } // end if... else...
763 } // end for
764 $dblist = $true_dblist;
765 unset($true_dblist);
766 } // end if
768 // 'only_db' is empty for the current user...
769 else {
770 // ... first checks whether the "safe_show_database" is on or not
771 // (if MYSQL supports this)
772 if (PMA_MYSQL_INT_VERSION >= 32330) {
773 $local_query = 'SHOW VARIABLES LIKE \'safe_show_database\'';
774 $rs = PMA_mysql_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE);
775 $is_safe_show_dbs = ($rs) ? @PMA_mysql_result($rs, 0, 'Value') : FALSE;
777 // ... and if on, try to get the available dbs list
778 if ($is_safe_show_dbs && strtoupper($is_safe_show_dbs) != 'OFF') {
779 $uva_alldbs = mysql_list_dbs($userlink);
780 while ($uva_row = PMA_mysql_fetch_array($uva_alldbs)) {
781 $dblist[] = $uva_row[0];
782 } // end while
783 $dblist_cnt = count($dblist);
784 unset($uva_alldbs);
785 mysql_free_result($rs);
786 } // end if ($is_safe_show_dbs)
787 } //end if (PMA_MYSQL_INT_VERSION)
789 // ... else checks for available databases in the "mysql" db
790 if (!$dblist_cnt) {
791 $auth_query = 'SELECT User, Select_priv '
792 . 'FROM mysql.user '
793 . 'WHERE User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\'';
794 $rs = PMA_mysql_query($auth_query, $dbh); // Debug: or PMA_mysqlDie('', $auth_query, FALSE);
795 } // end
796 } // end if (!$dblist_cnt)
798 // Access to "mysql" db allowed and dblist still empty -> gets the
799 // usable db list
800 if (!$dblist_cnt
801 && ($rs && @mysql_numrows($rs))) {
802 $row = PMA_mysql_fetch_array($rs);
803 mysql_free_result($rs);
804 // Correction uva 19991215
805 // Previous code assumed database "mysql" admin table "db" column
806 // "db" contains literal name of user database, and works if so.
807 // Mysql usage generally (and uva usage specifically) allows this
808 // column to contain regular expressions (we have all databases
809 // owned by a given student/faculty/staff beginning with user i.d.
810 // and governed by default by a single set of privileges with
811 // regular expression as key). This breaks previous code.
812 // This maintenance is to fix code to work correctly for regular
813 // expressions.
814 if ($row['Select_priv'] != 'Y') {
816 // 1. get allowed dbs from the "mysql.db" table
817 // lem9: User can be blank (anonymous user)
818 $local_query = 'SELECT DISTINCT Db FROM mysql.db WHERE Select_priv = \'Y\' AND (User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\' OR User = \'\')';
819 $rs = PMA_mysql_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE);
820 if ($rs && @mysql_numrows($rs)) {
821 // Will use as associative array of the following 2 code
822 // lines:
823 // the 1st is the only line intact from before
824 // correction,
825 // the 2nd replaces $dblist[] = $row['Db'];
826 $uva_mydbs = array();
827 // Code following those 2 lines in correction continues
828 // populating $dblist[], as previous code did. But it is
829 // now populated with actual database names instead of
830 // with regular expressions.
831 while ($row = PMA_mysql_fetch_array($rs)) {
832 // loic1: all databases cases - part 1
833 if (empty($row['Db']) || $row['Db'] == '%') {
834 $uva_mydbs['%'] = 1;
835 break;
837 // loic1: avoid multiple entries for dbs
838 if (!isset($uva_mydbs[$row['Db']])) {
839 $uva_mydbs[$row['Db']] = 1;
841 } // end while
842 mysql_free_result($rs);
843 $uva_alldbs = mysql_list_dbs($dbh);
844 // loic1: all databases cases - part 2
845 if (isset($uva_mydbs['%'])) {
846 while ($uva_row = PMA_mysql_fetch_array($uva_alldbs)) {
847 $dblist[] = $uva_row[0];
848 } // end while
849 } // end if
850 else {
851 while ($uva_row = PMA_mysql_fetch_array($uva_alldbs)) {
852 $uva_db = $uva_row[0];
853 if (isset($uva_mydbs[$uva_db]) && $uva_mydbs[$uva_db] == 1) {
854 $dblist[] = $uva_db;
855 $uva_mydbs[$uva_db] = 0;
856 } else if (!isset($dblist[$uva_db])) {
857 reset($uva_mydbs);
858 while (list($uva_matchpattern, $uva_value) = each($uva_mydbs)) {
859 // loic1: fixed bad regexp
860 // TODO: db names may contain characters
861 // that are regexp instructions
862 $re = '(^|(\\\\\\\\)+|[^\])';
863 $uva_regex = ereg_replace($re . '%', '\\1.*', ereg_replace($re . '_', '\\1.{1}', $uva_matchpattern));
864 // Fixed db name matching
865 // 2000-08-28 -- Benjamin Gandon
866 if (ereg('^' . $uva_regex . '$', $uva_db)) {
867 $dblist[] = $uva_db;
868 break;
870 } // end while
871 } // end if ... else if....
872 } // end while
873 } // end else
874 mysql_free_result($uva_alldbs);
875 unset($uva_mydbs);
876 } // end if
878 // 2. get allowed dbs from the "mysql.tables_priv" table
879 $local_query = 'SELECT DISTINCT Db FROM mysql.tables_priv WHERE Table_priv LIKE \'%Select%\' AND User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\'';
880 $rs = PMA_mysql_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE);
881 if ($rs && @mysql_numrows($rs)) {
882 while ($row = PMA_mysql_fetch_array($rs)) {
883 if (PMA_isInto($row['Db'], $dblist) == -1) {
884 $dblist[] = $row['Db'];
886 } // end while
887 mysql_free_result($rs);
888 } // end if
889 } // end if
890 } // end building available dbs from the "mysql" db
892 } // end server connecting
895 * Missing server hostname
897 else {
898 echo $strHostEmpty;
903 * Get the list and number of available databases.
905 * @param string the url to go back to in case of error
907 * @return boolean always true
909 * @global array the list of available databases
910 * @global integer the number of available databases
912 function PMA_availableDatabases($error_url = '')
914 global $dblist;
915 global $num_dbs;
917 $num_dbs = count($dblist);
919 // 1. A list of allowed databases has already been defined by the
920 // authentification process -> gets the available databases list
921 if ($num_dbs) {
922 $true_dblist = array();
923 for ($i = 0; $i < $num_dbs; $i++) {
924 $dblink = @PMA_mysql_select_db($dblist[$i]);
925 if ($dblink) {
926 $true_dblist[] = $dblist[$i];
927 } // end if
928 } // end for
929 $dblist = array();
930 $dblist = $true_dblist;
931 unset($true_dblist);
932 $num_dbs = count($dblist);
933 } // end if
935 // 2. Allowed database list is empty -> gets the list of all databases
936 // on the server
937 else {
938 $dbs = mysql_list_dbs() or PMA_mysqlDie('', 'mysql_list_dbs()', FALSE, $error_url);
939 $num_dbs = ($dbs) ? @mysql_num_rows($dbs) : 0;
940 $real_num_dbs = 0;
941 for ($i = 0; $i < $num_dbs; $i++) {
942 $db_name_tmp = PMA_mysql_dbname($dbs, $i);
943 $dblink = @PMA_mysql_select_db($db_name_tmp);
944 if ($dblink) {
945 $dblist[] = $db_name_tmp;
946 $real_num_dbs++;
948 } // end for
949 mysql_free_result($dbs);
950 $num_dbs = $real_num_dbs;
951 } // end else
953 return TRUE;
954 } // end of the 'PMA_availableDatabases()' function
958 /* ----------------------- Set of misc functions ----------------------- */
962 * Adds backquotes on both sides of a database, table or field name.
963 * Since MySQL 3.23.6 this allows to use non-alphanumeric characters in
964 * these names.
966 * @param mixed the database, table or field name to "backquote" or
967 * array of it
968 * @param boolean a flag to bypass this function (used by dump
969 * functions)
971 * @return mixed the "backquoted" database, table or field name if the
972 * current MySQL release is >= 3.23.6, the original one
973 * else
975 * @access public
977 function PMA_backquote($a_name, $do_it = TRUE)
979 if ($do_it
980 && PMA_MYSQL_INT_VERSION >= 32306
981 && !empty($a_name) && $a_name != '*') {
983 if (is_array($a_name)) {
984 $result = array();
985 reset($a_name);
986 while(list($key, $val) = each($a_name)) {
987 $result[$key] = '`' . $val . '`';
989 return $result;
990 } else {
991 return '`' . $a_name . '`';
993 } else {
994 return $a_name;
996 } // end of the 'PMA_backquote()' function
1000 * Format a string so it can be passed to a javascript function.
1001 * This function is used to displays a javascript confirmation box for
1002 * "DROP/DELETE/ALTER" queries.
1004 * @param string the string to format
1005 * @param boolean whether to add backquotes to the string or not
1007 * @return string the formated string
1009 * @access public
1011 function PMA_jsFormat($a_string = '', $add_backquotes = TRUE)
1013 if (is_string($a_string)) {
1014 $a_string = str_replace('"', '&quot;', $a_string);
1015 $a_string = str_replace('\\', '\\\\', $a_string);
1016 $a_string = str_replace('\'', '\\\'', $a_string);
1017 $a_string = str_replace('#', '\\#', $a_string);
1018 $a_string = str_replace("\012", '\\\\n', $a_string);
1019 $a_string = str_replace("\015", '\\\\r', $a_string);
1022 return (($add_backquotes) ? PMA_backquote($a_string) : $a_string);
1023 } // end of the 'PMA_jsFormat()' function
1027 * Defines the <CR><LF> value depending on the user OS.
1029 * @return string the <CR><LF> value to use
1031 * @access public
1033 function PMA_whichCrlf()
1035 $the_crlf = "\n";
1037 // The 'PMA_USR_OS' constant is defined in "./libraries/defines.lib.php3"
1038 // Win case
1039 if (PMA_USR_OS == 'Win') {
1040 $the_crlf = "\r\n";
1042 // Mac case
1043 else if (PMA_USR_OS == 'Mac') {
1044 $the_crlf = "\r";
1046 // Others
1047 else {
1048 $the_crlf = "\n";
1051 return $the_crlf;
1052 } // end of the 'PMA_whichCrlf()' function
1056 * Counts and displays the number of records in a table
1058 * Last revision 13 July 2001: Patch for limiting dump size from
1059 * vinay@sanisoft.com & girish@sanisoft.com
1061 * @param string the current database name
1062 * @param string the current table name
1063 * @param boolean whether to retain or to displays the result
1065 * @return mixed the number of records if retain is required, true else
1067 * @access public
1069 function PMA_countRecords($db, $table, $ret = FALSE)
1071 $result = PMA_mysql_query('SELECT COUNT(*) AS num FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table));
1072 $num = ($result) ? PMA_mysql_result($result, 0, 'num') : 0;
1073 mysql_free_result($result);
1074 if ($ret) {
1075 return $num;
1076 } else {
1077 echo number_format($num, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']);
1078 return TRUE;
1080 } // end of the 'PMA_countRecords()' function
1084 * Displays a message at the top of the "main" (right) frame
1086 * @param string the message to display
1088 * @global array the configuration array
1090 * @access public
1092 function PMA_showMessage($message)
1094 global $cfg;
1096 // Reloads the navigation frame via JavaScript if required
1097 if (isset($GLOBALS['reload']) && $GLOBALS['reload']) {
1098 echo "\n";
1099 $reload_url = './left.php3?' . PMA_generate_common_url($GLOBALS['db'], '', '&');
1101 <script type="text/javascript" language="javascript1.2">
1102 <!--
1103 if (typeof(window.parent) != 'undefined'
1104 && typeof(window.parent.frames['nav']) != 'undefined') {
1105 window.parent.frames['nav'].location.replace('<?php echo $reload_url; ?>');
1107 //-->
1108 </script>
1109 <?php
1112 // Corrects the tooltip text via JS if required
1113 else if (!empty($GLOBALS['table']) && $cfg['ShowTooltip'] && PMA_MYSQL_INT_VERSION >= 32303) {
1114 $result = @PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], TRUE) . '\'');
1115 if ($result) {
1116 $tbl_status = PMA_mysql_fetch_array($result, MYSQL_ASSOC);
1117 $tooltip = (empty($tbl_status['Comment']))
1118 ? ''
1119 : $tbl_status['Comment'] . ' ';
1120 $tooltip .= '(' . $tbl_status['Rows'] . ' ' . $GLOBALS['strRows'] . ')';
1121 mysql_free_result($result);
1122 $md5_tbl = md5($GLOBALS['table']);
1123 echo "\n";
1125 <script type="text/javascript" language="javascript1.2">
1126 <!--
1127 if (typeof(document.getElementById) != 'undefined'
1128 && typeof(window.parent.frames['nav']) != 'undefined'
1129 && typeof(window.parent.frames['nav'].document) != 'undefined' && typeof(window.parent.frames['nav'].document) != 'unknown'
1130 && typeof(window.parent.frames['nav'].document.getElementById('<?php echo 'tbl_' . $md5_tbl; ?>')) != 'undefined'
1131 && typeof(window.parent.frames['nav'].document.getElementById('<?php echo 'tbl_' . $md5_tbl; ?>').title) == 'string') {
1132 window.parent.frames['nav'].document.getElementById('<?php echo 'tbl_' . $md5_tbl; ?>').title = '<?php echo PMA_jsFormat($tooltip, FALSE); ?>';
1134 //-->
1135 </script>
1136 <?php
1137 } // end if
1138 } // end if... else if
1140 // Checks if the table needs to be repaired after a TRUNCATE query.
1141 if (PMA_MYSQL_INT_VERSION >= 40000
1142 && isset($GLOBALS['table']) && isset($GLOBALS['sql_query'])
1143 && $GLOBALS['sql_query'] == 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table'])) {
1144 if (!isset($tbl_status)) {
1145 $result = @PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], TRUE) . '\'');
1146 if ($result) {
1147 $tbl_status = PMA_mysql_fetch_array($result, MYSQL_ASSOC);
1148 mysql_free_result($result);
1151 if (isset($tbl_status) && (int) $tbl_status['Index_length'] > 1024) {
1152 @PMA_mysql_query('REPAIR TABLE ' . PMA_backquote($GLOBALS['table']));
1155 unset($tbl_status);
1157 echo "\n";
1159 <div align="<?php echo $GLOBALS['cell_align_left']; ?>">
1160 <table border="<?php echo $cfg['Border']; ?>" cellpadding="5">
1161 <tr>
1162 <td bgcolor="<?php echo $cfg['ThBgcolor']; ?>">
1163 <b><?php echo (get_magic_quotes_gpc()) ? stripslashes($message) : $message; ?></b><br />
1164 </td>
1165 </tr>
1166 <?php
1167 if ($cfg['ShowSQL'] == TRUE && !empty($GLOBALS['sql_query'])) {
1168 // Basic url query part
1169 $url_qpart = '?' . PMA_generate_common_url(isset($GLOBALS['db']) ? $GLOBALS['db'] : '', isset($GLOBALS['table']) ? $GLOBALS['table'] : '');
1170 echo "\n";
1172 <tr>
1173 <td bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
1174 <?php
1175 echo "\n";
1176 // Html format the query to be displayed
1177 // The nl2br function isn't used because its result isn't a valid
1178 // xhtml1.0 statement before php4.0.5 ("<br>" and not "<br />")
1179 // If we want to show some sql code it is easiest to create it here
1180 /* SQL-Parser-Analyzer */
1181 $sqlnr = 1;
1182 if (!empty($GLOBALS['show_as_php'])) {
1183 $new_line = '\';<br />' . "\n" . ' $sql .= \'';
1185 if (isset($new_line)) {
1186 /* SQL-Parser-Analyzer */
1187 $query_base = htmlspecialchars($GLOBALS['sql_query']);
1188 /* SQL-Parser-Analyzer */
1189 $query_base = ereg_replace("((\015\012)|(\015)|(\012))+", $new_line, $query_base);
1190 } else {
1191 $query_base = $GLOBALS['sql_query'];
1193 if (!empty($GLOBALS['show_as_php'])) {
1194 $query_base = '$sql = \'' . PMA_sqlAddslashes($query_base);
1195 } else if (!empty($GLOBALS['validatequery'])) {
1196 $query_base = PMA_validateSQL($query_base);
1197 } else {
1198 $parsed_sql = PMA_SQP_parse($query_base);
1199 $query_base = PMA_formatSql($parsed_sql);
1202 // Prepares links that may be displayed to edit/explain the query
1203 // (don't go to default pages, we must go to the page
1204 // where the query box is available)
1205 // (also, I don't see why we should check the goto variable)
1207 //if (!isset($GLOBALS['goto'])) {
1208 //$edit_target = (isset($GLOBALS['table'])) ? $cfg['DefaultTabTable'] : $cfg['DefaultTabDatabase'];
1209 $edit_target = (isset($GLOBALS['table'])) ? 'tbl_properties.php3' : 'db_details.php3';
1210 //} else if ($GLOBALS['goto'] != 'main.php3') {
1211 // $edit_target = $GLOBALS['goto'];
1212 //} else {
1213 // $edit_target = '';
1216 if (isset($cfg['SQLQuery']['Edit'])
1217 && ($cfg['SQLQuery']['Edit'] == TRUE )
1218 && (!empty($edit_target))) {
1220 $edit_link = '&nbsp;[<a href="'
1221 . $edit_target
1222 . $url_qpart
1223 . '&amp;sql_query=' . urlencode($GLOBALS['sql_query']) . '&amp;show_query=1#querybox">' . $GLOBALS['strEdit'] . '</a>]';
1224 } else {
1225 $edit_link = '';
1228 // Want to have the query explained (Mike Beck 2002-05-22)
1229 // but only explain a SELECT (that has not been explained)
1230 /* SQL-Parser-Analyzer */
1231 if (isset($cfg['SQLQuery']['Explain'])
1232 && $cfg['SQLQuery']['Explain'] == TRUE) {
1234 // Detect if we are validating as well
1235 // To preserve the validate uRL data
1236 if (!empty($GLOBALS['validatequery'])) {
1237 $explain_link_validate = '&amp;validatequery=1';
1238 } else {
1239 $explain_link_validate = '';
1242 $explain_link = '&nbsp;[<a href="sql.php3'
1243 . $url_qpart
1244 . $explain_link_validate
1245 . '&amp;sql_query=';
1247 if (eregi('^SELECT[[:space:]]+', $GLOBALS['sql_query'])) {
1248 $explain_link .= urlencode('EXPLAIN ' . $GLOBALS['sql_query']) . '">' . $GLOBALS['strExplain'];
1249 } else if (eregi('^EXPLAIN[[:space:]]+SELECT[[:space:]]+', $GLOBALS['sql_query'])) {
1250 $explain_link .= substr($GLOBALS['sql_query'], 8) . '">' . $GLOBALS['strNoExplain'];
1251 } else {
1252 $explain_link = '';
1254 if(!empty($explain_link)) {
1255 $explain_link .= '</a>]';
1257 } else {
1258 $explain_link = '';
1259 } //show explain
1261 // Also we would like to get the SQL formed in some nice
1262 // php-code (Mike Beck 2002-05-22)
1263 if (isset($cfg['SQLQuery']['ShowAsPHP'])
1264 && $cfg['SQLQuery']['ShowAsPHP'] == TRUE) {
1265 $php_link = '&nbsp;[<a href="sql.php3'
1266 . $url_qpart
1267 . '&amp;show_query=1'
1268 . '&amp;sql_query=' . urlencode($GLOBALS['sql_query'])
1269 . '&amp;show_as_php=';
1271 if (!empty($GLOBALS['show_as_php'])) {
1272 $php_link .= '0">' . $GLOBALS['strNoPhp'];
1273 } else {
1274 $php_link .= '1">' . $GLOBALS['strPhp'];
1276 $php_link .= '</a>]';
1277 } else {
1278 $php_link = '';
1279 } //show as php
1281 if (isset($cfg['SQLValidator']['use'])
1282 && $cfg['SQLValidator']['use'] == TRUE
1283 && isset($cfg['SQLQuery']['Validate'])
1284 && $cfg['SQLQuery']['Validate'] == TRUE) {
1285 $validate_link = '&nbsp;[<a href="sql.php3'
1286 . $url_qpart
1287 . '&amp;show_query=1'
1288 . '&amp;sql_query=' . urlencode($GLOBALS['sql_query'])
1289 . '&amp;validatequery=';
1290 if (!empty($GLOBALS['validatequery'])) {
1291 $validate_link .= '0">' . $GLOBALS['strNoValidateSQL'] ;
1292 } else {
1293 $validate_link .= '1">'. $GLOBALS['strValidateSQL'] ;
1295 $validate_link .= '</a>]';
1296 } else {
1297 $validate_link = '';
1298 } //validator
1300 // Displays the message
1301 echo ' ' . $GLOBALS['strSQLQuery'] . '&nbsp;:';
1302 if (!empty($edit_target)) {
1303 echo $edit_link . $explain_link . $php_link . $validate_link;
1305 echo '<br />' . "\n";
1306 echo ' ' . $query_base;
1307 // If a 'LIMIT' clause has been programatically added to the query
1308 // displays it
1309 if (!empty($GLOBALS['sql_limit_to_append'])) {
1310 if (!empty($GLOBALS['show_as_php'])) {
1311 echo $GLOBALS['sql_limit_to_append'];
1312 } else if (!empty($GLOBALS['validatequery'])) {
1313 // skip the extra bit here
1314 } else {
1315 echo '&nbsp;' . PMA_formatSql(PMA_SQP_parse($GLOBALS['sql_limit_to_append']));
1319 //Clean up the end of the PHP
1320 if (!empty($GLOBALS['show_as_php'])) {
1321 echo '\';';
1323 echo "\n";
1325 </td>
1326 </tr>
1327 <?php
1329 echo "\n";
1331 </table>
1332 </div><br />
1333 <?php
1334 } // end of the 'PMA_showMessage()' function
1338 * Displays a link to the official MySQL documentation
1340 * @param chapter of "HTML, one page per chapter" documentation
1341 * @param contains name of page/anchor that is being linked
1343 * @return string the html link
1345 * @access public
1347 function PMA_showMySQLDocu($chapter, $link)
1349 if (!empty($GLOBALS['cfg']['MySQLManualBase'])) {
1350 if (!empty($GLOBALS['cfg']['MySQLManualType'])) {
1351 switch ($GLOBALS['cfg']['MySQLManualType']) {
1352 case 'old':
1353 return '[<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/' . $link[0] . '/' . $link[1] . '/' . $link . '.html" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]';
1354 case 'chapters':
1355 return '[<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/manual_' . $chapter . '.html#' . $link . '" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]';
1356 case 'big':
1357 return '[<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '#' . $link . '" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]';
1358 case 'none':
1359 return '';
1360 case 'searchable':
1361 default:
1362 return '[<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/' . $link . '.html" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]';
1364 } else {
1365 // no Type defined, show the old one
1366 return '[<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/' . $link[0] . '/' . $link[1] . '/' . $link . '.html" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]';
1368 } else {
1369 // no URL defined
1370 if (!empty($GLOBALS['cfg']['ManualBaseShort'])) {
1371 // the old configuration
1372 return '[<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/' . $link[0] . '/' . $link[1] . '/' . $link . '.html" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]';
1373 } else {
1374 return '';
1377 } // end of the 'PMA_showDocuShort()' function
1381 * Formats $value to byte view
1383 * @param double the value to format
1384 * @param integer the sensitiveness
1385 * @param integer the number of decimals to retain
1387 * @return array the formatted value and its unit
1389 * @access public
1391 * @author staybyte
1392 * @version 1.2 - 18 July 2002
1394 function PMA_formatByteDown($value, $limes = 6, $comma = 0)
1396 $dh = pow(10, $comma);
1397 $li = pow(10, $limes);
1398 $return_value = $value;
1399 $unit = $GLOBALS['byteUnits'][0];
1401 for ( $d = 6, $ex = 15; $d >= 1; $d--, $ex-=3 ) {
1402 if (isset($GLOBALS['byteUnits'][$d]) && $value >= $li * pow(10, $ex)) {
1403 $value = round($value / ( pow(1024, $d) / $dh) ) /$dh;
1404 $unit = $GLOBALS['byteUnits'][$d];
1405 break 1;
1406 } // end if
1407 } // end for
1409 if ($unit != $GLOBALS['byteUnits'][0]) {
1410 $return_value = number_format($value, $comma, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']);
1411 } else {
1412 $return_value = number_format($value, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']);
1415 return array($return_value, $unit);
1416 } // end of the 'PMA_formatByteDown' function
1420 * Ensures a database/table/field's name is not a reserved word (for MySQL
1421 * releases < 3.23.6)
1423 * @param string the name to check
1424 * @param string the url to go back in case of error
1426 * @return boolean true if the name is valid (no return else)
1428 * @access public
1430 * @author Dell'Aiera Pol; Olivier Blin
1432 function PMA_checkReservedWords($the_name, $error_url)
1434 // The name contains caracters <> a-z, A-Z and "_" -> not a reserved
1435 // word
1436 if (!ereg('^[a-zA-Z_]+$', $the_name)) {
1437 return TRUE;
1440 // Else do the work
1441 $filename = 'badwords.txt';
1442 if (file_exists($filename)) {
1443 // Builds the reserved words array
1444 $fd = fopen($filename, 'r');
1445 $contents = fread($fd, filesize($filename) - 1);
1446 fclose ($fd);
1447 $word_list = explode("\n", $contents);
1449 // Do the checking
1450 $word_cnt = count($word_list);
1451 for ($i = 0; $i < $word_cnt; $i++) {
1452 if (strtolower($the_name) == $word_list[$i]) {
1453 PMA_mysqlDie(sprintf($GLOBALS['strInvalidName'], $the_name), '', FALSE, $error_url);
1454 } // end if
1455 } // end for
1456 } // end if
1457 } // end of the 'PMA_checkReservedWords' function
1461 * Writes localised date
1463 * @param string the current timestamp
1465 * @return string the formatted date
1467 * @access public
1469 function PMA_localisedDate($timestamp = -1)
1471 global $datefmt, $month, $day_of_week;
1473 if ($timestamp == -1) {
1474 $timestamp = time();
1477 $date = ereg_replace('%[aA]', $day_of_week[(int)strftime('%w', $timestamp)], $datefmt);
1478 $date = ereg_replace('%[bB]', $month[(int)strftime('%m', $timestamp)-1], $date);
1480 return strftime($date, $timestamp);
1481 } // end of the 'PMA_localisedDate()' function
1485 * Prints out a tab for tabbed navigation.
1486 * If the variables $link and $args ar left empty, an inactive tab is created
1488 * @param string the text to be displayed as link
1489 * @param string main link file, e.g. "test.php3"
1490 * @param string link arguments
1491 * @param string link attributes
1493 * @return string two table cells, the first beeing a separator, the second the tab itself
1495 * @access public
1497 function PMA_printTab($text, $link, $args = '', $attr = '') {
1498 global $PHP_SELF;
1499 global $db_details_links_count_tabs;
1501 if (basename($PHP_SELF) == $link
1502 && ($text != $GLOBALS['strEmpty'] && $text != $GLOBALS['strDrop'])) {
1503 $bgcolor = 'silver';
1504 } else {
1505 $bgcolor = '#DFDFDF';
1508 $db_details_links_count_tabs++;
1509 if (!empty($attr)) {
1510 $attr = ' ' . $attr;
1513 $out = "\n" . ' '
1514 . '<td bgcolor="' . $bgcolor . '" align="center" width="64" nowrap="nowrap" class="tab">'
1515 . "\n" . ' ';
1516 if (strlen($link) > 0) {
1517 $out .= '<a href="' . $link . '?' . $args . '"' . $attr . '>'
1518 . '<b>' . $text . '</b></a>';
1519 } else {
1520 $out .= '<b>' . $text . '</b>';
1522 $out .= "\n" . ' '
1523 . '</td>'
1524 . "\n" . ' '
1525 . '<td width="8">&nbsp;</td>';
1527 return $out;
1528 } // end of the 'PMA_printTab()' function
1532 * Displays a link, or a button if the link's URL is too large, to
1533 * accommodate some browsers' limitations
1535 * @param string the URL
1536 * @param string the link message
1537 * @param string js confirmation
1539 * @return string the results to be echoed or saved in an array
1541 function PMA_linkOrButton($url, $message, $js_conf)
1543 if (strlen($url) <= 2047) {
1544 $onclick_url = (empty($js_conf) ? '' : ' onclick="return confirmLink(this, \'' . $js_conf . '\')"');
1545 $link_or_button = ' <a href="' . $url . '"' . $onclick_url . '>' . "\n"
1546 . ' ' . $message . '</a>' . "\n";
1548 else {
1549 $edit_url_parts = parse_url($url);
1550 $query_parts = explode('&', $edit_url_parts['query']);
1551 $link_or_button = ' <form action="'
1552 . $edit_url_parts['path']
1553 . '" method="post">' . "\n";
1554 reset ($query_parts);
1555 while (list(, $query_pair) = each($query_parts)) {
1556 list($eachvar, $eachval) = explode('=', $query_pair);
1557 $link_or_button .= ' <input type="hidden" name="' . str_replace('amp;', '', $eachvar) . '" value="' . htmlspecialchars(urldecode($eachval)) . '" />' . "\n";
1558 } // end while
1559 $link_or_button .= ' <input type="submit" value="'
1560 . htmlspecialchars($message) . '" />' . "\n" . '</form>' . "\n";
1561 } // end if... else...
1563 return $link_or_button;
1564 } // end of the 'PMA_linkOrButton()' function
1568 * Returns a given timespan value in a readable format.
1570 * @param int the timespan
1572 * @return string the formatted value
1574 function PMA_timespanFormat($seconds)
1576 $return_string = '';
1577 $days = floor($seconds / 86400);
1578 if ($days > 0) {
1579 $seconds -= $days * 86400;
1581 $hours = floor($seconds / 3600);
1582 if ($days > 0 || $hours > 0) {
1583 $seconds -= $hours * 3600;
1585 $minutes = floor($seconds / 60);
1586 if ($days > 0 || $hours > 0 || $minutes > 0) {
1587 $seconds -= $minutes * 60;
1589 return sprintf($GLOBALS['timespanfmt'], (string)$days, (string)$hours, (string)$minutes, (string)$seconds);
1593 // Kanji encoding convert feature appended by Y.Kawada (2002/2/20)
1594 if (PMA_PHP_INT_VERSION >= 40006
1595 && @function_exists('mb_convert_encoding')
1596 && strpos(' ' . $lang, 'ja-')
1597 && file_exists('./libraries/kanji-encoding.lib.php3')) {
1598 include('./libraries/kanji-encoding.lib.php3');
1599 define('PMA_MULTIBYTE_ENCODING', 1);
1600 } // end if
1602 } // $__PMA_COMMON_LIB__