6 * Misc stuff and functions used by almost all the scripts.
7 * Among other things, it contains the advanced authentification work.
12 if (!defined('PMA_COMMON_LIB_INCLUDED')){
13 define('PMA_COMMON_LIB_INCLUDED', 1);
16 * Order of sections for common.lib.php3:
18 * in PHP3, functions and constants must be physically defined
19 * before they are referenced
21 * some functions need the constants of libraries/defines.lib.php3
23 * the PMA_setFontSizes() function must be before the call to the
24 * libraries/auth/cookie.auth.lib.php3 library
26 * the include of libraries/defines.lib.php3 must be after the connection
27 * to db to get the MySql version
29 * the PMA_sqlAddslashes() function must be before the connection to db
31 * the authentication libraries must be before the connection to db but
32 * after the PMA_isInto() function
34 * the PMA_mysqlDie() function must be before the connection to db but after
35 * mysql extension has been loaded
37 * ... so the required order is:
39 * - parsing of the configuration file
40 * - first load of the libraries/define.lib.php3 library (won't get the
41 * MySQL release number)
42 * - load of mysql extension (if necessary)
43 * - definition of PMA_sqlAddslashes()
44 * - definition of PMA_mysqlDie()
45 * - definition of PMA_isInto()
46 * - definition of PMA_setFontSizes()
47 * - loading of an authentication library
49 * - authentication work
50 * - second load of the libraries/define.lib.php3 library to get the MySQL
52 * - other functions, respecting dependencies
57 * Avoids undefined variables in PHP3
59 if (!isset($use_backquotes)) {
68 * Parses the configuration file and gets some constants used to define
69 * versions of phpMyAdmin/php/mysql...
71 include('./config.inc.php3');
73 // For compatibility with old config.inc.php3
74 if (!isset($cfgExecTimeLimit)) {
75 $cfgExecTimeLimit = 300; // 5 minuts
77 if (!isset($cfgShowStats)) {
80 if (!isset($cfgLoginCookieRecall)) {
81 $cfgLoginCookieRecall = TRUE;
83 if (!isset($cfgShowTooltip)) {
84 $cfgShowTooltip = TRUE;
86 if (!isset($cfgShowMysqlInfo)) {
87 $cfgShowMysqlInfo = FALSE;
89 if (!isset($cfgShowMysqlVars)) {
90 $cfgShowMysqlVars = FALSE;
92 if (!isset($cfgShowPhpInfo)) {
93 $cfgShowPhpInfo = FALSE;
95 if (!isset($cfgShowAll)) {
98 if (!isset($cfgNavigationBarIconic)) {
99 $cfgNavigationBarIconic = TRUE;
101 if (!isset($cfgProtectBinary)) {
102 if (isset($cfgProtectBlob)) {
103 $cfgProtectBinary = ($cfgProtectBlob ?
'blob' : FALSE);
104 unset($cfgProtectBlob);
106 $cfgProtectBinary = 'blob';
109 if (!isset($cfgShowFunctionFields)) {
110 $cfgShowFunctionFields = TRUE;
112 if (!isset($cfgZipDump)) {
113 $cfgZipDump = (isset($cfgGZipDump) ?
$cfgGZipDump : TRUE);
115 if (!isset($cfgLeftBgColor)) {
116 $cfgLeftBgColor = '#D0DCE0';
118 if (!isset($cfgLeftPointerColor)) {
119 $cfgLeftPointerColor = '';
121 if (!isset($cfgRightBgColor)) {
122 $cfgRightBgColor = '#F5F5F5';
124 if (!isset($cfgBrowsePointerColor)) {
125 $cfgBrowsePointerColor = '';
127 if (!isset($cfgBrowseMarkRow)) {
128 $cfgBrowseMarkRow = 0;
130 if (!isset($cfgTextareaCols)) {
131 $cfgTextareaCols = 40;
133 if (!isset($cfgTextareaRows)) {
134 $cfgTextareaRows = 7;
136 if (!isset($cfgDefaultDisplay)) {
137 $cfgDefaultDisplay = 'horizontal';
139 if (!isset($cfgRepeatCells)) {
140 $cfgRepeatCells = 100;
142 if (!isset($cfgLeftFrameLight)) {
143 $cfgLeftFrameLight = TRUE;
146 // Adds a trailing slash et the end of the phpMyAdmin uri if it does not
148 if ($cfgPmaAbsoluteUri != '' && substr($cfgPmaAbsoluteUri, -1) != '/') {
149 $cfgPmaAbsoluteUri .= '/';
152 // Gets some constants
153 include('./libraries/defines.lib.php3');
155 // If zlib output compression is set in the php configuration file, no
156 // output buffering should be run
157 if (PMA_PHP_INT_VERSION
< 40000
158 ||
(PMA_PHP_INT_VERSION
>= 40005 && @ini_get
('zlib.output_compression'))) {
164 * Loads the mysql extensions if it is not loaded yet
165 * staybyte - 26. June 2001
167 if (((PMA_PHP_INT_VERSION
>= 40000 && !@ini_get
('safe_mode') && @ini_get
('enable_dl'))
168 ||
(PMA_PHP_INT_VERSION
> 30009 && !@get_cfg_var
('safe_mode')))
169 && @function_exists
('dl')) {
170 if (PMA_PHP_INT_VERSION
< 40000) {
171 $extension = 'MySQL';
173 $extension = 'mysql';
175 if (PMA_IS_WINDOWS
) {
180 if (!@extension_loaded
($extension)) {
181 @dl
($extension.$suffix);
183 if (!@extension_loaded
($extension)) {
184 echo $strCantLoadMySQL;
187 } // end load mysql extension
191 * Add slashes before "'" and "\" characters so a value containing them can
192 * be used in a sql comparison.
194 * @param string the string to slash
195 * @param boolean whether the string will be used in a 'LIKE' clause
196 * (it then requires two more escaped sequences) or not
198 * @return string the slashed string
202 function PMA_sqlAddslashes($a_string = '', $is_like = FALSE)
205 $a_string = str_replace('\\', '\\\\\\\\', $a_string);
207 $a_string = str_replace('\\', '\\\\', $a_string);
209 $a_string = str_replace('\'', '\\\'', $a_string);
212 } // end of the 'PMA_sqlAddslashes()' function
216 * Displays a MySQL error message in the right frame.
218 * @param string the error mesage
219 * @param string the sql query that failed
220 * @param boolean whether to show a "modify" link or not
221 * @param string the "back" link url (full path is not required)
225 function PMA_mysqlDie($error_message = '', $the_query = '',
226 $is_modify_link = TRUE, $back_url = '')
228 if (!$error_message) {
229 $error_message = mysql_error();
231 if (!$the_query && !empty($GLOBALS['sql_query'])) {
232 $the_query = $GLOBALS['sql_query'];
235 echo '<b>'. $GLOBALS['strError'] . '</b>' . "\n";
236 // if the config password is wrong, or the MySQL server does not
237 // respond, do not show the query that would reveal the
239 if (!empty($the_query) && !strstr($the_query, 'connect')) {
240 $query_base = htmlspecialchars($the_query);
241 $query_base = ereg_replace("((\015\012)|(\015)|(\012)){3,}", "\n\n", $query_base);
243 echo ' ' . $GLOBALS['strSQLQuery'] . ' : ' . "\n";
244 if ($is_modify_link) {
246 . '<a href="db_details.php3?lang=' . $GLOBALS['lang'] . '&server=' . urlencode($GLOBALS['server']) . '&db=' . urlencode($GLOBALS['db']) . '&sql_query=' . urlencode($the_query) . '&show_query=y">' . $GLOBALS['strEdit'] . '</a>'
249 echo '<pre>' . "\n" . $query_base . "\n" . '</pre>' . "\n";
252 if (!empty($error_message)) {
253 $error_message = htmlspecialchars($error_message);
254 $error_message = ereg_replace("((\015\012)|(\015)|(\012)){3,}", "\n\n", $error_message);
257 echo ' ' . $GLOBALS['strMySQLSaid'] . '<br />' . "\n";
258 echo '<pre>' . "\n" . $error_message . "\n" . '</pre>' . "\n";
260 if (!empty($back_url)) {
261 echo '<a href="' . $back_url . '">' . $GLOBALS['strBack'] . '</a>';
265 include('./footer.inc.php3');
267 } // end of the 'PMA_mysqlDie()' function
271 * Defines whether a string exists inside an array or not
273 * @param string string to search for
274 * @param mixed array to search into
276 * @return integer the rank of the $toFind string in the array or '-1' if
277 * it hasn't been found
281 function PMA_isInto($toFind = '', &$in)
284 for ($i = 0; $i < $max && ($toFind != $in[$i]); $i++
) {
288 return ($i < $max) ?
$i : -1;
289 } // end of the 'PMA_isInto()' function
293 * Determines the font sizes to use depending on the os and browser of the
296 * This function is based on an article from phpBuilder (see
297 * http://www.phpbuilder.net/columns/tim20000821.php3).
299 * @return boolean always true
301 * @global string the standard font size
302 * @global string the font size for titles
303 * @global string the small font size
304 * @global string the smallest font size
310 function PMA_setFontSizes()
312 global $font_size, $font_bigger, $font_smaller, $font_smallest;
314 // IE (<6)/Opera for win case: needs smaller fonts than anyone else
315 if (PMA_USR_OS
== 'Win'
316 && ((PMA_USR_BROWSER_AGENT
== 'IE' && PMA_USR_BROWSER_VER
< 6) || PMA_USR_BROWSER_AGENT
== 'OPERA')) {
317 $font_size = 'x-small';
318 $font_bigger = 'large';
319 $font_smaller = '90%';
320 $font_smallest = '7pt';
322 // IE6 and other browsers for win case
323 else if (PMA_USR_OS
== 'Win') {
324 $font_size = 'small';
325 $font_bigger = 'large';
326 $font_smaller = (PMA_USR_BROWSER_AGENT
== 'IE')
329 $font_smallest = 'x-small';
331 // Some mac browsers need also smaller default fonts size (OmniWeb &
333 else if (PMA_USR_OS
== 'Mac'
334 && (PMA_USR_BROWSER_AGENT
== 'OMNIWEB' || PMA_USR_BROWSER_AGENT
== 'OPERA')) {
335 $font_size = 'x-small';
336 $font_bigger = 'large';
337 $font_smaller = '90%';
338 $font_smallest = '7pt';
340 // ... but most of them (except IE 5+ & NS 6+) need bigger fonts
341 else if (PMA_USR_OS
== 'Mac'
342 && ((PMA_USR_BROWSER_AGENT
!= 'IE' && PMA_USR_BROWSER_AGENT
!= 'MOZILLA')
343 || PMA_USR_BROWSER_VER
< 5)) {
344 $font_size = 'medium';
345 $font_bigger = 'x-large';
346 $font_smaller = 'small';
347 $font_smallest = 'x-small';
350 else if (PMA_USR_OS
== 'OS/2'
351 && PMA_USR_BROWSER_AGENT
== 'OPERA') {
352 $font_size = 'small';
353 $font_bigger = 'medium';
354 $font_smaller = 'x-small';
355 $font_smallest = 'x-small';
358 $font_size = 'small';
359 $font_bigger = 'large';
360 $font_smaller = 'x-small';
361 $font_smallest = 'x-small';
365 } // end of the 'PMA_setFontSizes()' function
369 * Use mysql_connect() or mysql_pconnect()?
371 $connect_func = ($cfgPersistentConnections) ?
'mysql_pconnect' : 'mysql_connect';
376 * Gets the valid servers list and parameters
379 while (list($key, $val) = each($cfgServers)) {
380 // Don't use servers with no hostname
381 if (empty($val['host'])) {
382 unset($cfgServers[$key]);
386 if (empty($server) ||
!isset($cfgServers[$server]) ||
!is_array($cfgServers[$server])) {
387 $server = $cfgServerDefault;
392 * If no server is selected, make sure that $cfgServer is empty (so that
393 * nothing will work), and skip server authentication.
394 * We do NOT exit here, but continue on without logging into any server.
395 * This way, the welcome page will still come up (with no server info) and
396 * present a choice of servers in the case that there are multiple servers
397 * and '$cfgServerDefault = 0' is set.
400 $cfgServer = array();
404 * Otherwise, set up $cfgServer and do the usual login stuff.
406 else if (isset($cfgServers[$server])) {
407 $cfgServer = $cfgServers[$server];
409 // Check how the config says to connect to the server
410 $server_port = (empty($cfgServer['port']))
412 : ':' . $cfgServer['port'];
413 if (strtolower($cfgServer['connect_type']) == 'tcp') {
414 $cfgServer['socket'] = '';
416 $server_socket = (empty($cfgServer['socket']) || PMA_PHP_INT_VERSION
< 30010)
418 : ':' . $cfgServer['socket'];
420 // Ensures compatibility with old config files
421 if (!isset($cfgServer['auth_type'])) {
422 $cfgServer['auth_type'] = (isset($cfgServer['adv_auth']) && $cfgServer['adv_auth'])
427 // Gets the authentication library that fits the cfgServer settings
428 // and run authentication
429 include('./libraries/auth/' . $cfgServer['auth_type'] . '.auth.lib.php3');
430 if (!PMA_auth_check()) {
436 // The user can work with only some databases
437 if (isset($cfgServer['only_db']) && $cfgServer['only_db'] != '') {
438 if (is_array($cfgServer['only_db'])) {
439 $dblist = $cfgServer['only_db'];
441 $dblist[] = $cfgServer['only_db'];
445 if (PMA_PHP_INT_VERSION
>= 40000) {
446 $bkp_track_err = @ini_set
('track_errors', 1);
449 // Try to connect MySQL with the standard user profile (will be used to
450 // get the privileges list for the current user but the true user link
451 // must be open after this one so it would be default one for all the
453 if ($cfgServer['stduser'] != '') {
454 $dbh = @$connect_func(
455 $cfgServer['host'] . $server_port . $server_socket,
456 $cfgServer['stduser'],
457 $cfgServer['stdpass']
461 $conn_error = mysql_error();
462 } else if (isset($php_errormsg)) {
463 $conn_error = $php_errormsg;
465 $conn_error = 'Cannot connect: invalid settings.';
467 $local_query = $connect_func . '('
468 . $cfgServer['host'] . $server_port . $server_socket . ', '
469 . $cfgServer['stduser'] . ', '
470 . $cfgServer['stdpass'] . ')';
471 PMA_mysqlDie($conn_error, $local_query, FALSE);
475 // Connects to the server (validates user's login)
476 $userlink = @$connect_func(
477 $cfgServer['host'] . $server_port . $server_socket,
479 $cfgServer['password']
481 if ($userlink == FALSE) {
485 if (PMA_PHP_INT_VERSION
>= 40000) {
486 @ini_set
('track_errors', $bkp_track_err);
489 // If stduser isn't defined, use the current user settings to get his
491 if ($cfgServer['stduser'] == '') {
495 // if 'only_db' is set for the current user, there is no need to check for
496 // available databases in the "mysql" db
497 $dblist_cnt = count($dblist);
499 $true_dblist = array();
501 for ($i = 0; $i < $dblist_cnt; $i++
) {
502 if ($is_show_dbs && ereg('(^|[^\])(_|%)', $dblist[$i])) {
503 $local_query = 'SHOW DATABASES LIKE \'' . $dblist[$i] . '\'';
504 $rs = mysql_query($local_query, $dbh);
505 // "SHOW DATABASES" statement is disabled
507 && (mysql_error() && mysql_errno() == 1045)) {
508 $true_dblist[] = str_replace('\\_', '_', str_replace('\\%', '%', $dblist[$i]));
509 $is_show_dbs = FALSE;
512 // else if (mysql_error()) {
513 // PMA_mysqlDie('', $local_query, FALSE);
515 while ($row = @mysql_fetch_row
($rs)) {
516 $true_dblist[] = $row[0];
519 mysql_free_result($rs);
522 $true_dblist[] = str_replace('\\_', '_', str_replace('\\%', '%', $dblist[$i]));
523 } // end if... else...
525 $dblist = $true_dblist;
529 // 'only_db' is empty for the current user -> checks for available
530 // databases in the "mysql" db
532 $auth_query = 'SELECT User, Select_priv '
534 . 'WHERE User = \'' . PMA_sqlAddslashes($cfgServer['user']) . '\'';
535 $rs = mysql_query($auth_query, $dbh); // Debug: or PMA_mysqlDie('', $auth_query, FALSE);
538 // Access to "mysql" db allowed -> gets the usable db list
539 if (!$dblist_cnt && @mysql_numrows
($rs)) {
540 $row = mysql_fetch_array($rs);
541 mysql_free_result($rs);
542 // Correction uva 19991215
543 // Previous code assumed database "mysql" admin table "db" column
544 // "db" contains literal name of user database, and works if so.
545 // Mysql usage generally (and uva usage specifically) allows this
546 // column to contain regular expressions (we have all databases
547 // owned by a given student/faculty/staff beginning with user i.d.
548 // and governed by default by a single set of privileges with
549 // regular expression as key). This breaks previous code.
550 // This maintenance is to fix code to work correctly for regular
552 if ($row['Select_priv'] != 'Y') {
554 // 1. get allowed dbs from the "mysql.db" table
555 // lem9: User can be blank (anonymous user)
556 $local_query = 'SELECT DISTINCT Db FROM mysql.db WHERE Select_priv = \'Y\' AND (User = \'' . PMA_sqlAddslashes($cfgServer['user']) . '\' OR User = \'\')';
557 $rs = mysql_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE);
558 if (@mysql_numrows
($rs)) {
559 // Will use as associative array of the following 2 code
561 // the 1st is the only line intact from before
563 // the 2nd replaces $dblist[] = $row['Db'];
564 $uva_mydbs = array();
565 // Code following those 2 lines in correction continues
566 // populating $dblist[], as previous code did. But it is
567 // now populated with actual database names instead of
568 // with regular expressions.
569 while ($row = mysql_fetch_array($rs)) {
570 // loic1: all databases cases - part 1
571 if (empty($row['Db']) ||
$row['Db'] == '%') {
575 // loic1: avoid multiple entries for dbs
576 if (!isset($uva_mydbs[$row['Db']])) {
577 $uva_mydbs[$row['Db']] = 1;
580 mysql_free_result($rs);
581 $uva_alldbs = mysql_list_dbs($dbh);
582 // loic1: all databases cases - part 2
583 if (isset($uva_mydbs['%'])) {
584 while ($uva_row = mysql_fetch_array($uva_alldbs)) {
585 $dblist[] = $uva_row[0];
589 while ($uva_row = mysql_fetch_array($uva_alldbs)) {
590 $uva_db = $uva_row[0];
591 if (isset($uva_mydbs[$uva_db]) && $uva_mydbs[$uva_db] == 1) {
593 $uva_mydbs[$uva_db] = 0;
594 } else if (!isset($dblist[$uva_db])) {
596 while (list($uva_matchpattern, $uva_value) = each($uva_mydbs)) {
597 // loic1: fixed bad regexp
598 // TODO: db names may contain characters
599 // that are regexp instructions
600 $re = '(^|(\\\\\\\\)+|[^\])';
601 $uva_regex = ereg_replace($re . '%', '\\1.*', ereg_replace($re . '_', '\\1.{1}', $uva_matchpattern));
602 // Fixed db name matching
603 // 2000-08-28 -- Benjamin Gandon
604 if (ereg('^' . $uva_regex . '$', $uva_db)) {
609 } // end if ... else if....
612 mysql_free_result($uva_alldbs);
616 // 2. get allowed dbs from the "mysql.tables_priv" table
617 $local_query = 'SELECT DISTINCT Db FROM mysql.tables_priv WHERE Table_priv LIKE \'%Select%\' AND User = \'' . PMA_sqlAddslashes($cfgServer['user']) . '\'';
618 $rs = mysql_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE);
619 if (@mysql_numrows
($rs)) {
620 while ($row = mysql_fetch_array($rs)) {
621 if (PMA_isInto($row['Db'], $dblist) == -1) {
622 $dblist[] = $row['Db'];
625 mysql_free_result($rs);
628 } // end building available dbs from the "mysql" db
630 } // end server connecting
633 * Missing server hostname
641 * Get the list and number of available databases.
643 * @param string the url to go back to in case of error
645 * @return boolean always true
647 * @global array the list of available databases
648 * @global integer the number of available databases
650 function PMA_availableDatabases($error_url = '')
655 $num_dbs = count($dblist);
657 // 1. A list of allowed databases has already been defined by the
658 // authentification process -> gets the available databases list
660 $true_dblist = array();
661 for ($i = 0; $i < $num_dbs; $i++
) {
662 $dblink = @mysql_select_db
($dblist[$i]);
664 $true_dblist[] = $dblist[$i];
668 $dblist = $true_dblist;
670 $num_dbs = count($dblist);
673 // 2. Allowed database list is empty -> gets the list of all databases
676 $dbs = mysql_list_dbs() or PMA_mysqlDie('', 'mysql_list_dbs()', FALSE, $error_url);
677 $num_dbs = @mysql_num_rows
($dbs);
679 for ($i = 0; $i < $num_dbs; $i++
) {
680 $db_name_tmp = mysql_dbname($dbs, $i);
681 $dblink = @mysql_select_db
($db_name_tmp);
683 $dblist[] = $db_name_tmp;
687 mysql_free_result($dbs);
688 $num_dbs = $real_num_dbs;
692 } // end of the 'PMA_availableDatabases()' function
696 * Gets constants that defines the PHP, MySQL... releases.
697 * This include must be located physically before any code that needs to
698 * reference the constants, else PHP 3.0.16 won't be happy; and must be
699 * located after we are connected to db to get the MySql version.
701 include('./libraries/defines.lib.php3');
705 /* ----------------------- Set of misc functions ----------------------- */
709 * Adds backquotes on both sides of a database, table or field name.
710 * Since MySQL 3.23.6 this allows to use non-alphanumeric characters in
713 * @param string the database, table or field name to "backquote"
714 * @param boolean a flag to bypass this function (used by dump functions)
716 * @return string the "backquoted" database, table or field name if the
717 * current MySQL release is >= 3.23.6, the original one
722 function PMA_backquote($a_name, $do_it = TRUE)
725 && PMA_MYSQL_INT_VERSION
>= 32306
726 && !empty($a_name) && $a_name != '*') {
727 return '`' . $a_name . '`';
731 } // end of the 'PMA_backquote()' function
735 * Format a string so it can be passed to a javascript function.
736 * This function is used to displays a javascript confirmation box for
737 * "DROP/DELETE/ALTER" queries.
739 * @param string the string to format
740 * @param boolean whether to add backquotes to the string or not
742 * @return string the formated string
746 function PMA_jsFormat($a_string = '', $add_backquotes = TRUE)
748 if (is_string($a_string)) {
749 $a_string = str_replace('"', '"', $a_string);
750 $a_string = str_replace('\\', '\\\\', $a_string);
751 $a_string = str_replace('\'', '\\\'', $a_string);
752 $a_string = str_replace('#', '\\#', $a_string);
753 $a_string = str_replace("\012", '\\\\n', $a_string);
754 $a_string = str_replace("\015", '\\\\r', $a_string);
757 return (($add_backquotes) ?
PMA_backquote($a_string) : $a_string);
758 } // end of the 'PMA_jsFormat()' function
762 * Defines the <CR><LF> value depending on the user OS.
764 * @return string the <CR><LF> value to use
768 function PMA_whichCrlf()
772 // The 'PMA_USR_OS' constant is defined in "./libraries/defines.lib.php3"
774 if (PMA_USR_OS
== 'Win') {
778 else if (PMA_USR_OS
== 'Mac') {
787 } // end of the 'PMA_whichCrlf()' function
791 * Counts and displays the number of records in a table
793 * Last revision 13 July 2001: Patch for limiting dump size from
794 * vinay@sanisoft.com & girish@sanisoft.com
796 * @param string the current database name
797 * @param string the current table name
798 * @param boolean whether to retain or to displays the result
800 * @return mixed the number of records if retain is required, true else
804 function PMA_countRecords($db, $table, $ret = FALSE)
806 $result = mysql_query('SELECT COUNT(*) AS num FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table));
807 $num = mysql_result($result, 0, 'num');
808 mysql_free_result($result);
812 echo number_format($num, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']);
815 } // end of the 'PMA_countRecords()' function
819 * Displays a message at the top of the "main" (right) frame
821 * @param string the message to display
825 function PMA_showMessage($message)
827 // Reloads the navigation frame via JavaScript if required
828 if (isset($GLOBALS['reload']) && $GLOBALS['reload']) {
830 $reload_url = './left.php3'
831 . '?lang=' . $GLOBALS['lang']
832 . '&server=' . $GLOBALS['server']
833 . ((!empty($GLOBALS['db'])) ?
'&db=' . urlencode($GLOBALS['db']) : '');
835 <script type
="text/javascript" language
="javascript1.2">
837 window
.parent
.frames
['nav'].location
.replace('<?php echo $reload_url; ?>');
844 <div align
="<?php echo $GLOBALS['cell_align_left']; ?>">
845 <table border
="<?php echo $GLOBALS['cfgBorder']; ?>" cellpadding
="5">
847 <td bgcolor
="<?php echo $GLOBALS['cfgThBgcolor']; ?>">
848 <b
><?php
echo get_magic_quotes_gpc() ?
stripslashes($message) : $message; ?
></b
><br
/>
852 if ($GLOBALS['cfgShowSQL'] == TRUE && !empty($GLOBALS['sql_query'])) {
856 <td bgcolor
="<?php echo $GLOBALS['cfgBgcolorOne']; ?>">
859 // The nl2br function isn't used because its result isn't a valid
860 // xhtml1.0 statement before php4.0.5 ("<br>" and not "<br />")
861 $new_line = '<br />' . "\n" . ' ';
862 $query_base = htmlspecialchars($GLOBALS['sql_query']);
863 $query_base = ereg_replace("((\015\012)|(\015)|(\012))+", $new_line, $query_base);
864 if (!isset($GLOBALS['show_query']) ||
$GLOBALS['show_query'] != 'y') {
865 if (!isset($GLOBALS['goto'])) {
866 $edit_target = (isset($GLOBALS['table'])) ?
'tbl_properties.php3' : 'db_details.php3';
867 } else if ($GLOBALS['goto'] != 'main.php3') {
868 $edit_target = $GLOBALS['goto'];
872 if ($edit_target == 'tbl_properties.php3') {
873 $edit_link = '<a href="tbl_properties.php3?lang=' . $GLOBALS['lang'] . '&server=' . urlencode($GLOBALS['server']) . '&db=' . urlencode($GLOBALS['db']) . '&table=' . urlencode($GLOBALS['table']) . '&sql_query=' . urlencode($GLOBALS['sql_query']) . '&show_query=y#querybox">' . $GLOBALS['strEdit'] . '</a>';
874 } else if ($edit_target != '') {
875 $edit_link = '<a href="db_details.php3?lang=' . $GLOBALS['lang'] . '&server=' . urlencode($GLOBALS['server']) . '&db=' . urlencode($GLOBALS['db']) . '&sql_query=' . urlencode($GLOBALS['sql_query']) . '&show_query=y#querybox">' . $GLOBALS['strEdit'] . '</a>';
878 if (!empty($edit_target)) {
879 echo ' ' . $GLOBALS['strSQLQuery'] . ' : [' . $edit_link . ']<br />' . "\n";
881 echo ' ' . $GLOBALS['strSQLQuery'] . ' :<br />' . "\n";
883 echo ' ' . $query_base;
884 // If a 'LIMIT' clause has been programatically added to the query
886 if (!empty($GLOBALS['sql_limit_to_append'])) {
887 echo $GLOBALS['sql_limit_to_append'];
900 } // end of the 'PMA_showMessage()' function
904 * Displays a link to the official MySQL documentation (short)
906 * @param string an anchor to move to
908 * @return string the html link
912 function PMA_showDocuShort($link)
914 if (!empty($GLOBALS['cfgManualBaseShort'])) {
915 return '[<a href="' . $GLOBALS['cfgManualBaseShort'] . '/' . $link .'" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]';
917 } // end of the 'PMA_showDocuShort()' function
921 * Formats $value to byte view
923 * @param double the value to format
924 * @param integer the sensitiveness
925 * @param integer the number of decimals to retain
927 * @return array the formatted value and its unit
932 * @version 1.1 - 07 July 2001
934 function PMA_formatByteDown($value, $limes = 6, $comma = 0)
936 $dh = pow(10, $comma);
937 $li = pow(10, $limes);
938 $return_value = $value;
939 $unit = $GLOBALS['byteUnits'][0];
941 if ($value >= $li*1000000) {
942 $value = round($value/(1073741824/$dh))/$dh;
943 $unit = $GLOBALS['byteUnits'][3];
945 else if ($value >= $li*1000) {
946 $value = round($value/(1048576/$dh))/$dh;
947 $unit = $GLOBALS['byteUnits'][2];
949 else if ($value >= $li) {
950 $value = round($value/(1024/$dh))/$dh;
951 $unit = $GLOBALS['byteUnits'][1];
953 if ($unit != $GLOBALS['byteUnits'][0]) {
954 $return_value = number_format($value, $comma, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']);
956 $return_value = number_format($value, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']);
959 return array($return_value, $unit);
960 } // end of the 'PMA_formatByteDown' function
964 * Ensures a database/table/field's name is not a reserved word (for MySQL
967 * @param string the name to check
968 * @param string the url to go back in case of error
970 * @return boolean true if the name is valid (no return else)
974 * @author Dell'Aiera Pol; Olivier Blin
976 function PMA_checkReservedWords($the_name, $error_url)
978 // The name contains caracters <> a-z, A-Z and "_" -> not a reserved
980 if (!ereg('^[a-zA-Z_]+$', $the_name)) {
985 $filename = 'badwords.txt';
986 if (file_exists($filename)) {
987 // Builds the reserved words array
988 $fd = fopen($filename, 'r');
989 $contents = fread($fd, filesize($filename) - 1);
991 $word_list = explode("\n", $contents);
994 $word_cnt = count($word_list);
995 for ($i = 0; $i < $word_cnt; $i++
) {
996 if (strtolower($the_name) == $word_list[$i]) {
997 PMA_mysqlDie(sprintf($GLOBALS['strInvalidName'], $the_name), '', FALSE, $error_url);
1001 } // end of the 'PMA_checkReservedWords' function
1005 * Writes localised date
1007 * @param string the current timestamp
1009 * @return string the formatted date
1013 function PMA_localisedDate($timestamp = -1)
1015 global $datefmt, $month, $day_of_week;
1017 if ($timestamp == -1) {
1018 $timestamp = time();
1021 $date = ereg_replace('%[aA]', $day_of_week[(int)strftime('%w', $timestamp)], $datefmt);
1022 $date = ereg_replace('%[bB]', $month[(int)strftime('%m', $timestamp)-1], $date);
1024 return strftime($date, $timestamp);
1025 } // end of the 'PMA_localisedDate()' function
1027 } // $__PMA_COMMON_LIB__