/** * Show index data * * @param string $table The table name * @param string $schema The schema name * @param boolean $print_mode Whether the output is for the print mode * * @return string HTML for showing index * * @access public */ public static function getHtmlForIndexes($table, $schema, $print_mode = false) { $indexes = Index::getFromTable($table, $schema); $no_indexes_class = count($indexes) > 0 ? ' hide' : ''; $no_indexes = "<div class='no_indexes_defined{$no_indexes_class}'>"; $no_indexes .= Message::notice(__('No index defined!'))->getDisplay(); $no_indexes .= '</div>'; if (!$print_mode) { $r = '<fieldset class="index_info">'; $r .= '<legend id="index_header">' . __('Indexes'); $r .= Util::showMySQLDocu('optimizing-database-structure'); $r .= '</legend>'; $r .= $no_indexes; if (count($indexes) < 1) { $r .= '</fieldset>'; return $r; } $r .= Index::findDuplicates($table, $schema); } else { $r = '<h3>' . __('Indexes') . '</h3>'; $r .= $no_indexes; if (count($indexes) < 1) { return $r; } } $r .= '<table id="table_index">'; $r .= '<thead>'; $r .= '<tr>'; if (!$print_mode) { $r .= '<th colspan="2" class="print_ignore">' . __('Action') . '</th>'; } $r .= '<th>' . __('Keyname') . '</th>'; $r .= '<th>' . __('Type') . '</th>'; $r .= '<th>' . __('Unique') . '</th>'; $r .= '<th>' . __('Packed') . '</th>'; $r .= '<th>' . __('Column') . '</th>'; $r .= '<th>' . __('Cardinality') . '</th>'; $r .= '<th>' . __('Collation') . '</th>'; $r .= '<th>' . __('Null') . '</th>'; $r .= '<th>' . __('Comment') . '</th>'; $r .= '</tr>'; $r .= '</thead>'; $r .= '<tbody>'; foreach ($indexes as $index) { $row_span = ' rowspan="' . $index->getColumnCount() . '" '; $r .= '<tr class="noclick" >'; if (!$print_mode) { $this_params = $GLOBALS['url_params']; $this_params['index'] = $index->getName(); $r .= '<td class="edit_index print_ignore'; $r .= ' ajax'; $r .= '" ' . $row_span . '>' . ' <a class="'; $r .= 'ajax'; $r .= '" href="tbl_indexes.php' . URL::getCommon($this_params) . '">' . Util::getIcon('b_edit.png', __('Edit')) . '</a>' . '</td>' . "\n"; $this_params = $GLOBALS['url_params']; if ($index->getName() == 'PRIMARY') { $this_params['sql_query'] = 'ALTER TABLE ' . Util::backquote($table) . ' DROP PRIMARY KEY;'; $this_params['message_to_show'] = __('The primary key has been dropped.'); $js_msg = Sanitize::jsFormat('ALTER TABLE ' . $table . ' DROP PRIMARY KEY'); } else { $this_params['sql_query'] = 'ALTER TABLE ' . Util::backquote($table) . ' DROP INDEX ' . Util::backquote($index->getName()) . ';'; $this_params['message_to_show'] = sprintf(__('Index %s has been dropped.'), htmlspecialchars($index->getName())); $js_msg = Sanitize::jsFormat('ALTER TABLE ' . $table . ' DROP INDEX ' . $index->getName() . ';'); } $r .= '<td ' . $row_span . ' class="print_ignore">'; $r .= '<input type="hidden" class="drop_primary_key_index_msg"' . ' value="' . $js_msg . '" />'; $r .= ' <a class="drop_primary_key_index_anchor'; $r .= ' ajax'; $r .= '" href="sql.php' . URL::getCommon($this_params) . '" >' . Util::getIcon('b_drop.png', __('Drop')) . '</a>' . '</td>' . "\n"; } if (!$print_mode) { $r .= '<th ' . $row_span . '>' . htmlspecialchars($index->getName()) . '</th>'; } else { $r .= '<td ' . $row_span . '>' . htmlspecialchars($index->getName()) . '</td>'; } $r .= '<td ' . $row_span . '>'; $type = $index->getType(); if (!empty($type)) { $r .= htmlspecialchars($type); } else { $r .= htmlspecialchars($index->getChoice()); } $r .= '</td>'; $r .= '<td ' . $row_span . '>' . $index->isUnique(true) . '</td>'; $r .= '<td ' . $row_span . '>' . $index->isPacked() . '</td>'; foreach ($index->getColumns() as $column) { if ($column->getSeqInIndex() > 1) { $r .= '<tr class="noclick" >'; } $r .= '<td>' . htmlspecialchars($column->getName()); if ($column->getSubPart()) { $r .= ' (' . htmlspecialchars($column->getSubPart()) . ')'; } $r .= '</td>'; $r .= '<td>' . htmlspecialchars($column->getCardinality()) . '</td>'; $r .= '<td>' . htmlspecialchars($column->getCollation()) . '</td>'; $r .= '<td>' . htmlspecialchars($column->getNull(true)) . '</td>'; if ($column->getSeqInIndex() == 1) { $r .= '<td ' . $row_span . '>' . htmlspecialchars($index->getComments()) . '</td>'; } $r .= '</tr>'; } // end foreach $index['Sequences'] } // end while $r .= '</tbody>'; $r .= '</table>'; if (!$print_mode) { $r .= '</fieldset>'; } return $r; }