Documentation TYPO3 par Ameos

sql.php

00001 <?php
00002 /* $Id: sql.php,v 2.5 2004/01/05 00:37:02 lem9 Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
00004 
00008 require_once('./libraries/grab_globals.lib.php');
00009 require_once('./libraries/common.lib.php');
00010 
00011 
00015 // Security checkings
00016 if (!empty($goto)) {
00017     $is_gotofile     = preg_replace('@^([^?]+).*$@s', '\\1', $goto);
00018     if (!@file_exists('./' . $is_gotofile)) {
00019         unset($goto);
00020     } else {
00021         $is_gotofile = ($is_gotofile == $goto);
00022     }
00023 } // end if (security checkings)
00024 
00025 if (empty($goto)) {
00026     $goto         = (empty($table)) ? $cfg['DefaultTabDatabase'] : $cfg['DefaultTabTable'];
00027     $is_gotofile  = TRUE;
00028 } // end if
00029 if (!isset($err_url)) {
00030     $err_url = (!empty($back) ? $back : $goto)
00031              . '?' . PMA_generate_common_url(isset($db) ? $db : '')
00032              . ((strpos(' ' . $goto, 'db_details') != 1 && isset($table)) ? '&amp;table=' . urlencode($table) : '');
00033 } // end if
00034 
00035 // Coming from a bookmark dialog
00036 if (isset($fields['query'])) {
00037     $sql_query = $fields['query'];
00038 }
00039 
00040 // This one is just to fill $db
00041 if (isset($fields['dbase'])) {
00042     $db = $fields['dbase'];
00043 }
00044 
00045 // Now we can check the parameters
00046 PMA_checkParameters(array('sql_query', 'db'));
00047 
00048 
00056 if (!defined('PMA_CHK_DROP')
00057     && !$cfg['AllowUserDropDatabase']
00058     && preg_match('@DROP[[:space:]]+DATABASE[[:space:]]+@i', $sql_query)) {
00059     // Checks if the user is a Superuser
00060     // TODO: set a global variable with this information
00061     // loic1: optimized query
00062     $result = @PMA_mysql_query('USE mysql');
00063     if (PMA_mysql_error()) {
00064         require_once('./header.inc.php');
00065         PMA_mysqlDie($strNoDropDatabases, '', '', $err_url);
00066     } // end if
00067 } // end if
00068 
00069 
00073 if (isset($store_bkm)) {
00074     require_once('./libraries/bookmark.lib.php');
00075     PMA_addBookmarks($fields, $cfg['Bookmark'], (isset($bkm_all_users) && $bkm_all_users == 'true' ? true : false));
00076     header('Location: ' . $cfg['PmaAbsoluteUri'] . $goto);
00077 } // end if
00078 
00079 
00083 // $sql_query has been urlencoded in the confirmation form for drop/delete
00084 // queries or in the navigation bar for browsing among records
00085 if (isset($btnDrop) || isset($navig)) {
00086     $sql_query = urldecode($sql_query);
00087 }
00088 
00093 $GLOBALS['unparsed_sql'] = $sql_query;
00094 $parsed_sql = PMA_SQP_parse($sql_query);
00095 $analyzed_sql = PMA_SQP_analyze($parsed_sql);
00096 // Bug #641765 - Robbat2 - 12 January 2003, 10:49PM
00097 // Reverted - Robbat2 - 13 January 2003, 2:40PM
00098 $sql_query = PMA_SQP_formatHtml($parsed_sql, 'query_only');
00099 
00100 // old code did not work, for example, when there is a bracket
00101 // before the SELECT
00102 // so I guess it's ok to check for a real SELECT ... FROM
00103 //$is_select = eregi('^SELECT[[:space:]]+', $sql_query);
00104 $is_select = isset($analyzed_sql[0]['queryflags']['select_from']);
00105 
00106 // If the query is a Select, extract the db and table names and modify
00107 // $db and $table, to have correct page headers, links and left frame.
00108 // db and table name may be enclosed with backquotes, db is optionnal,
00109 // query may contain aliases.
00110 
00111 // (TODO: if there are more than one table name in the Select:
00112 // - do not extract the first table name
00113 // - do not show a table name in the page header
00114 // - do not display the sub-pages links)
00115 
00116 if ($is_select) {
00117     $prev_db = $db;
00118     if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name'])) {
00119         $table = $analyzed_sql[0]['table_ref'][0]['table_true_name'];
00120     }
00121     if (isset($analyzed_sql[0]['table_ref'][0]['db'])
00122        && !empty($analyzed_sql[0]['table_ref'][0]['db'])) {
00123         $db    = $analyzed_sql[0]['table_ref'][0]['db'];
00124     }
00125     else {
00126         $db = $prev_db;
00127     }
00128     $reload  = ($db == $prev_db) ? 0 : 1;
00129 }
00130 
00134 if ($goto == 'sql.php') {
00135     $goto = 'sql.php?'
00136           . PMA_generate_common_url($db, $table)
00137           . '&amp;pos=' . $pos
00138           . '&amp;sql_query=' . urlencode($sql_query);
00139 } // end if
00140 
00141 
00145 if (isset($btnDrop) && $btnDrop == $strNo) {
00146     if (!empty($back)) {
00147         $goto = $back;
00148     }
00149     if ($is_gotofile) {
00150         if (strpos(' ' . $goto, 'db_details') == 1 && !empty($table)) {
00151             unset($table);
00152         }
00153         $active_page = $goto;
00154         require('./' . preg_replace('@\.\.*@', '.', $goto));
00155     } else {
00156         header('Location: ' . $cfg['PmaAbsoluteUri'] . str_replace('&amp;', '&', $goto));
00157     }
00158     exit();
00159 } // end if
00160 
00161 
00171 if (!$cfg['Confirm']
00172     || (isset($is_js_confirmed) && $is_js_confirmed)
00173     || isset($btnDrop)
00174 
00175     // if we are coming from a "Create PHP code" or a "Without PHP Code"
00176     // dialog, we won't execute the query anyway, so don't confirm
00177     //|| !empty($GLOBALS['show_as_php'])
00178     || isset($GLOBALS['show_as_php'])
00179 
00180     || !empty($GLOBALS['validatequery'])) {
00181     $do_confirm = FALSE;
00182 } else {
00183     //$do_confirm = (eregi('DROP[[:space:]]+(IF[[:space:]]+EXISTS[[:space:]]+)?(TABLE|DATABASE[[:space:]])|ALTER[[:space:]]+TABLE[[:space:]]+((`[^`]+`)|([A-Za-z0-9_$]+))[[:space:]]+DROP[[:space:]]|DELETE[[:space:]]+FROM[[:space:]]', $sql_query));
00184 
00185     $do_confirm = isset($analyzed_sql[0]['queryflags']['need_confirm']);
00186 }
00187 
00188 if ($do_confirm) {
00189     $stripped_sql_query = $sql_query;
00190     require_once('./header.inc.php');
00191     echo $strDoYouReally . '&nbsp;:<br />' . "\n";
00192     echo '<tt>' . htmlspecialchars($stripped_sql_query) . '</tt>&nbsp;?<br/>' . "\n";
00193     ?>
00194 <form action="sql.php" method="post">
00195     <?php echo PMA_generate_common_hidden_inputs($db, (isset($table)?$table:'')); ?>
00196     <input type="hidden" name="sql_query" value="<?php echo urlencode($sql_query); ?>" />
00197     <input type="hidden" name="zero_rows" value="<?php echo isset($zero_rows) ? $zero_rows : ''; ?>" />
00198     <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
00199     <input type="hidden" name="back" value="<?php echo isset($back) ? $back : ''; ?>" />
00200     <input type="hidden" name="reload" value="<?php echo isset($reload) ? $reload : 0; ?>" />
00201     <input type="hidden" name="purge" value="<?php echo isset($purge) ? $purge : ''; ?>" />
00202     <input type="hidden" name="cpurge" value="<?php echo isset($cpurge) ? $cpurge : ''; ?>" />
00203     <input type="hidden" name="purgekey" value="<?php echo isset($purgekey) ? $purgekey : ''; ?>" />
00204     <input type="hidden" name="show_query" value="<?php echo isset($show_query) ? $show_query : ''; ?>" />
00205     <input type="submit" name="btnDrop" value="<?php echo $strYes; ?>" />
00206     <input type="submit" name="btnDrop" value="<?php echo $strNo; ?>" />
00207 </form>
00208     <?php
00209     echo "\n";
00210 } // end if
00211 
00212 
00216 else {
00217     if (!isset($sql_query)) {
00218         $sql_query = '';
00219     }
00220     // Defines some variables
00221     // loic1: A table has to be created -> left frame should be reloaded
00222     if ((!isset($reload) || $reload == 0)
00223         && preg_match('@^CREATE TABLE[[:space:]]+(.*)@i', $sql_query)) {
00224         $reload           = 1;
00225     }
00226     // Gets the number of rows per page
00227     if (empty($session_max_rows)) {
00228         $session_max_rows = $cfg['MaxRows'];
00229     } else if ($session_max_rows != 'all') {
00230         $cfg['MaxRows']   = $session_max_rows;
00231     }
00232     // Defines the display mode (horizontal/vertical) and header "frequency"
00233     if (empty($disp_direction)) {
00234         $disp_direction   = $cfg['DefaultDisplay'];
00235     }
00236     if (empty($repeat_cells)) {
00237         $repeat_cells     = $cfg['RepeatCells'];
00238     }
00239 
00240     // SK -- Patch: $is_group added for use in calculation of total number of
00241     //              rows.
00242     //              $is_count is changed for more correct "LIMIT" clause
00243     //              appending in queries like
00244     //                "SELECT COUNT(...) FROM ... GROUP BY ..."
00245 
00246     // TODO: detect all this with the parser, to avoid problems finding
00247     // those strings in comments or backquoted identifiers
00248 
00249     $is_explain = $is_count = $is_export = $is_delete = $is_insert = $is_affected = $is_show = $is_maint = $is_analyse = $is_group = $is_func = FALSE;
00250     if ($is_select) { // see line 141
00251         $is_group = preg_match('@(GROUP[[:space:]]+BY|HAVING|SELECT[[:space:]]+DISTINCT)[[:space:]]+@i', $sql_query);
00252         $is_func =  !$is_group && (preg_match('@[[:space:]]+(SUM|AVG|STD|STDDEV|MIN|MAX|BIT_OR|BIT_AND)\s*\(@i', $sql_query));
00253         $is_count = !$is_group && (preg_match('@^SELECT[[:space:]]+COUNT\((.*\.+)?.*\)@i', $sql_query));
00254         $is_export   = (preg_match('@[[:space:]]+INTO[[:space:]]+OUTFILE[[:space:]]+@i', $sql_query));
00255         $is_analyse  = (preg_match('@[[:space:]]+PROCEDURE[[:space:]]+ANALYSE@i', $sql_query));
00256     } else if (preg_match('@^EXPLAIN[[:space:]]+@i', $sql_query)) {
00257         $is_explain  = TRUE;
00258     } else if (preg_match('@^DELETE[[:space:]]+@i', $sql_query)) {
00259         $is_delete   = TRUE;
00260         $is_affected = TRUE;
00261     } else if (preg_match('@^(INSERT|LOAD[[:space:]]+DATA|REPLACE)[[:space:]]+@i', $sql_query)) {
00262         $is_insert   = TRUE;
00263         $is_affected = TRUE;
00264     } else if (preg_match('@^UPDATE[[:space:]]+@i', $sql_query)) {
00265         $is_affected = TRUE;
00266     } else if (preg_match('@^SHOW[[:space:]]+@i', $sql_query)) {
00267         $is_show     = TRUE;
00268     } else if (preg_match('@^(CHECK|ANALYZE|REPAIR|OPTIMIZE)[[:space:]]+TABLE[[:space:]]+@i', $sql_query)) {
00269         $is_maint    = TRUE;
00270     }
00271 
00272     // Do append a "LIMIT" clause?
00273     if (isset($pos)
00274         && (!$cfg['ShowAll'] || $session_max_rows != 'all')
00275         && !($is_count || $is_export || $is_func || $is_analyse)
00276         && isset($analyzed_sql[0]['queryflags']['select_from'])
00277         && !preg_match('@[[:space:]]LIMIT[[:space:]0-9,-]+$@i', $sql_query)) {
00278         $sql_limit_to_append = " LIMIT $pos, ".$cfg['MaxRows'];
00279         if (preg_match('@(.*)([[:space:]](PROCEDURE[[:space:]](.*)|FOR[[:space:]]+UPDATE|LOCK[[:space:]]+IN[[:space:]]+SHARE[[:space:]]+MODE))$@i', $sql_query, $regs)) {
00280             $full_sql_query  = $regs[1] . $sql_limit_to_append . $regs[2];
00281         } else {
00282             $full_sql_query  = $sql_query . $sql_limit_to_append;
00283         }
00284     } else {
00285         $full_sql_query      = $sql_query;
00286     } // end if...else
00287 
00288     PMA_mysql_select_db($db);
00289 
00290     // If the query is a DELETE query with no WHERE clause, get the number of
00291     // rows that will be deleted (mysql_affected_rows will always return 0 in
00292     // this case)
00293     if ($is_delete
00294         && preg_match('@^DELETE([[:space:]].+)?([[:space:]]FROM[[:space:]](.+))$@i', $sql_query, $parts)
00295         && !preg_match('@[[:space:]]WHERE[[:space:]]@i', $parts[3])) {
00296         $cnt_all_result = @PMA_mysql_query('SELECT COUNT(*) as count' .  $parts[2]);
00297         if ($cnt_all_result) {
00298             $num_rows   = PMA_mysql_result($cnt_all_result, 0, 'count');
00299             mysql_free_result($cnt_all_result);
00300         } else {
00301             $num_rows   = 0;
00302         }
00303     }
00304 
00305     //  E x e c u t e    t h e    q u e r y
00306 
00307     // Only if we didn't ask to see the php code (mikebeck)
00308     if (isset($GLOBALS['show_as_php']) || !empty($GLOBALS['validatequery'])) {
00309         unset($result);
00310         $num_rows = 0;
00311     }
00312     else {
00313         // garvin: Measure query time. TODO-Item http://sourceforge.net/tracker/index.php?func=detail&aid=571934&group_id=23067&atid=377411
00314         list($usec, $sec) = explode(' ',microtime());
00315         $querytime_before = ((float)$usec + (float)$sec);
00316 
00317         $result   = @PMA_mysql_query($full_sql_query);
00318 
00319         list($usec, $sec) = explode(' ',microtime());
00320         $querytime_after = ((float)$usec + (float)$sec);
00321 
00322         $GLOBALS['querytime'] = $querytime_after - $querytime_before;
00323 
00324         // Displays an error message if required and stop parsing the script
00325         if (PMA_mysql_error()) {
00326             $error        = PMA_mysql_error();
00327             require_once('./header.inc.php');
00328             $full_err_url = (preg_match('@^(db_details|tbl_properties)@', $err_url))
00329                           ? $err_url . '&amp;show_query=1&amp;sql_query=' . urlencode($sql_query)
00330                           : $err_url;
00331             PMA_mysqlDie($error, $full_sql_query, '', $full_err_url);
00332         }
00333 
00334         // Gets the number of rows affected/returned
00335         // (This must be done immediately after the query because
00336         // mysql_affected_rows() reports about the last query done)
00337 
00338         if (!$is_affected) {
00339             $num_rows = ($result) ? @mysql_num_rows($result) : 0;
00340         } else if (!isset($num_rows)) {
00341             $num_rows = @mysql_affected_rows();
00342         }
00343 
00344         // Checks if the current database has changed
00345         // This could happen if the user sends a query like "USE `database`;"
00346         $res = PMA_mysql_query('SELECT DATABASE() AS "db";');
00347         $row = PMA_mysql_fetch_array($res);
00348         if (is_array($row) && isset($row['db']) && $db != $row['db']) {
00349             $db     = $row['db'];
00350             $reload = 1;
00351         }
00352         @mysql_free_result($res);
00353         unset($res);
00354         unset($row);
00355 
00356         // tmpfile remove after convert encoding appended by Y.Kawada
00357         if (function_exists('PMA_kanji_file_conv')
00358             && (isset($textfile) && file_exists($textfile))) {
00359             unlink($textfile);
00360         }
00361 
00362         // Counts the total number of rows for the same 'SELECT' query without the
00363         // 'LIMIT' clause that may have been programatically added
00364 
00365         if (empty($sql_limit_to_append)) {
00366             $unlim_num_rows         = $num_rows;
00367             // if we did not append a limit, set this to get a correct
00368             // "Showing rows..." message
00369             $GLOBALS['session_max_rows'] = 'all';
00370         }
00371         else if ($is_select) {
00372 
00373                 //    c o u n t    q u e r y
00374 
00375                 // If we are "just browsing", there is only one table,
00376                 // and no where clause (or just 'WHERE 1 '),
00377                 // so we do a quick count (which uses MaxExactCount)
00378                 // because SQL_CALC_FOUND_ROWS
00379                 // is not quick on large InnoDB tables
00380 
00381                 if (!$is_group
00382                  && !isset($analyzed_sql[0]['queryflags']['union'])
00383                  && !isset($analyzed_sql[0]['table_ref'][1]['table_name'])
00384                  && (empty($analyzed_sql[0]['where_clause'])
00385                    || $analyzed_sql[0]['where_clause'] == '1 ')) {
00386 
00387                     // "j u s t   b r o w s i n g"
00388                     $unlim_num_rows = PMA_countRecords($db, $table, TRUE);
00389 
00390                 } else { // n o t   " j u s t   b r o w s i n g "
00391 
00392                     if (PMA_MYSQL_INT_VERSION < 40000) {
00393                         // TODO: detect DISTINCT in the parser
00394                         if (stristr($sql_query, 'DISTINCT')) {
00395                             $count_what = 'DISTINCT ' . $analyzed_sql[0]['select_expr_clause'];
00396                         } else {
00397                             $count_what = '*';
00398                         }
00399 
00400                         $count_query = 'SELECT COUNT(' . $count_what . ') AS count';
00401                     }
00402 
00403                     // add the remaining of select expression if there is
00404                     // a GROUP BY or HAVING clause
00405                     if (PMA_MYSQL_INT_VERSION < 40000
00406                      && $count_what =='*'
00407                      && (!empty($analyzed_sql[0]['group_by_clause'])
00408                         || !empty($analyzed_sql[0]['having_clause']))) {
00409                         $count_query .= ' ,' . $analyzed_sql[0]['select_expr_clause'];
00410                     }
00411 
00412                     if (PMA_MYSQL_INT_VERSION >= 40000) {
00413                          // add select expression after the SQL_CALC_FOUND_ROWS
00414 //                        if (eregi('DISTINCT(.*)', $sql_query)) {
00415 //                            $count_query .= 'DISTINCT ' . $analyzed_sql[0]['select_expr_clause'];
00416 //                        } else {
00417                             //$count_query .= $analyzed_sql[0]['select_expr_clause'];
00418 
00419                             // for UNION, just adding SQL_CALC_FOUND_ROWS
00420                             // after the first SELECT works.
00421 
00422                             // take the left part, could be:
00423                             // SELECT
00424                             // (SELECT
00425                             $count_query = PMA_SQP_formatHtml($parsed_sql, 'query_only', 0, $analyzed_sql[0]['position_of_first_select'] + 1);
00426                             $count_query .= ' SQL_CALC_FOUND_ROWS ';
00427 
00428                             // add everything that was after the first SELECT
00429                             $count_query .= PMA_SQP_formatHtml($parsed_sql, 'query_only', $analyzed_sql[0]['position_of_first_select']+1);
00430 //                        }
00431                     } else { // PMA_MYSQL_INT_VERSION < 40000
00432 
00433                         if (!empty($analyzed_sql[0]['from_clause'])) {
00434                             $count_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
00435                         }
00436                         if (!empty($analyzed_sql[0]['where_clause'])) {
00437                             $count_query .= ' WHERE ' . $analyzed_sql[0]['where_clause'];
00438                         }
00439                         if (!empty($analyzed_sql[0]['group_by_clause'])) {
00440                             $count_query .= ' GROUP BY ' . $analyzed_sql[0]['group_by_clause'];
00441                         }
00442                         if (!empty($analyzed_sql[0]['having_clause'])) {
00443                             $count_query .= ' HAVING ' . $analyzed_sql[0]['having_clause'];
00444                         }
00445                     } // end if
00446 
00447                     // if using SQL_CALC_FOUND_ROWS, add a LIMIT to avoid
00448                     // long delays. Returned count will be complete anyway.
00449                     // (but a LIMIT would disrupt results in an UNION)
00450 
00451                     if (PMA_MYSQL_INT_VERSION >= 40000
00452                     && !isset($analyzed_sql[0]['queryflags']['union'])) {
00453                         $count_query .= ' LIMIT 1';
00454                     }
00455 
00456                     // run the count query
00457 //DEBUG echo "trace cq=" . $count_query . "<br/>";
00458 
00459                     if (PMA_MYSQL_INT_VERSION < 40000) {
00460                         if ($cnt_all_result = PMA_mysql_query($count_query)) {
00461                             if ($is_group && $count_what == '*') {
00462                                 $unlim_num_rows = @mysql_num_rows($cnt_all_result);
00463                             } else {
00464                                 $unlim_num_rows = PMA_mysql_result($cnt_all_result, 0, 'count');
00465                             }
00466                             mysql_free_result($cnt_all_result);
00467                         } else {
00468                             if (mysql_error()) {
00469 
00470                                 // there are some cases where the generated
00471                                 // count_query (for MySQL 3) is wrong,
00472                                 // so we get here.
00473                                 //TODO: use a big unlimited query to get
00474                                 // the correct number of rows (depending
00475                                 // on a config variable?)
00476                                 $unlim_num_rows = 0;
00477                             }
00478                         }
00479                     } else {
00480                         PMA_mysql_query($count_query);
00481                         // if (mysql_error()) {
00482                         // void. I tried the case
00483                         // (SELECT `User`, `Host`, `Db`, `Select_priv` FROM `db`)
00484                         // UNION (SELECT `User`, `Host`, "%" AS "Db",
00485                         // `Select_priv`
00486                         // FROM `user`) ORDER BY `User`, `Host`, `Db`;
00487                         // and although the generated count_query is wrong
00488                         // the SELECT FOUND_ROWS() work!
00489                         // }
00490                         $cnt_all_result = PMA_mysql_query('SELECT FOUND_ROWS() as count');
00491                         $unlim_num_rows = PMA_mysql_result($cnt_all_result,0,'count');
00492                     }
00493             } // end else "just browsing"
00494 
00495         } else { // not $is_select
00496              $unlim_num_rows         = 0;
00497         } // end rows total count
00498 
00499         // garvin: if a table or database gets dropped, check column comments.
00500         if (isset($purge) && $purge == '1') {
00501             require_once('./libraries/relation_cleanup.lib.php');
00502 
00503             if (isset($table) && isset($db) && !empty($table) && !empty($db)) {
00504                 PMA_relationsCleanupTable($db, $table);
00505             } elseif (isset($db) && !empty($db)) {
00506                 PMA_relationsCleanupDatabase($db);
00507             } else {
00508                 // garvin: VOID. No DB/Table gets deleted.
00509             } // end if relation-stuff
00510          } // end if ($purge)
00511 
00512         // garvin: If a column gets dropped, do relation magic.
00513         if (isset($cpurge) && $cpurge == '1' && isset($purgekey)
00514             && isset($db) && isset($table)
00515             && !empty($db) && !empty($table) && !empty($purgekey)) {
00516             require_once('./libraries/relation_cleanup.lib.php');
00517             PMA_relationsCleanupColumn($db, $table, $purgekey);
00518 
00519         } // end if column PMA_* purge
00520     } // end else "didn't ask to see php code"
00521 
00522 
00523     // No rows returned -> move back to the calling page
00524     if ($num_rows < 1 || $is_affected) {
00525         if ($is_delete) {
00526             $message = $strDeletedRows . '&nbsp;' . $num_rows;
00527         } else if ($is_insert) {
00528             $message = $strInsertedRows . '&nbsp;' . $num_rows;
00529             $insert_id = mysql_insert_id();
00530             if ($insert_id != 0) {
00531                 $message .= '<br />'.$strInsertedRowId . '&nbsp;' . $insert_id;
00532             }
00533         } else if ($is_affected) {
00534             $message = $strAffectedRows . '&nbsp;' . $num_rows;
00535         } else if (!empty($zero_rows)) {
00536             $message = $zero_rows;
00537         } else if (!empty($GLOBALS['show_as_php'])) {
00538             $message = $strPhp;
00539         } else if (!empty($GLOBALS['validatequery'])) {
00540             $message = $strValidateSQL;
00541         } else {
00542             $message = $strEmptyResultSet;
00543         }
00544 
00545         $message .= ' ' . (isset($GLOBALS['querytime']) ? '(' . sprintf($strQueryTime, $GLOBALS['querytime']) . ')' : '');
00546 
00547         if ($is_gotofile) {
00548             $goto = preg_replace('@\.\.*@', '.', $goto);
00549             // Checks for a valid target script
00550             if (isset($table) && $table == '') {
00551                 unset($table);
00552             }
00553             if (isset($db) && $db == '') {
00554                 unset($db);
00555             }
00556             $is_db = $is_table = FALSE;
00557             if (strpos(' ' . $goto, 'tbl_properties') == 1) {
00558                 if (!isset($table)) {
00559                     $goto     = 'db_details.php';
00560                 } else {
00561                     $is_table = @PMA_mysql_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'');
00562                     if (!($is_table && @mysql_numrows($is_table))) {
00563                         $goto = 'db_details.php';
00564                         unset($table);
00565                     }
00566                 } // end if... else...
00567             }
00568             if (strpos(' ' . $goto, 'db_details') == 1) {
00569                 if (isset($table)) {
00570                     unset($table);
00571                 }
00572                 if (!isset($db)) {
00573                     $goto     = 'main.php';
00574                 } else {
00575                     $is_db    = @PMA_mysql_select_db($db);
00576                     if (!$is_db) {
00577                         $goto = 'main.php';
00578                         unset($db);
00579                     }
00580                 } // end if... else...
00581             }
00582             // Loads to target script
00583             if (strpos(' ' . $goto, 'db_details') == 1
00584                 || strpos(' ' . $goto, 'tbl_properties') == 1) {
00585                 $js_to_run = 'functions.js';
00586             }
00587             if ($goto != 'main.php') {
00588                 require_once('./header.inc.php');
00589             }
00590             $active_page = $goto;
00591             require('./' . $goto);
00592         } // end if file_exist
00593         else {
00594             header('Location: ' . $cfg['PmaAbsoluteUri'] . str_replace('&amp;', '&', $goto) . '&message=' . urlencode($message));
00595         } // end else
00596         exit();
00597     } // end no rows returned
00598 
00599     // At least one row is returned -> displays a table with results
00600     else {
00601         // Displays the headers
00602         if (isset($show_query)) {
00603             unset($show_query);
00604         }
00605         if (isset($printview) && $printview == '1') {
00606             require_once('./header_printview.inc.php');
00607         } else {
00608             $js_to_run = 'functions.js';
00609             unset($message);
00610             if (!empty($table)) {
00611                 require('./tbl_properties_common.php');
00612                 $url_query .= '&amp;goto=tbl_properties.php&amp;back=tbl_properties.php';
00613                 require('./tbl_properties_table_info.php');
00614             }
00615             else {
00616                 require('./db_details_common.php');
00617                 require('./db_details_db_info.php');
00618             }
00619         }
00620 
00621         require_once('./libraries/relation.lib.php');
00622         $cfgRelation = PMA_getRelationsParam();
00623 
00624         // Gets the list of fields properties
00625         if (isset($result) && $result) {
00626             while ($field = PMA_mysql_fetch_field($result)) {
00627                 $fields_meta[] = $field;
00628             }
00629             $fields_cnt        = count($fields_meta);
00630         }
00631 
00632         // Display previous update query (from tbl_replace)
00633         if (isset($disp_query) && $cfg['ShowSQL'] == TRUE) {
00634             $tmp_sql_query = $GLOBALS['sql_query'];
00635             $tmp_sql_limit_to_append = (isset($GLOBALS['sql_limit_to_append'])?$GLOBALS['sql_limit_to_append']:'');
00636             $GLOBALS['sql_query'] = $disp_query;
00637             $GLOBALS['sql_limit_to_append'] = '';
00638             PMA_showMessage($disp_message);
00639             $GLOBALS['sql_query'] = $tmp_sql_query;
00640             $GLOBALS['sql_limit_to_append'] = $tmp_sql_limit_to_append;
00641         }
00642 
00643         // Displays the results in a table
00644         require_once('./libraries/display_tbl.lib.php');
00645         if (empty($disp_mode)) {
00646             // see the "PMA_setDisplayMode()" function in
00647             // libraries/display_tbl.lib.php
00648             $disp_mode = 'urdr111101';
00649         }
00650         if (!isset($dontlimitchars)) {
00651             $dontlimitchars = 0;
00652         }
00653 
00654         PMA_displayTable($result, $disp_mode, $analyzed_sql);
00655         mysql_free_result($result);
00656 
00657         if ($disp_mode[6] == '1' || $disp_mode[9] == '1') {
00658             echo "\n";
00659             echo '<p>' . "\n";
00660 
00661             // Displays "Insert a new row" link if required
00662             if ($disp_mode[6] == '1') {
00663                 $lnk_goto  = 'sql.php?'
00664                            . PMA_generate_common_url($db, $table)
00665                            . '&amp;pos=' . $pos
00666                            . '&amp;session_max_rows=' . $session_max_rows
00667                            . '&amp;disp_direction=' . $disp_direction
00668                            . '&amp;repeat_cells=' . $repeat_cells
00669                            . '&amp;dontlimitchars=' . $dontlimitchars
00670                            . '&amp;sql_query=' . urlencode($sql_query);
00671                 $url_query = '?'
00672                            . PMA_generate_common_url($db, $table)
00673                            . '&amp;pos=' . $pos
00674                            . '&amp;session_max_rows=' . $session_max_rows
00675                            . '&amp;disp_direction=' . $disp_direction
00676                            . '&amp;repeat_cells=' . $repeat_cells
00677                            . '&amp;dontlimitchars=' . $dontlimitchars
00678                            . '&amp;sql_query=' . urlencode($sql_query)
00679                            . '&amp;goto=' . urlencode($lnk_goto);
00680 
00681                 echo '    <!-- Insert a new row -->' . "\n"
00682                    . '    <a href="tbl_change.php' . $url_query . '">' . $strInsertNewRow . '</a>';
00683                 if ($disp_mode[9] == '1') {
00684                     echo '<br />';
00685                 }
00686                 echo "\n";
00687             } // end insert new row
00688 
00689             // Displays "printable view" link if required
00690             if ($disp_mode[9] == '1') {
00691                 $url_query = '?'
00692                            . PMA_generate_common_url($db, $table)
00693                            . '&amp;pos=' . $pos
00694                            . '&amp;session_max_rows=' . $session_max_rows
00695                            . '&amp;disp_direction=' . $disp_direction
00696                            . '&amp;repeat_cells=' . $repeat_cells
00697                            . '&amp;printview=1'
00698                            . '&amp;sql_query=' . urlencode($sql_query);
00699                 echo '    <!-- Print view -->' . "\n"
00700                    . '    <a href="sql.php' . $url_query
00701                    . ((isset($dontlimitchars) && $dontlimitchars == '1') ? '&amp;dontlimitchars=1' : '')
00702                    . '" target="print_view">' . $strPrintView . '</a>' . "\n";
00703                 if (!$dontlimitchars) {
00704                    echo   '    <br />' . "\n"
00705                         . '    <a href="sql.php' . $url_query
00706                         . '&amp;dontlimitchars=1'
00707                         . '" target="print_view">' . $strPrintViewFull . '</a>' . "\n";
00708                 }
00709             } // end displays "printable view"
00710 
00711             echo '</p>' . "\n";
00712         }
00713 
00714         // Export link
00715         // (the url_query has extra parameters that won't be used to export)
00716         // (the single_table parameter is used in display_export.lib.php
00717         //  to hide the SQL and the structure export dialogs)
00718         if (!isset($printview)) {
00719             if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
00720                 $single_table   = '&amp;single_table=true';
00721             } else {
00722                 $single_table   = '';
00723             }
00724             echo '    <!-- Export -->' . "\n"
00725                    . '    <a href="tbl_properties_export.php' . $url_query
00726                    . '&amp;unlim_num_rows=' . $unlim_num_rows
00727                    . $single_table
00728                    . '">' . $strExport . '</a>' . "\n";
00729         }
00730 
00731         // Bookmark Support if required
00732         if ($disp_mode[7] == '1'
00733             && ($cfg['Bookmark']['db'] && $cfg['Bookmark']['table'] && empty($id_bookmark))
00734             && !empty($sql_query)) {
00735             echo "\n";
00736 
00737             $goto = 'sql.php?'
00738                   . PMA_generate_common_url($db, $table)
00739                   . '&amp;pos=' . $pos
00740                   . '&amp;session_max_rows=' . $session_max_rows
00741                   . '&amp;disp_direction=' . $disp_direction
00742                   . '&amp;repeat_cells=' . $repeat_cells
00743                   . '&amp;dontlimitchars=' . $dontlimitchars
00744                   . '&amp;sql_query=' . urlencode($sql_query)
00745                   . '&amp;id_bookmark=1';
00746             ?>
00747 <!-- Bookmark the query -->
00748 <form action="sql.php" method="post" onsubmit="return emptyFormElements(this, 'fields[label]');">
00749             <?php
00750             echo "\n";
00751             if ($disp_mode[3] == '1') {
00752                 echo '    <i>' . $strOr . '</i>' . "\n";
00753             }
00754             ?>
00755     <br /><br />
00756     <?php echo $strBookmarkLabel; ?>:
00757     <?php echo PMA_generate_common_hidden_inputs(); ?>
00758     <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
00759     <input type="hidden" name="fields[dbase]" value="<?php echo htmlspecialchars($db); ?>" />
00760     <input type="hidden" name="fields[user]" value="<?php echo $cfg['Bookmark']['user']; ?>" />
00761     <input type="hidden" name="fields[query]" value="<?php echo urlencode(isset($complete_query) ? $complete_query : $sql_query); ?>" />
00762     <input type="text" name="fields[label]" value="" />
00763     <input type="checkbox" name="bkm_all_users" id="bkm_all_users" value="true" /><label for="bkm_all_users"><?php echo $strBookmarkAllUsers; ?></label>
00764     <input type="submit" name="store_bkm" value="<?php echo $strBookmarkThis; ?>" />
00765 </form>
00766             <?php
00767         } // end bookmark support
00768 
00769         // Do print the page if required
00770         if (isset($printview) && $printview == '1') {
00771             echo "\n";
00772             ?>
00773 <script type="text/javascript" language="javascript1.2">
00774 <!--
00775 // Do print the page
00776 if (typeof(window.print) != 'undefined') {
00777     window.print();
00778 }
00779 //-->
00780 </script>
00781             <?php
00782         } // end print case
00783     } // end rows returned
00784 
00785 } // end executes the query
00786 echo "\n\n";
00787 
00791 require_once('./footer.inc.php');
00792 ?>


Généré par Le spécialiste TYPO3 avec  doxygen 1.4.6