aspect ratio
[phpmyadmin/crack.git] / tbl_printview.php3
blob90beb6be75e755600d00c2c71f46244336f9d263
1 <?php
2 /* $Id$ */
5 /**
6 * Gets the variables sent or posted to this script, then displays headers
7 */
8 if (!isset($selected_tbl)) {
9 include('./libraries/grab_globals.lib.php3');
10 include('./header.inc.php3');
13 // Check parameters
15 if (!defined('PMA_COMMON_LIB_INCLUDED')) {
16 include('./libraries/common.lib.php3');
19 PMA_checkParameters(array('the_tables'));
20 if (!is_array($the_tables)) {
21 exit();
24 /**
25 * Gets the relations settings
27 require('./libraries/relation.lib.php3');
28 require('./libraries/transformations.lib.php3');
30 $cfgRelation = PMA_getRelationsParam();
33 /**
34 * Defines the url to return to in case of error in a sql statement
36 if (isset($table)) {
37 $err_url = 'tbl_properties.php3?' . PMA_generate_common_url($db, $table);
38 } else {
39 $err_url = 'db_details.php3?' . PMA_generate_common_url($db);
43 /**
44 * Selects the database
46 PMA_mysql_select_db($db);
49 /**
50 * Multi-tables printview thanks to Christophe Gesché from the "MySQL Form
51 * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
53 if (isset($selected_tbl) && is_array($selected_tbl)) {
54 $the_tables = $selected_tbl;
55 } else if (isset($table)) {
56 $the_tables[] = $table;
58 $multi_tables = (count($the_tables) > 1);
60 if ($multi_tables) {
61 $tbl_list = '';
62 while (list($key, $table) = each($the_tables)) {
63 $tbl_list .= (empty($tbl_list) ? '' : ', ')
64 . PMA_backquote(urldecode($table));
66 echo '<b>'. $strShowTables . '&nbsp;:&nbsp;' . $tbl_list . '</b>' . "\n";
67 echo '<hr />' . "\n";
68 } // end if
70 $tables_cnt = count($the_tables);
71 reset($the_tables);
72 $counter = 0;
74 while (list($key, $table) = each($the_tables)) {
75 $table = urldecode($table);
76 if ($counter + 1 >= $tables_cnt) {
77 $breakstyle = '';
78 } else {
79 $breakstyle = ' style="page-break-after: always;"';
81 $counter++;
82 echo '<div' . $breakstyle . '>' . "\n";
83 echo '<h1>' . $table . '</h1>' . "\n";
85 /**
86 * Gets table informations
88 // The 'show table' statement works correct since 3.23.03
89 if (PMA_MYSQL_INT_VERSION >= 32303) {
90 $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
91 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
92 $showtable = PMA_mysql_fetch_array($result);
93 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
94 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
95 } else {
96 $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table);
97 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
98 $showtable = array();
99 $num_rows = PMA_mysql_result($result, 0, 'count');
100 $show_comment = '';
101 } // end display comments
102 if ($result) {
103 mysql_free_result($result);
108 * Gets table keys and retains them
110 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
111 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
112 $primary = '';
113 $indexes = array();
114 $lastIndex = '';
115 $indexes_info = array();
116 $indexes_data = array();
117 $pk_array = array(); // will be use to emphasis prim. keys in the table
118 // view
119 while ($row = PMA_mysql_fetch_array($result)) {
120 // Backups the list of primary keys
121 if ($row['Key_name'] == 'PRIMARY') {
122 $primary .= $row['Column_name'] . ', ';
123 $pk_array[$row['Column_name']] = 1;
125 // Retains keys informations
126 if ($row['Key_name'] != $lastIndex ){
127 $indexes[] = $row['Key_name'];
128 $lastIndex = $row['Key_name'];
130 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
131 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
132 if (isset($row['Cardinality'])) {
133 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
135 // I don't know what does following column mean....
136 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
137 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
139 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
140 if (isset($row['Sub_part'])) {
141 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
144 } // end while
145 if ($result) {
146 mysql_free_result($result);
151 * Gets fields properties
153 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
154 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
155 $fields_cnt = mysql_num_rows($result);
157 // Check if we can use Relations (Mike Beck)
158 if (!empty($cfgRelation['relation'])) {
159 // Find which tables are related with the current one and write it in
160 // an array
161 $res_rel = PMA_getForeigners($db, $table);
163 if (count($res_rel) > 0) {
164 $have_rel = TRUE;
165 } else {
166 $have_rel = FALSE;
169 else {
170 $have_rel = FALSE;
171 } // end if
175 * Displays the comments of the table if MySQL >= 3.23
177 if (!empty($show_comment)) {
178 echo $strTableComments . '&nbsp;:&nbsp;' . $show_comment . '<br /><br />';
182 * Displays the table structure
186 <!-- TABLE INFORMATIONS -->
187 <table width="95%" bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
188 <tr>
189 <th width="50"><?php echo $strField; ?></th>
190 <th width="80"><?php echo $strType; ?></th>
191 <!--<th width="50"><?php echo $strAttr; ?></th>-->
192 <th width="40"><?php echo $strNull; ?></th>
193 <th width="70"><?php echo $strDefault; ?></th>
194 <!--<th width="50"><?php echo $strExtra; ?></th>-->
195 <?php
196 echo "\n";
197 if ($have_rel) {
198 echo ' <th>' . $strLinksTo . '</th>' . "\n";
200 if ($cfgRelation['commwork']) {
201 echo ' <th>' . $strComments . '</th>' . "\n";
203 if ($cfgRelation['mimework']) {
204 echo ' <th>MIME</th>' . "\n";
207 </tr>
209 <?php
210 $i = 0;
211 while ($row = PMA_mysql_fetch_array($result)) {
212 $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
213 $i++;
215 $type = $row['Type'];
216 // reformat mysql query output - staybyte - 9. June 2001
217 // loic1: set or enum types: slashes single quotes inside options
218 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
219 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
220 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
221 $type_nowrap = '';
223 $binary = 0;
224 $unsigned = 0;
225 $zerofill = 0;
226 } else {
227 $type_nowrap = ' nowrap="nowrap"';
228 $type = eregi_replace('BINARY', '', $type);
229 $type = eregi_replace('ZEROFILL', '', $type);
230 $type = eregi_replace('UNSIGNED', '', $type);
231 if (empty($type)) {
232 $type = '&nbsp;';
235 $binary = eregi('BINARY', $row['Type'], $test);
236 $unsigned = eregi('UNSIGNED', $row['Type'], $test);
237 $zerofill = eregi('ZEROFILL', $row['Type'], $test);
239 $strAttribute = '&nbsp;';
240 if ($binary) {
241 $strAttribute = 'BINARY';
243 if ($unsigned) {
244 $strAttribute = 'UNSIGNED';
246 if ($zerofill) {
247 $strAttribute = 'UNSIGNED ZEROFILL';
249 if (!isset($row['Default'])) {
250 if ($row['Null'] != '') {
251 $row['Default'] = '<i>NULL</i>';
253 } else {
254 $row['Default'] = htmlspecialchars($row['Default']);
256 $field_name = htmlspecialchars($row['Field']);
257 echo "\n";
259 <tr>
260 <td width="50" class="print" nowrap="nowrap">
261 <?php
262 if (isset($pk_array[$row['Field']])) {
263 echo ' <u>' . $field_name . '</u>&nbsp;' . "\n";
264 } else {
265 echo ' ' . $field_name . '&nbsp;' . "\n";
268 </td>
269 <td width="80" class="print"<?php echo $type_nowrap; ?>><?php echo $type; ?><bdo dir="ltr"></bdo></td>
270 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $strAttribute; ?></td>-->
271 <td width="40" class="print"><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?>&nbsp;</td>
272 <td width="70" class="print" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?>&nbsp;</td>
273 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?>&nbsp;</td>-->
274 <?php
275 echo "\n";
276 if ($have_rel) {
277 echo ' <td class="print">';
278 if (isset($res_rel[$field_name])) {
279 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] );
281 echo '&nbsp;</td>' . "\n";
283 if ($cfgRelation['commwork']) {
284 echo ' <td class="print">';
285 $comments = PMA_getComments($db, $table);
286 if (isset($comments[$field_name])) {
287 echo htmlspecialchars($comments[$field_name]);
289 echo '&nbsp;</td>' . "\n";
291 if ($cfgRelation['mimework']) {
292 $mime_map = PMA_getMIME($db, $table, true);
294 echo ' <td class="print">';
295 if (isset($mime_map[$field_name])) {
296 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
298 echo '&nbsp;</td>' . "\n";
301 </tr>
302 <?php
303 } // end while
304 mysql_free_result($result);
306 echo "\n";
308 </table>
311 <?php
313 * Displays indexes
315 $index_count = (isset($indexes))
316 ? count($indexes)
317 : 0;
318 if ($index_count > 0) {
319 echo "\n";
321 <br /><br />
323 <!-- Indexes -->
324 &nbsp;<big><?php echo $strIndexes . '&nbsp;:'; ?></big>
325 <table bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
326 <tr>
327 <th><?php echo $strKeyname; ?></th>
328 <th><?php echo $strType; ?></th>
329 <th><?php echo $strCardinality; ?></th>
330 <th colspan="2"><?php echo $strField; ?></th>
331 </tr>
332 <?php
333 echo "\n";
334 while (list($index_no, $index_name) = each($indexes)) {
335 $cell_bgd = (($index_no % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']);
336 $index_td = ' <td class="print" rowspan="' . count($indexes_info[$index_name]['Sequences']) . '">' . "\n";
337 echo ' <tr>' . "\n";
338 echo $index_td
339 . ' ' . htmlspecialchars($index_name) . "\n"
340 . ' </td>' . "\n";
342 if ($indexes_info[$index_name]['Comment'] == 'FULLTEXT') {
343 $index_type = 'FULLTEXT';
344 } else if ($index_name == 'PRIMARY') {
345 $index_type = 'PRIMARY';
346 } else if ($indexes_info[$index_name]['Non_unique'] == '0') {
347 $index_type = 'UNIQUE';
348 } else {
349 $index_type = 'INDEX';
351 echo $index_td
352 . ' ' . $index_type . "\n"
353 . ' </td>' . "\n";
355 echo $index_td
356 . ' ' . (isset($indexes_info[$index_name]['Cardinality']) ? $indexes_info[$index_name]['Cardinality'] : $strNone) . "\n"
357 . ' </td>' . "\n";
359 while (list($row_no, $seq_index) = each($indexes_info[$index_name]['Sequences'])) {
360 if ($row_no > 0) {
361 echo ' <tr>' . "\n";
363 if (!empty($indexes_data[$index_name][$seq_index]['Sub_part'])) {
364 echo ' <td class="print">' . "\n"
365 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
366 . ' </td>' . "\n";
367 echo ' <td align="right" class="print">' . "\n"
368 . ' ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n"
369 . ' </td>' . "\n";
370 echo ' </tr>' . "\n";
371 } else {
372 echo ' <td class="print" colspan="2">' . "\n"
373 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
374 . ' </td>' . "\n";
375 echo ' </tr>' . "\n";
377 } // end while
378 } // end while
379 echo "\n";
381 </table>
382 <?php
383 echo "\n";
384 } // end display indexes
388 * Displays Space usage and row statistics
390 * staybyte - 9 June 2001
392 if ($cfg['ShowStats']) {
393 $nonisam = FALSE;
394 if (isset($showtable['Type']) && !eregi('ISAM|HEAP', $showtable['Type'])) {
395 $nonisam = TRUE;
397 if (PMA_MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE) {
398 // Gets some sizes
399 $mergetable = FALSE;
400 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
401 $mergetable = TRUE;
403 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
404 if ($mergetable == FALSE) {
405 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
407 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
408 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
409 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
410 } else {
411 unset($free_size);
412 unset($free_unit);
413 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
415 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
416 if ($num_rows > 0) {
417 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
420 // Displays them
422 <br /><br />
424 <table border="0" cellspacing="0" cellpadding="0">
425 <tr>
427 <!-- Space usage -->
428 <td class="print" valign="top">
429 &nbsp;<big><?php echo $strSpaceUsage . '&nbsp;:'; ?></big>
430 <table width="100%" bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
431 <tr>
432 <th><?php echo $strType; ?></th>
433 <th colspan="2" align="center"><?php echo $strUsage; ?></th>
434 </tr>
435 <tr>
436 <td class="print" style="padding-right: 10px"><?php echo $strData; ?></td>
437 <td align="right" class="print" nowrap="nowrap"><?php echo $data_size; ?></td>
438 <td class="print"><?php echo $data_unit; ?></td>
439 </tr>
440 <?php
441 if (isset($index_size)) {
442 echo "\n";
444 <tr>
445 <td class="print" style="padding-right: 10px"><?php echo $strIndex; ?></td>
446 <td align="right" class="print" nowrap="nowrap"><?php echo $index_size; ?></td>
447 <td class="print"><?php echo $index_unit; ?></td>
448 </tr>
449 <?php
451 if (isset($free_size)) {
452 echo "\n";
454 <tr style="color: #bb0000">
455 <td class="print" style="padding-right: 10px"><?php echo $strOverhead; ?></td>
456 <td align="right" class="print" nowrap="nowrap"><?php echo $free_size; ?></td>
457 <td class="print"><?php echo $free_unit; ?></td>
458 </tr>
459 <tr>
460 <td class="print" style="padding-right: 10px"><?php echo $strEffective; ?></td>
461 <td align="right" class="print" nowrap="nowrap"><?php echo $effect_size; ?></td>
462 <td class="print"><?php echo $effect_unit; ?></td>
463 </tr>
464 <?php
466 if (isset($tot_size) && $mergetable == FALSE) {
467 echo "\n";
469 <tr>
470 <td class="print" style="padding-right: 10px"><?php echo $strTotalUC; ?></td>
471 <td align="right" class="print" nowrap="nowrap"><?php echo $tot_size; ?></td>
472 <td class="print"><?php echo $tot_unit; ?></td>
473 </tr>
474 <?php
476 echo "\n";
478 </table>
479 </td>
481 <td width="20" class="print">&nbsp;</td>
483 <!-- Rows Statistic -->
484 <td valign="top">
485 &nbsp;<big><?php echo $strRowsStatistic . '&nbsp;:'; ?></big>
486 <table width=100% bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
487 <tr>
488 <th><?php echo $strStatement; ?></th>
489 <th align="center"><?php echo $strValue; ?></th>
490 </tr>
491 <?php
492 $i = 0;
493 if (isset($showtable['Row_format'])) {
494 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
495 echo "\n";
497 <tr>
498 <td class="print"><?php echo ucfirst($strFormat); ?></td>
499 <td align="<?php echo $cell_align_left; ?>" class="print" nowrap="nowrap">
500 <?php
501 echo ' ';
502 if ($showtable['Row_format'] == 'Fixed') {
503 echo $strFixed;
504 } else if ($showtable['Row_format'] == 'Dynamic') {
505 echo $strDynamic;
506 } else {
507 echo $showtable['Row_format'];
509 echo "\n";
511 </td>
512 </tr>
513 <?php
515 if (isset($showtable['Rows'])) {
516 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
517 echo "\n";
519 <tr>
520 <td class="print"><?php echo ucfirst($strRows); ?></td>
521 <td align="right" class="print" nowrap="nowrap">
522 <?php echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
523 </td>
524 </tr>
525 <?php
527 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
528 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
529 echo "\n";
531 <tr>
532 <td class="print"><?php echo ucfirst($strRowLength); ?>&nbsp;&oslash;</td>
533 <td class="print" nowrap="nowrap">
534 <?php echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
535 </td>
536 </tr>
537 <?php
539 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == FALSE) {
540 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
541 echo "\n";
543 <tr>
544 <td class="print"><?php echo ucfirst($strRowSize); ?>&nbsp;&oslash;</td>
545 <td align="right" class="print" nowrap="nowrap">
546 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
547 </td>
548 </tr>
549 <?php
551 if (isset($showtable['Auto_increment'])) {
552 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
553 echo "\n";
555 <tr>
556 <td class="print"><?php echo ucfirst($strNext); ?>&nbsp;Autoindex</td>
557 <td align="right" class="print" nowrap="nowrap">
558 <?php echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
559 </td>
560 </tr>
561 <?php
563 echo "\n";
565 if (isset($showtable['Create_time'])) {
566 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
567 echo "\n";
569 <tr>
570 <td class="print"><?php echo $strStatCreateTime; ?></td>
571 <td align="right" class="print" nowrap="nowrap">
572 <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
573 </td>
574 </tr>
575 <?php
577 echo "\n";
579 if (isset($showtable['Update_time'])) {
580 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
581 echo "\n";
583 <tr>
584 <td class="print"><?php echo $strStatUpdateTime; ?></td>
585 <td align="right" class="print" nowrap="nowrap">
586 <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
587 </td>
588 </tr>
589 <?php
591 echo "\n";
593 if (isset($showtable['Check_time'])) {
594 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
595 echo "\n";
597 <tr>
598 <td class="print"><?php echo $strStatCheckTime; ?></td>
599 <td align="right" class="print" nowrap="nowrap">
600 <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
601 </td>
602 </tr>
603 <?php
605 echo "\n";
607 </table>
608 </td>
609 </tr>
610 </table>
612 <?php
613 } // end if (PMA_MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE)
614 } // end if ($cfg['ShowStats'])
616 echo "\n";
617 if ($multi_tables) {
618 unset($ret_keys);
619 unset($num_rows);
620 unset($show_comment);
621 echo '<hr />' . "\n";
622 } // end if
623 echo '</div>' . "\n";
625 } // end while
630 * Displays the footer
632 echo "\n";
634 <script type="text/javascript" language="javascript1.2">
635 <!--
636 function printPage()
638 document.getElementById('print').style.visibility = 'hidden';
639 // Do print the page
640 if (typeof(window.print) != 'undefined') {
641 window.print();
643 document.getElementById('print').style.visibility = '';
645 //-->
646 </script>
647 <?php
648 echo '<br /><br />&nbsp;<input type="button" style="visibility: ; width: 100px; height: 25px" id="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
650 require('./footer.inc.php3');