Translation update done using Pootle.
[phpmyadmin/ammaryasirr.git] / db_structure.php
blob01c215677c84820603250d4c96e72b5b273a418b
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package phpMyAdmin
6 */
8 /**
11 require_once './libraries/common.inc.php';
13 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
14 $GLOBALS['js_include'][] = 'db_structure.js';
15 $GLOBALS['js_include'][] = 'tbl_change.js';
16 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
18 /**
19 * Prepares the tables list if the user where not redirected to this script
20 * because there is no table in the database ($is_info is true)
22 if (empty($is_info)) {
23 // Drops/deletes/etc. multiple tables if required
24 if ((!empty($submit_mult) && isset($selected_tbl))
25 || isset($mult_btn)) {
26 $action = 'db_structure.php';
27 $err_url = 'db_structure.php?'. PMA_generate_common_url($db);
29 // see bug #2794840; in this case, code path is:
30 // db_structure.php -> libraries/mult_submits.inc.php -> sql.php
31 // -> db_structure.php and if we got an error on the multi submit,
32 // we must display it here and not call again mult_submits.inc.php
33 if (! isset($error) || false === $error) {
34 require './libraries/mult_submits.inc.php';
36 if (empty($message)) {
37 $message = PMA_Message::success();
40 require './libraries/db_common.inc.php';
41 $url_query .= '&amp;goto=db_structure.php';
43 // Gets the database structure
44 $sub_part = '_structure';
45 require './libraries/db_info.inc.php';
47 require_once './libraries/replication.inc.php';
50 require_once './libraries/bookmark.lib.php';
52 require_once './libraries/mysql_charsets.lib.php';
53 $db_collation = PMA_getDbCollation($db);
55 // in a separate file to avoid redeclaration of functions in some code paths
56 require_once './libraries/db_structure.lib.php';
57 $titles = PMA_buildActionTitles();
59 // 1. No tables
60 if ($num_tables == 0) {
61 echo '<p>' . __('No tables found in database') . '</p>' . "\n";
63 if (empty($db_is_information_schema)) {
64 require './libraries/display_create_table.lib.php';
65 } // end if (Create Table dialog)
67 /**
68 * Displays the footer
70 require_once './libraries/footer.inc.php';
71 exit;
74 // else
75 // 2. Shows table informations
77 /**
78 * Displays the tables list
80 echo '<div id="tableslistcontainer">';
81 $_url_params = array(
82 'pos' => $pos,
83 'db' => $db);
85 // Add the sort options if they exists
86 if (isset($_REQUEST['sort'])) {
87 $_url_params['sort'] = $_REQUEST['sort'];
90 if (isset($_REQUEST['sort_order'])) {
91 $_url_params['sort_order'] = $_REQUEST['sort_order'];
94 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
97 <form method="post" action="db_structure.php" name="tablesForm" id="tablesForm">
98 <?php
99 echo PMA_generate_common_hidden_inputs($db);
101 PMA_TableHeader($db_is_information_schema, $server_slave_status);
103 $i = $sum_entries = 0;
104 $sum_size = (double) 0;
105 $overhead_size = (double) 0;
106 $overhead_check = '';
107 $checked = !empty($checkall) ? ' checked="checked"' : '';
108 $num_columns = $cfg['PropertiesNumColumns'] > 1 ? ceil($num_tables / $cfg['PropertiesNumColumns']) + 1 : 0;
109 $row_count = 0;
112 $hidden_fields = array();
113 $odd_row = true;
114 $sum_row_count_pre = '';
116 $tableReductionCount = 0; // the amount to reduce the table count by
118 foreach ($tables as $keyname => $each_table) {
119 if (PMA_BS_IsHiddenTable($keyname)) {
120 $tableReductionCount++;
121 continue;
124 // Get valid statistics whatever is the table type
126 $table_is_view = false;
127 $table_encoded = urlencode($each_table['TABLE_NAME']);
128 // Sets parameters for links
129 $tbl_url_query = $url_query . '&amp;table=' . $table_encoded;
130 // do not list the previous table's size info for a view
131 $formatted_size = '-';
132 $unit = '';
134 switch ( $each_table['ENGINE']) {
135 // MyISAM, ISAM or Heap table: Row count, data size and index size
136 // are accurate; data size is accurate for ARCHIVE
137 case 'MyISAM' :
138 case 'ISAM' :
139 case 'HEAP' :
140 case 'MEMORY' :
141 case 'ARCHIVE' :
142 case 'Aria' :
143 case 'Maria' :
144 if ($db_is_information_schema) {
145 $each_table['Rows'] = PMA_Table::countRecords($db,
146 $each_table['Name']);
149 if ($is_show_stats) {
150 $tblsize = doubleval($each_table['Data_length']) + doubleval($each_table['Index_length']);
151 $sum_size += $tblsize;
152 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ? 1 : 0);
153 if (isset($each_table['Data_free']) && $each_table['Data_free'] > 0) {
154 list($formatted_overhead, $overhead_unit) = PMA_formatByteDown($each_table['Data_free'], 3, ($each_table['Data_free'] > 0) ? 1 : 0);
155 $overhead_size += $each_table['Data_free'];
158 break;
159 case 'InnoDB' :
160 // InnoDB table: Row count is not accurate but data and index
161 // sizes are.
163 if ($each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount']) {
164 $each_table['COUNTED'] = true;
165 $each_table['TABLE_ROWS'] = PMA_Table::countRecords($db,
166 $each_table['TABLE_NAME'], $force_exact = true,
167 $is_view = false);
168 } else {
169 $each_table['COUNTED'] = false;
172 if ($is_show_stats) {
173 $tblsize = $each_table['Data_length'] + $each_table['Index_length'];
174 $sum_size += $tblsize;
175 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ? 1 : 0);
177 //$display_rows = ' - ';
178 break;
179 // Mysql 5.0.x (and lower) uses MRG_MyISAM and MySQL 5.1.x (and higher) uses MRG_MYISAM
180 // Both are aliases for MERGE
181 case 'MRG_MyISAM' :
182 case 'MRG_MYISAM' :
183 case 'MERGE' :
184 case 'BerkeleyDB' :
185 // Merge or BerkleyDB table: Only row count is accurate.
186 if ($is_show_stats) {
187 $formatted_size = ' - ';
188 $unit = '';
190 break;
191 // for a view, the ENGINE is sometimes reported as null,
192 // or on some servers it's reported as "SYSTEM VIEW"
193 case null :
194 case 'SYSTEM VIEW' :
195 // if table is broken, Engine is reported as null, so one more test
196 if ($each_table['TABLE_TYPE'] == 'VIEW') {
197 // countRecords() takes care of $cfg['MaxExactCountViews']
198 $each_table['TABLE_ROWS'] = PMA_Table::countRecords($db,
199 $each_table['TABLE_NAME'], $force_exact = true,
200 $is_view = true);
201 $table_is_view = true;
203 break;
204 default :
205 // Unknown table type.
206 if ($is_show_stats) {
207 $formatted_size = 'unknown';
208 $unit = '';
210 } // end switch
212 if (! PMA_Table::isMerge($db, $each_table['TABLE_NAME'])) {
213 $sum_entries += $each_table['TABLE_ROWS'];
216 if (isset($each_table['Collation'])) {
217 $collation = '<dfn title="'
218 . PMA_getCollationDescr($each_table['Collation']) . '">'
219 . $each_table['Collation'] . '</dfn>';
220 } else {
221 $collation = '---';
224 if ($is_show_stats) {
225 if (isset($formatted_overhead)) {
226 $overhead = '<a href="tbl_structure.php?'
227 . $tbl_url_query . '#showusage">' . $formatted_overhead
228 . ' ' . $overhead_unit . '</a>' . "\n";
229 unset($formatted_overhead);
230 $overhead_check .=
231 "document.getElementById('checkbox_tbl_" . ($i + 1) . "').checked = true;";
232 } else {
233 $overhead = '-';
235 } // end if
237 $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$each_table['TABLE_NAME']]))
238 ? str_replace(' ', '&nbsp;', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
239 : str_replace(' ', '&nbsp;', htmlspecialchars($each_table['TABLE_NAME']));
240 $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$each_table['TABLE_NAME']]))
241 ? str_replace(' ', '&nbsp;', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
242 : str_replace(' ', '&nbsp;', htmlspecialchars($each_table['TABLE_NAME']));
244 $i++;
246 $row_count++;
247 if ($table_is_view) {
248 $hidden_fields[] = '<input type="hidden" name="views[]" value="' . htmlspecialchars($each_table['TABLE_NAME']) . '" />';
251 if ($each_table['TABLE_ROWS'] > 0) {
252 $browse_table = '<a href="sql.php?' . $tbl_url_query . '&amp;pos=0">' . $titles['Browse'] . '</a>';
253 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">' . $titles['Search'] . '</a>';
254 $browse_table_label = '<a href="sql.php?' . $tbl_url_query . '&amp;pos=0">' . $truename . '</a>';
255 } else {
256 $browse_table = $titles['NoBrowse'];
257 $search_table = $titles['NoSearch'];
258 $browse_table_label = '<a href="tbl_structure.php?' . $tbl_url_query . '">' . $truename . '</a>';
261 if (! $db_is_information_schema) {
262 if (! empty($each_table['TABLE_ROWS'])) {
263 $empty_table = '<a ';
264 if ($GLOBALS['cfg']['AjaxEnable']) {
265 $empty_table .= 'class="truncate_table_anchor"';
267 $empty_table .= ' href="sql.php?' . $tbl_url_query
268 . '&amp;sql_query=';
269 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
270 . '&amp;message_to_show='
271 . urlencode(sprintf(__('Table %s has been emptied'), htmlspecialchars($each_table['TABLE_NAME'])))
272 .'">' . $titles['Empty'] . '</a>';
273 } else {
274 $empty_table = $titles['NoEmpty'];
276 $drop_query = 'DROP '
277 . ($table_is_view ? 'VIEW' : 'TABLE')
278 . ' ' . PMA_backquote($each_table['TABLE_NAME']);
279 $drop_message = sprintf(
280 $table_is_view ? __('View %s has been dropped') : __('Table %s has been dropped'),
281 str_replace(' ', '&nbsp;', htmlspecialchars($each_table['TABLE_NAME'])));
284 $tracking_icon = '';
285 if (PMA_Tracker::isActive()) {
286 if (PMA_Tracker::isTracked($GLOBALS["db"], $truename)) {
287 $tracking_icon = '<a href="tbl_tracking.php?' . $url_query.'&amp;table=' . $truename . '"><img class="icon ic_eye" src="themes/dot.gif" alt="' . __('Tracking is active.') . '" title="' . __('Tracking is active.') . '" /></a>';
288 } elseif (PMA_Tracker::getVersion($GLOBALS["db"], $truename) > 0) {
289 $tracking_icon = '<a href="tbl_tracking.php?' . $url_query . '&amp;table=' . $truename . '"><img class="icon ic_eye" src="themes/dot.gif" alt="' . __('Tracking is not active.') . '" title="' . __('Tracking is not active.') . '" /></a>';
293 if ($num_columns > 0 && $num_tables > $num_columns
294 && (($row_count % $num_columns) == 0)) {
295 $row_count = 1;
296 $odd_row = true;
298 </tr>
299 </tbody>
300 </table>
301 <?php
302 PMA_TableHeader(false, $server_slave_status);
305 $ignored = false;
306 $do = false;
308 if ($server_slave_status) {
309 ////////////////////////////////////////////////////////////////
311 if ((strlen(array_search($truename, $server_slave_Do_Table)) > 0)
312 || (strlen(array_search($db, $server_slave_Do_DB)) > 0)
313 || (count($server_slave_Do_DB) == 1 && count($server_slave_Ignore_DB) == 1)
315 $do = true;
317 foreach ($server_slave_Wild_Do_Table as $db_table) {
318 $table_part = PMA_extract_db_or_table($db_table, 'table');
319 if (($db == PMA_extract_db_or_table($db_table, 'db')) && (preg_match("@^" . substr($table_part, 0, strlen($table_part) - 1) . "@", $truename))) {
320 $do = true;
323 ////////////////////////////////////////////////////////////////////
324 if ((strlen(array_search($truename, $server_slave_Ignore_Table)) > 0) || (strlen(array_search($db, $server_slave_Ignore_DB)) > 0)) {
325 $ignored = true;
327 foreach ($server_slave_Wild_Ignore_Table as $db_table) {
328 $table_part = PMA_extract_db_or_table($db_table, 'table');
329 if (($db == PMA_extract_db_or_table($db_table)) && (preg_match("@^" . substr($table_part, 0, strlen($table_part) - 1) . "@", $truename))) {
330 $ignored = true;
333 unset($table_part);
336 <tr class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
337 <td align="center">
338 <input type="checkbox" name="selected_tbl[]"
339 value="<?php echo htmlspecialchars($each_table['TABLE_NAME']); ?>"
340 id="checkbox_tbl_<?php echo $i; ?>"<?php echo $checked; ?> /></td>
341 <th><?php echo $browse_table_label; ?>
342 <?php echo (! empty($tracking_icon) ? $tracking_icon : ''); ?>
343 </th>
344 <?php if ($server_slave_status) { ?><td align="center"><?php echo $ignored ? ' <img class="icon ic_s_cancel" src="themes/dot.gif" alt="NOT REPLICATED" />' : ''. $do ? ' <img class="icon ic_s_success" src="themes/dot.gif" alt="REPLICATED" />' : ''; ?></td><?php } ?>
345 <td align="center"><?php echo $browse_table; ?></td>
346 <td align="center">
347 <a href="tbl_structure.php?<?php echo $tbl_url_query; ?>">
348 <?php echo $titles['Structure']; ?></a></td>
349 <td align="center"><?php echo $search_table; ?></td>
350 <?php if (! $db_is_information_schema) { ?>
351 <td align="center" class="insert_table">
352 <a <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? 'class="ajax"' : ''); ?> href="tbl_change.php?<?php echo $tbl_url_query; ?>">
353 <?php echo $titles['Insert']; ?></a></td>
354 <td align="center"><?php echo $empty_table; ?></td>
355 <td align="center">
356 <a <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? 'class="drop_table_anchor"' : ''); ?> href="sql.php?<?php echo $tbl_url_query;
357 ?>&amp;reload=1&amp;purge=1&amp;sql_query=<?php
358 echo urlencode($drop_query); ?>&amp;message_to_show=<?php
359 echo urlencode($drop_message); ?>" >
360 <?php echo $titles['Drop']; ?></a></td>
361 <?php } // end if (! $db_is_information_schema)
363 // there is a null value in the ENGINE
364 // - when the table needs to be repaired, or
365 // - when it's a view
366 // so ensure that we'll display "in use" below for a table
367 // that needs to be repaired
368 if (isset($each_table['TABLE_ROWS']) && ($each_table['ENGINE'] != null || $table_is_view)) {
369 if ($table_is_view) {
370 if ($each_table['TABLE_ROWS'] >= $GLOBALS['cfg']['MaxExactCountViews']) {
371 $row_count_pre = '~';
372 $sum_row_count_pre = '~';
373 $show_superscript = PMA_showHint(PMA_sanitize(sprintf(__('This view has at least this number of rows. Please refer to %sdocumentation%s.'), '[a@./Documentation.html#cfg_MaxExactCountViews@_blank]', '[/a]')));
375 } elseif ($each_table['ENGINE'] == 'InnoDB' && (! $each_table['COUNTED'])) {
376 // InnoDB table: we did not get an accurate row count
377 $row_count_pre = '~';
378 $sum_row_count_pre = '~';
379 $show_superscript = '';
380 } else {
381 $row_count_pre = '';
382 $show_superscript = '';
385 <td class="value tbl_rows"><?php echo $row_count_pre . PMA_formatNumber($each_table['TABLE_ROWS'], 0) . $show_superscript; ?></td>
386 <?php if (!($cfg['PropertiesNumColumns'] > 1)) { ?>
387 <td nowrap="nowrap"><?php echo ($table_is_view ? __('View') : $each_table['ENGINE']); ?></td>
388 <?php if (isset($collation)) { ?>
389 <td nowrap="nowrap"><?php echo $collation ?></td>
390 <?php } ?>
391 <?php } ?>
393 <?php if ($is_show_stats) { ?>
394 <td class="value tbl_size"><a
395 href="tbl_structure.php?<?php echo $tbl_url_query; ?>#showusage"
396 ><?php echo $formatted_size . ' ' . $unit; ?></a></td>
397 <td class="value"><?php echo $overhead; ?></td>
398 <?php } // end if ?>
399 <?php } elseif ($table_is_view) { ?>
400 <td class="value">-</td>
401 <td><?php echo __('View'); ?></td>
402 <td>---</td>
403 <?php if ($is_show_stats) { ?>
404 <td class="value">-</td>
405 <td class="value">-</td>
406 <?php } ?>
407 <?php } else { ?>
408 <td colspan="<?php echo ($colspan_for_structure - ($db_is_information_schema ? 5 : 8)) ?>"
409 align="center">
410 <?php echo __('in use'); ?></td>
411 <?php } // end if (isset($each_table['TABLE_ROWS'])) else ?>
412 </tr>
413 <?php
414 } // end foreach
416 // Show Summary
417 if ($is_show_stats) {
418 list($sum_formatted, $unit) = PMA_formatByteDown($sum_size, 3, 1);
419 list($overhead_formatted, $overhead_unit) =
420 PMA_formatByteDown($overhead_size, 3, 1);
423 </tbody>
424 <tbody id="tbl_summary_row">
425 <tr><th></th>
426 <th align="center" nowrap="nowrap">
427 <?php
428 // for blobstreaming - if the number of tables is 0, set tableReductionCount to 0
429 // (we don't want negative numbers here)
430 if ($num_tables == 0)
431 $tableReductionCount = 0;
433 echo sprintf(_ngettext('%s table', '%s tables', $num_tables - $tableReductionCount), PMA_formatNumber($num_tables - $tableReductionCount, 0));
435 </th>
436 <?php
437 if ($server_slave_status) {
438 echo ' <th>' . __('Replication') . '</th>' . "\n";
441 <th colspan="<?php echo ($db_is_information_schema ? 3 : 6) ?>" align="center">
442 <?php echo __('Sum'); ?></th>
443 <th class="value tbl_rows"><?php echo $sum_row_count_pre . PMA_formatNumber($sum_entries, 0); ?></th>
444 <?php
445 if (!($cfg['PropertiesNumColumns'] > 1)) {
446 $default_engine = PMA_DBI_get_default_engine();
447 echo ' <th align="center">' . "\n"
448 . ' <dfn title="'
449 . sprintf(__('%s is the default storage engine on this MySQL server.'), $default_engine) . '">' .$default_engine . '</dfn></th>' . "\n";
450 // we got a case where $db_collation was empty
451 echo ' <th align="center">' . "\n";
452 if (! empty($db_collation)) {
453 echo ' <dfn title="'
454 . PMA_getCollationDescr($db_collation) . ' (' . __('Default') . ')">' . $db_collation
455 . '</dfn>';
457 echo '</th>';
460 if ($is_show_stats) {
462 <th class="value tbl_size"><?php echo $sum_formatted . ' ' . $unit; ?></th>
463 <th class="value"><?php echo $overhead_formatted . ' ' . $overhead_unit; ?></th>
464 <?php
467 </tr>
468 </tbody>
469 </table>
471 <div class="clearfloat">
472 <?php
473 // Check all tables url
474 $checkall_url = 'db_structure.php?' . PMA_generate_common_url($db);
476 <img class="selectallarrow" src="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
477 width="38" height="22" alt="<?php echo __('With selected:'); ?>" />
478 <a href="<?php echo $checkall_url; ?>&amp;checkall=1"
479 onclick="if (markAllRows('tablesForm')) return false;">
480 <?php echo __('Check All'); ?></a>
482 <a href="<?php echo $checkall_url; ?>"
483 onclick="if (unMarkAllRows('tablesForm')) return false;">
484 <?php echo __('Uncheck All'); ?></a>
485 <?php if ($overhead_check != '') { ?>
487 <a href="#" onclick="unMarkAllRows('tablesForm');
488 <?php echo $overhead_check; ?> return false;">
489 <?php echo __('Check tables having overhead'); ?></a>
490 <?php } ?>
492 <select name="submit_mult" onchange="this.form.submit();" style="margin: 0 3em 0 3em;">
493 <?php
494 echo ' <option value="' . __('With selected:') . '" selected="selected">'
495 . __('With selected:') . '</option>' . "\n";
496 echo ' <option value="export" >'
497 . __('Export') . '</option>' . "\n";
498 echo ' <option value="print" >'
499 . __('Print view') . '</option>' . "\n";
501 if (!$db_is_information_schema && !$cfg['DisableMultiTableMaintenance']) {
502 echo ' <option value="empty_tbl" >'
503 . __('Empty') . '</option>' . "\n";
504 echo ' <option value="drop_tbl" >'
505 . __('Drop') . '</option>' . "\n";
506 echo ' <option value="check_tbl" >'
507 . __('Check table') . '</option>' . "\n";
508 echo ' <option value="optimize_tbl" >'
509 . __('Optimize table') . '</option>' . "\n";
510 echo ' <option value="repair_tbl" >'
511 . __('Repair table') . '</option>' . "\n";
512 echo ' <option value="analyze_tbl" >'
513 . __('Analyze table') . '</option>' . "\n";
514 echo ' <option value="add_prefix_tbl" >'
515 . __('Add prefix to table') . '</option>' . "\n";
516 echo ' <option value="replace_prefix_tbl" >'
517 . __('Replace table prefix') . '</option>' . "\n";
518 echo ' <option value="copy_tbl_change_prefix" >'
519 . __('Copy table with prefix') . '</option>' . "\n";
522 </select>
523 <script type="text/javascript">
524 <!--
525 // Fake js to allow the use of the <noscript> tag
526 //-->
527 </script>
528 <noscript>
529 <input type="submit" value="<?php echo __('Go'); ?>" />
530 </noscript>
531 <?php echo implode("\n", $hidden_fields) . "\n"; ?>
532 </div>
533 </form>
534 <?php
535 // display again the table list navigator
536 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
538 </div>
539 <hr />
541 <?php
544 * Work on the database
546 /* DATABASE WORK */
547 /* Printable view of a table */
548 echo '<p>';
549 echo '<a href="db_printview.php?' . $url_query . '">';
550 if ($cfg['PropertiesIconic']) {
551 echo '<img class="icon ic_b_print" src="themes/dot.gif" alt="" />';
553 echo __('Print view') . '</a> ';
555 echo '<a href="./db_datadict.php?' . $url_query . '">';
556 if ($cfg['PropertiesIconic']) {
557 echo '<img class="icon ic_b_tblanalyse" src="themes/dot.gif" alt="" />';
559 echo __('Data Dictionary') . '</a>';
560 echo '</p>';
562 if (empty($db_is_information_schema)) {
563 require './libraries/display_create_table.lib.php';
564 } // end if (Create Table dialog)
567 * Displays the footer
569 require './libraries/footer.inc.php';