00001 <?php
00002
00003
00004
00050
00051
00052 require_once('./libraries/grab_globals.lib.php');
00053
00058 if (!isset($is_minimum_common)) {
00059 $is_minimum_common = FALSE;
00060 }
00061
00065 if (!isset($use_backquotes)) {
00066 $use_backquotes = 0;
00067 }
00068 if (!isset($pos)) {
00069 $pos = 0;
00070 }
00071
00076 unset($cfg);
00077
00081 if (file_exists('./config.inc.developer.php')) {
00082 $cfgfile_to_load = 'config.inc.developer.php';
00083 } else {
00084 $cfgfile_to_load = 'config.inc.php';
00085 }
00086
00091 $old_error_reporting = error_reporting(0);
00092
00093 $config_fd = fopen($cfgfile_to_load, 'r');
00094 $result = eval('?>' . fread($config_fd, filesize($cfgfile_to_load)));
00095 fclose($config_fd);
00096
00097 if ($result === FALSE || (!isset($cfgServers) && !isset($cfg['Servers']))) {
00098
00099 $cfg = array('DefaultLang' => 'en-iso-8859-1',
00100 'AllowAnywhereRecoding' => FALSE);
00101
00102 require_once('./libraries/select_lang.lib.php');
00103
00104
00105 header( 'Location: error.php'
00106 . '?lang=' . urlencode( $available_languages[$lang][2] )
00107 . '&char=' . urlencode( $charset )
00108 . '&dir=' . urlencode( $text_dir )
00109 . '&type=' . urlencode( $strError )
00110 . '&error=' . urlencode( strtr($strConfigFileError, array('<br />' => '[br]')) . '[br][br]' . '[a@' . $cfgfile_to_load . '@_blank]' . $cfgfile_to_load . '[/a]' )
00111 );
00112 exit();
00113 }
00114 error_reporting($old_error_reporting);
00115 unset($old_error_reporting, $cfgfile_to_load);
00116
00121 if (isset($cfg['FileRevision'])) {
00122
00123
00124 $cfg['FileRevision'] = str_replace('$' . 'Revision: ', '', $cfg['FileRevision']);
00125 $cfg['FileRevision'] = str_replace(' $', '', $cfg['FileRevision']);
00126 $cfg['FileRevision'] = explode('.', $cfg['FileRevision']);
00127 } else {
00128 $cfg['FileRevision'] = array(1, 1);
00129 }
00130 if ($cfg['FileRevision'][0] < 2 || ($cfg['FileRevision'][0] == 2 && $cfg['FileRevision'][1] < 64)) {
00131 require_once('./libraries/config_import.lib.php');
00132 }
00133
00137 require_once('./libraries/select_lang.lib.php');
00143 require_once('./libraries/defines.lib.php');
00144
00145
00146 require_once('./libraries/sanitizing.lib.php');
00147
00148
00149 if (isset($convcharset)) {
00150 $convcharset = PMA_sanitize($convcharset);
00151 }
00152
00153 if ($is_minimum_common == FALSE) {
00158 $is_upload = TRUE;
00159 if (strtolower(@ini_get('file_uploads')) == 'off'
00160 || @ini_get('file_uploads') == 0) {
00161 $is_upload = FALSE;
00162 }
00163
00171 function get_real_size($size=0) {
00173 if (!$size) {
00174 return 0;
00175 }
00176 $scan['MB'] = 1048576;
00177 $scan['Mb'] = 1048576;
00178 $scan['M'] = 1048576;
00179 $scan['m'] = 1048576;
00180 $scan['KB'] = 1024;
00181 $scan['Kb'] = 1024;
00182 $scan['K'] = 1024;
00183 $scan['k'] = 1024;
00184
00185 while (list($key) = each($scan)) {
00186 if ((strlen($size)>strlen($key))&&(substr($size, strlen($size) - strlen($key))==$key)) {
00187 $size = substr($size, 0, strlen($size) - strlen($key)) * $scan[$key];
00188 break;
00189 }
00190 }
00191 return $size;
00192 }
00193
00194
00195 if (!$filesize = ini_get('upload_max_filesize')) {
00196 $filesize = "5M";
00197 }
00198 $max_upload_size = get_real_size($filesize);
00199
00200 if ($postsize = ini_get('post_max_size')) {
00201 $postsize = get_real_size($postsize);
00202 if ($postsize < $max_upload_size) {
00203 $max_upload_size = $postsize;
00204 }
00205 }
00206 unset($filesize);
00207 unset($postsize);
00208
00222 function PMA_displayMaximumUploadSize($max_upload_size) {
00223 list($max_size, $max_unit) = PMA_formatByteDown($max_upload_size);
00224 return '(' . sprintf($GLOBALS['strMaximumSize'], $max_size, $max_unit) . ')';
00225 }
00226
00237 function PMA_generateHiddenMaxFileSize($max_size){
00238 return '<input type="hidden" name="MAX_FILE_SIZE" value="' .$max_size . '" />';
00239 }
00240
00244 require_once('./libraries/charset_conversion.lib.php');
00245
00249 require_once('./libraries/string.lib.php');
00250 }
00251
00264 function PMA_securePath($path) {
00265
00266
00267 $path = preg_replace('@\.\.*@','.',$path);
00268
00269 return $path;
00270 }
00271
00272
00273
00274 if (@ini_get('zlib.output_compression')) {
00275 $cfg['OBGzip'] = FALSE;
00276 }
00277
00278
00279 if (strtolower($cfg['OBGzip']) == 'auto') {
00280 if (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 6 && PMA_USR_BROWSER_VER < 7) {
00281 $cfg['OBGzip'] = FALSE;
00282 } else {
00283 $cfg['OBGzip'] = TRUE;
00284 }
00285 }
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295 $theme_cookie_name = 'pma_theme';
00296 if ($GLOBALS['cfg']['ThemePerServer'] && isset($server)) {
00297 $theme_cookie_name .= '-' . $server;
00298 }
00299
00300
00301 if (!$cfg['ThemeManager'] || !isset($_COOKIE[$theme_cookie_name]) || empty($_COOKIE[$theme_cookie_name])){
00302 $GLOBALS['theme'] = $cfg['ThemeDefault'];
00303 $ThemeDefaultOk = FALSE;
00304 if ($cfg['ThemePath']!='' && $cfg['ThemePath'] != FALSE) {
00305 $tmp_theme_mainpath = $cfg['ThemePath'];
00306 $tmp_theme_fullpath = $cfg['ThemePath'] . '/' .$cfg['ThemeDefault'];
00307 if (@is_dir($tmp_theme_mainpath)) {
00308 if (isset($cfg['ThemeDefault']) && @is_dir($tmp_theme_fullpath)) {
00309 $ThemeDefaultOk = TRUE;
00310 }
00311 }
00312 }
00313 if ($ThemeDefaultOk == TRUE){
00314 $GLOBALS['theme'] = $cfg['ThemeDefault'];
00315 } else {
00316 $GLOBALS['theme'] = 'original';
00317 }
00318 } else {
00319
00320
00321 if (isset($_POST['set_theme'])) {
00322 $GLOBALS['theme'] = PMA_securePath($_POST['set_theme']);
00323 } else {
00324 $GLOBALS['theme'] = PMA_securePath($_COOKIE[$theme_cookie_name]);
00325 }
00326 }
00327
00328
00329 unset($theme_name, $theme_generation, $theme_version);
00330 @include($cfg['ThemePath'] . '/' . $GLOBALS['theme'] . '/info.inc.php');
00331
00332
00333 if (!isset($theme_name, $theme_generation, $theme_version)) {
00334 $GLOBALS['theme'] = 'original';
00335 } elseif ($theme_generation != PMA_THEME_GENERATION) {
00336 $GLOBALS['theme'] = 'original';
00337 } elseif ($theme_version < PMA_THEME_VERSION) {
00338 $GLOBALS['theme'] = 'original';
00339 }
00340
00341 $pmaThemeImage = $cfg['ThemePath'] . '/' . $GLOBALS['theme'] . '/img/';
00342 $tmp_layout_file = $cfg['ThemePath'] . '/' . $GLOBALS['theme'] . '/layout.inc.php';
00343 if (@file_exists($tmp_layout_file)) {
00344 include($tmp_layout_file);
00345 }
00346 if (!is_dir($pmaThemeImage)) {
00347 $pmaThemeImage = $cfg['ThemePath'] . '/original/img/';
00348 }
00349
00350
00354
00355
00356 if (isset($_COOKIE) && !empty($_COOKIE['pma_collation_connection']) && empty($_POST['collation_connection'])) {
00357 $collation_connection = $_COOKIE['pma_collation_connection'];
00358 }
00359
00360
00361 if ($is_minimum_common == FALSE) {
00365 require_once('./libraries/url_generating.lib.php');
00366
00384 function PMA_sqlAddslashes($a_string = '', $is_like = FALSE, $crlf = FALSE, $php_code = FALSE)
00385 {
00386 if ($is_like) {
00387 $a_string = str_replace('\\', '\\\\\\\\', $a_string);
00388 } else {
00389 $a_string = str_replace('\\', '\\\\', $a_string);
00390 }
00391
00392 if ($crlf) {
00393 $a_string = str_replace("\n", '\n', $a_string);
00394 $a_string = str_replace("\r", '\r', $a_string);
00395 $a_string = str_replace("\t", '\t', $a_string);
00396 }
00397
00398 if ($php_code) {
00399 $a_string = str_replace('\'', '\\\'', $a_string);
00400 } else {
00401 $a_string = str_replace('\'', '\'\'', $a_string);
00402 }
00403
00404 return $a_string;
00405 }
00406
00407
00419 function PMA_escape_mysql_wildcards($name)
00420 {
00421 $name = str_replace('_', '\\_', $name);
00422 $name = str_replace('%', '\\%', $name);
00423
00424 return $name;
00425 }
00426
00427
00442 function PMA_formatSql($parsed_sql, $unparsed_sql = '')
00443 {
00444 global $cfg;
00445
00446
00447
00448
00449 if (PMA_SQP_isError()) {
00450 return $parsed_sql;
00451 }
00452
00453 if (!is_array($parsed_sql)) {
00454
00455
00456 $formatted_sql = '<pre>' . "\n"
00457 . (($cfg['SQP']['fmtType'] == 'none' && $unparsed_sql != '') ? $unparsed_sql : $parsed_sql) . "\n"
00458 . '</pre>';
00459 return $formatted_sql;
00460 }
00461
00462 $formatted_sql = '';
00463
00464 switch ($cfg['SQP']['fmtType']) {
00465 case 'none':
00466 if ($unparsed_sql != '') {
00467 $formatted_sql = "<pre>\n" . PMA_SQP_formatNone(array('raw' => $unparsed_sql)) . "\n</pre>";
00468 } else {
00469 $formatted_sql = PMA_SQP_formatNone($parsed_sql);
00470 }
00471 break;
00472 case 'html':
00473 $formatted_sql = PMA_SQP_formatHtml($parsed_sql,'color');
00474 break;
00475 case 'text':
00476
00477 $formatted_sql = PMA_SQP_formatHtml($parsed_sql,'text');
00478 break;
00479 default:
00480 break;
00481 }
00482
00483 return $formatted_sql;
00484 }
00485
00486
00497
00498 function PMA_showMySQLDocu($chapter, $link)
00499 {
00500
00501 if (!empty($GLOBALS['cfg']['MySQLManualBase'])) {
00502 if (!empty($GLOBALS['cfg']['MySQLManualType'])) {
00503 switch ($GLOBALS['cfg']['MySQLManualType']) {
00504 case 'old':
00505 if ($GLOBALS['cfg']['ReplaceHelpImg']) {
00506 return '<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/' . $link[0] . '/' . $link[1] . '/' . $link . '.html" target="mysql_doc"><img src="' . $GLOBALS['pmaThemeImage'] . 'b_help.png" width="11" height="11" border="0" alt="' . $GLOBALS['strDocu'] . '" title="' . $GLOBALS['strDocu'] . '" hspace="2" align="middle" /></a>';
00507 }else{
00508 return '[<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/' . $link[0] . '/' . $link[1] . '/' . $link . '.html" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]';
00509 }
00510 case 'chapters':
00511 if ($GLOBALS['cfg']['ReplaceHelpImg']) {
00512 return '<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/manual_' . $chapter . '.html#' . $link . '" target="mysql_doc"><img src="' . $GLOBALS['pmaThemeImage'] . 'b_help.png" width="11" height="11" border="0" alt="' . $GLOBALS['strDocu'] . '" title="' . $GLOBALS['strDocu'] . '" hspace="2" align="middle" /></a>';
00513 } else {
00514 return '[<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/manual_' . $chapter . '.html#' . $link . '" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]'; }
00515 case 'big':
00516 if ($GLOBALS['cfg']['ReplaceHelpImg']) {
00517 return '<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '#' . $link . '" target="mysql_doc"><img src="' . $GLOBALS['pmaThemeImage'] . 'b_help.png" width="11" height="11" border="0" alt="' . $GLOBALS['strDocu'] . '" title="' . $GLOBALS['strDocu'] . '" hspace="2" align="middle" /></a>';
00518 } else {
00519 return '[<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '#' . $link . '" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]';
00520 }
00521 case 'none':
00522 return '';
00523 case 'searchable':
00524 default:
00525 if ($GLOBALS['cfg']['ReplaceHelpImg']) {
00526 return '<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/' . $link . '.html" target="mysql_doc"><img src="' . $GLOBALS['pmaThemeImage'] . 'b_help.png" width="11" height="11" border="0" alt="' . $GLOBALS['strDocu'] . '" title="' . $GLOBALS['strDocu'] . '" hspace="2" align="middle" /></a>';
00527 } else {
00528 return '[<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/' . $link . '.html" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]';
00529 }
00530 }
00531 } else {
00532
00533 if ($GLOBALS['cfg']['ReplaceHelpImg']) {
00534 return '<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/' . $link[0] . '/' . $link[1] . '/' . $link . '.html" target="mysql_doc"><img src="' . $GLOBALS['pmaThemeImage'] . 'b_help.png" width="11" height="11" border="0" alt="' . $GLOBALS['strDocu'] . '" title="' . $GLOBALS['strDocu'] . '" hspace="2" align="middle" /></a>';
00535 } else {
00536 return '[<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/' . $link[0] . '/' . $link[1] . '/' . $link . '.html" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]';
00537 }
00538 }
00539 } else {
00540
00541 if (!empty($GLOBALS['cfg']['ManualBaseShort'])) {
00542
00543 if ($GLOBALS['cfg']['ReplaceHelpImg']) {
00544 return '<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/' . $link[0] . '/' . $link[1] . '/' . $link . '.html" target="mysql_doc"><img src="' . $GLOBALS['pmaThemeImage'] . 'b_help.png" width="11" height="11" border="0" alt="' . $GLOBALS['strDocu'] . '" title="' . $GLOBALS['strDocu'] . '" hspace="2" align="middle" /></a>';
00545 } else {
00546 return '[<a href="' . $GLOBALS['cfg']['MySQLManualBase'] . '/' . $link[0] . '/' . $link[1] . '/' . $link . '.html" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]';
00547 }
00548 } else {
00549 return '';
00550 }
00551 }
00552 }
00553
00554
00562 function PMA_showHint($hint_message)
00563 {
00564
00565 return '<img class="lightbulb" src="' . $GLOBALS['pmaThemeImage'] . 'b_tipp.png" width="16" height="16" border="0" alt="Tip" title="Tip" align="middle" onmouseover="pmaTooltip(\'' . PMA_jsFormat($hint_message, FALSE) . '\'); return false;" onmouseout="swapTooltip(\'default\'); return false;" />';
00566 }
00567
00581 function PMA_mysqlDie($error_message = '', $the_query = '',
00582 $is_modify_link = TRUE, $back_url = '',
00583 $exit = TRUE)
00584 {
00585 global $cfg, $table, $db, $sql_query;
00586
00587 require_once('./header.inc.php');
00588
00589 if (!$error_message) {
00590 $error_message = PMA_DBI_getError();
00591 }
00592 if (!$the_query && !empty($GLOBALS['sql_query'])) {
00593 $the_query = $GLOBALS['sql_query'];
00594 }
00595
00596
00597
00598
00599 if (!function_exists('PMA_SQP_isError') || PMA_SQP_isError()) {
00600 $formatted_sql = htmlspecialchars($the_query);
00601 } else {
00602 $formatted_sql = PMA_formatSql(PMA_SQP_parse(PMA_sanitize($the_query)), $the_query);
00603 }
00604
00605 echo "\n" . '<!-- PMA-SQL-ERROR -->' . "\n";
00606 echo ' <table border="0" cellpadding="2" cellspacing="1">'
00607 . ' <tr>' . "\n"
00608 . ' <th class="tblHeadError"><div class="errorhead">' . $GLOBALS['strError'] . '</div></th>' . "\n"
00609 . ' </tr>' . "\n"
00610 . ' <tr>' . "\n"
00611 . ' <td>';
00612
00613
00614
00615 if (!empty($the_query) && !strstr($the_query, 'connect')) {
00616
00617
00618
00619 if (function_exists('PMA_SQP_isError') && PMA_SQP_isError()) {
00620 echo PMA_SQP_getErrorString();
00621 }
00622
00623
00624 echo '<div class="tblWarn"><p>' . "\n";
00625 echo ' <b>' . $GLOBALS['strSQLQuery'] . ':</b>' . "\n";
00626 if (strstr(strtolower($formatted_sql),'select')) {
00627 echo PMA_showMySQLDocu('Reference', 'SELECT');
00628 }
00629 if ($is_modify_link && isset($db)) {
00630 if (isset($table)) {
00631 $doedit_goto = '<a href="tbl_properties.php?' . PMA_generate_common_url($db, $table) . '&sql_query=' . urlencode($the_query) . '&show_query=1">';
00632 } else {
00633 $doedit_goto = '<a href="db_details.php?' . PMA_generate_common_url($db) . '&sql_query=' . urlencode($the_query) . '&show_query=1">';
00634 }
00635 if ($GLOBALS['cfg']['PropertiesIconic']) {
00636 echo $doedit_goto
00637 . '<img src=" '. $GLOBALS['pmaThemeImage'] . 'b_edit.png" width="16" height="16" border="0" hspace="2" align="middle" alt="' . $GLOBALS['strEdit'] .'" />'
00638 . '</a>';
00639 } else {
00640 echo ' ['
00641 . $doedit_goto . $GLOBALS['strEdit'] . '</a>'
00642 . ']' . "\n";
00643 }
00644 }
00645 echo '</p>' . "\n"
00646 . '<p>' . "\n"
00647 . ' ' . $formatted_sql . "\n"
00648 . '</p></div>' . "\n";
00649 }
00650
00651 $tmp_mysql_error = '';
00652 if (!empty($error_message)) {
00653 $tmp_mysql_error = strtolower($error_message);
00654 $error_message = htmlspecialchars($error_message);
00655 $error_message = preg_replace("@((\015\012)|(\015)|(\012)){3,}@", "\n\n", $error_message);
00656 }
00657
00658 echo '<div class="tblWarn"><p>' . "\n"
00659 . ' <b>' . $GLOBALS['strMySQLSaid'] . '</b>'
00660 . PMA_showMySQLDocu('Error-returns', 'Error-returns')
00661 . "\n"
00662 . '</p>' . "\n";
00663
00664
00665
00666
00667
00668 $error_message = str_replace(' ', ' ', $error_message);
00669
00670 $error_message = str_replace("\t", ' ', $error_message);
00671
00672 $error_message = nl2br($error_message);
00673
00674 echo '<code>' . "\n"
00675 . $error_message . "\n"
00676 . '</code><br />' . "\n";
00677
00678
00679
00680
00681
00682 if (substr($error_message, 1, 4) == '1062') {
00683
00684 $mysql_error_values = array();
00685 $mysql_error_words = explode(' ',$tmp_mysql_error);
00686 foreach ($mysql_error_words as $mysql_error_word) {
00687 if (strstr($mysql_error_word, "'")) {
00688 $mysql_error_values = explode('-', preg_replace("/'/", "", $mysql_error_word));
00689 break;
00690 }
00691 }
00692 $duplicate_sql_query = '';
00693 if (isset($mysql_error_values[0])) {
00694 $tmp_fields = PMA_DBI_get_fields($db, $table, NULL);
00695 if ($tmp_fields) {
00696 foreach ($tmp_fields as $tmp_field) {
00697 $duplicate_sql_query .= (($duplicate_sql_query!='') ? ' OR ' : '') . PMA_backquote($tmp_field['Field']) . " LIKE '" . $mysql_error_values[0] . "'";
00698 }
00699 }
00700 }
00701 if ($duplicate_sql_query!='') {
00702 $duplicate_sql_query = "SELECT * FROM " . PMA_backquote($table) . " WHERE (" . $duplicate_sql_query . ")";
00703 } else {
00704 $duplicate_sql_query = "SELECT * FROM " . PMA_backquote($table) . "";
00705 }
00706 echo ' <form method="post" action="read_dump.php" style="padding: 0px; margin: 0px">' ."\n"
00707 . ' <input type="hidden" name="sql_query" value="' . $duplicate_sql_query . '" />' . "\n"
00708 . ' ' . PMA_generate_common_hidden_inputs($db, $table) . "\n"
00709 . ' <input type="submit" name="submit" value="' . $GLOBALS['strBrowse'] . '" />' . "\n"
00710 . ' </form>' . "\n";
00711 }
00712
00713 echo '</div>';
00714
00715 if (!empty($back_url) && $exit) {
00716 $goto_back_url='<a href="' . (strstr($back_url, '?') ? $back_url . '&no_history=true' : $back_url . '?no_history=true') . '"> ';
00717 echo ' </td> ' . "\n"
00718 . ' </tr>' . "\n"
00719 . ' <tr><td class="tblHeaders" align="center">';
00720 echo '[' . $goto_back_url . $GLOBALS['strBack'] . ' </a>]';
00721 }
00722 echo ' </td>' . "\n"
00723 . ' </tr>' . "\n"
00724 . ' </table>' . "\n\n";
00725 if ($exit) {
00726 require_once('./footer.inc.php');
00727 }
00728 }
00729
00730
00742 function PMA_isInto($toFind = '', &$in)
00743 {
00744 $max = count($in);
00745 for ($i = 0; $i < $max && ($toFind != $in[$i]); $i++) {
00746
00747 }
00748
00749 return ($i < $max) ? $i : -1;
00750 }
00751
00752
00764 function PMA_convert_using($string, $mode='unquoted') {
00765
00766 if ($mode == 'quoted') {
00767 $possible_quote = "'";
00768 } else {
00769 $possible_quote = "";
00770 }
00771
00772 if (PMA_MYSQL_INT_VERSION >= 40100) {
00773 list($conn_charset) = explode('_', $GLOBALS['collation_connection']);
00774 $converted_string = "CONVERT(" . $possible_quote . $string . $possible_quote . " USING " . $conn_charset . ")";
00775 } else {
00776 $converted_string = $possible_quote . $string . $possible_quote;
00777 }
00778 return $converted_string;
00779 }
00780
00781 }
00782
00798 function PMA_safe_db_list($only_db_check, $dbh, $dblist_cnt, $rs, $userlink, $cfg, $dblist) {
00799 if ($only_db_check == FALSE) {
00800
00801
00802 $dblist = PMA_DBI_get_dblist();
00803 $dblist_cnt = count($dblist);
00804
00805
00806
00807 if (!$dblist_cnt) {
00808 $auth_query = 'SELECT User, Select_priv '
00809 . 'FROM mysql.user '
00810 . 'WHERE User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\'';
00811 $rs = PMA_DBI_try_query($auth_query, $dbh);
00812 }
00813 }
00814
00815
00816
00817 if (!$dblist_cnt
00818 && ($rs && @PMA_DBI_num_rows($rs))) {
00819 $row = PMA_DBI_fetch_assoc($rs);
00820 PMA_DBI_free_result($rs);
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831 if ($row['Select_priv'] != 'Y') {
00832
00833
00834
00835 $local_query = 'SELECT DISTINCT Db FROM mysql.db WHERE Select_priv = \'Y\' AND (User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\' OR User = \'\')';
00836 $rs = PMA_DBI_try_query($local_query, $dbh);
00837 if ($rs && @PMA_DBI_num_rows($rs)) {
00838
00839
00840
00841
00842
00843 $uva_mydbs = array();
00844
00845
00846
00847
00848 while ($row = PMA_DBI_fetch_assoc($rs)) {
00849
00850 if (empty($row['Db']) || $row['Db'] == '%') {
00851 $uva_mydbs['%'] = 1;
00852 break;
00853 }
00854
00855 if (!isset($uva_mydbs[$row['Db']])) {
00856 $uva_mydbs[$row['Db']] = 1;
00857 }
00858 }
00859 PMA_DBI_free_result($rs);
00860 $uva_alldbs = PMA_DBI_query('SHOW DATABASES;', $GLOBALS['dbh']);
00861
00862 if (isset($uva_mydbs['%'])) {
00863 while ($uva_row = PMA_DBI_fetch_row($uva_alldbs)) {
00864 $dblist[] = $uva_row[0];
00865 }
00866 }
00867 else {
00868 while ($uva_row = PMA_DBI_fetch_row($uva_alldbs)) {
00869 $uva_db = $uva_row[0];
00870 if (isset($uva_mydbs[$uva_db]) && $uva_mydbs[$uva_db] == 1) {
00871 $dblist[] = $uva_db;
00872 $uva_mydbs[$uva_db] = 0;
00873 } else if (!isset($dblist[$uva_db])) {
00874 foreach ($uva_mydbs AS $uva_matchpattern => $uva_value) {
00875
00876
00877
00878 $re = '(^|(\\\\\\\\)+|[^\])';
00879 $uva_regex = ereg_replace($re . '%', '\\1.*', ereg_replace($re . '_', '\\1.{1}', $uva_matchpattern));
00880
00881
00882 if (ereg('^' . $uva_regex . '$', $uva_db)) {
00883 $dblist[] = $uva_db;
00884 break;
00885 }
00886 }
00887 }
00888 }
00889 }
00890 PMA_DBI_free_result($uva_alldbs);
00891 unset($uva_mydbs);
00892 }
00893
00894
00895 $local_query = 'SELECT DISTINCT Db FROM mysql.tables_priv WHERE Table_priv LIKE \'%Select%\' AND User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\'';
00896 $rs = PMA_DBI_try_query($local_query, $dbh);
00897 if ($rs && @PMA_DBI_num_rows($rs)) {
00898 while ($row = PMA_DBI_fetch_assoc($rs)) {
00899 if (PMA_isInto($row['Db'], $dblist) == -1) {
00900 $dblist[] = $row['Db'];
00901 }
00902 }
00903 PMA_DBI_free_result($rs);
00904 }
00905 }
00906 }
00907
00908 return $dblist;
00909 }
00910
00929 function PMA_setFontSizes()
00930 {
00931 global $font_size, $font_biggest, $font_bigger, $font_smaller, $font_smallest;
00932
00933
00934 if (PMA_USR_OS == 'Win'
00935 && ((PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 7)
00936 || (PMA_USR_BROWSER_AGENT == 'OPERA' && PMA_USR_BROWSER_VER < 7))) {
00937 $font_size = 'x-small';
00938 $font_biggest = 'large';
00939 $font_bigger = 'medium';
00940 $font_smaller = '90%';
00941 $font_smallest = '7pt';
00942 }
00943
00944 else if (PMA_USR_OS == 'Win') {
00945 $font_size = 'small';
00946 $font_biggest = 'large';
00947 $font_bigger = 'medium';
00948 $font_smaller = (PMA_USR_BROWSER_AGENT == 'IE')
00949 ? '90%'
00950 : 'x-small';
00951 $font_smallest = 'x-small';
00952 }
00953
00954
00955
00956
00957
00958
00959 else if (PMA_USR_OS == 'Mac'
00960 && (PMA_USR_BROWSER_AGENT == 'OMNIWEB' || PMA_USR_BROWSER_AGENT == 'OPERA' || PMA_USR_BROWSER_AGENT == 'SAFARI')) {
00961 $font_size = 'x-small';
00962 $font_biggest = 'large';
00963 $font_bigger = 'medium';
00964 $font_smaller = '90%';
00965 $font_smallest = '7pt';
00966 }
00967
00968 else if ((PMA_USR_OS == 'Mac'
00969 && ((PMA_USR_BROWSER_AGENT != 'IE' && PMA_USR_BROWSER_AGENT != 'MOZILLA')
00970 || PMA_USR_BROWSER_VER < 5))
00971 || PMA_USR_BROWSER_AGENT == 'KONQUEROR') {
00972 $font_size = 'medium';
00973 $font_biggest = 'x-large';
00974 $font_bigger = 'large';
00975 $font_smaller = 'small';
00976 $font_smallest = 'x-small';
00977 }
00978
00979 else if (PMA_USR_OS == 'OS/2'
00980 && PMA_USR_BROWSER_AGENT == 'OPERA') {
00981 $font_size = 'small';
00982 $font_biggest = 'medium';
00983 $font_bigger = 'medium';
00984 $font_smaller = 'x-small';
00985 $font_smallest = 'x-small';
00986 }
00987 else {
00988 $font_size = 'small';
00989 $font_biggest = 'large';
00990 $font_bigger = 'medium';
00991 $font_smaller = 'x-small';
00992 $font_smallest = 'x-small';
00993 }
00994
00995 return TRUE;
00996 }
00997
00998
00999 if ($is_minimum_common == FALSE) {
01006
01007
01008 if (empty($cfg['PmaAbsoluteUri'])) {
01009
01010 $url = array();
01011
01012
01013 if (!empty($_SERVER['REQUEST_URI'])) {
01014 $url = parse_url($_SERVER['REQUEST_URI']);
01015 }
01016
01017
01018 if (empty($url['scheme'])) {
01019
01020 if (!empty($_SERVER['HTTP_SCHEME'])) {
01021 $url['scheme'] = $_SERVER['HTTP_SCHEME'];
01022 } else {
01023 $url['scheme'] = (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') ? 'https' : 'http';
01024 }
01025
01026
01027 if (!empty($_SERVER['HTTP_HOST'])) {
01028 if (strpos($_SERVER['HTTP_HOST'], ':') > 0) {
01029 list($url['host'], $url['port']) = explode(':', $_SERVER['HTTP_HOST']);
01030 } else {
01031 $url['host'] = $_SERVER['HTTP_HOST'];
01032 }
01033 } else if (!empty($_SERVER['SERVER_NAME'])) {
01034 $url['host'] = $_SERVER['SERVER_NAME'];
01035 } else {
01036
01037 header( 'Location: error.php'
01038 . '?lang=' . urlencode( $available_languages[$lang][2] )
01039 . '&char=' . urlencode( $charset )
01040 . '&dir=' . urlencode( $text_dir )
01041 . '&type=' . urlencode( $strError )
01042 . '&error=' . urlencode( strtr($strPmaUriError, array('<tt>' => '[tt]', '</tt>' => '[/tt]')))
01043 );
01044 exit();
01045 }
01046
01047
01048 if (empty($url['port']) && !empty($_SERVER['SERVER_PORT'])) {
01049 $url['port'] = $_SERVER['SERVER_PORT'];
01050 }
01051
01052
01053 if (empty($url['path'])) {
01054 if (!empty($_SERVER['PATH_INFO'])) {
01055 $path = parse_url($_SERVER['PATH_INFO']);
01056 } else {
01057
01058 $path = parse_url($_SERVER['PHP_SELF']);
01059 }
01060 $url['path'] = $path['path'];
01061 unset($path);
01062 }
01063 }
01064
01065
01066 $cfg['PmaAbsoluteUri'] = $url['scheme'] . ':
01067
01068 if (!empty($url['user'])) {
01069 $cfg['PmaAbsoluteUri'] .= $url['user'];
01070 if (!empty($url['pass'])) {
01071 $cfg['PmaAbsoluteUri'] .= ':' . $url['pass'];
01072 }
01073 $cfg['PmaAbsoluteUri'] .= '@';
01074 }
01075
01076 $cfg['PmaAbsoluteUri'] .= $url['host'];
01077
01078 if (!empty($url['port']) && (($url['scheme'] == 'http' && $url['port'] != 80) || ($url['scheme'] == 'https' && $url['port'] != 443))) {
01079 $cfg['PmaAbsoluteUri'] .= ':' . $url['port'];
01080 }
01081
01082 $cfg['PmaAbsoluteUri'] .= substr($url['path'], 0, strrpos($url['path'], '/') + 1);
01083
01084 unset($url);
01085
01086
01087
01088
01089
01090
01091 } else {
01092
01093
01094
01095
01096
01097 if (substr($cfg['PmaAbsoluteUri'], -1) != '/') {
01098 $cfg['PmaAbsoluteUri'] .= '/';
01099 }
01100
01101
01102
01103 if (substr($cfg['PmaAbsoluteUri'], 0, 7) != 'http:
01104 $cfg['PmaAbsoluteUri'] = ((!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') ? 'https' : 'http') . ':'
01105 . (substr($cfg['PmaAbsoluteUri'], 0, 2) == '
01106 . $cfg['PmaAbsoluteUri'];
01107 }
01108 }
01109
01110
01111 $pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']);
01112 $cookie_path = substr($pma_uri_parts['path'], 0, strrpos($pma_uri_parts['path'], '/')) . '/';
01113 $is_https = (isset($pma_uri_parts['scheme']) && $pma_uri_parts['scheme'] == 'https') ? 1 : 0;
01114
01115 $dblist = array();
01116
01120 foreach ($cfg['Servers'] AS $key => $val) {
01121
01122 if ( ($val['connect_type'] == 'tcp') && empty($val['host'])) {
01123 unset($cfg['Servers'][$key]);
01124 }
01125
01126
01127
01128
01129
01130
01131 if ( ($val['connect_type'] == 'socket') && empty($val['host']) && empty($val['verbose']) ) {
01132 $cfg['Servers'][$key]['verbose'] = $GLOBALS['strServer'] . $key;
01133 $val['verbose'] = $GLOBALS['strServer'] . $key;
01134 }
01135 }
01136
01137 if (empty($server) || !isset($cfg['Servers'][$server]) || !is_array($cfg['Servers'][$server])) {
01138 $server = $cfg['ServerDefault'];
01139 }
01140
01141
01150 if ($server == 0) {
01151 $cfg['Server'] = array();
01152 }
01153
01157 else if (isset($cfg['Servers'][$server])) {
01158 $cfg['Server'] = $cfg['Servers'][$server];
01159
01163 require_once('./libraries/database_interface.lib.php');
01164
01165
01166
01167
01168
01169 $coming_from_common = TRUE;
01170
01171 require_once('./libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php');
01172 if (!PMA_auth_check()) {
01173 PMA_auth();
01174 } else {
01175 PMA_auth_set_user();
01176 }
01177
01178
01179
01180
01181
01182
01183
01184 if (isset($cfg['Server']['AllowDeny']) && isset($cfg['Server']['AllowDeny']['order'])) {
01185 require_once('./libraries/ip_allow_deny.lib.php');
01186
01187 $allowDeny_forbidden = FALSE;
01188 if ($cfg['Server']['AllowDeny']['order'] == 'allow,deny') {
01189 $allowDeny_forbidden = TRUE;
01190 if (PMA_allowDeny('allow')) {
01191 $allowDeny_forbidden = FALSE;
01192 }
01193 if (PMA_allowDeny('deny')) {
01194 $allowDeny_forbidden = TRUE;
01195 }
01196 } else if ($cfg['Server']['AllowDeny']['order'] == 'deny,allow') {
01197 if (PMA_allowDeny('deny')) {
01198 $allowDeny_forbidden = TRUE;
01199 }
01200 if (PMA_allowDeny('allow')) {
01201 $allowDeny_forbidden = FALSE;
01202 }
01203 } else if ($cfg['Server']['AllowDeny']['order'] == 'explicit') {
01204 if (PMA_allowDeny('allow')
01205 && !PMA_allowDeny('deny')) {
01206 $allowDeny_forbidden = FALSE;
01207 } else {
01208 $allowDeny_forbidden = TRUE;
01209 }
01210 }
01211
01212
01213 if ($allowDeny_forbidden) {
01214 PMA_auth_fails();
01215 }
01216 unset($allowDeny_forbidden);
01217 }
01218
01219
01220 if (!$cfg['Server']['AllowRoot'] && $cfg['Server']['user'] == 'root') {
01221 $allowDeny_forbidden = TRUE;
01222 PMA_auth_fails();
01223 unset($allowDeny_forbidden);
01224 }
01225
01226
01227 if (isset($cfg['Server']['only_db']) && $cfg['Server']['only_db'] != '') {
01228 if (is_array($cfg['Server']['only_db'])) {
01229 $dblist = $cfg['Server']['only_db'];
01230 } else {
01231 $dblist[] = $cfg['Server']['only_db'];
01232 }
01233 }
01234
01235 $bkp_track_err = @ini_set('track_errors', 1);
01236
01237
01238
01239
01240
01241 if ($cfg['Server']['controluser'] != '') {
01242 $dbh = PMA_DBI_connect($cfg['Server']['controluser'], $cfg['Server']['controlpass'], TRUE);
01243 } else {
01244 $dbh = PMA_DBI_connect($cfg['Server']['user'], $cfg['Server']['password'], TRUE);
01245 }
01246
01247
01248
01249
01250
01251 $userlink = PMA_DBI_connect($cfg['Server']['user'], $cfg['Server']['password'], FALSE);
01252
01253
01254
01255
01256 @ini_set('track_errors', $bkp_track_err);
01257 unset($bkp_track_err);
01258
01262 require_once('./libraries/sqlparser.lib.php');
01263
01267 require_once('./libraries/sqlvalidator.lib.php');
01268
01269
01270
01271 $dblist_cnt = count($dblist);
01272 if ($dblist_cnt) {
01273 $true_dblist = array();
01274 $is_show_dbs = TRUE;
01275
01276 $dblist_asterisk_bool = FALSE;
01277 for ($i = 0; $i < $dblist_cnt; $i++) {
01278
01279
01280 if ($dblist[$i] == '*' && $dblist_asterisk_bool == FALSE) {
01281 $dblist_asterisk_bool = TRUE;
01282 $dblist_full = PMA_safe_db_list(FALSE, $dbh, FALSE, $rs, $userlink, $cfg, $dblist);
01283 foreach ($dblist_full AS $dbl_key => $dbl_val) {
01284 if (!in_array($dbl_val, $dblist)) {
01285 $true_dblist[] = $dbl_val;
01286 }
01287 }
01288
01289 continue;
01290 } elseif ($dblist[$i] == '*') {
01291
01292 continue;
01293 }
01294 if ($is_show_dbs && ereg('(^|[^\])(_|%)', $dblist[$i])) {
01295 $local_query = 'SHOW DATABASES LIKE \'' . $dblist[$i] . '\'';
01296
01297
01298 $rs = PMA_DBI_try_query($local_query, $dbh);
01299
01300 if ($i == 0
01301 && (substr(PMA_DBI_getError($dbh), 1, 4) == 1045)) {
01302
01303 $true_dblist[] = str_replace('\\_', '_', str_replace('\\%', '%', $dblist[$i]));
01304 $is_show_dbs = FALSE;
01305 }
01306
01307
01308
01309
01310 while ($row = @PMA_DBI_fetch_row($rs)) {
01311 $true_dblist[] = $row[0];
01312 }
01313 if ($rs) {
01314 PMA_DBI_free_result($rs);
01315 }
01316 } else {
01317 $true_dblist[] = str_replace('\\_', '_', str_replace('\\%', '%', $dblist[$i]));
01318 }
01319 }
01320 $dblist = $true_dblist;
01321 unset($true_dblist);
01322 $only_db_check = TRUE;
01323 }
01324
01325
01326 else {
01327 $only_db_check = FALSE;
01328 }
01329
01330 if (isset($dblist_full) && !count($dblist_full)) {
01331 $dblist = PMA_safe_db_list($only_db_check, $dbh, $dblist_cnt, $rs, $userlink, $cfg, $dblist);
01332 }
01333
01334 }
01338 else {
01339 echo $strHostEmpty;
01340 }
01341
01350 function PMA_sendHeaderLocation($uri)
01351 {
01352 if (PMA_IS_IIS && strlen($uri) > 600) {
01353
01354 echo '<html><head><title>- - -</title>' . "\n";
01355 echo '<meta http-equiv="expires" content="0">' . "\n";
01356 echo '<meta http-equiv="Pragma" content="no-cache">' . "\n";
01357 echo '<meta http-equiv="Cache-Control" content="no-cache">' . "\n";
01358 echo '<meta http-equiv="Refresh" content="0;url=' .$uri . '">' . "\n";
01359 echo '<script language="JavaScript">' . "\n";
01360 echo 'setTimeout ("window.location = unescape(\'"' . $uri . '"\')",2000); </script>' . "\n";
01361 echo '</head>' . "\n";
01362 echo '<body> <script language="JavaScript">' . "\n";
01363 echo 'document.write (\'<p><a href="' . $uri . '">' . $GLOBALS['strGo'] . '</a></p>\');' . "\n";
01364 echo '</script></body></html>' . "\n";
01365
01366 } else {
01367 header('Location: ' . $uri);
01368 }
01369 }
01370
01371
01383 function PMA_availableDatabases($error_url = '')
01384 {
01385 global $dblist;
01386 global $num_dbs;
01387 global $cfg;
01388
01389 $num_dbs = count($dblist);
01390
01391
01392
01393 if ($num_dbs) {
01394 $true_dblist = array();
01395 for ($i = 0; $i < $num_dbs; $i++) {
01396 $dblink = @PMA_DBI_select_db($dblist[$i]);
01397 if ($dblink) {
01398 $true_dblist[] = $dblist[$i];
01399 }
01400 }
01401 $dblist = array();
01402 $dblist = $true_dblist;
01403 unset($true_dblist);
01404 $num_dbs = count($dblist);
01405 }
01406
01407
01408 else if (!isset($cfg['Server']['only_db']) || $cfg['Server']['only_db'] == '') {
01409 $dblist = PMA_DBI_get_dblist();
01410 $num_dbs = count($dblist);
01411 }
01412
01413 return TRUE;
01414 }
01415
01416
01417
01418
01419
01420
01437 function PMA_backquote($a_name, $do_it = TRUE)
01438 {
01439
01440 if ($do_it
01441 && (!empty($a_name) || $a_name == '0') && $a_name != '*') {
01442
01443 if (is_array($a_name)) {
01444 $result = array();
01445 foreach ($a_name AS $key => $val) {
01446 $result[$key] = '`' . $val . '`';
01447 }
01448 return $result;
01449 } else {
01450 return '`' . $a_name . '`';
01451 }
01452 } else {
01453 return $a_name;
01454 }
01455 }
01456
01457
01470 function PMA_jsFormat($a_string = '', $add_backquotes = TRUE)
01471 {
01472 if (is_string($a_string)) {
01473 $a_string = htmlspecialchars($a_string);
01474 $a_string = str_replace('\\', '\\\\', $a_string);
01475 $a_string = str_replace('\'', '\\\'', $a_string);
01476 $a_string = str_replace('#', '\\#', $a_string);
01477 $a_string = str_replace("\012", '\\\\n', $a_string);
01478 $a_string = str_replace("\015", '\\\\r', $a_string);
01479 }
01480
01481 return (($add_backquotes) ? PMA_backquote($a_string) : $a_string);
01482 }
01483
01484
01492 function PMA_whichCrlf()
01493 {
01494 $the_crlf = "\n";
01495
01496
01497
01498 if (PMA_USR_OS == 'Win') {
01499 $the_crlf = "\r\n";
01500 }
01501
01502 else if (PMA_USR_OS == 'Mac') {
01503 $the_crlf = "\r";
01504 }
01505
01506 else {
01507 $the_crlf = "\n";
01508 }
01509
01510 return $the_crlf;
01511 }
01512
01513
01529 function PMA_countRecords($db, $table, $ret = FALSE, $force_exact = FALSE)
01530 {
01531 global $err_url, $cfg;
01532 if (!$force_exact) {
01533 $result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';');
01534 $showtable = PMA_DBI_fetch_assoc($result);
01535 $num = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
01536 if ($num < $cfg['MaxExactCount']) {
01537 unset($num);
01538 }
01539 PMA_DBI_free_result($result);
01540 }
01541
01542 if (!isset($num)) {
01543 $result = PMA_DBI_query('SELECT COUNT(*) AS num FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table));
01544 list($num) = ($result) ? PMA_DBI_fetch_row($result) : array(0);
01545 PMA_DBI_free_result($result);
01546 }
01547 if ($ret) {
01548 return $num;
01549 } else {
01550 echo number_format($num, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']);
01551 return TRUE;
01552 }
01553 }
01554
01563 function PMA_reloadNavigation() {
01564 global $cfg;
01565
01566
01567 if (isset($GLOBALS['reload']) && $GLOBALS['reload']) {
01568 echo "\n";
01569 $reload_url = './left.php?' . PMA_generate_common_url((isset($GLOBALS['db']) ? $GLOBALS['db'] : ''), '', '&');
01570 ?>
01571 <script type="text/javascript" language="javascript1.2">
01572 <!--
01573 if (typeof(window.parent) != 'undefined'
01574 && typeof(window.parent.frames['nav']) != 'undefined') {
01575 window.parent.frames['nav'].goTo('<?php echo $reload_url; ?>&hash=' + <?php echo (($cfg['QueryFrame'] && $cfg['QueryFrameJS']) ? 'window.parent.frames[\'queryframe\'].document.hashform.hash.value' : "'" . md5($cfg['PmaAbsoluteUri']) . "'"); ?>);
01576 }
01577
01578 </script>
01579 <?php
01580 unset($GLOBALS['reload']);
01581 }
01582 }
01583
01593 function PMA_showMessage($message)
01594 {
01595 global $cfg;
01596
01597
01598 $message = PMA_sanitize($message);
01599
01600
01601 if (!empty($GLOBALS['table']) && $cfg['ShowTooltip']) {
01602 $result = PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], TRUE) . '\'');
01603 if ($result) {
01604 $tbl_status = PMA_DBI_fetch_assoc($result);
01605 $tooltip = (empty($tbl_status['Comment']))
01606 ? ''
01607 : $tbl_status['Comment'] . ' ';
01608 $tooltip .= '(' . $tbl_status['Rows'] . ' ' . $GLOBALS['strRows'] . ')';
01609 PMA_DBI_free_result($result);
01610 $md5_tbl = md5($GLOBALS['table']);
01611 echo "\n";
01612 ?>
01613 <script type="text/javascript" language="javascript1.2">
01614 <!--
01615 if (typeof(document.getElementById) != 'undefined'
01616 && typeof(window.parent.frames['nav']) != 'undefined'
01617 && typeof(window.parent.frames['nav'].document) != 'undefined' && typeof(window.parent.frames['nav'].document) != 'unknown'
01618 && (window.parent.frames['nav'].document.getElementById('<?php echo 'tbl_' . $md5_tbl; ?>'))
01619 && typeof(window.parent.frames['nav'].document.getElementById('<?php echo 'tbl_' . $md5_tbl; ?>')) != 'undefined'
01620 && typeof(window.parent.frames['nav'].document.getElementById('<?php echo 'tbl_' . $md5_tbl; ?>').title) == 'string') {
01621 window.parent.frames['nav'].document.getElementById('<?php echo 'tbl_' . $md5_tbl; ?>').title = '<?php echo PMA_jsFormat($tooltip, FALSE); ?>';
01622 }
01623
01624 </script>
01625 <?php
01626 }
01627 }
01628
01629
01630 if (isset($GLOBALS['table']) && isset($GLOBALS['sql_query'])
01631 && $GLOBALS['sql_query'] == 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table'])) {
01632 if (!isset($tbl_status)) {
01633 $result = @PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], TRUE) . '\'');
01634 if ($result) {
01635 $tbl_status = PMA_DBI_fetch_assoc($result);
01636 PMA_DBI_free_result($result);
01637 }
01638 }
01639 if (isset($tbl_status) && (int) $tbl_status['Index_length'] > 1024) {
01640 PMA_DBI_try_query('REPAIR TABLE ' . PMA_backquote($GLOBALS['table']));
01641 }
01642 }
01643 unset($tbl_status);
01644
01645 echo "\n";
01646 ?>
01647 <br />
01648 <div align="<?php echo $GLOBALS['cell_align_left']; ?>">
01649 <table border="<?php echo $cfg['Border']; ?>" cellpadding="5" cellspacing="1">
01650 <?php if (isset($GLOBALS['show_error_header']) && $GLOBALS['show_error_header']) { ?>
01651 <tr><th class="tblHeadError"><div class="errorhead"><?php echo $GLOBALS['strError']; ?></div></th></tr>
01652 <?php } ?>
01653 <tr>
01654 <th<?php echo ($GLOBALS['theme'] != 'original') ? ' class="tblHeaders"' : ' bgcolor="' . $cfg['ThBgcolor'] . '"'; ?>>
01655 <b><?php echo $message; ?></b>
01656 </th>
01657 </tr>
01658 <?php
01659 if ($cfg['ShowSQL'] == TRUE && (!empty($GLOBALS['sql_query']) || !empty($GLOBALS['display_query']))) {
01660 $local_query = !empty($GLOBALS['display_query']) ? $GLOBALS['display_query'] : (($cfg['SQP']['fmtType'] == 'none' && isset($GLOBALS['unparsed_sql']) && $GLOBALS['unparsed_sql'] != '') ? $GLOBALS['unparsed_sql'] : $GLOBALS['sql_query']);
01661
01662 $url_qpart = '?' . PMA_generate_common_url(isset($GLOBALS['db']) ? $GLOBALS['db'] : '', isset($GLOBALS['table']) ? $GLOBALS['table'] : '');
01663 echo "\n";
01664 ?>
01665 <tr>
01666 <td bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
01667 <?php
01668 echo "\n";
01669
01670
01671
01672
01673
01674
01675 if (!empty($GLOBALS['show_as_php'])) {
01676 $new_line = '\'<br />' . "\n" . ' . \' ';
01677 }
01678 if (isset($new_line)) {
01679
01680 $query_base = PMA_sqlAddslashes(htmlspecialchars($local_query), FALSE, FALSE, TRUE);
01681
01682 $query_base = preg_replace("@((\015\012)|(\015)|(\012))+@", $new_line, $query_base);
01683 } else {
01684 $query_base = $local_query;
01685 }
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699 if (preg_match('@^SELECT[[:space:]]+@i', $query_base)
01700 && isset($GLOBALS['sql_limit_to_append'])) {
01701 $query_base .= $GLOBALS['sql_limit_to_append'];
01702 }
01703
01704 if (!empty($GLOBALS['show_as_php'])) {
01705 $query_base = '$sql = \'' . $query_base;
01706 } else if (!empty($GLOBALS['validatequery'])) {
01707 $query_base = PMA_validateSQL($query_base);
01708 } else {
01709
01710 if (isset($GLOBALS['parsed_sql']) && $query_base == $GLOBALS['parsed_sql']['raw']) {
01711 $parsed_sql = $GLOBALS['parsed_sql'];
01712 } else {
01713 $parsed_sql = PMA_SQP_parse($query_base);
01714 }
01715 $query_base = PMA_formatSql($parsed_sql, $query_base);
01716 }
01717
01718
01719
01720
01721
01722
01723
01724
01725 $edit_target = isset($GLOBALS['db']) ? (isset($GLOBALS['table']) ? 'tbl_properties.php' : 'db_details.php') : '';
01726
01727
01728
01729
01730
01731
01732 if (isset($cfg['SQLQuery']['Edit'])
01733 && ($cfg['SQLQuery']['Edit'] == TRUE )
01734 && (!empty($edit_target))) {
01735
01736 $onclick = '';
01737 if ($cfg['QueryFrameJS'] && $cfg['QueryFrame']) {
01738 $onclick = 'focus_querywindow(\'' . urlencode($local_query) . '\'); return false;';
01739 }
01740
01741 $edit_link = $edit_target
01742 . $url_qpart
01743 . '&sql_query=' . urlencode($local_query)
01744 . '&show_query=1#querybox"';
01745 $edit_link = ' [' . PMA_linkOrButton( $edit_link, $GLOBALS['strEdit'], array( 'onclick' => $onclick ) ) . ']';
01746 } else {
01747 $edit_link = '';
01748 }
01749
01750 // Want to have the query explained (Mike Beck 2002-05-22)
01751 // but only explain a SELECT (that has not been explained)
01752 /* SQL-Parser-Analyzer */
01753 if (isset($cfg['SQLQuery']['Explain'])
01754 && $cfg['SQLQuery']['Explain'] == TRUE) {
01755
01756 // Detect if we are validating as well
01757 // To preserve the validate uRL data
01758 if (!empty($GLOBALS['validatequery'])) {
01759 $explain_link_validate = '&validatequery=1';
01760 } else {
01761 $explain_link_validate = '';
01762 }
01763
01764 $explain_link = 'read_dump.php'
01765 . $url_qpart
01766 . $explain_link_validate
01767 . '&sql_query=';
01768
01769 if (preg_match('@^SELECT[[:space:]]+@i', $local_query)) {
01770 $explain_link .= urlencode('EXPLAIN ' . $local_query);
01771 $message = $GLOBALS['strExplain'];
01772 } else if (preg_match('@^EXPLAIN[[:space:]]+SELECT[[:space:]]+@i', $local_query)) {
01773 $explain_link .= urlencode(substr($local_query, 8));
01774 $message = $GLOBALS['strNoExplain'];
01775 } else {
01776 $explain_link = '';
01777 }
01778 if (!empty($explain_link)) {
01779 $explain_link = ' [' . PMA_linkOrButton( $explain_link, $message ) . ']';
01780 }
01781 } else {
01782 $explain_link = '';
01783 } //show explain
01784
01785 // Also we would like to get the SQL formed in some nice
01786 // php-code (Mike Beck 2002-05-22)
01787 if (isset($cfg['SQLQuery']['ShowAsPHP'])
01788 && $cfg['SQLQuery']['ShowAsPHP'] == TRUE) {
01789 $php_link = 'read_dump.php'
01790 . $url_qpart
01791 . '&show_query=1'
01792 . '&sql_query=' . urlencode($local_query)
01793 . '&show_as_php=';
01794
01795 if (!empty($GLOBALS['show_as_php'])) {
01796 $php_link .= '0';
01797 $message = $GLOBALS['strNoPhp'];
01798 } else {
01799 $php_link .= '1';
01800 $message = $GLOBALS['strPhp'];
01801 }
01802 $php_link = ' [' . PMA_linkOrButton( $php_link, $message ) . ']';
01803
01804 if (isset($GLOBALS['show_as_php']) && $GLOBALS['show_as_php'] == '1') {
01805 $runquery_link
01806 = 'read_dump.php'
01807 . $url_qpart
01808 . '&show_query=1'
01809 . '&sql_query=' . urlencode($local_query);
01810 $php_link .= ' [' . PMA_linkOrButton( $runquery_link, $GLOBALS['strRunQuery'] ) . ']';
01811 }
01812
01813 } else {
01814 $php_link = '';
01815 } //show as php
01816
01817 // Refresh query
01818 if (isset($cfg['SQLQuery']['Refresh'])
01819 && $cfg['SQLQuery']['Refresh']
01820 && preg_match('@^(SELECT|SHOW)[[:space:]]+@i', $local_query)) {
01821
01822 $refresh_link = 'read_dump.php'
01823 . $url_qpart
01824 . '&show_query=1'
01825 . '&sql_query=' . urlencode($local_query);
01826 $refresh_link = ' [' . PMA_linkOrButton( $refresh_link, $GLOBALS['strRefresh'] ) . ']';
01827 } else {
01828 $refresh_link = '';
01829 } //show as php
01830
01831 if (isset($cfg['SQLValidator']['use'])
01832 && $cfg['SQLValidator']['use'] == TRUE
01833 && isset($cfg['SQLQuery']['Validate'])
01834 && $cfg['SQLQuery']['Validate'] == TRUE) {
01835 $validate_link = 'read_dump.php'
01836 . $url_qpart
01837 . '&show_query=1'
01838 . '&sql_query=' . urlencode($local_query)
01839 . '&validatequery=';
01840 if (!empty($GLOBALS['validatequery'])) {
01841 $validate_link .= '0';
01842 $message = $GLOBALS['strNoValidateSQL'] ;
01843 } else {
01844 $validate_link .= '1';
01845 $message = $GLOBALS['strValidateSQL'] ;
01846 }
01847 $validate_link = ' [' . PMA_linkOrButton( $validate_link, $GLOBALS['strRefresh'] ) . ']';
01848 } else {
01849 $validate_link = '';
01850 } //validator
01851
01852 // Displays the message
01853 echo ' <b>' . $GLOBALS['strSQLQuery'] . ':</b> ';
01854 echo '<br />' . "\n";
01855 echo ' ' . $query_base;
01856
01857 unset($local_query);
01858 //Clean up the end of the PHP
01859 if (!empty($GLOBALS['show_as_php'])) {
01860 echo '\';';
01861 }
01862 echo "\n";
01863 ?>
01864 </td>
01865 </tr>
01866 <?php
01867 if (!empty($edit_target)) {
01868 echo '<tr><td class="tblFooters">';
01869 echo $edit_link . $explain_link . $php_link . $refresh_link . $validate_link;
01870 echo '</td></tr>' . "\n";
01871 }
01872 }
01873 echo "\n";
01874 ?>
01875 </table>
01876 </div><br />
01877 <?php
01878 } // end of the 'PMA_showMessage()' function
01879
01880
01895 function PMA_formatByteDown($value, $limes = 6, $comma = 0)
01896 {
01897 $dh = pow(10, $comma);
01898 $li = pow(10, $limes);
01899 $return_value = $value;
01900 $unit = $GLOBALS['byteUnits'][0];
01901
01902 for ( $d = 6, $ex = 15; $d >= 1; $d--, $ex-=3 ) {
01903 if (isset($GLOBALS['byteUnits'][$d]) && $value >= $li * pow(10, $ex)) {
01904 $value = round($value / ( pow(1024, $d) / $dh) ) /$dh;
01905 $unit = $GLOBALS['byteUnits'][$d];
01906 break 1;
01907 } // end if
01908 } // end for
01909
01910 if ($unit != $GLOBALS['byteUnits'][0]) {
01911 $return_value = number_format($value, $comma, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']);
01912 } else {
01913 $return_value = number_format($value, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']);
01914 }
01915
01916 return array($return_value, $unit);
01917 } // end of the 'PMA_formatByteDown' function
01918
01919
01930 function PMA_getEnumSetOptions($type_def) {
01931 $open = strpos($type_def, '(');
01932 $close = strrpos($type_def, ')');
01933 if (!$open || !$close) {
01934 return FALSE;
01935 }
01936 $options = substr($type_def, $open + 2, $close - $open - 3);
01937 $options = explode('\',\'', $options);
01938 return $options;
01939 } // end of the 'PMA_getEnumSetOptions' function
01940
01950 function PMA_localisedDate($timestamp = -1, $format = '')
01951 {
01952 global $datefmt, $month, $day_of_week;
01953
01954 if ($format == '') {
01955 $format = $datefmt;
01956 }
01957
01958 if ($timestamp == -1) {
01959 $timestamp = time();
01960 }
01961
01962 $date = preg_replace('@%[aA]@', $day_of_week[(int)strftime('%w', $timestamp)], $format);
01963 $date = preg_replace('@%[bB]@', $month[(int)strftime('%m', $timestamp)-1], $date);
01964
01965 return strftime($date, $timestamp);
01966 } // end of the 'PMA_localisedDate()' function
01967
01968
01979 function PMA_getTab( $tab )
01980 {
01981 // default values
01982 $defaults = array(
01983 'text' => '',
01984 'class' => '',
01985 'active' => false,
01986 'link' => '',
01987 'sep' => '?',
01988 'attr' => '',
01989 'args' => '',
01990 );
01991
01992 $tab = array_merge( $defaults, $tab );
01993
01994 // determine aditional style-class
01995 if ( empty( $tab['class'] ) ) {
01996 if ($tab['text'] == $GLOBALS['strEmpty'] || $tab['text'] == $GLOBALS['strDrop']) {
01997 $tab['class'] = 'caution';
01998 }
01999 elseif ( isset( $tab['active'] ) && $tab['active']
02000 || isset($GLOBALS['active_page']) && $GLOBALS['active_page'] == $tab['link']
02001 || basename($_SERVER['PHP_SELF']) == $tab['link'] )
02002 {
02003 $tab['class'] = 'active';
02004 }
02005 }
02006
02007 // build the link
02008 if ( ! empty( $tab['link'] ) ) {
02009 $tab['link'] = htmlentities( $tab['link'] );
02010 $tab['link'] = $tab['link'] . $tab['sep'] . ( empty( $GLOBALS['url_query'] ) ? PMA_generate_common_url() : $GLOBALS['url_query'] );
02011 if ( ! empty( $tab['args'] ) ) {
02012 foreach( $tab['args'] as $param => $value ) {
02013 $tab['link'] .= '&' . urlencode( $param ) . '=' . urlencode( $value );
02014 }
02015 }
02016 }
02017
02018 // display icon, even if iconic is disabled but the link-text is missing
02019 if ( ( $GLOBALS['cfg']['MainPageIconic'] || empty( $tab['text'] ) )
02020 && isset( $tab['icon'] ) ) {
02021 $image = '<img src="' . htmlentities( $GLOBALS['pmaThemeImage'] ) . '%1$s" width="16" height="16" border="0" alt="%2$s" />%2$s';
02022 $tab['text'] = sprintf( $image, htmlentities( $tab['icon'] ), $tab['text'] );
02023 }
02024 // check to not display an empty link-text
02025 elseif ( empty( $tab['text'] ) ) {
02026 $tab['text'] = '?';
02027 trigger_error( __FILE__ . '(' . __LINE__ . '): ' . 'empty linktext in function ' . __FUNCTION__ . '()', E_USER_NOTICE );
02028 }
02029
02030 if ( ! empty( $tab['link'] ) ) {
02031 $out = '<a class="tab' . htmlentities( $tab['class'] ) . '" href="' . $tab['link'] . '" ' . $tab['attr'] . '>'
02032 . $tab['text'] . '</a>';
02033 } else {
02034 $out = '<span class="tab' . htmlentities( $tab['class'] ) . '">' . $tab['text'] . '</span>';
02035 }
02036
02037 return $out;
02038 } // end of the 'PMA_printTab()' function
02039
02047 function PMA_getTabs( $tabs, $tag_id = 'topmenu' )
02048 {
02049 $tab_navigation = '<!-- top menu -->' . "\n";
02050 $tab_navigation .= '<div id="' . htmlentities( $tag_id ) . '">' . "\n";
02051
02052 foreach ( $tabs as $tab )
02053 {
02054 $tab_navigation .= PMA_getTab( $tab ) . "\n";
02055 }
02056
02057 $tab_navigation .= '</div>' . "\n";
02058 $tab_navigation .= '<!-- end top menu -->' . "\n\n";
02059
02060 return $tab_navigation;
02061 }
02062
02063
02077 function PMA_linkOrButton($url, $message, $tag_params = array(), $new_form = TRUE, $strip_img = FALSE, $target = '')
02078 {
02079 if ( ! is_array( $tag_params ) )
02080 {
02081 $tmp = $tag_params;
02082 $tag_params = array();
02083 if ( ! empty( $tmp ) )
02084 {
02085 $tag_params['onclick'] = 'return confirmLink(this, \'' . $tmp . '\')';
02086 }
02087 unset( $tmp );
02088 }
02089 if ( ! empty( $target ) ) {
02090 $tag_params['target'] = htmlentities( $target );
02091 }
02092
02093 $tag_params_strings = array();
02094 foreach( $tag_params as $par_name => $par_value ) {
02095 // htmlentities() only on non javascript
02096 $par_value = substr( $par_name,0 ,2 ) == 'on' ? $par_value : htmlentities( $par_value );
02097 $tag_params_strings[] = $par_name . '="' . $par_value . '"';
02098 }
02099
02100
02101 if (strlen($url) <= 1000) {
02102 $ret = '<a href="' . $url . '" ' . implode( ' ', $tag_params_strings ) . '>' . "\n"
02103 . ' ' . $message . '</a>' . "\n";
02104 }
02105 else {
02106
02107
02108
02109
02110
02111 if ( empty( $tag_params['class'] ) ) {
02112 $tag_params['class'] = 'link';
02113 }
02114 $url = str_replace('&', '&', $url);
02115 $url_parts = parse_url($url);
02116 $query_parts = explode('&', $url_parts['query']);
02117 if ($new_form) {
02118 $ret = '<form action="' . $url_parts['path'] . '" class="link"'
02119 . ' method="post"' . $target . ' style="display: inline;">';
02120 $subname_open = '';
02121 $subname_close = '';
02122 $submit_name = '';
02123 } else {
02124 $query_parts[] = 'redirect=' . $url_parts['path'];
02125 if ( empty( $GLOBALS['subform_counter'] ) ) {
02126 $GLOBALS['subform_counter'] = 0;
02127 }
02128 $GLOBALS['subform_counter']++;
02129 $ret = '';
02130 $subname_open = 'subform[' . $GLOBALS['subform_counter'] . '][';
02131 $subname_close = ']';
02132 $submit_name = ' name="usesubform[' . $GLOBALS['subform_counter'] . ']"';
02133 }
02134 foreach ($query_parts AS $query_pair) {
02135 list($eachvar, $eachval) = explode('=', $query_pair);
02136 $ret .= '<input type="hidden" name="' . $subname_open . $eachvar . $subname_close . '" value="' . htmlspecialchars(urldecode($eachval)) . '" />';
02137 }
02138
02139 if (stristr($message, '<img')) {
02140 if ($strip_img) {
02141 $message = trim( strip_tags( $message ) );
02142 $ret .= '<input type="submit"' . $submit_name . ' ' . implode( ' ', $tag_params_strings )
02143 . ' value="' . htmlspecialchars($message) . '" />';
02144 } else {
02145 $ret .= '<input type="image"' . $submit_name . ' ' . implode( ' ', $tag_params_strings )
02146 . ' src="' . preg_replace('°^.*\ssrc="([^"]*)".*$°si', '\1', $message) . '"'
02147 . ' value="' . htmlspecialchars(preg_replace('°^.*\salt="([^"]*)".*$°si', '\1', $message)) . '" />';
02148 }
02149 } else {
02150 $message = trim( strip_tags( $message ) );
02151 $ret .= '<input type="submit"' . $submit_name . ' ' . implode( ' ', $tag_params_strings )
02152 . ' value="' . htmlspecialchars($message) . '" />';
02153 }
02154 if ($new_form) {
02155 $ret .= '</form>';
02156 }
02157 } // end if... else...
02158
02159 return $ret;
02160 } // end of the 'PMA_linkOrButton()' function
02161
02162
02170 function PMA_timespanFormat($seconds)
02171 {
02172 $return_string = '';
02173 $days = floor($seconds / 86400);
02174 if ($days > 0) {
02175 $seconds -= $days * 86400;
02176 }
02177 $hours = floor($seconds / 3600);
02178 if ($days > 0 || $hours > 0) {
02179 $seconds -= $hours * 3600;
02180 }
02181 $minutes = floor($seconds / 60);
02182 if ($days > 0 || $hours > 0 || $minutes > 0) {
02183 $seconds -= $minutes * 60;
02184 }
02185 return sprintf($GLOBALS['timespanfmt'], (string)$days, (string)$hours, (string)$minutes, (string)$seconds);
02186 }
02187
02200 function PMA_flipstring($string, $Separator = "<br />\n") {
02201 $format_string = '';
02202 $charbuff = false;
02203
02204 for ($i = 0; $i < strlen($string); $i++) {
02205 $char = $string{$i};
02206 $append = false;
02207
02208 if ($char == '&') {
02209 $format_string .= $charbuff;
02210 $charbuff = $char;
02211 $append = true;
02212 } elseif (!empty($charbuff)) {
02213 $charbuff .= $char;
02214 } elseif ($char == ';' && !empty($charbuff)) {
02215 $format_string .= $charbuff;
02216 $charbuff = false;
02217 $append = true;
02218 } else {
02219 $format_string .= $char;
02220 $append = true;
02221 }
02222
02223 if ($append && ($i != strlen($string))) {
02224 $format_string .= $Separator;
02225 }
02226 }
02227
02228 return $format_string;
02229 }
02230
02231
02249 function PMA_checkParameters($params, $die = TRUE) {
02250 global $PHP_SELF;
02251
02252 $reported_script_name = basename($PHP_SELF);
02253 $found_error = FALSE;
02254 $error_message = '';
02255
02256 foreach ($params AS $param) {
02257 if (!isset($GLOBALS[$param])) {
02258 $error_message .= $reported_script_name . ': Missing parameter: ' . $param . ' <a href="./Documentation.html#faqmissingparameters" target="documentation"> (FAQ 2.8)</a><br />';
02259 $found_error = TRUE;
02260 }
02261 }
02262 if ($found_error) {
02263 require_once('./libraries/header_meta_style.inc.php');
02264 echo '</head><body><p>' . $error_message . '</p></body></html>';
02265 if ($die) {
02266 exit();
02267 }
02268 }
02269 } // end function
02270
02271 // Kanji encoding convert feature appended by Y.Kawada (2002/2/20)
02272 if (@function_exists('mb_convert_encoding')
02273 && strpos(' ' . $lang, 'ja-')
02274 && file_exists('./libraries/kanji-encoding.lib.php')) {
02275 require_once('./libraries/kanji-encoding.lib.php');
02276 define('PMA_MULTIBYTE_ENCODING', 1);
02277 } // end if
02278
02290 function PMA_checkFileExtensions($file, $extension) {
02291 if (substr($file, -1 * strlen($extension)) == $extension) {
02292 return TRUE;
02293 }
02294 if ($GLOBALS['cfg']['GZipDump'] && @function_exists('gzopen')) {
02295 if (substr($file, -3 - strlen($extension)) == $extension . '.gz') {
02296 return TRUE;
02297 }
02298 }
02299 if ($GLOBALS['cfg']['BZipDump'] && @function_exists('bzdecompress')) {
02300 if (substr($file, -4 - strlen($extension)) == $extension . '.bz2') {
02301 return TRUE;
02302 }
02303 }
02304 return FALSE;
02305 } // end function
02306
02319 function PMA_getUvaCondition($handle, $fields_cnt, $fields_meta, $row) {
02320
02321 $primary_key = '';
02322 $unique_key = '';
02323 $uva_nonprimary_condition = '';
02324
02325 for ($i = 0; $i < $fields_cnt; ++$i) {
02326 $field_flags = PMA_DBI_field_flags($handle, $i);
02327 $meta = $fields_meta[$i];
02328 // do not use an alias in a condition
02329 $column_for_condition = $meta->name;
02330 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
02331 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
02332 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
02333 if (!empty($alias)) {
02334 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
02335 if ($alias == $meta->name) {
02336 $column_for_condition = $true_column;
02337 } // end if
02338 } // end if
02339 } // end while
02340 }
02341
02342 // to fix the bug where float fields (primary or not)
02343 // can't be matched because of the imprecision of
02344 // floating comparison, use CONCAT
02345 // (also, the syntax "CONCAT(field) IS NULL"
02346 // that we need on the next "if" will work)
02347 if ($meta->type == 'real') {
02348 $condition = ' CONCAT(' . PMA_backquote($column_for_condition) . ') ';
02349 } else {
02350 // string and blob fields have to be converted using
02351 // the system character set (always utf8) since
02352 // mysql4.1 can use different charset for fields.
02353 if (PMA_MYSQL_INT_VERSION >= 40100 && ($meta->type == 'string' || $meta->type == 'blob')) {
02354 $condition = ' CONVERT(' . PMA_backquote($column_for_condition) . ' USING utf8) ';
02355 } else {
02356 $condition = ' ' . PMA_backquote($column_for_condition) . ' ';
02357 }
02358 } // end if... else...
02359
02360 if (!isset($row[$i]) || is_null($row[$i])) {
02361 $condition .= 'IS NULL AND';
02362 } else {
02363 // timestamp is numeric on some MySQL 4.1
02364 if ($meta->numeric && $meta->type != 'timestamp') {
02365 $condition .= '= ' . $row[$i] . ' AND';
02366 } elseif ($meta->type == 'blob'
02367 // hexify only if this is a true not empty BLOB
02368 && stristr($field_flags, 'BINARY')
02369 && !empty($row[$i])) {
02370 // use a CAST if possible, to avoid problems
02371 // if the field contains wildcard characters % or _
02372 if (PMA_MYSQL_INT_VERSION < 40002) {
02373 $condition .= 'LIKE 0x' . bin2hex($row[$i]). ' AND';
02374 } else {
02375 $condition .= '= CAST(0x' . bin2hex($row[$i]). ' AS BINARY) AND';
02376 }
02377 } else {
02378 $condition .= '= \'' . PMA_sqlAddslashes($row[$i], FALSE, TRUE) . '\' AND';
02379 }
02380 }
02381 if ($meta->primary_key > 0) {
02382 $primary_key .= $condition;
02383 } else if ($meta->unique_key > 0) {
02384 $unique_key .= $condition;
02385 }
02386 $uva_nonprimary_condition .= $condition;
02387 } // end for
02388
02389 // Correction uva 19991216: prefer primary or unique keys
02390 // for condition, but use conjunction of all values if no
02391 // primary key
02392 if ($primary_key) {
02393 $uva_condition = $primary_key;
02394 } else if ($unique_key) {
02395 $uva_condition = $unique_key;
02396 } else {
02397 $uva_condition = $uva_nonprimary_condition;
02398 }
02399
02400 return preg_replace('|\s?AND$|', '', $uva_condition);
02401 } // end function
02402
02415 function PMA_buttonOrImage($button_name, $button_class, $image_name, $text, $image) {
02416 global $pmaThemeImage, $propicon;
02417
02418 /* Opera has trouble with <input type="image"> */
02419 /* IE has trouble with <button> */
02420 if (PMA_USR_BROWSER_AGENT != 'IE') {
02421 echo '<button class="' . $button_class . '" type="submit" name="' . $button_name . '" value="' . $text . '" title="' . $text . '">' . "\n"
02422 . '<img src="' . $pmaThemeImage . $image . '" title="' . $text . '" alt="' . $text . '" width="16" height="16" />' . (($propicon == 'both') ? ' ' . $text : '') . "\n"
02423 . '</button>' . "\n";
02424 } else {
02425 echo '<input type="image" name="' . $image_name . '" value="' .$text . '" title="' . $text . '" src="' . $pmaThemeImage . $image . '" />' . (($propicon == 'both') ? ' ' . $text : '') . "\n";
02426 }
02427 } // end function
02428
02452 function PMA_pageselector($url, $rows, $pageNow = 1, $nbTotalPage = 1, $showAll = 200, $sliceStart = 5, $sliceEnd = 5, $percent = 20, $range = 10) {
02453 $gotopage = '<br />' . $GLOBALS['strPageNumber']
02454 . '<select name="goToPage" onchange="goToUrl(this, \'' . $url . '\');">' . "\n";
02455 if ($nbTotalPage < $showAll) {
02456 $pages = range(1, $nbTotalPage);
02457 } else {
02458 $pages = array();
02459
02460 // Always show first X pages
02461 for ($i = 1; $i <= $sliceStart; $i++) {
02462 $pages[] = $i;
02463 }
02464
02465 // Always show last X pages
02466 for ($i = $nbTotalPage - $sliceEnd; $i <= $nbTotalPage; $i++) {
02467 $pages[] = $i;
02468 }
02469
02470 // garvin: Based on the number of results we add the specified $percent percentate to each page number,
02471 // so that we have a representing page number every now and then to immideately jump to specific pages.
02472 // As soon as we get near our currently chosen page ($pageNow - $range), every page number will be
02473 // shown.
02474 $i = $sliceStart;
02475 $x = $nbTotalPage - $sliceEnd;
02476 $met_boundary = false;
02477 while($i <= $x) {
02478 if ($i >= ($pageNow - $range) && $i <= ($pageNow + $range)) {
02479 // If our pageselector comes near the current page, we use 1 counter increments
02480 $i++;
02481 $met_boundary = true;
02482 } else {
02483 // We add the percentate increment to our current page to hop to the next one in range
02484 $i = $i + floor($nbTotalPage / $percent);
02485
02486 // Make sure that we do not cross our boundaries.
02487 if ($i > ($pageNow - $range) && !$met_boundary) {
02488 $i = $pageNow - $range;
02489 }
02490 }
02491
02492 if ($i > 0 && $i <= $x) {
02493 $pages[] = $i;
02494 }
02495 }
02496
02497 // Since because of ellipsing of the current page some numbers may be double,
02498 // we unify our array:
02499 sort($pages);
02500 $pages = array_unique($pages);
02501 }
02502
02503 foreach($pages AS $i) {
02504 if ($i == $pageNow) {
02505 $selected = 'selected="selected" style="font-weight: bold"';
02506 } else {
02507 $selected = '';
02508 }
02509 $gotopage .= ' <option ' . $selected . ' value="' . (($i - 1) * $rows) . '">' . $i . '</option>' . "\n";
02510 }
02511
02512 $gotopage .= ' </select>';
02513
02514 return $gotopage;
02515 } // end function
02516
02517
02518 function PMA_generateAlterTable($oldcol, $newcol, $full_field_type, $collation, $null, $default, $default_current_timestamp, $extra, $comment='') {
02519
02520 // $default_current_timestamp has priority over $default
02521 // TODO: on the interface, some js to clear the default value
02522 // when the default current_timestamp is checked
02523
02524 $query = PMA_backquote($oldcol) . ' ' . PMA_backquote($newcol) . ' '
02525 . $full_field_type;
02526 if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($collation) && $collation != 'NULL' && preg_match('@^(TINYTEXT|TEXT|MEDIUMTEXT|LONGTEXT|VARCHAR\(\d+\)|CHAR\(\d+\))$@i', $full_field_type)) {
02527 $query .= PMA_generateCharsetQueryPart($collation);
02528 }
02529
02530 if (!empty($null)) {
02531 $query .= ' NOT NULL';
02532 } else {
02533 $query .= ' NULL';
02534 }
02535
02536 if ($default_current_timestamp && strpos(' ' . strtoupper($full_field_type),'TIMESTAMP') == 1) {
02537 $query .= ' DEFAULT CURRENT_TIMESTAMP';
02538 // 0 is empty in PHP
02539 } elseif (!empty($default) || $default == '0') {
02540 if (strtoupper($default) == 'NULL') {
02541 $query .= ' DEFAULT NULL';
02542 } else {
02543 $query .= ' DEFAULT \'' . PMA_sqlAddslashes($default) . '\'';
02544 }
02545 }
02546
02547 if (!empty($extra)) {
02548 $query .= ' ' . $extra;
02549 }
02550 if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($comment)) {
02551 $query .= " COMMENT '" . PMA_sqlAddslashes($comment) . "'";
02552 }
02553 return $query;
02554 } // end function
02555
02556 } // end if: minimal common.lib needed?
02557
02558 ?>