Merge remote-tracking branch 'origin/master' into drizzle
[phpmyadmin.git] / tbl_structure.php
blob9170dcd4809781633fbc9b59d83b97882cbc1cdc
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 = (array) PMA_DBI_get_columns($db, $table, null, true);
128 // Get more complete field information
129 // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
130 // but later, if the analyser returns more information, it
131 // could be executed for any MySQL version and replace
132 // the info given by SHOW FULL COLUMNS FROM.
134 // We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
135 // SHOW FULL COLUMNS or INFORMATION_SCHEMA incorrectly says NULL
136 // and SHOW CREATE TABLE says NOT NULL (tested
137 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
139 $show_create_table = PMA_DBI_fetch_value(
140 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
141 0, 1);
142 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
145 * prepare table infos
147 // action titles (image or string)
148 $titles = array();
149 $titles['Change'] = PMA_getIcon('b_edit.png', __('Change'), true);
150 $titles['Drop'] = PMA_getIcon('b_drop.png', __('Drop'), true);
151 $titles['NoDrop'] = PMA_getIcon('b_drop.png', __('Drop'), true);
152 $titles['Primary'] = PMA_getIcon('b_primary.png', __('Primary'), true);
153 $titles['Index'] = PMA_getIcon('b_index.png', __('Index'), true);
154 $titles['Unique'] = PMA_getIcon('b_unique.png', __('Unique'), true);
155 $titles['Spatial'] = PMA_getIcon('b_spatial.png', __('Spatial'), 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['NoSpatial'] = PMA_getIcon('bd_spatial.png', __('Spatial'), true);
161 $titles['NoIdxFulltext'] = PMA_getIcon('bd_ftext.png', __('Fulltext'), true);
162 $titles['BrowseDistinctValues'] = PMA_getIcon('b_browse.png', __('Browse distinct values'), true);
164 // hidden action titles (image and string)
165 $hidden_titles = array();
166 $hidden_titles['BrowseDistinctValues'] = PMA_getIcon('b_browse.png', __('Browse distinct values'), false, true);
167 $hidden_titles['Primary'] = PMA_getIcon('b_primary.png', __('Add primary key'), false, true);
168 $hidden_titles['NoPrimary'] = PMA_getIcon('bd_primary.png', __('Add primary key'), false, true);
169 $hidden_titles['Index'] = PMA_getIcon('b_index.png', __('Add index'), false, true);
170 $hidden_titles['NoIndex'] = PMA_getIcon('bd_index.png', __('Add index'), false, true);
171 $hidden_titles['Unique'] = PMA_getIcon('b_unique.png', __('Add unique index'), false, true);
172 $hidden_titles['NoUnique'] = PMA_getIcon('bd_unique.png', __('Add unique index'), false, true);
173 $hidden_titles['Spatial'] = PMA_getIcon('b_spatial.png', __('Add SPATIAL index'), false, true);
174 $hidden_titles['NoSpatial'] = PMA_getIcon('bd_spatial.png', __('Add SPATIAL index'), false, true);
175 $hidden_titles['IdxFulltext'] = PMA_getIcon('b_ftext.png', __('Add FULLTEXT index'), false, true);
176 $hidden_titles['NoIdxFulltext'] = PMA_getIcon('bd_ftext.png', __('Add FULLTEXT index'), false, true);
179 * Displays the table structure ('show table' works correct since 3.23.03)
181 /* TABLE INFORMATION */
182 // table header
183 $i = 0;
185 <form method="post" action="tbl_structure.php" name="fieldsForm" id="fieldsForm" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : '');?>>
186 <?php echo PMA_generate_common_hidden_inputs($db, $table);
187 echo '<input type="hidden" name="table_type" value=';
188 if($db_is_information_schema) {
189 echo '"information_schema" />';
190 } else if ($tbl_is_view) {
191 echo '"view" />';
192 } else {
193 echo '"table" />';
194 } ?>
196 <table id="tablestructure" class="data">
197 <thead>
198 <tr>
199 <th id="th<?php echo ++$i; ?>"></th>
200 <th id="th<?php echo ++$i; ?>">#</th>
201 <th id="th<?php echo ++$i; ?>" class="column"><?php echo __('Name'); ?></th>
202 <th id="th<?php echo ++$i; ?>" class="type"><?php echo __('Type'); ?></th>
203 <th id="th<?php echo ++$i; ?>" class="collation"><?php echo __('Collation'); ?></th>
204 <th id="th<?php echo ++$i; ?>" class="attributes"><?php echo __('Attributes'); ?></th>
205 <th id="th<?php echo ++$i; ?>" class="null"><?php echo __('Null'); ?></th>
206 <th id="th<?php echo ++$i; ?>" class="default"><?php echo __('Default'); ?></th>
207 <th id="th<?php echo ++$i; ?>" class="extra"><?php echo __('Extra'); ?></th>
208 <?php if ($db_is_information_schema || $tbl_is_view) { ?>
209 <th id="th<?php echo ++$i; ?>" class="view"><?php echo __('View'); ?></th>
210 <?php } else { ?>
211 <th colspan="7" id="th<?php echo ++$i; ?>" class="action"><?php echo __('Action'); ?></th>
212 <?php } ?>
213 </tr>
214 </thead>
215 <tbody>
217 <?php
218 unset($i);
220 // table body
222 // prepare comments
223 $comments_map = array();
224 $mime_map = array();
226 if ($GLOBALS['cfg']['ShowPropertyComments']) {
227 require_once './libraries/transformations.lib.php';
229 //$cfgRelation = PMA_getRelationsParam();
231 $comments_map = PMA_getComments($db, $table);
233 if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) {
234 $mime_map = PMA_getMIME($db, $table, true);
238 $rownum = 0;
239 $aryFields = array();
240 $checked = (!empty($checkall) ? ' checked="checked"' : '');
241 $save_row = array();
242 $odd_row = true;
243 foreach ($fields as $row) {
244 $save_row[] = $row;
245 $rownum++;
246 $aryFields[] = $row['Field'];
248 $type = $row['Type'];
249 $extracted_fieldspec = PMA_extractFieldSpec($row['Type']);
251 if ('set' == $extracted_fieldspec['type'] || 'enum' == $extracted_fieldspec['type']) {
252 $type = $extracted_fieldspec['type'] . '(' .
253 str_replace("','", "', '", $extracted_fieldspec['spec_in_brackets']) . ')';
255 // for the case ENUM('&#8211;','&ldquo;')
256 $type = htmlspecialchars($type);
257 if(strlen($type) > $GLOBALS['cfg']['LimitChars']) {
258 $type = '<abbr title="' . $type . '">' . substr($type, 0, $GLOBALS['cfg']['LimitChars']) . '</abbr>';
261 $type_nowrap = '';
263 $binary = 0;
264 $unsigned = 0;
265 $zerofill = 0;
266 } else {
267 $type_nowrap = ' nowrap="nowrap"';
268 // strip the "BINARY" attribute, except if we find "BINARY(" because
269 // this would be a BINARY or VARBINARY field type
270 if (!preg_match('@BINARY[\(]@i', $type)) {
271 $type = preg_replace('@BINARY@i', '', $type);
273 $type = preg_replace('@ZEROFILL@i', '', $type);
274 $type = preg_replace('@UNSIGNED@i', '', $type);
275 if (empty($type)) {
276 $type = ' ';
279 if (!preg_match('@BINARY[\(]@i', $row['Type'])) {
280 $binary = stristr($row['Type'], 'blob') || stristr($row['Type'], 'binary');
281 } else {
282 $binary = false;
285 $unsigned = stristr($row['Type'], 'unsigned');
286 $zerofill = stristr($row['Type'], 'zerofill');
289 unset($field_charset);
290 if ((substr($type, 0, 4) == 'char'
291 || substr($type, 0, 7) == 'varchar'
292 || substr($type, 0, 4) == 'text'
293 || substr($type, 0, 8) == 'tinytext'
294 || substr($type, 0, 10) == 'mediumtext'
295 || substr($type, 0, 8) == 'longtext'
296 || substr($type, 0, 3) == 'set'
297 || substr($type, 0, 4) == 'enum'
298 ) && !$binary) {
299 if (strpos($type, ' character set ')) {
300 $type = substr($type, 0, strpos($type, ' character set '));
302 if (!empty($row['Collation'])) {
303 $field_charset = $row['Collation'];
304 } else {
305 $field_charset = '';
307 } else {
308 $field_charset = '';
311 // Display basic mimetype [MIME]
312 if ($cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME'] && isset($mime_map[$row['Field']]['mimetype'])) {
313 $type_mime = '<br />MIME: ' . str_replace('_', '/', $mime_map[$row['Field']]['mimetype']);
314 } else {
315 $type_mime = '';
318 $attribute = ' ';
319 if ($binary) {
320 $attribute = 'BINARY';
322 if ($unsigned) {
323 $attribute = 'UNSIGNED';
325 if ($zerofill) {
326 $attribute = 'UNSIGNED ZEROFILL';
329 // MySQL 4.1.2+ TIMESTAMP options
330 // (if on_update_current_timestamp is set, then it's TRUE)
331 if (isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])) {
332 $attribute = 'on update CURRENT_TIMESTAMP';
335 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
336 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
337 // the latter.
338 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']) {
339 $row['Null'] = '';
343 if (! isset($row['Default'])) {
344 if ($row['Null'] == 'YES') {
345 $row['Default'] = '<i>NULL</i>';
347 } else {
348 $row['Default'] = htmlspecialchars($row['Default']);
351 $field_encoded = urlencode($row['Field']);
352 $field_name = htmlspecialchars($row['Field']);
353 $displayed_field_name = $field_name;
355 // underline commented fields and display a hover-title (CSS only)
357 if (isset($comments_map[$row['Field']])) {
358 $displayed_field_name = '<span class="commented_column" title="' . htmlspecialchars($comments_map[$row['Field']]) . '">' . $field_name . '</span>';
361 if ($primary && $primary->hasColumn($field_name)) {
362 $displayed_field_name = '<u>' . $field_name . '</u>';
364 echo "\n";
366 <tr class="<?php echo $odd_row ? 'odd': 'even'; $odd_row = !$odd_row; ?>">
367 <td align="center">
368 <input type="checkbox" name="selected_fld[]" value="<?php echo htmlspecialchars($row['Field']); ?>" id="checkbox_row_<?php echo $rownum; ?>" <?php echo $checked; ?> />
369 </td>
370 <td align="right">
371 <?php echo $rownum; ?>
372 </td>
373 <th nowrap="nowrap"><label for="checkbox_row_<?php echo $rownum; ?>"><?php echo $displayed_field_name; ?></label></th>
374 <td<?php echo $type_nowrap; ?>><bdo dir="ltr" xml:lang="en"><?php echo $type; echo $type_mime; ?></bdo></td>
375 <td><?php echo (empty($field_charset) ? '' : '<dfn title="' . PMA_getCollationDescr($field_charset) . '">' . $field_charset . '</dfn>'); ?></td>
376 <td nowrap="nowrap" class="column_attribute"><?php echo $attribute; ?></td>
377 <td><?php echo (($row['Null'] == 'YES') ? __('Yes') : __('No')); ?></td>
378 <td nowrap="nowrap"><?php
379 if (isset($row['Default'])) {
380 if ($extracted_fieldspec['type'] == 'bit') {
381 // here, $row['Default'] contains something like b'010'
382 echo PMA_convert_bit_default_value($row['Default']);
383 } else {
384 echo $row['Default'];
387 else {
388 echo '<i>' . _pgettext('None for default','None') . '</i>';
389 } ?></td>
390 <td nowrap="nowrap"><?php echo strtoupper($row['Extra']); ?></td>
391 <td align="center" class="browse">
392 <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'])); ?>">
393 <?php echo $titles['BrowseDistinctValues']; ?></a>
394 </td>
395 <?php if (! $tbl_is_view && ! $db_is_information_schema) { ?>
396 <td align="center" class="edit">
397 <a href="tbl_alter.php?<?php echo $url_query; ?>&amp;field=<?php echo $field_encoded; ?>">
398 <?php echo $titles['Change']; ?></a>
399 </td>
400 <td align="center" class="drop">
401 <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']))); ?>" >
402 <?php echo $titles['Drop']; ?></a>
403 </td>
404 <td align="center" class="primary">
405 <?php
406 if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_type || ($primary && $primary->hasColumn($field_name))) {
407 echo $titles['NoPrimary'] . "\n";
408 $primary_enabled = false;
409 } else {
410 echo "\n";
412 <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']))); ?>" >
413 <?php echo $titles['Primary']; ?></a>
414 <?php $primary_enabled = true;
416 echo "\n";
418 </td>
419 <td align="center" class="unique">
420 <?php
421 if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_type || isset($columns_with_unique_index[$field_name])) {
422 echo $titles['NoUnique'] . "\n";
423 $unique_enabled = false;
424 } else {
425 echo "\n";
427 <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']))); ?>">
428 <?php echo $titles['Unique']; ?></a>
429 <?php $unique_enabled = true;
431 echo "\n";
433 </td>
434 <td align="center" class="index">
435 <?php
436 if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_type) {
437 echo $titles['NoIndex'] . "\n";
438 $index_enabled = false;
439 } else {
440 echo "\n";
442 <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']))); ?>">
443 <?php echo $titles['Index']; ?></a>
444 <?php
445 $index_enabled = true;
447 echo "\n";
449 </td>
450 <td align="center" class="spatial">
451 <?php
452 $spatial_types = array(
453 'geometry', 'point', 'linestring', 'polygon', 'multipoint',
454 'multilinestring', 'multipolygon', 'geomtrycollection'
456 if (! in_array($type, $spatial_types) || 'MYISAM' != $tbl_type) {
457 echo $titles['NoSpatial'] . "\n";
458 $spatial_enabled = false;
459 } else {
460 echo "\n";
462 <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']))); ?>">
463 <?php echo $titles['Spatial']; ?></a>
464 <?php
465 $spatial_enabled = true;
467 echo "\n";
469 </td>
470 <?php
471 if (! empty($tbl_type) && ($tbl_type == 'MYISAM' || $tbl_type == 'ARIA' || $tbl_type == 'MARIA')
472 // FULLTEXT is possible on TEXT, CHAR and VARCHAR
473 && (strpos(' ' . $type, 'text') || strpos(' ' . $type, 'char'))) {
474 echo "\n";
476 <td align="center" nowrap="nowrap" class="fulltext">
477 <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']))); ?>">
478 <?php echo $titles['IdxFulltext']; ?></a>
479 <?php $fulltext_enabled = true; ?>
480 </td>
481 <?php
482 } else {
483 echo "\n";
485 <td align="center" nowrap="nowrap" class="fulltext">
486 <?php echo $titles['NoIdxFulltext'] . "\n"; ?>
487 <?php $fulltext_enabled = false; ?>
488 </td>
489 <?php
490 } // end if... else...
491 echo "\n";
493 <td class="more_opts" id="more_opts<?php echo $rownum; ?>">
494 <?php echo __('More'); ?> <img src="<?php echo $pmaThemeImage . 'more.png'; ?>" alt="<?php echo __('Show more actions'); ?>" />
495 <div class="structure_actions_dropdown" id="row_<?php echo $rownum; ?>">
497 <div class="action_browse">
498 <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'])); ?>">
499 <?php echo $hidden_titles['BrowseDistinctValues']; ?>
500 </a>
501 </div>
502 <div <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="action_primary"' : ''); ?>>
503 <?php
504 if(isset($primary_enabled)) {
505 if($primary_enabled) { ?>
506 <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']))); ?>">
507 <?php echo $hidden_titles['Primary']; ?>
508 </a>
509 <?php
510 } else {
511 echo $hidden_titles['NoPrimary'];
513 } ?>
514 </div>
515 <div class="action_unique">
516 <?php
517 if(isset($unique_enabled)) {
518 if($unique_enabled) { ?>
519 <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']))); ?>">
520 <?php echo $hidden_titles['Unique']; ?>
521 </a>
522 <?php
523 } else {
524 echo $hidden_titles['NoUnique'];
526 } ?>
527 </div>
528 <div class="action_index">
529 <?php
530 if(isset($index_enabled)) {
531 if($index_enabled) { ?>
532 <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']))); ?>">
533 <?php echo $hidden_titles['Index']; ?>
534 </a>
535 <?php
536 } else {
537 echo $hidden_titles['NoIndex'];
539 } ?>
540 </div>
541 <?php if (!PMA_DRIZZLE) { ?>
542 <div class="action_spatial">
543 <?php
544 if(isset($spatial_enabled)) {
545 if($spatial_enabled) { ?>
546 <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']))); ?>">
547 <?php echo $hidden_titles['Spatial']; ?>
548 </a>
549 <?php
550 } else {
551 echo $hidden_titles['NoSpatial'];
553 } ?>
554 </div>
555 <div class="action_fulltext">
556 <?php
557 if(isset($fulltext_enabled)) {
558 if($fulltext_enabled) { ?>
559 <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']))); ?>">
560 <?php echo $hidden_titles['IdxFulltext']; ?>
561 </a>
562 <?php
563 } else {
564 echo $hidden_titles['NoIdxFulltext'];
566 } ?>
567 </div>
568 <?php } ?>
569 </div>
570 </td>
571 <?php
572 } // end if (! $tbl_is_view && ! $db_is_information_schema)
574 </tr>
575 <?php
576 unset($field_charset);
577 } // end while
579 echo '</tbody>' . "\n"
580 .'</table>' . "\n";
582 $checkall_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table);
585 <img class="selectallarrow" src="<?php echo $pmaThemeImage . 'arrow_' . $text_dir . '.png'; ?>"
586 width="38" height="22" alt="<?php echo __('With selected:'); ?>" />
587 <a href="<?php echo $checkall_url; ?>&amp;checkall=1"
588 onclick="if (markAllRows('fieldsForm')) return false;">
589 <?php echo __('Check All'); ?></a>
591 <a href="<?php echo $checkall_url; ?>"
592 onclick="if (unMarkAllRows('fieldsForm')) return false;">
593 <?php echo __('Uncheck All'); ?></a>
595 <i><?php echo __('With selected:'); ?></i>
597 <?php
598 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_browse', __('Browse'), 'b_browse.png', 'browse');
600 if (! $tbl_is_view && ! $db_is_information_schema) {
601 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_change', __('Change'), 'b_edit.png', 'change');
602 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_drop', __('Drop'), 'b_drop.png', 'drop');
603 if ('ARCHIVE' != $tbl_type) {
604 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_primary', __('Primary'), 'b_primary.png', 'primary');
605 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_unique', __('Unique'), 'b_unique.png', 'unique');
606 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_index', __('Index'), 'b_index.png', 'index');
609 if (! empty($tbl_type) && $tbl_type == 'MYISAM') {
610 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_spatial', __('Spatial'), 'b_spatial.png', 'spatial');
612 if (! empty($tbl_type) && ($tbl_type == 'MYISAM' || $tbl_type == 'ARIA' || $tbl_type == 'MARIA')) {
613 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_fulltext', __('Fulltext'), 'b_ftext.png', 'ftext');
617 </form>
618 <hr />
620 <?php
622 * Work on the table
625 <a href="tbl_printview.php?<?php echo $url_query; ?>"><?php
626 if ($cfg['PropertiesIconic']) {
627 echo '<img class="icon" src="' . $pmaThemeImage . 'b_print.png" width="16" height="16" alt="' . __('Print view') . '"/>';
629 echo __('Print view');
630 ?></a>
632 <?php
633 if (! $tbl_is_view && ! $db_is_information_schema) {
635 // if internal relations are available, or foreign keys are supported
636 // ($tbl_type comes from libraries/tbl_info.inc.php)
637 if ($cfgRelation['relwork'] || PMA_foreignkey_supported($tbl_type)) {
639 <a href="tbl_relation.php?<?php echo $url_query; ?>"><?php
640 if ($cfg['PropertiesIconic']) {
641 echo '<img class="icon" src="' . $pmaThemeImage . 'b_relations.png" width="16" height="16" alt="' . __('Relation view') . '"/>';
643 echo __('Relation view');
644 ?></a>
645 <?php
648 if (!PMA_DRIZZLE) {
650 <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
651 if ($cfg['PropertiesIconic']) {
652 echo '<img class="icon" src="' . $pmaThemeImage . 'b_tblanalyse.png" width="16" height="16" alt="' . __('Propose table structure') . '" />';
654 echo __('Propose table structure');
655 ?></a>
656 <?php
657 echo PMA_showMySQLDocu('Extending_MySQL', 'procedure_analyse') . "\n";
660 if(PMA_Tracker::isActive())
662 echo '<a href="tbl_tracking.php?' . $url_query . '">';
664 if ($cfg['PropertiesIconic'])
666 echo '<img class="icon" src="' . $pmaThemeImage . 'eye.png" width="16" height="16" alt="' . __('Track table') . '" /> ';
668 echo __('Track table') . '</a>';
672 <br />
673 <form method="post" action="tbl_addfield.php"
674 onsubmit="return checkFormElementInRange(this, 'num_fields', '<?php echo str_replace('\'', '\\\'', __('You have to add at least one column.')); ?>', 1)">
675 <?php
676 echo PMA_generate_common_hidden_inputs($db, $table);
677 if ($cfg['PropertiesIconic']) {
678 echo '<img class="icon" src="' . $pmaThemeImage . 'b_insrow.png" width="16" height="16" alt="' . __('Add column') . '"/>';
680 echo sprintf(__('Add %s column(s)'), '<input type="text" name="num_fields" size="2" maxlength="2" value="1" onfocus="this.select()" />');
682 // I tried displaying the drop-down inside the label but with Firefox
683 // the drop-down was blinking
684 $fieldOptions = '<select name="after_field" onclick="this.form.field_where[2].checked=true" onchange="this.form.field_where[2].checked=true">';
685 foreach ($aryFields as $fieldname) {
686 $fieldOptions .= '<option value="' . htmlspecialchars($fieldname) . '">' . htmlspecialchars($fieldname) . '</option>' . "\n";
688 unset($aryFields);
689 $fieldOptions .= '</select>';
691 $choices = array(
692 'last' => __('At End of Table'),
693 'first' => __('At Beginning of Table'),
694 'after' => sprintf(__('After %s'), '')
696 PMA_display_html_radio('field_where', $choices, 'last', false);
697 echo $fieldOptions;
698 unset($fieldOptions, $choices);
700 <input type="submit" value="<?php echo __('Go'); ?>" />
701 </form>
702 <iframe class="IE_hack" scrolling="no"></iframe>
703 <hr />
704 <div id="index_div" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?> >
705 <?php
709 * If there are more than 20 rows, displays browse/select/insert/empty/drop
710 * links again
712 if (count($fields) > 20) {
713 require './libraries/tbl_links.inc.php';
714 } // end if (count($fields) > 20)
717 * Displays indexes
720 if (! $tbl_is_view && ! $db_is_information_schema && 'ARCHIVE' != $tbl_type) {
722 * Display indexes
724 echo PMA_Index::getView($table, $db);
726 </div>
727 <form action="./tbl_indexes.php" method="post"
728 onsubmit="return checkFormElementInRange(this, 'added_fields',
729 '<?php echo str_replace('\'', '\\\'', __('Column count has to be larger than zero.')); ?>',
730 1)">
731 <fieldset>
732 <?php
733 echo PMA_generate_common_hidden_inputs($db, $table);
734 echo sprintf(__('Create an index on &nbsp;%s&nbsp;columns'),
735 '<input type="text" size="2" name="added_fields" value="1" />');
737 <input type="submit" name="create_index" value="<?php echo __('Go'); ?>" />
738 </fieldset>
739 </form>
740 <br />
741 <?php
745 * Displays Space usage and row statistics
747 // BEGIN - Calc Table Space
748 // Get valid statistics whatever is the table type
749 if ($cfg['ShowStats']) {
750 echo '<div id="tablestatistics">';
751 if (empty($showtable)) {
752 $showtable = PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], null, true);
755 $nonisam = false;
756 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
757 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
758 $nonisam = true;
761 // Gets some sizes
763 $mergetable = PMA_Table::isMerge($GLOBALS['db'], $GLOBALS['table']);
765 // this is to display for example 261.2 MiB instead of 268k KiB
766 $max_digits = 5;
767 $decimals = 1;
768 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length'], $max_digits, $decimals);
769 if ($mergetable == false) {
770 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length'], $max_digits, $decimals);
772 // InnoDB returns a huge value in Data_free, do not use it
773 if (! $is_innodb && isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
774 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free'], $max_digits, $decimals);
775 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free'], $max_digits, $decimals);
776 } else {
777 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
779 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
780 if ($table_info_num_rows > 0) {
781 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
784 // Displays them
785 $odd_row = false;
788 <a name="showusage"></a>
789 <?php if (! $tbl_is_view && ! $db_is_information_schema) { ?>
790 <table id="tablespaceusage" class="data">
791 <caption class="tblHeaders"><?php echo __('Space usage'); ?></caption>
792 <thead>
793 <tr>
794 <th><?php echo __('Type'); ?></th>
795 <th colspan="2"><?php echo __('Usage'); ?></th>
796 </tr>
797 </thead>
798 <tbody>
799 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
800 <th class="name"><?php echo __('Data'); ?></th>
801 <td class="value"><?php echo $data_size; ?></td>
802 <td class="unit"><?php echo $data_unit; ?></td>
803 </tr>
804 <?php
805 if (isset($index_size)) {
807 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
808 <th class="name"><?php echo __('Index'); ?></th>
809 <td class="value"><?php echo $index_size; ?></td>
810 <td class="unit"><?php echo $index_unit; ?></td>
811 </tr>
812 <?php
814 if (isset($free_size)) {
816 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?> error">
817 <th class="name"><?php echo __('Overhead'); ?></th>
818 <td class="value"><?php echo $free_size; ?></td>
819 <td class="unit"><?php echo $free_unit; ?></td>
820 </tr>
821 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
822 <th class="name"><?php echo __('Effective'); ?></th>
823 <td class="value"><?php echo $effect_size; ?></td>
824 <td class="unit"><?php echo $effect_unit; ?></td>
825 </tr>
826 <?php
828 if (isset($tot_size) && $mergetable == false) {
830 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
831 <th class="name"><?php echo __('Total'); ?></th>
832 <td class="value"><?php echo $tot_size; ?></td>
833 <td class="unit"><?php echo $tot_unit; ?></td>
834 </tr>
835 <?php
837 // Optimize link if overhead
838 if (isset($free_size) && !PMA_DRIZZLE && ($tbl_type == 'MYISAM' || $tbl_type == 'ARIA' || $tbl_type == 'MARIA' || $tbl_type == 'BDB')) {
840 <tr class="tblFooters">
841 <td colspan="3" align="center">
842 <a href="sql.php?<?php echo $url_query; ?>&pos=0&amp;sql_query=<?php echo urlencode('OPTIMIZE TABLE ' . PMA_backquote($table)); ?>"><?php
843 if ($cfg['PropertiesIconic']) {
844 echo '<img class="icon" src="' . $pmaThemeImage . 'b_tbloptimize.png" width="16" height="16" alt="' . __('Optimize table'). '" />';
846 echo __('Optimize table');
847 ?></a>
848 </td>
849 </tr>
850 <?php
853 </tbody>
854 </table>
855 <?php
857 $odd_row = false;
859 <table id="tablerowstats" class="data">
860 <caption class="tblHeaders"><?php echo __('Row Statistics'); ?></caption>
861 <thead>
862 <tr>
863 <th><?php echo __('Statements'); ?></th>
864 <th><?php echo __('Value'); ?></th>
865 </tr>
866 </thead>
867 <tbody>
868 <?php
869 if (isset($showtable['Row_format'])) {
871 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
872 <th class="name"><?php echo __('Format'); ?></th>
873 <td class="value"><?php
874 if ($showtable['Row_format'] == 'Fixed') {
875 echo __('static');
876 } elseif ($showtable['Row_format'] == 'Dynamic') {
877 echo __('dynamic');
878 } else {
879 echo $showtable['Row_format'];
881 ?></td>
882 </tr>
883 <?php
885 if (! empty($showtable['Create_options'])) {
887 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
888 <th class="name"><?php echo __('Options'); ?></th>
889 <td class="value"><?php
890 if ($showtable['Create_options'] == 'partitioned') {
891 echo __('partitioned');
892 } else {
893 echo $showtable['Create_options'];
895 ?></td>
896 </tr>
897 <?php
899 if (!empty($tbl_collation)) {
901 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
902 <th class="name"><?php echo __('Collation'); ?></th>
903 <td class="value"><?php
904 echo '<dfn title="' . PMA_getCollationDescr($tbl_collation) . '">' . $tbl_collation . '</dfn>';
905 ?></td>
906 </tr>
907 <?php
909 if (!$is_innodb && isset($showtable['Rows'])) {
911 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
912 <th class="name"><?php echo __('Rows'); ?></th>
913 <td class="value"><?php echo PMA_formatNumber($showtable['Rows'], 0); ?></td>
914 </tr>
915 <?php
917 if (!$is_innodb && isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
919 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
920 <th class="name"><?php echo __('Row length'); ?> &oslash;</th>
921 <td class="value"><?php echo PMA_formatNumber($showtable['Avg_row_length'], 0); ?></td>
922 </tr>
923 <?php
925 if (!$is_innodb && isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
927 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
928 <th class="name"><?php echo __(' Row size '); ?> &oslash;</th>
929 <td class="value"><?php echo $avg_size . ' ' . $avg_unit; ?></td>
930 </tr>
931 <?php
933 if (isset($showtable['Auto_increment'])) {
935 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
936 <th class="name"><?php echo __('Next'); ?> Autoindex</th>
937 <td class="value"><?php echo PMA_formatNumber($showtable['Auto_increment'], 0); ?></td>
938 </tr>
939 <?php
941 if (isset($showtable['Create_time'])) {
943 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
944 <th class="name"><?php echo __('Creation'); ?></th>
945 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Create_time'])); ?></td>
946 </tr>
947 <?php
949 if (isset($showtable['Update_time'])) {
951 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
952 <th class="name"><?php echo __('Last update'); ?></th>
953 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Update_time'])); ?></td>
954 </tr>
955 <?php
957 if (isset($showtable['Check_time'])) {
959 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
960 <th class="name"><?php echo __('Last check'); ?></th>
961 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Check_time'])); ?></td>
962 </tr>
963 <?php
966 </tbody>
967 </table>
969 <!-- close tablestatistics div -->
970 </div>
972 <?php
974 // END - Calc Table Space
976 echo '<div class="clearfloat"></div>' . "\n";
979 * Displays the footer
981 require './libraries/footer.inc.php';