some updates
[phpmyadmin/crack.git] / tbl_printview.php3
blob78ece0d7d68b6007cb16707a6369e7c641e807fc
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'
26 . '?lang=' . $lang
27 . '&amp;convcharset=' . $convcharset
28 . '&amp;server=' . $server
29 . '&amp;db=' . urlencode($db)
30 . '&amp;table=' . urlencode($table);
31 } else {
32 $err_url = 'db_details.php3'
33 . '?lang=' . $lang
34 . '&amp;convcharset=' . $convcharset
35 . '&amp;server=' . $server
36 . '&amp;db=' . urlencode($db);
40 /**
41 * Selects the database
43 PMA_mysql_select_db($db);
46 /**
47 * Multi-tables printview thanks to Christophe Gesché from the "MySQL Form
48 * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
50 if (isset($selected_tbl) && is_array($selected_tbl)) {
51 $the_tables = $selected_tbl;
52 } else if (isset($table)) {
53 $the_tables[] = $table;
55 $multi_tables = (count($the_tables) > 1);
57 if ($multi_tables) {
58 $tbl_list = '';
59 while (list($key, $table) = each($the_tables)) {
60 $tbl_list .= (empty($tbl_list) ? '' : ', ')
61 . PMA_backquote(urldecode($table));
63 echo '<b>'. $strShowTables . '&nbsp;:&nbsp;' . $tbl_list . '</b>' . "\n";
64 echo '<hr />' . "\n";
65 } // end if
67 $tables_cnt = count($the_tables);
68 reset($the_tables);
69 $counter = 0;
71 while (list($key, $table) = each($the_tables)) {
72 $table = urldecode($table);
73 if ($counter + 1 >= $tables_cnt) {
74 $breakstyle = '';
75 } else {
76 $breakstyle = ' style="page-break-after: always;"';
78 $counter++;
79 echo '<div' . $breakstyle . '>' . "\n";
80 echo '<h1>' . $table . '</h1>' . "\n";
82 /**
83 * Gets table informations
85 // The 'show table' statement works correct since 3.23.03
86 if (PMA_MYSQL_INT_VERSION >= 32303) {
87 $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
88 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
89 $showtable = PMA_mysql_fetch_array($result);
90 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
91 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
92 } else {
93 $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table);
94 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
95 $showtable = array();
96 $num_rows = PMA_mysql_result($result, 0, 'count');
97 $show_comment = '';
98 } // end display comments
99 if ($result) {
100 mysql_free_result($result);
105 * Gets table keys and retains them
107 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
108 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
109 $primary = '';
110 $indexes = array();
111 $lastIndex = '';
112 $indexes_info = array();
113 $indexes_data = array();
114 $pk_array = array(); // will be use to emphasis prim. keys in the table
115 // view
116 while ($row = PMA_mysql_fetch_array($result)) {
117 // Backups the list of primary keys
118 if ($row['Key_name'] == 'PRIMARY') {
119 $primary .= $row['Column_name'] . ', ';
120 $pk_array[$row['Column_name']] = 1;
122 // Retains keys informations
123 if ($row['Key_name'] != $lastIndex ){
124 $indexes[] = $row['Key_name'];
125 $lastIndex = $row['Key_name'];
127 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
128 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
129 if (isset($row['Cardinality'])) {
130 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
132 // I don't know what does following column mean....
133 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
134 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
136 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
137 if (isset($row['Sub_part'])) {
138 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
141 } // end while
142 if ($result) {
143 mysql_free_result($result);
148 * Gets fields properties
150 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
151 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
152 $fields_cnt = mysql_num_rows($result);
154 // Check if we can use Relations (Mike Beck)
155 if (!empty($cfgRelation['relation'])) {
156 // Find which tables are related with the current one and write it in
157 // an array
158 $res_rel = PMA_getForeigners($db, $table);
160 if (count($res_rel) > 0) {
161 $have_rel = TRUE;
162 } else {
163 $have_rel = FALSE;
166 else {
167 $have_rel = FALSE;
168 } // end if
172 * Displays the comments of the table if MySQL >= 3.23
174 if (!empty($show_comment)) {
175 echo $strTableComments . '&nbsp;:&nbsp;' . $show_comment . '<br /><br />';
179 * Displays the table structure
183 <!-- TABLE INFORMATIONS -->
184 <table width="95%" bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
185 <tr>
186 <th width="50"><?php echo $strField; ?></th>
187 <th width="80"><?php echo $strType; ?></th>
188 <!--<th width="50"><?php echo $strAttr; ?></th>-->
189 <th width="40"><?php echo $strNull; ?></th>
190 <th width="70"><?php echo $strDefault; ?></th>
191 <!--<th width="50"><?php echo $strExtra; ?></th>-->
192 <?php
193 echo "\n";
194 if ($have_rel) {
195 echo ' <th>' . $strLinksTo . '</th>' . "\n";
197 if ($cfgRelation['commwork']) {
198 echo ' <th>' . $strComments . '</th>' . "\n";
201 </tr>
203 <?php
204 $i = 0;
205 while ($row = PMA_mysql_fetch_array($result)) {
206 $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
207 $i++;
209 $type = $row['Type'];
210 // reformat mysql query output - staybyte - 9. June 2001
211 // loic1: set or enum types: slashes single quotes inside options
212 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
213 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
214 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
215 $type_nowrap = '';
216 } else {
217 $type_nowrap = ' nowrap="nowrap"';
219 $type = eregi_replace('BINARY', '', $type);
220 $type = eregi_replace('ZEROFILL', '', $type);
221 $type = eregi_replace('UNSIGNED', '', $type);
222 if (empty($type)) {
223 $type = '&nbsp;';
226 $binary = eregi('BINARY', $row['Type'], $test);
227 $unsigned = eregi('UNSIGNED', $row['Type'], $test);
228 $zerofill = eregi('ZEROFILL', $row['Type'], $test);
229 $strAttribute = '&nbsp;';
230 if ($binary) {
231 $strAttribute = 'BINARY';
233 if ($unsigned) {
234 $strAttribute = 'UNSIGNED';
236 if ($zerofill) {
237 $strAttribute = 'UNSIGNED ZEROFILL';
239 if (!isset($row['Default'])) {
240 if ($row['Null'] != '') {
241 $row['Default'] = '<i>NULL</i>';
243 } else {
244 $row['Default'] = htmlspecialchars($row['Default']);
246 $field_name = htmlspecialchars($row['Field']);
247 echo "\n";
249 <tr>
250 <td width="50" class="print" nowrap="nowrap">
251 <?php
252 if (isset($pk_array[$row['Field']])) {
253 echo ' <u>' . $field_name . '</u>&nbsp;' . "\n";
254 } else {
255 echo ' ' . $field_name . '&nbsp;' . "\n";
258 </td>
259 <td width="80" class="print"<?php echo $type_nowrap; ?>><?php echo $type; ?><bdo dir="ltr"></bdo></td>
260 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $strAttribute; ?></td>-->
261 <td width="40" class="print"><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?>&nbsp;</td>
262 <td width="70" class="print" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?>&nbsp;</td>
263 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?>&nbsp;</td>-->
264 <?php
265 echo "\n";
266 if ($have_rel) {
267 echo ' <td class="print">';
268 if (isset($res_rel[$field_name])) {
269 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] );
271 echo '&nbsp;</td>' . "\n";
273 if ($cfgRelation['commwork']) {
274 echo ' <td class="print">';
275 $comments = PMA_getComments($db, $table);
276 if (isset($comments[$field_name])) {
277 echo htmlspecialchars($comments[$field_name]);
279 echo '&nbsp;</td>' . "\n";
282 </tr>
283 <?php
284 } // end while
285 mysql_free_result($result);
287 echo "\n";
289 </table>
292 <?php
294 * Displays indexes
296 $index_count = (isset($indexes))
297 ? count($indexes)
298 : 0;
299 if ($index_count > 0) {
300 echo "\n";
302 <br /><br />
304 <!-- Indexes -->
305 &nbsp;<big><?php echo $strIndexes . '&nbsp;:'; ?></big>
306 <table bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
307 <tr>
308 <th><?php echo $strKeyname; ?></th>
309 <th><?php echo $strType; ?></th>
310 <th><?php echo $strCardinality; ?></th>
311 <th colspan="2"><?php echo $strField; ?></th>
312 </tr>
313 <?php
314 echo "\n";
315 while (list($index_no, $index_name) = each($indexes)) {
316 $cell_bgd = (($index_no % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']);
317 $index_td = ' <td class="print" rowspan="' . count($indexes_info[$index_name]['Sequences']) . '">' . "\n";
318 echo ' <tr>' . "\n";
319 echo $index_td
320 . ' ' . htmlspecialchars($index_name) . "\n"
321 . ' </td>' . "\n";
323 if ($indexes_info[$index_name]['Comment'] == 'FULLTEXT') {
324 $index_type = 'FULLTEXT';
325 } else if ($index_name == 'PRIMARY') {
326 $index_type = 'PRIMARY';
327 } else if ($indexes_info[$index_name]['Non_unique'] == '0') {
328 $index_type = 'UNIQUE';
329 } else {
330 $index_type = 'INDEX';
332 echo $index_td
333 . ' ' . $index_type . "\n"
334 . ' </td>' . "\n";
336 echo $index_td
337 . ' ' . (isset($indexes_info[$index_name]['Cardinality']) ? $indexes_info[$index_name]['Cardinality'] : $strNone) . "\n"
338 . ' </td>' . "\n";
340 while (list($row_no, $seq_index) = each($indexes_info[$index_name]['Sequences'])) {
341 if ($row_no > 0) {
342 echo ' <tr>' . "\n";
344 if (!empty($indexes_data[$index_name][$seq_index]['Sub_part'])) {
345 echo ' <td class="print">' . "\n"
346 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
347 . ' </td>' . "\n";
348 echo ' <td align="right" class="print">' . "\n"
349 . ' ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n"
350 . ' </td>' . "\n";
351 echo ' </tr>' . "\n";
352 } else {
353 echo ' <td class="print" colspan="2">' . "\n"
354 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
355 . ' </td>' . "\n";
356 echo ' </tr>' . "\n";
358 } // end while
359 } // end while
360 echo "\n";
362 </table>
363 <?php
364 echo "\n";
365 } // end display indexes
369 * Displays Space usage and row statistics
371 * staybyte - 9 June 2001
373 if ($cfg['ShowStats']) {
374 $nonisam = FALSE;
375 if (isset($showtable['Type']) && !eregi('ISAM|HEAP', $showtable['Type'])) {
376 $nonisam = TRUE;
378 if (PMA_MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE) {
379 // Gets some sizes
380 $mergetable = FALSE;
381 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
382 $mergetable = TRUE;
384 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
385 if ($mergetable == FALSE) {
386 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
388 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
389 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
390 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
391 } else {
392 unset($free_size);
393 unset($free_unit);
394 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
396 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
397 if ($num_rows > 0) {
398 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
401 // Displays them
403 <br /><br />
405 <table border="0" cellspacing="0" cellpadding="0">
406 <tr>
408 <!-- Space usage -->
409 <td class="print" valign="top">
410 &nbsp;<big><?php echo $strSpaceUsage . '&nbsp;:'; ?></big>
411 <table width="100%" bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
412 <tr>
413 <th><?php echo $strType; ?></th>
414 <th colspan="2" align="center"><?php echo $strUsage; ?></th>
415 </tr>
416 <tr>
417 <td class="print" style="padding-right: 10px"><?php echo $strData; ?></td>
418 <td align="right" class="print" nowrap="nowrap"><?php echo $data_size; ?></td>
419 <td class="print"><?php echo $data_unit; ?></td>
420 </tr>
421 <?php
422 if (isset($index_size)) {
423 echo "\n";
425 <tr>
426 <td class="print" style="padding-right: 10px"><?php echo $strIndex; ?></td>
427 <td align="right" class="print" nowrap="nowrap"><?php echo $index_size; ?></td>
428 <td class="print"><?php echo $index_unit; ?></td>
429 </tr>
430 <?php
432 if (isset($free_size)) {
433 echo "\n";
435 <tr style="color: #bb0000">
436 <td class="print" style="padding-right: 10px"><?php echo $strOverhead; ?></td>
437 <td align="right" class="print" nowrap="nowrap"><?php echo $free_size; ?></td>
438 <td class="print"><?php echo $free_unit; ?></td>
439 </tr>
440 <tr>
441 <td class="print" style="padding-right: 10px"><?php echo $strEffective; ?></td>
442 <td align="right" class="print" nowrap="nowrap"><?php echo $effect_size; ?></td>
443 <td class="print"><?php echo $effect_unit; ?></td>
444 </tr>
445 <?php
447 if (isset($tot_size) && $mergetable == FALSE) {
448 echo "\n";
450 <tr>
451 <td class="print" style="padding-right: 10px"><?php echo $strTotalUC; ?></td>
452 <td align="right" class="print" nowrap="nowrap"><?php echo $tot_size; ?></td>
453 <td class="print"><?php echo $tot_unit; ?></td>
454 </tr>
455 <?php
457 echo "\n";
459 </table>
460 </td>
462 <td width="20" class="print">&nbsp;</td>
464 <!-- Rows Statistic -->
465 <td valign="top">
466 &nbsp;<big><?php echo $strRowsStatistic . '&nbsp;:'; ?></big>
467 <table width=100% bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
468 <tr>
469 <th><?php echo $strStatement; ?></th>
470 <th align="center"><?php echo $strValue; ?></th>
471 </tr>
472 <?php
473 $i = 0;
474 if (isset($showtable['Row_format'])) {
475 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
476 echo "\n";
478 <tr>
479 <td class="print"><?php echo ucfirst($strFormat); ?></td>
480 <td align="<?php echo $cell_align_left; ?>" class="print" nowrap="nowrap">
481 <?php
482 echo ' ';
483 if ($showtable['Row_format'] == 'Fixed') {
484 echo $strFixed;
485 } else if ($showtable['Row_format'] == 'Dynamic') {
486 echo $strDynamic;
487 } else {
488 echo $showtable['Row_format'];
490 echo "\n";
492 </td>
493 </tr>
494 <?php
496 if (isset($showtable['Rows'])) {
497 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
498 echo "\n";
500 <tr>
501 <td class="print"><?php echo ucfirst($strRows); ?></td>
502 <td align="right" class="print" nowrap="nowrap">
503 <?php echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
504 </td>
505 </tr>
506 <?php
508 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
509 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
510 echo "\n";
512 <tr>
513 <td class="print"><?php echo ucfirst($strRowLength); ?>&nbsp;&oslash;</td>
514 <td class="print" nowrap="nowrap">
515 <?php echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
516 </td>
517 </tr>
518 <?php
520 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == FALSE) {
521 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
522 echo "\n";
524 <tr>
525 <td class="print"><?php echo ucfirst($strRowSize); ?>&nbsp;&oslash;</td>
526 <td align="right" class="print" nowrap="nowrap">
527 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
528 </td>
529 </tr>
530 <?php
532 if (isset($showtable['Auto_increment'])) {
533 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
534 echo "\n";
536 <tr>
537 <td class="print"><?php echo ucfirst($strNext); ?>&nbsp;Autoindex</td>
538 <td align="right" class="print" nowrap="nowrap">
539 <?php echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
540 </td>
541 </tr>
542 <?php
544 echo "\n";
546 </table>
547 </td>
548 </tr>
549 </table>
551 <?php
552 } // end if (PMA_MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE)
553 } // end if ($cfg['ShowStats'])
555 echo "\n";
556 if ($multi_tables) {
557 unset($ret_keys);
558 unset($num_rows);
559 unset($show_comment);
560 echo '<hr />' . "\n";
561 } // end if
562 echo '</div>' . "\n";
564 } // end while
569 * Displays the footer
571 echo "\n";
573 <script type="text/javascript" language="javascript1.2">
574 <!--
575 function printPage()
577 document.all.print.style.visibility = 'hidden';
578 // Do print the page
579 if (typeof(window.print) != 'undefined') {
580 window.print();
582 document.all.print.style.visibility = '';
584 //-->
585 </script>
586 <?php
587 echo '<br /><br />&nbsp;<input type="button" style="visibility: ; width: 100px; height: 25px" name="print" value="Print" onclick="printPage()">' . "\n";
589 require('./footer.inc.php3');