Move common code into a function
[phpmyadmin/ammaryasirr.git] / tbl_structure.php
blob73374d7a5e9b555f280ba713178a147360f6d3ac
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 if ('set' == $extracted_fieldspec['type'] || 'enum' == $extracted_fieldspec['type']) {
249 $type = $extracted_fieldspec['type'] . '(' .
250 str_replace("','", "', '", $extracted_fieldspec['spec_in_brackets']) . ')';
252 // for the case ENUM('&#8211;','&ldquo;')
253 $type = htmlspecialchars($type);
254 if(strlen($type) > $GLOBALS['cfg']['LimitChars']) {
255 $type = '<abbr title="full text">' . substr($type, 0, $GLOBALS['cfg']['LimitChars']) . '</abbr>';
258 $type_nowrap = '';
260 $binary = 0;
261 $unsigned = 0;
262 $zerofill = 0;
263 } else {
264 $type_nowrap = ' nowrap="nowrap"';
265 // strip the "BINARY" attribute, except if we find "BINARY(" because
266 // this would be a BINARY or VARBINARY field type
267 if (!preg_match('@BINARY[\(]@i', $type)) {
268 $type = preg_replace('@BINARY@i', '', $type);
270 $type = preg_replace('@ZEROFILL@i', '', $type);
271 $type = preg_replace('@UNSIGNED@i', '', $type);
272 if (empty($type)) {
273 $type = ' ';
276 if (!preg_match('@BINARY[\(]@i', $row['Type'])) {
277 $binary = stristr($row['Type'], 'blob') || stristr($row['Type'], 'binary');
278 } else {
279 $binary = false;
282 $unsigned = stristr($row['Type'], 'unsigned');
283 $zerofill = stristr($row['Type'], 'zerofill');
286 unset($field_charset);
287 if ((substr($type, 0, 4) == 'char'
288 || substr($type, 0, 7) == 'varchar'
289 || substr($type, 0, 4) == 'text'
290 || substr($type, 0, 8) == 'tinytext'
291 || substr($type, 0, 10) == 'mediumtext'
292 || substr($type, 0, 8) == 'longtext'
293 || substr($type, 0, 3) == 'set'
294 || substr($type, 0, 4) == 'enum'
295 ) && !$binary) {
296 if (strpos($type, ' character set ')) {
297 $type = substr($type, 0, strpos($type, ' character set '));
299 if (!empty($row['Collation'])) {
300 $field_charset = $row['Collation'];
301 } else {
302 $field_charset = '';
304 } else {
305 $field_charset = '';
308 // Display basic mimetype [MIME]
309 if ($cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME'] && isset($mime_map[$row['Field']]['mimetype'])) {
310 $type_mime = '<br />MIME: ' . str_replace('_', '/', $mime_map[$row['Field']]['mimetype']);
311 } else {
312 $type_mime = '';
315 $attribute = ' ';
316 if ($binary) {
317 $attribute = 'BINARY';
319 if ($unsigned) {
320 $attribute = 'UNSIGNED';
322 if ($zerofill) {
323 $attribute = 'UNSIGNED ZEROFILL';
326 // MySQL 4.1.2+ TIMESTAMP options
327 // (if on_update_current_timestamp is set, then it's TRUE)
328 if (isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])) {
329 $attribute = 'on update CURRENT_TIMESTAMP';
332 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
333 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
334 // the latter.
335 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']) {
336 $row['Null'] = '';
340 if (!isset($row['Default'])) {
341 if ($row['Null'] == 'YES') {
342 $row['Default'] = '<i>NULL</i>';
344 } else {
345 $row['Default'] = htmlspecialchars($row['Default']);
348 $field_encoded = urlencode($row['Field']);
349 $field_name = htmlspecialchars($row['Field']);
350 $displayed_field_name = $field_name;
352 // underline commented fields and display a hover-title (CSS only)
354 if (isset($comments_map[$row['Field']])) {
355 $displayed_field_name = '<span class="commented_column" title="' . htmlspecialchars($comments_map[$row['Field']]) . '">' . $field_name . '</span>';
358 if ($primary && $primary->hasColumn($field_name)) {
359 $displayed_field_name = '<u>' . $field_name . '</u>';
361 echo "\n";
363 <tr class="<?php echo $odd_row ? 'odd': 'even'; $odd_row = !$odd_row; ?>">
364 <td align="center">
365 <input type="checkbox" name="selected_fld[]" value="<?php echo htmlspecialchars($row['Field']); ?>" id="checkbox_row_<?php echo $rownum; ?>" <?php echo $checked; ?> />
366 </td>
367 <td align="right">
368 <?php echo $rownum; ?>
369 </td>
370 <th nowrap="nowrap"><label for="checkbox_row_<?php echo $rownum; ?>"><?php echo $displayed_field_name; ?></label></th>
371 <td<?php echo $type_nowrap; ?>><bdo dir="ltr" xml:lang="en"><?php echo $type; echo $type_mime; ?></bdo></td>
372 <td><?php echo (empty($field_charset) ? '' : '<dfn title="' . PMA_getCollationDescr($field_charset) . '">' . $field_charset . '</dfn>'); ?></td>
373 <td nowrap="nowrap" class="column_attribute"><?php echo $attribute; ?></td>
374 <td><?php echo (($row['Null'] == 'YES') ? __('Yes') : __('No')); ?></td>
375 <td nowrap="nowrap"><?php
376 if (isset($row['Default'])) {
377 if ($extracted_fieldspec['type'] == 'bit') {
378 // here, $row['Default'] contains something like b'010'
379 echo PMA_convert_bit_default_value($row['Default']);
380 } else {
381 echo $row['Default'];
384 else {
385 echo '<i>' . _pgettext('None for default','None') . '</i>';
386 } ?></td>
387 <td nowrap="nowrap"><?php echo strtoupper($row['Extra']); ?></td>
388 <td align="center" class="browse">
389 <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'])); ?>">
390 <?php echo $titles['BrowseDistinctValues']; ?></a>
391 </td>
392 <?php if (! $tbl_is_view && ! $db_is_information_schema) { ?>
393 <td align="center" class="edit">
394 <a href="tbl_alter.php?<?php echo $url_query; ?>&amp;field=<?php echo $field_encoded; ?>">
395 <?php echo $titles['Change']; ?></a>
396 </td>
397 <td align="center" class="drop">
398 <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']))); ?>" >
399 <?php echo $titles['Drop']; ?></a>
400 </td>
401 <td align="center" class="primary">
402 <?php
403 if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_type || ($primary && $primary->hasColumn($field_name))) {
404 echo $titles['NoPrimary'] . "\n";
405 $primary_enabled = false;
406 } else {
407 echo "\n";
409 <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']))); ?>" >
410 <?php echo $titles['Primary']; ?></a>
411 <?php $primary_enabled = true;
413 echo "\n";
415 </td>
416 <td align="center" class="unique">
417 <?php
418 if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_type || isset($columns_with_unique_index[$field_name])) {
419 echo $titles['NoUnique'] . "\n";
420 $unique_enabled = false;
421 } else {
422 echo "\n";
424 <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']))); ?>">
425 <?php echo $titles['Unique']; ?></a>
426 <?php $unique_enabled = true;
428 echo "\n";
430 </td>
431 <td align="center" class="index">
432 <?php
433 if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_type) {
434 echo $titles['NoIndex'] . "\n";
435 $index_enabled = false;
436 } else {
437 echo "\n";
439 <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']))); ?>">
440 <?php echo $titles['Index']; ?></a>
441 <?php
442 $index_enabled = true;
444 echo "\n";
446 </td>
447 <?php
448 if (! empty($tbl_type) && ($tbl_type == 'MYISAM' || $tbl_type == 'ARIA' || $tbl_type == 'MARIA')
449 // FULLTEXT is possible on TEXT, CHAR and VARCHAR
450 && (strpos(' ' . $type, 'text') || strpos(' ' . $type, 'char'))) {
451 echo "\n";
453 <td align="center" nowrap="nowrap" class="fulltext">
454 <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']))); ?>">
455 <?php echo $titles['IdxFulltext']; ?></a>
456 <?php $fulltext_enabled = true; ?>
457 </td>
458 <?php
459 } else {
460 echo "\n";
462 <td align="center" nowrap="nowrap" class="fulltext">
463 <?php echo $titles['NoIdxFulltext'] . "\n"; ?>
464 <?php $fulltext_enabled = false; ?>
465 </td>
466 <?php
467 } // end if... else...
468 echo "\n";
469 } // end if (! $tbl_is_view && ! $db_is_information_schema)
471 <td class="more_opts" id="more_opts<?php echo $rownum; ?>">
472 <?php echo __('More'); ?> <img src="<?php echo $pmaThemeImage . 'more.png'; ?>" alt="<?php echo __('Show more actions'); ?>" />
473 <div class="structure_actions_dropdown" id="row_<?php echo $rownum; ?>">
475 <div class="action_browse">
476 <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'])); ?>">
477 <?php echo $hidden_titles['BrowseDistinctValues']; ?>
478 </a>
479 </div>
480 <div <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="action_primary"' : ''); ?>>
481 <?php
482 if(isset($primary_enabled)) {
483 if($primary_enabled) { ?>
484 <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']))); ?>">
485 <?php echo $hidden_titles['Primary']; ?>
486 </a>
487 <?php
488 } else {
489 echo $hidden_titles['NoPrimary'];
491 } ?>
492 </div>
493 <div class="action_unique">
494 <?php
495 if(isset($unique_enabled)) {
496 if($unique_enabled) { ?>
497 <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']))); ?>">
498 <?php echo $hidden_titles['Unique']; ?>
499 </a>
500 <?php
501 } else {
502 echo $hidden_titles['NoUnique'];
504 } ?>
505 </div>
506 <div class="action_index">
507 <?php
508 if(isset($index_enabled)) {
509 if($index_enabled) { ?>
510 <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']))); ?>">
511 <?php echo $hidden_titles['Index']; ?>
512 </a>
513 <?php
514 } else {
515 echo $hidden_titles['NoIndex'];
517 } ?>
518 </div>
519 <div class="action_fulltext">
520 <?php
521 if(isset($fulltext_enabled)) {
522 if($fulltext_enabled) { ?>
523 <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']))); ?>">
524 <?php echo $hidden_titles['IdxFulltext']; ?>
525 </a>
526 <?php
527 } else {
528 echo $hidden_titles['NoIdxFulltext'];
530 } ?>
531 </div>
532 </div>
533 </td>
534 </tr>
535 <?php
536 unset($field_charset);
537 } // end while
539 echo '</tbody>' . "\n"
540 .'</table>' . "\n";
542 $checkall_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table);
545 <img class="selectallarrow" src="<?php echo $pmaThemeImage . 'arrow_' . $text_dir . '.png'; ?>"
546 width="38" height="22" alt="<?php echo __('With selected:'); ?>" />
547 <a href="<?php echo $checkall_url; ?>&amp;checkall=1"
548 onclick="if (markAllRows('fieldsForm')) return false;">
549 <?php echo __('Check All'); ?></a>
551 <a href="<?php echo $checkall_url; ?>"
552 onclick="if (unMarkAllRows('fieldsForm')) return false;">
553 <?php echo __('Uncheck All'); ?></a>
555 <i><?php echo __('With selected:'); ?></i>
557 <?php
558 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_browse', __('Browse'), 'b_browse.png', 'browse');
560 if (! $tbl_is_view && ! $db_is_information_schema) {
561 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_change', __('Change'), 'b_edit.png', 'change');
562 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_drop', __('Drop'), 'b_drop.png', 'drop');
563 if ('ARCHIVE' != $tbl_type) {
564 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_primary', __('Primary'), 'b_primary.png', 'primary');
565 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_unique', __('Unique'), 'b_unique.png', 'unique');
566 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_index', __('Index'), 'b_index.png', 'index');
569 if (! empty($tbl_type) && ($tbl_type == 'MYISAM' || $tbl_type == 'ARIA' || $tbl_type == 'MARIA')) {
570 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_fulltext', __('Fulltext'), 'b_ftext.png', 'ftext');
574 </form>
575 <hr />
577 <?php
579 * Work on the table
582 <a href="tbl_printview.php?<?php echo $url_query; ?>"><?php
583 if ($cfg['PropertiesIconic']) {
584 echo '<img class="icon" src="' . $pmaThemeImage . 'b_print.png" width="16" height="16" alt="' . __('Print view') . '"/>';
586 echo __('Print view');
587 ?></a>
589 <?php
590 if (! $tbl_is_view && ! $db_is_information_schema) {
592 // if internal relations are available, or foreign keys are supported
593 // ($tbl_type comes from libraries/tbl_info.inc.php)
594 if ($cfgRelation['relwork'] || PMA_foreignkey_supported($tbl_type)) {
596 <a href="tbl_relation.php?<?php echo $url_query; ?>"><?php
597 if ($cfg['PropertiesIconic']) {
598 echo '<img class="icon" src="' . $pmaThemeImage . 'b_relations.png" width="16" height="16" alt="' . __('Relation view') . '"/>';
600 echo __('Relation view');
601 ?></a>
602 <?php
605 <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
606 if ($cfg['PropertiesIconic']) {
607 echo '<img class="icon" src="' . $pmaThemeImage . 'b_tblanalyse.png" width="16" height="16" alt="' . __('Propose table structure') . '" />';
609 echo __('Propose table structure');
610 ?></a><?php
611 echo PMA_showMySQLDocu('Extending_MySQL', 'procedure_analyse') . "\n";
614 if(PMA_Tracker::isActive())
616 echo '<a href="tbl_tracking.php?' . $url_query . '">';
618 if ($cfg['PropertiesIconic'])
620 echo '<img class="icon" src="' . $pmaThemeImage . 'eye.png" width="16" height="16" alt="' . __('Track table') . '" /> ';
622 echo __('Track table') . '</a>';
626 <br />
627 <form method="post" action="tbl_addfield.php"
628 onsubmit="return checkFormElementInRange(this, 'num_fields', '<?php echo str_replace('\'', '\\\'', __('You have to add at least one column.')); ?>', 1)">
629 <?php
630 echo PMA_generate_common_hidden_inputs($db, $table);
631 if ($cfg['PropertiesIconic']) {
632 echo '<img class="icon" src="' . $pmaThemeImage . 'b_insrow.png" width="16" height="16" alt="' . __('Add column') . '"/>';
634 echo sprintf(__('Add %s column(s)'), '<input type="text" name="num_fields" size="2" maxlength="2" value="1" onfocus="this.select()" />');
636 // I tried displaying the drop-down inside the label but with Firefox
637 // the drop-down was blinking
638 $fieldOptions = '<select name="after_field" onclick="this.form.field_where[2].checked=true" onchange="this.form.field_where[2].checked=true">';
639 foreach ($aryFields as $fieldname) {
640 $fieldOptions .= '<option value="' . htmlspecialchars($fieldname) . '">' . htmlspecialchars($fieldname) . '</option>' . "\n";
642 unset($aryFields);
643 $fieldOptions .= '</select>';
645 $choices = array(
646 'last' => __('At End of Table'),
647 'first' => __('At Beginning of Table'),
648 'after' => sprintf(__('After %s'), '')
650 PMA_display_html_radio('field_where', $choices, 'last', false);
651 echo $fieldOptions;
652 unset($fieldOptions, $choices);
654 <input type="submit" value="<?php echo __('Go'); ?>" />
655 </form>
656 <iframe class="IE_hack" scrolling="no"></iframe>
657 <hr />
658 <?php
662 * If there are more than 20 rows, displays browse/select/insert/empty/drop
663 * links again
665 if ($fields_cnt > 20) {
666 require './libraries/tbl_links.inc.php';
667 } // end if ($fields_cnt > 20)
670 * Displays indexes
673 if (! $tbl_is_view && ! $db_is_information_schema && 'ARCHIVE' != $tbl_type) {
675 * Display indexes
677 echo PMA_Index::getView($table, $db);
679 <br />
680 <form action="./tbl_indexes.php" method="post"
681 onsubmit="return checkFormElementInRange(this, 'idx_num_fields',
682 '<?php echo str_replace('\'', '\\\'', __('Column count has to be larger than zero.')); ?>',
683 1)">
684 <fieldset>
685 <?php
686 echo PMA_generate_common_hidden_inputs($db, $table);
687 echo sprintf(__('Create an index on &nbsp;%s&nbsp;columns'),
688 '<input type="text" size="2" name="added_fields" value="1" />');
690 <input type="submit" name="create_index" value="<?php echo __('Go'); ?>"
691 onclick="return checkFormElementInRange(this.form,
692 'idx_num_fields',
693 '<?php echo str_replace('\'', '\\\'', __('Column count has to be larger than zero.')); ?>',
694 1)" />
695 </fieldset>
696 </form>
697 <br />
698 <?php
701 PMA_generate_slider_effect('tablestatistics', __('Details...'));
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 if (empty($showtable)) {
710 $showtable = PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], null, true);
713 $nonisam = false;
714 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
715 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
716 $nonisam = true;
719 // Gets some sizes
721 $mergetable = PMA_Table::isMerge($GLOBALS['db'], $GLOBALS['table']);
723 // this is to display for example 261.2 MiB instead of 268k KiB
724 $max_digits = 5;
725 $decimals = 1;
726 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length'], $max_digits, $decimals);
727 if ($mergetable == false) {
728 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length'], $max_digits, $decimals);
730 // InnoDB returns a huge value in Data_free, do not use it
731 if (! $is_innodb && isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
732 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free'], $max_digits, $decimals);
733 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free'], $max_digits, $decimals);
734 } else {
735 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
737 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
738 if ($table_info_num_rows > 0) {
739 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
742 // Displays them
743 $odd_row = false;
746 <a name="showusage"></a>
747 <?php if (! $tbl_is_view && ! $db_is_information_schema) { ?>
748 <table id="tablespaceusage" class="data">
749 <caption class="tblHeaders"><?php echo __('Space usage'); ?></caption>
750 <thead>
751 <tr>
752 <th><?php echo __('Type'); ?></th>
753 <th colspan="2"><?php echo __('Usage'); ?></th>
754 </tr>
755 </thead>
756 <tbody>
757 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
758 <th class="name"><?php echo __('Data'); ?></th>
759 <td class="value"><?php echo $data_size; ?></td>
760 <td class="unit"><?php echo $data_unit; ?></td>
761 </tr>
762 <?php
763 if (isset($index_size)) {
765 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
766 <th class="name"><?php echo __('Index'); ?></th>
767 <td class="value"><?php echo $index_size; ?></td>
768 <td class="unit"><?php echo $index_unit; ?></td>
769 </tr>
770 <?php
772 if (isset($free_size)) {
774 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?> warning">
775 <th class="name"><?php echo __('Overhead'); ?></th>
776 <td class="value"><?php echo $free_size; ?></td>
777 <td class="unit"><?php echo $free_unit; ?></td>
778 </tr>
779 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
780 <th class="name"><?php echo __('Effective'); ?></th>
781 <td class="value"><?php echo $effect_size; ?></td>
782 <td class="unit"><?php echo $effect_unit; ?></td>
783 </tr>
784 <?php
786 if (isset($tot_size) && $mergetable == false) {
788 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
789 <th class="name"><?php echo __('Total'); ?></th>
790 <td class="value"><?php echo $tot_size; ?></td>
791 <td class="unit"><?php echo $tot_unit; ?></td>
792 </tr>
793 <?php
795 // Optimize link if overhead
796 if (isset($free_size) && ($tbl_type == 'MYISAM' || $tbl_type == 'ARIA' || $tbl_type == 'MARIA' || $tbl_type == 'BDB')) {
798 <tr class="tblFooters">
799 <td colspan="3" align="center">
800 <a href="sql.php?<?php echo $url_query; ?>&pos=0&amp;sql_query=<?php echo urlencode('OPTIMIZE TABLE ' . PMA_backquote($table)); ?>"><?php
801 if ($cfg['PropertiesIconic']) {
802 echo '<img class="icon" src="' . $pmaThemeImage . 'b_tbloptimize.png" width="16" height="16" alt="' . __('Optimize table'). '" />';
804 echo __('Optimize table');
805 ?></a>
806 </td>
807 </tr>
808 <?php
811 </tbody>
812 </table>
813 <?php
815 $odd_row = false;
817 <table id="tablerowstats" class="data">
818 <caption class="tblHeaders"><?php echo __('Row Statistics'); ?></caption>
819 <thead>
820 <tr>
821 <th><?php echo __('Statements'); ?></th>
822 <th><?php echo __('Value'); ?></th>
823 </tr>
824 </thead>
825 <tbody>
826 <?php
827 if (isset($showtable['Row_format'])) {
829 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
830 <th class="name"><?php echo __('Format'); ?></th>
831 <td class="value"><?php
832 if ($showtable['Row_format'] == 'Fixed') {
833 echo __('static');
834 } elseif ($showtable['Row_format'] == 'Dynamic') {
835 echo __('dynamic');
836 } else {
837 echo $showtable['Row_format'];
839 ?></td>
840 </tr>
841 <?php
843 if (! empty($showtable['Create_options'])) {
845 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
846 <th class="name"><?php echo __('Options'); ?></th>
847 <td class="value"><?php
848 if ($showtable['Create_options'] == 'partitioned') {
849 echo __('partitioned');
850 } else {
851 echo $showtable['Create_options'];
853 ?></td>
854 </tr>
855 <?php
857 if (!empty($tbl_collation)) {
859 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
860 <th class="name"><?php echo __('Collation'); ?></th>
861 <td class="value"><?php
862 echo '<dfn title="' . PMA_getCollationDescr($tbl_collation) . '">' . $tbl_collation . '</dfn>';
863 ?></td>
864 </tr>
865 <?php
867 if (!$is_innodb && isset($showtable['Rows'])) {
869 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
870 <th class="name"><?php echo __('Rows'); ?></th>
871 <td class="value"><?php echo PMA_formatNumber($showtable['Rows'], 0); ?></td>
872 </tr>
873 <?php
875 if (!$is_innodb && isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
877 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
878 <th class="name"><?php echo __('Row length'); ?> &oslash;</th>
879 <td class="value"><?php echo PMA_formatNumber($showtable['Avg_row_length'], 0); ?></td>
880 </tr>
881 <?php
883 if (!$is_innodb && isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
885 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
886 <th class="name"><?php echo __(' Row size '); ?> &oslash;</th>
887 <td class="value"><?php echo $avg_size . ' ' . $avg_unit; ?></td>
888 </tr>
889 <?php
891 if (isset($showtable['Auto_increment'])) {
893 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
894 <th class="name"><?php echo __('Next'); ?> Autoindex</th>
895 <td class="value"><?php echo PMA_formatNumber($showtable['Auto_increment'], 0); ?></td>
896 </tr>
897 <?php
899 if (isset($showtable['Create_time'])) {
901 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
902 <th class="name"><?php echo __('Creation'); ?></th>
903 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Create_time'])); ?></td>
904 </tr>
905 <?php
907 if (isset($showtable['Update_time'])) {
909 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
910 <th class="name"><?php echo __('Last update'); ?></th>
911 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Update_time'])); ?></td>
912 </tr>
913 <?php
915 if (isset($showtable['Check_time'])) {
917 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
918 <th class="name"><?php echo __('Last check'); ?></th>
919 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Check_time'])); ?></td>
920 </tr>
921 <?php
924 </tbody>
925 </table>
927 <!-- close slider div -->
928 </div>
930 <?php
932 // END - Calc Table Space
934 require './libraries/tbl_triggers.lib.php';
936 echo '<div class="clearfloat"></div>' . "\n";
939 * Displays the footer
941 require './libraries/footer.inc.php';