diff --git a/libraries/tbl_indexes.lib.php b/libraries/tbl_indexes.lib.php
index 9359a4802..413e40d37 100644
--- a/libraries/tbl_indexes.lib.php
+++ b/libraries/tbl_indexes.lib.php
@@ -1,182 +1,182 @@
$w_count) {
- if (isset($idx_collection['PRIMARY'][$w_keyname]) && (isset($idx_collection['INDEX'][$w_keyname]) || isset($idx_collection['UNIQUE'][$w_keyname]))) {
- $output .= PMA_index_warning(sprintf($GLOBALS['strIndexWarningPrimary'], htmlspecialchars($w_keyname)), $table);
- } elseif (isset($idx_collection['UNIQUE'][$w_keyname]) && isset($idx_collection['INDEX'][$w_keyname])) {
- $output .= PMA_index_warning(sprintf($GLOBALS['strIndexWarningUnique'], htmlspecialchars($w_keyname)), $table);
- }
-
- foreach($index_types AS $index_type) {
- if (isset($idx_collection[$index_type][$w_keyname]) && $idx_collection[$index_type][$w_keyname] > 1) {
- $output .= PMA_index_warning(sprintf($GLOBALS['strIndexWarningMultiple'], $index_type, htmlspecialchars($w_keyname)), $table);
- }
- }
- }
- }
+/**
+ * Function to check over array of indexes and look for common problems
+ *
+ * @param array Array of indexes
+ * @param boolean Whether to output HTML in table layout
+ *
+ * @access public
+ * @return string Output HTML
+ * @author Garvin Hicking (pma@supergarv.de)
+ */
+function PMA_check_indexes($idx_collection, $table = true) {
+ $index_types = PMA_get_indextypes();
+ $output = '';
+ if ( ! is_array($idx_collection) || empty($idx_collection['ALL'])) {
return $output;
}
- /**
- * Loop array of returned index keys and extract key information to
- * seperate arrays. Those arrays are passed by reference.
- *
- * @param array Referenced Array of indexes
- * @param array Referenced return array
- * @param array Referenced return array
- * @param array Referenced return array
- *
- * @access public
- * @return boolean void
- * @author Garvin Hicking (pma@supergarv.de)
- */
- function PMA_extract_indexes(&$ret_keys, &$indexes, &$indexes_info, &$indexes_data) {
- if (!is_array($ret_keys)) {
- return false;
+ foreach($idx_collection['ALL'] AS $w_keyname => $w_count) {
+ if (isset($idx_collection['PRIMARY'][$w_keyname]) && (isset($idx_collection['INDEX'][$w_keyname]) || isset($idx_collection['UNIQUE'][$w_keyname]))) {
+ $output .= PMA_index_warning(sprintf($GLOBALS['strIndexWarningPrimary'], htmlspecialchars($w_keyname)), $table);
+ } elseif (isset($idx_collection['UNIQUE'][$w_keyname]) && isset($idx_collection['INDEX'][$w_keyname])) {
+ $output .= PMA_index_warning(sprintf($GLOBALS['strIndexWarningUnique'], htmlspecialchars($w_keyname)), $table);
}
- $prev_index = '';
- foreach ($ret_keys as $row) {
- if ($row['Key_name'] != $prev_index ){
- $indexes[] = $row['Key_name'];
- $prev_index = $row['Key_name'];
+ foreach($index_types AS $index_type) {
+ if (isset($idx_collection[$index_type][$w_keyname]) && $idx_collection[$index_type][$w_keyname] > 1) {
+ $output .= PMA_index_warning(sprintf($GLOBALS['strIndexWarningMultiple'], $index_type, htmlspecialchars($w_keyname)), $table);
}
-
- $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
- $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
-
- if (isset($row['Cardinality'])) {
- $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
- }
-
- // I don't know what does following column mean....
- // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
- $indexes_info[$row['Key_name']]['Comment'] = (isset($row['Comment']))
- ? $row['Comment']
- : '';
- $indexes_info[$row['Key_name']]['Index_type'] = (isset($row['Index_type']))
- ? $row['Index_type']
- : '';
-
- $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
- if (isset($row['Sub_part'])) {
- $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
- }
- } // end while
-
- return true;
+ }
}
- /**
- * Show index data and prepare returned collection array for index
- * key checks.
- *
- * @param string The tablename
- * @param array Referenced Array of indexes
- * @param array Referenced info array
- * @param array Referenced data array
- * @param boolean Output HTML code, or just return collection array?
- *
- * @access public
- * @return array Index collection array
- * @author Garvin Hicking (pma@supergarv.de)
- */
- function PMA_show_indexes($table, &$indexes, &$indexes_info, &$indexes_data, $display_html = true, $print_mode = false) {
- $idx_collection = array();
- foreach ($indexes AS $index_no => $index_name) {
- if ($display_html) {
- if ($print_mode) {
- $index_td = '
' . "\n";
- } else {
- $cell_bgd = (($index_no % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo']);
- $index_td = ' | ' . "\n";
- }
- echo ' | ' . "\n";
- echo $index_td
- . ' ' . htmlspecialchars($index_name) . "\n"
- . ' ' . "\n";
- }
+ return $output;
+}
- if ((PMA_MYSQL_INT_VERSION < 40002 && $indexes_info[$index_name]['Comment'] == 'FULLTEXT')
- || (PMA_MYSQL_INT_VERSION >= 40002 && $indexes_info[$index_name]['Index_type'] == 'FULLTEXT')) {
- $index_type = 'FULLTEXT';
- } else if ($index_name == 'PRIMARY') {
- $index_type = 'PRIMARY';
- } else if ($indexes_info[$index_name]['Non_unique'] == '0') {
- $index_type = 'UNIQUE';
- } else {
- $index_type = 'INDEX';
- }
+/**
+ * Loop array of returned index keys and extract key information to
+ * seperate arrays. Those arrays are passed by reference.
+ *
+ * @param array Referenced Array of indexes
+ * @param array Referenced return array
+ * @param array Referenced return array
+ * @param array Referenced return array
+ *
+ * @access public
+ * @return boolean void
+ * @author Garvin Hicking (pma@supergarv.de)
+ */
+function PMA_extract_indexes(&$ret_keys, &$indexes, &$indexes_info, &$indexes_data) {
+ if (!is_array($ret_keys)) {
+ return false;
+ }
- if ($display_html) {
- echo $index_td
- . ' ' . $index_type . "\n"
- . ' ' . "\n";
+ $prev_index = '';
+ foreach ($ret_keys as $row) {
+ if ($row['Key_name'] != $prev_index ){
+ $indexes[] = $row['Key_name'];
+ $prev_index = $row['Key_name'];
+ }
- echo str_replace('">' . "\n", '" align="right">' . "\n", $index_td)
- . ' ' . (isset($indexes_info[$index_name]['Cardinality']) ? $indexes_info[$index_name]['Cardinality'] : $GLOBALS['strNone']) . ' ' . "\n"
- . ' ' . "\n";
+ $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
+ $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
- if (!$print_mode) {
- echo $index_td
- . ' ' . $GLOBALS['edit_link_text'] . '' . "\n"
- . ' ' . "\n";
- }
+ if (isset($row['Cardinality'])) {
+ $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
+ }
+
+ // I don't know what does following column mean....
+ // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
+ $indexes_info[$row['Key_name']]['Comment'] = (isset($row['Comment']))
+ ? $row['Comment']
+ : '';
+ $indexes_info[$row['Key_name']]['Index_type'] = (isset($row['Index_type']))
+ ? $row['Index_type']
+ : '';
+
+ $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
+ if (isset($row['Sub_part'])) {
+ $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
+ }
+ } // end while
+
+ return true;
+}
+
+/**
+ * Show index data and prepare returned collection array for index
+ * key checks.
+ *
+ * @param string $table The tablename
+ * @param array $indexes Referenced Array of indexes
+ * @param array $indexes_info Referenced info array
+ * @param array $indexes_data Referenced data array
+ * @param boolean $display_html Output HTML code, or just return collection array?
+ * @param boolean $print_mode
+ * @access public
+ * @return array Index collection array
+ * @author Garvin Hicking (pma@supergarv.de)
+ */
+function PMA_show_indexes($table, &$indexes, &$indexes_info, &$indexes_data, $display_html = true, $print_mode = false) {
+ $idx_collection = array();
+ $odd_row = true;
+ foreach ($indexes as $index_name) {
+ if ($display_html) {
+ $row_span = ' rowspan="' . count($indexes_info[$index_name]['Sequences']) . '" ';
+
+ echo '
' . "\n";
+ echo ' ' . "\n"
+ . ' ' . htmlspecialchars($index_name) . "\n"
+ . ' | ' . "\n";
+ }
+
+ if ((PMA_MYSQL_INT_VERSION < 40002 && $indexes_info[$index_name]['Comment'] == 'FULLTEXT')
+ || (PMA_MYSQL_INT_VERSION >= 40002 && $indexes_info[$index_name]['Index_type'] == 'FULLTEXT')) {
+ $index_type = 'FULLTEXT';
+ } elseif ($index_name == 'PRIMARY') {
+ $index_type = 'PRIMARY';
+ } elseif ($indexes_info[$index_name]['Non_unique'] == '0') {
+ $index_type = 'UNIQUE';
+ } else {
+ $index_type = 'INDEX';
+ }
+
+ if ($display_html) {
+ echo ' ' . "\n"
+ . ' ' . $index_type . ' | ' . "\n";
+
+ echo ' ' . "\n"
+ . ' ' . (isset($indexes_info[$index_name]['Cardinality']) ? $indexes_info[$index_name]['Cardinality'] : $GLOBALS['strNone']) . ' ' . "\n"
+ . ' | ' . "\n";
+
+ if (!$print_mode) {
+ echo ' ' . "\n"
+ . ' ' . $GLOBALS['edit_link_text'] . '' . "\n"
+ . ' | ' . "\n";
if ($index_name == 'PRIMARY') {
$local_query = urlencode('ALTER TABLE ' . PMA_backquote($table) . ' DROP PRIMARY KEY');
@@ -188,90 +188,70 @@
$zero_rows = urlencode(sprintf($GLOBALS['strIndexHasBeenDropped'], htmlspecialchars($index_name)));
}
- if (!$print_mode) {
- echo $index_td
- . ' ' . $GLOBALS['drop_link_text'] . '' . "\n"
- . ' ' . "\n";
+ echo ' ' . "\n"
+ . ' ' . $GLOBALS['drop_link_text'] . '' . "\n"
+ . ' | ' . "\n";
+ }
+ }
+
+ foreach ($indexes_info[$index_name]['Sequences'] AS $row_no => $seq_index) {
+ $col_name = $indexes_data[$index_name][$seq_index]['Column_name'];
+ if ($row_no == 0) {
+ if (isset($idx_collection[$index_type][$col_name])) {
+ $idx_collection[$index_type][$col_name]++;
+ } else {
+ $idx_collection[$index_type][$col_name] = 1;
+ }
+
+ if (isset($idx_collection['ALL'][$col_name])) {
+ $idx_collection['ALL'][$col_name]++;
+ } else {
+ $idx_collection['ALL'][$col_name] = 1;
}
}
- foreach ($indexes_info[$index_name]['Sequences'] AS $row_no => $seq_index) {
- $col_name = $indexes_data[$index_name][$seq_index]['Column_name'];
- if ($row_no == 0) {
- if (isset($idx_collection[$index_type][$col_name])) {
- $idx_collection[$index_type][$col_name]++;
- } else {
- $idx_collection[$index_type][$col_name] = 1;
- }
-
- if (isset($idx_collection['ALL'][$col_name])) {
- $idx_collection['ALL'][$col_name]++;
- } else {
- $idx_collection['ALL'][$col_name] = 1;
- }
+ if ($display_html) {
+ if ($row_no > 0) {
+ echo '
' . "\n";
}
- if ($display_html) {
- if ($row_no > 0) {
- echo '
' . "\n";
- }
-
- if ($print_mode) {
- $bgcolor = 'class="print"';
- } else {
- $bgcolor = 'bgcolor="' . $cell_bgd . '"';
- }
-
- if (!empty($indexes_data[$index_name][$seq_index]['Sub_part'])) {
- echo ' ' . "\n"
- . ' ' . $col_name . "\n"
- . ' | ' . "\n";
- echo ' ' . "\n"
- . ' ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n"
- . ' | ' . "\n";
- echo '
' . "\n";
- } else {
- echo ' ' . "\n"
- . ' ' . htmlspecialchars($col_name) . "\n"
- . ' | ' . "\n";
- echo ' ' . "\n";
- }
+ if (!empty($indexes_data[$index_name][$seq_index]['Sub_part'])) {
+ echo ' ' . $col_name . ' | ' . "\n";
+ echo ' ' . "\n"
+ . ' ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n"
+ . ' | ' . "\n";
+ echo ' ' . "\n";
+ } else {
+ echo ' ' . "\n"
+ . ' ' . htmlspecialchars($col_name) . "\n"
+ . ' | ' . "\n";
+ echo ' ' . "\n";
}
- } // end while
- } // end while
+ }
+ } // end foreach $indexes_info[$index_name]['Sequences']
- return $idx_collection;
+ $odd_row = ! $odd_row;
+ } // end while
+
+ return $idx_collection;
+}
+
+/**
+ * Function to emit a index warning
+ *
+ * @author Garvin Hicking (pma@supergarv.de)
+ * @access public
+ * @param string $string Message string
+ * @param boolean $table Whether to output HTML in table layout
+ * @return string Output HTML
+ */
+function PMA_index_warning($string, $table = true) {
+ $output = '' . $string . '
';
+
+ if ( $table ) {
+ $output = '' . $output . ' |
';
}
- /**
- * Function to emit a index warning
- *
- * @param string Message string
- * @param boolean Whether to output HTML in table layout
- *
- * @access public
- * @output string Output HTML
- * @author Garvin Hicking (pma@supergarv.de)
- */
- function PMA_index_warning($string, $table = true) {
- $output = '';
- if ($table) {
- $output .= "\n" . ' ' . "\n";
- }
-
- if ($GLOBALS['cfg']['ErrorIconic']) {
- $output .= ' ';
- }
-
- $output .= ' ' . $string . '';
-
- if ($table) {
- $output .= ' |
';
- } else {
- $output .= '
';
- }
-
- $output .= "\n\n";
- return $output;
- }
+ return $output . "\n";
+}
?>
diff --git a/tbl_indexes.php b/tbl_indexes.php
index 14c767ab0..ffaf682a4 100644
--- a/tbl_indexes.php
+++ b/tbl_indexes.php
@@ -21,27 +21,41 @@ $index_types_cnt = count($index_types);
*/
if (!defined('PMA_IDX_INCLUDED')) {
// Not a valid db name -> back to the welcome page
- if (!empty($db)) {
+ if ( !empty($db) ) {
$is_db = PMA_DBI_select_db($db);
}
- if (empty($db) || !$is_db) {
- PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . 'main.php?' . PMA_generate_common_url('', '', '&') . (isset($message) ? '&message=' . urlencode($message) : '') . '&reload=1');
+ if ( empty($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_details sub-page
- if (!empty($table)) {
- $is_table = PMA_DBI_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'', NULL, PMA_DBI_QUERY_STORE);
+ if ( !empty($table) ) {
+ $is_table = PMA_DBI_query('SHOW TABLES LIKE \''
+ . PMA_sqlAddslashes($table, TRUE) . '\'', NULL, PMA_DBI_QUERY_STORE);
}
- if (empty($table)
- || !($is_table && PMA_DBI_num_rows($is_table))) {
- PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . $cfg['DefaultTabDatabase'] . '?' . PMA_generate_common_url($db, '', '&') . (isset($message) ? '&message=' . urlencode($message) : '') . '&reload=1');
+ if ( empty($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;
- } else if (isset($is_table)) {
+ } elseif ( isset($is_table) ) {
PMA_DBI_free_result($is_table);
}
// Displays headers (if needed)
- $js_to_run = ((isset($index) && isset($do_save_data)) ? 'functions.js' : 'indexes.js');
+ $js_to_run = isset($index) && isset($do_save_data)
+ ? 'functions.js'
+ : 'indexes.js';
require_once('./libraries/header.inc.php');
} // end if
@@ -67,7 +81,8 @@ PMA_extract_indexes($ret_keys, $indexes, $indexes_info, $indexes_data);
// Get fields and stores their name/type
// fields had already been grabbed in "tbl_properties.php"
if (!defined('PMA_IDX_INCLUDED')) {
- $fields_rs = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';');
+ $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;
@@ -80,7 +95,8 @@ foreach ($save_row AS $saved_row_key => $row) {
$fields_names[] = $row['Field'];
// loic1: set or enum types: slashes single quotes inside options
if (preg_match('@^(set|enum)\((.+)\)$@i', $row['Type'], $tmp)) {
- $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
+ $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'',
+ ',' . $tmp[2]), 1);
$fields_types[] = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
} else {
$fields_types[] = $row['Type'];
@@ -135,13 +151,16 @@ if (!defined('PMA_IDX_INCLUDED')
$sql_query .= ' ADD PRIMARY KEY (';
break;
case 'FULLTEXT':
- $sql_query .= ' ADD FULLTEXT ' . (empty($index) ? '' : PMA_backquote($index)) . ' (';
+ $sql_query .= ' ADD FULLTEXT '
+ . (empty($index) ? '' : PMA_backquote($index)) . ' (';
break;
case 'UNIQUE':
- $sql_query .= ' ADD UNIQUE ' . (empty($index) ? '' : PMA_backquote($index)) . ' (';
+ $sql_query .= ' ADD UNIQUE '
+ . (empty($index) ? '' : PMA_backquote($index)) . ' (';
break;
case 'INDEX':
- $sql_query .= ' ADD INDEX ' . (empty($index) ? '' : PMA_backquote($index)) . ' (';
+ $sql_query .= ' ADD INDEX '
+ . (empty($index) ? '' : PMA_backquote($index)) . ' (';
break;
} // end switch
$index_fields = '';
@@ -149,7 +168,9 @@ if (!defined('PMA_IDX_INCLUDED')
if ($name != '--ignore--') {
$index_fields .= (empty($index_fields) ? '' : ',')
. PMA_backquote($name)
- . (empty($sub_part[$i]) ? '' : '(' . $sub_part[$i] . ')');
+ . (empty($sub_part[$i])
+ ? ''
+ : '(' . $sub_part[$i] . ')');
}
} // end while
if (empty($index_fields)){
@@ -159,7 +180,8 @@ if (!defined('PMA_IDX_INCLUDED')
}
$result = PMA_DBI_query($sql_query);
- $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered;
+ $message = $strTable . ' ' . htmlspecialchars($table) . ' '
+ . $strHasBeenAltered;
$active_page = 'tbl_properties_structure.php';
require('./tbl_properties_structure.php');
@@ -187,7 +209,8 @@ else if (!defined('PMA_IDX_INCLUDED')
$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' => '');
+ $edited_index_data[$i] = array('Column_name' => '',
+ 'Sub_part' => '');
} // end for
if ($old_index == ''
&& !isset($indexes_info['PRIMARY'])
@@ -199,8 +222,10 @@ else if (!defined('PMA_IDX_INCLUDED')
$edited_index_data = $indexes_data[$old_index];
- if ((PMA_MYSQL_INT_VERSION < 40002 && $edited_index_info['Comment'] == 'FULLTEXT')
- || (PMA_MYSQL_INT_VERSION >= 40002 && $edited_index_info['Index_type'] == 'FULLTEXT')) {
+ if ((PMA_MYSQL_INT_VERSION < 40002
+ && $edited_index_info['Comment'] == 'FULLTEXT')
+ || (PMA_MYSQL_INT_VERSION >= 40002
+ && $edited_index_info['Index_type'] == 'FULLTEXT')) {
$index_type = 'FULLTEXT';
} else if ($index == 'PRIMARY') {
$index_type = 'PRIMARY';
@@ -218,7 +243,8 @@ else if (!defined('PMA_IDX_INCLUDED')
$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' => '');
+ $edited_index_data[$i] = array('Column_name' => '',
+ 'Sub_part' => '');
} // end for
// Restore entered values
@@ -232,67 +258,79 @@ else if (!defined('PMA_IDX_INCLUDED')
// end preparing form values
?>
-
+