Merge branch 'master' of ssh://phpmyadmin.git.sourceforge.net/gitroot/phpmyadmin...
[phpmyadmin.git] / tbl_printview.php
blob7f7a8c804968d8028ff6891657a414435af89e16
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 * @package phpMyAdmin
7 */
9 /**
12 require_once './libraries/common.inc.php';
14 require './libraries/tbl_common.php';
16 /**
17 * Gets the variables sent or posted to this script, then displays headers
19 $print_view = true;
20 if (! isset($selected_tbl)) {
21 require_once './libraries/header.inc.php';
24 // Check parameters
26 if (! isset($the_tables) || ! is_array($the_tables)) {
27 $the_tables = array();
30 /**
31 * Gets the relations settings
33 require_once './libraries/relation.lib.php';
34 require_once './libraries/transformations.lib.php';
35 require_once './libraries/Index.class.php';
37 $cfgRelation = PMA_getRelationsParam();
39 /**
40 * Defines the url to return to in case of error in a sql statement
42 if (strlen($table)) {
43 $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
44 } else {
45 $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
49 /**
50 * Selects the database
52 PMA_DBI_select_db($db);
55 /**
56 * Multi-tables printview
58 if (isset($selected_tbl) && is_array($selected_tbl)) {
59 $the_tables = $selected_tbl;
60 } elseif (strlen($table)) {
61 $the_tables[] = $table;
63 $multi_tables = (count($the_tables) > 1);
65 if ($multi_tables) {
66 if (empty($GLOBALS['is_header_sent'])) {
67 require_once './libraries/header.inc.php';
69 $tbl_list = '';
70 foreach ($the_tables as $key => $table) {
71 $tbl_list .= (empty($tbl_list) ? '' : ', ')
72 . PMA_backquote($table);
74 echo '<strong>'. __('Show tables') . ': ' . $tbl_list . '</strong>' . "\n";
75 echo '<hr />' . "\n";
76 } // end if
78 $tables_cnt = count($the_tables);
79 $counter = 0;
81 foreach ($the_tables as $key => $table) {
82 if ($counter + 1 >= $tables_cnt) {
83 $breakstyle = '';
84 } else {
85 $breakstyle = ' style="page-break-after: always;"';
87 $counter++;
88 echo '<div' . $breakstyle . '>' . "\n";
89 echo '<h1>' . $table . '</h1>' . "\n";
91 /**
92 * Gets table informations
94 $showtable = PMA_Table::sGetStatusInfo($db, $table);
95 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
96 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
98 $tbl_is_view = PMA_Table::isView($db, $table);
101 * Gets fields properties
103 $result = PMA_DBI_query(
104 'SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null,
105 PMA_DBI_QUERY_STORE);
106 $fields_cnt = PMA_DBI_num_rows($result);
109 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
110 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
111 // and SHOW CREATE TABLE says NOT NULL (tested
112 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
114 $show_create_table = PMA_DBI_fetch_value(
115 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
116 0, 1);
117 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
119 // Check if we can use Relations (Mike Beck)
120 // Find which tables are related with the current one and write it in
121 // an array
122 $res_rel = PMA_getForeigners($db, $table);
123 $have_rel = (bool) count($res_rel);
126 * Displays the comments of the table if MySQL >= 3.23
128 if (!empty($show_comment)) {
129 echo __('Table comments') . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
133 * Displays the table structure
137 <!-- TABLE INFORMATIONS -->
138 <table style="width: 100%;">
139 <thead>
140 <tr>
141 <th><?php echo __('Column'); ?></th>
142 <th><?php echo __('Type'); ?></th>
143 <!--<th><?php echo __('Attributes'); ?></th>-->
144 <th><?php echo __('Null'); ?></th>
145 <th><?php echo __('Default'); ?></th>
146 <!--<th><?php echo __('Extra'); ?></th>-->
147 <?php
148 if ($have_rel) {
149 echo '<th>' . __('Links to') . '</th>' . "\n";
151 echo ' <th>' . __('Comments') . '</th>' . "\n";
152 if ($cfgRelation['mimework']) {
153 echo ' <th>MIME</th>' . "\n";
156 </tr>
157 </thead>
158 <tbody>
159 <?php
160 while ($row = PMA_DBI_fetch_assoc($result)) {
161 $type = $row['Type'];
162 // reformat mysql query output
163 // set or enum types: slashes single quotes inside options
164 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
165 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'',
166 ',' . $tmp[2]), 1);
167 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
169 $binary = 0;
170 $unsigned = 0;
171 $zerofill = 0;
172 } else {
173 $type = preg_replace('@BINARY@i', '', $type);
174 $type = preg_replace('@ZEROFILL@i', '', $type);
175 $type = preg_replace('@UNSIGNED@i', '', $type);
176 if (empty($type)) {
177 $type = '&nbsp;';
180 $binary = stristr($row['Type'], 'binary');
181 $unsigned = stristr($row['Type'], 'unsigned');
182 $zerofill = stristr($row['Type'], 'zerofill');
184 $attribute = '&nbsp;';
185 if ($binary) {
186 $attribute = 'BINARY';
188 if ($unsigned) {
189 $attribute = 'UNSIGNED';
191 if ($zerofill) {
192 $attribute = 'UNSIGNED ZEROFILL';
194 if (!isset($row['Default'])) {
195 if ($row['Null'] != '' && $row['Null'] != 'NO') {
196 $row['Default'] = '<i>NULL</i>';
198 } else {
199 $row['Default'] = htmlspecialchars($row['Default']);
201 $field_name = htmlspecialchars($row['Field']);
203 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
204 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
205 // the latter.
207 * @todo merge this logic with the one in tbl_structure.php
208 * or move it in a function similar to PMA_DBI_get_columns_full()
209 * but based on SHOW CREATE TABLE because information_schema
210 * cannot be trusted in this case (MySQL bug)
212 if (!empty($analyzed_sql[0]['create_table_fields'][$field_name]['type']) && $analyzed_sql[0]['create_table_fields'][$field_name]['type'] == 'TIMESTAMP' && $analyzed_sql[0]['create_table_fields'][$field_name]['timestamp_not_null']) {
213 $row['Null'] = '';
217 <tr><td>
218 <?php
219 if (isset($pk_array[$row['Field']])) {
220 echo ' <u>' . $field_name . '</u>' . "\n";
221 } else {
222 echo ' ' . $field_name . "\n";
225 </td>
226 <td><?php echo $type; ?><bdo dir="ltr"></bdo></td>
227 <!--<td><?php echo $attribute; ?></td>-->
228 <td><?php echo (($row['Null'] == '' || $row['Null'] == 'NO') ? __('No') : __('Yes')); ?>&nbsp;</td>
229 <td><?php if (isset($row['Default'])) { echo $row['Default']; } ?>&nbsp;</td>
230 <!--<td><?php echo $row['Extra']; ?>&nbsp;</td>-->
231 <?php
232 if ($have_rel) {
233 echo ' <td>';
234 if (isset($res_rel[$field_name])) {
235 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
237 echo '&nbsp;</td>' . "\n";
239 echo ' <td>';
240 $comments = PMA_getComments($db, $table);
241 if (isset($comments[$field_name])) {
242 echo htmlspecialchars($comments[$field_name]);
244 echo '&nbsp;</td>' . "\n";
245 if ($cfgRelation['mimework']) {
246 $mime_map = PMA_getMIME($db, $table, true);
248 echo ' <td>';
249 if (isset($mime_map[$field_name])) {
250 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
252 echo '&nbsp;</td>' . "\n";
255 </tr>
256 <?php
257 } // end while
258 PMA_DBI_free_result($result);
260 </tbody>
261 </table>
262 <?php
263 if (! $tbl_is_view && $db != 'information_schema') {
265 * Displays indexes
267 echo PMA_Index::getView($table, $db, true);
270 * Displays Space usage and row statistics
273 if ($cfg['ShowStats']) {
274 $nonisam = false;
275 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
276 $nonisam = true;
278 if ($nonisam == false) {
279 // Gets some sizes
281 $mergetable = PMA_Table::isMerge($db, $table);
283 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
284 if ($mergetable == false) {
285 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
287 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
288 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
289 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
290 } else {
291 unset($free_size);
292 unset($free_unit);
293 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
295 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
296 if ($num_rows > 0) {
297 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
300 // Displays them
302 <br /><br />
304 <table border="0" cellspacing="0" cellpadding="0" class="noborder">
305 <tr>
307 <!-- Space usage -->
308 <td valign="top">
309 <big><?php echo __('Space usage') . ':'; ?></big>
310 <table width="100%">
311 <tr>
312 <th><?php echo __('Type'); ?></th>
313 <th colspan="2" align="center"><?php echo __('Usage'); ?></th>
314 </tr>
315 <tr>
316 <td style="padding-right: 10px"><?php echo __('Data'); ?></td>
317 <td align="right"><?php echo $data_size; ?></td>
318 <td><?php echo $data_unit; ?></td>
319 </tr>
320 <?php
321 if (isset($index_size)) {
322 echo "\n";
324 <tr>
325 <td style="padding-right: 10px"><?php echo __('Index'); ?></td>
326 <td align="right"><?php echo $index_size; ?></td>
327 <td><?php echo $index_unit; ?></td>
328 </tr>
329 <?php
331 if (isset($free_size)) {
332 echo "\n";
334 <tr style="color: #bb0000">
335 <td style="padding-right: 10px"><?php echo __('Overhead'); ?></td>
336 <td align="right"><?php echo $free_size; ?></td>
337 <td><?php echo $free_unit; ?></td>
338 </tr>
339 <tr>
340 <td style="padding-right: 10px"><?php echo __('Effective'); ?></td>
341 <td align="right"><?php echo $effect_size; ?></td>
342 <td><?php echo $effect_unit; ?></td>
343 </tr>
344 <?php
346 if (isset($tot_size) && $mergetable == false) {
347 echo "\n";
349 <tr>
350 <td style="padding-right: 10px"><?php echo __('Total'); ?></td>
351 <td align="right"><?php echo $tot_size; ?></td>
352 <td><?php echo $tot_unit; ?></td>
353 </tr>
354 <?php
356 echo "\n";
358 </table>
359 </td>
361 <td width="20">&nbsp;</td>
363 <!-- Rows Statistic -->
364 <td valign="top">
365 <big><?php echo __('Row Statistics') . ':'; ?></big>
366 <table width="100%">
367 <tr>
368 <th><?php echo __('Statements'); ?></th>
369 <th align="center"><?php echo __('Value'); ?></th>
370 </tr>
371 <?php
372 if (isset($showtable['Row_format'])) {
374 <tr>
375 <td><?php echo ucfirst(__('Format')); ?></td>
376 <td align="<?php echo $cell_align_left; ?>">
377 <?php
378 if ($showtable['Row_format'] == 'Fixed') {
379 echo __('static');
380 } elseif ($showtable['Row_format'] == 'Dynamic') {
381 echo __('dynamic');
382 } else {
383 echo $showtable['Row_format'];
386 </td>
387 </tr>
388 <?php
390 if (isset($showtable['Rows'])) {
392 <tr>
393 <td><?php echo ucfirst(__('Rows')); ?></td>
394 <td align="right">
395 <?php echo PMA_formatNumber($showtable['Rows'], 0) . "\n"; ?>
396 </td>
397 </tr>
398 <?php
400 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
402 <tr>
403 <td><?php echo ucfirst(__('Row length')); ?>&nbsp;&oslash;</td>
404 <td>
405 <?php echo PMA_formatNumber($showtable['Avg_row_length'], 0) . "\n"; ?>
406 </td>
407 </tr>
408 <?php
410 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
412 <tr>
413 <td><?php echo ucfirst(__(' Row size ')); ?>&nbsp;&oslash;</td>
414 <td align="right">
415 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
416 </td>
417 </tr>
418 <?php
420 if (isset($showtable['Auto_increment'])) {
422 <tr>
423 <td><?php echo ucfirst(__('Next')); ?>&nbsp;Autoindex</td>
424 <td align="right">
425 <?php echo PMA_formatNumber($showtable['Auto_increment'], 0) . "\n"; ?>
426 </td>
427 </tr>
428 <?php
430 if (isset($showtable['Create_time'])) {
432 <tr>
433 <td><?php echo __('Creation'); ?></td>
434 <td align="right">
435 <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
436 </td>
437 </tr>
438 <?php
440 if (isset($showtable['Update_time'])) {
442 <tr>
443 <td><?php echo __('Last update'); ?></td>
444 <td align="right">
445 <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
446 </td>
447 </tr>
448 <?php
450 if (isset($showtable['Check_time'])) {
452 <tr>
453 <td><?php echo __('Last check'); ?></td>
454 <td align="right">
455 <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
456 </td>
457 </tr>
458 <?php
462 </table>
463 </td>
464 </tr>
465 </table>
467 <?php
468 } // end if ($nonisam == false)
469 } // end if ($cfg['ShowStats'])
471 if ($multi_tables) {
472 unset($num_rows, $show_comment);
473 echo '<hr />' . "\n";
474 } // end if
475 echo '</div>' . "\n";
477 } // end while
480 * Displays the footer
484 <script type="text/javascript">
485 //<![CDATA[
486 function printPage()
488 // Do print the page
489 if (typeof(window.print) != 'undefined') {
490 window.print();
493 //]]>
494 </script>
496 <p class="print_ignore">
497 <input type="button" id="print" value="<?php echo __('Print'); ?>"
498 onclick="printPage()" /></p>
500 <?php
501 require_once './libraries/footer.inc.php';