Ensured that the correct font families are used.
[phpmyadmin/crack.git] / tbl_printview.php3
blobc2a27a4bbcf538b9a2a4ae846ec3a76bdaf5afc8
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');
14 /**
15 * Gets the relations settings
17 require('./libraries/relation.lib.php3');
18 $cfgRelation = PMA_getRelationsParam();
21 /**
22 * Defines the url to return to in case of error in a sql statement
24 if (isset($table)) {
25 $err_url = 'tbl_properties.php3?' . PMA_generate_common_url($db, $table);
26 } else {
27 $err_url = 'db_details.php3?' . PMA_generate_common_url($db);
31 /**
32 * Selects the database
34 PMA_mysql_select_db($db);
37 /**
38 * Multi-tables printview thanks to Christophe Gesché from the "MySQL Form
39 * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
41 if (isset($selected_tbl) && is_array($selected_tbl)) {
42 $the_tables = $selected_tbl;
43 } else if (isset($table)) {
44 $the_tables[] = $table;
46 $multi_tables = (count($the_tables) > 1);
48 if ($multi_tables) {
49 $tbl_list = '';
50 while (list($key, $table) = each($the_tables)) {
51 $tbl_list .= (empty($tbl_list) ? '' : ', ')
52 . PMA_backquote(urldecode($table));
54 echo '<b>'. $strShowTables . '&nbsp;:&nbsp;' . $tbl_list . '</b>' . "\n";
55 echo '<hr />' . "\n";
56 } // end if
58 $tables_cnt = count($the_tables);
59 reset($the_tables);
60 $counter = 0;
62 while (list($key, $table) = each($the_tables)) {
63 $table = urldecode($table);
64 if ($counter + 1 >= $tables_cnt) {
65 $breakstyle = '';
66 } else {
67 $breakstyle = ' style="page-break-after: always;"';
69 $counter++;
70 echo '<div' . $breakstyle . '>' . "\n";
71 echo '<h1>' . $table . '</h1>' . "\n";
73 /**
74 * Gets table informations
76 // The 'show table' statement works correct since 3.23.03
77 if (PMA_MYSQL_INT_VERSION >= 32303) {
78 $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
79 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
80 $showtable = PMA_mysql_fetch_array($result);
81 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
82 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
83 } else {
84 $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table);
85 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
86 $showtable = array();
87 $num_rows = PMA_mysql_result($result, 0, 'count');
88 $show_comment = '';
89 } // end display comments
90 if ($result) {
91 mysql_free_result($result);
95 /**
96 * Gets table keys and retains them
98 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
99 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
100 $primary = '';
101 $indexes = array();
102 $lastIndex = '';
103 $indexes_info = array();
104 $indexes_data = array();
105 $pk_array = array(); // will be use to emphasis prim. keys in the table
106 // view
107 while ($row = PMA_mysql_fetch_array($result)) {
108 // Backups the list of primary keys
109 if ($row['Key_name'] == 'PRIMARY') {
110 $primary .= $row['Column_name'] . ', ';
111 $pk_array[$row['Column_name']] = 1;
113 // Retains keys informations
114 if ($row['Key_name'] != $lastIndex ){
115 $indexes[] = $row['Key_name'];
116 $lastIndex = $row['Key_name'];
118 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
119 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
120 if (isset($row['Cardinality'])) {
121 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
123 // I don't know what does following column mean....
124 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
125 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
127 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
128 if (isset($row['Sub_part'])) {
129 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
132 } // end while
133 if ($result) {
134 mysql_free_result($result);
139 * Gets fields properties
141 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
142 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
143 $fields_cnt = mysql_num_rows($result);
145 // Check if we can use Relations (Mike Beck)
146 if (!empty($cfgRelation['relation'])) {
147 // Find which tables are related with the current one and write it in
148 // an array
149 $res_rel = PMA_getForeigners($db, $table);
151 if (count($res_rel) > 0) {
152 $have_rel = TRUE;
153 } else {
154 $have_rel = FALSE;
157 else {
158 $have_rel = FALSE;
159 } // end if
163 * Displays the comments of the table if MySQL >= 3.23
165 if (!empty($show_comment)) {
166 echo $strTableComments . '&nbsp;:&nbsp;' . $show_comment . '<br /><br />';
170 * Displays the table structure
174 <!-- TABLE INFORMATIONS -->
175 <table width="95%" bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
176 <tr>
177 <th width="50"><?php echo $strField; ?></th>
178 <th width="80"><?php echo $strType; ?></th>
179 <!--<th width="50"><?php echo $strAttr; ?></th>-->
180 <th width="40"><?php echo $strNull; ?></th>
181 <th width="70"><?php echo $strDefault; ?></th>
182 <!--<th width="50"><?php echo $strExtra; ?></th>-->
183 <?php
184 echo "\n";
185 if ($have_rel) {
186 echo ' <th>' . $strLinksTo . '</th>' . "\n";
188 if ($cfgRelation['commwork']) {
189 echo ' <th>' . $strComments . '</th>' . "\n";
192 </tr>
194 <?php
195 $i = 0;
196 while ($row = PMA_mysql_fetch_array($result)) {
197 $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
198 $i++;
200 $type = $row['Type'];
201 // reformat mysql query output - staybyte - 9. June 2001
202 // loic1: set or enum types: slashes single quotes inside options
203 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
204 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
205 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
206 $type_nowrap = '';
208 $binary = 0;
209 $unsigned = 0;
210 $zerofill = 0;
211 } else {
212 $type_nowrap = ' nowrap="nowrap"';
213 $type = eregi_replace('BINARY', '', $type);
214 $type = eregi_replace('ZEROFILL', '', $type);
215 $type = eregi_replace('UNSIGNED', '', $type);
216 if (empty($type)) {
217 $type = '&nbsp;';
220 $binary = eregi('BINARY', $row['Type'], $test);
221 $unsigned = eregi('UNSIGNED', $row['Type'], $test);
222 $zerofill = eregi('ZEROFILL', $row['Type'], $test);
224 $strAttribute = '&nbsp;';
225 if ($binary) {
226 $strAttribute = 'BINARY';
228 if ($unsigned) {
229 $strAttribute = 'UNSIGNED';
231 if ($zerofill) {
232 $strAttribute = 'UNSIGNED ZEROFILL';
234 if (!isset($row['Default'])) {
235 if ($row['Null'] != '') {
236 $row['Default'] = '<i>NULL</i>';
238 } else {
239 $row['Default'] = htmlspecialchars($row['Default']);
241 $field_name = htmlspecialchars($row['Field']);
242 echo "\n";
244 <tr>
245 <td width="50" class="print" nowrap="nowrap">
246 <?php
247 if (isset($pk_array[$row['Field']])) {
248 echo ' <u>' . $field_name . '</u>&nbsp;' . "\n";
249 } else {
250 echo ' ' . $field_name . '&nbsp;' . "\n";
253 </td>
254 <td width="80" class="print"<?php echo $type_nowrap; ?>><?php echo $type; ?><bdo dir="ltr"></bdo></td>
255 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $strAttribute; ?></td>-->
256 <td width="40" class="print"><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?>&nbsp;</td>
257 <td width="70" class="print" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?>&nbsp;</td>
258 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?>&nbsp;</td>-->
259 <?php
260 echo "\n";
261 if ($have_rel) {
262 echo ' <td class="print">';
263 if (isset($res_rel[$field_name])) {
264 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] );
266 echo '&nbsp;</td>' . "\n";
268 if ($cfgRelation['commwork']) {
269 echo ' <td class="print">';
270 $comments = PMA_getComments($db, $table);
271 if (isset($comments[$field_name])) {
272 echo htmlspecialchars($comments[$field_name]);
274 echo '&nbsp;</td>' . "\n";
277 </tr>
278 <?php
279 } // end while
280 mysql_free_result($result);
282 echo "\n";
284 </table>
287 <?php
289 * Displays indexes
291 $index_count = (isset($indexes))
292 ? count($indexes)
293 : 0;
294 if ($index_count > 0) {
295 echo "\n";
297 <br /><br />
299 <!-- Indexes -->
300 &nbsp;<big><?php echo $strIndexes . '&nbsp;:'; ?></big>
301 <table bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
302 <tr>
303 <th><?php echo $strKeyname; ?></th>
304 <th><?php echo $strType; ?></th>
305 <th><?php echo $strCardinality; ?></th>
306 <th colspan="2"><?php echo $strField; ?></th>
307 </tr>
308 <?php
309 echo "\n";
310 while (list($index_no, $index_name) = each($indexes)) {
311 $cell_bgd = (($index_no % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']);
312 $index_td = ' <td class="print" rowspan="' . count($indexes_info[$index_name]['Sequences']) . '">' . "\n";
313 echo ' <tr>' . "\n";
314 echo $index_td
315 . ' ' . htmlspecialchars($index_name) . "\n"
316 . ' </td>' . "\n";
318 if ($indexes_info[$index_name]['Comment'] == 'FULLTEXT') {
319 $index_type = 'FULLTEXT';
320 } else if ($index_name == 'PRIMARY') {
321 $index_type = 'PRIMARY';
322 } else if ($indexes_info[$index_name]['Non_unique'] == '0') {
323 $index_type = 'UNIQUE';
324 } else {
325 $index_type = 'INDEX';
327 echo $index_td
328 . ' ' . $index_type . "\n"
329 . ' </td>' . "\n";
331 echo $index_td
332 . ' ' . (isset($indexes_info[$index_name]['Cardinality']) ? $indexes_info[$index_name]['Cardinality'] : $strNone) . "\n"
333 . ' </td>' . "\n";
335 while (list($row_no, $seq_index) = each($indexes_info[$index_name]['Sequences'])) {
336 if ($row_no > 0) {
337 echo ' <tr>' . "\n";
339 if (!empty($indexes_data[$index_name][$seq_index]['Sub_part'])) {
340 echo ' <td class="print">' . "\n"
341 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
342 . ' </td>' . "\n";
343 echo ' <td align="right" class="print">' . "\n"
344 . ' ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n"
345 . ' </td>' . "\n";
346 echo ' </tr>' . "\n";
347 } else {
348 echo ' <td class="print" colspan="2">' . "\n"
349 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
350 . ' </td>' . "\n";
351 echo ' </tr>' . "\n";
353 } // end while
354 } // end while
355 echo "\n";
357 </table>
358 <?php
359 echo "\n";
360 } // end display indexes
364 * Displays Space usage and row statistics
366 * staybyte - 9 June 2001
368 if ($cfg['ShowStats']) {
369 $nonisam = FALSE;
370 if (isset($showtable['Type']) && !eregi('ISAM|HEAP', $showtable['Type'])) {
371 $nonisam = TRUE;
373 if (PMA_MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE) {
374 // Gets some sizes
375 $mergetable = FALSE;
376 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
377 $mergetable = TRUE;
379 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
380 if ($mergetable == FALSE) {
381 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
383 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
384 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
385 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
386 } else {
387 unset($free_size);
388 unset($free_unit);
389 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
391 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
392 if ($num_rows > 0) {
393 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
396 // Displays them
398 <br /><br />
400 <table border="0" cellspacing="0" cellpadding="0">
401 <tr>
403 <!-- Space usage -->
404 <td class="print" valign="top">
405 &nbsp;<big><?php echo $strSpaceUsage . '&nbsp;:'; ?></big>
406 <table width="100%" bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
407 <tr>
408 <th><?php echo $strType; ?></th>
409 <th colspan="2" align="center"><?php echo $strUsage; ?></th>
410 </tr>
411 <tr>
412 <td class="print" style="padding-right: 10px"><?php echo $strData; ?></td>
413 <td align="right" class="print" nowrap="nowrap"><?php echo $data_size; ?></td>
414 <td class="print"><?php echo $data_unit; ?></td>
415 </tr>
416 <?php
417 if (isset($index_size)) {
418 echo "\n";
420 <tr>
421 <td class="print" style="padding-right: 10px"><?php echo $strIndex; ?></td>
422 <td align="right" class="print" nowrap="nowrap"><?php echo $index_size; ?></td>
423 <td class="print"><?php echo $index_unit; ?></td>
424 </tr>
425 <?php
427 if (isset($free_size)) {
428 echo "\n";
430 <tr style="color: #bb0000">
431 <td class="print" style="padding-right: 10px"><?php echo $strOverhead; ?></td>
432 <td align="right" class="print" nowrap="nowrap"><?php echo $free_size; ?></td>
433 <td class="print"><?php echo $free_unit; ?></td>
434 </tr>
435 <tr>
436 <td class="print" style="padding-right: 10px"><?php echo $strEffective; ?></td>
437 <td align="right" class="print" nowrap="nowrap"><?php echo $effect_size; ?></td>
438 <td class="print"><?php echo $effect_unit; ?></td>
439 </tr>
440 <?php
442 if (isset($tot_size) && $mergetable == FALSE) {
443 echo "\n";
445 <tr>
446 <td class="print" style="padding-right: 10px"><?php echo $strTotalUC; ?></td>
447 <td align="right" class="print" nowrap="nowrap"><?php echo $tot_size; ?></td>
448 <td class="print"><?php echo $tot_unit; ?></td>
449 </tr>
450 <?php
452 echo "\n";
454 </table>
455 </td>
457 <td width="20" class="print">&nbsp;</td>
459 <!-- Rows Statistic -->
460 <td valign="top">
461 &nbsp;<big><?php echo $strRowsStatistic . '&nbsp;:'; ?></big>
462 <table width=100% bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
463 <tr>
464 <th><?php echo $strStatement; ?></th>
465 <th align="center"><?php echo $strValue; ?></th>
466 </tr>
467 <?php
468 $i = 0;
469 if (isset($showtable['Row_format'])) {
470 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
471 echo "\n";
473 <tr>
474 <td class="print"><?php echo ucfirst($strFormat); ?></td>
475 <td align="<?php echo $cell_align_left; ?>" class="print" nowrap="nowrap">
476 <?php
477 echo ' ';
478 if ($showtable['Row_format'] == 'Fixed') {
479 echo $strFixed;
480 } else if ($showtable['Row_format'] == 'Dynamic') {
481 echo $strDynamic;
482 } else {
483 echo $showtable['Row_format'];
485 echo "\n";
487 </td>
488 </tr>
489 <?php
491 if (isset($showtable['Rows'])) {
492 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
493 echo "\n";
495 <tr>
496 <td class="print"><?php echo ucfirst($strRows); ?></td>
497 <td align="right" class="print" nowrap="nowrap">
498 <?php echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
499 </td>
500 </tr>
501 <?php
503 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
504 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
505 echo "\n";
507 <tr>
508 <td class="print"><?php echo ucfirst($strRowLength); ?>&nbsp;&oslash;</td>
509 <td class="print" nowrap="nowrap">
510 <?php echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
511 </td>
512 </tr>
513 <?php
515 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == FALSE) {
516 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
517 echo "\n";
519 <tr>
520 <td class="print"><?php echo ucfirst($strRowSize); ?>&nbsp;&oslash;</td>
521 <td align="right" class="print" nowrap="nowrap">
522 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
523 </td>
524 </tr>
525 <?php
527 if (isset($showtable['Auto_increment'])) {
528 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
529 echo "\n";
531 <tr>
532 <td class="print"><?php echo ucfirst($strNext); ?>&nbsp;Autoindex</td>
533 <td align="right" class="print" nowrap="nowrap">
534 <?php echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
535 </td>
536 </tr>
537 <?php
539 echo "\n";
541 </table>
542 </td>
543 </tr>
544 </table>
546 <?php
547 } // end if (PMA_MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE)
548 } // end if ($cfg['ShowStats'])
550 echo "\n";
551 if ($multi_tables) {
552 unset($ret_keys);
553 unset($num_rows);
554 unset($show_comment);
555 echo '<hr />' . "\n";
556 } // end if
557 echo '</div>' . "\n";
559 } // end while
564 * Displays the footer
566 echo "\n";
568 <script type="text/javascript" language="javascript1.2">
569 <!--
570 function printPage()
572 document.all.print.style.visibility = 'hidden';
573 // Do print the page
574 if (typeof(window.print) != 'undefined') {
575 window.print();
577 document.all.print.style.visibility = '';
579 //-->
580 </script>
581 <?php
582 echo '<br /><br />&nbsp;<input type="button" style="visibility: ; width: 100px; height: 25px" name="print" value="Print" onclick="printPage()">' . "\n";
584 require('./footer.inc.php3');