Merge pull request #431 from xmujay/0609_monitor
[phpmyadmin/aamir.git] / libraries / display_indexes.lib.php
blobd158dda1b0a70ed46033945335d867fad3c12521
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Display the form to edit/create an index
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 if (isset($_REQUEST['index']) && is_array($_REQUEST['index'])) {
13 // coming already from form
14 $add_fields
15 = count($_REQUEST['index']['columns']['names']) - $index->getColumnCount();
16 if (isset($_REQUEST['add_fields'])) {
17 $add_fields += $_REQUEST['added_fields'];
19 } elseif (isset($_REQUEST['create_index'])) {
20 $add_fields = $_REQUEST['added_fields'];
21 } else {
22 $add_fields = 1;
23 }// end preparing form values
25 $html = "";
26 $html .= '<form action="tbl_indexes.php" method="post" name="index_frm" id="index_frm" class="ajax"'
27 . 'onsubmit="if (typeof(this.elements[\'index[Key_name]\'].disabled) != \'undefined\') {'
28 . 'this.elements[\'index[Key_name]\'].disabled = false}">';
30 $form_params = array(
31 'db' => $db,
32 'table' => $table,
35 if (isset($_REQUEST['create_index'])) {
36 $form_params['create_index'] = 1;
37 } elseif (isset($_REQUEST['old_index'])) {
38 $form_params['old_index'] = $_REQUEST['old_index'];
39 } elseif (isset($_REQUEST['index'])) {
40 $form_params['old_index'] = $_REQUEST['index'];
43 $html .= PMA_generate_common_hidden_inputs($form_params);
45 $html .= '<fieldset id="index_edit_fields">';
47 if ($GLOBALS['is_ajax_request'] != true) {
48 $html .= '<legend>';
49 if (isset($_REQUEST['create_index'])) {
50 $html .= __('Add index');
51 } else {
52 $html .= __('Edit index');
54 $html .= '</legend>';
57 $html .= '<div class="index_info">';
59 $html .= '<div>'
60 . '<div class="label">'
61 . '<strong>'
62 . '<label for="input_index_name">'
63 . __('Index name:')
64 . PMA_Util::showHint(
65 PMA_Message::notice(
66 __(
67 '("PRIMARY" <b>must</b> be the name of'
68 . ' and <b>only of</b> a primary key!)'
72 . '</label>'
73 . '</strong>'
74 . '</div>'
75 . '<input type="text" name="index[Key_name]" id="input_index_name" size="25"'
76 . 'value="' . htmlspecialchars($index->getName()) . '"'
77 . 'onfocus="this.select()" />'
78 . '</div>';
80 if (PMA_MYSQL_INT_VERSION > 50500) {
81 $html .= '<div>'
82 . '<div class="label">'
83 . '<strong>'
84 . '<label for="input_index_comment">'
85 . __('Comment:')
86 . '</label>'
87 . '</strong>'
88 . '</div>'
89 . '<input type="text" name="index[Index_comment]" id="input_index_comment" size="30"'
90 . 'value="' . htmlspecialchars($index->getComment()) . '"'
91 . 'onfocus="this.select()" />'
92 . '</div>';
95 $html .= '<div>'
96 . '<div class="label">'
97 . '<strong>'
98 . '<label for="select_index_type">'
99 . __('Index type:')
100 . PMA_Util::showMySQLDocu('SQL-Syntax', 'ALTER_TABLE')
101 . '</label>'
102 . '</strong>'
103 . '</div>'
104 . '<select name="index[Index_type]" id="select_index_type" >'
105 . $index->generateIndexSelector()
106 . '</select>'
107 . '</div>';
109 $html .= '<div class="clearfloat"></div>';
111 $html .= '</div>';
113 $html .= '<table id="index_columns">';
115 $html .= '<thead>'
116 . '<tr>'
117 . '<th>' . __('Column') . '</th>'
118 . '<th>' . __('Size') . '</th>'
119 . '</tr>'
120 . '</thead>';
122 $odd_row = true;
123 $spatial_types = array(
124 'geometry', 'point', 'linestring', 'polygon', 'multipoint',
125 'multilinestring', 'multipolygon', 'geomtrycollection'
127 $html .= '<tbody>';
128 foreach ($index->getColumns() as $column) {
129 $html .= '<tr class="';
130 $html .= $odd_row ? 'odd' : 'even';
131 $html .= 'noclick">';
132 $html .= '<td>';
133 $html .= '<select name="index[columns][names][]">';
134 $html .= '<option value="">-- ' . __('Ignore') . ' --</option>';
135 foreach ($fields as $field_name => $field_type) {
136 if (($index->getType() != 'FULLTEXT'
137 || preg_match('/(char|text)/i', $field_type))
138 && ($index->getType() != 'SPATIAL'
139 || in_array($field_type, $spatial_types))
141 $html .= '<option value="' . htmlspecialchars($field_name) . '"'
142 . (($field_name == $column->getName())
143 ? ' selected="selected"'
144 : '') . '>'
145 . htmlspecialchars($field_name) . ' ['
146 . htmlspecialchars($field_type) . ']'
147 . '</option>' . "\n";
149 } // end foreach $fields
150 $html .= '</select>';
151 $html .= '</td>';
152 $html .= '<td>';
153 $html .= '<input type="text" size="5" onfocus="this.select()"'
154 . 'name="index[columns][sub_parts][]" value="';
155 if ($index->getType() != 'SPATIAL') {
156 $html .= $column->getSubPart();
158 $html .= '"/>';
159 $html .= '</td>';
160 $html .= '</tr>';
161 $odd_row = !$odd_row;
162 } // end foreach $edited_index_info['Sequences']
164 for ($i = 0; $i < $add_fields; $i++) {
165 $html .= '<tr class="';
166 $html .= $odd_row ? 'odd' : 'even';
167 $html .= 'noclick">';
168 $html .= '<td>';
169 $html .= '<select name="index[columns][names][]">';
170 $html .= '<option value="">-- ' . __('Ignore') . ' --</option>';
171 foreach ($fields as $field_name => $field_type) {
172 $html .= '<option value="' . htmlspecialchars($field_name) . '">'
173 . htmlspecialchars($field_name) . ' ['
174 . htmlspecialchars($field_type) . ']'
175 . '</option>' . "\n";
176 } // end foreach $fields
177 $html .= '</select>';
178 $html .= '</td>';
179 $html .= '<td>'
180 . '<input type="text" size="5" onfocus="this.select()"'
181 . 'name="index[columns][sub_parts][]" value="" />'
182 . '</td>';
183 $html .= '</tr>';
184 $odd_row = !$odd_row;
185 } // end foreach $edited_index_info['Sequences']
187 $html .= '</tbody>';
189 $html .= '</table>';
191 $html .= '</fieldset>';
193 $html .= '<fieldset class="tblFooters">';
194 if ($GLOBALS['is_ajax_request'] != true || ! empty($_REQUEST['ajax_page_request'])) {
195 $html .= '<input type="submit" name="do_save_data" value="' . __('Save') . '" />';
196 $html .= '<span id="addMoreColumns">';
197 $html .= __('Or') . ' ';
198 $html .= printf(
199 __('Add %s column(s) to index') . "\n",
200 '<input type="text" name="added_fields" size="2" value="1" />'
202 $html .= '<input type="submit" name="add_fields" value="' . __('Go') . '" />' . "\n";
203 $html .= '</span>';
204 } else {
205 $btn_value = sprintf(__('Add %s column(s) to index'), 1);
206 $html .= '<div class="slider"></div>';
207 $html .= '<div class="add_fields">';
208 $html .= '<input type="submit" value="' . $btn_value . '" />';
209 $html .= '</div>';
211 $html .= '</fieldset>';
213 $html .= '</form>';
215 $response = PMA_Response::getInstance();
216 $response->addHTML($html);
217 $header = $response->getHeader();
218 $scripts = $header->getScripts();
219 $scripts->addFile('indexes.js');