more cleanup/refactoring on index code
This commit is contained in:
@@ -20,9 +20,9 @@ class PMA_Index
|
||||
protected static $_registry = array();
|
||||
|
||||
/**
|
||||
* @var string The name of the database
|
||||
* @var string The name of the schema
|
||||
*/
|
||||
protected $_database = '';
|
||||
protected $_schema = '';
|
||||
|
||||
/**
|
||||
* @var string The name of the table
|
||||
@@ -86,21 +86,36 @@ class PMA_Index
|
||||
$this->set($params);
|
||||
}
|
||||
|
||||
static public function singleton($schema, $table, $index_name = '')
|
||||
{
|
||||
PMA_Index::_loadIndexes($table, $schema);
|
||||
if (! isset(PMA_Index::$_registry[$schema][$table][$index_name])) {
|
||||
$index = new PMA_Index;
|
||||
if (strlen($index_name)) {
|
||||
$index->setName($index_name);
|
||||
PMA_Index::$_registry[$schema][$table][$index->getName()] = $index;
|
||||
}
|
||||
return $index;
|
||||
} else {
|
||||
return PMA_Index::$_registry[$schema][$table][$index_name];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an array with all indexes from the given table
|
||||
*
|
||||
* @uses PMA_Index::_loadIndexes()
|
||||
* @uses PMA_Index::$_registry
|
||||
* @param string $table
|
||||
* @param string $database
|
||||
* @param string $schema
|
||||
* @return array
|
||||
*/
|
||||
static public function getFromTable($table, $database)
|
||||
static public function getFromTable($table, $schema)
|
||||
{
|
||||
PMA_Index::_loadIndexes($table, $database);
|
||||
PMA_Index::_loadIndexes($table, $schema);
|
||||
|
||||
if (isset(PMA_Index::$_registry[$database][$table])) {
|
||||
return PMA_Index::$_registry[$database][$table];
|
||||
if (isset(PMA_Index::$_registry[$schema][$table])) {
|
||||
return PMA_Index::$_registry[$schema][$table];
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
@@ -112,15 +127,15 @@ class PMA_Index
|
||||
* @uses PMA_Index::_loadIndexes()
|
||||
* @uses PMA_Index::$_registry
|
||||
* @param string $table
|
||||
* @param string $database
|
||||
* @param string $schema
|
||||
* @return mixed primary index or false if no one exists
|
||||
*/
|
||||
static public function getPrimary($table, $database)
|
||||
static public function getPrimary($table, $schema)
|
||||
{
|
||||
PMA_Index::_loadIndexes($table, $database);
|
||||
PMA_Index::_loadIndexes($table, $schema);
|
||||
|
||||
if (isset(PMA_Index::$_registry[$database][$table]['PRIMARY'])) {
|
||||
return PMA_Index::$_registry[$database][$table]['PRIMARY'];
|
||||
if (isset(PMA_Index::$_registry[$schema][$table]['PRIMARY'])) {
|
||||
return PMA_Index::$_registry[$schema][$table]['PRIMARY'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -135,22 +150,23 @@ class PMA_Index
|
||||
* @uses PMA_Index
|
||||
* @uses PMA_Index->addColumn()
|
||||
* @param string $table
|
||||
* @param string $database
|
||||
* @param string $schema
|
||||
* @return boolean
|
||||
*/
|
||||
static protected function _loadIndexes($table, $database)
|
||||
static protected function _loadIndexes($table, $schema)
|
||||
{
|
||||
if (isset(PMA_Index::$_registry[$database][$table])) {
|
||||
if (isset(PMA_Index::$_registry[$schema][$table])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$_raw_indexes = PMA_DBI_fetch_result('SHOW INDEX FROM ' . PMA_backquote($database) . '.' . PMA_backquote($table));
|
||||
$_raw_indexes = PMA_DBI_fetch_result('SHOW INDEX FROM ' . PMA_backquote($schema) . '.' . PMA_backquote($table));
|
||||
foreach ($_raw_indexes as $_each_index) {
|
||||
if (! isset(PMA_Index::$_registry[$database][$table][$_each_index['Key_name']])) {
|
||||
$_each_index['Schema'] = $schema;
|
||||
if (! isset(PMA_Index::$_registry[$schema][$table][$_each_index['Key_name']])) {
|
||||
$key = new PMA_Index($_each_index);
|
||||
PMA_Index::$_registry[$database][$table][$_each_index['Key_name']] = $key;
|
||||
PMA_Index::$_registry[$schema][$table][$_each_index['Key_name']] = $key;
|
||||
} else {
|
||||
$key = PMA_Index::$_registry[$database][$table][$_each_index['Key_name']];
|
||||
$key = PMA_Index::$_registry[$schema][$table][$_each_index['Key_name']];
|
||||
}
|
||||
|
||||
$key->addColumn($_each_index);
|
||||
@@ -168,8 +184,37 @@ class PMA_Index
|
||||
*/
|
||||
public function addColumn($params)
|
||||
{
|
||||
if (strlen($params['Column_name'])) {
|
||||
$this->_columns[$params['Column_name']] = new PMA_Index_Column($params);
|
||||
}
|
||||
}
|
||||
|
||||
public function addColumns($columns)
|
||||
{
|
||||
$_columns = array();
|
||||
|
||||
if (isset($columns['names'])) {
|
||||
// coming from form
|
||||
// $columns[names][]
|
||||
// $columns[sub_parts][]
|
||||
foreach ($columns['names'] as $key => $name) {
|
||||
$_columns[] = array(
|
||||
'Column_name' => $name,
|
||||
'Sub_part' => $columns['sub_parts'][$key],
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// coming from SHOW INDEXES
|
||||
// $columns[][name]
|
||||
// $columns[][sub_part]
|
||||
// ...
|
||||
$_columns = $columns;
|
||||
}
|
||||
|
||||
foreach ($_columns as $column) {
|
||||
$this->addColumn($column);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if $column indexed in this index
|
||||
@@ -185,8 +230,11 @@ class PMA_Index
|
||||
|
||||
public function set($params)
|
||||
{
|
||||
if (isset($params['Column_name'])) {
|
||||
$this->_database = $params['Column_name'];
|
||||
if (isset($params['columns'])) {
|
||||
$this->addColumns($params['columns']);
|
||||
}
|
||||
if (isset($params['Schema'])) {
|
||||
$this->_schema = $params['Schema'];
|
||||
}
|
||||
if (isset($params['Table'])) {
|
||||
$this->_table = $params['Table'];
|
||||
@@ -295,6 +343,11 @@ class PMA_Index
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->_name = (string) $name;
|
||||
}
|
||||
|
||||
public function getColumns()
|
||||
{
|
||||
return $this->_columns;
|
||||
|
344
tbl_indexes.php
344
tbl_indexes.php
@@ -12,49 +12,7 @@
|
||||
require_once './libraries/common.inc.php';
|
||||
require_once './libraries/tbl_indexes.lib.php';
|
||||
require_once './libraries/Index.class.php';
|
||||
|
||||
/**
|
||||
* Ensures the db & table are valid, then loads headers and gets indexes
|
||||
* informations.
|
||||
* Skipped if this script is called by "tbl_sql.php"
|
||||
*/
|
||||
// Not a valid db name -> back to the welcome page
|
||||
if (strlen($db)) {
|
||||
$is_db = PMA_DBI_select_db($db);
|
||||
}
|
||||
if (!strlen($db) || !$is_db) {
|
||||
$uri_params = array('reload' => '1');
|
||||
if (isset($message)) {
|
||||
$uri_params['message'] = $message;
|
||||
}
|
||||
PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . 'main.php'
|
||||
. PMA_generate_common_url($uri_params, '&'));
|
||||
exit;
|
||||
}
|
||||
// Not a valid table name -> back to the default db sub-page
|
||||
if (strlen($table)) {
|
||||
$is_table = PMA_DBI_query('SHOW TABLES LIKE \''
|
||||
. PMA_sqlAddslashes($table, TRUE) . '\'', null, PMA_DBI_QUERY_STORE);
|
||||
}
|
||||
if (! strlen($table)
|
||||
|| !($is_table && PMA_DBI_num_rows($is_table))) {
|
||||
$uri_params = array('reload' => '1', 'db' => $db);
|
||||
if (isset($message)) {
|
||||
$uri_params['message'] = $message;
|
||||
}
|
||||
PMA_sendHeaderLocation($cfg['PmaAbsoluteUri']
|
||||
. $cfg['DefaultTabDatabase']
|
||||
. PMA_generate_common_url($uri_params, '&'));
|
||||
exit;
|
||||
} elseif (isset($is_table)) {
|
||||
PMA_DBI_free_result($is_table);
|
||||
}
|
||||
|
||||
// Displays headers (if needed)
|
||||
$GLOBALS['js_include'][] = 'functions.js';
|
||||
$GLOBALS['js_include'][] = 'indexes.js';
|
||||
require_once './libraries/header.inc.php';
|
||||
|
||||
require_once './libraries/tbl_common.php';
|
||||
|
||||
/**
|
||||
* Gets fields and indexes informations
|
||||
@@ -68,229 +26,173 @@ $ret_keys = PMA_get_indexes($table, $err_url_0);
|
||||
|
||||
PMA_extract_indexes($ret_keys, $indexes_info, $indexes_data);
|
||||
|
||||
$indexes = PMA_Index::getFromTable($table, $db);
|
||||
|
||||
// Get fields and stores their name/type
|
||||
// fields had already been grabbed in "tbl_sql.php"
|
||||
$fields_rs = PMA_DBI_query('SHOW FIELDS FROM '
|
||||
. PMA_backquote($table) . ';');
|
||||
$save_row = array();
|
||||
while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
|
||||
$save_row[] = $row;
|
||||
}
|
||||
|
||||
$fields_names = array();
|
||||
$fields_types = array();
|
||||
foreach ($save_row AS $saved_row_key => $row) {
|
||||
$fields_names[] = $row['Field'];
|
||||
// loic1: set or enum types: slashes single quotes inside options
|
||||
$fields = array();
|
||||
foreach (PMA_DBI_get_fields($db, $table) as $row) {
|
||||
if (preg_match('@^(set|enum)\((.+)\)$@i', $row['Type'], $tmp)) {
|
||||
$tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'',
|
||||
',' . $tmp[2]), 1);
|
||||
$fields_types[] = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
|
||||
$fields[$row['Field']] = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
|
||||
} else {
|
||||
$fields_types[] = $row['Type'];
|
||||
$fields[$row['Field']] = $row['Type'];
|
||||
}
|
||||
} // end while
|
||||
|
||||
if ($fields_rs) {
|
||||
PMA_DBI_free_result($fields_rs);
|
||||
// Prepares the form values
|
||||
if (isset($_REQUEST['index'])) {
|
||||
if (is_array($_REQUEST['index'])) {
|
||||
// coming already from form
|
||||
$index = new PMA_Index($_REQUEST['index']);
|
||||
} else {
|
||||
$index = PMA_Index::singleton($db, $table, $_REQUEST['index']);
|
||||
}
|
||||
} else {
|
||||
$index = new PMA_Index;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Do run the query to build the new index and moves back to
|
||||
* "tbl_sql.php"
|
||||
* Process the data from the edit/create index form,
|
||||
* run the query to build the new index
|
||||
* and moves back to "tbl_sql.php"
|
||||
*/
|
||||
if (isset($index) && isset($do_save_data)) {
|
||||
$err_url = 'tbl_indexes.php?' . PMA_generate_common_url($db, $table);
|
||||
if (empty($old_index)) {
|
||||
$err_url .= '&create_index=1&idx_num_fields=' . $idx_num_fields;
|
||||
} else {
|
||||
$err_url .= '&index=' . urlencode($old_index);
|
||||
}
|
||||
|
||||
if ($index_type == 'PRIMARY') {
|
||||
if ($index == '') {
|
||||
$index = 'PRIMARY';
|
||||
} elseif ($index != 'PRIMARY') {
|
||||
PMA_mysqlDie($strPrimaryKeyName, '', FALSE, $err_url);
|
||||
}
|
||||
} elseif ($index == 'PRIMARY') {
|
||||
PMA_mysqlDie($strCantRenameIdxToPrimary, '', FALSE, $err_url);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['do_save_data'])) {
|
||||
$error = false;
|
||||
|
||||
// $sql_query is the one displayed in the query box
|
||||
$sql_query = 'ALTER TABLE ' . PMA_backquote($table);
|
||||
$sql_query = 'ALTER TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table);
|
||||
|
||||
// Drops the old index
|
||||
if (!empty($old_index)) {
|
||||
if ($old_index == 'PRIMARY') {
|
||||
if (! empty($_REQUEST['old_index'])) {
|
||||
if ($_REQUEST['old_index'] == 'PRIMARY') {
|
||||
$sql_query .= ' DROP PRIMARY KEY,';
|
||||
} else {
|
||||
$sql_query .= ' DROP INDEX ' . PMA_backquote($old_index) .',';
|
||||
$sql_query .= ' DROP INDEX ' . PMA_backquote($_REQUEST['old_index']) . ',';
|
||||
}
|
||||
} // end if
|
||||
|
||||
// Builds the new one
|
||||
switch ($index_type) {
|
||||
switch ($index->getType()) {
|
||||
case 'PRIMARY':
|
||||
$sql_query .= ' ADD PRIMARY KEY (';
|
||||
if ($index->getName() == '') {
|
||||
$index->setName('PRIMARY');
|
||||
} elseif ($index->getName() != 'PRIMARY') {
|
||||
$error = PMA_Message::error('strPrimaryKeyName');
|
||||
}
|
||||
$sql_query .= ' ADD PRIMARY KEY';
|
||||
break;
|
||||
case 'FULLTEXT':
|
||||
$sql_query .= ' ADD FULLTEXT '
|
||||
. (empty($index) ? '' : PMA_backquote($index)) . ' (';
|
||||
break;
|
||||
case 'UNIQUE':
|
||||
$sql_query .= ' ADD UNIQUE '
|
||||
. (empty($index) ? '' : PMA_backquote($index)) . ' (';
|
||||
break;
|
||||
case 'INDEX':
|
||||
$sql_query .= ' ADD INDEX '
|
||||
. (empty($index) ? '' : PMA_backquote($index)) . ' (';
|
||||
if ($index->getName() == 'PRIMARY') {
|
||||
$error = PMA_Message::error('strCantRenameIdxToPrimary');
|
||||
}
|
||||
$sql_query .= ' ADD ' . $index->getType() . ' '
|
||||
. ($index->getName() ? PMA_backquote($index->getName()) : '');
|
||||
break;
|
||||
} // end switch
|
||||
$index_fields = '';
|
||||
foreach ($column AS $i => $name) {
|
||||
if ($name != '--ignore--') {
|
||||
$index_fields .= (empty($index_fields) ? '' : ',')
|
||||
. PMA_backquote($name)
|
||||
. (empty($sub_part[$i])
|
||||
? ''
|
||||
: '(' . $sub_part[$i] . ')');
|
||||
|
||||
$index_fields = array();
|
||||
foreach ($index->getColumns() as $key => $column) {
|
||||
$index_fields[$key] = PMA_backquote($column->getName());
|
||||
if ($column->getSubPart()) {
|
||||
$index_fields[$key] .= '(' . $column->getSubPart() . ')';
|
||||
}
|
||||
} // end while
|
||||
|
||||
if (empty($index_fields)){
|
||||
PMA_mysqlDie($strNoIndexPartsDefined, '', FALSE, $err_url);
|
||||
$error = PMA_Message::error('strNoIndexPartsDefined');
|
||||
} else {
|
||||
$sql_query .= $index_fields . ')';
|
||||
$sql_query .= ' (' . implode(', ', $index_fields) . ')';
|
||||
}
|
||||
|
||||
$result = PMA_DBI_query($sql_query);
|
||||
if (! $error) {
|
||||
PMA_DBI_query($sql_query);
|
||||
$message = PMA_Message::success('strTableAlteredSuccessfully');
|
||||
$message->addParam($table);
|
||||
|
||||
$active_page = 'tbl_structure.php';
|
||||
require './tbl_structure.php';
|
||||
exit;
|
||||
} else {
|
||||
$error->display();
|
||||
}
|
||||
} // end builds the new index
|
||||
|
||||
|
||||
/**
|
||||
* Edits an index or defines a new one
|
||||
* Display the form to edit/create an index
|
||||
*/
|
||||
elseif (isset($index) || isset($create_index)) {
|
||||
|
||||
// Prepares the form values
|
||||
if (!isset($index)) {
|
||||
$index = '';
|
||||
}
|
||||
if (!isset($old_index)){
|
||||
$old_index = $index;
|
||||
}
|
||||
if (!isset($index_type)) {
|
||||
$index_type = '';
|
||||
}
|
||||
if ($old_index == '' || !isset($indexes_info[$old_index])) {
|
||||
$edited_index_info['Sequences'] = array();
|
||||
$edited_index_data = array();
|
||||
for ($i = 1; $i <= $idx_num_fields; $i++) {
|
||||
$edited_index_info['Sequences'][] = $i;
|
||||
$edited_index_data[$i] = array('Column_name' => '',
|
||||
'Sub_part' => '');
|
||||
} // end for
|
||||
if ($old_index == ''
|
||||
&& !isset($indexes_info['PRIMARY'])
|
||||
&& ($index_type == '' || $index_type == 'PRIMARY')) {
|
||||
$old_index = 'PRIMARY';
|
||||
// Displays headers (if needed)
|
||||
$GLOBALS['js_include'][] = 'functions.js';
|
||||
$GLOBALS['js_include'][] = 'indexes.js';
|
||||
|
||||
require_once './libraries/tbl_info.inc.php';
|
||||
require_once './libraries/tbl_links.inc.php';
|
||||
|
||||
if (is_array($_REQUEST['index'])) {
|
||||
// coming already from form
|
||||
$add_fields =
|
||||
count($_REQUEST['index']['columns']['names']) - $index->getColumnCount();
|
||||
if (isset($_REQUEST['add_fields'])) {
|
||||
$add_fields += $_REQUEST['added_fields'];
|
||||
}
|
||||
} elseif (isset($_REQUEST['create_index'])) {
|
||||
$add_fields = $_REQUEST['added_fields'];
|
||||
} else {
|
||||
$edited_index_info = $indexes_info[$old_index];
|
||||
$edited_index_data = $indexes_data[$old_index];
|
||||
|
||||
|
||||
if ($edited_index_info['Index_type'] == 'FULLTEXT') {
|
||||
$index_type = 'FULLTEXT';
|
||||
} elseif ($index == 'PRIMARY') {
|
||||
$index_type = 'PRIMARY';
|
||||
} elseif ($edited_index_info['Non_unique'] == '0') {
|
||||
$index_type = 'UNIQUE';
|
||||
} else {
|
||||
$index_type = 'INDEX';
|
||||
$add_fields = 1;
|
||||
}
|
||||
} // end if... else...
|
||||
|
||||
if (isset($add_fields)) {
|
||||
if (isset($prev_add_fields)) {
|
||||
$added_fields += $prev_add_fields;
|
||||
}
|
||||
$field_cnt = count($edited_index_info['Sequences']) + 1;
|
||||
for ($i = $field_cnt; $i < ($added_fields + $field_cnt); $i++) {
|
||||
$edited_index_info['Sequences'][] = $i;
|
||||
$edited_index_data[$i] = array('Column_name' => '',
|
||||
'Sub_part' => '');
|
||||
} // end for
|
||||
|
||||
// Restore entered values
|
||||
foreach ($column AS $i => $name) {
|
||||
if ($name != '--ignore--'){
|
||||
$edited_index_data[$i+1]['Column_name'] = $name;
|
||||
$edited_index_data[$i+1]['Sub_part'] = $sub_part[$i];
|
||||
}
|
||||
} // end while
|
||||
} // end if
|
||||
// end preparing form values
|
||||
?>
|
||||
|
||||
<div style="float: left;">
|
||||
<form action="./tbl_indexes.php" method="post" name="index_frm"
|
||||
onsubmit="if (typeof(this.elements['index'].disabled) != 'undefined') {
|
||||
this.elements['index'].disabled = false}">
|
||||
<?php
|
||||
echo PMA_generate_common_hidden_inputs($db, $table);
|
||||
$form_params = array(
|
||||
'db' => $db,
|
||||
'table' => $table,
|
||||
);
|
||||
|
||||
if (isset($create_index)) {
|
||||
echo '<input type="hidden" name="create_index" value="1" />' . "\n";
|
||||
}
|
||||
if (isset($added_fields)) {
|
||||
echo ' <input type="hidden" name="prev_add_fields" value="'
|
||||
. $added_fields . '" />' . "\n";
|
||||
}
|
||||
if (isset($idx_num_fields)) {
|
||||
echo ' <input type="hidden" name="idx_num_fields" value="'
|
||||
. $idx_num_fields . '" />' . "\n";
|
||||
if (isset($_REQUEST['create_index'])) {
|
||||
$form_params['create_index'] = 1;
|
||||
} elseif (isset($_REQUEST['old_index'])) {
|
||||
$form_params['old_index'] = $_REQUEST['old_index'];
|
||||
} elseif (isset($_REQUEST['index'])) {
|
||||
$form_params['old_index'] = $_REQUEST['index'];
|
||||
}
|
||||
|
||||
echo PMA_generate_common_hidden_inputs($form_params);
|
||||
?>
|
||||
<input type="hidden" name="old_index" value="<?php
|
||||
echo (isset($create_index) ? '' : htmlspecialchars($old_index)); ?>" />
|
||||
|
||||
<fieldset>
|
||||
<legend>
|
||||
<?php
|
||||
echo (isset($create_index) ? $strCreateIndexTopic : $strModifyIndexTopic);
|
||||
echo (isset($_REQUEST['create_index'])
|
||||
? $strCreateIndexTopic
|
||||
: $strModifyIndexTopic);
|
||||
?>
|
||||
</legend>
|
||||
|
||||
<div class="formelement">
|
||||
<label for="input_index_name"><?php echo $strIndexName; ?></label>
|
||||
<input type="text" name="index" id="input_index_name" size="25"
|
||||
value="<?php echo htmlspecialchars($index); ?>" onfocus="this.select()" />
|
||||
<input type="text" name="index[Key_name]" id="input_index_name" size="25"
|
||||
value="<?php echo htmlspecialchars($index->getName()); ?>" onfocus="this.select()" />
|
||||
</div>
|
||||
|
||||
<div class="formelement">
|
||||
<label for="select_index_type"><?php echo $strIndexType; ?></label>
|
||||
<select name="index_type" id="select_index_type" onchange="return checkIndexName()">
|
||||
<select name="index[Index_type]" id="select_index_type" onchange="return checkIndexName()">
|
||||
<?php
|
||||
foreach (PMA_get_indextypes() as $each_index_type) {
|
||||
if ($each_index_type === 'PRIMARY'
|
||||
&& $index !== 'PRIMARY'
|
||||
&& $index->getName() !== 'PRIMARY'
|
||||
&& isset($indexes_info['PRIMARY'])) {
|
||||
// skip PRIMARY if there is already one in the table
|
||||
continue;
|
||||
}
|
||||
echo ' '
|
||||
. '<option value="' . $each_index_type . '"'
|
||||
. (($index_type == $each_index_type) ? ' selected="selected"' : '')
|
||||
echo '<option value="' . $each_index_type . '"'
|
||||
. (($index->getType() == $each_index_type) ? ' selected="selected"' : '')
|
||||
. '>'. $each_index_type . '</option>' . "\n";
|
||||
}
|
||||
?>
|
||||
@@ -313,38 +215,47 @@ PMA_Message::warning('strPrimaryKeyWarning')->display();
|
||||
<tbody>
|
||||
<?php
|
||||
$odd_row = true;
|
||||
foreach ($edited_index_info['Sequences'] as $seq_index) {
|
||||
$add_type = (is_array($fields_types) && count($fields_types) == count($fields_names));
|
||||
$selected = $edited_index_data[$seq_index]['Column_name'];
|
||||
if (!empty($edited_index_data[$seq_index]['Sub_part'])) {
|
||||
$sub_part = ' value="' . $edited_index_data[$seq_index]['Sub_part'] . '"';
|
||||
} else {
|
||||
$sub_part = '';
|
||||
}
|
||||
foreach ($index->getColumns() as $column) {
|
||||
?>
|
||||
|
||||
<tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
|
||||
<td><select name="column[]">
|
||||
<option value="--ignore--"
|
||||
<?php if ('--ignore--' == $selected) { echo ' selected="selected"'; } ?>>
|
||||
-- <?php echo $strIgnore; ?> --</option>
|
||||
<td><select name="index[columns][names][]">
|
||||
<option value="">-- <?php echo $strIgnore; ?> --</option>
|
||||
<?php
|
||||
foreach ($fields_names AS $key => $val) {
|
||||
if ($index_type != 'FULLTEXT'
|
||||
|| preg_match('@^(varchar|text|tinytext|mediumtext|longtext)@i', $fields_types[$key])) {
|
||||
echo "\n" . ' '
|
||||
. '<option value="' . htmlspecialchars($val) . '"'
|
||||
. (($val == $selected) ? ' selected="selected"' : '') . '>'
|
||||
. htmlspecialchars($val) . (($add_type) ? ' ['
|
||||
. $fields_types[$key] . ']' : '') . '</option>' . "\n";
|
||||
foreach ($fields as $field_name => $field_type) {
|
||||
if ($index->getType() != 'FULLTEXT'
|
||||
|| preg_match('/(char|text)/i', $field_type)) {
|
||||
echo '<option value="' . htmlspecialchars($field_name) . '"'
|
||||
. (($field_name == $column->getName()) ? ' selected="selected"' : '') . '>'
|
||||
. htmlspecialchars($field_name) . ' [' . $field_type . ']'
|
||||
. '</option>' . "\n";
|
||||
}
|
||||
} // end foreach $fields_names
|
||||
} // end foreach $fields
|
||||
?>
|
||||
|
||||
</select>
|
||||
</td>
|
||||
<td><input type="text" size="5" onfocus="this.select()"
|
||||
name="sub_part[]"<?php echo $sub_part; ?> />
|
||||
name="index[columns][sub_parts][]" value="<?php echo $column->getSubPart(); ?>" />
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
$odd_row = !$odd_row;
|
||||
} // end foreach $edited_index_info['Sequences']
|
||||
for ($i = 0; $i < $add_fields; $i++) {
|
||||
?>
|
||||
<tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
|
||||
<td><select name="index[columns][names][]">
|
||||
<option value="">-- <?php echo $strIgnore; ?> --</option>
|
||||
<?php
|
||||
foreach ($fields as $field_name => $field_type) {
|
||||
echo '<option value="' . htmlspecialchars($field_name) . '">'
|
||||
. htmlspecialchars($field_name) . ' [' . $field_type . ']'
|
||||
. '</option>' . "\n";
|
||||
} // end foreach $fields
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
<td><input type="text" size="5" onfocus="this.select()"
|
||||
name="index[columns][sub_parts][]" value="" />
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
@@ -358,21 +269,18 @@ PMA_Message::warning('strPrimaryKeyWarning')->display();
|
||||
<fieldset class="tblFooters">
|
||||
<input type="submit" name="do_save_data" value="<?php echo $strSave; ?>" />
|
||||
<?php
|
||||
echo $strOr;
|
||||
echo ' ' . sprintf($strAddToIndex,
|
||||
echo $strOr . ' ';
|
||||
echo sprintf($strAddToIndex,
|
||||
'<input type="text" name="added_fields" size="2" value="1"'
|
||||
.' onfocus="this.select()" />') . "\n";
|
||||
echo '<input type="submit" name="add_fields" value="' . $strGo . '"'
|
||||
.' onclick="return checkFormElementInRange(this.form,'
|
||||
.' \'added_fields\', \''
|
||||
. str_replace('\'', '\\\'', $GLOBALS['strInvalidColumnCount'])
|
||||
. '\', 1)" />' . "\n";
|
||||
." 'added_fields', '" . PMA_jsFormat($GLOBALS['strInvalidColumnCount']) . "', 1"
|
||||
.')" />' . "\n";
|
||||
?>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the footer
|
||||
|
@@ -546,7 +546,7 @@ if (! $tbl_is_view && ! $db_is_information_schema) {
|
||||
<?php
|
||||
echo PMA_generate_common_hidden_inputs($db, $table);
|
||||
echo sprintf($strCreateIndex,
|
||||
'<input type="text" size="2" name="idx_num_fields" value="1" />');
|
||||
'<input type="text" size="2" name="added_fields" value="1" />');
|
||||
?>
|
||||
<input type="submit" name="create_index" value="<?php echo $strGo; ?>"
|
||||
onclick="return checkFormElementInRange(this.form,
|
||||
|
Reference in New Issue
Block a user