Fixed: 'Browse foreign values' not working properly
[phpmyadmin/ammaryasirr.git] / tbl_structure.php
blobbbaee89d5e64b8cdd3956faac76df1c293b4ef62
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';
17 $GLOBALS['js_include'][] = 'indexes.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_spatial_x'])) {
34 $submit_mult = 'spatial';
35 } elseif (isset($_REQUEST['submit_mult_fulltext_x'])) {
36 $submit_mult = 'ftext';
37 } elseif (isset($_REQUEST['submit_mult_browse_x'])) {
38 $submit_mult = 'browse';
39 } elseif (isset($_REQUEST['submit_mult'])) {
40 $submit_mult = $_REQUEST['submit_mult'];
41 } elseif (isset($_REQUEST['mult_btn']) && $_REQUEST['mult_btn'] == __('Yes')) {
42 $submit_mult = 'row_delete';
43 if (isset($_REQUEST['selected'])) {
44 $_REQUEST['selected_fld'] = $_REQUEST['selected'];
48 if (! empty($submit_mult) && isset($_REQUEST['selected_fld'])) {
49 $err_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table);
50 if ($submit_mult == 'browse') {
51 // browsing the table displaying only selected fields/columns
52 $GLOBALS['active_page'] = 'sql.php';
53 $sql_query = '';
54 foreach ($_REQUEST['selected_fld'] as $idx => $sval) {
55 if ($sql_query == '') {
56 $sql_query .= 'SELECT ' . PMA_backquote($sval);
57 } else {
58 $sql_query .= ', ' . PMA_backquote($sval);
62 // what is this htmlspecialchars() for??
63 //$sql_query .= ' FROM ' . PMA_backquote(htmlspecialchars($table));
64 $sql_query .= ' FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
65 require './sql.php';
66 exit;
67 } else {
68 // handle multiple field commands
69 // handle confirmation of deleting multiple fields/columns
70 $action = 'tbl_structure.php';
71 require './libraries/mult_submits.inc.php';
72 //require_once './libraries/header.inc.php';
73 //require_once './libraries/tbl_links.inc.php';
75 if (empty($message)) {
76 $message = PMA_Message::success();
81 /**
82 * Gets the relation settings
84 $cfgRelation = PMA_getRelationsParam();
86 /**
87 * Runs common work
89 require_once './libraries/tbl_common.php';
90 $url_query .= '&amp;goto=tbl_structure.php&amp;back=tbl_structure.php';
91 $url_params['goto'] = 'tbl_structure.php';
92 $url_params['back'] = 'tbl_structure.php';
94 /**
95 * Prepares the table structure display
99 /**
100 * Gets tables informations
102 require_once './libraries/tbl_info.inc.php';
105 * Displays top menu links
107 require_once './libraries/tbl_links.inc.php';
108 require_once './libraries/Index.class.php';
110 // 2. Gets table keys and retains them
111 // @todo should be: $server->db($db)->table($table)->primary()
112 $primary = PMA_Index::getPrimary($table, $db);
114 $columns_with_unique_index = array();
115 foreach (PMA_Index::getFromTable($table, $db) as $index) {
116 if ($index->isUnique() && $index->getChoice() == 'UNIQUE') {
117 $columns = $index->getColumns();
118 foreach ($columns as $column_name => $dummy) {
119 $columns_with_unique_index[$column_name] = 1;
123 unset($index, $columns, $column_name, $dummy);
125 // 3. Get fields
126 $fields = PMA_DBI_get_columns($db, $table, true);
127 $fields_cnt = count($fields);
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'));
151 $titles['Drop'] = PMA_getIcon('b_drop.png', __('Drop'));
152 $titles['NoDrop'] = PMA_getIcon('b_drop.png', __('Drop'));
153 $titles['Primary'] = PMA_getIcon('b_primary.png', __('Primary'));
154 $titles['Index'] = PMA_getIcon('b_index.png', __('Index'));
155 $titles['Unique'] = PMA_getIcon('b_unique.png', __('Unique'));
156 $titles['Spatial'] = PMA_getIcon('b_spatial.png', __('Spatial'));
157 $titles['IdxFulltext'] = PMA_getIcon('b_ftext.png', __('Fulltext'));
158 $titles['NoPrimary'] = PMA_getIcon('bd_primary.png', __('Primary'));
159 $titles['NoIndex'] = PMA_getIcon('bd_index.png', __('Index'));
160 $titles['NoUnique'] = PMA_getIcon('bd_unique.png', __('Unique'));
161 $titles['NoSpatial'] = PMA_getIcon('bd_spatial.png', __('Spatial'));
162 $titles['NoIdxFulltext'] = PMA_getIcon('bd_ftext.png', __('Fulltext'));
163 $titles['BrowseDistinctValues'] = PMA_getIcon('b_browse.png', __('Browse distinct values'));
165 // hidden action titles (image and string)
166 $hidden_titles = array();
167 $hidden_titles['BrowseDistinctValues'] = PMA_getIcon('b_browse.png', __('Browse distinct values'), true);
168 $hidden_titles['Primary'] = PMA_getIcon('b_primary.png', __('Add primary key'), true);
169 $hidden_titles['NoPrimary'] = PMA_getIcon('bd_primary.png', __('Add primary key'), true);
170 $hidden_titles['Index'] = PMA_getIcon('b_index.png', __('Add index'), true);
171 $hidden_titles['NoIndex'] = PMA_getIcon('bd_index.png', __('Add index'), true);
172 $hidden_titles['Unique'] = PMA_getIcon('b_unique.png', __('Add unique index'), true);
173 $hidden_titles['NoUnique'] = PMA_getIcon('bd_unique.png', __('Add unique index'), true);
174 $hidden_titles['Spatial'] = PMA_getIcon('b_spatial.png', __('Add SPATIAL index'), true);
175 $hidden_titles['NoSpatial'] = PMA_getIcon('bd_spatial.png', __('Add SPATIAL index'), true);
176 $hidden_titles['IdxFulltext'] = PMA_getIcon('b_ftext.png', __('Add FULLTEXT index'), true);
177 $hidden_titles['NoIdxFulltext'] = PMA_getIcon('bd_ftext.png', __('Add FULLTEXT index'), true);
180 * Displays the table structure ('show table' works correct since 3.23.03)
182 /* TABLE INFORMATION */
183 // table header
184 $i = 0;
186 <form method="post" action="tbl_structure.php" name="fieldsForm" id="fieldsForm" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : '');?>>
187 <?php echo PMA_generate_common_hidden_inputs($db, $table);
188 echo '<input type="hidden" name="table_type" value=';
189 if ($db_is_information_schema) {
190 echo '"information_schema" />';
191 } else if ($tbl_is_view) {
192 echo '"view" />';
193 } else {
194 echo '"table" />';
195 } ?>
197 <table id="tablestructure" class="data">
198 <thead>
199 <tr>
200 <th id="th<?php echo ++$i; ?>"></th>
201 <th id="th<?php echo ++$i; ?>">#</th>
202 <th id="th<?php echo ++$i; ?>" class="column"><?php echo __('Name'); ?></th>
203 <th id="th<?php echo ++$i; ?>" class="type"><?php echo __('Type'); ?></th>
204 <th id="th<?php echo ++$i; ?>" class="collation"><?php echo __('Collation'); ?></th>
205 <th id="th<?php echo ++$i; ?>" class="attributes"><?php echo __('Attributes'); ?></th>
206 <th id="th<?php echo ++$i; ?>" class="null"><?php echo __('Null'); ?></th>
207 <th id="th<?php echo ++$i; ?>" class="default"><?php echo __('Default'); ?></th>
208 <th id="th<?php echo ++$i; ?>" class="extra"><?php echo __('Extra'); ?></th>
209 <?php if ($db_is_information_schema || $tbl_is_view) { ?>
210 <th id="th<?php echo ++$i; ?>" class="view"><?php echo __('View'); ?></th>
211 <?php } else { ?>
212 <th colspan="7" id="th<?php echo ++$i; ?>" class="action"><?php echo __('Action'); ?></th>
213 <?php } ?>
214 </tr>
215 </thead>
216 <tbody>
218 <?php
219 unset($i);
221 // table body
223 // prepare comments
224 $comments_map = array();
225 $mime_map = array();
227 if ($GLOBALS['cfg']['ShowPropertyComments']) {
228 require_once './libraries/transformations.lib.php';
230 //$cfgRelation = PMA_getRelationsParam();
232 $comments_map = PMA_getComments($db, $table);
234 if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) {
235 $mime_map = PMA_getMIME($db, $table, true);
239 $rownum = 0;
240 $aryFields = array();
241 $checked = (!empty($checkall) ? ' checked="checked"' : '');
242 $save_row = array();
243 $odd_row = true;
244 foreach ($fields as $row) {
245 $save_row[] = $row;
246 $rownum++;
247 $aryFields[] = $row['Field'];
249 $type = $row['Type'];
250 $extracted_fieldspec = PMA_extractFieldSpec($row['Type']);
252 if ('set' == $extracted_fieldspec['type'] || 'enum' == $extracted_fieldspec['type']) {
253 $type_nowrap = '';
254 } else {
255 $type_nowrap = ' nowrap="nowrap"';
257 $type = $extracted_fieldspec['print_type'];
258 if (empty($type)) {
259 $type = ' ';
261 // for the case ENUM('&#8211;','&ldquo;')
262 $type = htmlspecialchars($type);
263 // in case it is too long
264 if (strlen($type) > $GLOBALS['cfg']['LimitChars']) {
265 $type = '<abbr title="' . $type . '">' . substr($type, 0, $GLOBALS['cfg']['LimitChars']) . '</abbr>';
268 unset($field_charset);
269 if ((substr($type, 0, 4) == 'char'
270 || substr($type, 0, 7) == 'varchar'
271 || substr($type, 0, 4) == 'text'
272 || substr($type, 0, 8) == 'tinytext'
273 || substr($type, 0, 10) == 'mediumtext'
274 || substr($type, 0, 8) == 'longtext'
275 || substr($type, 0, 3) == 'set'
276 || substr($type, 0, 4) == 'enum'
277 ) && !$extracted_fieldspec['binary']) {
278 if (strpos($type, ' character set ')) {
279 $type = substr($type, 0, strpos($type, ' character set '));
281 if (!empty($row['Collation'])) {
282 $field_charset = $row['Collation'];
283 } else {
284 $field_charset = '';
286 } else {
287 $field_charset = '';
290 // Display basic mimetype [MIME]
291 if ($cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME'] && isset($mime_map[$row['Field']]['mimetype'])) {
292 $type_mime = '<br />MIME: ' . str_replace('_', '/', $mime_map[$row['Field']]['mimetype']);
293 } else {
294 $type_mime = '';
297 $attribute = $extracted_fieldspec['attribute'];
299 // MySQL 4.1.2+ TIMESTAMP options
300 // (if on_update_current_timestamp is set, then it's TRUE)
301 if (isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])) {
302 $attribute = 'on update CURRENT_TIMESTAMP';
305 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
306 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
307 // the latter.
308 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']) {
309 $row['Null'] = '';
313 if (! isset($row['Default'])) {
314 if ($row['Null'] == 'YES') {
315 $row['Default'] = '<i>NULL</i>';
317 } else {
318 $row['Default'] = htmlspecialchars($row['Default']);
321 $field_encoded = urlencode($row['Field']);
322 $field_name = htmlspecialchars($row['Field']);
323 $displayed_field_name = $field_name;
325 // underline commented fields and display a hover-title (CSS only)
327 if (isset($comments_map[$row['Field']])) {
328 $displayed_field_name = '<span class="commented_column" title="' . htmlspecialchars($comments_map[$row['Field']]) . '">' . $field_name . '</span>';
331 if ($primary && $primary->hasColumn($field_name)) {
332 $displayed_field_name = '<u>' . $field_name . '</u>';
334 echo "\n";
336 <tr class="<?php echo $odd_row ? 'odd': 'even'; $odd_row = !$odd_row; ?>">
337 <td align="center">
338 <input type="checkbox" name="selected_fld[]" value="<?php echo htmlspecialchars($row['Field']); ?>" id="checkbox_row_<?php echo $rownum; ?>" <?php echo $checked; ?> />
339 </td>
340 <td align="right">
341 <?php echo $rownum; ?>
342 </td>
343 <th nowrap="nowrap"><label for="checkbox_row_<?php echo $rownum; ?>"><?php echo $displayed_field_name; ?></label></th>
344 <td<?php echo $type_nowrap; ?>><bdo dir="ltr" xml:lang="en"><?php echo $type; echo $type_mime; ?></bdo></td>
345 <td><?php echo (empty($field_charset) ? '' : '<dfn title="' . PMA_getCollationDescr($field_charset) . '">' . $field_charset . '</dfn>'); ?></td>
346 <td nowrap="nowrap" class="column_attribute"><?php echo $attribute; ?></td>
347 <td><?php echo (($row['Null'] == 'YES') ? __('Yes') : __('No')); ?></td>
348 <td nowrap="nowrap"><?php
349 if (isset($row['Default'])) {
350 if ($extracted_fieldspec['type'] == 'bit') {
351 // here, $row['Default'] contains something like b'010'
352 echo PMA_convert_bit_default_value($row['Default']);
353 } else {
354 echo $row['Default'];
357 else {
358 echo '<i>' . _pgettext('None for default','None') . '</i>';
359 } ?></td>
360 <td nowrap="nowrap"><?php echo strtoupper($row['Extra']); ?></td>
361 <td align="center" class="browse">
362 <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'])); ?>">
363 <?php echo $titles['BrowseDistinctValues']; ?></a>
364 </td>
365 <?php if (! $tbl_is_view && ! $db_is_information_schema) { ?>
366 <td align="center" class="edit">
367 <a href="tbl_alter.php?<?php echo $url_query; ?>&amp;field=<?php echo $field_encoded; ?>">
368 <?php echo $titles['Change']; ?></a>
369 </td>
370 <td align="center" class="drop">
371 <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']))); ?>" >
372 <?php echo $titles['Drop']; ?></a>
373 </td>
374 <td align="center" class="primary">
375 <?php
376 if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_type || ($primary && $primary->hasColumn($field_name))) {
377 echo $titles['NoPrimary'] . "\n";
378 $primary_enabled = false;
379 } else {
380 echo "\n";
382 <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']))); ?>" >
383 <?php echo $titles['Primary']; ?></a>
384 <?php $primary_enabled = true;
386 echo "\n";
388 </td>
389 <td align="center" class="unique">
390 <?php
391 if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_type || isset($columns_with_unique_index[$field_name])) {
392 echo $titles['NoUnique'] . "\n";
393 $unique_enabled = false;
394 } else {
395 echo "\n";
397 <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']))); ?>">
398 <?php echo $titles['Unique']; ?></a>
399 <?php $unique_enabled = true;
401 echo "\n";
403 </td>
404 <td align="center" class="index">
405 <?php
406 if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_type) {
407 echo $titles['NoIndex'] . "\n";
408 $index_enabled = false;
409 } else {
410 echo "\n";
412 <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']))); ?>">
413 <?php echo $titles['Index']; ?></a>
414 <?php
415 $index_enabled = true;
417 echo "\n";
419 </td>
420 <td align="center" class="spatial">
421 <?php
422 $spatial_types = array(
423 'geometry', 'point', 'linestring', 'polygon', 'multipoint',
424 'multilinestring', 'multipolygon', 'geomtrycollection'
426 if (! in_array($type, $spatial_types) || 'MYISAM' != $tbl_type) {
427 echo $titles['NoSpatial'] . "\n";
428 $spatial_enabled = false;
429 } else {
430 echo "\n";
432 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD SPATIAL(' . PMA_backquote($row['Field']) . ')'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('An index has been added on %s'), htmlspecialchars($row['Field']))); ?>">
433 <?php echo $titles['Spatial']; ?></a>
434 <?php
435 $spatial_enabled = true;
437 echo "\n";
439 </td>
440 <?php
441 if (! empty($tbl_type) && ($tbl_type == 'MYISAM' || $tbl_type == 'ARIA' || $tbl_type == 'MARIA')
442 // FULLTEXT is possible on TEXT, CHAR and VARCHAR
443 && (strpos(' ' . $type, 'text') || strpos(' ' . $type, 'char'))) {
444 echo "\n";
446 <td align="center" nowrap="nowrap" class="fulltext">
447 <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']))); ?>">
448 <?php echo $titles['IdxFulltext']; ?></a>
449 <?php $fulltext_enabled = true; ?>
450 </td>
451 <?php
452 } else {
453 echo "\n";
455 <td align="center" nowrap="nowrap" class="fulltext">
456 <?php echo $titles['NoIdxFulltext'] . "\n"; ?>
457 <?php $fulltext_enabled = false; ?>
458 </td>
459 <?php
460 } // end if... else...
461 echo "\n";
463 <td class="more_opts" id="more_opts<?php echo $rownum; ?>">
464 <?php echo __('More'); ?> <img class="icon ic_more" src="themes/dot.gif" alt="<?php echo __('Show more actions'); ?>" />
465 <div class="structure_actions_dropdown" id="row_<?php echo $rownum; ?>">
467 <div class="action_browse">
468 <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'])); ?>">
469 <?php echo $hidden_titles['BrowseDistinctValues']; ?>
470 </a>
471 </div>
472 <div <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="action_primary"' : ''); ?>>
473 <?php
474 if (isset($primary_enabled)) {
475 if ($primary_enabled) { ?>
476 <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']))); ?>">
477 <?php echo $hidden_titles['Primary']; ?>
478 </a>
479 <?php
480 } else {
481 echo $hidden_titles['NoPrimary'];
483 } ?>
484 </div>
485 <div class="action_unique">
486 <?php
487 if (isset($unique_enabled)) {
488 if ($unique_enabled) { ?>
489 <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']))); ?>">
490 <?php echo $hidden_titles['Unique']; ?>
491 </a>
492 <?php
493 } else {
494 echo $hidden_titles['NoUnique'];
496 } ?>
497 </div>
498 <div class="action_index">
499 <?php
500 if (isset($index_enabled)) {
501 if ($index_enabled) { ?>
502 <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']))); ?>">
503 <?php echo $hidden_titles['Index']; ?>
504 </a>
505 <?php
506 } else {
507 echo $hidden_titles['NoIndex'];
509 } ?>
510 </div>
511 <div class="action_spatial">
512 <?php
513 if (isset($spatial_enabled)) {
514 if ($spatial_enabled) { ?>
515 <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD SPATIAL(' . PMA_backquote($row['Field']) . ')'); ?>&amp;message_to_show=<?php echo urlencode(sprintf(__('An index has been added on %s'), htmlspecialchars($row['Field']))); ?>">
516 <?php echo $hidden_titles['Spatial']; ?>
517 </a>
518 <?php
519 } else {
520 echo $hidden_titles['NoSpatial'];
522 } ?>
523 </div>
524 <div class="action_fulltext">
525 <?php
526 if (isset($fulltext_enabled)) {
527 if ($fulltext_enabled) { ?>
528 <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']))); ?>">
529 <?php echo $hidden_titles['IdxFulltext']; ?>
530 </a>
531 <?php
532 } else {
533 echo $hidden_titles['NoIdxFulltext'];
535 } ?>
536 </div>
537 </div>
538 </td>
539 <?php
540 } // end if (! $tbl_is_view && ! $db_is_information_schema)
542 </tr>
543 <?php
544 unset($field_charset);
545 } // end foreach
547 echo '</tbody>' . "\n"
548 .'</table>' . "\n";
550 $checkall_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table);
553 <img class="selectallarrow" src="<?php echo $pmaThemeImage . 'arrow_' . $text_dir . '.png'; ?>"
554 width="38" height="22" alt="<?php echo __('With selected:'); ?>" />
555 <a href="<?php echo $checkall_url; ?>&amp;checkall=1"
556 onclick="if (markAllRows('fieldsForm')) return false;">
557 <?php echo __('Check All'); ?></a>
559 <a href="<?php echo $checkall_url; ?>"
560 onclick="if (unMarkAllRows('fieldsForm')) return false;">
561 <?php echo __('Uncheck All'); ?></a>
563 <i><?php echo __('With selected:'); ?></i>
565 <?php
566 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_browse', __('Browse'), 'b_browse.png', 'browse');
568 if (! $tbl_is_view && ! $db_is_information_schema) {
569 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_change', __('Change'), 'b_edit.png', 'change');
570 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_drop', __('Drop'), 'b_drop.png', 'drop');
571 if ('ARCHIVE' != $tbl_type) {
572 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_primary', __('Primary'), 'b_primary.png', 'primary');
573 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_unique', __('Unique'), 'b_unique.png', 'unique');
574 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_index', __('Index'), 'b_index.png', 'index');
577 if (! empty($tbl_type) && $tbl_type == 'MYISAM') {
578 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_spatial', __('Spatial'), 'b_spatial.png', 'spatial');
580 if (! empty($tbl_type) && ($tbl_type == 'MYISAM' || $tbl_type == 'ARIA' || $tbl_type == 'MARIA')) {
581 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_fulltext', __('Fulltext'), 'b_ftext.png', 'ftext');
585 </form>
586 <hr />
588 <?php
590 * Work on the table
593 if ($tbl_is_view) {
594 $create_view = PMA_DBI_get_definition($db, 'VIEW', $table);
595 echo PMA_linkOrButton(
596 'tbl_sql.php' . PMA_generate_common_url(
597 $url_params +
598 array(
599 'sql_query' => $create_view,
600 'show_query' => '1',
603 PMA_getIcon('b_edit.png', __('Edit view'))
608 <a href="tbl_printview.php?<?php echo $url_query; ?>"><?php
609 echo PMA_getIcon('b_print.png', __('Print view'));
610 ?></a>
612 <?php
613 if (! $tbl_is_view && ! $db_is_information_schema) {
615 // if internal relations are available, or foreign keys are supported
616 // ($tbl_type comes from libraries/tbl_info.inc.php)
617 if ($cfgRelation['relwork'] || PMA_foreignkey_supported($tbl_type)) {
619 <a href="tbl_relation.php?<?php echo $url_query; ?>"><?php
620 echo PMA_getIcon('b_relations.png', __('Relation view'));
621 ?></a>
622 <?php
625 <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
626 echo PMA_getIcon('b_tblanalyse.png', __('Propose table structure'));
627 ?></a><?php
628 echo PMA_showMySQLDocu('Extending_MySQL', 'procedure_analyse') . "\n";
631 if (PMA_Tracker::isActive())
633 echo '<a href="tbl_tracking.php?' . $url_query . '">';
634 echo PMA_getIcon('eye.png', __('Track table'));
635 echo '</a>';
639 <br />
640 <form method="post" action="tbl_addfield.php" id="addColumns" name="addColumns" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : '');?>
641 onsubmit="return checkFormElementInRange(this, 'num_fields', '<?php echo str_replace('\'', '\\\'', __('You have to add at least one column.')); ?>', 1)">
642 <?php
643 echo PMA_generate_common_hidden_inputs($db, $table);
644 if ($cfg['PropertiesIconic']) {
645 echo '<img class="icon ic_b_insrow" src="themes/dot.gif" alt="' . __('Add column') . '"/>';
647 echo sprintf(__('Add %s column(s)'), '<input type="text" name="num_fields" size="2" maxlength="2" value="1" onfocus="this.select()" />');
649 // I tried displaying the drop-down inside the label but with Firefox
650 // the drop-down was blinking
651 $fieldOptions = '<select name="after_field" onclick="this.form.field_where[2].checked=true" onchange="this.form.field_where[2].checked=true">';
652 foreach ($aryFields as $fieldname) {
653 $fieldOptions .= '<option value="' . htmlspecialchars($fieldname) . '">' . htmlspecialchars($fieldname) . '</option>' . "\n";
655 unset($aryFields);
656 $fieldOptions .= '</select>';
658 $choices = array(
659 'last' => __('At End of Table'),
660 'first' => __('At Beginning of Table'),
661 'after' => sprintf(__('After %s'), '')
663 PMA_display_html_radio('field_where', $choices, 'last', false);
664 echo $fieldOptions;
665 unset($fieldOptions, $choices);
667 <input type="submit" value="<?php echo __('Go'); ?>" />
668 </form>
669 <iframe class="IE_hack" scrolling="no"></iframe>
670 <hr />
671 <div id="index_div" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?> >
672 <?php
676 * If there are more than 20 rows, displays browse/select/insert/empty/drop
677 * links again
679 if ($fields_cnt > 20) {
680 require './libraries/tbl_links.inc.php';
681 } // end if ($fields_cnt > 20)
684 * Displays indexes
687 if (! $tbl_is_view && ! $db_is_information_schema && 'ARCHIVE' != $tbl_type) {
689 * Display indexes
691 echo PMA_Index::getView($table, $db);
693 </div>
694 <form action="./tbl_indexes.php" method="post"
695 onsubmit="return checkFormElementInRange(this, 'added_fields',
696 '<?php echo str_replace('\'', '\\\'', __('Column count has to be larger than zero.')); ?>',
697 1)">
698 <fieldset>
699 <?php
700 echo PMA_generate_common_hidden_inputs($db, $table);
701 echo sprintf(__('Create an index on &nbsp;%s&nbsp;columns'),
702 '<input type="text" size="2" name="added_fields" value="1" />');
704 <input type="submit" name="create_index" value="<?php echo __('Go'); ?>" />
705 </fieldset>
706 </form>
707 <br />
708 <?php
712 * Displays Space usage and row statistics
714 // BEGIN - Calc Table Space
715 // Get valid statistics whatever is the table type
716 if ($cfg['ShowStats']) {
717 echo '<div id="tablestatistics">';
718 if (empty($showtable)) {
719 $showtable = PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], null, true);
722 $nonisam = false;
723 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
724 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
725 $nonisam = true;
728 // Gets some sizes
730 $mergetable = PMA_Table::isMerge($GLOBALS['db'], $GLOBALS['table']);
732 // this is to display for example 261.2 MiB instead of 268k KiB
733 $max_digits = 5;
734 $decimals = 1;
735 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length'], $max_digits, $decimals);
736 if ($mergetable == false) {
737 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length'], $max_digits, $decimals);
739 // InnoDB returns a huge value in Data_free, do not use it
740 if (! $is_innodb && isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
741 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free'], $max_digits, $decimals);
742 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free'], $max_digits, $decimals);
743 } else {
744 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
746 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
747 if ($table_info_num_rows > 0) {
748 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
751 // Displays them
752 $odd_row = false;
755 <a name="showusage"></a>
756 <?php if (! $tbl_is_view && ! $db_is_information_schema) { ?>
757 <table id="tablespaceusage" class="data">
758 <caption class="tblHeaders"><?php echo __('Space usage'); ?></caption>
759 <thead>
760 <tr>
761 <th><?php echo __('Type'); ?></th>
762 <th colspan="2"><?php echo __('Usage'); ?></th>
763 </tr>
764 </thead>
765 <tbody>
766 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
767 <th class="name"><?php echo __('Data'); ?></th>
768 <td class="value"><?php echo $data_size; ?></td>
769 <td class="unit"><?php echo $data_unit; ?></td>
770 </tr>
771 <?php
772 if (isset($index_size)) {
774 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
775 <th class="name"><?php echo __('Index'); ?></th>
776 <td class="value"><?php echo $index_size; ?></td>
777 <td class="unit"><?php echo $index_unit; ?></td>
778 </tr>
779 <?php
781 if (isset($free_size)) {
783 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?> error">
784 <th class="name"><?php echo __('Overhead'); ?></th>
785 <td class="value"><?php echo $free_size; ?></td>
786 <td class="unit"><?php echo $free_unit; ?></td>
787 </tr>
788 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
789 <th class="name"><?php echo __('Effective'); ?></th>
790 <td class="value"><?php echo $effect_size; ?></td>
791 <td class="unit"><?php echo $effect_unit; ?></td>
792 </tr>
793 <?php
795 if (isset($tot_size) && $mergetable == false) {
797 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
798 <th class="name"><?php echo __('Total'); ?></th>
799 <td class="value"><?php echo $tot_size; ?></td>
800 <td class="unit"><?php echo $tot_unit; ?></td>
801 </tr>
802 <?php
804 // Optimize link if overhead
805 if (isset($free_size) && ($tbl_type == 'MYISAM' || $tbl_type == 'ARIA' || $tbl_type == 'MARIA' || $tbl_type == 'BDB')) {
807 <tr class="tblFooters">
808 <td colspan="3" align="center">
809 <a href="sql.php?<?php echo $url_query; ?>&pos=0&amp;sql_query=<?php echo urlencode('OPTIMIZE TABLE ' . PMA_backquote($table)); ?>"><?php
810 echo PMA_getIcon('b_tbloptimize.png', __('Optimize table'));
811 ?></a>
812 </td>
813 </tr>
814 <?php
817 </tbody>
818 </table>
819 <?php
821 $odd_row = false;
823 <table id="tablerowstats" class="data">
824 <caption class="tblHeaders"><?php echo __('Row Statistics'); ?></caption>
825 <thead>
826 <tr>
827 <th><?php echo __('Statements'); ?></th>
828 <th><?php echo __('Value'); ?></th>
829 </tr>
830 </thead>
831 <tbody>
832 <?php
833 if (isset($showtable['Row_format'])) {
835 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
836 <th class="name"><?php echo __('Format'); ?></th>
837 <td class="value"><?php
838 if ($showtable['Row_format'] == 'Fixed') {
839 echo __('static');
840 } elseif ($showtable['Row_format'] == 'Dynamic') {
841 echo __('dynamic');
842 } else {
843 echo $showtable['Row_format'];
845 ?></td>
846 </tr>
847 <?php
849 if (! empty($showtable['Create_options'])) {
851 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
852 <th class="name"><?php echo __('Options'); ?></th>
853 <td class="value"><?php
854 if ($showtable['Create_options'] == 'partitioned') {
855 echo __('partitioned');
856 } else {
857 echo $showtable['Create_options'];
859 ?></td>
860 </tr>
861 <?php
863 if (!empty($tbl_collation)) {
865 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
866 <th class="name"><?php echo __('Collation'); ?></th>
867 <td class="value"><?php
868 echo '<dfn title="' . PMA_getCollationDescr($tbl_collation) . '">' . $tbl_collation . '</dfn>';
869 ?></td>
870 </tr>
871 <?php
873 if (!$is_innodb && isset($showtable['Rows'])) {
875 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
876 <th class="name"><?php echo __('Rows'); ?></th>
877 <td class="value"><?php echo PMA_formatNumber($showtable['Rows'], 0); ?></td>
878 </tr>
879 <?php
881 if (!$is_innodb && isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
883 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
884 <th class="name"><?php echo __('Row length'); ?> &oslash;</th>
885 <td class="value"><?php echo PMA_formatNumber($showtable['Avg_row_length'], 0); ?></td>
886 </tr>
887 <?php
889 if (!$is_innodb && isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
891 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
892 <th class="name"><?php echo __('Row size'); ?> &oslash;</th>
893 <td class="value"><?php echo $avg_size . ' ' . $avg_unit; ?></td>
894 </tr>
895 <?php
897 if (isset($showtable['Auto_increment'])) {
899 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
900 <th class="name"><?php echo __('Next autoindex'); ?></th>
901 <td class="value"><?php echo PMA_formatNumber($showtable['Auto_increment'], 0); ?></td>
902 </tr>
903 <?php
905 if (isset($showtable['Create_time'])) {
907 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
908 <th class="name"><?php echo __('Creation'); ?></th>
909 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Create_time'])); ?></td>
910 </tr>
911 <?php
913 if (isset($showtable['Update_time'])) {
915 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
916 <th class="name"><?php echo __('Last update'); ?></th>
917 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Update_time'])); ?></td>
918 </tr>
919 <?php
921 if (isset($showtable['Check_time'])) {
923 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
924 <th class="name"><?php echo __('Last check'); ?></th>
925 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Check_time'])); ?></td>
926 </tr>
927 <?php
930 </tbody>
931 </table>
933 <!-- close tablestatistics div -->
934 </div>
936 <?php
938 // END - Calc Table Space
940 echo '<div class="clearfloat"></div>' . "\n";
943 * Displays the footer
945 require './libraries/footer.inc.php';