Translation is already loaded by libraries/select_lang.lib.php.
[phpmyadmin/last10db.git] / tbl_printview.php
blob72d70170054a538cdeb40409f10e5ccebed259f6
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 */
8 /**
11 require_once './libraries/common.inc.php';
13 require './libraries/tbl_common.php';
15 /**
16 * Gets the variables sent or posted to this script, then displays headers
18 $print_view = true;
19 if (! isset($selected_tbl)) {
20 require_once './libraries/header.inc.php';
23 // Check parameters
25 if (! isset($the_tables) || ! is_array($the_tables)) {
26 $the_tables = array();
29 /**
30 * Gets the relations settings
32 require_once './libraries/relation.lib.php';
33 require_once './libraries/transformations.lib.php';
34 require_once './libraries/Index.class.php';
36 $cfgRelation = PMA_getRelationsParam();
38 /**
39 * Defines the url to return to in case of error in a sql statement
41 if (strlen($table)) {
42 $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
43 } else {
44 $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
48 /**
49 * Selects the database
51 PMA_DBI_select_db($db);
54 /**
55 * Multi-tables printview thanks to Christophe Gesche from the "MySQL Form
56 * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
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 '<b>'. $strShowTables . ': ' . $tbl_list . '</b>' . "\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 $result = PMA_DBI_query(
95 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, true) . '\';');
96 $showtable = PMA_DBI_fetch_assoc($result);
97 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
98 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
99 PMA_DBI_free_result($result);
101 $tbl_is_view = PMA_Table::isView($db, $table);
104 * Gets fields properties
106 $result = PMA_DBI_query(
107 'SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null,
108 PMA_DBI_QUERY_STORE);
109 $fields_cnt = PMA_DBI_num_rows($result);
112 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
113 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
114 // and SHOW CREATE TABLE says NOT NULL (tested
115 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
117 $show_create_table = PMA_DBI_fetch_value(
118 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
119 0, 1);
120 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
122 // Check if we can use Relations (Mike Beck)
123 // Find which tables are related with the current one and write it in
124 // an array
125 $res_rel = PMA_getForeigners($db, $table);
126 $have_rel = (bool) count($res_rel);
129 * Displays the comments of the table if MySQL >= 3.23
131 if (!empty($show_comment)) {
132 echo $strTableComments . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
136 * Displays the table structure
140 <!-- TABLE INFORMATIONS -->
141 <table style="width: 100%;">
142 <thead>
143 <tr>
144 <th><?php echo $strField; ?></th>
145 <th><?php echo $strType; ?></th>
146 <!--<th><?php echo $strAttr; ?></th>-->
147 <th><?php echo $strNull; ?></th>
148 <th><?php echo $strDefault; ?></th>
149 <!--<th><?php echo $strExtra; ?></th>-->
150 <?php
151 if ($have_rel) {
152 echo '<th>' . $strLinksTo . '</th>' . "\n";
154 echo ' <th>' . $strComments . '</th>' . "\n";
155 if ($cfgRelation['mimework']) {
156 echo ' <th>MIME</th>' . "\n";
159 </tr>
160 </thead>
161 <tbody>
162 <?php
163 while ($row = PMA_DBI_fetch_assoc($result)) {
164 $type = $row['Type'];
165 // reformat mysql query output - staybyte - 9. June 2001
166 // loic1: set or enum types: slashes single quotes inside options
167 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
168 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'',
169 ',' . $tmp[2]), 1);
170 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
172 $binary = 0;
173 $unsigned = 0;
174 $zerofill = 0;
175 } else {
176 $type = preg_replace('@BINARY@i', '', $type);
177 $type = preg_replace('@ZEROFILL@i', '', $type);
178 $type = preg_replace('@UNSIGNED@i', '', $type);
179 if (empty($type)) {
180 $type = '&nbsp;';
183 $binary = stristr($row['Type'], 'binary');
184 $unsigned = stristr($row['Type'], 'unsigned');
185 $zerofill = stristr($row['Type'], 'zerofill');
187 $strAttribute = '&nbsp;';
188 if ($binary) {
189 $strAttribute = 'BINARY';
191 if ($unsigned) {
192 $strAttribute = 'UNSIGNED';
194 if ($zerofill) {
195 $strAttribute = 'UNSIGNED ZEROFILL';
197 if (!isset($row['Default'])) {
198 if ($row['Null'] != '' && $row['Null'] != 'NO') {
199 $row['Default'] = '<i>NULL</i>';
201 } else {
202 $row['Default'] = htmlspecialchars($row['Default']);
204 $field_name = htmlspecialchars($row['Field']);
206 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
207 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
208 // the latter.
210 * @todo merge this logic with the one in tbl_structure.php
211 * or move it in a function similar to PMA_DBI_get_columns_full()
212 * but based on SHOW CREATE TABLE because information_schema
213 * cannot be trusted in this case (MySQL bug)
215 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']) {
216 $row['Null'] = '';
220 <tr><td>
221 <?php
222 if (isset($pk_array[$row['Field']])) {
223 echo ' <u>' . $field_name . '</u>' . "\n";
224 } else {
225 echo ' ' . $field_name . "\n";
228 </td>
229 <td><?php echo $type; ?><bdo dir="ltr"></bdo></td>
230 <!--<td><?php echo $strAttribute; ?></td>-->
231 <td><?php echo (($row['Null'] == '' || $row['Null'] == 'NO') ? $strNo : $strYes); ?>&nbsp;</td>
232 <td><?php if (isset($row['Default'])) { echo $row['Default']; } ?>&nbsp;</td>
233 <!--<td><?php echo $row['Extra']; ?>&nbsp;</td>-->
234 <?php
235 if ($have_rel) {
236 echo ' <td>';
237 if (isset($res_rel[$field_name])) {
238 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
240 echo '&nbsp;</td>' . "\n";
242 echo ' <td>';
243 $comments = PMA_getComments($db, $table);
244 if (isset($comments[$field_name])) {
245 echo htmlspecialchars($comments[$field_name]);
247 echo '&nbsp;</td>' . "\n";
248 if ($cfgRelation['mimework']) {
249 $mime_map = PMA_getMIME($db, $table, true);
251 echo ' <td>';
252 if (isset($mime_map[$field_name])) {
253 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
255 echo '&nbsp;</td>' . "\n";
258 </tr>
259 <?php
260 } // end while
261 PMA_DBI_free_result($result);
263 </tbody>
264 </table>
265 <?php
266 if (! $tbl_is_view && $db != 'information_schema') {
268 * Displays indexes
270 echo PMA_Index::getView($table, $db, true);
273 * Displays Space usage and row statistics
275 * staybyte - 9 June 2001
277 if ($cfg['ShowStats']) {
278 $nonisam = false;
279 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
280 $nonisam = true;
282 if ($nonisam == false) {
283 // Gets some sizes
284 $mergetable = false;
285 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
286 $mergetable = true;
288 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
289 if ($mergetable == false) {
290 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
292 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
293 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
294 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
295 } else {
296 unset($free_size);
297 unset($free_unit);
298 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
300 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
301 if ($num_rows > 0) {
302 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
305 // Displays them
307 <br /><br />
309 <table border="0" cellspacing="0" cellpadding="0" class="noborder">
310 <tr>
312 <!-- Space usage -->
313 <td valign="top">
314 <big><?php echo $strSpaceUsage . ':'; ?></big>
315 <table width="100%">
316 <tr>
317 <th><?php echo $strType; ?></th>
318 <th colspan="2" align="center"><?php echo $strUsage; ?></th>
319 </tr>
320 <tr>
321 <td style="padding-right: 10px"><?php echo $strData; ?></td>
322 <td align="right"><?php echo $data_size; ?></td>
323 <td><?php echo $data_unit; ?></td>
324 </tr>
325 <?php
326 if (isset($index_size)) {
327 echo "\n";
329 <tr>
330 <td style="padding-right: 10px"><?php echo $strIndex; ?></td>
331 <td align="right"><?php echo $index_size; ?></td>
332 <td><?php echo $index_unit; ?></td>
333 </tr>
334 <?php
336 if (isset($free_size)) {
337 echo "\n";
339 <tr style="color: #bb0000">
340 <td style="padding-right: 10px"><?php echo $strOverhead; ?></td>
341 <td align="right"><?php echo $free_size; ?></td>
342 <td><?php echo $free_unit; ?></td>
343 </tr>
344 <tr>
345 <td style="padding-right: 10px"><?php echo $strEffective; ?></td>
346 <td align="right"><?php echo $effect_size; ?></td>
347 <td><?php echo $effect_unit; ?></td>
348 </tr>
349 <?php
351 if (isset($tot_size) && $mergetable == false) {
352 echo "\n";
354 <tr>
355 <td style="padding-right: 10px"><?php echo $strTotalUC; ?></td>
356 <td align="right"><?php echo $tot_size; ?></td>
357 <td><?php echo $tot_unit; ?></td>
358 </tr>
359 <?php
361 echo "\n";
363 </table>
364 </td>
366 <td width="20">&nbsp;</td>
368 <!-- Rows Statistic -->
369 <td valign="top">
370 <big><?php echo $strRowsStatistic . ':'; ?></big>
371 <table width="100%">
372 <tr>
373 <th><?php echo $strStatement; ?></th>
374 <th align="center"><?php echo $strValue; ?></th>
375 </tr>
376 <?php
377 if (isset($showtable['Row_format'])) {
379 <tr>
380 <td><?php echo ucfirst($strFormat); ?></td>
381 <td align="<?php echo $cell_align_left; ?>">
382 <?php
383 if ($showtable['Row_format'] == 'Fixed') {
384 echo $strFixed;
385 } elseif ($showtable['Row_format'] == 'Dynamic') {
386 echo $strDynamic;
387 } else {
388 echo $showtable['Row_format'];
391 </td>
392 </tr>
393 <?php
395 if (isset($showtable['Rows'])) {
397 <tr>
398 <td><?php echo ucfirst($strRows); ?></td>
399 <td align="right">
400 <?php echo PMA_formatNumber($showtable['Rows'], 0) . "\n"; ?>
401 </td>
402 </tr>
403 <?php
405 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
407 <tr>
408 <td><?php echo ucfirst($strRowLength); ?>&nbsp;&oslash;</td>
409 <td>
410 <?php echo PMA_formatNumber($showtable['Avg_row_length'], 0) . "\n"; ?>
411 </td>
412 </tr>
413 <?php
415 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
417 <tr>
418 <td><?php echo ucfirst($strRowSize); ?>&nbsp;&oslash;</td>
419 <td align="right">
420 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
421 </td>
422 </tr>
423 <?php
425 if (isset($showtable['Auto_increment'])) {
427 <tr>
428 <td><?php echo ucfirst($strNext); ?>&nbsp;Autoindex</td>
429 <td align="right">
430 <?php echo PMA_formatNumber($showtable['Auto_increment'], 0) . "\n"; ?>
431 </td>
432 </tr>
433 <?php
435 if (isset($showtable['Create_time'])) {
437 <tr>
438 <td><?php echo $strStatCreateTime; ?></td>
439 <td align="right">
440 <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
441 </td>
442 </tr>
443 <?php
445 if (isset($showtable['Update_time'])) {
447 <tr>
448 <td><?php echo $strStatUpdateTime; ?></td>
449 <td align="right">
450 <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
451 </td>
452 </tr>
453 <?php
455 if (isset($showtable['Check_time'])) {
457 <tr>
458 <td><?php echo $strStatCheckTime; ?></td>
459 <td align="right">
460 <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
461 </td>
462 </tr>
463 <?php
467 </table>
468 </td>
469 </tr>
470 </table>
472 <?php
473 } // end if ($nonisam == false)
474 } // end if ($cfg['ShowStats'])
476 if ($multi_tables) {
477 unset($num_rows, $show_comment);
478 echo '<hr />' . "\n";
479 } // end if
480 echo '</div>' . "\n";
482 } // end while
485 * Displays the footer
489 <script type="text/javascript">
490 //<![CDATA[
491 function printPage()
493 // Do print the page
494 if (typeof(window.print) != 'undefined') {
495 window.print();
498 //]]>
499 </script>
501 <p class="print_ignore">
502 <input type="button" id="print" value="<?php echo $strPrint; ?>"
503 onclick="printPage()" /></p>
505 <?php
506 require_once './libraries/footer.inc.php';