bug #3449659 [navi] Fast filter broken with table tree
[phpmyadmin/madhuracj.git] / tbl_structure.php
blob246bd0e4da4296eab643d479d46b94cfd8ea3aef
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Displays table structure infos like fields/columns, indexes, size, rows
5 * and allows manipulation of indexes and columns/fields
6 * @package phpMyAdmin
7 */
9 /**
12 require_once './libraries/common.inc.php';
13 require_once './libraries/mysql_charsets.lib.php';
15 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
16 $GLOBALS['js_include'][] = 'tbl_structure.js';
18 /**
19 * handle multiple field commands if required
21 * submit_mult_*_x comes from IE if <input type="img" ...> is used
23 if (isset($_REQUEST['submit_mult_change_x'])) {
24 $submit_mult = 'change';
25 } elseif (isset($_REQUEST['submit_mult_drop_x'])) {
26 $submit_mult = 'drop';
27 } elseif (isset($_REQUEST['submit_mult_primary_x'])) {
28 $submit_mult = 'primary';
29 } elseif (isset($_REQUEST['submit_mult_index_x'])) {
30 $submit_mult = 'index';
31 } elseif (isset($_REQUEST['submit_mult_unique_x'])) {
32 $submit_mult = 'unique';
33 } elseif (isset($_REQUEST['submit_mult_fulltext_x'])) {
34 $submit_mult = 'ftext';
35 } elseif (isset($_REQUEST['submit_mult_browse_x'])) {
36 $submit_mult = 'browse';
37 } elseif (isset($_REQUEST['submit_mult'])) {
38 $submit_mult = $_REQUEST['submit_mult'];
39 } elseif (isset($_REQUEST['mult_btn']) && $_REQUEST['mult_btn'] == __('Yes')) {
40 $submit_mult = 'row_delete';
41 if (isset($_REQUEST['selected'])) {
42 $_REQUEST['selected_fld'] = $_REQUEST['selected'];
46 if (! empty($submit_mult) && isset($_REQUEST['selected_fld'])) {
47 $err_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table);
48 if ($submit_mult == 'browse') {
49 // browsing the table displaying only selected fields/columns
50 $GLOBALS['active_page'] = 'sql.php';
51 $sql_query = '';
52 foreach ($_REQUEST['selected_fld'] as $idx => $sval) {
53 if ($sql_query == '') {
54 $sql_query .= 'SELECT ' . PMA_backquote($sval);
55 } else {
56 $sql_query .= ', ' . PMA_backquote($sval);
60 // what is this htmlspecialchars() for??
61 //$sql_query .= ' FROM ' . PMA_backquote(htmlspecialchars($table));
62 $sql_query .= ' FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
63 require './sql.php';
64 exit;
65 } else {
66 // handle multiple field commands
67 // handle confirmation of deleting multiple fields/columns
68 $action = 'tbl_structure.php';
69 require './libraries/mult_submits.inc.php';
70 //require_once './libraries/header.inc.php';
71 //require_once './libraries/tbl_links.inc.php';
73 if (empty($message)) {
74 $message = PMA_Message::success();
79 /**
80 * Gets the relation settings
82 $cfgRelation = PMA_getRelationsParam();
84 /**
85 * Runs common work
87 require_once './libraries/tbl_common.php';
88 $url_query .= '&amp;goto=tbl_structure.php&amp;back=tbl_structure.php';
89 $url_params['goto'] = 'tbl_structure.php';
90 $url_params['back'] = 'tbl_structure.php';
92 /**
93 * Prepares the table structure display
97 /**
98 * Gets tables informations
100 require_once './libraries/tbl_info.inc.php';
103 * Displays top menu links
105 require_once './libraries/tbl_links.inc.php';
106 require_once './libraries/Index.class.php';
108 // 2. Gets table keys and retains them
109 // @todo should be: $server->db($db)->table($table)->primary()
110 $primary = PMA_Index::getPrimary($table, $db);
112 $columns_with_unique_index = array();
113 foreach (PMA_Index::getFromTable($table, $db) as $index) {
114 if ($index->isUnique() && $index->getChoice() == 'UNIQUE') {
115 $columns = $index->getColumns();
116 foreach ($columns as $column_name => $dummy) {
117 $columns_with_unique_index[$column_name] = 1;
121 unset($index, $columns, $column_name, $dummy);
123 // 3. Get fields
124 $fields_rs = PMA_DRIZZLE
125 ? PMA_DBI_query('SHOW COLUMNS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE)
126 : PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
127 $fields_cnt = PMA_DBI_num_rows($fields_rs);
129 // Get more complete field information
130 // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
131 // but later, if the analyser returns more information, it
132 // could be executed for any MySQL version and replace
133 // the info given by SHOW FULL FIELDS FROM.
135 // We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
136 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
137 // and SHOW CREATE TABLE says NOT NULL (tested
138 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
140 $show_create_table = PMA_DBI_fetch_value(
141 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
142 0, 1);
143 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
146 * prepare table infos
148 // action titles (image or string)
149 $titles = array();
150 $titles['Change'] = PMA_getIcon('b_edit.png', __('Change'), true);
151 $titles['Drop'] = PMA_getIcon('b_drop.png', __('Drop'), true);
152 $titles['NoDrop'] = PMA_getIcon('b_drop.png', __('Drop'), true);
153 $titles['Primary'] = PMA_getIcon('b_primary.png', __('Primary'), true);
154 $titles['Index'] = PMA_getIcon('b_index.png', __('Index'), true);
155 $titles['Unique'] = PMA_getIcon('b_unique.png', __('Unique'), true);
156 $titles['IdxFulltext'] = PMA_getIcon('b_ftext.png', __('Fulltext'), true);
157 $titles['NoPrimary'] = PMA_getIcon('bd_primary.png', __('Primary'), true);
158 $titles['NoIndex'] = PMA_getIcon('bd_index.png', __('Index'), true);
159 $titles['NoUnique'] = PMA_getIcon('bd_unique.png', __('Unique'), true);
160 $titles['NoIdxFulltext'] = PMA_getIcon('bd_ftext.png', __('Fulltext'), true);
161 $titles['BrowseDistinctValues'] = PMA_getIcon('b_browse.png', __('Browse distinct values'), true);
163 // hidden action titles (image and string)
164 $hidden_titles = array();
165 $hidden_titles['BrowseDistinctValues'] = PMA_getIcon('b_browse.png', __('Browse distinct values'), false, true);
166 $hidden_titles['Primary'] = PMA_getIcon('b_primary.png', __('Add primary key'), false, true);
167 $hidden_titles['NoPrimary'] = PMA_getIcon('bd_primary.png', __('Add primary key'), false, true);
168 $hidden_titles['Index'] = PMA_getIcon('b_index.png', __('Add index'), false, true);
169 $hidden_titles['NoIndex'] = PMA_getIcon('bd_index.png', __('Add index'), false, true);
170 $hidden_titles['Unique'] = PMA_getIcon('b_unique.png', __('Add unique index'), false, true);
171 $hidden_titles['NoUnique'] = PMA_getIcon('bd_unique.png', __('Add unique index'), false, true);
172 $hidden_titles['IdxFulltext'] = PMA_getIcon('b_ftext.png', __('Add FULLTEXT index'), false, true);
173 $hidden_titles['NoIdxFulltext'] = PMA_getIcon('bd_ftext.png', __('Add FULLTEXT index'), false, true);
176 * Displays the table structure ('show table' works correct since 3.23.03)
178 /* TABLE INFORMATION */
179 // table header
180 $i = 0;
182 <form method="post" action="tbl_structure.php" name="fieldsForm" id="fieldsForm">
183 <?php echo PMA_generate_common_hidden_inputs($db, $table);
184 echo '<input type="hidden" name="table_type" value=';
185 if($db_is_information_schema) {
186 echo '"information_schema" />';
187 } else if ($tbl_is_view) {
188 echo '"view" />';
189 } else {
190 echo '"table" />';
191 } ?>
193 <table id="tablestructure" class="data">
194 <thead>
195 <tr>
196 <th id="th<?php echo ++$i; ?>"></th>
197 <th id="th<?php echo ++$i; ?>">#</th>
198 <th id="th<?php echo ++$i; ?>" class="column"><?php echo __('Column'); ?></th>
199 <th id="th<?php echo ++$i; ?>" class="type"><?php echo __('Type'); ?></th>
200 <th id="th<?php echo ++$i; ?>" class="collation"><?php echo __('Collation'); ?></th>
201 <th id="th<?php echo ++$i; ?>" class="attributes"><?php echo __('Attributes'); ?></th>
202 <th id="th<?php echo ++$i; ?>" class="null"><?php echo __('Null'); ?></th>
203 <th id="th<?php echo ++$i; ?>" class="default"><?php echo __('Default'); ?></th>
204 <th id="th<?php echo ++$i; ?>" class="extra"><?php echo __('Extra'); ?></th>
205 <?php if ($db_is_information_schema || $tbl_is_view) { ?>
206 <th id="th<?php echo ++$i; ?>" class="view"><?php echo __('View'); ?></th>
207 <?php } else { ?>
208 <th colspan="7" id="th<?php echo ++$i; ?>" class="action"><?php echo __('Action'); ?></th>
209 <?php } ?>
210 </tr>
211 </thead>
212 <tbody>
214 <?php
215 unset($i);
217 // table body
219 // prepare comments
220 $comments_map = array();
221 $mime_map = array();
223 if ($GLOBALS['cfg']['ShowPropertyComments']) {
224 require_once './libraries/transformations.lib.php';
226 //$cfgRelation = PMA_getRelationsParam();
228 $comments_map = PMA_getComments($db, $table);
230 if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) {
231 $mime_map = PMA_getMIME($db, $table, true);
235 $rownum = 0;
236 $aryFields = array();
237 $checked = (!empty($checkall) ? ' checked="checked"' : '');
238 $save_row = array();
239 $odd_row = true;
240 while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
241 $save_row[] = $row;
242 $rownum++;
243 $aryFields[] = $row['Field'];
245 $type = $row['Type'];
246 $extracted_fieldspec = PMA_extractFieldSpec($row['Type']);
248 $truncated = false;
249 if ('set' == $extracted_fieldspec['type'] || 'enum' == $extracted_fieldspec['type']) {
250 $type = $extracted_fieldspec['type'] . '(' .
251 str_replace("','", "', '", $extracted_fieldspec['spec_in_brackets']) . ')';
253 // for the case ENUM('&#8211;','&ldquo;')
254 $type = htmlspecialchars($type);
255 if(strlen($type) > $GLOBALS['cfg']['LimitChars']) {
256 $truncated = true;
257 $type = '<abbr title="' . $type . '">' . substr($type, 0, $GLOBALS['cfg']['LimitChars']) . '</abbr>';
260 $type_nowrap = '';
262 $binary = 0;
263 $unsigned = 0;
264 $zerofill = 0;
265 } else {
266 $type_nowrap = ' nowrap="nowrap"';
267 // strip the "BINARY" attribute, except if we find "BINARY(" because
268 // this would be a BINARY or VARBINARY field type
269 if (!preg_match('@BINARY[\(]@i', $type)) {
270 $type = preg_replace('@BINARY@i', '', $type);
272 $type = preg_replace('@ZEROFILL@i', '', $type);
273 $type = preg_replace('@UNSIGNED@i', '', $type);
274 if (empty($type)) {
275 $type = ' ';
278 if (!preg_match('@BINARY[\(]@i', $row['Type'])) {
279 $binary = stristr($row['Type'], 'blob') || stristr($row['Type'], 'binary');
280 } else {
281 $binary = false;
284 $unsigned = stristr($row['Type'], 'unsigned');
285 $zerofill = stristr($row['Type'], 'zerofill');
288 unset($field_charset);
289 if ((substr($type, 0, 4) == 'char'
290 || substr($type, 0, 7) == 'varchar'
291 || substr($type, 0, 4) == 'text'
292 || substr($type, 0, 8) == 'tinytext'
293 || substr($type, 0, 10) == 'mediumtext'
294 || substr($type, 0, 8) == 'longtext'
295 || substr($type, 0, 3) == 'set'
296 || substr($type, 0, 4) == 'enum'
297 || ($truncated && substr($type, 13, 4) == 'enum'))
298 && !$binary
300 if (strpos($type, ' character set ')) {
301 $type = substr($type, 0, strpos($type, ' character set '));
303 if (!empty($row['Collation'])) {
304 $field_charset = $row['Collation'];
305 } else {
306 $field_charset = '';
308 } else {
309 $field_charset = '';
312 // Display basic mimetype [MIME]
313 if ($cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME'] && isset($mime_map[$row['Field']]['mimetype'])) {
314 $type_mime = '<br />MIME: ' . str_replace('_', '/', $mime_map[$row['Field']]['mimetype']);
315 } else {
316 $type_mime = '';
319 $attribute = ' ';
320 if ($binary) {
321 $attribute = 'BINARY';
323 if ($unsigned) {
324 $attribute = 'UNSIGNED';
326 if ($zerofill) {
327 $attribute = 'UNSIGNED ZEROFILL';
330 // MySQL 4.1.2+ TIMESTAMP options
331 // (if on_update_current_timestamp is set, then it's TRUE)
332 if (isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])) {
333 $attribute = 'on update CURRENT_TIMESTAMP';
336 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
337 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
338 // the latter.
339 if (!empty($analyzed_sql[0]['create_table_fields'][$row['Field']]['type']) && $analyzed_sql[0]['create_table_fields'][$row['Field']]['type'] == 'TIMESTAMP' && $analyzed_sql[0]['create_table_fields'][$row['Field']]['timestamp_not_null']) {
340 $row['Null'] = '';
344 if (!isset($row['Default'])) {
345 if ($row['Null'] == 'YES') {
346 $row['Default'] = '<i>NULL</i>';
348 } else {
349 $row['Default'] = htmlspecialchars($row['Default']);
352 $field_encoded = urlencode($row['Field']);
353 $field_name = htmlspecialchars($row['Field']);
354 $displayed_field_name = $field_name;
356 // underline commented fields and display a hover-title (CSS only)
358 if (isset($comments_map[$row['Field']])) {
359 $displayed_field_name = '<span class="commented_column" title="' . htmlspecialchars($comments_map[$row['Field']]) . '">' . $field_name . '</span>';
362 if ($primary && $primary->hasColumn($field_name)) {
363 $displayed_field_name = '<u>' . $field_name . '</u>';
365 echo "\n";
367 <tr class="<?php echo $odd_row ? 'odd': 'even'; $odd_row = !$odd_row; ?>">
368 <td align="center">
369 <input type="checkbox" name="selected_fld[]" value="<?php echo htmlspecialchars($row['Field']); ?>" id="checkbox_row_<?php echo $rownum; ?>" <?php echo $checked; ?> />
370 </td>
371 <td align="right">
372 <?php echo $rownum; ?>
373 </td>
374 <th nowrap="nowrap"><label for="checkbox_row_<?php echo $rownum; ?>"><?php echo $displayed_field_name; ?></label></th>
375 <td<?php echo $type_nowrap; ?>><bdo dir="ltr" xml:lang="en"><?php echo $type; echo $type_mime; ?></bdo></td>
376 <td><?php echo (empty($field_charset) ? '' : '<dfn title="' . PMA_getCollationDescr($field_charset) . '">' . $field_charset . '</dfn>'); ?></td>
377 <td nowrap="nowrap" class="column_attribute"><?php echo $attribute; ?></td>
378 <td><?php echo (($row['Null'] == 'YES') ? __('Yes') : __('No')); ?></td>
379 <td nowrap="nowrap"><?php
380 if (isset($row['Default'])) {
381 if ($extracted_fieldspec['type'] == 'bit') {
382 // here, $row['Default'] contains something like b'010'
383 echo PMA_convert_bit_default_value($row['Default']);
384 } else {
385 echo $row['Default'];
388 else {
389 echo '<i>' . _pgettext('None for default','None') . '</i>';
390 } ?></td>
391 <td nowrap="nowrap"><?php echo strtoupper($row['Extra']); ?></td>
392 <td align="center" class="browse">
393 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('SELECT COUNT(*) AS ' . PMA_backquote(__('Rows')) . ', ' . PMA_backquote($row['Field']) . ' FROM ' . PMA_backquote($table) . ' GROUP BY ' . PMA_backquote($row['Field']) . ' ORDER BY ' . PMA_backquote($row['Field'])); ?>">
394 <?php echo $titles['BrowseDistinctValues']; ?></a>
395 </td>
396 <?php if (! $tbl_is_view && ! $db_is_information_schema) { ?>
397 <td align="center" class="edit">
398 <a href="tbl_alter.php?<?php echo $url_query; ?>&amp;field=<?php echo $field_encoded; ?>">
399 <?php echo $titles['Change']; ?></a>
400 </td>
401 <td align="center" class="drop">
402 <a <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="drop_column_anchor"' : ''); ?> href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' DROP ' . PMA_backquote($row['Field'])); ?>&amp;dropped_column=<?php echo urlencode($row['Field']); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('Column %s has been dropped'), htmlspecialchars($row['Field']))); ?>" >
403 <?php echo $titles['Drop']; ?></a>
404 </td>
405 <td align="center" class="primary">
406 <?php
407 if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_type || ($primary && $primary->hasColumn($field_name))) {
408 echo $titles['NoPrimary'] . "\n";
409 $primary_enabled = false;
410 } else {
411 echo "\n";
413 <a class="add_primary_key_anchor" href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ($primary ? ' DROP PRIMARY KEY,' : '') . ' ADD PRIMARY KEY(' . PMA_backquote($row['Field']) . ')'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('A primary key has been added on %s'), htmlspecialchars($row['Field']))); ?>" >
414 <?php echo $titles['Primary']; ?></a>
415 <?php $primary_enabled = true;
417 echo "\n";
419 </td>
420 <td align="center" class="unique">
421 <?php
422 if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_type || isset($columns_with_unique_index[$field_name])) {
423 echo $titles['NoUnique'] . "\n";
424 $unique_enabled = false;
425 } else {
426 echo "\n";
428 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD UNIQUE(' . PMA_backquote($row['Field']) . ')'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('An index has been added on %s'), htmlspecialchars($row['Field']))); ?>">
429 <?php echo $titles['Unique']; ?></a>
430 <?php $unique_enabled = true;
432 echo "\n";
434 </td>
435 <td align="center" class="index">
436 <?php
437 if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_type) {
438 echo $titles['NoIndex'] . "\n";
439 $index_enabled = false;
440 } else {
441 echo "\n";
443 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD INDEX(' . PMA_backquote($row['Field']) . ')'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('An index has been added on %s'), htmlspecialchars($row['Field']))); ?>">
444 <?php echo $titles['Index']; ?></a>
445 <?php
446 $index_enabled = true;
448 echo "\n";
450 </td>
451 <?php
452 if (! empty($tbl_type) && ($tbl_type == 'MYISAM' || $tbl_type == 'ARIA' || $tbl_type == 'MARIA')
453 // FULLTEXT is possible on TEXT, CHAR and VARCHAR
454 && (strpos(' ' . $type, 'text') || strpos(' ' . $type, 'char'))) {
455 echo "\n";
457 <td align="center" nowrap="nowrap" class="fulltext">
458 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD FULLTEXT(' . PMA_backquote($row['Field']) . ')'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('An index has been added on %s'), htmlspecialchars($row['Field']))); ?>">
459 <?php echo $titles['IdxFulltext']; ?></a>
460 <?php $fulltext_enabled = true; ?>
461 </td>
462 <?php
463 } else {
464 echo "\n";
466 <td align="center" nowrap="nowrap" class="fulltext">
467 <?php echo $titles['NoIdxFulltext'] . "\n"; ?>
468 <?php $fulltext_enabled = false; ?>
469 </td>
470 <?php
471 } // end if... else...
472 echo "\n";
474 <td class="more_opts" id="more_opts<?php echo $rownum; ?>">
475 <?php echo __('More'); ?> <img src="<?php echo $pmaThemeImage . 'more.png'; ?>" alt="<?php echo __('Show more actions'); ?>" />
476 <div class="structure_actions_dropdown" id="row_<?php echo $rownum; ?>">
478 <div class="action_browse">
479 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('SELECT COUNT(*) AS ' . PMA_backquote(__('Rows')) . ', ' . PMA_backquote($row['Field']) . ' FROM ' . PMA_backquote($table) . ' GROUP BY ' . PMA_backquote($row['Field']) . ' ORDER BY ' . PMA_backquote($row['Field'])); ?>">
480 <?php echo $hidden_titles['BrowseDistinctValues']; ?>
481 </a>
482 </div>
483 <div <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="action_primary"' : ''); ?>>
484 <?php
485 if(isset($primary_enabled)) {
486 if($primary_enabled) { ?>
487 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ($primary ? ' DROP PRIMARY KEY,' : '') . ' ADD PRIMARY KEY(' . PMA_backquote($row['Field']) . ')'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('A primary key has been added on %s'), htmlspecialchars($row['Field']))); ?>">
488 <?php echo $hidden_titles['Primary']; ?>
489 </a>
490 <?php
491 } else {
492 echo $hidden_titles['NoPrimary'];
494 } ?>
495 </div>
496 <div class="action_unique">
497 <?php
498 if(isset($unique_enabled)) {
499 if($unique_enabled) { ?>
500 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD UNIQUE(' . PMA_backquote($row['Field']) . ')'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('An index has been added on %s'), htmlspecialchars($row['Field']))); ?>">
501 <?php echo $hidden_titles['Unique']; ?>
502 </a>
503 <?php
504 } else {
505 echo $hidden_titles['NoUnique'];
507 } ?>
508 </div>
509 <div class="action_index">
510 <?php
511 if(isset($index_enabled)) {
512 if($index_enabled) { ?>
513 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD INDEX(' . PMA_backquote($row['Field']) . ')'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('An index has been added on %s'), htmlspecialchars($row['Field']))); ?>">
514 <?php echo $hidden_titles['Index']; ?>
515 </a>
516 <?php
517 } else {
518 echo $hidden_titles['NoIndex'];
520 } ?>
521 </div>
522 <div class="action_fulltext">
523 <?php
524 if(isset($fulltext_enabled)) {
525 if($fulltext_enabled) { ?>
526 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD FULLTEXT(' . PMA_backquote($row['Field']) . ')'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('An index has been added on %s'), htmlspecialchars($row['Field']))); ?>">
527 <?php echo $hidden_titles['IdxFulltext']; ?>
528 </a>
529 <?php
530 } else {
531 echo $hidden_titles['NoIdxFulltext'];
533 } ?>
534 </div>
535 </div>
536 </td>
537 <?php
538 } // end if (! $tbl_is_view && ! $db_is_information_schema)
540 </tr>
541 <?php
542 unset($field_charset);
543 } // end while
545 echo '</tbody>' . "\n"
546 .'</table>' . "\n";
548 $checkall_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table);
551 <img class="selectallarrow" src="<?php echo $pmaThemeImage . 'arrow_' . $text_dir . '.png'; ?>"
552 width="38" height="22" alt="<?php echo __('With selected:'); ?>" />
553 <a href="<?php echo $checkall_url; ?>&amp;checkall=1"
554 onclick="if (markAllRows('fieldsForm')) return false;">
555 <?php echo __('Check All'); ?></a>
557 <a href="<?php echo $checkall_url; ?>"
558 onclick="if (unMarkAllRows('fieldsForm')) return false;">
559 <?php echo __('Uncheck All'); ?></a>
561 <i><?php echo __('With selected:'); ?></i>
563 <?php
564 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_browse', __('Browse'), 'b_browse.png', 'browse');
566 if (! $tbl_is_view && ! $db_is_information_schema) {
567 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_change', __('Change'), 'b_edit.png', 'change');
568 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_drop', __('Drop'), 'b_drop.png', 'drop');
569 if ('ARCHIVE' != $tbl_type) {
570 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_primary', __('Primary'), 'b_primary.png', 'primary');
571 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_unique', __('Unique'), 'b_unique.png', 'unique');
572 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_index', __('Index'), 'b_index.png', 'index');
575 if (! empty($tbl_type) && ($tbl_type == 'MYISAM' || $tbl_type == 'ARIA' || $tbl_type == 'MARIA')) {
576 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_fulltext', __('Fulltext'), 'b_ftext.png', 'ftext');
580 </form>
581 <hr />
583 <?php
585 * Work on the table
588 <a href="tbl_printview.php?<?php echo $url_query; ?>"><?php
589 if ($cfg['PropertiesIconic']) {
590 echo '<img class="icon" src="' . $pmaThemeImage . 'b_print.png" width="16" height="16" alt="' . __('Print view') . '"/>';
592 echo __('Print view');
593 ?></a>
595 <?php
596 if (! $tbl_is_view && ! $db_is_information_schema) {
598 // if internal relations are available, or foreign keys are supported
599 // ($tbl_type comes from libraries/tbl_info.inc.php)
600 if ($cfgRelation['relwork'] || PMA_foreignkey_supported($tbl_type)) {
602 <a href="tbl_relation.php?<?php echo $url_query; ?>"><?php
603 if ($cfg['PropertiesIconic']) {
604 echo '<img class="icon" src="' . $pmaThemeImage . 'b_relations.png" width="16" height="16" alt="' . __('Relation view') . '"/>';
606 echo __('Relation view');
607 ?></a>
608 <?php
611 <a href="sql.php?<?php echo $url_query; ?>&amp;session_max_rows=all&amp;sql_query=<?php echo urlencode('SELECT * FROM ' . PMA_backquote($table) . ' PROCEDURE ANALYSE()'); ?>"><?php
612 if ($cfg['PropertiesIconic']) {
613 echo '<img class="icon" src="' . $pmaThemeImage . 'b_tblanalyse.png" width="16" height="16" alt="' . __('Propose table structure') . '" />';
615 echo __('Propose table structure');
616 ?></a><?php
617 echo PMA_showMySQLDocu('Extending_MySQL', 'procedure_analyse') . "\n";
620 if(PMA_Tracker::isActive())
622 echo '<a href="tbl_tracking.php?' . $url_query . '">';
624 if ($cfg['PropertiesIconic'])
626 echo '<img class="icon" src="' . $pmaThemeImage . 'eye.png" width="16" height="16" alt="' . __('Track table') . '" /> ';
628 echo __('Track table') . '</a>';
632 <br />
633 <form method="post" action="tbl_addfield.php"
634 onsubmit="return checkFormElementInRange(this, 'num_fields', '<?php echo str_replace('\'', '\\\'', __('You have to add at least one column.')); ?>', 1)">
635 <?php
636 echo PMA_generate_common_hidden_inputs($db, $table);
637 if ($cfg['PropertiesIconic']) {
638 echo '<img class="icon" src="' . $pmaThemeImage . 'b_insrow.png" width="16" height="16" alt="' . __('Add column') . '"/>';
640 echo sprintf(__('Add %s column(s)'), '<input type="text" name="num_fields" size="2" maxlength="2" value="1" onfocus="this.select()" />');
642 // I tried displaying the drop-down inside the label but with Firefox
643 // the drop-down was blinking
644 $fieldOptions = '<select name="after_field" onclick="this.form.field_where[2].checked=true" onchange="this.form.field_where[2].checked=true">';
645 foreach ($aryFields as $fieldname) {
646 $fieldOptions .= '<option value="' . htmlspecialchars($fieldname) . '">' . htmlspecialchars($fieldname) . '</option>' . "\n";
648 unset($aryFields);
649 $fieldOptions .= '</select>';
651 $choices = array(
652 'last' => __('At End of Table'),
653 'first' => __('At Beginning of Table'),
654 'after' => sprintf(__('After %s'), '')
656 PMA_display_html_radio('field_where', $choices, 'last', false);
657 echo $fieldOptions;
658 unset($fieldOptions, $choices);
660 <input type="submit" value="<?php echo __('Go'); ?>" />
661 </form>
662 <iframe class="IE_hack" scrolling="no"></iframe>
663 <hr />
664 <?php
668 * If there are more than 20 rows, displays browse/select/insert/empty/drop
669 * links again
671 if ($fields_cnt > 20) {
672 require './libraries/tbl_links.inc.php';
673 } // end if ($fields_cnt > 20)
676 * Displays indexes
679 if (! $tbl_is_view && ! $db_is_information_schema && 'ARCHIVE' != $tbl_type) {
681 * Display indexes
683 echo PMA_Index::getView($table, $db);
685 <br />
686 <form action="./tbl_indexes.php" method="post"
687 onsubmit="return checkFormElementInRange(this, 'added_fields',
688 '<?php echo str_replace('\'', '\\\'', __('Column count has to be larger than zero.')); ?>',
689 1)">
690 <fieldset>
691 <?php
692 echo PMA_generate_common_hidden_inputs($db, $table);
693 echo sprintf(__('Create an index on &nbsp;%s&nbsp;columns'),
694 '<input type="text" size="2" name="added_fields" value="1" />');
696 <input type="submit" name="create_index" value="<?php echo __('Go'); ?>" />
697 </fieldset>
698 </form>
699 <br />
700 <?php
704 * Displays Space usage and row statistics
706 // BEGIN - Calc Table Space
707 // Get valid statistics whatever is the table type
708 if ($cfg['ShowStats']) {
709 echo '<div id="tablestatistics">';
710 if (empty($showtable)) {
711 $showtable = PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], null, true);
714 $nonisam = false;
715 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
716 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
717 $nonisam = true;
720 // Gets some sizes
722 $mergetable = PMA_Table::isMerge($GLOBALS['db'], $GLOBALS['table']);
724 // this is to display for example 261.2 MiB instead of 268k KiB
725 $max_digits = 5;
726 $decimals = 1;
727 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length'], $max_digits, $decimals);
728 if ($mergetable == false) {
729 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length'], $max_digits, $decimals);
731 // InnoDB returns a huge value in Data_free, do not use it
732 if (! $is_innodb && isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
733 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free'], $max_digits, $decimals);
734 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free'], $max_digits, $decimals);
735 } else {
736 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
738 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
739 if ($table_info_num_rows > 0) {
740 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
743 // Displays them
744 $odd_row = false;
747 <a name="showusage"></a>
748 <?php if (! $tbl_is_view && ! $db_is_information_schema) { ?>
749 <table id="tablespaceusage" class="data">
750 <caption class="tblHeaders"><?php echo __('Space usage'); ?></caption>
751 <thead>
752 <tr>
753 <th><?php echo __('Type'); ?></th>
754 <th colspan="2"><?php echo __('Usage'); ?></th>
755 </tr>
756 </thead>
757 <tbody>
758 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
759 <th class="name"><?php echo __('Data'); ?></th>
760 <td class="value"><?php echo $data_size; ?></td>
761 <td class="unit"><?php echo $data_unit; ?></td>
762 </tr>
763 <?php
764 if (isset($index_size)) {
766 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
767 <th class="name"><?php echo __('Index'); ?></th>
768 <td class="value"><?php echo $index_size; ?></td>
769 <td class="unit"><?php echo $index_unit; ?></td>
770 </tr>
771 <?php
773 if (isset($free_size)) {
775 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?> error">
776 <th class="name"><?php echo __('Overhead'); ?></th>
777 <td class="value"><?php echo $free_size; ?></td>
778 <td class="unit"><?php echo $free_unit; ?></td>
779 </tr>
780 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
781 <th class="name"><?php echo __('Effective'); ?></th>
782 <td class="value"><?php echo $effect_size; ?></td>
783 <td class="unit"><?php echo $effect_unit; ?></td>
784 </tr>
785 <?php
787 if (isset($tot_size) && $mergetable == false) {
789 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
790 <th class="name"><?php echo __('Total'); ?></th>
791 <td class="value"><?php echo $tot_size; ?></td>
792 <td class="unit"><?php echo $tot_unit; ?></td>
793 </tr>
794 <?php
796 // Optimize link if overhead
797 if (isset($free_size) && ($tbl_type == 'MYISAM' || $tbl_type == 'ARIA' || $tbl_type == 'MARIA' || $tbl_type == 'BDB')) {
799 <tr class="tblFooters">
800 <td colspan="3" align="center">
801 <a href="sql.php?<?php echo $url_query; ?>&pos=0&amp;sql_query=<?php echo urlencode('OPTIMIZE TABLE ' . PMA_backquote($table)); ?>"><?php
802 if ($cfg['PropertiesIconic']) {
803 echo '<img class="icon" src="' . $pmaThemeImage . 'b_tbloptimize.png" width="16" height="16" alt="' . __('Optimize table'). '" />';
805 echo __('Optimize table');
806 ?></a>
807 </td>
808 </tr>
809 <?php
812 </tbody>
813 </table>
814 <?php
816 $odd_row = false;
818 <table id="tablerowstats" class="data">
819 <caption class="tblHeaders"><?php echo __('Row Statistics'); ?></caption>
820 <thead>
821 <tr>
822 <th><?php echo __('Statements'); ?></th>
823 <th><?php echo __('Value'); ?></th>
824 </tr>
825 </thead>
826 <tbody>
827 <?php
828 if (isset($showtable['Row_format'])) {
830 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
831 <th class="name"><?php echo __('Format'); ?></th>
832 <td class="value"><?php
833 if ($showtable['Row_format'] == 'Fixed') {
834 echo __('static');
835 } elseif ($showtable['Row_format'] == 'Dynamic') {
836 echo __('dynamic');
837 } else {
838 echo $showtable['Row_format'];
840 ?></td>
841 </tr>
842 <?php
844 if (! empty($showtable['Create_options'])) {
846 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
847 <th class="name"><?php echo __('Options'); ?></th>
848 <td class="value"><?php
849 if ($showtable['Create_options'] == 'partitioned') {
850 echo __('partitioned');
851 } else {
852 echo $showtable['Create_options'];
854 ?></td>
855 </tr>
856 <?php
858 if (!empty($tbl_collation)) {
860 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
861 <th class="name"><?php echo __('Collation'); ?></th>
862 <td class="value"><?php
863 echo '<dfn title="' . PMA_getCollationDescr($tbl_collation) . '">' . $tbl_collation . '</dfn>';
864 ?></td>
865 </tr>
866 <?php
868 if (!$is_innodb && isset($showtable['Rows'])) {
870 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
871 <th class="name"><?php echo __('Rows'); ?></th>
872 <td class="value"><?php echo PMA_formatNumber($showtable['Rows'], 0); ?></td>
873 </tr>
874 <?php
876 if (!$is_innodb && isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
878 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
879 <th class="name"><?php echo __('Row length'); ?> &oslash;</th>
880 <td class="value"><?php echo PMA_formatNumber($showtable['Avg_row_length'], 0); ?></td>
881 </tr>
882 <?php
884 if (!$is_innodb && isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
886 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
887 <th class="name"><?php echo __(' Row size '); ?> &oslash;</th>
888 <td class="value"><?php echo $avg_size . ' ' . $avg_unit; ?></td>
889 </tr>
890 <?php
892 if (isset($showtable['Auto_increment'])) {
894 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
895 <th class="name"><?php echo __('Next'); ?> Autoindex</th>
896 <td class="value"><?php echo PMA_formatNumber($showtable['Auto_increment'], 0); ?></td>
897 </tr>
898 <?php
900 if (isset($showtable['Create_time'])) {
902 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
903 <th class="name"><?php echo __('Creation'); ?></th>
904 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Create_time'])); ?></td>
905 </tr>
906 <?php
908 if (isset($showtable['Update_time'])) {
910 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
911 <th class="name"><?php echo __('Last update'); ?></th>
912 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Update_time'])); ?></td>
913 </tr>
914 <?php
916 if (isset($showtable['Check_time'])) {
918 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
919 <th class="name"><?php echo __('Last check'); ?></th>
920 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Check_time'])); ?></td>
921 </tr>
922 <?php
925 </tbody>
926 </table>
928 <!-- close tablestatistics div -->
929 </div>
931 <?php
933 // END - Calc Table Space
935 require './libraries/tbl_triggers.lib.php';
937 echo '<div class="clearfloat"></div>' . "\n";
940 * Displays the footer
942 require './libraries/footer.inc.php';