Remove deprecated function PMA_DBI_get_fields
[phpmyadmin/thilankatest.git] / tbl_structure.php
blob9878b9e2636eaf27844afd34961d60c2b1c0e9ac
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";
470 <td class="more_opts" id="more_opts<?php echo $rownum; ?>">
471 <?php echo __('More'); ?> <img src="<?php echo $pmaThemeImage . 'more.png'; ?>" alt="<?php echo __('Show more actions'); ?>" />
472 <div class="structure_actions_dropdown" id="row_<?php echo $rownum; ?>">
474 <div class="action_browse">
475 <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'])); ?>">
476 <?php echo $hidden_titles['BrowseDistinctValues']; ?>
477 </a>
478 </div>
479 <div <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="action_primary"' : ''); ?>>
480 <?php
481 if(isset($primary_enabled)) {
482 if($primary_enabled) { ?>
483 <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']))); ?>">
484 <?php echo $hidden_titles['Primary']; ?>
485 </a>
486 <?php
487 } else {
488 echo $hidden_titles['NoPrimary'];
490 } ?>
491 </div>
492 <div class="action_unique">
493 <?php
494 if(isset($unique_enabled)) {
495 if($unique_enabled) { ?>
496 <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']))); ?>">
497 <?php echo $hidden_titles['Unique']; ?>
498 </a>
499 <?php
500 } else {
501 echo $hidden_titles['NoUnique'];
503 } ?>
504 </div>
505 <div class="action_index">
506 <?php
507 if(isset($index_enabled)) {
508 if($index_enabled) { ?>
509 <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']))); ?>">
510 <?php echo $hidden_titles['Index']; ?>
511 </a>
512 <?php
513 } else {
514 echo $hidden_titles['NoIndex'];
516 } ?>
517 </div>
518 <div class="action_fulltext">
519 <?php
520 if(isset($fulltext_enabled)) {
521 if($fulltext_enabled) { ?>
522 <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']))); ?>">
523 <?php echo $hidden_titles['IdxFulltext']; ?>
524 </a>
525 <?php
526 } else {
527 echo $hidden_titles['NoIdxFulltext'];
529 } ?>
530 </div>
531 </div>
532 </td>
533 <?php
534 } // end if (! $tbl_is_view && ! $db_is_information_schema)
536 </tr>
537 <?php
538 unset($field_charset);
539 } // end while
541 echo '</tbody>' . "\n"
542 .'</table>' . "\n";
544 $checkall_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table);
547 <img class="selectallarrow" src="<?php echo $pmaThemeImage . 'arrow_' . $text_dir . '.png'; ?>"
548 width="38" height="22" alt="<?php echo __('With selected:'); ?>" />
549 <a href="<?php echo $checkall_url; ?>&amp;checkall=1"
550 onclick="if (markAllRows('fieldsForm')) return false;">
551 <?php echo __('Check All'); ?></a>
553 <a href="<?php echo $checkall_url; ?>"
554 onclick="if (unMarkAllRows('fieldsForm')) return false;">
555 <?php echo __('Uncheck All'); ?></a>
557 <i><?php echo __('With selected:'); ?></i>
559 <?php
560 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_browse', __('Browse'), 'b_browse.png', 'browse');
562 if (! $tbl_is_view && ! $db_is_information_schema) {
563 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_change', __('Change'), 'b_edit.png', 'change');
564 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_drop', __('Drop'), 'b_drop.png', 'drop');
565 if ('ARCHIVE' != $tbl_type) {
566 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_primary', __('Primary'), 'b_primary.png', 'primary');
567 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_unique', __('Unique'), 'b_unique.png', 'unique');
568 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_index', __('Index'), 'b_index.png', 'index');
571 if (! empty($tbl_type) && ($tbl_type == 'MYISAM' || $tbl_type == 'ARIA' || $tbl_type == 'MARIA')) {
572 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_fulltext', __('Fulltext'), 'b_ftext.png', 'ftext');
576 </form>
577 <hr />
579 <?php
581 * Work on the table
584 <a href="tbl_printview.php?<?php echo $url_query; ?>"><?php
585 if ($cfg['PropertiesIconic']) {
586 echo '<img class="icon" src="' . $pmaThemeImage . 'b_print.png" width="16" height="16" alt="' . __('Print view') . '"/>';
588 echo __('Print view');
589 ?></a>
591 <?php
592 if (! $tbl_is_view && ! $db_is_information_schema) {
594 // if internal relations are available, or foreign keys are supported
595 // ($tbl_type comes from libraries/tbl_info.inc.php)
596 if ($cfgRelation['relwork'] || PMA_foreignkey_supported($tbl_type)) {
598 <a href="tbl_relation.php?<?php echo $url_query; ?>"><?php
599 if ($cfg['PropertiesIconic']) {
600 echo '<img class="icon" src="' . $pmaThemeImage . 'b_relations.png" width="16" height="16" alt="' . __('Relation view') . '"/>';
602 echo __('Relation view');
603 ?></a>
604 <?php
607 <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
608 if ($cfg['PropertiesIconic']) {
609 echo '<img class="icon" src="' . $pmaThemeImage . 'b_tblanalyse.png" width="16" height="16" alt="' . __('Propose table structure') . '" />';
611 echo __('Propose table structure');
612 ?></a><?php
613 echo PMA_showMySQLDocu('Extending_MySQL', 'procedure_analyse') . "\n";
616 if(PMA_Tracker::isActive())
618 echo '<a href="tbl_tracking.php?' . $url_query . '">';
620 if ($cfg['PropertiesIconic'])
622 echo '<img class="icon" src="' . $pmaThemeImage . 'eye.png" width="16" height="16" alt="' . __('Track table') . '" /> ';
624 echo __('Track table') . '</a>';
628 <br />
629 <form method="post" action="tbl_addfield.php"
630 onsubmit="return checkFormElementInRange(this, 'num_fields', '<?php echo str_replace('\'', '\\\'', __('You have to add at least one column.')); ?>', 1)">
631 <?php
632 echo PMA_generate_common_hidden_inputs($db, $table);
633 if ($cfg['PropertiesIconic']) {
634 echo '<img class="icon" src="' . $pmaThemeImage . 'b_insrow.png" width="16" height="16" alt="' . __('Add column') . '"/>';
636 echo sprintf(__('Add %s column(s)'), '<input type="text" name="num_fields" size="2" maxlength="2" value="1" onfocus="this.select()" />');
638 // I tried displaying the drop-down inside the label but with Firefox
639 // the drop-down was blinking
640 $fieldOptions = '<select name="after_field" onclick="this.form.field_where[2].checked=true" onchange="this.form.field_where[2].checked=true">';
641 foreach ($aryFields as $fieldname) {
642 $fieldOptions .= '<option value="' . htmlspecialchars($fieldname) . '">' . htmlspecialchars($fieldname) . '</option>' . "\n";
644 unset($aryFields);
645 $fieldOptions .= '</select>';
647 $choices = array(
648 'last' => __('At End of Table'),
649 'first' => __('At Beginning of Table'),
650 'after' => sprintf(__('After %s'), '')
652 PMA_display_html_radio('field_where', $choices, 'last', false);
653 echo $fieldOptions;
654 unset($fieldOptions, $choices);
656 <input type="submit" value="<?php echo __('Go'); ?>" />
657 </form>
658 <iframe class="IE_hack" scrolling="no"></iframe>
659 <hr />
660 <?php
664 * If there are more than 20 rows, displays browse/select/insert/empty/drop
665 * links again
667 if ($fields_cnt > 20) {
668 require './libraries/tbl_links.inc.php';
669 } // end if ($fields_cnt > 20)
672 * Displays indexes
675 if (! $tbl_is_view && ! $db_is_information_schema && 'ARCHIVE' != $tbl_type) {
677 * Display indexes
679 echo PMA_Index::getView($table, $db);
681 <br />
682 <form action="./tbl_indexes.php" method="post"
683 onsubmit="return checkFormElementInRange(this, 'idx_num_fields',
684 '<?php echo str_replace('\'', '\\\'', __('Column count has to be larger than zero.')); ?>',
685 1)">
686 <fieldset>
687 <?php
688 echo PMA_generate_common_hidden_inputs($db, $table);
689 echo sprintf(__('Create an index on &nbsp;%s&nbsp;columns'),
690 '<input type="text" size="2" name="added_fields" value="1" />');
692 <input type="submit" name="create_index" value="<?php echo __('Go'); ?>"
693 onclick="return checkFormElementInRange(this.form,
694 'idx_num_fields',
695 '<?php echo str_replace('\'', '\\\'', __('Column count has to be larger than zero.')); ?>',
696 1)" />
697 </fieldset>
698 </form>
699 <br />
700 <?php
703 PMA_generate_slider_effect('tablestatistics', __('Details...'));
706 * Displays Space usage and row statistics
708 // BEGIN - Calc Table Space
709 // Get valid statistics whatever is the table type
710 if ($cfg['ShowStats']) {
711 if (empty($showtable)) {
712 $showtable = PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], null, true);
715 $nonisam = false;
716 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
717 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
718 $nonisam = true;
721 // Gets some sizes
723 $mergetable = PMA_Table::isMerge($GLOBALS['db'], $GLOBALS['table']);
725 // this is to display for example 261.2 MiB instead of 268k KiB
726 $max_digits = 5;
727 $decimals = 1;
728 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length'], $max_digits, $decimals);
729 if ($mergetable == false) {
730 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length'], $max_digits, $decimals);
732 // InnoDB returns a huge value in Data_free, do not use it
733 if (! $is_innodb && isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
734 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free'], $max_digits, $decimals);
735 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free'], $max_digits, $decimals);
736 } else {
737 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
739 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
740 if ($table_info_num_rows > 0) {
741 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
744 // Displays them
745 $odd_row = false;
748 <a name="showusage"></a>
749 <?php if (! $tbl_is_view && ! $db_is_information_schema) { ?>
750 <table id="tablespaceusage" class="data">
751 <caption class="tblHeaders"><?php echo __('Space usage'); ?></caption>
752 <thead>
753 <tr>
754 <th><?php echo __('Type'); ?></th>
755 <th colspan="2"><?php echo __('Usage'); ?></th>
756 </tr>
757 </thead>
758 <tbody>
759 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
760 <th class="name"><?php echo __('Data'); ?></th>
761 <td class="value"><?php echo $data_size; ?></td>
762 <td class="unit"><?php echo $data_unit; ?></td>
763 </tr>
764 <?php
765 if (isset($index_size)) {
767 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
768 <th class="name"><?php echo __('Index'); ?></th>
769 <td class="value"><?php echo $index_size; ?></td>
770 <td class="unit"><?php echo $index_unit; ?></td>
771 </tr>
772 <?php
774 if (isset($free_size)) {
776 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?> error">
777 <th class="name"><?php echo __('Overhead'); ?></th>
778 <td class="value"><?php echo $free_size; ?></td>
779 <td class="unit"><?php echo $free_unit; ?></td>
780 </tr>
781 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
782 <th class="name"><?php echo __('Effective'); ?></th>
783 <td class="value"><?php echo $effect_size; ?></td>
784 <td class="unit"><?php echo $effect_unit; ?></td>
785 </tr>
786 <?php
788 if (isset($tot_size) && $mergetable == false) {
790 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
791 <th class="name"><?php echo __('Total'); ?></th>
792 <td class="value"><?php echo $tot_size; ?></td>
793 <td class="unit"><?php echo $tot_unit; ?></td>
794 </tr>
795 <?php
797 // Optimize link if overhead
798 if (isset($free_size) && ($tbl_type == 'MYISAM' || $tbl_type == 'ARIA' || $tbl_type == 'MARIA' || $tbl_type == 'BDB')) {
800 <tr class="tblFooters">
801 <td colspan="3" align="center">
802 <a href="sql.php?<?php echo $url_query; ?>&pos=0&amp;sql_query=<?php echo urlencode('OPTIMIZE TABLE ' . PMA_backquote($table)); ?>"><?php
803 if ($cfg['PropertiesIconic']) {
804 echo '<img class="icon" src="' . $pmaThemeImage . 'b_tbloptimize.png" width="16" height="16" alt="' . __('Optimize table'). '" />';
806 echo __('Optimize table');
807 ?></a>
808 </td>
809 </tr>
810 <?php
813 </tbody>
814 </table>
815 <?php
817 $odd_row = false;
819 <table id="tablerowstats" class="data">
820 <caption class="tblHeaders"><?php echo __('Row Statistics'); ?></caption>
821 <thead>
822 <tr>
823 <th><?php echo __('Statements'); ?></th>
824 <th><?php echo __('Value'); ?></th>
825 </tr>
826 </thead>
827 <tbody>
828 <?php
829 if (isset($showtable['Row_format'])) {
831 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
832 <th class="name"><?php echo __('Format'); ?></th>
833 <td class="value"><?php
834 if ($showtable['Row_format'] == 'Fixed') {
835 echo __('static');
836 } elseif ($showtable['Row_format'] == 'Dynamic') {
837 echo __('dynamic');
838 } else {
839 echo $showtable['Row_format'];
841 ?></td>
842 </tr>
843 <?php
845 if (! empty($showtable['Create_options'])) {
847 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
848 <th class="name"><?php echo __('Options'); ?></th>
849 <td class="value"><?php
850 if ($showtable['Create_options'] == 'partitioned') {
851 echo __('partitioned');
852 } else {
853 echo $showtable['Create_options'];
855 ?></td>
856 </tr>
857 <?php
859 if (!empty($tbl_collation)) {
861 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
862 <th class="name"><?php echo __('Collation'); ?></th>
863 <td class="value"><?php
864 echo '<dfn title="' . PMA_getCollationDescr($tbl_collation) . '">' . $tbl_collation . '</dfn>';
865 ?></td>
866 </tr>
867 <?php
869 if (!$is_innodb && isset($showtable['Rows'])) {
871 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
872 <th class="name"><?php echo __('Rows'); ?></th>
873 <td class="value"><?php echo PMA_formatNumber($showtable['Rows'], 0); ?></td>
874 </tr>
875 <?php
877 if (!$is_innodb && isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
879 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
880 <th class="name"><?php echo __('Row length'); ?> &oslash;</th>
881 <td class="value"><?php echo PMA_formatNumber($showtable['Avg_row_length'], 0); ?></td>
882 </tr>
883 <?php
885 if (!$is_innodb && isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
887 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
888 <th class="name"><?php echo __(' Row size '); ?> &oslash;</th>
889 <td class="value"><?php echo $avg_size . ' ' . $avg_unit; ?></td>
890 </tr>
891 <?php
893 if (isset($showtable['Auto_increment'])) {
895 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
896 <th class="name"><?php echo __('Next'); ?> Autoindex</th>
897 <td class="value"><?php echo PMA_formatNumber($showtable['Auto_increment'], 0); ?></td>
898 </tr>
899 <?php
901 if (isset($showtable['Create_time'])) {
903 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
904 <th class="name"><?php echo __('Creation'); ?></th>
905 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Create_time'])); ?></td>
906 </tr>
907 <?php
909 if (isset($showtable['Update_time'])) {
911 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
912 <th class="name"><?php echo __('Last update'); ?></th>
913 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Update_time'])); ?></td>
914 </tr>
915 <?php
917 if (isset($showtable['Check_time'])) {
919 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
920 <th class="name"><?php echo __('Last check'); ?></th>
921 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Check_time'])); ?></td>
922 </tr>
923 <?php
926 </tbody>
927 </table>
929 <!-- close slider div -->
930 </div>
932 <?php
934 // END - Calc Table Space
936 require './libraries/tbl_triggers.lib.php';
938 echo '<div class="clearfloat"></div>' . "\n";
941 * Displays the footer
943 require './libraries/footer.inc.php';