Documentation TYPO3 par Ameos

common.lib.php

00001 <?php
00002 /* $Id: common.lib.php,v 2.10 2003/12/30 18:24:10 rabus Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
00004 
00054 if (!isset($is_minimum_common)) {
00055     $is_minimum_common = FALSE;
00056 }
00057 
00061 if (!isset($use_backquotes)) {
00062     $use_backquotes   = 0;
00063 }
00064 if (!isset($pos)) {
00065     $pos              = 0;
00066 }
00067 
00071 if (file_exists('./config.inc.developer.php')) {
00072     $cfgfile_to_load = './config.inc.developer.php';
00073 } else {
00074     $cfgfile_to_load = './config.inc.php';
00075 }
00076 
00081 $old_error_reporting = error_reporting(0);
00082 include_once($cfgfile_to_load);
00083 // Include failed
00084 if (!isset($cfgServers) && !isset($cfg['Servers'])) {
00085     // Creates fake settings
00086     $cfg = array('DefaultLang'           => 'en-iso-8859-1',
00087                     'AllowAnywhereRecoding' => FALSE);
00088     // Loads the language file
00089     require_once('./libraries/select_lang.lib.php');
00090     // Sends the Content-Type header
00091     header('Content-Type: text/html; charset=' . $charset);
00092     // Displays the error message
00093     ?>
00094 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
00095 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
00096 <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; ?>">
00097 
00098 <head>
00099 <title>phpMyAdmin</title>
00100 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>" />
00101 
00102 <style type="text/css">
00103 <!--
00104 body  {font-family: sans-serif; font-size: small; color: #000000; background-color: #F5F5F5}
00105 h1    {font-family: sans-serif; font-size: large; font-weight: bold}
00106 //-->
00107 </style>
00108 </head>
00109 
00110 
00111 <body bgcolor="#ffffff">
00112 <h1>phpMyAdmin - <?php echo $strError; ?></h1>
00113 <p>
00114 <?php echo $strConfigFileError; ?><br /><br />
00115 <a href="config.inc.php" target="_blank">config.inc.php</a>
00116 </p>
00117 </body>
00118 
00119 </html>
00120     <?php
00121     exit();
00122 }
00123 error_reporting($old_error_reporting);
00124 unset($old_error_reporting, $cfgfile_to_load);
00125 
00130 if (isset($cfg['FileRevision'])) {
00131     // converting revision string into an array
00132     //     e.g. "Revision: 2.0" becomes array(2, 0).
00133     $cfg['FileRevision'] = str_replace('$' . 'Revision: ', '', $cfg['FileRevision']);
00134     $cfg['FileRevision'] = str_replace(' $', '', $cfg['FileRevision']);
00135     $cfg['FileRevision'] = explode('.', $cfg['FileRevision']);
00136 } else {
00137     $cfg['FileRevision'] = array(1, 1);
00138 }
00139 if ($cfg['FileRevision'][0] < 2 || ($cfg['FileRevision'][0] == 2 && $cfg['FileRevision'][1] < 4)) {
00140     require_once('./libraries/config_import.lib.php');
00141 }
00142 
00146 require_once('./libraries/select_lang.lib.php');
00147 
00148 if ($is_minimum_common == FALSE) {
00152     require_once('./libraries/mysql_wrappers.lib.php');
00153 }
00154 
00160 require_once('./libraries/defines.lib.php');
00161 
00162 if ($is_minimum_common == FALSE) {
00167       $is_upload = TRUE;
00168       if (strtolower(@ini_get('file_uploads')) == 'off'
00169              || @ini_get('file_uploads') == 0) {
00170           $is_upload = FALSE;
00171       }
00172 
00180     function get_real_size($size=0) {
00182         if (!$size) {
00183             return 0;
00184         }
00185         $scan['MB'] = 1048576;
00186         $scan['Mb'] = 1048576;
00187         $scan['M'] = 1048576;
00188         $scan['m'] = 1048576;
00189         $scan['KB'] = 1024;
00190         $scan['Kb'] = 1024;
00191         $scan['K'] = 1024;
00192         $scan['k'] = 1024;
00193 
00194         while (list($key) = each($scan)) {
00195             if ((strlen($size)>strlen($key))&&(substr($size, strlen($size) - strlen($key))==$key)) {
00196                 $size = substr($size, 0, strlen($size) - strlen($key)) * $scan[$key];
00197                 break;
00198             }
00199         }
00200         return $size;
00201     } // end function
00202 
00203 
00204     if (!$filesize = ini_get('upload_max_filesize')) {
00205         $filesize = "5M";
00206     }
00207     $max_upload_size = get_real_size($filesize);
00208 
00209     if ($postsize = ini_get('post_max_size')) {
00210         $postsize = get_real_size($postsize);
00211         if ($postsize < $max_upload_size) {
00212             $max_upload_size = $postsize;
00213         }
00214     }
00215     unset($filesize);
00216     unset($postsize);
00217 
00231      function PMA_displayMaximumUploadSize($max_upload_size) {
00232          list($max_size, $max_unit) = PMA_formatByteDown($max_upload_size);
00233          return '(' . sprintf($GLOBALS['strMaximumSize'], $max_size, $max_unit) . ')';
00234      }
00235 
00246      function PMA_generateHiddenMaxFileSize($max_size){
00247          return '<input type="hidden" name="MAX_FILE_SIZE" value="' .$max_size . '" />';
00248      }
00249 
00253     require_once('./libraries/charset_conversion.lib.php');
00254 }
00255 
00256 if ($is_minimum_common == FALSE) {
00260     require_once('./libraries/string.lib.php');
00261 }
00262 
00263 // If zlib output compression is set in the php configuration file, no
00264 // output buffering should be run
00265 if (@ini_get('zlib.output_compression')) {
00266     $cfg['OBGzip'] = FALSE;
00267 }
00268 
00269 // disable output-buffering (if set to 'auto') for IE6, else enable it.
00270 if (strtolower($cfg['OBGzip']) == 'auto') {
00271     if (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 6 && PMA_USR_BROWSER_VER < 7) {
00272         $cfg['OBGzip'] = FALSE;
00273     } else {
00274         $cfg['OBGzip'] = TRUE;
00275     }
00276 }
00277 
00278 if ($is_minimum_common == FALSE) {
00282     require_once('./libraries/url_generating.lib.php');
00283 
00287     if (!@function_exists('mysql_connect')) {
00288         PMA_dl('mysql');
00289     }
00290 
00291     // check whether mysql is available
00292     if (!@function_exists('mysql_connect')) {
00293         if (empty($is_header_sent)) {
00294             require_once('./libraries/header_http.inc.php');
00295         }
00296         echo $strCantLoadMySQL . '<br />' . "\n"
00297              . '<a href="./Documentation.html#faqmysql" target="documentation">' . $GLOBALS['strDocu'] . '</a>' . "\n";
00298         exit();
00299     }
00300 
00301 
00316     function PMA_sqlAddslashes($a_string = '', $is_like = FALSE, $crlf = FALSE)
00317     {
00318         if ($is_like) {
00319             $a_string = str_replace('\\', '\\\\\\\\', $a_string);
00320         } else {
00321             $a_string = str_replace('\\', '\\\\', $a_string);
00322         }
00323 
00324         if ($crlf) {
00325             $a_string = str_replace("\n", '\n', $a_string);
00326             $a_string = str_replace("\r", '\r', $a_string);
00327             $a_string = str_replace("\t", '\t', $a_string);
00328         }
00329 
00330         $a_string = str_replace('\'', '\\\'', $a_string);
00331 
00332         return $a_string;
00333     } // end of the 'PMA_sqlAddslashes()' function
00334 
00335 
00347     function PMA_escape_mysql_wildcards($name)
00348     {
00349         $name = str_replace('_', '\\_', $name);
00350         $name = str_replace('%', '\\%', $name);
00351 
00352         return $name;
00353     } // end of the 'PMA_escape_mysql_wildcards()' function
00354 
00355 
00370     function PMA_formatSql($parsed_sql, $unparsed_sql = '')
00371     {
00372         global $cfg;
00373 
00374         // Check that we actually have a valid set of parsed data
00375         // well, not quite
00376         // first check for the SQL parser having hit an error
00377         if (PMA_SQP_isError()) {
00378             return $parsed_sql;
00379         }
00380         // then check for an array
00381         if (!is_array($parsed_sql)) {
00382             // We don't so just return the input directly
00383             // This is intended to be used for when the SQL Parser is turned off
00384             $formatted_sql = '<pre>' . "\n"
00385                             . (($cfg['SQP']['fmtType'] == 'none' && $unparsed_sql != '') ? $unparsed_sql : $parsed_sql) . "\n"
00386                             . '</pre>';
00387             return $formatted_sql;
00388         }
00389 
00390         $formatted_sql        = '';
00391 
00392         switch ($cfg['SQP']['fmtType']) {
00393             case 'none':
00394                 if ($unparsed_sql != '') {
00395                     $formatted_sql = "<pre>\n" . PMA_SQP_formatNone(array('raw' => $unparsed_sql)) . "\n</pre>";
00396                 } else {
00397                     $formatted_sql = PMA_SQP_formatNone($parsed_sql);
00398                 }
00399                 break;
00400             case 'html':
00401                 $formatted_sql = PMA_SQP_formatHtml($parsed_sql,'color');
00402                 break;
00403             case 'text':
00404                 //$formatted_sql = PMA_SQP_formatText($parsed_sql);
00405                 $formatted_sql = PMA_SQP_formatHtml($parsed_sql,'text');
00406                 break;
00407             default:
00408                 break;
00409         } // end switch
00410 
00411         return $formatted_sql;
00412     } // end of the "PMA_formatSql()" function
00413 
00414 
00425     function PMA_showMySQLDocu($chapter, $link)
00426     {
00427         if (!empty($GLOBALS['cfg']['MySQLManualBase'])) {
00428             if (!empty($GLOBALS['cfg']['MySQLManualType'])) {
00429                 switch ($GLOBALS['cfg']['MySQLManualType']) {
00430                     case 'old':
00431                         return '[<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/' . $link[0] . '/' . $link[1] . '/' . $link . '.html" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]';
00432                     case 'chapters':
00433                         return '[<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/manual_' . $chapter . '.html#' . $link . '" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]';
00434                     case 'big':
00435                         return '[<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '#' . $link . '" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]';
00436                     case 'none':
00437                         return '';
00438                     case 'searchable':
00439                     default:
00440                         return '[<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/' . $link . '.html" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]';
00441                 }
00442             } else {
00443                 // no Type defined, show the old one
00444                 return '[<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/' . $link[0] . '/' . $link[1] . '/' . $link . '.html" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]';
00445             }
00446         } else {
00447             // no URL defined
00448             if (!empty($GLOBALS['cfg']['ManualBaseShort'])) {
00449                 // the old configuration
00450                 return '[<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/' . $link[0] . '/' . $link[1] . '/' . $link . '.html" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]';
00451             } else {
00452                 return '';
00453             }
00454         }
00455     } // end of the 'PMA_showDocu()' function
00456 
00470     function PMA_mysqlDie($error_message = '', $the_query = '',
00471                             $is_modify_link = TRUE, $back_url = '',
00472                             $exit = TRUE)
00473     {
00474         global $cfg, $table, $db, $sql_query;
00475 
00476         require_once('./header.inc.php');
00477 
00478         if (!$error_message) {
00479             $error_message = PMA_mysql_error();
00480         }
00481         if (!$the_query && !empty($GLOBALS['sql_query'])) {
00482             $the_query = $GLOBALS['sql_query'];
00483         }
00484 
00485         // --- Added to solve bug #641765
00486         // Robbat2 - 12 January 2003, 9:46PM
00487         // Revised, Robbat2 - 13 Janurary 2003, 2:59PM
00488         if (PMA_SQP_isError()) {
00489             $parsed_sql = htmlspecialchars($the_query);
00490         } else {
00491             $parsed_sql = PMA_SQP_parse($the_query);
00492         }
00493         // ---
00494 
00495         echo '<p><b>'. $GLOBALS['strError'] . '</b></p>' . "\n";
00496         // if the config password is wrong, or the MySQL server does not
00497         // respond, do not show the query that would reveal the
00498         // username/password
00499         if (!empty($the_query) && !strstr($the_query, 'connect')) {
00500             // --- Added to solve bug #641765
00501             // Robbat2 - 12 January 2003, 9:46PM
00502             // Revised, Robbat2 - 13 Janurary 2003, 2:59PM
00503             if (PMA_SQP_isError()) {
00504                 echo PMA_SQP_getErrorString();
00505             }
00506             // ---
00507             echo '<p>' . "\n";
00508             echo '    ' . $GLOBALS['strSQLQuery'] . '&nbsp;:&nbsp;' . "\n";
00509             if ($is_modify_link && isset($db)) {
00510                 echo '    ['
00511                         . '<a href="db_details.php?' . PMA_generate_common_url($GLOBALS['db']) . '&amp;sql_query=' . urlencode($the_query) . '&amp;show_query=1">' . $GLOBALS['strEdit'] . '</a>'
00512                         . ']' . "\n";
00513             } // end if
00514             echo '</p>' . "\n"
00515                     . '<p>' . "\n"
00516                     . '    ' . PMA_formatSql($parsed_sql, $the_query) . "\n"
00517                     . '</p>' . "\n";
00518         } // end if
00519         if (!empty($error_message)) {
00520             $error_message = htmlspecialchars($error_message);
00521             $error_message = preg_replace("@((\015\012)|(\015)|(\012)){3,}@", "\n\n", $error_message);
00522         }
00523         echo '<p>' . "\n"
00524                 . '    ' . $GLOBALS['strMySQLSaid'] . '<br />' . "\n"
00525                 . '</p>' . "\n";
00526 
00527         // The error message will be displayed within a CODE segment.
00528         // To preserve original formatting, but allow wordwrapping, we do a couple of replacements
00529 
00530         // Replace all non-single blanks with their HTML-counterpart
00531         $error_message = str_replace('  ', '&nbsp;&nbsp;', $error_message);
00532         // Replace TAB-characters with their HTML-counterpart
00533         $error_message = str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', $error_message);
00534         // Replace linebreaks
00535         $error_message = nl2br($error_message);
00536 
00537         echo '<code>' . "\n"
00538                 . $error_message . "\n"
00539                 . '</code><br /><br />' . "\n";
00540 
00541         echo PMA_showMySQLDocu('Error-returns', 'Error-returns');
00542 
00543         if (!empty($back_url) && $exit) {
00544             echo '&nbsp;&middot;&nbsp;[<a href="' . (strstr($back_url, '?') ? $back_url . '&amp;no_history=true' : $back_url . '?no_history=true') . '">' . $GLOBALS['strBack'] . '</a>]';
00545         }
00546         echo "\n";
00547 
00548         if ($exit) {
00549             require_once('./footer.inc.php');
00550         }
00551     } // end of the 'PMA_mysqlDie()' function
00552 
00553 
00565     function PMA_isInto($toFind = '', &$in)
00566     {
00567         $max = count($in);
00568         for ($i = 0; $i < $max && ($toFind != $in[$i]); $i++) {
00569             // void();
00570         }
00571 
00572         return ($i < $max) ? $i : -1;
00573     }  // end of the 'PMA_isInto()' function
00574 }
00575 
00591 function PMA_safe_db_list($only_db_check, $dbh, $dblist_cnt, $rs, $userlink, $cfg, $dblist) {
00592 
00593     if ($only_db_check == FALSE) {
00594         // ... first checks whether the "safe_show_database" is on or not
00595         //     (if MYSQL supports this)
00596         $is_safe_show_dbs = FALSE;
00597         if (PMA_MYSQL_INT_VERSION >= 40002) {
00598             $is_safe_show_dbs = 'ON';
00599         }
00600         else {
00601             $local_query      = 'SHOW VARIABLES LIKE \'safe\\_show\\_database\'';
00602             $rs               = PMA_mysql_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE);
00603             $is_safe_show_dbs = ($rs) ? @PMA_mysql_result($rs, 0, 'Value') : FALSE;
00604             mysql_free_result($rs);
00605         }
00606 
00607         // ... and if on, try to get the available dbs list
00608         if ($is_safe_show_dbs && strtoupper($is_safe_show_dbs) != 'OFF') {
00609             $uva_alldbs   = mysql_list_dbs($userlink);
00610             while ($uva_row = PMA_mysql_fetch_array($uva_alldbs)) {
00611                   $dblist[] = $uva_row[0];
00612             } // end while
00613             $dblist_cnt   = count($dblist);
00614             unset($uva_alldbs);
00615         } // end if ($is_safe_show_dbs)
00616 
00617         // ... else checks for available databases in the "mysql" db
00618         if (!$dblist_cnt) {
00619             $auth_query   = 'SELECT User, Select_priv '
00620                           . 'FROM mysql.user '
00621                           . 'WHERE User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\'';
00622             $rs           = PMA_mysql_query($auth_query, $dbh); // Debug: or PMA_mysqlDie('', $auth_query, FALSE);
00623         } // end
00624     }
00625 
00626     // Access to "mysql" db allowed and dblist still empty -> gets the
00627     // usable db list
00628     if (!$dblist_cnt
00629         && ($rs && @mysql_numrows($rs))) {
00630         $row = PMA_mysql_fetch_array($rs);
00631         mysql_free_result($rs);
00632         // Correction uva 19991215
00633         // Previous code assumed database "mysql" admin table "db" column
00634         // "db" contains literal name of user database, and works if so.
00635         // Mysql usage generally (and uva usage specifically) allows this
00636         // column to contain regular expressions (we have all databases
00637         // owned by a given student/faculty/staff beginning with user i.d.
00638         // and governed by default by a single set of privileges with
00639         // regular expression as key). This breaks previous code.
00640         // This maintenance is to fix code to work correctly for regular
00641         // expressions.
00642         if ($row['Select_priv'] != 'Y') {
00643 
00644             // 1. get allowed dbs from the "mysql.db" table
00645             // lem9: User can be blank (anonymous user)
00646             $local_query = 'SELECT DISTINCT Db FROM mysql.db WHERE Select_priv = \'Y\' AND (User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\' OR User = \'\')';
00647             $rs          = PMA_mysql_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE);
00648             if ($rs && @mysql_numrows($rs)) {
00649                 // Will use as associative array of the following 2 code
00650                 // lines:
00651                 //   the 1st is the only line intact from before
00652                 //     correction,
00653                 //   the 2nd replaces $dblist[] = $row['Db'];
00654                 $uva_mydbs = array();
00655                 // Code following those 2 lines in correction continues
00656                 // populating $dblist[], as previous code did. But it is
00657                 // now populated with actual database names instead of
00658                 // with regular expressions.
00659                 while ($row = PMA_mysql_fetch_array($rs)) {
00660                     // loic1: all databases cases - part 1
00661                     if (empty($row['Db']) || $row['Db'] == '%') {
00662                         $uva_mydbs['%'] = 1;
00663                         break;
00664                     }
00665                     // loic1: avoid multiple entries for dbs
00666                     if (!isset($uva_mydbs[$row['Db']])) {
00667                         $uva_mydbs[$row['Db']] = 1;
00668                     }
00669                 } // end while
00670                 mysql_free_result($rs);
00671                 $uva_alldbs = mysql_list_dbs($dbh);
00672                 // loic1: all databases cases - part 2
00673                 if (isset($uva_mydbs['%'])) {
00674                     while ($uva_row = PMA_mysql_fetch_array($uva_alldbs)) {
00675                         $dblist[] = $uva_row[0];
00676                     } // end while
00677                 } // end if
00678                 else {
00679                     while ($uva_row = PMA_mysql_fetch_array($uva_alldbs)) {
00680                         $uva_db = $uva_row[0];
00681                         if (isset($uva_mydbs[$uva_db]) && $uva_mydbs[$uva_db] == 1) {
00682                             $dblist[]           = $uva_db;
00683                             $uva_mydbs[$uva_db] = 0;
00684                         } else if (!isset($dblist[$uva_db])) {
00685                             foreach($uva_mydbs AS $uva_matchpattern => $uva_value) {
00686                                 // loic1: fixed bad regexp
00687                                 // TODO: db names may contain characters
00688                                 //       that are regexp instructions
00689                                 $re        = '(^|(\\\\\\\\)+|[^\])';
00690                                 $uva_regex = ereg_replace($re . '%', '\\1.*', ereg_replace($re . '_', '\\1.{1}', $uva_matchpattern));
00691                                 // Fixed db name matching
00692                                 // 2000-08-28 -- Benjamin Gandon
00693                                 if (ereg('^' . $uva_regex . '$', $uva_db)) {
00694                                     $dblist[] = $uva_db;
00695                                     break;
00696                                 }
00697                             } // end while
00698                         } // end if ... else if....
00699                     } // end while
00700                 } // end else
00701                 mysql_free_result($uva_alldbs);
00702                 unset($uva_mydbs);
00703             } // end if
00704 
00705             // 2. get allowed dbs from the "mysql.tables_priv" table
00706             $local_query = 'SELECT DISTINCT Db FROM mysql.tables_priv WHERE Table_priv LIKE \'%Select%\' AND User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\'';
00707             $rs          = PMA_mysql_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE);
00708             if ($rs && @mysql_numrows($rs)) {
00709                 while ($row = PMA_mysql_fetch_array($rs)) {
00710                     if (PMA_isInto($row['Db'], $dblist) == -1) {
00711                         $dblist[] = $row['Db'];
00712                     }
00713                 } // end while
00714                 mysql_free_result($rs);
00715             } // end if
00716         } // end if
00717     } // end building available dbs from the "mysql" db
00718 
00719     return $dblist;
00720 }
00721 
00740 function PMA_setFontSizes()
00741 {
00742     global $font_size, $font_biggest, $font_bigger, $font_smaller, $font_smallest;
00743 
00744     // IE (<6)/Opera (<7) for win case: needs smaller fonts than anyone else
00745     if (PMA_USR_OS == 'Win'
00746         && ((PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 6)
00747         || (PMA_USR_BROWSER_AGENT == 'OPERA' && PMA_USR_BROWSER_VER < 7))) {
00748         $font_size     = 'x-small';
00749         $font_biggest  = 'large';
00750         $font_bigger   = 'medium';
00751         $font_smaller  = '90%';
00752         $font_smallest = '7pt';
00753     }
00754     // IE6 and other browsers for win case
00755     else if (PMA_USR_OS == 'Win') {
00756         $font_size     = 'small';
00757         $font_biggest  = 'large';
00758         $font_bigger   = 'medium';
00759         $font_smaller  = (PMA_USR_BROWSER_AGENT == 'IE')
00760                         ? '90%'
00761                         : 'x-small';
00762         $font_smallest = 'x-small';
00763     }
00764     // Some mac browsers need also smaller default fonts size (OmniWeb &
00765     // Opera)...
00766     // and a beta version of Safari did also, but not the final 1.0 version
00767     // so I remove   || PMA_USR_BROWSER_AGENT == 'SAFARI'
00768     // but we got a report that Safari 1.0 build 85.5 needs it!
00769 
00770     else if (PMA_USR_OS == 'Mac'
00771                 && (PMA_USR_BROWSER_AGENT == 'OMNIWEB' || PMA_USR_BROWSER_AGENT == 'OPERA' || PMA_USR_BROWSER_AGENT == 'SAFARI')) {
00772         $font_size     = 'x-small';
00773         $font_biggest  = 'large';
00774         $font_bigger   = 'medium';
00775         $font_smaller  = '90%';
00776         $font_smallest = '7pt';
00777     }
00778     // ... but most of them (except IE 5+ & NS 6+) need bigger fonts
00779     else if ((PMA_USR_OS == 'Mac'
00780                 && ((PMA_USR_BROWSER_AGENT != 'IE' && PMA_USR_BROWSER_AGENT != 'MOZILLA')
00781                     || PMA_USR_BROWSER_VER < 5))
00782             || PMA_USR_BROWSER_AGENT == 'KONQUEROR') {
00783         $font_size     = 'medium';
00784         $font_biggest  = 'x-large';
00785         $font_bigger   = 'large';
00786         $font_smaller  = 'small';
00787         $font_smallest = 'x-small';
00788     }
00789     // OS/2 browser
00790     else if (PMA_USR_OS == 'OS/2'
00791                 && PMA_USR_BROWSER_AGENT == 'OPERA') {
00792         $font_size     = 'small';
00793         $font_biggest  = 'medium';
00794         $font_bigger   = 'medium';
00795         $font_smaller  = 'x-small';
00796         $font_smallest = 'x-small';
00797     }
00798     else {
00799         $font_size     = 'small';
00800         $font_biggest  = 'large';
00801         $font_bigger   = 'medium';
00802         $font_smaller  = 'x-small';
00803         $font_smallest = 'x-small';
00804     }
00805 
00806     return TRUE;
00807 } // end of the 'PMA_setFontSizes()' function
00808 
00809 
00810 if ($is_minimum_common == FALSE) {
00816     $display_pmaAbsoluteUri_warning = 0;
00817 
00818     // Olivier: Setup a default value to let the people and lazy syadmins
00819     //          work anyway, but display a big warning on the main.php
00820     //          page.
00821     if (empty($cfg['PmaAbsoluteUri'])) {
00822         if (!empty($_SERVER)) {
00823             $SERVER_ARRAY = '_SERVER';
00824         } else {
00825             $SERVER_ARRAY = 'GLOBALS';
00826         } // end if
00827         if (isset(${$SERVER_ARRAY}['HTTP_HOST'])) {
00828             $HTTP_HOST = ${$SERVER_ARRAY}['HTTP_HOST'];
00829         }
00830         if (isset(${$SERVER_ARRAY}['HTTPS'])) {
00831             $HTTPS = ${$SERVER_ARRAY}['HTTPS'];
00832         }
00833         if (isset(${$SERVER_ARRAY}['SERVER_PORT'])) {
00834             $SERVER_PORT = ${$SERVER_ARRAY}['SERVER_PORT'];
00835         }
00836         if (isset(${$SERVER_ARRAY}['REQUEST_URI'])) {
00837             $REQUEST_URI = ${$SERVER_ARRAY}['REQUEST_URI'];
00838         }
00839         if (isset(${$SERVER_ARRAY}['PATH_INFO'])) {
00840             $PATH_INFO = ${$SERVER_ARRAY}['PATH_INFO'];
00841         }
00842         if (isset(${$SERVER_ARRAY}['HTTP_SCHEME'])) {
00843             $HTTP_SCHEME = ${$SERVER_ARRAY}['HTTP_SCHEME'];
00844         }
00845         if (!empty($HTTP_SCHEME)) {
00846             $cfg['PmaAbsoluteUri']      = $HTTP_SCHEME . '://';
00847         } else {
00848             $cfg['PmaAbsoluteUri']      = ((!empty($HTTPS) && strtolower($HTTPS) != 'off') ? 'https' : 'http') . '://';
00849         }
00850         $port_in_HTTP_HOST              = (strpos($HTTP_HOST, ':') > 0);
00851         $cfg['PmaAbsoluteUri']          .= $HTTP_HOST;
00852 
00853         // if $cfg['PmaAbsoluteUri'] is empty and port == 80 or port == 443, do not add ":80" or ":443"
00854         // to the generated URL -> prevents a double password query in case of http authentication.
00855 
00856         if (!(!$port_in_HTTP_HOST && !empty($SERVER_PORT) && ($SERVER_PORT == 80 || $SERVER_PORT == 443))) {
00857             $cfg['PmaAbsoluteUri']      .= ((!empty($SERVER_PORT) && !$port_in_HTTP_HOST) ? ':' . $SERVER_PORT : '');
00858         }
00859 
00860         // rabus: if php is in CGI mode, $PHP_SELF often contains the path to the CGI executable.
00861         //   This is why we try to get the path from $REQUEST_URI or $PATH_INFO first.
00862         if (isset($REQUEST_URI)) {
00863             $cfg['PmaAbsoluteUri']      .= substr($REQUEST_URI, 0, strrpos($REQUEST_URI, '/') + 1);
00864         } else if (isset($PATH_INFO)) {
00865             $cfg['PmaAbsoluteUri']      .= substr($PATH_INFO, 0, strrpos($PATH_INFO, '/') + 1);
00866         } else {
00867             $cfg['PmaAbsoluteUri']      .= substr($PHP_SELF, 0, strrpos($PHP_SELF, '/') + 1);
00868         }
00869 
00870         // We display the warning by default, but not if it is disabled thru
00871         // via the $cfg['PmaAbsoluteUri_DisableWarning'] variable.
00872         // This is intended for sysadmins that actually want the default
00873         // behaviour of auto-detection due to their setup.
00874         // See the mailing list message:
00875         // http://sourceforge.net/mailarchive/forum.php?thread_id=859093&forum_id=2141
00876         if ($cfg['PmaAbsoluteUri_DisableWarning'] == FALSE) {
00877             $display_pmaAbsoluteUri_warning = 1;
00878         }
00879     } else {
00880         // The URI is specified, however users do often specify this
00881         // wrongly, so we try to fix this.
00882 
00883         // Adds a trailing slash et the end of the phpMyAdmin uri if it
00884         // does not exist.
00885         if (substr($cfg['PmaAbsoluteUri'], -1) != '/') {
00886             $cfg['PmaAbsoluteUri'] .= '/';
00887         }
00888 
00889         // If URI doesn't start with http:// or https://, we will add
00890         // this.
00891         if (substr($cfg['PmaAbsoluteUri'], 0, 7) != 'http://' && substr($cfg['PmaAbsoluteUri'], 0, 8) != 'https://') {
00892             if (!empty($_SERVER)) {
00893                 $SERVER_ARRAY = '_SERVER';
00894             } else {
00895                 $SERVER_ARRAY = 'GLOBALS';
00896             } // end if
00897             if (isset(${$SERVER_ARRAY}['HTTPS'])) {
00898                 $HTTPS = ${$SERVER_ARRAY}['HTTPS'];
00899             }
00900 
00901             $cfg['PmaAbsoluteUri']          = ((!empty($HTTPS) && strtolower($HTTPS) != 'off') ? 'https' : 'http') . ':'
00902                                             . (substr($cfg['PmaAbsoluteUri'], 0, 2) == '//' ? '' : '//')
00903                                             . $cfg['PmaAbsoluteUri'];
00904         }
00905     }
00906 
00907 
00911     $connect_func = ($cfg['PersistentConnections']) ? 'mysql_pconnect' : 'mysql_connect';
00912     $dblist       = array();
00913 
00914 
00918     foreach($cfg['Servers'] AS $key => $val) {
00919         // Don't use servers with no hostname
00920         if ( ($val['connect_type'] == 'tcp') && empty($val['host'])) {
00921             unset($cfg['Servers'][$key]);
00922         }
00923 
00924         // Final solution to bug #582890
00925         // If we are using a socket connection
00926         // and there is nothing in the verbose server name
00927         // or the host field, then generate a name for the server
00928         // in the form of "Server 2", localized of course!
00929         if ( ($val['connect_type'] == 'socket') && empty($val['host']) && empty($val['verbose']) ) {
00930             $cfg['Servers'][$key]['verbose'] = sprintf($GLOBALS['strServer'], $key);
00931             $val['verbose']                  = sprintf($GLOBALS['strServer'],$key);
00932         }
00933     }
00934 
00935     if (empty($server) || !isset($cfg['Servers'][$server]) || !is_array($cfg['Servers'][$server])) {
00936         $server = $cfg['ServerDefault'];
00937     }
00938 
00939 
00948     if ($server == 0) {
00949         $cfg['Server'] = array();
00950     }
00951 
00955     else if (isset($cfg['Servers'][$server])) {
00956         $cfg['Server'] = $cfg['Servers'][$server];
00957 
00958         // Check how the config says to connect to the server
00959         $server_port   = (empty($cfg['Server']['port']))
00960                        ? ''
00961                        : ':' . $cfg['Server']['port'];
00962         if (strtolower($cfg['Server']['connect_type']) == 'tcp') {
00963             $cfg['Server']['socket'] = '';
00964         }
00965         $server_socket = (empty($cfg['Server']['socket']))
00966                        ? ''
00967                        : ':' . $cfg['Server']['socket'];
00968         if (PMA_MYSQL_CLIENT_API >= 32349) {
00969             $client_flags = $cfg['Server']['compress'] && defined('MYSQL_CLIENT_COMPRESS') ? MYSQL_CLIENT_COMPRESS : 0;
00970         }
00971 
00972         // Gets the authentication library that fits the $cfg['Server'] settings
00973         // and run authentication
00974 
00975         // (for a quick check of path disclosure in auth/cookies:)
00976         $coming_from_common = TRUE;
00977 
00978         require_once('./libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php');
00979         if (!PMA_auth_check()) {
00980             PMA_auth();
00981         } else {
00982             PMA_auth_set_user();
00983         }
00984 
00985         // Check IP-based Allow/Deny rules as soon as possible to reject the
00986         // user
00987         // Based on mod_access in Apache:
00988         // http://cvs.apache.org/viewcvs.cgi/httpd-2.0/modules/aaa/mod_access.c?rev=1.37&content-type=text/vnd.viewcvs-markup
00989         // Look at: "static int check_dir_access(request_rec *r)"
00990         // Robbat2 - May 10, 2002
00991         if (isset($cfg['Server']['AllowDeny']) && isset($cfg['Server']['AllowDeny']['order'])) {
00992             require_once('./libraries/ip_allow_deny.lib.php');
00993 
00994             $allowDeny_forbidden         = FALSE; // default
00995             if ($cfg['Server']['AllowDeny']['order'] == 'allow,deny') {
00996                 $allowDeny_forbidden     = TRUE;
00997                 if (PMA_allowDeny('allow')) {
00998                     $allowDeny_forbidden = FALSE;
00999                 }
01000                 if (PMA_allowDeny('deny')) {
01001                     $allowDeny_forbidden = TRUE;
01002                 }
01003             } else if ($cfg['Server']['AllowDeny']['order'] == 'deny,allow') {
01004                 if (PMA_allowDeny('deny')) {
01005                     $allowDeny_forbidden = TRUE;
01006                 }
01007                 if (PMA_allowDeny('allow')) {
01008                     $allowDeny_forbidden = FALSE;
01009                 }
01010             } else if ($cfg['Server']['AllowDeny']['order'] == 'explicit') {
01011                 if (PMA_allowDeny('allow')
01012                     && !PMA_allowDeny('deny')) {
01013                     $allowDeny_forbidden = FALSE;
01014                 } else {
01015                     $allowDeny_forbidden = TRUE;
01016                 }
01017             } // end if... else if... else if
01018 
01019             // Ejects the user if banished
01020             if ($allowDeny_forbidden) {
01021                PMA_auth_fails();
01022             }
01023             unset($allowDeny_forbidden); //Clean up after you!
01024         } // end if
01025 
01026         // The user can work with only some databases
01027         if (isset($cfg['Server']['only_db']) && $cfg['Server']['only_db'] != '') {
01028             if (is_array($cfg['Server']['only_db'])) {
01029                 $dblist   = $cfg['Server']['only_db'];
01030             } else {
01031                 $dblist[] = $cfg['Server']['only_db'];
01032             }
01033         } // end if
01034 
01035         $bkp_track_err = @ini_set('track_errors', 1);
01036 
01037         // Try to connect MySQL with the control user profile (will be used to
01038         // get the privileges list for the current user but the true user link
01039         // must be open after this one so it would be default one for all the
01040         // scripts)
01041         if ($cfg['Server']['controluser'] != '') {
01042             if (empty($client_flags)) {
01043                 $dbh            = @$connect_func(
01044                                       $cfg['Server']['host'] . $server_port . $server_socket,
01045                                       $cfg['Server']['controluser'],
01046                                       $cfg['Server']['controlpass']
01047                                   );
01048             } else {
01049                 $dbh            = @$connect_func(
01050                                       $cfg['Server']['host'] . $server_port . $server_socket,
01051                                       $cfg['Server']['controluser'],
01052                                       $cfg['Server']['controlpass'],
01053                                       FALSE,
01054                                       $client_flags
01055                                   );
01056             }
01057             if ($dbh == FALSE) {
01058                 if (PMA_mysql_error()) {
01059                     $conn_error = PMA_mysql_error();
01060                 } else if (isset($php_errormsg)) {
01061                     $conn_error = $php_errormsg;
01062                 } else {
01063                     $conn_error = 'Cannot connect: invalid settings.';
01064                 }
01065                 $local_query    = $connect_func . '('
01066                                 . $cfg['Server']['host'] . $server_port . $server_socket . ', '
01067                                 . $cfg['Server']['controluser'] . ', '
01068                                 . $cfg['Server']['controlpass']
01069                                 . (empty($client_flags) ? '' : ', FALSE, ' . $client_flags)
01070                                 . ')';
01071                 require_once('./header.inc.php');
01072                 //PMA_mysqlDie($conn_error, $local_query, FALSE);
01073                 PMA_mysqlDie($conn_error, '', FALSE);
01074             } // end if
01075         } // end if
01076 
01077         // Pass #1 of DB-Config to read in master level DB-Config will go here
01078         // Robbat2 - May 11, 2002
01079 
01080         // Connects to the server (validates user's login)
01081         if (empty($client_flags)) {
01082             $userlink           = @$connect_func(
01083                                       $cfg['Server']['host'] . $server_port . $server_socket,
01084                                       $cfg['Server']['user'],
01085                                       $cfg['Server']['password']
01086                                   );
01087         } else {
01088             $userlink           = @$connect_func(
01089                                       $cfg['Server']['host'] . $server_port . $server_socket,
01090                                       $cfg['Server']['user'],
01091                                       $cfg['Server']['password'],
01092                                       FALSE,
01093                                       $client_flags
01094                                   );
01095         }
01096         if ($userlink == FALSE) {
01097             PMA_auth_fails();
01098         } // end if
01099 
01100         // Pass #2 of DB-Config to read in user level DB-Config will go here
01101         // Robbat2 - May 11, 2002
01102 
01103         @ini_set('track_errors', $bkp_track_err);
01104 
01105         // If controluser isn't defined, use the current user settings to get
01106         // his rights
01107         if ($cfg['Server']['controluser'] == '') {
01108             $dbh = $userlink;
01109         }
01110 
01111         // Gets the mysql release number
01112         require_once('./libraries/defines_mysql.lib.php');
01113 
01117         require_once('./libraries/sqlparser.lib.php');
01118 
01122         require_once('./libraries/sqlvalidator.lib.php');
01123 
01124         // if 'only_db' is set for the current user, there is no need to check for
01125         // available databases in the "mysql" db
01126         $dblist_cnt = count($dblist);
01127         if ($dblist_cnt) {
01128             $true_dblist  = array();
01129             $is_show_dbs  = TRUE;
01130 
01131             $dblist_asterisk_bool = FALSE;
01132             for ($i = 0; $i < $dblist_cnt; $i++) {
01133 
01134                 // The current position
01135                 if ($dblist[$i] == '*' && $dblist_asterisk_bool == FALSE) {
01136                     $dblist_asterisk_bool = TRUE;
01137                     $dblist_full = PMA_safe_db_list(FALSE, $dbh, FALSE, $rs, $userlink, $cfg, $dblist);
01138                     foreach($dblist_full AS $dbl_key => $dbl_val) {
01139                         if (!in_array($dbl_val, $dblist)) {
01140                             $true_dblist[] = $dbl_val;
01141                         }
01142                     }
01143 
01144                     continue;
01145                 } elseif ($dblist[$i] == '*') {
01146                     // We don't want more than one asterisk inside our 'only_db'.
01147                     continue;
01148                 }
01149                 if ($is_show_dbs && ereg('(^|[^\])(_|%)', $dblist[$i])) {
01150                     $local_query = 'SHOW DATABASES LIKE \'' . $dblist[$i] . '\'';
01151                     $rs          = PMA_mysql_query($local_query, $dbh);
01152                     // "SHOW DATABASES" statement is disabled
01153                     if ($i == 0
01154                         && (PMA_mysql_error() && mysql_errno() == 1045)) {
01155                         $true_dblist[] = str_replace('\\_', '_', str_replace('\\%', '%', $dblist[$i]));
01156                         $is_show_dbs   = FALSE;
01157                     }
01158                     // Debug
01159                     // else if (PMA_mysql_error()) {
01160                     //    PMA_mysqlDie('', $local_query, FALSE);
01161                     // }
01162                     while ($row = @PMA_mysql_fetch_row($rs)) {
01163                         $true_dblist[] = $row[0];
01164                     } // end while
01165                     if ($rs) {
01166                         mysql_free_result($rs);
01167                     }
01168                 } else {
01169                     $true_dblist[]     = str_replace('\\_', '_', str_replace('\\%', '%', $dblist[$i]));
01170                 } // end if... else...
01171             } // end for
01172             $dblist       = $true_dblist;
01173             unset($true_dblist);
01174             $only_db_check = TRUE;
01175         } // end if
01176 
01177         // 'only_db' is empty for the current user...
01178         else {
01179             $only_db_check = FALSE;
01180         } // end if (!$dblist_cnt)
01181 
01182         if (isset($dblist_full) && !count($dblist_full)) {
01183             $dblist = PMA_safe_db_list($only_db_check, $dbh, $dblist_cnt, $rs, $userlink, $cfg, $dblist);
01184         }
01185 
01186     } // end server connecting
01190     else {
01191         echo $strHostEmpty;
01192     }
01193 
01194 
01205     function PMA_availableDatabases($error_url = '')
01206     {
01207         global $dblist;
01208         global $num_dbs;
01209 
01210         $num_dbs = count($dblist);
01211 
01212         // 1. A list of allowed databases has already been defined by the
01213         //    authentification process -> gets the available databases list
01214         if ($num_dbs) {
01215             $true_dblist = array();
01216             for ($i = 0; $i < $num_dbs; $i++) {
01217                 $dblink  = @PMA_mysql_select_db($dblist[$i]);
01218                 if ($dblink) {
01219                     $true_dblist[] = $dblist[$i];
01220                 } // end if
01221             } // end for
01222             $dblist      = array();
01223             $dblist      = $true_dblist;
01224             unset($true_dblist);
01225             $num_dbs     = count($dblist);
01226         } // end if
01227 
01228         // 2. Allowed database list is empty -> gets the list of all databases
01229         //    on the server
01230         else {
01231             $dbs          = mysql_list_dbs() or PMA_mysqlDie('', 'SHOW DATABASES;', FALSE, $error_url);
01232             $num_dbs      = ($dbs) ? @mysql_num_rows($dbs) : 0;
01233             $real_num_dbs = 0;
01234             for ($i = 0; $i < $num_dbs; $i++) {
01235                 $db_name_tmp = PMA_mysql_dbname($dbs, $i);
01236                 $dblink      = @PMA_mysql_select_db($db_name_tmp);
01237                 if ($dblink) {
01238                     $dblist[] = $db_name_tmp;
01239                     $real_num_dbs++;
01240                 }
01241             } // end for
01242             mysql_free_result($dbs);
01243             $num_dbs = $real_num_dbs;
01244         } // end else
01245 
01246         return TRUE;
01247     } // end of the 'PMA_availableDatabases()' function
01248 
01249 
01250 
01251     /* ----------------------- Set of misc functions ----------------------- */
01252 
01253 
01270     function PMA_backquote($a_name, $do_it = TRUE)
01271     {
01272         if ($do_it
01273             && !empty($a_name) && $a_name != '*') {
01274 
01275             if (is_array($a_name)) {
01276                  $result = array();
01277                  foreach($a_name AS $key => $val) {
01278                      $result[$key] = '`' . $val . '`';
01279                  }
01280                  return $result;
01281             } else {
01282                 return '`' . $a_name . '`';
01283             }
01284         } else {
01285             return $a_name;
01286         }
01287     } // end of the 'PMA_backquote()' function
01288 
01289 
01302     function PMA_jsFormat($a_string = '', $add_backquotes = TRUE)
01303     {
01304         if (is_string($a_string)) {
01305             $a_string = htmlspecialchars($a_string);
01306             $a_string = str_replace('\\', '\\\\', $a_string);
01307             $a_string = str_replace('\'', '\\\'', $a_string);
01308             $a_string = str_replace('#', '\\#', $a_string);
01309             $a_string = str_replace("\012", '\\\\n', $a_string);
01310             $a_string = str_replace("\015", '\\\\r', $a_string);
01311         }
01312 
01313         return (($add_backquotes) ? PMA_backquote($a_string) : $a_string);
01314     } // end of the 'PMA_jsFormat()' function
01315 
01316 
01324     function PMA_whichCrlf()
01325     {
01326         $the_crlf = "\n";
01327 
01328         // The 'PMA_USR_OS' constant is defined in "./libraries/defines.lib.php"
01329         // Win case
01330         if (PMA_USR_OS == 'Win') {
01331             $the_crlf = "\r\n";
01332         }
01333         // Mac case
01334         else if (PMA_USR_OS == 'Mac') {
01335             $the_crlf = "\r";
01336         }
01337         // Others
01338         else {
01339             $the_crlf = "\n";
01340         }
01341 
01342         return $the_crlf;
01343     } // end of the 'PMA_whichCrlf()' function
01344 
01345 
01360     function PMA_countRecords($db, $table, $ret = FALSE)
01361     {
01362         global $err_url, $cfg;
01363         $local_query  = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
01364         $result       = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
01365         $showtable    = PMA_mysql_fetch_array($result);
01366         $num     = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
01367         if ($num < $cfg['MaxExactCount']) {
01368             unset($num);
01369         }
01370         mysql_free_result($result);
01371 
01372         if (!isset($num)) {
01373             $result = PMA_mysql_query('SELECT COUNT(*) AS num FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)) or PMA_mysqlDie('', $local_query, '', $err_url);
01374             $num    = ($result) ? PMA_mysql_result($result, 0, 'num') : 0;
01375             mysql_free_result($result);
01376         }
01377         if ($ret) {
01378             return $num;
01379         } else {
01380             echo number_format($num, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']);
01381             return TRUE;
01382         }
01383     } // end of the 'PMA_countRecords()' function
01384 
01385 
01395     function PMA_showMessage($message)
01396     {
01397         global $cfg;
01398 
01399         require_once('./header.inc.php');
01400 
01401         // Reloads the navigation frame via JavaScript if required
01402         if (isset($GLOBALS['reload']) && $GLOBALS['reload']) {
01403             echo "\n";
01404             $reload_url = './left.php?' . PMA_generate_common_url((isset($GLOBALS['db']) ? $GLOBALS['db'] : ''), '', '&')
01405             ?>
01406 <script type="text/javascript" language="javascript1.2">
01407 <!--
01408 if (typeof(window.parent) != 'undefined'
01409     && typeof(window.parent.frames['nav']) != 'undefined') {
01410     window.parent.frames['nav'].location.replace('<?php echo $reload_url; ?>&hash=' + <?php echo (($cfg['QueryFrame'] && $cfg['QueryFrameJS']) ? 'window.parent.frames[\'queryframe\'].document.hashform.hash.value' : "'" . md5($cfg['PmaAbsoluteUri']) . "'"); ?>);
01411 }
01412 //-->
01413 </script>
01414             <?php
01415             unset($GLOBALS['reload']);
01416         }
01417 
01418         // Corrects the tooltip text via JS if required
01419         else if (!empty($GLOBALS['table']) && $cfg['ShowTooltip']) {
01420             $result = @PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], TRUE) . '\'');
01421             if ($result) {
01422                 $tbl_status = PMA_mysql_fetch_array($result, MYSQL_ASSOC);
01423                 $tooltip    = (empty($tbl_status['Comment']))
01424                             ? ''
01425                             : $tbl_status['Comment'] . ' ';
01426                 $tooltip .= '(' . $tbl_status['Rows'] . ' ' . $GLOBALS['strRows'] . ')';
01427                 mysql_free_result($result);
01428                 $md5_tbl = md5($GLOBALS['table']);
01429                 echo "\n";
01430                 ?>
01431 <script type="text/javascript" language="javascript1.2">
01432 <!--
01433 if (typeof(document.getElementById) != 'undefined'
01434     && typeof(window.parent.frames['nav']) != 'undefined'
01435     && typeof(window.parent.frames['nav'].document) != 'undefined' && typeof(window.parent.frames['nav'].document) != 'unknown'
01436     && (window.parent.frames['nav'].document.getElementById('<?php echo 'tbl_' . $md5_tbl; ?>'))
01437     && typeof(window.parent.frames['nav'].document.getElementById('<?php echo 'tbl_' . $md5_tbl; ?>')) != 'undefined'
01438     && typeof(window.parent.frames['nav'].document.getElementById('<?php echo 'tbl_' . $md5_tbl; ?>').title) == 'string') {
01439     window.parent.frames['nav'].document.getElementById('<?php echo 'tbl_' . $md5_tbl; ?>').title = '<?php echo PMA_jsFormat($tooltip, FALSE); ?>';
01440 }
01441 //-->
01442 </script>
01443                 <?php
01444             } // end if
01445         } // end if... else if
01446 
01447         // Checks if the table needs to be repaired after a TRUNCATE query.
01448         if (isset($GLOBALS['table']) && isset($GLOBALS['sql_query'])
01449             && $GLOBALS['sql_query'] == 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table'])) {
01450             if (!isset($tbl_status)) {
01451                 $result = @PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], TRUE) . '\'');
01452                 if ($result) {
01453                     $tbl_status = PMA_mysql_fetch_array($result, MYSQL_ASSOC);
01454                     mysql_free_result($result);
01455                 }
01456             }
01457             if (isset($tbl_status) && (int) $tbl_status['Index_length'] > 1024) {
01458                 @PMA_mysql_query('REPAIR TABLE ' . PMA_backquote($GLOBALS['table']));
01459             }
01460         }
01461         unset($tbl_status);
01462 
01463         echo "\n";
01464         ?>
01465 <div align="<?php echo $GLOBALS['cell_align_left']; ?>">
01466     <table border="<?php echo $cfg['Border']; ?>" cellpadding="5">
01467     <tr>
01468         <td bgcolor="<?php echo $cfg['ThBgcolor']; ?>">
01469             <b><?php echo $message; ?></b><br />
01470         </td>
01471     </tr>
01472         <?php
01473         if ($cfg['ShowSQL'] == TRUE && (!empty($GLOBALS['sql_query']) || !empty($GLOBALS['display_query']))) {
01474             $local_query = !empty($GLOBALS['display_query']) ? $GLOBALS['display_query'] : (($cfg['SQP']['fmtType'] == 'none' && $GLOBALS['unparsed_sql'] != '') ? $GLOBALS['unparsed_sql'] : $GLOBALS['sql_query']);
01475             // Basic url query part
01476             $url_qpart = '?' . PMA_generate_common_url(isset($GLOBALS['db']) ? $GLOBALS['db'] : '', isset($GLOBALS['table']) ? $GLOBALS['table'] : '');
01477             echo "\n";
01478             ?>
01479     <tr>
01480         <td bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
01481             <?php
01482             echo "\n";
01483             // Html format the query to be displayed
01484             // The nl2br function isn't used because its result isn't a valid
01485             // xhtml1.0 statement before php4.0.5 ("<br>" and not "<br />")
01486             // If we want to show some sql code it is easiest to create it here
01487              /* SQL-Parser-Analyzer */
01488             $sqlnr = 1;
01489             if (!empty($GLOBALS['show_as_php'])) {
01490                 $new_line = '\'<br />' . "\n" . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;. \' ';
01491             }
01492             if (isset($new_line)) {
01493                  /* SQL-Parser-Analyzer */
01494                 $query_base = PMA_sqlAddslashes(htmlspecialchars($local_query));
01495                  /* SQL-Parser-Analyzer */
01496                 $query_base = preg_replace("@((\015\012)|(\015)|(\012))+@", $new_line, $query_base);
01497             } else {
01498                 $query_base = $local_query;
01499             }
01500             if (!empty($GLOBALS['show_as_php'])) {
01501                 $query_base = '$sql  = \'' . $query_base;
01502             } else if (!empty($GLOBALS['validatequery'])) {
01503                 $query_base = PMA_validateSQL($query_base);
01504             } else {
01505                 $parsed_sql = PMA_SQP_parse($query_base);
01506                 $query_base = PMA_formatSql($parsed_sql, $query_base);
01507             }
01508 
01509             // Prepares links that may be displayed to edit/explain the query
01510             // (don't go to default pages, we must go to the page
01511             // where the query box is available)
01512             // (also, I don't see why we should check the goto variable)
01513 
01514             //if (!isset($GLOBALS['goto'])) {
01515                 //$edit_target = (isset($GLOBALS['table'])) ? $cfg['DefaultTabTable'] : $cfg['DefaultTabDatabase'];
01516             $edit_target = isset($GLOBALS['db']) ? (isset($GLOBALS['table']) ? 'tbl_properties.php' : 'db_details.php') : '';
01517             //} else if ($GLOBALS['goto'] != 'main.php') {
01518             //    $edit_target = $GLOBALS['goto'];
01519             //} else {
01520             //    $edit_target = '';
01521             //}
01522 
01523             if (isset($cfg['SQLQuery']['Edit'])
01524                 && ($cfg['SQLQuery']['Edit'] == TRUE )
01525                 && (!empty($edit_target))) {
01526 
01527                 $onclick = '';
01528                 if ($cfg['QueryFrameJS'] && $cfg['QueryFrame']) {
01529                     $onclick = 'onclick="focus_querywindow(\'' . urlencode($local_query) . '\'); return false;"';
01530                 }
01531 
01532                 $edit_link = '&nbsp;[<a href="'
01533                            . $edit_target
01534                            . $url_qpart
01535                            . '&amp;sql_query=' . urlencode($local_query) . '&amp;show_query=1#querybox" ' . $onclick . '>' . $GLOBALS['strEdit'] . '</a>]';
01536             } else {
01537                 $edit_link = '';
01538             }
01539 
01540             // Want to have the query explained (Mike Beck 2002-05-22)
01541             // but only explain a SELECT (that has not been explained)
01542             /* SQL-Parser-Analyzer */
01543             if (isset($cfg['SQLQuery']['Explain'])
01544                 && $cfg['SQLQuery']['Explain'] == TRUE) {
01545 
01546                 // Detect if we are validating as well
01547                 // To preserve the validate uRL data
01548                 if (!empty($GLOBALS['validatequery'])) {
01549                     $explain_link_validate = '&amp;validatequery=1';
01550                 } else {
01551                     $explain_link_validate = '';
01552                 }
01553 
01554                 $explain_link = '&nbsp;[<a href="sql.php'
01555                               . $url_qpart
01556                               . $explain_link_validate
01557                               . '&amp;sql_query=';
01558 
01559                 if (preg_match('@^SELECT[[:space:]]+@i', $local_query)) {
01560                     $explain_link .= urlencode('EXPLAIN ' . $local_query) . '">' . $GLOBALS['strExplain'];
01561                 } else if (preg_match('@^EXPLAIN[[:space:]]+SELECT[[:space:]]+@i', $local_query)) {
01562                     $explain_link .= urlencode(substr($local_query, 8)) . '">' . $GLOBALS['strNoExplain'];
01563                 } else {
01564                     $explain_link = '';
01565                 }
01566                 if(!empty($explain_link)) {
01567                     $explain_link .= '</a>]';
01568                 }
01569             } else {
01570                 $explain_link = '';
01571             } //show explain
01572 
01573             // Also we would like to get the SQL formed in some nice
01574             // php-code (Mike Beck 2002-05-22)
01575             if (isset($cfg['SQLQuery']['ShowAsPHP'])
01576                 && $cfg['SQLQuery']['ShowAsPHP'] == TRUE) {
01577                 $php_link = '&nbsp;[<a href="sql.php'
01578                           . $url_qpart
01579                           . '&amp;show_query=1'
01580                           . '&amp;sql_query=' . urlencode($local_query)
01581                           . '&amp;show_as_php=';
01582 
01583                 if (!empty($GLOBALS['show_as_php'])) {
01584                     $php_link .= '0">' . $GLOBALS['strNoPhp'];
01585                 } else {
01586                     $php_link .= '1">' . $GLOBALS['strPhp'];
01587                 }
01588                 $php_link .= '</a>]';
01589 
01590                 if (isset($GLOBALS['show_as_php']) && $GLOBALS['show_as_php'] == '1') {
01591                     $php_link .= '&nbsp;[<a href="sql.php'
01592                               . $url_qpart
01593                               . '&amp;show_query=1'
01594                               . '&amp;sql_query=' . urlencode($local_query)
01595                               . '">' . $GLOBALS['strRunQuery'] . '</a>]';
01596                 }
01597 
01598             } else {
01599                 $php_link = '';
01600             } //show as php
01601 
01602             if (isset($cfg['SQLValidator']['use'])
01603                 && $cfg['SQLValidator']['use'] == TRUE
01604                 && isset($cfg['SQLQuery']['Validate'])
01605                 && $cfg['SQLQuery']['Validate'] == TRUE) {
01606                 $validate_link = '&nbsp;[<a href="sql.php'
01607                                . $url_qpart
01608                                . '&amp;show_query=1'
01609                                . '&amp;sql_query=' . urlencode($local_query)
01610                                . '&amp;validatequery=';
01611                 if (!empty($GLOBALS['validatequery'])) {
01612                     $validate_link .= '0">' .  $GLOBALS['strNoValidateSQL'] ;
01613                 } else {
01614                     $validate_link .= '1">'. $GLOBALS['strValidateSQL'] ;
01615                 }
01616                 $validate_link .= '</a>]';
01617             } else {
01618                 $validate_link = '';
01619             } //validator
01620 
01621             // Displays the message
01622             echo '            ' . $GLOBALS['strSQLQuery'] . '&nbsp;:';
01623             if (!empty($edit_target)) {
01624                 echo $edit_link . $explain_link . $php_link . $validate_link;
01625             }
01626             echo '<br />' . "\n";
01627             echo '            ' . $query_base;
01628             // If a 'LIMIT' clause has been programatically added to the query
01629             // displays it
01630             if (!empty($GLOBALS['sql_limit_to_append'])) {
01631                 if (!empty($GLOBALS['show_as_php'])) {
01632                     echo $GLOBALS['sql_limit_to_append'];
01633                 } else if (!empty($GLOBALS['validatequery'])) {
01634                     // skip the extra bit here
01635                 } else {
01636                     echo '&nbsp;' . PMA_formatSql(PMA_SQP_parse($GLOBALS['sql_limit_to_append'], $GLOBALS['sql_limit_to_append']));
01637                 }
01638             }
01639 
01640             unset($local_query);
01641             //Clean up the end of the PHP
01642             if (!empty($GLOBALS['show_as_php'])) {
01643                 echo '\';';
01644             }
01645             echo "\n";
01646             ?>
01647         </td>
01648     </tr>
01649            <?php
01650         }
01651         echo "\n";
01652         ?>
01653     </table>
01654 </div><br />
01655         <?php
01656     } // end of the 'PMA_showMessage()' function
01657 
01658 
01673     function PMA_formatByteDown($value, $limes = 6, $comma = 0)
01674     {
01675         $dh           = pow(10, $comma);
01676         $li           = pow(10, $limes);
01677         $return_value = $value;
01678         $unit         = $GLOBALS['byteUnits'][0];
01679 
01680         for ( $d = 6, $ex = 15; $d >= 1; $d--, $ex-=3 ) {
01681             if (isset($GLOBALS['byteUnits'][$d]) && $value >= $li * pow(10, $ex)) {
01682                 $value = round($value / ( pow(1024, $d) / $dh) ) /$dh;
01683                 $unit = $GLOBALS['byteUnits'][$d];
01684                 break 1;
01685             } // end if
01686         } // end for
01687 
01688         if ($unit != $GLOBALS['byteUnits'][0]) {
01689             $return_value = number_format($value, $comma, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']);
01690         } else {
01691             $return_value = number_format($value, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']);
01692         }
01693 
01694         return array($return_value, $unit);
01695     } // end of the 'PMA_formatByteDown' function
01696 
01697 
01708     function PMA_getEnumSetOptions($type_def) {
01709         $open = strpos($type_def, '(');
01710         $close = strrpos($type_def, ')');
01711         if (!$open || !$close) {
01712             return FALSE;
01713         }
01714         $options = substr($type_def, $open + 2, $close - $open - 3);
01715         $options = explode('\',\'', $options);
01716         return $options;
01717     } // end of the 'PMA_getEnumSetOptions' function
01718 
01728     function PMA_localisedDate($timestamp = -1, $format = '')
01729     {
01730         global $datefmt, $month, $day_of_week;
01731 
01732         if ($format == '') {
01733             $format = $datefmt;
01734         }
01735 
01736         if ($timestamp == -1) {
01737             $timestamp = time();
01738         }
01739 
01740         $date = preg_replace('@%[aA]@', $day_of_week[(int)strftime('%w', $timestamp)], $format);
01741         $date = preg_replace('@%[bB]@', $month[(int)strftime('%m', $timestamp)-1], $date);
01742 
01743         return strftime($date, $timestamp);
01744     } // end of the 'PMA_localisedDate()' function
01745 
01746 
01762     function PMA_printTab($text, $link, $args = '', $attr = '', $sep = '?', $active = false) {
01763         global $PHP_SELF, $cfg;
01764         global $db_details_links_count_tabs;
01765 
01766         if (((!isset($GLOBALS['active_page']) && basename($PHP_SELF) == $link) ||
01767                 $active ||
01768                 (isset($GLOBALS['active_page']) && $GLOBALS['active_page'] == $link)
01769             ) && ($text != $GLOBALS['strEmpty'] && $text != $GLOBALS['strDrop'])) {
01770             $bgcolor = 'silver';
01771         } else {
01772             $bgcolor = '#DFDFDF';
01773         }
01774 
01775         $db_details_links_count_tabs++;
01776         if (!empty($attr)) {
01777             if ($cfg['LightTabs']) {
01778                 $attr = ' ' . $attr;
01779             } else {
01780                 $attr = ' style="display:block" ' . $attr;
01781             }
01782         } else {
01783             if ($cfg['LightTabs']) {
01784                 $attr = ' ';
01785             } else {
01786                 $attr = ' style="display:block" ';
01787             }
01788         }
01789 
01790         if ($cfg['LightTabs']) {
01791             $out = '';
01792             if (strlen($link) > 0) {
01793                 $out .= '<nobr><a href="' . $link . $sep . $args . '"' . $attr . '>'
01794                      .  '<b>' . $text . '</b></a></nobr>';
01795             } else {
01796                 $out .= '<nobr><b>' . $text . '</b></nobr>';
01797             }
01798             $out = '[ ' . $out . ' ]&nbsp;&nbsp;&nbsp;';
01799         } else {
01800             $out     = "\n" . '        '
01801                      . '<td bgcolor="' . $bgcolor . '" align="center" width="64" nowrap="nowrap" class="tab">'
01802                      . "\n" . '            ';
01803             if (strlen($link) > 0) {
01804                 $out .= '<nobr><a href="' . $link . $sep . $args . '"' . $attr . '>'
01805                      .  '<b>' . $text . '</b></a></nobr>';
01806             } else {
01807                 $out .= '<nobr><b>' . $text . '</b></nobr>';
01808             }
01809             $out     .= "\n" . '        '
01810                      .  '</td>'
01811                      .  "\n" . '        '
01812                      .  '<td width="8">&nbsp;</td>';
01813         }
01814 
01815         return $out;
01816     } // end of the 'PMA_printTab()' function
01817 
01818 
01829     function PMA_linkOrButton($url, $message, $js_conf)
01830     {
01831         if (strlen($url) <= 2047) {
01832             $onclick_url        = (empty($js_conf) ? '' : ' onclick="return confirmLink(this, \'' . $js_conf . '\')"');
01833             $link_or_button     = '        <a href="' . $url . '"' . $onclick_url . '>' . "\n"
01834                                 . '           ' . $message . '</a>' . "\n";
01835         }
01836         else {
01837             $edit_url_parts     = parse_url($url);
01838             $query_parts        = explode('&', $edit_url_parts['query']);
01839             $link_or_button     = '        <form action="'
01840                                 . $edit_url_parts['path']
01841                                 . '" method="post">' . "\n";
01842             foreach($query_parts AS $query_pair) {
01843                 list($eachvar, $eachval) = explode('=', $query_pair);
01844                 $link_or_button .= '            <input type="hidden" name="' . str_replace('amp;', '', $eachvar) . '" value="' . htmlspecialchars(urldecode($eachval)) . '" />' . "\n";
01845             } // end while
01846 
01847             if (stristr($message, '<img')) {
01848                 $link_or_button     .= '            <input type="image" src="' . preg_replace('@^.*src="(.*)".*$@si', '\1', $message) . '" value="'
01849                                     . htmlspecialchars(preg_replace('@^.*alt="(.*)".*$@si', '\1', $message)) . '" />' . "\n" . '</form>' . "\n";
01850             } else {
01851                 $link_or_button     .= '            <input type="submit" value="'
01852                                     . htmlspecialchars($message) . '" />' . "\n" . '</form>' . "\n";
01853             }
01854         } // end if... else...
01855 
01856         return $link_or_button;
01857     } // end of the 'PMA_linkOrButton()' function
01858 
01859 
01867     function PMA_timespanFormat($seconds)
01868     {
01869         $return_string = '';
01870         $days = floor($seconds / 86400);
01871         if ($days > 0) {
01872             $seconds -= $days * 86400;
01873         }
01874         $hours = floor($seconds / 3600);
01875         if ($days > 0 || $hours > 0) {
01876             $seconds -= $hours * 3600;
01877         }
01878         $minutes = floor($seconds / 60);
01879         if ($days > 0 || $hours > 0 || $minutes > 0) {
01880             $seconds -= $minutes * 60;
01881         }
01882         return sprintf($GLOBALS['timespanfmt'], (string)$days, (string)$hours, (string)$minutes, (string)$seconds);
01883     }
01884 
01897     function PMA_flipstring($string, $Separator = "<br />\n") {
01898         $format_string = '';
01899         $charbuff = false;
01900 
01901         for ($i = 0; $i <= strlen($string); $i++) {
01902             $char = $string{$i};
01903             $append = false;
01904 
01905             if ($char == '&') {
01906                 $format_string .= $charbuff;
01907                 $charbuff = $char;
01908                 $append = true;
01909             } elseif (!empty($charbuff)) {
01910                 $charbuff .= $char;
01911             } elseif ($char == ';' && !empty($charbuff)) {
01912                 $format_string .= $charbuff;
01913                 $charbuff = false;
01914                 $append = true;
01915             } else {
01916                 $format_string .= $char;
01917                 $append = true;
01918             }
01919 
01920             if ($append && ($i != strlen($string))) {
01921                 $format_string .= $Separator;
01922             }
01923         }
01924 
01925         return $format_string;
01926     }
01927 
01928 
01943     function PMA_checkParameters($params, $die = TRUE) {
01944         global $PHP_SELF;
01945 
01946         $reported_script_name = basename($PHP_SELF);
01947         $found_error = FALSE;
01948         $error_message = '';
01949 
01950         foreach($params AS $param) {
01951             if (!isset($GLOBALS[$param])) {
01952                 $error_message .= $reported_script_name . ': Missing ' . $param . '<br />';
01953                 $found_error = TRUE;
01954             }
01955         }
01956         if ($found_error) {
01957             require_once('./libraries/header_meta_style.inc.php');
01958             echo '</head><body><p>' . $error_message . '</p></body></html>';
01959             if ($die) {
01960                 exit();
01961             }
01962         }
01963     } // end function
01964 
01965 
01966     // Kanji encoding convert feature appended by Y.Kawada (2002/2/20)
01967     if (@function_exists('mb_convert_encoding')
01968         && strpos(' ' . $lang, 'ja-')
01969         && file_exists('./libraries/kanji-encoding.lib.php')) {
01970         require_once('./libraries/kanji-encoding.lib.php');
01971         define('PMA_MULTIBYTE_ENCODING', 1);
01972     } // end if
01973 
01984     function PMA_checkFileExtensions($file, $extension) {
01985         if (substr($file, -1 * strlen($extension)) == $extension) {
01986             return TRUE;
01987         }
01988         if ($GLOBALS['cfg']['GZipDump'] && @function_exists('gzopen')) {
01989             if (substr($file, -3 - strlen($extension)) == $extension . '.gz') {
01990                 return TRUE;
01991             }
01992         }
01993         if ($GLOBALS['cfg']['BZipDump'] && @function_exists('bzdecompress')) {
01994             if (substr($file, -4 - strlen($extension)) == $extension . '.bz2') {
01995                 return TRUE;
01996             }
01997         }
01998         return FALSE;
01999     } // end function
02000 
02001 } // end if: minimal common.lib needed?
02002 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6