[ Index ]
 

Code source de phpMyAdmin 2.10.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/ -> tbl_operations.php (source)

   1  <?php
   2  /* $Id: tbl_operations.php 9608 2006-10-26 07:46:45Z nijel $ */
   3  // vim: expandtab sw=4 ts=4 sts=4:
   4  
   5  require_once  './libraries/common.lib.php';
   6  require_once  './libraries/Table.class.php';
   7  
   8  $pma_table = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
   9  
  10  /**
  11   * Runs common work
  12   */
  13  require  './libraries/tbl_common.php';
  14  $url_query .= '&amp;goto=tbl_operations.php&amp;back=tbl_operations.php';
  15  $url_params['goto'] = $url_params['back'] = 'tbl_operations.php';
  16  
  17  /**
  18   * Gets relation settings
  19   */
  20  require_once  './libraries/relation.lib.php';
  21  $cfgRelation = PMA_getRelationsParam();
  22  
  23  /**
  24   * Gets available MySQL charsets and storage engines
  25   */
  26  require_once  './libraries/mysql_charsets.lib.php';
  27  require_once  './libraries/storage_engines.lib.php';
  28  
  29  // reselect current db (needed in some cases probably due to
  30  // the calling of relation.lib.php)
  31  PMA_DBI_select_db($GLOBALS['db']);
  32  
  33  /**
  34   * Gets tables informations
  35   */
  36  
  37  require  './libraries/tbl_info.inc.php';
  38  
  39  $reread_info = false;
  40  $errors = array();
  41  $table_alters = array();
  42  
  43  /**
  44   * Updates table comment, type and options if required
  45   */
  46  if (isset($_REQUEST['submitoptions'])) {
  47      $message = '';
  48      if (isset($_REQUEST['new_name'])) {
  49          if ($pma_table->rename($_REQUEST['new_name'])) {
  50              $message .= $pma_table->getLastMessage();
  51              $GLOBALS['table'] = $pma_table->getName();;
  52              $reread_info = true;
  53              $reload = true;
  54          } else {
  55              $errors[] = $pma_table->getLastError();
  56              $message .= $pma_table->getLastError();
  57          }
  58      }
  59      if (isset($_REQUEST['comment'])
  60        && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment']) {
  61          $table_alters[] = 'COMMENT = \'' . PMA_sqlAddslashes($_REQUEST['comment']) . '\'';
  62      }
  63      if (! empty($_REQUEST['new_tbl_type'])
  64        && strtolower($_REQUEST['new_tbl_type']) !== strtolower($tbl_type)) {
  65          $table_alters[] = PMA_ENGINE_KEYWORD . ' = ' . $_REQUEST['new_tbl_type'];
  66          $tbl_type = $_REQUEST['new_tbl_type'];
  67      }
  68  
  69      if (! empty($_REQUEST['tbl_collation'])
  70        && $_REQUEST['tbl_collation'] !== $tbl_collation) {
  71          $table_alters[] = 'DEFAULT ' . PMA_generateCharsetQueryPart($_REQUEST['tbl_collation']);
  72      }
  73  
  74      $l_tbl_type = strtolower($tbl_type);
  75  
  76      if (($l_tbl_type === 'myisam' || $l_tbl_type === 'isam')
  77        && isset($_REQUEST['new_pack_keys'])
  78        && $_REQUEST['new_pack_keys'] != (string)$pack_keys) {
  79          $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
  80      }
  81  
  82      $checksum = empty($checksum) ? '0' : '1';
  83      $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ? '0' : '1';
  84      if (($l_tbl_type === 'myisam')
  85        && $_REQUEST['new_checksum'] !== $checksum) {
  86          $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum'];
  87      }
  88  
  89      $delay_key_write = empty($delay_key_write) ? '0' : '1';
  90      $_REQUEST['new_delay_key_write'] = empty($_REQUEST['new_delay_key_write']) ? '0' : '1';
  91      if (($l_tbl_type === 'myisam')
  92        && $_REQUEST['new_delay_key_write'] !== $delay_key_write) {
  93          $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write'];
  94      }
  95  
  96      if (($l_tbl_type === 'myisam' || $l_tbl_type === 'innodb')
  97        &&  ! empty($_REQUEST['new_auto_increment'])
  98        && (! isset($auto_increment) || $_REQUEST['new_auto_increment'] !== $auto_increment)) {
  99          $table_alters[] = 'auto_increment = ' . PMA_sqlAddslashes($_REQUEST['new_auto_increment']);
 100      }
 101  
 102      if (count($table_alters) > 0) {
 103          $sql_query      = 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']);
 104          $sql_query     .= "\r\n" . implode("\r\n", $table_alters);
 105          $message        .= PMA_DBI_query($sql_query) ? $strSuccess : $strError;
 106          $reread_info    = true;
 107          unset($table_alters);
 108      }
 109  }
 110  /**
 111   * Reordering the table has been requested by the user
 112   */
 113  if (isset($_REQUEST['submitorderby']) && ! empty($_REQUEST['order_field'])) {
 114      $sql_query = '
 115          ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . '
 116          ORDER BY ' . PMA_backquote(urldecode($_REQUEST['order_field']));
 117      if (isset($_REQUEST['order_order']) && $_REQUEST['order_order'] === 'desc') {
 118          $sql_query .= ' DESC';
 119      }
 120      $message = PMA_DBI_query($sql_query) ? $strSuccess : $strError;
 121  } // end if
 122  
 123  
 124  if ($reread_info) {
 125      $checksum = $delay_key_write = 0;
 126      require  './libraries/tbl_info.inc.php';
 127  }
 128  unset($reread_info);
 129  
 130  /**
 131   * Displays top menu links
 132   */
 133  require_once  './libraries/tbl_links.inc.php';
 134  
 135  $url_params['goto'] = 'tbl_operations.php';
 136  $url_params['back'] = 'tbl_operations.php';
 137  
 138  /**
 139   * Get columns names
 140   */
 141  $local_query = '
 142      SHOW COLUMNS
 143      FROM ' . PMA_backquote($GLOBALS['table']) . '
 144      FROM ' . PMA_backquote($GLOBALS['db']);
 145  $columns = PMA_DBI_fetch_result($local_query, null, 'Field');
 146  unset($local_query);
 147  
 148  /**
 149   * Displays the page
 150   */
 151  ?>
 152  <!-- Order the table -->
 153  <div id="div_table_order">
 154  <form method="post" action="tbl_operations.php">
 155  <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
 156  <fieldset id="fieldset_table_order">
 157      <legend><?php echo $strAlterOrderBy; ?></legend>
 158      <select name="order_field">
 159  <?php
 160  foreach ($columns as $fieldname) {
 161      echo '            <option value="' . htmlspecialchars($fieldname) . '">'
 162          . htmlspecialchars($fieldname) . '</option>' . "\n";
 163  }
 164  unset($columns);
 165  ?>
 166      </select> <?php echo $strSingly; ?>
 167      <select name="order_order">
 168          <option value="asc"><?php echo $strAscending; ?></option>
 169          <option value="desc"><?php echo $strDescending; ?></option>
 170      </select>
 171      <input type="submit" name="submitorderby" value="<?php echo $strGo; ?>" />
 172  </fieldset>
 173  </form>
 174  </div>
 175  
 176  <!-- Move table -->
 177  <div id="div_table_rename">
 178  <form method="post" action="tbl_move_copy.php"
 179      onsubmit="return emptyFormElements(this, 'new_name')">
 180  <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
 181  <input type="hidden" name="reload" value="1" />
 182  <input type="hidden" name="what" value="data" />
 183  <fieldset id="fieldset_table_rename">
 184      <legend><?php echo $strMoveTable; ?></legend>
 185      <select name="target_db">
 186          <?php echo $GLOBALS['PMA_List_Database']->getHtmlOptions(); ?>
 187      </select>
 188      &nbsp;<b>.</b>&nbsp;
 189      <input type="text" size="20" name="new_name" onfocus="this.select()"
 190  value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" /><br />
 191      <?php
 192      // starting with MySQL 5.0.24, SHOW CREATE TABLE includes the AUTO_INCREMENT
 193      // next value but users can decide if they want it or not for the operation
 194      ?>
 195      <input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment_mv" checked="checked" />
 196      <label for="checkbox_auto_increment_mv"><?php echo $strAddAutoIncrement; ?></label><br />
 197  </fieldset>
 198  <fieldset class="tblFooters">
 199      <input type="submit" name="submit_move" value="<?php echo $strGo; ?>" />
 200  </fieldset>
 201  </form>
 202  </div>
 203  
 204  <?php
 205  if (strstr($show_comment, '; InnoDB free') === false) {
 206      if (strstr($show_comment, 'InnoDB free') === false) {
 207          // only user entered comment
 208          $comment = $show_comment;
 209      } else {
 210          // here we have just InnoDB generated part
 211          $comment = '';
 212      }
 213  } else {
 214      // remove InnoDB comment from end, just the minimal part (*? is non greedy)
 215      $comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment);
 216  }
 217  
 218  // PACK_KEYS: MyISAM or ISAM
 219  // DELAY_KEY_WRITE, CHECKSUM, : MyISAM only
 220  // AUTO_INCREMENT: MyISAM and InnoDB since 5.0.3
 221  
 222  // nijel: Here should be version check for InnoDB, however it is supported
 223  // in >5.0.4, >4.1.12 and >4.0.11, so I decided not to
 224  // check for version
 225  ?>
 226  
 227  <!-- Table options -->
 228  <div id="div_table_options">
 229  <form method="post" action="tbl_operations.php">
 230  <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
 231  <input type="hidden" name="reload" value="1" />
 232  <fieldset>
 233      <legend><?php echo $strTableOptions; ?></legend>
 234  
 235      <table>
 236      <!-- Change table name -->
 237      <tr><td><?php echo $strRenameTable; ?></td>
 238          <td><input type="text" size="20" name="new_name" onfocus="this.select()"
 239                  value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" />
 240          </td>
 241      </tr>
 242  
 243      <!-- Table comments -->
 244      <tr><td><?php echo $strTableComments; ?></td>
 245          <td><input type="text" name="comment" maxlength="60" size="30"
 246                  value="<?php echo htmlspecialchars($comment); ?>" onfocus="this.select()" />
 247              <input type="hidden" name="prev_comment" value="<?php echo urlencode($comment); ?>" />
 248          </td>
 249      </tr>
 250  
 251      <!-- Storage engine -->
 252      <tr><td><?php echo $strStorageEngine; ?>
 253              <?php echo PMA_showMySQLDocu('Storage_engines', 'Storage_engines'); ?>
 254          </td>
 255          <td><?php echo PMA_generateEnginesDropdown('new_tbl_type', null, false, $tbl_type, 4); ?>
 256          </td>
 257      </tr>
 258  
 259  <?php
 260  if (PMA_MYSQL_INT_VERSION >= 40100) {
 261      ?>
 262      <!-- Table character set -->
 263      <tr><td><?php echo $strCollation; ?></td>
 264          <td><?php echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION,
 265                  'tbl_collation', null, $tbl_collation, false, 3); ?>
 266          </td>
 267      </tr>
 268      <?php
 269  }
 270  if ($tbl_type == 'MYISAM' || $tbl_type == 'ISAM') {
 271      ?>
 272      <tr>
 273          <td><label for="new_pack_keys">pack_keys</label></td>
 274          <td><select name="new_pack_keys" id="new_pack_keys">
 275                  <option value="DEFAULT"
 276                      <?php if ($pack_keys == 'DEFAULT') echo 'selected="selected"'; ?>
 277                      >DEFAULT</option>
 278                  <option value="0"
 279                      <?php if ($pack_keys == '0') echo 'selected="selected"'; ?>
 280                      >0</option>
 281                  <option value="1"
 282                      <?php if ($pack_keys == '1') echo 'selected="selected"'; ?>
 283                      >1</option>
 284              </select>
 285          </td>
 286      </tr>
 287      <?php
 288  } // end if (MYISAM|ISAM)
 289  
 290  if ($tbl_type == 'MYISAM') {
 291      ?>
 292      <tr><td><label for="new_checksum">checksum</label></td>
 293          <td><input type="checkbox" name="new_checksum" id="new_checksum"
 294                  value="1"
 295      <?php echo (isset($checksum) && $checksum == 1)
 296          ? ' checked="checked"'
 297          : ''; ?> />
 298          </td>
 299      </tr>
 300  
 301      <tr><td><label for="new_delay_key_write">delay_key_write</label></td>
 302          <td><input type="checkbox" name="new_delay_key_write" id="new_delay_key_write"
 303                  value="1"
 304      <?php echo (isset($delay_key_write) && $delay_key_write == 1)
 305          ? ' checked="checked"'
 306          : ''; ?> />
 307          </td>
 308      </tr>
 309  
 310      <?php
 311  } // end if (MYISAM)
 312  
 313  if (isset($auto_increment) && strlen($auto_increment) > 0
 314    && ($tbl_type == 'MYISAM' || $tbl_type == 'INNODB')) {
 315      ?>
 316      <tr><td><label for="auto_increment_opt">auto_increment</label></td>
 317          <td><input type="text" name="new_auto_increment" id="auto_increment_opt"
 318                  value="<?php echo $auto_increment; ?>" /></td>
 319      </tr>
 320      <?php
 321  } // end if (MYISAM|INNODB)
 322  ?>
 323      </table>
 324  </fieldset>
 325  <fieldset class="tblFooters">
 326          <input type="submit" name="submitoptions" value="<?php echo $strGo; ?>" />
 327  </fieldset>
 328  </form>
 329  </div>
 330  
 331  <!-- Copy table -->
 332  <div id="div_table_copy">
 333  <form method="post" action="tbl_move_copy.php"
 334      onsubmit="return emptyFormElements(this, 'new_name')">
 335  <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
 336  <input type="hidden" name="reload" value="1" />
 337  <fieldset>
 338      <legend><?php echo $strCopyTable; ?></legend>
 339      <select name="target_db">
 340          <?php echo $GLOBALS['PMA_List_Database']->getHtmlOptions(true); ?>
 341      </select>
 342      &nbsp;<b>.</b>&nbsp;
 343      <input type="text" size="20" name="new_name" onfocus="this.select()" /><br />
 344  
 345      <input type="radio" name="what" value="structure" id="radio_copy_structure" />
 346      <label for="radio_copy_structure"><?php echo $strStrucOnly; ?></label><br />
 347      <input type="radio" name="what" value="data" id="radio_copy_data" checked="checked" />
 348      <label for="radio_copy_data"><?php echo $strStrucData; ?></label><br />
 349      <input type="radio" name="what" value="dataonly" id="radio_copy_dataonly" />
 350      <label for="radio_copy_dataonly"><?php echo $strDataOnly; ?></label><br />
 351  
 352      <input type="checkbox" name="drop_if_exists" value="true" id="checkbox_drop" />
 353      <label for="checkbox_drop"><?php echo sprintf($strAddClause, 'DROP TABLE'); ?></label><br />
 354      <input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment_cp" />
 355      <label for="checkbox_auto_increment_cp"><?php echo $strAddAutoIncrement; ?></label><br />
 356      <?php
 357          // display "Add constraints" choice only if there are
 358          // foreign keys
 359          if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'innodb')) {
 360          ?>
 361      <input type="checkbox" name="add_constraints" value="1" id="checkbox_constraints" />
 362      <label for="checkbox_constraints"><?php echo $strAddConstraints; ?></label><br />
 363          <?php
 364          } // endif
 365          if (isset($_COOKIE['pma_switch_to_new'])
 366            && $_COOKIE['pma_switch_to_new'] == 'true') {
 367              $pma_switch_to_new = 'true';
 368          }
 369      ?>
 370      <input type="checkbox" name="switch_to_new" value="true"
 371          id="checkbox_switch"<?php echo
 372              isset($pma_switch_to_new) && $pma_switch_to_new == 'true'
 373              ? ' checked="checked"'
 374              : ''; ?> />
 375      <label for="checkbox_switch"><?php echo $strSwitchToTable; ?></label>
 376  </fieldset>
 377  <fieldset class="tblFooters">
 378      <input type="submit" name="submit_copy" value="<?php echo $strGo; ?>" />
 379  </fieldset>
 380  </form>
 381  </div>
 382  
 383  <br class="clearfloat"/>
 384  
 385  <h1><?php echo $strTableMaintenance; ?></h1>
 386  
 387  <ul>
 388  <?php
 389  if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB' || $tbl_type == 'INNODB') {
 390      if ($tbl_type == 'MYISAM' || $tbl_type == 'INNODB') {
 391          $this_url_params = array_merge($url_params,
 392              array('sql_query' => 'CHECK TABLE ' . PMA_backquote($GLOBALS['table'])));
 393          ?>
 394      <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
 395              <?php echo $strCheckTable; ?></a>
 396          <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'CHECK_TABLE'); ?>
 397      </li>
 398          <?php
 399      }
 400      if ($tbl_type == 'INNODB') {
 401          $this_url_params = array_merge($url_params,
 402              array('sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ' . PMA_ENGINE_KEYWORD . '=InnoDB'));
 403          ?>
 404      <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
 405              <?php echo $strDefragment; ?></a>
 406          <?php echo PMA_showMySQLDocu('Table_types', 'InnoDB_File_Defragmenting'); ?>
 407      </li>
 408          <?php
 409      }
 410      if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB') {
 411          $this_url_params = array_merge($url_params,
 412              array('sql_query' => 'ANALYZE TABLE ' . PMA_backquote($GLOBALS['table'])));
 413          ?>
 414      <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
 415              <?php echo $strAnalyzeTable; ?></a>
 416          <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'ANALYZE_TABLE');?>
 417      </li>
 418          <?php
 419      }
 420      if ($tbl_type == 'MYISAM') {
 421          $this_url_params = array_merge($url_params,
 422              array('sql_query' => 'REPAIR TABLE ' . PMA_backquote($GLOBALS['table'])));
 423          ?>
 424      <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
 425              <?php echo $strRepairTable; ?></a>
 426          <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'REPAIR_TABLE'); ?>
 427      </li>
 428          <?php
 429      }
 430      if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB' || $tbl_type == 'INNODB') {
 431          $this_url_params = array_merge($url_params,
 432              array('sql_query' => 'OPTIMIZE TABLE ' . PMA_backquote($GLOBALS['table'])));
 433          ?>
 434      <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
 435              <?php echo $strOptimizeTable; ?></a>
 436          <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE'); ?>
 437      </li>
 438          <?php
 439      }
 440  } // end MYISAM or BERKELEYDB case
 441  $this_url_params = array_merge($url_params,
 442      array(
 443          'sql_query' => 'FLUSH TABLE ' . PMA_backquote($GLOBALS['table']),
 444          'zero_rows' => sprintf($strTableHasBeenFlushed,
 445              htmlspecialchars($GLOBALS['table'])),
 446          'reload'    => 1,
 447          ));
 448  ?>
 449      <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
 450              <?php echo $strFlushTable; ?></a>
 451          <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH'); ?>
 452      </li>
 453  </ul>
 454  <?php
 455  // Referential integrity check
 456  // The Referential integrity check was intended for the non-InnoDB
 457  // tables for which the relations are defined in pmadb
 458  // so I assume that if the current table is InnoDB, I don't display
 459  // this choice (InnoDB maintains integrity by itself)
 460  
 461  if ($cfgRelation['relwork'] && $tbl_type != "INNODB") {
 462  
 463      // we need this PMA_DBI_select_db if the user has access to more than one db
 464      // and $GLOBALS['db'] is not the last of the list, because
 465      // PMA_List_Database::_checkAccess()
 466      // has made a PMA_DBI_select_db() on the last one
 467      PMA_DBI_select_db($GLOBALS['db']);
 468      $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);
 469  
 470      if ($foreign) {
 471          ?>
 472      <!-- Referential integrity check -->
 473      <ul>
 474          <?php echo $strReferentialIntegrity; ?><br />
 475          <?php
 476          echo "\n";
 477          foreach ($foreign AS $master => $arr) {
 478              $join_query  = 'SELECT ' . PMA_backquote($GLOBALS['table']) . '.* FROM '
 479                           . PMA_backquote($GLOBALS['table']) . ' LEFT JOIN '
 480                           . PMA_backquote($arr['foreign_table']);
 481              if ($arr['foreign_table'] == $GLOBALS['table']) {
 482                  $foreign_table = $GLOBALS['table'] . '1';
 483                  $join_query .= ' AS ' . PMA_backquote($foreign_table);
 484              } else {
 485                  $foreign_table = $arr['foreign_table'];
 486              }
 487              $join_query .= ' ON '
 488                           . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
 489                           . ' = ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
 490                           . ' WHERE '
 491                           . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
 492                           . ' IS NULL AND '
 493                           . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
 494                           . ' IS NOT NULL';
 495              $this_url_params = array_merge($url_params,
 496                  array('sql_query' => $join_query));
 497              echo '        <li>'
 498                   . '<a href="sql.php'
 499                   . PMA_generate_common_url($this_url_params)
 500                   . '">' . $master . '&nbsp;->&nbsp;' . $arr['foreign_table'] . '.' . $arr['foreign_field']
 501                   . '</a></li>' . "\n";
 502          } //  foreach $foreign
 503          unset($foreign_table, $join_query);
 504          ?>
 505      </ul>
 506          <?php
 507      } // end if ($result)
 508  
 509  } // end  if (!empty($cfg['Server']['relation']))
 510  
 511  
 512  /**
 513   * Displays the footer
 514   */
 515  require_once  './libraries/footer.inc.php';
 516  ?>


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