[ Index ]
 

Code source de phpMyAdmin 2.10.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/ -> querywindow.php (source)

   1  <?php
   2  /* $Id: querywindow.php 10144 2007-03-20 11:22:31Z cybot_tm $ */
   3  // vim: expandtab sw=4 ts=4 sts=4:
   4  
   5  require_once ('./libraries/common.lib.php');
   6  
   7  $is_superuser = PMA_isSuperuser();
   8  
   9  /**
  10   * Gets the variables sent to this script, retains the db name that may have
  11   * been defined as startup option and include a core library
  12   */
  13  if (isset($db) && strlen($db)) {
  14      $db_start = $db;
  15  }
  16  
  17  
  18  /**
  19   * Gets a core script and starts output buffering work
  20   */
  21  require_once  './libraries/sql_query_form.lib.php';
  22  require_once ('./libraries/ob.lib.php');
  23  if ( $GLOBALS['cfg']['OBGzip'] ) {
  24      $ob_mode = PMA_outBufferModeGet();
  25      if ( $ob_mode ) {
  26          PMA_outBufferPre( $ob_mode );
  27      }
  28  }
  29  
  30  require_once ('./libraries/relation.lib.php');
  31  $cfgRelation = PMA_getRelationsParam();
  32  
  33  
  34  // initialize some variables
  35  $_sql_history = array();
  36  $_input_query_history = array();
  37  
  38  // garvin: For re-usability, moved http-headers and stylesheets
  39  // to a seperate file. It can now be included by libraries/header.inc.php,
  40  // querywindow.php.
  41  
  42  require_once ('./libraries/header_http.inc.php');
  43  require_once ('./libraries/header_meta_style.inc.php');
  44  ?>
  45  <script type="text/javascript" language="javascript">
  46  //<![CDATA[
  47  function query_auto_commit() {
  48      document.getElementById( 'sqlqueryform' ).target = window.opener.frame_content.name;
  49      document.getElementById( 'sqlqueryform' ).submit();
  50      return;
  51  }
  52  
  53  function query_tab_commit(tab) {
  54      document.getElementById('hiddenqueryform').querydisplay_tab.value = tab;
  55      document.getElementById('hiddenqueryform').submit();
  56      return false;
  57  }
  58  
  59  // js form validation stuff
  60  /**/
  61  var errorMsg0   = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strFormEmpty']); ?>';
  62  var errorMsg1   = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strNotNumber']); ?>';
  63  var noDropDbMsg = '<?php echo (!$is_superuser && !$GLOBALS['cfg']['AllowUserDropDatabase'])
  64      ? str_replace('\'', '\\\'', $GLOBALS['strNoDropDatabases']) : ''; ?>';
  65  var confirmMsg  = '<?php echo $GLOBALS['cfg']['Confirm']
  66      ? str_replace('\'', '\\\'', $GLOBALS['strDoYouReally']) : ''; ?>';
  67  /**/
  68  
  69  <?php
  70  if ( empty( $querydisplay_tab ) ) {
  71      $onload = 'onload="resize();"';
  72  ?>
  73  function resize() {
  74  
  75      // for Gecko
  76      if ( typeof( self.sizeToContent ) == 'function' ) {
  77          self.sizeToContent();
  78          //self.scrollbars.visible = false;
  79          // give some more space ... to prevent 'fli(pp/ck)ing'
  80          self.resizeBy( 10, 50 );
  81          return;
  82      }
  83  
  84      // for IE, Opera
  85      if (document.getElementById && typeof(document.getElementById('querywindowcontainer')) != 'undefined' ) {
  86  
  87          // get content size
  88          var newWidth  = document.getElementById('querywindowcontainer').offsetWidth;
  89          var newHeight = document.getElementById('querywindowcontainer').offsetHeight;
  90  
  91          // set size to contentsize
  92          // plus some offset for scrollbars, borders, statusbar, menus ...
  93          self.resizeTo( newWidth + 45, newHeight + 75 );
  94      }
  95  }
  96  <?php
  97  } else {
  98      $onload = '';
  99  }
 100  ?>
 101  //]]>
 102  </script>
 103  <script src="./js/functions.js" type="text/javascript" language="javascript"></script>
 104  </head>
 105  
 106  <body id="bodyquerywindow" <?php echo $onload; ?> >
 107  <div id="querywindowcontainer">
 108  <?php
 109  if ( !isset($no_js) ) {
 110      $querydisplay_tab = (isset($querydisplay_tab) ? $querydisplay_tab : $GLOBALS['cfg']['QueryWindowDefTab']);
 111  
 112      $tabs = array();
 113      $tabs['sql']['icon']   = 'b_sql.png';
 114      $tabs['sql']['text']   = $strSQL;
 115      $tabs['sql']['link']   = '#';
 116      $tabs['sql']['attr']   = 'onclick="javascript:query_tab_commit(\'sql\');return false;"';
 117      $tabs['sql']['active'] = (bool) ( $querydisplay_tab == 'sql' );
 118      $tabs['import']['icon']   = 'b_import.png';
 119      $tabs['import']['text']   = $strImportFiles;
 120      $tabs['import']['link']   = '#';
 121      $tabs['import']['attr']   = 'onclick="javascript:query_tab_commit(\'files\');return false;"';
 122      $tabs['import']['active'] = (bool) ( $querydisplay_tab == 'files' );
 123      $tabs['history']['icon']   = 'b_bookmark.png';
 124      $tabs['history']['text']   = $strQuerySQLHistory;
 125      $tabs['history']['link']   = '#';
 126      $tabs['history']['attr']   = 'onclick="javascript:query_tab_commit(\'history\');return false;"';
 127      $tabs['history']['active'] = (bool) ( $querydisplay_tab == 'history' );
 128  
 129      if ( $GLOBALS['cfg']['QueryWindowDefTab'] == 'full' ) {
 130          $tabs['all']['text']   = $strAll;
 131          $tabs['all']['link']   = '#';
 132          $tabs['all']['attr']   = 'onclick="javascript:query_tab_commit(\'full\');return false;"';
 133          $tabs['all']['active'] = (bool) ( $querydisplay_tab == 'full' );
 134      }
 135  
 136      echo PMA_getTabs( $tabs );
 137      unset( $tabs );
 138  } else {
 139      $querydisplay_tab = 'full';
 140  }
 141  
 142  if ( true == $GLOBALS['cfg']['PropertiesIconic'] ) {
 143      $titles['Change'] =
 144           '<img class="icon" width="16" height="16" src="' . $pmaThemeImage
 145          . 'b_edit.png" alt="' . $strChange . '" title="' . $strChange
 146          . '" />';
 147  
 148      if ( 'both' === $GLOBALS['cfg']['PropertiesIconic'] ) {
 149          $titles['Change'] .= $strChange;
 150      }
 151  } else {
 152      $titles['Change'] = $strChange;
 153  }
 154  
 155  // Hidden forms and query frame interaction stuff
 156  
 157  if ( ! empty( $query_history_latest ) && ! empty( $query_history_latest_db ) ) {
 158      if ( $GLOBALS['cfg']['QueryHistoryDB'] && $cfgRelation['historywork'] ) {
 159          PMA_setHistory((isset($query_history_latest_db) ? $query_history_latest_db : ''),
 160              (isset($query_history_latest_table) ? $query_history_latest_table : ''),
 161              $GLOBALS['cfg']['Server']['user'],
 162              $query_history_latest );
 163      }
 164  
 165      $_input_query_history[$query_history_latest] = array(
 166          'db'    => $query_history_latest_db,
 167          'table' => isset($query_history_latest_table) ? $query_history_latest_table : '',
 168      );
 169  
 170      $_sql_history[$query_history_latest] = array(
 171          'db'    =>  $query_history_latest_db,
 172          'table' => isset($query_history_latest_table) ? $query_history_latest_table : '',
 173      );
 174  
 175      $sql_query = $query_history_latest;
 176      $db = $query_history_latest_db;
 177      $table = $query_history_latest_table;
 178  } elseif ( ! empty( $query_history_latest ) ) {
 179      $sql_query = $query_history_latest;
 180  }
 181  
 182  if (isset($sql_query)) {
 183      $show_query = 1;
 184  }
 185  
 186  if ( $GLOBALS['cfg']['QueryHistoryDB'] && $cfgRelation['historywork'] ) {
 187  
 188      $temp_history = PMA_getHistory( $GLOBALS['cfg']['Server']['user'] );
 189      if (is_array($temp_history) && count($temp_history) > 0) {
 190          foreach ($temp_history AS $history_nr => $history_array) {
 191              if ( ! isset( $_sql_history[$history_array['sqlquery']] ) ) {
 192                  $_sql_history[$history_array['sqlquery']] = array(
 193                      'db'    => $history_array['db'],
 194                      'table' => isset( $history_array['table'] ) ? $history_array['table'] : '',
 195                  );
 196              }
 197          }
 198      }
 199  
 200  } else {
 201  
 202      if (isset($query_history) && is_array($query_history)) {
 203          $current_index = count($query_history);
 204          foreach ($query_history AS $query_no => $query_sql) {
 205              if ( ! isset( $_input_query_history[$query_sql] ) ) {
 206                  $_input_query_history[$query_sql] = array(
 207                      'db'    => $query_history_db[$query_no],
 208                      'table' => isset($query_history_table[$query_no]) ? $query_history_table[$query_no] : '',
 209                  );
 210                  $_sql_history[$query_sql] = array(
 211                      'db'    => $query_history_db[$query_no],
 212                      'table' => isset( $query_history_table[$query_no] ) ? $query_history_table[$query_no] : '',
 213                  );
 214              } // end if check if this item exists
 215          } // end while print history
 216      } // end if history exists
 217  } // end if DB-based history
 218  
 219  $url_query = PMA_generate_common_url(isset($db) ? $db : '', isset($table) ? $table : '');
 220  if (!isset($goto)) {
 221      $goto = '';
 222  }
 223  
 224  require_once  './libraries/bookmark.lib.php';
 225  
 226  if (isset($no_js) && $no_js) {
 227      // ... we redirect to appropriate query sql page
 228      // works only full if $db and $table is also stored/grabbed from $_COOKIE
 229      if ( isset( $table ) && strlen($table) ) {
 230          require  './tbl_sql.php';
 231      } elseif ( isset($db) && strlen($db) ) {
 232          require  './db_sql.php';
 233      } else {
 234          require  './server_sql.php';
 235      }
 236      exit;
 237  }
 238  
 239  /**
 240   * Defines the query to be displayed in the query textarea
 241   */
 242  if ( ! empty( $show_query ) ) {
 243      $query_to_display = $sql_query;
 244  } else {
 245      $query_to_display = '';
 246  }
 247  unset( $sql_query );
 248  
 249  PMA_sqlQueryForm( $query_to_display, $querydisplay_tab );
 250  
 251  // Hidden forms and query frame interaction stuff
 252  if (isset($auto_commit) && $auto_commit == 'true') {
 253  ?>
 254          <script type="text/javascript" language="javascript">
 255          //<![CDATA[
 256          query_auto_commit();
 257          //]]>
 258          </script>
 259  <?php
 260  }
 261  
 262  if ( count( $_sql_history ) > 0
 263    && ( $querydisplay_tab == 'history' || $querydisplay_tab == 'full' ) ) {
 264      $tab = isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full';
 265      echo $strQuerySQLHistory . ':<br />' . "\n"
 266          .'<ul>';
 267      foreach ( $_sql_history as $sql => $query ) {
 268          echo '<li>' . "\n";
 269          // edit link
 270          echo '<a href="#" onclick="'
 271                 .' document.getElementById(\'hiddenqueryform\').'
 272                 .'querydisplay_tab.value = \'' . $tab . '\';'
 273                 .' document.getElementById(\'hiddenqueryform\').'
 274                 .'query_history_latest.value = \''
 275                 . preg_replace('/(\r|\n)+/i', '\\n',
 276                      PMA_jsFormat($sql, false) ) . '\';'
 277                 .' document.getElementById(\'hiddenqueryform\').'
 278                 .'auto_commit.value = \'false\';'
 279                 .' document.getElementById(\'hiddenqueryform\').'
 280                 .'db.value = \'' . htmlspecialchars( $query['db'] ) . '\';'
 281                 .' document.getElementById(\'hiddenqueryform\').'
 282                 .'query_history_latest_db.value = \''
 283                 . htmlspecialchars( $query['db'] ) . '\';'
 284                 .' document.getElementById(\'hiddenqueryform\').'
 285                 .'table.value = \'' . htmlspecialchars( $query['table'] ) . '\';'
 286                 .' document.getElementById(\'hiddenqueryform\').'
 287                 .'query_history_latest_table.value = \''
 288                 . htmlspecialchars( $query['table'] ) . '\';'
 289                 .' document.getElementById(\'hiddenqueryform\').submit();'
 290                 .' return false;">' . $titles['Change'] . '</a>';
 291              // execute link
 292          echo '<a href="#" onclick="'
 293                 .' document.getElementById(\'hiddenqueryform\').'
 294                 .'querydisplay_tab.value = \'' . $tab . '\';'
 295                 .' document.getElementById(\'hiddenqueryform\').'
 296                 .'query_history_latest.value = \''
 297                 . preg_replace('/(\r|\n)+/i', '\\r\\n',
 298                      PMA_jsFormat($sql, false) ) . '\';'
 299                 .' document.getElementById(\'hiddenqueryform\').'
 300                 .'auto_commit.value = \'true\';'
 301                 .' document.getElementById(\'hiddenqueryform\').'
 302                 .'db.value = \'' . htmlspecialchars( $query['db'] ) . '\';'
 303                 .' document.getElementById(\'hiddenqueryform\').'
 304                 .'query_history_latest_db.value = \''
 305                 . htmlspecialchars( $query['db'] ) . '\';'
 306                 .' document.getElementById(\'hiddenqueryform\').'
 307                 .'table.value = \'' . htmlspecialchars( $query['table'] ) . '\';'
 308                 .' document.getElementById(\'hiddenqueryform\').'
 309                 .'query_history_latest_table.value = \''
 310                 . htmlspecialchars( $query['table'] ) . '\';'
 311                 .' document.getElementById(\'hiddenqueryform\').submit();'
 312                 .' return false;">[' . htmlspecialchars( $query['db'] ) . '] '
 313                 . htmlspecialchars($sql) . '</a>' . "\n";
 314  
 315          echo '</li>' . "\n";
 316      }
 317      unset( $tab, $_sql_history, $sql, $query );
 318      echo '</ul>' . "\n";
 319  }
 320  ?>
 321  <form action="querywindow.php" method="post" name="querywindow" id="hiddenqueryform">
 322  <?php
 323  echo PMA_generate_common_hidden_inputs('', '') . "\n";
 324  foreach ( $_input_query_history as $sql => $history ) {
 325      echo '<input type="hidden" name="query_history[]" value="'
 326          . $sql . '" />' . "\n";
 327      echo '<input type="hidden" name="query_history_db[]" value="'
 328          . htmlspecialchars( $history['db'] ) . '" />' . "\n";
 329      echo '<input type="hidden" name="query_history_table[]" value="'
 330          . htmlspecialchars( $history['table'] ) . '" />' . "\n";
 331  }
 332  unset( $_input_query_history, $sql, $history );
 333  ?>
 334      <input type="hidden" name="db" value="<?php echo (! isset($db) ? '' : htmlspecialchars($db)); ?>" />
 335      <input type="hidden" name="table" value="<?php echo (! isset($table) ? '' : htmlspecialchars($table)); ?>" />
 336  
 337      <input type="hidden" name="query_history_latest" value="" />
 338      <input type="hidden" name="query_history_latest_db" value="" />
 339      <input type="hidden" name="query_history_latest_table" value="" />
 340  
 341      <input type="hidden" name="previous_db" value="<?php echo htmlspecialchars($db); ?>" />
 342  
 343      <input type="hidden" name="auto_commit" value="false" />
 344      <input type="hidden" name="querydisplay_tab" value="<?php echo $querydisplay_tab; ?>" />
 345  </form>
 346      <?php
 347  ?>
 348  </div>
 349  </body>
 350  </html>
 351  
 352  <?php
 353  
 354  /**
 355   * Close MySql connections
 356   */
 357  if (isset($controllink) && $controllink) {
 358      PMA_DBI_close($controllink);
 359  }
 360  if (isset($userlink) && $userlink) {
 361      PMA_DBI_close($userlink);
 362  }
 363  
 364  
 365  /**
 366   * Sends bufferized data
 367   */
 368  if ( $GLOBALS['cfg']['OBGzip'] && isset( $ob_mode ) && $ob_mode ) {
 369       PMA_outBufferPost($ob_mode);
 370  }
 371  ?>


Généré le : Mon Nov 26 15:18:20 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics