Translation update done using Pootle.
[phpmyadmin/madhuracj.git] / tbl_indexes.php
blob195568b860bf6597ee569f208eaf87f328ee47e5
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Displays index edit/creation form and handles it
6 * @package PhpMyAdmin
7 */
9 /**
10 * Gets some core libraries
12 require_once './libraries/common.inc.php';
13 require_once './libraries/Index.class.php';
14 require_once './libraries/tbl_common.php';
16 // Get fields and stores their name/type
17 $fields = array();
18 foreach (PMA_DBI_get_columns_full($db, $table) as $row) {
19 if (preg_match('@^(set|enum)\((.+)\)$@i', $row['Type'], $tmp)) {
20 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'',
21 ',' . $tmp[2]), 1);
22 $fields[$row['Field']] = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
23 } else {
24 $fields[$row['Field']] = $row['Type'];
26 } // end while
28 // Prepares the form values
29 if (isset($_REQUEST['index'])) {
30 if (is_array($_REQUEST['index'])) {
31 // coming already from form
32 $index = new PMA_Index($_REQUEST['index']);
33 } else {
34 $index = PMA_Index::singleton($db, $table, $_REQUEST['index']);
36 } else {
37 $index = new PMA_Index;
40 /**
41 * Process the data from the edit/create index form,
42 * run the query to build the new index
43 * and moves back to "tbl_sql.php"
45 if (isset($_REQUEST['do_save_data'])) {
46 $error = false;
48 // $sql_query is the one displayed in the query box
49 $sql_query = 'ALTER TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table);
51 // Drops the old index
52 if (! empty($_REQUEST['old_index'])) {
53 if ($_REQUEST['old_index'] == 'PRIMARY') {
54 $sql_query .= ' DROP PRIMARY KEY,';
55 } else {
56 $sql_query .= ' DROP INDEX ' . PMA_backquote($_REQUEST['old_index']) . ',';
58 } // end if
60 // Builds the new one
61 switch ($index->getType()) {
62 case 'PRIMARY':
63 if ($index->getName() == '') {
64 $index->setName('PRIMARY');
65 } elseif ($index->getName() != 'PRIMARY') {
66 $error = PMA_Message::error(__('The name of the primary key must be "PRIMARY"!'));
68 $sql_query .= ' ADD PRIMARY KEY';
69 break;
70 case 'FULLTEXT':
71 case 'UNIQUE':
72 case 'INDEX':
73 case 'SPATIAL':
74 if ($index->getName() == 'PRIMARY') {
75 $error = PMA_Message::error(__('Can\'t rename index to PRIMARY!'));
77 $sql_query .= ' ADD ' . $index->getType() . ' '
78 . ($index->getName() ? PMA_backquote($index->getName()) : '');
79 break;
80 } // end switch
82 $index_fields = array();
83 foreach ($index->getColumns() as $key => $column) {
84 $index_fields[$key] = PMA_backquote($column->getName());
85 if ($column->getSubPart()) {
86 $index_fields[$key] .= '(' . $column->getSubPart() . ')';
88 } // end while
90 if (empty($index_fields)) {
91 $error = PMA_Message::error(__('No index parts defined!'));
92 } else {
93 $sql_query .= ' (' . implode(', ', $index_fields) . ')';
96 if (! $error) {
97 PMA_DBI_query($sql_query);
98 $message = PMA_Message::success(__('Table %1$s has been altered successfully'));
99 $message->addParam($table);
101 if ( $GLOBALS['is_ajax_request'] == true) {
102 $extra_data['index_table'] = PMA_Index::getView($table, $db);
103 $extra_data['sql_query'] = PMA_showMessage(null, $sql_query);
104 PMA_ajaxResponse($message, $message->isSuccess(), $extra_data);
107 $active_page = 'tbl_structure.php';
108 include './tbl_structure.php';
109 exit;
110 } else {
111 if ( $GLOBALS['is_ajax_request'] == true) {
112 $extra_data['error'] = $error;
113 PMA_ajaxResponse($error, false);
115 $error->display();
117 } // end builds the new index
121 * Display the form to edit/create an index
124 // Displays headers (if needed)
125 $GLOBALS['js_include'][] = 'indexes.js';
126 require_once './libraries/tbl_info.inc.php';
127 if ($GLOBALS['is_ajax_request'] != true) {
128 include_once './libraries/tbl_links.inc.php';
131 if (isset($_REQUEST['index']) && is_array($_REQUEST['index'])) {
132 // coming already from form
133 $add_fields =
134 count($_REQUEST['index']['columns']['names']) - $index->getColumnCount();
135 if (isset($_REQUEST['add_fields'])) {
136 $add_fields += $_REQUEST['added_fields'];
138 } elseif (isset($_REQUEST['create_index'])) {
139 $add_fields = $_REQUEST['added_fields'];
140 } else {
141 $add_fields = 1;
144 // end preparing form values
147 <form action="./tbl_indexes.php" method="post" name="index_frm" id="index_frm" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?>
148 onsubmit="if (typeof(this.elements['index[Key_name]'].disabled) != 'undefined') {
149 this.elements['index[Key_name]'].disabled = false}">
150 <?php
151 $form_params = array(
152 'db' => $db,
153 'table' => $table,
156 if (isset($_REQUEST['create_index'])) {
157 $form_params['create_index'] = 1;
158 } elseif (isset($_REQUEST['old_index'])) {
159 $form_params['old_index'] = $_REQUEST['old_index'];
160 } elseif (isset($_REQUEST['index'])) {
161 $form_params['old_index'] = $_REQUEST['index'];
164 echo PMA_generate_common_hidden_inputs($form_params);
166 <fieldset id="index_edit_fields">
167 <?php
168 if ($GLOBALS['is_ajax_request'] != true) {
170 <legend>
171 <?php
172 if (isset($_REQUEST['create_index'])) {
173 echo __('Add index');
174 } else {
175 echo __('Edit index');
178 </legend>
179 <?php
182 <div class='index_info'>
183 <div>
184 <div class="label">
185 <strong>
186 <label for="input_index_name">
187 <?php echo __('Index name:'); ?>
188 <?php echo PMA_showhint(PMA_Message::notice(__('("PRIMARY" <b>must</b> be the name of and <b>only of</b> a primary key!)'))); ?>
189 </label>
190 </strong>
191 </div>
192 <input type="text" name="index[Key_name]" id="input_index_name" size="25"
193 value="<?php echo htmlspecialchars($index->getName()); ?>" onfocus="this.select()" />
194 </div>
195 <div>
196 <div class="label">
197 <strong>
198 <label for="select_index_type">
199 <?php echo __('Index type:'); ?>
200 <?php echo PMA_showMySQLDocu('SQL-Syntax', 'ALTER_TABLE'); ?>
201 </label>
202 </strong>
203 </div>
204 <select name="index[Index_type]" id="select_index_type" >
205 <?php echo $index->generateIndexSelector(); ?>
206 </select>
207 </div>
208 <div class="clearfloat"></div>
209 </div>
211 <table id="index_columns">
212 <thead>
213 <tr><th><?php echo __('Column'); ?></th>
214 <th><?php echo __('Size'); ?></th>
215 </tr>
216 </thead>
217 <tbody>
218 <?php
219 $odd_row = true;
220 $spatial_types = array(
221 'geometry', 'point', 'linestring', 'polygon', 'multipoint',
222 'multilinestring', 'multipolygon', 'geomtrycollection'
224 foreach ($index->getColumns() as $column) {
226 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?> noclick">
227 <td><select name="index[columns][names][]">
228 <option value="">-- <?php echo __('Ignore'); ?> --</option>
229 <?php
230 foreach ($fields as $field_name => $field_type) {
231 if (($index->getType() != 'FULLTEXT' || preg_match('/(char|text)/i', $field_type))
232 && ($index->getType() != 'SPATIAL' || in_array($field_type, $spatial_types))
234 echo '<option value="' . htmlspecialchars($field_name) . '"'
235 . (($field_name == $column->getName()) ? ' selected="selected"' : '') . '>'
236 . htmlspecialchars($field_name) . ' [' . $field_type . ']'
237 . '</option>' . "\n";
239 } // end foreach $fields
241 </select>
242 </td>
243 <td><input type="text" size="5" onfocus="this.select()"
244 name="index[columns][sub_parts][]"
245 value="<?php if ($index->getType() != 'SPATIAL') { echo $column->getSubPart(); } ?>" />
246 </td>
247 </tr>
248 <?php
249 $odd_row = !$odd_row;
250 } // end foreach $edited_index_info['Sequences']
251 for ($i = 0; $i < $add_fields; $i++) {
253 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?> noclick">
254 <td><select name="index[columns][names][]">
255 <option value="">-- <?php echo __('Ignore'); ?> --</option>
256 <?php
257 foreach ($fields as $field_name => $field_type) {
258 echo '<option value="' . htmlspecialchars($field_name) . '">'
259 . htmlspecialchars($field_name) . ' [' . $field_type . ']'
260 . '</option>' . "\n";
261 } // end foreach $fields
263 </select>
264 </td>
265 <td><input type="text" size="5" onfocus="this.select()"
266 name="index[columns][sub_parts][]" value="" />
267 </td>
268 </tr>
269 <?php
270 $odd_row = !$odd_row;
271 } // end foreach $edited_index_info['Sequences']
273 </tbody>
274 </table>
275 </fieldset>
276 <fieldset class="tblFooters">
277 <?php
278 if ($GLOBALS['is_ajax_request'] != true) {
280 <input type="submit" name="do_save_data" value="<?php echo __('Save'); ?>" />
281 <span id="addMoreColumns">
282 <?php
283 echo __('Or') . ' ';
284 printf(
285 __('Add to index &nbsp;%s&nbsp;column(s)') . "\n",
286 '<input type="text" name="added_fields" size="2" value="1" />'
288 echo '<input type="submit" name="add_fields" value="' . __('Go') . '" />' . "\n";
290 </span>
291 <?php
292 } else {
293 $btn_value = sprintf(__('Add %d column(s) to index'), 1);
294 echo '<div class="slider"></div>';
295 echo '<div class="add_fields">';
296 echo '<input type="submit" value="' . $btn_value . '" />';
297 echo '</div>';
300 </fieldset>
301 </form>
302 <?php
305 * Displays the footer
307 require './libraries/footer.inc.php';