home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / querywindow.php < prev    next >
Encoding:
PHP Script  |  2003-11-26  |  16.1 KB  |  301 lines

  1. <?php
  2. /* $Id: querywindow.php,v 2.2 2003/11/26 22:52:24 rabus Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5.  
  6. /**
  7.  * Gets the variables sent to this script, retains the db name that may have
  8.  * been defined as startup option and include a core library
  9.  */
  10. require_once('./libraries/grab_globals.lib.php');
  11. if (!empty($db)) {
  12.     $db_start = $db;
  13. }
  14.  
  15.  
  16. /**
  17.  * Gets a core script and starts output buffering work
  18.  */
  19. require_once('./libraries/common.lib.php');
  20. require_once('./libraries/ob.lib.php');
  21. if ($cfg['OBGzip']) {
  22.     $ob_mode = PMA_outBufferModeGet();
  23.     if ($ob_mode) {
  24.         PMA_outBufferPre($ob_mode);
  25.     }
  26. }
  27.  
  28. require_once('./libraries/relation.lib.php');
  29. $cfgRelation = PMA_getRelationsParam();
  30.  
  31. /**
  32.  * Get the list and number of available databases.
  33.  * Skipped if no server selected: in this case no database should be displayed
  34.  * before the user choose among available ones at the welcome screen.
  35.  */
  36. if ($server > 0) {
  37.     PMA_availableDatabases(); // this function is defined in "common.lib.php"
  38. } else {
  39.     $num_dbs = 0;
  40. }
  41.  
  42. // garvin: For re-usability, moved http-headers and stylesheets
  43. // to a seperate file. It can now be included by header.inc.php,
  44. // queryframe.php, querywindow.php.
  45.  
  46. require_once('./libraries/header_http.inc.php');
  47. require_once('./libraries/header_meta_style.inc.php');
  48. ?>
  49.  
  50. <script type="text/javascript" language="javascript">
  51. <?php
  52. if ($cfg['QueryFrame'] && $cfg['QueryFrameJS'] && $cfg['QueryFrameDebug']) {
  53.     $js_db = (isset($db) ? $db : 'FALSE');
  54.     $js_table = (isset($table) ? $table : 'FALSE');
  55.     $js_server = (isset($server) ? $server : 'FALSE');
  56.  
  57.     $js_true_db = '\' + document.querywindow.db.value + \'';
  58.     $js_true_table = '\' + document.querywindow.table.value + \'';
  59.     $js_true_server = '\' + document.querywindow.server.value + \'';
  60.  
  61.     $js_parent = '\' + opener.location.href + \'';
  62.     $js_frame = '\' + opener.parent.location.href + \'';
  63. ?>
  64. function debug() {
  65.     alert('<?php echo sprintf($strQueryFrameDebugBox, $js_db, $js_table, $js_server, $js_true_db, $js_true_table, $js_true_server, $js_parent, $js_frame); ?>');
  66.     return false;
  67. }
  68. <?php
  69. }
  70. ?>
  71. function query_auto_commit() {
  72.     document.sqlform.submit();
  73. }
  74.  
  75. function query_tab_commit(tab) {
  76.     document.querywindow.querydisplay_tab.value = tab;
  77.     document.querywindow.submit();
  78.     return false;
  79. }
  80.  
  81. // js form validation stuff
  82. var errorMsg0   = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strFormEmpty']); ?>';
  83. var errorMsg1   = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strNotNumber']); ?>';
  84. var errorMsg2   = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strNotValidNumber']); ?>';
  85. var noDropDbMsg = '<?php echo((!$GLOBALS['cfg']['AllowUserDropDatabase']) ? str_replace('\'', '\\\'', $GLOBALS['strNoDropDatabases']) : ''); ?>';
  86. var confirmMsg  = '<?php echo(($GLOBALS['cfg']['Confirm']) ? str_replace('\'', '\\\'', $GLOBALS['strDoYouReally']) : ''); ?>';
  87. //-->
  88. </script>
  89. <script src="libraries/functions.js" type="text/javascript" language="javascript"></script>
  90. </head>
  91.  
  92. <body bgcolor="<?php echo ($cfg['QueryFrameJS'] ? $cfg['LeftBgColor'] : $cfg['RightBgColor']); ?>">
  93.  
  94. <?php
  95. if ($cfg['QueryFrameJS'] && !isset($no_js)) {
  96.     $querydisplay_tab = (isset($querydisplay_tab) ? $querydisplay_tab : $cfg['QueryWindowDefTab']);
  97.  
  98.     if ($cfg['LightTabs']) {
  99.         echo ' ';
  100.     } else {
  101.         echo '<table border="0" cellspacing="0" cellpadding="3" width="100%" class="tabs">
  102.         <tr>
  103.             <td width="8"> </td>';
  104.     }
  105.     echo "\n";
  106.     echo PMA_printTab($strSQL, '#', '', 'onClick="javascript:query_tab_commit(\'sql\');return false;"', '', (isset($querydisplay_tab) && $querydisplay_tab == 'sql' ? TRUE : FALSE));
  107.     echo PMA_printTab($strImportFiles, '#', '', 'onClick="javascript:query_tab_commit(\'files\');return false;"', '', (isset($querydisplay_tab) && $querydisplay_tab == 'files' ? TRUE : FALSE));
  108.     echo PMA_printTab($strQuerySQLHistory, '#', '', 'onClick="javascript:query_tab_commit(\'history\');return false;"', '', (isset($querydisplay_tab) && $querydisplay_tab == 'history' ? TRUE : FALSE));
  109.  
  110.     if ($cfg['QueryWindowDefTab'] == 'full') {
  111.         echo PMA_printTab($strAll, '#', '', 'onClick="javascript:query_tab_commit(\'full\');return false;"', '', (isset($querydisplay_tab) && $querydisplay_tab == 'full' ? TRUE : FALSE));
  112.     }
  113.  
  114.     if (!$cfg['LightTabs']) {
  115.         echo '</tr></table>';
  116.     } else {
  117.         echo '<br />';
  118.     }
  119. } else {
  120.     $querydisplay_tab = 'full';
  121. }
  122.  
  123. ?>
  124. <br />
  125.  
  126. <?php
  127. if ($cfg['PropertiesIconic'] == true) {
  128.     // We need to copy the value or else the == 'both' check will always return true
  129.     $propicon = (string)$cfg['PropertiesIconic'];
  130.  
  131.     if ($propicon == 'both') {
  132.         $iconic_spacer = '<nobr>';
  133.     } else {
  134.         $iconic_spacer = '';
  135.     }
  136.  
  137.     $titles['Change']        = $iconic_spacer . '<img hspace="7" width="12" height="13" src="images/button_edit.png" alt="' . $strChange . '" title="' . $strChange . '" border="0" />';
  138.  
  139.     if ($propicon == 'both') {
  140.         $titles['Change']        .= ' ' . $strChange . ' </nobr>';
  141.     }
  142. } else {
  143.     $titles['Change']        = $strChange;
  144. }
  145.  
  146. // Hidden forms and query frame interaction stuff
  147. if ($cfg['QueryFrame'] && $cfg['QueryFrameJS']) {
  148.  
  149.     $input_query_history = array();
  150.     $sql_history = array();
  151.     $dup_sql = array();
  152.  
  153.     if (isset($query_history_latest) && isset($query_history_latest_db) && $query_history_latest != '' && $query_history_latest_db != '') {
  154.         if ($cfg['QueryHistoryDB'] && $cfgRelation['historywork']) {
  155.             PMA_setHistory((isset($query_history_latest_db) ? $query_history_latest_db : ''), (isset($query_history_latest_table) ? $query_history_latest_table : ''), $cfg['Server']['user'], $query_history_latest);
  156.         }
  157.  
  158.         $input_query_history[] = '<input type="hidden" name="query_history[]" value="' . $query_history_latest . '" />';
  159.         $input_query_history[] = '<input type="hidden" name="query_history_db[]" value="' . htmlspecialchars($query_history_latest_db) . '" />';
  160.         $input_query_history[] = '<input type="hidden" name="query_history_table[]" value="' . (isset($query_history_latest_table) ? htmlspecialchars($query_history_latest_table) : '') . '" />';
  161.  
  162.         $sql_history[] = '<li>'
  163.                        . '<a href="#" onClick="document.querywindow.querydisplay_tab.value = \'' . (isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full') . '\'; document.querywindow.query_history_latest.value = \'' . preg_replace('/(\n)/i', ' ', addslashes(htmlspecialchars($query_history_latest))) . '\'; document.querywindow.auto_commit.value = \'false\'; document.querywindow.db.value = \'' . htmlspecialchars($query_history_latest_db) . '\'; document.querywindow.query_history_latest_db.value = \'' . htmlspecialchars($query_history_latest_db) . '\'; document.querywindow.table.value = \'' . (isset($query_history_latest_table) ? htmlspecialchars($query_history_latest_table) : '') . '\'; document.querywindow.query_history_latest_table.value = \'' . (isset($query_history_latest_table) ? htmlspecialchars($query_history_latest_table) : '') . '\'; document.querywindow.submit(); return false;">' . $titles['Change'] . '</a>'
  164.                        . '<a href="#" onClick="document.querywindow.querydisplay_tab.value = \'' . (isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full') . '\'; document.querywindow.query_history_latest.value = \'' . preg_replace('/(\n)/i', ' ', addslashes(htmlspecialchars($query_history_latest))) . '\'; document.querywindow.auto_commit.value = \'true\'; document.querywindow.db.value = \'' . htmlspecialchars($query_history_latest_db) . '\'; document.querywindow.query_history_latest_db.value = \'' . htmlspecialchars($query_history_latest_db) . '\'; document.querywindow.table.value = \'' . (isset($query_history_latest_table) ? htmlspecialchars($query_history_latest_table) : '') . '\'; document.querywindow.query_history_latest_table.value = \'' . (isset($query_history_latest_table) ? htmlspecialchars($query_history_latest_table) : '') . '\'; document.querywindow.submit(); return false;">[' . htmlspecialchars($query_history_latest_db) . '] ' . urldecode($query_history_latest) . '</a>'
  165.                        . '</li>' . "\n";
  166.  
  167.         $sql_query = urldecode($query_history_latest);
  168.         $db = $query_history_latest_db;
  169.         $table = $query_history_latest_table;
  170.         $dup_sql[$query_history_latest] = true;
  171.     } elseif (isset($query_history_latest) && $query_history_latest != '') {
  172.         $sql_query = urldecode($query_history_latest);
  173.     }
  174.  
  175.     if (isset($sql_query)) {
  176.         $show_query = 1;
  177.     }
  178.  
  179.     if ($cfg['QueryHistoryDB'] && $cfgRelation['historywork']) {
  180.  
  181.         $temp_history = PMA_getHistory($cfg['Server']['user']);
  182.         if (is_array($temp_history) && count($temp_history) > 0) {
  183.             foreach($temp_history AS $history_nr => $history_array) {
  184.                 if (!isset($dup_sql[$history_array['sqlquery']])) {
  185.                     $sql_history[] = '<li>'
  186.                                    . '<a href="#" onClick="document.querywindow.querydisplay_tab.value = \'' . (isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full') . '\'; document.querywindow.query_history_latest.value = \'' . preg_replace('/(\n)/i', ' ', addslashes(htmlspecialchars($history_array['sqlquery']))) . '\'; document.querywindow.auto_commit.value = \'false\'; document.querywindow.db.value = \'' . htmlspecialchars($history_array['db']) . '\'; document.querywindow.query_history_latest_db.value = \'' . htmlspecialchars($history_array['db']) . '\'; document.querywindow.table.value = \'' . (isset($history_array['table']) ? htmlspecialchars($history_array['table']) : '') . '\'; document.querywindow.query_history_latest_table.value = \'' . (isset($history_array['table']) ? htmlspecialchars($history_array['table']) : '') . '\'; document.querywindow.submit(); return false;">' . $titles['Change'] . '</a>'
  187.                                    . '<a href="#" onClick="document.querywindow.querydisplay_tab.value = \'' . (isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full') . '\'; document.querywindow.query_history_latest.value = \'' . preg_replace('/(\n)/i', ' ', addslashes(htmlspecialchars($history_array['sqlquery']))) . '\'; document.querywindow.auto_commit.value = \'true\'; document.querywindow.db.value = \'' . htmlspecialchars($history_array['db']) . '\'; document.querywindow.query_history_latest_db.value = \'' . htmlspecialchars($history_array['db']) . '\'; document.querywindow.table.value = \'' . (isset($history_array['table']) ? htmlspecialchars($history_array['table']) : '') . '\'; document.querywindow.query_history_latest_table.value = \'' . (isset($history_array['table']) ? htmlspecialchars($history_array['table']) : '') . '\'; document.querywindow.submit(); return false;">[' . htmlspecialchars($history_array['db']) . '] ' . urldecode($history_array['sqlquery']) . '</a>'
  188.                                    . '</li>' . "\n";
  189.                     $dup_sql[$history_array['sqlquery']] = true;
  190.                 }
  191.             }
  192.         }
  193.  
  194.     } else {
  195.  
  196.         if (isset($query_history) && is_array($query_history)) {
  197.             $current_index = count($query_history);
  198.             foreach($query_history AS $query_no => $query_sql) {
  199.                 if (!isset($dup_sql[$query_sql])) {
  200.  
  201.                     $input_query_history[] = '<input type="hidden" name="query_history[]" value="' . $query_sql . '" />';
  202.                     $input_query_history[] = '<input type="hidden" name="query_history_db[]" value="' . htmlspecialchars($query_history_db[$query_no]) . '" />';
  203.                     $input_query_history[] = '<input type="hidden" name="query_history_table[]" value="' . (isset($query_history_table[$query_no]) ? htmlspecialchars($query_history_table[$query_no]) : '') . '" />';
  204.  
  205.                     $sql_history[] = '<li>'
  206.                                    . '<a href="#" onClick="document.querywindow.querydisplay_tab.value = \'' . (isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full') . '\'; document.querywindow.query_history_latest.value = \'' . htmlspecialchars($query_sql) . '\'; document.querywindow.auto_commit.value = \'false\'; document.querywindow.db.value = \'' . htmlspecialchars($query_history_db[$query_no]) . '\'; document.querywindow.query_history_latest_db.value = \'' . htmlspecialchars($query_history_db[$query_no]) . '\'; document.querywindow.table.value = \'' . (isset($query_history_table[$query_no]) ? htmlspecialchars($query_history_table[$query_no]) : '') . '\'; document.querywindow.query_history_latest_table.value = \'' . (isset($query_history_table[$query_no]) ? htmlspecialchars($query_history_table[$query_no]) : '') . '\'; document.querywindow.submit(); return false;">' . $titles['Change'] . '</a>'
  207.                                    . '<a href="#" onClick="document.querywindow.querydisplay_tab.value = \'' . (isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full') . '\'; document.querywindow.query_history_latest.value = \'' . htmlspecialchars($query_sql) . '\'; document.querywindow.auto_commit.value = \'true\'; document.querywindow.db.value = \'' . htmlspecialchars($query_history_db[$query_no]) . '\'; document.querywindow.query_history_latest_db.value = \'' . htmlspecialchars($query_history_db[$query_no]) . '\'; document.querywindow.table.value = \'' . (isset($query_history_table[$query_no]) ? htmlspecialchars($query_history_table[$query_no]) : '') . '\'; document.querywindow.query_history_latest_table.value = \'' . (isset($query_history_table[$query_no]) ? htmlspecialchars($query_history_table[$query_no]) : '') . '\'; document.querywindow.submit(); return false;">[' . htmlspecialchars($query_history_db[$query_no]) . '] ' . urldecode($query_sql) . '</a>'
  208.                                    . '</li>' . "\n";
  209.                     $dup_sql[$query_sql] = true;
  210.                 } // end if check if this item exists
  211.             } // end while print history
  212.         } // end if history exists
  213.  
  214.     } // end if DB-based history
  215. }
  216.  
  217. $url_query = PMA_generate_common_url(isset($db) ? $db : '', isset($table) ? $table : '');
  218. if (!isset($goto)) {
  219.     $goto = '';
  220. }
  221.  
  222. require_once './libraries/bookmark.lib.php';
  223. $is_inside_querywindow = TRUE;
  224. require './tbl_query_box.php';
  225.  
  226. // Hidden forms and query frame interaction stuff
  227. if ($cfg['QueryFrame'] && $cfg['QueryFrameJS']) {
  228.     if (isset($auto_commit) && $auto_commit == 'true') {
  229.     ?>
  230.         <script type="text/javascript" language="javascript">
  231.         query_auto_commit();
  232.         </script>
  233.     <?php
  234.     }
  235.  
  236.     if (isset($sql_history) && isset($querydisplay_tab) && ($querydisplay_tab == 'history' || $querydisplay_tab == 'full') && is_array($sql_history) && count($sql_history) > 0) {
  237.     ?>
  238.     <li>
  239.         <div style="margin-bottom: 10px"><?php echo $strQuerySQLHistory . ':<br><ul>' . implode('', $sql_history) . '</ul>'; ?></div>
  240.     </li>
  241.     <?php
  242.     }
  243. ?>
  244. <form action="querywindow.php" method="post" name="querywindow">
  245. <?php
  246.     echo PMA_generate_common_hidden_inputs('', '');
  247.     if (count($input_query_history) > 0) {
  248.         echo implode("\n", $input_query_history);
  249.     }
  250. ?>
  251.     <input type="hidden" name="db" value="<?php echo (empty($db) ? '' : htmlspecialchars($db)); ?>" />
  252.     <input type="hidden" name="table" value="<?php echo (empty($table) ? '' : htmlspecialchars($table)); ?>" />
  253.  
  254.     <input type="hidden" name="query_history_latest" value="" />
  255.     <input type="hidden" name="query_history_latest_db" value="" />
  256.     <input type="hidden" name="query_history_latest_table" value="" />
  257.  
  258.     <input type="hidden" name="previous_db" value="<?php echo htmlspecialchars($db); ?>" />
  259.  
  260.     <input type="hidden" name="auto_commit" value="false" />
  261.     <input type="hidden" name="querydisplay_tab" value="<?php echo $querydisplay_tab; ?>" />
  262. </form>
  263. <?php
  264. }
  265.  
  266. /* REMOVE ME */
  267. if ($cfg['QueryFrame'] && $cfg['QueryFrameJS'] && $cfg['QueryFrameDebug']) {
  268. ?>
  269. <br>
  270. <center>
  271.     <a href='#' onClick='return debug();'><?php echo $strQueryFrameDebug; ?></a>
  272. </center>
  273. <?php
  274. }
  275. /* REMOVE ME */
  276. ?>
  277.  
  278. </body>
  279. </html>
  280.  
  281. <?php
  282. /**
  283.  * Close MySql connections
  284.  */
  285. if (isset($dbh) && $dbh) {
  286.     @mysql_close($dbh);
  287. }
  288. if (isset($userlink) && $userlink) {
  289.     @mysql_close($userlink);
  290. }
  291.  
  292.  
  293. /**
  294.  * Sends bufferized data
  295.  */
  296. if (isset($cfg['OBGzip']) && $cfg['OBGzip']
  297.     && isset($ob_mode) && $ob_mode) {
  298.      PMA_outBufferPost($ob_mode);
  299. }
  300. ?>
  301.