Translation update done using Pootle.
[phpmyadmin/ammaryasirr.git] / tbl_structure.php
bloba4e969231124c07a19fb264c6fc4b483203b86d2
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_rs = PMA_DRIZZLE
127 ? PMA_DBI_query('SHOW COLUMNS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE)
128 : PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
129 $fields_cnt = PMA_DBI_num_rows($fields_rs);
131 // Get more complete field information
132 // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
133 // but later, if the analyser returns more information, it
134 // could be executed for any MySQL version and replace
135 // the info given by SHOW FULL FIELDS FROM.
137 // We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
138 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
139 // and SHOW CREATE TABLE says NOT NULL (tested
140 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
142 $show_create_table = PMA_DBI_fetch_value(
143 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
144 0, 1);
145 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
148 * prepare table infos
150 // action titles (image or string)
151 $titles = array();
152 $titles['Change'] = PMA_getIcon('b_edit.png', __('Change'), true);
153 $titles['Drop'] = PMA_getIcon('b_drop.png', __('Drop'), true);
154 $titles['NoDrop'] = PMA_getIcon('b_drop.png', __('Drop'), true);
155 $titles['Primary'] = PMA_getIcon('b_primary.png', __('Primary'), true);
156 $titles['Index'] = PMA_getIcon('b_index.png', __('Index'), true);
157 $titles['Unique'] = PMA_getIcon('b_unique.png', __('Unique'), true);
158 $titles['Spatial'] = PMA_getIcon('b_spatial.png', __('Spatial'), true);
159 $titles['IdxFulltext'] = PMA_getIcon('b_ftext.png', __('Fulltext'), true);
160 $titles['NoPrimary'] = PMA_getIcon('bd_primary.png', __('Primary'), true);
161 $titles['NoIndex'] = PMA_getIcon('bd_index.png', __('Index'), true);
162 $titles['NoUnique'] = PMA_getIcon('bd_unique.png', __('Unique'), true);
163 $titles['NoSpatial'] = PMA_getIcon('bd_spatial.png', __('Spatial'), true);
164 $titles['NoIdxFulltext'] = PMA_getIcon('bd_ftext.png', __('Fulltext'), true);
165 $titles['BrowseDistinctValues'] = PMA_getIcon('b_browse.png', __('Browse distinct values'), true);
167 // hidden action titles (image and string)
168 $hidden_titles = array();
169 $hidden_titles['BrowseDistinctValues'] = PMA_getIcon('b_browse.png', __('Browse distinct values'), false, true);
170 $hidden_titles['Primary'] = PMA_getIcon('b_primary.png', __('Add primary key'), false, true);
171 $hidden_titles['NoPrimary'] = PMA_getIcon('bd_primary.png', __('Add primary key'), false, true);
172 $hidden_titles['Index'] = PMA_getIcon('b_index.png', __('Add index'), false, true);
173 $hidden_titles['NoIndex'] = PMA_getIcon('bd_index.png', __('Add index'), false, true);
174 $hidden_titles['Unique'] = PMA_getIcon('b_unique.png', __('Add unique index'), false, true);
175 $hidden_titles['NoUnique'] = PMA_getIcon('bd_unique.png', __('Add unique index'), false, true);
176 $hidden_titles['Spatial'] = PMA_getIcon('b_spatial.png', __('Add SPATIAL index'), false, true);
177 $hidden_titles['NoSpatial'] = PMA_getIcon('bd_spatial.png', __('Add SPATIAL index'), false, true);
178 $hidden_titles['IdxFulltext'] = PMA_getIcon('b_ftext.png', __('Add FULLTEXT index'), false, true);
179 $hidden_titles['NoIdxFulltext'] = PMA_getIcon('bd_ftext.png', __('Add FULLTEXT index'), false, true);
182 * Displays the table structure ('show table' works correct since 3.23.03)
184 /* TABLE INFORMATION */
185 // table header
186 $i = 0;
188 <form method="post" action="tbl_structure.php" name="fieldsForm" id="fieldsForm" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : '');?>>
189 <?php echo PMA_generate_common_hidden_inputs($db, $table);
190 echo '<input type="hidden" name="table_type" value=';
191 if ($db_is_information_schema) {
192 echo '"information_schema" />';
193 } else if ($tbl_is_view) {
194 echo '"view" />';
195 } else {
196 echo '"table" />';
197 } ?>
199 <table id="tablestructure" class="data">
200 <thead>
201 <tr>
202 <th id="th<?php echo ++$i; ?>"></th>
203 <th id="th<?php echo ++$i; ?>">#</th>
204 <th id="th<?php echo ++$i; ?>" class="column"><?php echo __('Name'); ?></th>
205 <th id="th<?php echo ++$i; ?>" class="type"><?php echo __('Type'); ?></th>
206 <th id="th<?php echo ++$i; ?>" class="collation"><?php echo __('Collation'); ?></th>
207 <th id="th<?php echo ++$i; ?>" class="attributes"><?php echo __('Attributes'); ?></th>
208 <th id="th<?php echo ++$i; ?>" class="null"><?php echo __('Null'); ?></th>
209 <th id="th<?php echo ++$i; ?>" class="default"><?php echo __('Default'); ?></th>
210 <th id="th<?php echo ++$i; ?>" class="extra"><?php echo __('Extra'); ?></th>
211 <?php if ($db_is_information_schema || $tbl_is_view) { ?>
212 <th id="th<?php echo ++$i; ?>" class="view"><?php echo __('View'); ?></th>
213 <?php } else { ?>
214 <th colspan="7" id="th<?php echo ++$i; ?>" class="action"><?php echo __('Action'); ?></th>
215 <?php } ?>
216 </tr>
217 </thead>
218 <tbody>
220 <?php
221 unset($i);
223 // table body
225 // prepare comments
226 $comments_map = array();
227 $mime_map = array();
229 if ($GLOBALS['cfg']['ShowPropertyComments']) {
230 require_once './libraries/transformations.lib.php';
232 //$cfgRelation = PMA_getRelationsParam();
234 $comments_map = PMA_getComments($db, $table);
236 if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) {
237 $mime_map = PMA_getMIME($db, $table, true);
241 $rownum = 0;
242 $aryFields = array();
243 $checked = (!empty($checkall) ? ' checked="checked"' : '');
244 $save_row = array();
245 $odd_row = true;
246 while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
247 $save_row[] = $row;
248 $rownum++;
249 $aryFields[] = $row['Field'];
251 $type = $row['Type'];
252 $extracted_fieldspec = PMA_extractFieldSpec($row['Type']);
254 if ('set' == $extracted_fieldspec['type'] || 'enum' == $extracted_fieldspec['type']) {
255 $type = $extracted_fieldspec['type'] . '(' .
256 str_replace("','", "', '", $extracted_fieldspec['spec_in_brackets']) . ')';
258 // for the case ENUM('&#8211;','&ldquo;')
259 $type = htmlspecialchars($type);
260 if (strlen($type) > $GLOBALS['cfg']['LimitChars']) {
261 $type = '<abbr title="' . $type . '">' . substr($type, 0, $GLOBALS['cfg']['LimitChars']) . '</abbr>';
264 $type_nowrap = '';
266 $binary = 0;
267 $unsigned = 0;
268 $zerofill = 0;
269 } else {
270 $type_nowrap = ' nowrap="nowrap"';
271 // strip the "BINARY" attribute, except if we find "BINARY(" because
272 // this would be a BINARY or VARBINARY field type
273 if (!preg_match('@BINARY[\(]@i', $type)) {
274 $type = preg_replace('@BINARY@i', '', $type);
276 $type = preg_replace('@ZEROFILL@i', '', $type);
277 $type = preg_replace('@UNSIGNED@i', '', $type);
278 if (empty($type)) {
279 $type = ' ';
282 if (!preg_match('@BINARY[\(]@i', $row['Type'])) {
283 $binary = stristr($row['Type'], 'blob') || stristr($row['Type'], 'binary');
284 } else {
285 $binary = false;
288 $unsigned = stristr($row['Type'], 'unsigned');
289 $zerofill = stristr($row['Type'], 'zerofill');
292 unset($field_charset);
293 if ((substr($type, 0, 4) == 'char'
294 || substr($type, 0, 7) == 'varchar'
295 || substr($type, 0, 4) == 'text'
296 || substr($type, 0, 8) == 'tinytext'
297 || substr($type, 0, 10) == 'mediumtext'
298 || substr($type, 0, 8) == 'longtext'
299 || substr($type, 0, 3) == 'set'
300 || substr($type, 0, 4) == 'enum'
301 ) && !$binary) {
302 if (strpos($type, ' character set ')) {
303 $type = substr($type, 0, strpos($type, ' character set '));
305 if (!empty($row['Collation'])) {
306 $field_charset = $row['Collation'];
307 } else {
308 $field_charset = '';
310 } else {
311 $field_charset = '';
314 // Display basic mimetype [MIME]
315 if ($cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME'] && isset($mime_map[$row['Field']]['mimetype'])) {
316 $type_mime = '<br />MIME: ' . str_replace('_', '/', $mime_map[$row['Field']]['mimetype']);
317 } else {
318 $type_mime = '';
321 $attribute = ' ';
322 if ($binary) {
323 $attribute = 'BINARY';
325 if ($unsigned) {
326 $attribute = 'UNSIGNED';
328 if ($zerofill) {
329 $attribute = 'UNSIGNED ZEROFILL';
332 // MySQL 4.1.2+ TIMESTAMP options
333 // (if on_update_current_timestamp is set, then it's TRUE)
334 if (isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])) {
335 $attribute = 'on update CURRENT_TIMESTAMP';
338 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
339 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
340 // the latter.
341 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']) {
342 $row['Null'] = '';
346 if (! isset($row['Default'])) {
347 if ($row['Null'] == 'YES') {
348 $row['Default'] = '<i>NULL</i>';
350 } else {
351 $row['Default'] = htmlspecialchars($row['Default']);
354 $field_encoded = urlencode($row['Field']);
355 $field_name = htmlspecialchars($row['Field']);
356 $displayed_field_name = $field_name;
358 // underline commented fields and display a hover-title (CSS only)
360 if (isset($comments_map[$row['Field']])) {
361 $displayed_field_name = '<span class="commented_column" title="' . htmlspecialchars($comments_map[$row['Field']]) . '">' . $field_name . '</span>';
364 if ($primary && $primary->hasColumn($field_name)) {
365 $displayed_field_name = '<u>' . $field_name . '</u>';
367 echo "\n";
369 <tr class="<?php echo $odd_row ? 'odd': 'even'; $odd_row = !$odd_row; ?>">
370 <td align="center">
371 <input type="checkbox" name="selected_fld[]" value="<?php echo htmlspecialchars($row['Field']); ?>" id="checkbox_row_<?php echo $rownum; ?>" <?php echo $checked; ?> />
372 </td>
373 <td align="right">
374 <?php echo $rownum; ?>
375 </td>
376 <th nowrap="nowrap"><label for="checkbox_row_<?php echo $rownum; ?>"><?php echo $displayed_field_name; ?></label></th>
377 <td<?php echo $type_nowrap; ?>><bdo dir="ltr" xml:lang="en"><?php echo $type; echo $type_mime; ?></bdo></td>
378 <td><?php echo (empty($field_charset) ? '' : '<dfn title="' . PMA_getCollationDescr($field_charset) . '">' . $field_charset . '</dfn>'); ?></td>
379 <td nowrap="nowrap" class="column_attribute"><?php echo $attribute; ?></td>
380 <td><?php echo (($row['Null'] == 'YES') ? __('Yes') : __('No')); ?></td>
381 <td nowrap="nowrap"><?php
382 if (isset($row['Default'])) {
383 if ($extracted_fieldspec['type'] == 'bit') {
384 // here, $row['Default'] contains something like b'010'
385 echo PMA_convert_bit_default_value($row['Default']);
386 } else {
387 echo $row['Default'];
390 else {
391 echo '<i>' . _pgettext('None for default','None') . '</i>';
392 } ?></td>
393 <td nowrap="nowrap"><?php echo strtoupper($row['Extra']); ?></td>
394 <td align="center" class="browse">
395 <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'])); ?>">
396 <?php echo $titles['BrowseDistinctValues']; ?></a>
397 </td>
398 <?php if (! $tbl_is_view && ! $db_is_information_schema) { ?>
399 <td align="center" class="edit">
400 <a href="tbl_alter.php?<?php echo $url_query; ?>&amp;field=<?php echo $field_encoded; ?>">
401 <?php echo $titles['Change']; ?></a>
402 </td>
403 <td align="center" class="drop">
404 <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']))); ?>" >
405 <?php echo $titles['Drop']; ?></a>
406 </td>
407 <td align="center" class="primary">
408 <?php
409 if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_type || ($primary && $primary->hasColumn($field_name))) {
410 echo $titles['NoPrimary'] . "\n";
411 $primary_enabled = false;
412 } else {
413 echo "\n";
415 <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']))); ?>" >
416 <?php echo $titles['Primary']; ?></a>
417 <?php $primary_enabled = true;
419 echo "\n";
421 </td>
422 <td align="center" class="unique">
423 <?php
424 if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_type || isset($columns_with_unique_index[$field_name])) {
425 echo $titles['NoUnique'] . "\n";
426 $unique_enabled = false;
427 } else {
428 echo "\n";
430 <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']))); ?>">
431 <?php echo $titles['Unique']; ?></a>
432 <?php $unique_enabled = true;
434 echo "\n";
436 </td>
437 <td align="center" class="index">
438 <?php
439 if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_type) {
440 echo $titles['NoIndex'] . "\n";
441 $index_enabled = false;
442 } else {
443 echo "\n";
445 <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']))); ?>">
446 <?php echo $titles['Index']; ?></a>
447 <?php
448 $index_enabled = true;
450 echo "\n";
452 </td>
453 <td align="center" class="spatial">
454 <?php
455 $spatial_types = array(
456 'geometry', 'point', 'linestring', 'polygon', 'multipoint',
457 'multilinestring', 'multipolygon', 'geomtrycollection'
459 if (! in_array($type, $spatial_types) || 'MYISAM' != $tbl_type) {
460 echo $titles['NoSpatial'] . "\n";
461 $spatial_enabled = false;
462 } else {
463 echo "\n";
465 <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']))); ?>">
466 <?php echo $titles['Spatial']; ?></a>
467 <?php
468 $spatial_enabled = true;
470 echo "\n";
472 </td>
473 <?php
474 if (! empty($tbl_type) && ($tbl_type == 'MYISAM' || $tbl_type == 'ARIA' || $tbl_type == 'MARIA')
475 // FULLTEXT is possible on TEXT, CHAR and VARCHAR
476 && (strpos(' ' . $type, 'text') || strpos(' ' . $type, 'char'))) {
477 echo "\n";
479 <td align="center" nowrap="nowrap" class="fulltext">
480 <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']))); ?>">
481 <?php echo $titles['IdxFulltext']; ?></a>
482 <?php $fulltext_enabled = true; ?>
483 </td>
484 <?php
485 } else {
486 echo "\n";
488 <td align="center" nowrap="nowrap" class="fulltext">
489 <?php echo $titles['NoIdxFulltext'] . "\n"; ?>
490 <?php $fulltext_enabled = false; ?>
491 </td>
492 <?php
493 } // end if... else...
494 echo "\n";
496 <td class="more_opts" id="more_opts<?php echo $rownum; ?>">
497 <?php echo __('More'); ?> <img class="icon ic_more" src="themes/dot.gif" alt="<?php echo __('Show more actions'); ?>" />
498 <div class="structure_actions_dropdown" id="row_<?php echo $rownum; ?>">
500 <div class="action_browse">
501 <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'])); ?>">
502 <?php echo $hidden_titles['BrowseDistinctValues']; ?>
503 </a>
504 </div>
505 <div <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="action_primary"' : ''); ?>>
506 <?php
507 if (isset($primary_enabled)) {
508 if ($primary_enabled) { ?>
509 <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']))); ?>">
510 <?php echo $hidden_titles['Primary']; ?>
511 </a>
512 <?php
513 } else {
514 echo $hidden_titles['NoPrimary'];
516 } ?>
517 </div>
518 <div class="action_unique">
519 <?php
520 if (isset($unique_enabled)) {
521 if ($unique_enabled) { ?>
522 <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']))); ?>">
523 <?php echo $hidden_titles['Unique']; ?>
524 </a>
525 <?php
526 } else {
527 echo $hidden_titles['NoUnique'];
529 } ?>
530 </div>
531 <div class="action_index">
532 <?php
533 if (isset($index_enabled)) {
534 if ($index_enabled) { ?>
535 <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']))); ?>">
536 <?php echo $hidden_titles['Index']; ?>
537 </a>
538 <?php
539 } else {
540 echo $hidden_titles['NoIndex'];
542 } ?>
543 </div>
544 <div class="action_spatial">
545 <?php
546 if (isset($spatial_enabled)) {
547 if ($spatial_enabled) { ?>
548 <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']))); ?>">
549 <?php echo $hidden_titles['Spatial']; ?>
550 </a>
551 <?php
552 } else {
553 echo $hidden_titles['NoSpatial'];
555 } ?>
556 </div>
557 <div class="action_fulltext">
558 <?php
559 if (isset($fulltext_enabled)) {
560 if ($fulltext_enabled) { ?>
561 <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']))); ?>">
562 <?php echo $hidden_titles['IdxFulltext']; ?>
563 </a>
564 <?php
565 } else {
566 echo $hidden_titles['NoIdxFulltext'];
568 } ?>
569 </div>
570 </div>
571 </td>
572 <?php
573 } // end if (! $tbl_is_view && ! $db_is_information_schema)
575 </tr>
576 <?php
577 unset($field_charset);
578 } // end while
580 echo '</tbody>' . "\n"
581 .'</table>' . "\n";
583 $checkall_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table);
586 <img class="selectallarrow" src="<?php echo $pmaThemeImage . 'arrow_' . $text_dir . '.png'; ?>"
587 width="38" height="22" alt="<?php echo __('With selected:'); ?>" />
588 <a href="<?php echo $checkall_url; ?>&amp;checkall=1"
589 onclick="if (markAllRows('fieldsForm')) return false;">
590 <?php echo __('Check All'); ?></a>
592 <a href="<?php echo $checkall_url; ?>"
593 onclick="if (unMarkAllRows('fieldsForm')) return false;">
594 <?php echo __('Uncheck All'); ?></a>
596 <i><?php echo __('With selected:'); ?></i>
598 <?php
599 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_browse', __('Browse'), 'b_browse.png', 'browse');
601 if (! $tbl_is_view && ! $db_is_information_schema) {
602 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_change', __('Change'), 'b_edit.png', 'change');
603 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_drop', __('Drop'), 'b_drop.png', 'drop');
604 if ('ARCHIVE' != $tbl_type) {
605 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_primary', __('Primary'), 'b_primary.png', 'primary');
606 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_unique', __('Unique'), 'b_unique.png', 'unique');
607 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_index', __('Index'), 'b_index.png', 'index');
610 if (! empty($tbl_type) && $tbl_type == 'MYISAM') {
611 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_spatial', __('Spatial'), 'b_spatial.png', 'spatial');
613 if (! empty($tbl_type) && ($tbl_type == 'MYISAM' || $tbl_type == 'ARIA' || $tbl_type == 'MARIA')) {
614 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_fulltext', __('Fulltext'), 'b_ftext.png', 'ftext');
618 </form>
619 <hr />
621 <?php
623 * Work on the table
626 <a href="tbl_printview.php?<?php echo $url_query; ?>"><?php
627 if ($cfg['PropertiesIconic']) {
628 echo '<img class="icon ic_b_print" src="themes/dot.gif" alt="' . __('Print view') . '"/>';
630 echo __('Print view');
631 ?></a>
633 <?php
634 if (! $tbl_is_view && ! $db_is_information_schema) {
636 // if internal relations are available, or foreign keys are supported
637 // ($tbl_type comes from libraries/tbl_info.inc.php)
638 if ($cfgRelation['relwork'] || PMA_foreignkey_supported($tbl_type)) {
640 <a href="tbl_relation.php?<?php echo $url_query; ?>"><?php
641 if ($cfg['PropertiesIconic']) {
642 echo '<img class="icon ic_b_relations" src="themes/dot.gif" alt="' . __('Relation view') . '"/>';
644 echo __('Relation view');
645 ?></a>
646 <?php
649 <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
650 if ($cfg['PropertiesIconic']) {
651 echo '<img class="icon ic_b_tblanalyse" src="themes/dot.gif" alt="' . __('Propose table structure') . '" />';
653 echo __('Propose table structure');
654 ?></a><?php
655 echo PMA_showMySQLDocu('Extending_MySQL', 'procedure_analyse') . "\n";
658 if (PMA_Tracker::isActive())
660 echo '<a href="tbl_tracking.php?' . $url_query . '">';
662 if ($cfg['PropertiesIconic'])
664 echo '<img class="icon ic_eye" src="themes/dot.gif" alt="' . __('Track table') . '" /> ';
666 echo __('Track table') . '</a>';
670 <br />
671 <form method="post" action="tbl_addfield.php" id="addColumns" name="addColumns" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : '');?>
672 onsubmit="return checkFormElementInRange(this, 'num_fields', '<?php echo str_replace('\'', '\\\'', __('You have to add at least one column.')); ?>', 1)">
673 <?php
674 echo PMA_generate_common_hidden_inputs($db, $table);
675 if ($cfg['PropertiesIconic']) {
676 echo '<img class="icon ic_b_insrow" src="themes/dot.gif" alt="' . __('Add column') . '"/>';
678 echo sprintf(__('Add %s column(s)'), '<input type="text" name="num_fields" size="2" maxlength="2" value="1" onfocus="this.select()" />');
680 // I tried displaying the drop-down inside the label but with Firefox
681 // the drop-down was blinking
682 $fieldOptions = '<select name="after_field" onclick="this.form.field_where[2].checked=true" onchange="this.form.field_where[2].checked=true">';
683 foreach ($aryFields as $fieldname) {
684 $fieldOptions .= '<option value="' . htmlspecialchars($fieldname) . '">' . htmlspecialchars($fieldname) . '</option>' . "\n";
686 unset($aryFields);
687 $fieldOptions .= '</select>';
689 $choices = array(
690 'last' => __('At End of Table'),
691 'first' => __('At Beginning of Table'),
692 'after' => sprintf(__('After %s'), '')
694 PMA_display_html_radio('field_where', $choices, 'last', false);
695 echo $fieldOptions;
696 unset($fieldOptions, $choices);
698 <input type="submit" value="<?php echo __('Go'); ?>" />
699 </form>
700 <iframe class="IE_hack" scrolling="no"></iframe>
701 <hr />
702 <div id="index_div" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?> >
703 <?php
707 * If there are more than 20 rows, displays browse/select/insert/empty/drop
708 * links again
710 if ($fields_cnt > 20) {
711 require './libraries/tbl_links.inc.php';
712 } // end if ($fields_cnt > 20)
715 * Displays indexes
718 if (! $tbl_is_view && ! $db_is_information_schema && 'ARCHIVE' != $tbl_type) {
720 * Display indexes
722 echo PMA_Index::getView($table, $db);
724 </div>
725 <form action="./tbl_indexes.php" method="post"
726 onsubmit="return checkFormElementInRange(this, 'added_fields',
727 '<?php echo str_replace('\'', '\\\'', __('Column count has to be larger than zero.')); ?>',
728 1)">
729 <fieldset>
730 <?php
731 echo PMA_generate_common_hidden_inputs($db, $table);
732 echo sprintf(__('Create an index on &nbsp;%s&nbsp;columns'),
733 '<input type="text" size="2" name="added_fields" value="1" />');
735 <input type="submit" name="create_index" value="<?php echo __('Go'); ?>" />
736 </fieldset>
737 </form>
738 <br />
739 <?php
743 * Displays Space usage and row statistics
745 // BEGIN - Calc Table Space
746 // Get valid statistics whatever is the table type
747 if ($cfg['ShowStats']) {
748 echo '<div id="tablestatistics">';
749 if (empty($showtable)) {
750 $showtable = PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], null, true);
753 $nonisam = false;
754 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
755 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
756 $nonisam = true;
759 // Gets some sizes
761 $mergetable = PMA_Table::isMerge($GLOBALS['db'], $GLOBALS['table']);
763 // this is to display for example 261.2 MiB instead of 268k KiB
764 $max_digits = 5;
765 $decimals = 1;
766 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length'], $max_digits, $decimals);
767 if ($mergetable == false) {
768 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length'], $max_digits, $decimals);
770 // InnoDB returns a huge value in Data_free, do not use it
771 if (! $is_innodb && isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
772 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free'], $max_digits, $decimals);
773 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free'], $max_digits, $decimals);
774 } else {
775 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
777 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
778 if ($table_info_num_rows > 0) {
779 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
782 // Displays them
783 $odd_row = false;
786 <a name="showusage"></a>
787 <?php if (! $tbl_is_view && ! $db_is_information_schema) { ?>
788 <table id="tablespaceusage" class="data">
789 <caption class="tblHeaders"><?php echo __('Space usage'); ?></caption>
790 <thead>
791 <tr>
792 <th><?php echo __('Type'); ?></th>
793 <th colspan="2"><?php echo __('Usage'); ?></th>
794 </tr>
795 </thead>
796 <tbody>
797 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
798 <th class="name"><?php echo __('Data'); ?></th>
799 <td class="value"><?php echo $data_size; ?></td>
800 <td class="unit"><?php echo $data_unit; ?></td>
801 </tr>
802 <?php
803 if (isset($index_size)) {
805 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
806 <th class="name"><?php echo __('Index'); ?></th>
807 <td class="value"><?php echo $index_size; ?></td>
808 <td class="unit"><?php echo $index_unit; ?></td>
809 </tr>
810 <?php
812 if (isset($free_size)) {
814 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?> error">
815 <th class="name"><?php echo __('Overhead'); ?></th>
816 <td class="value"><?php echo $free_size; ?></td>
817 <td class="unit"><?php echo $free_unit; ?></td>
818 </tr>
819 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
820 <th class="name"><?php echo __('Effective'); ?></th>
821 <td class="value"><?php echo $effect_size; ?></td>
822 <td class="unit"><?php echo $effect_unit; ?></td>
823 </tr>
824 <?php
826 if (isset($tot_size) && $mergetable == false) {
828 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
829 <th class="name"><?php echo __('Total'); ?></th>
830 <td class="value"><?php echo $tot_size; ?></td>
831 <td class="unit"><?php echo $tot_unit; ?></td>
832 </tr>
833 <?php
835 // Optimize link if overhead
836 if (isset($free_size) && ($tbl_type == 'MYISAM' || $tbl_type == 'ARIA' || $tbl_type == 'MARIA' || $tbl_type == 'BDB')) {
838 <tr class="tblFooters">
839 <td colspan="3" align="center">
840 <a href="sql.php?<?php echo $url_query; ?>&pos=0&amp;sql_query=<?php echo urlencode('OPTIMIZE TABLE ' . PMA_backquote($table)); ?>"><?php
841 if ($cfg['PropertiesIconic']) {
842 echo '<img class="icon ic_b_tbloptimize" src="themes/dot.gif" alt="' . __('Optimize table'). '" />';
844 echo __('Optimize table');
845 ?></a>
846 </td>
847 </tr>
848 <?php
851 </tbody>
852 </table>
853 <?php
855 $odd_row = false;
857 <table id="tablerowstats" class="data">
858 <caption class="tblHeaders"><?php echo __('Row Statistics'); ?></caption>
859 <thead>
860 <tr>
861 <th><?php echo __('Statements'); ?></th>
862 <th><?php echo __('Value'); ?></th>
863 </tr>
864 </thead>
865 <tbody>
866 <?php
867 if (isset($showtable['Row_format'])) {
869 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
870 <th class="name"><?php echo __('Format'); ?></th>
871 <td class="value"><?php
872 if ($showtable['Row_format'] == 'Fixed') {
873 echo __('static');
874 } elseif ($showtable['Row_format'] == 'Dynamic') {
875 echo __('dynamic');
876 } else {
877 echo $showtable['Row_format'];
879 ?></td>
880 </tr>
881 <?php
883 if (! empty($showtable['Create_options'])) {
885 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
886 <th class="name"><?php echo __('Options'); ?></th>
887 <td class="value"><?php
888 if ($showtable['Create_options'] == 'partitioned') {
889 echo __('partitioned');
890 } else {
891 echo $showtable['Create_options'];
893 ?></td>
894 </tr>
895 <?php
897 if (!empty($tbl_collation)) {
899 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
900 <th class="name"><?php echo __('Collation'); ?></th>
901 <td class="value"><?php
902 echo '<dfn title="' . PMA_getCollationDescr($tbl_collation) . '">' . $tbl_collation . '</dfn>';
903 ?></td>
904 </tr>
905 <?php
907 if (!$is_innodb && isset($showtable['Rows'])) {
909 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
910 <th class="name"><?php echo __('Rows'); ?></th>
911 <td class="value"><?php echo PMA_formatNumber($showtable['Rows'], 0); ?></td>
912 </tr>
913 <?php
915 if (!$is_innodb && isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
917 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
918 <th class="name"><?php echo __('Row length'); ?> &oslash;</th>
919 <td class="value"><?php echo PMA_formatNumber($showtable['Avg_row_length'], 0); ?></td>
920 </tr>
921 <?php
923 if (!$is_innodb && isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
925 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
926 <th class="name"><?php echo __(' Row size '); ?> &oslash;</th>
927 <td class="value"><?php echo $avg_size . ' ' . $avg_unit; ?></td>
928 </tr>
929 <?php
931 if (isset($showtable['Auto_increment'])) {
933 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
934 <th class="name"><?php echo __('Next'); ?> Autoindex</th>
935 <td class="value"><?php echo PMA_formatNumber($showtable['Auto_increment'], 0); ?></td>
936 </tr>
937 <?php
939 if (isset($showtable['Create_time'])) {
941 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
942 <th class="name"><?php echo __('Creation'); ?></th>
943 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Create_time'])); ?></td>
944 </tr>
945 <?php
947 if (isset($showtable['Update_time'])) {
949 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
950 <th class="name"><?php echo __('Last update'); ?></th>
951 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Update_time'])); ?></td>
952 </tr>
953 <?php
955 if (isset($showtable['Check_time'])) {
957 <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
958 <th class="name"><?php echo __('Last check'); ?></th>
959 <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Check_time'])); ?></td>
960 </tr>
961 <?php
964 </tbody>
965 </table>
967 <!-- close tablestatistics div -->
968 </div>
970 <?php
972 // END - Calc Table Space
974 echo '<div class="clearfloat"></div>' . "\n";
977 * Displays the footer
979 require './libraries/footer.inc.php';