update
[phpmyadmin/crack.git] / tbl_printview.php3
blobab30ba45c64a3db5a9687d57855075b01a9cde79
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 require('./libraries/transformations.lib.php3');
20 $cfgRelation = PMA_getRelationsParam();
23 /**
24 * Defines the url to return to in case of error in a sql statement
26 if (isset($table)) {
27 $err_url = 'tbl_properties.php3?' . PMA_generate_common_url($db, $table);
28 } else {
29 $err_url = 'db_details.php3?' . PMA_generate_common_url($db);
33 /**
34 * Selects the database
36 PMA_mysql_select_db($db);
39 /**
40 * Multi-tables printview thanks to Christophe Gesché from the "MySQL Form
41 * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
43 if (isset($selected_tbl) && is_array($selected_tbl)) {
44 $the_tables = $selected_tbl;
45 } else if (isset($table)) {
46 $the_tables[] = $table;
48 $multi_tables = (count($the_tables) > 1);
50 if ($multi_tables) {
51 $tbl_list = '';
52 while (list($key, $table) = each($the_tables)) {
53 $tbl_list .= (empty($tbl_list) ? '' : ', ')
54 . PMA_backquote(urldecode($table));
56 echo '<b>'. $strShowTables . '&nbsp;:&nbsp;' . $tbl_list . '</b>' . "\n";
57 echo '<hr />' . "\n";
58 } // end if
60 $tables_cnt = count($the_tables);
61 reset($the_tables);
62 $counter = 0;
64 while (list($key, $table) = each($the_tables)) {
65 $table = urldecode($table);
66 if ($counter + 1 >= $tables_cnt) {
67 $breakstyle = '';
68 } else {
69 $breakstyle = ' style="page-break-after: always;"';
71 $counter++;
72 echo '<div' . $breakstyle . '>' . "\n";
73 echo '<h1>' . $table . '</h1>' . "\n";
75 /**
76 * Gets table informations
78 // The 'show table' statement works correct since 3.23.03
79 if (PMA_MYSQL_INT_VERSION >= 32303) {
80 $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
81 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
82 $showtable = PMA_mysql_fetch_array($result);
83 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
84 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
85 } else {
86 $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table);
87 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
88 $showtable = array();
89 $num_rows = PMA_mysql_result($result, 0, 'count');
90 $show_comment = '';
91 } // end display comments
92 if ($result) {
93 mysql_free_result($result);
97 /**
98 * Gets table keys and retains them
100 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
101 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
102 $primary = '';
103 $indexes = array();
104 $lastIndex = '';
105 $indexes_info = array();
106 $indexes_data = array();
107 $pk_array = array(); // will be use to emphasis prim. keys in the table
108 // view
109 while ($row = PMA_mysql_fetch_array($result)) {
110 // Backups the list of primary keys
111 if ($row['Key_name'] == 'PRIMARY') {
112 $primary .= $row['Column_name'] . ', ';
113 $pk_array[$row['Column_name']] = 1;
115 // Retains keys informations
116 if ($row['Key_name'] != $lastIndex ){
117 $indexes[] = $row['Key_name'];
118 $lastIndex = $row['Key_name'];
120 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
121 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
122 if (isset($row['Cardinality'])) {
123 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
125 // I don't know what does following column mean....
126 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
127 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
129 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
130 if (isset($row['Sub_part'])) {
131 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
134 } // end while
135 if ($result) {
136 mysql_free_result($result);
141 * Gets fields properties
143 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
144 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
145 $fields_cnt = mysql_num_rows($result);
147 // Check if we can use Relations (Mike Beck)
148 if (!empty($cfgRelation['relation'])) {
149 // Find which tables are related with the current one and write it in
150 // an array
151 $res_rel = PMA_getForeigners($db, $table);
153 if (count($res_rel) > 0) {
154 $have_rel = TRUE;
155 } else {
156 $have_rel = FALSE;
159 else {
160 $have_rel = FALSE;
161 } // end if
165 * Displays the comments of the table if MySQL >= 3.23
167 if (!empty($show_comment)) {
168 echo $strTableComments . '&nbsp;:&nbsp;' . $show_comment . '<br /><br />';
172 * Displays the table structure
176 <!-- TABLE INFORMATIONS -->
177 <table width="95%" bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
178 <tr>
179 <th width="50"><?php echo $strField; ?></th>
180 <th width="80"><?php echo $strType; ?></th>
181 <!--<th width="50"><?php echo $strAttr; ?></th>-->
182 <th width="40"><?php echo $strNull; ?></th>
183 <th width="70"><?php echo $strDefault; ?></th>
184 <!--<th width="50"><?php echo $strExtra; ?></th>-->
185 <?php
186 echo "\n";
187 if ($have_rel) {
188 echo ' <th>' . $strLinksTo . '</th>' . "\n";
190 if ($cfgRelation['commwork']) {
191 echo ' <th>' . $strComments . '</th>' . "\n";
193 if ($cfgRelation['mimework']) {
194 echo ' <th>MIME</th>' . "\n";
197 </tr>
199 <?php
200 $i = 0;
201 while ($row = PMA_mysql_fetch_array($result)) {
202 $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
203 $i++;
205 $type = $row['Type'];
206 // reformat mysql query output - staybyte - 9. June 2001
207 // loic1: set or enum types: slashes single quotes inside options
208 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
209 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
210 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
211 $type_nowrap = '';
213 $binary = 0;
214 $unsigned = 0;
215 $zerofill = 0;
216 } else {
217 $type_nowrap = ' nowrap="nowrap"';
218 $type = eregi_replace('BINARY', '', $type);
219 $type = eregi_replace('ZEROFILL', '', $type);
220 $type = eregi_replace('UNSIGNED', '', $type);
221 if (empty($type)) {
222 $type = '&nbsp;';
225 $binary = eregi('BINARY', $row['Type'], $test);
226 $unsigned = eregi('UNSIGNED', $row['Type'], $test);
227 $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";
281 if ($cfgRelation['mimework']) {
282 $mime_map = PMA_getMIME($db, $table, true);
284 echo ' <td class="print">';
285 if (isset($mime_map[$field_name])) {
286 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
288 echo '&nbsp;</td>' . "\n";
291 </tr>
292 <?php
293 } // end while
294 mysql_free_result($result);
296 echo "\n";
298 </table>
301 <?php
303 * Displays indexes
305 $index_count = (isset($indexes))
306 ? count($indexes)
307 : 0;
308 if ($index_count > 0) {
309 echo "\n";
311 <br /><br />
313 <!-- Indexes -->
314 &nbsp;<big><?php echo $strIndexes . '&nbsp;:'; ?></big>
315 <table bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
316 <tr>
317 <th><?php echo $strKeyname; ?></th>
318 <th><?php echo $strType; ?></th>
319 <th><?php echo $strCardinality; ?></th>
320 <th colspan="2"><?php echo $strField; ?></th>
321 </tr>
322 <?php
323 echo "\n";
324 while (list($index_no, $index_name) = each($indexes)) {
325 $cell_bgd = (($index_no % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']);
326 $index_td = ' <td class="print" rowspan="' . count($indexes_info[$index_name]['Sequences']) . '">' . "\n";
327 echo ' <tr>' . "\n";
328 echo $index_td
329 . ' ' . htmlspecialchars($index_name) . "\n"
330 . ' </td>' . "\n";
332 if ($indexes_info[$index_name]['Comment'] == 'FULLTEXT') {
333 $index_type = 'FULLTEXT';
334 } else if ($index_name == 'PRIMARY') {
335 $index_type = 'PRIMARY';
336 } else if ($indexes_info[$index_name]['Non_unique'] == '0') {
337 $index_type = 'UNIQUE';
338 } else {
339 $index_type = 'INDEX';
341 echo $index_td
342 . ' ' . $index_type . "\n"
343 . ' </td>' . "\n";
345 echo $index_td
346 . ' ' . (isset($indexes_info[$index_name]['Cardinality']) ? $indexes_info[$index_name]['Cardinality'] : $strNone) . "\n"
347 . ' </td>' . "\n";
349 while (list($row_no, $seq_index) = each($indexes_info[$index_name]['Sequences'])) {
350 if ($row_no > 0) {
351 echo ' <tr>' . "\n";
353 if (!empty($indexes_data[$index_name][$seq_index]['Sub_part'])) {
354 echo ' <td class="print">' . "\n"
355 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
356 . ' </td>' . "\n";
357 echo ' <td align="right" class="print">' . "\n"
358 . ' ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n"
359 . ' </td>' . "\n";
360 echo ' </tr>' . "\n";
361 } else {
362 echo ' <td class="print" colspan="2">' . "\n"
363 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
364 . ' </td>' . "\n";
365 echo ' </tr>' . "\n";
367 } // end while
368 } // end while
369 echo "\n";
371 </table>
372 <?php
373 echo "\n";
374 } // end display indexes
378 * Displays Space usage and row statistics
380 * staybyte - 9 June 2001
382 if ($cfg['ShowStats']) {
383 $nonisam = FALSE;
384 if (isset($showtable['Type']) && !eregi('ISAM|HEAP', $showtable['Type'])) {
385 $nonisam = TRUE;
387 if (PMA_MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE) {
388 // Gets some sizes
389 $mergetable = FALSE;
390 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
391 $mergetable = TRUE;
393 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
394 if ($mergetable == FALSE) {
395 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
397 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
398 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
399 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
400 } else {
401 unset($free_size);
402 unset($free_unit);
403 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
405 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
406 if ($num_rows > 0) {
407 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
410 // Displays them
412 <br /><br />
414 <table border="0" cellspacing="0" cellpadding="0">
415 <tr>
417 <!-- Space usage -->
418 <td class="print" valign="top">
419 &nbsp;<big><?php echo $strSpaceUsage . '&nbsp;:'; ?></big>
420 <table width="100%" bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
421 <tr>
422 <th><?php echo $strType; ?></th>
423 <th colspan="2" align="center"><?php echo $strUsage; ?></th>
424 </tr>
425 <tr>
426 <td class="print" style="padding-right: 10px"><?php echo $strData; ?></td>
427 <td align="right" class="print" nowrap="nowrap"><?php echo $data_size; ?></td>
428 <td class="print"><?php echo $data_unit; ?></td>
429 </tr>
430 <?php
431 if (isset($index_size)) {
432 echo "\n";
434 <tr>
435 <td class="print" style="padding-right: 10px"><?php echo $strIndex; ?></td>
436 <td align="right" class="print" nowrap="nowrap"><?php echo $index_size; ?></td>
437 <td class="print"><?php echo $index_unit; ?></td>
438 </tr>
439 <?php
441 if (isset($free_size)) {
442 echo "\n";
444 <tr style="color: #bb0000">
445 <td class="print" style="padding-right: 10px"><?php echo $strOverhead; ?></td>
446 <td align="right" class="print" nowrap="nowrap"><?php echo $free_size; ?></td>
447 <td class="print"><?php echo $free_unit; ?></td>
448 </tr>
449 <tr>
450 <td class="print" style="padding-right: 10px"><?php echo $strEffective; ?></td>
451 <td align="right" class="print" nowrap="nowrap"><?php echo $effect_size; ?></td>
452 <td class="print"><?php echo $effect_unit; ?></td>
453 </tr>
454 <?php
456 if (isset($tot_size) && $mergetable == FALSE) {
457 echo "\n";
459 <tr>
460 <td class="print" style="padding-right: 10px"><?php echo $strTotalUC; ?></td>
461 <td align="right" class="print" nowrap="nowrap"><?php echo $tot_size; ?></td>
462 <td class="print"><?php echo $tot_unit; ?></td>
463 </tr>
464 <?php
466 echo "\n";
468 </table>
469 </td>
471 <td width="20" class="print">&nbsp;</td>
473 <!-- Rows Statistic -->
474 <td valign="top">
475 &nbsp;<big><?php echo $strRowsStatistic . '&nbsp;:'; ?></big>
476 <table width=100% bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
477 <tr>
478 <th><?php echo $strStatement; ?></th>
479 <th align="center"><?php echo $strValue; ?></th>
480 </tr>
481 <?php
482 $i = 0;
483 if (isset($showtable['Row_format'])) {
484 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
485 echo "\n";
487 <tr>
488 <td class="print"><?php echo ucfirst($strFormat); ?></td>
489 <td align="<?php echo $cell_align_left; ?>" class="print" nowrap="nowrap">
490 <?php
491 echo ' ';
492 if ($showtable['Row_format'] == 'Fixed') {
493 echo $strFixed;
494 } else if ($showtable['Row_format'] == 'Dynamic') {
495 echo $strDynamic;
496 } else {
497 echo $showtable['Row_format'];
499 echo "\n";
501 </td>
502 </tr>
503 <?php
505 if (isset($showtable['Rows'])) {
506 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
507 echo "\n";
509 <tr>
510 <td class="print"><?php echo ucfirst($strRows); ?></td>
511 <td align="right" class="print" nowrap="nowrap">
512 <?php echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
513 </td>
514 </tr>
515 <?php
517 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
518 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
519 echo "\n";
521 <tr>
522 <td class="print"><?php echo ucfirst($strRowLength); ?>&nbsp;&oslash;</td>
523 <td class="print" nowrap="nowrap">
524 <?php echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
525 </td>
526 </tr>
527 <?php
529 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == FALSE) {
530 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
531 echo "\n";
533 <tr>
534 <td class="print"><?php echo ucfirst($strRowSize); ?>&nbsp;&oslash;</td>
535 <td align="right" class="print" nowrap="nowrap">
536 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
537 </td>
538 </tr>
539 <?php
541 if (isset($showtable['Auto_increment'])) {
542 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
543 echo "\n";
545 <tr>
546 <td class="print"><?php echo ucfirst($strNext); ?>&nbsp;Autoindex</td>
547 <td align="right" class="print" nowrap="nowrap">
548 <?php echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
549 </td>
550 </tr>
551 <?php
553 echo "\n";
555 if (isset($showtable['Create_time'])) {
556 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
557 echo "\n";
559 <tr>
560 <td class="print"><?php echo $strStatCreateTime; ?></td>
561 <td align="right" class="print" nowrap="nowrap">
562 <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
563 </td>
564 </tr>
565 <?php
567 echo "\n";
569 if (isset($showtable['Update_time'])) {
570 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
571 echo "\n";
573 <tr>
574 <td class="print"><?php echo $strStatUpdateTime; ?></td>
575 <td align="right" class="print" nowrap="nowrap">
576 <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
577 </td>
578 </tr>
579 <?php
581 echo "\n";
583 if (isset($showtable['Check_time'])) {
584 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
585 echo "\n";
587 <tr>
588 <td class="print"><?php echo $strStatCheckTime; ?></td>
589 <td align="right" class="print" nowrap="nowrap">
590 <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
591 </td>
592 </tr>
593 <?php
595 echo "\n";
597 </table>
598 </td>
599 </tr>
600 </table>
602 <?php
603 } // end if (PMA_MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE)
604 } // end if ($cfg['ShowStats'])
606 echo "\n";
607 if ($multi_tables) {
608 unset($ret_keys);
609 unset($num_rows);
610 unset($show_comment);
611 echo '<hr />' . "\n";
612 } // end if
613 echo '</div>' . "\n";
615 } // end while
620 * Displays the footer
622 echo "\n";
624 <script type="text/javascript" language="javascript1.2">
625 <!--
626 function printPage()
628 document.getElementById('print').style.visibility = 'hidden';
629 // Do print the page
630 if (typeof(window.print) != 'undefined') {
631 window.print();
633 document.getElementById('print').style.visibility = '';
635 //-->
636 </script>
637 <?php
638 echo '<br /><br />&nbsp;<input type="button" style="visibility: ; width: 100px; height: 25px" id="print" value="Print" onclick="printPage()">' . "\n";
640 require('./footer.inc.php3');