update
[phpmyadmin/crack.git] / tbl_printview.php3
blobbd69f13fc61545ff0ba4ab78e7040ab924795417
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 (!isset($the_tables) || !is_array($the_tables)) {
16 $the_tables = array();
19 /**
20 * Gets the relations settings
22 require('./libraries/relation.lib.php3');
23 require('./libraries/transformations.lib.php3');
25 $cfgRelation = PMA_getRelationsParam();
28 /**
29 * Defines the url to return to in case of error in a sql statement
31 if (isset($table)) {
32 $err_url = 'tbl_properties.php3?' . PMA_generate_common_url($db, $table);
33 } else {
34 $err_url = 'db_details.php3?' . PMA_generate_common_url($db);
38 /**
39 * Selects the database
41 PMA_mysql_select_db($db);
44 /**
45 * Multi-tables printview thanks to Christophe Gesché from the "MySQL Form
46 * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
48 if (isset($selected_tbl) && is_array($selected_tbl)) {
49 $the_tables = $selected_tbl;
50 } else if (isset($table)) {
51 $the_tables[] = $table;
53 $multi_tables = (count($the_tables) > 1);
55 if ($multi_tables) {
56 $tbl_list = '';
57 while (list($key, $table) = each($the_tables)) {
58 $tbl_list .= (empty($tbl_list) ? '' : ', ')
59 . PMA_backquote(urldecode($table));
61 echo '<b>'. $strShowTables . '&nbsp;:&nbsp;' . $tbl_list . '</b>' . "\n";
62 echo '<hr />' . "\n";
63 } // end if
65 $tables_cnt = count($the_tables);
66 reset($the_tables);
67 $counter = 0;
69 while (list($key, $table) = each($the_tables)) {
70 $table = urldecode($table);
71 if ($counter + 1 >= $tables_cnt) {
72 $breakstyle = '';
73 } else {
74 $breakstyle = ' style="page-break-after: always;"';
76 $counter++;
77 echo '<div' . $breakstyle . '>' . "\n";
78 echo '<h1>' . $table . '</h1>' . "\n";
80 /**
81 * Gets table informations
83 // The 'show table' statement works correct since 3.23.03
84 if (PMA_MYSQL_INT_VERSION >= 32303) {
85 $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
86 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
87 $showtable = PMA_mysql_fetch_array($result);
88 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
89 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
90 } else {
91 $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table);
92 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
93 $showtable = array();
94 $num_rows = PMA_mysql_result($result, 0, 'count');
95 $show_comment = '';
96 } // end display comments
97 if ($result) {
98 mysql_free_result($result);
103 * Gets table keys and retains them
105 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
106 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
107 $primary = '';
108 $indexes = array();
109 $lastIndex = '';
110 $indexes_info = array();
111 $indexes_data = array();
112 $pk_array = array(); // will be use to emphasis prim. keys in the table
113 // view
114 while ($row = PMA_mysql_fetch_array($result)) {
115 // Backups the list of primary keys
116 if ($row['Key_name'] == 'PRIMARY') {
117 $primary .= $row['Column_name'] . ', ';
118 $pk_array[$row['Column_name']] = 1;
120 // Retains keys informations
121 if ($row['Key_name'] != $lastIndex ){
122 $indexes[] = $row['Key_name'];
123 $lastIndex = $row['Key_name'];
125 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
126 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
127 if (isset($row['Cardinality'])) {
128 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
130 // I don't know what does following column mean....
131 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
132 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
134 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
135 if (isset($row['Sub_part'])) {
136 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
139 } // end while
140 if ($result) {
141 mysql_free_result($result);
146 * Gets fields properties
148 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
149 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
150 $fields_cnt = mysql_num_rows($result);
152 // Check if we can use Relations (Mike Beck)
153 if (!empty($cfgRelation['relation'])) {
154 // Find which tables are related with the current one and write it in
155 // an array
156 $res_rel = PMA_getForeigners($db, $table);
158 if (count($res_rel) > 0) {
159 $have_rel = TRUE;
160 } else {
161 $have_rel = FALSE;
164 else {
165 $have_rel = FALSE;
166 } // end if
170 * Displays the comments of the table if MySQL >= 3.23
172 if (!empty($show_comment)) {
173 echo $strTableComments . '&nbsp;:&nbsp;' . $show_comment . '<br /><br />';
177 * Displays the table structure
181 <!-- TABLE INFORMATIONS -->
182 <table width="95%" bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
183 <tr>
184 <th width="50"><?php echo $strField; ?></th>
185 <th width="80"><?php echo $strType; ?></th>
186 <!--<th width="50"><?php echo $strAttr; ?></th>-->
187 <th width="40"><?php echo $strNull; ?></th>
188 <th width="70"><?php echo $strDefault; ?></th>
189 <!--<th width="50"><?php echo $strExtra; ?></th>-->
190 <?php
191 echo "\n";
192 if ($have_rel) {
193 echo ' <th>' . $strLinksTo . '</th>' . "\n";
195 if ($cfgRelation['commwork']) {
196 echo ' <th>' . $strComments . '</th>' . "\n";
198 if ($cfgRelation['mimework']) {
199 echo ' <th>MIME</th>' . "\n";
202 </tr>
204 <?php
205 $i = 0;
206 while ($row = PMA_mysql_fetch_array($result)) {
207 $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
208 $i++;
210 $type = $row['Type'];
211 // reformat mysql query output - staybyte - 9. June 2001
212 // loic1: set or enum types: slashes single quotes inside options
213 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
214 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
215 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
216 $type_nowrap = '';
218 $binary = 0;
219 $unsigned = 0;
220 $zerofill = 0;
221 } else {
222 $type_nowrap = ' nowrap="nowrap"';
223 $type = eregi_replace('BINARY', '', $type);
224 $type = eregi_replace('ZEROFILL', '', $type);
225 $type = eregi_replace('UNSIGNED', '', $type);
226 if (empty($type)) {
227 $type = '&nbsp;';
230 $binary = eregi('BINARY', $row['Type'], $test);
231 $unsigned = eregi('UNSIGNED', $row['Type'], $test);
232 $zerofill = eregi('ZEROFILL', $row['Type'], $test);
234 $strAttribute = '&nbsp;';
235 if ($binary) {
236 $strAttribute = 'BINARY';
238 if ($unsigned) {
239 $strAttribute = 'UNSIGNED';
241 if ($zerofill) {
242 $strAttribute = 'UNSIGNED ZEROFILL';
244 if (!isset($row['Default'])) {
245 if ($row['Null'] != '') {
246 $row['Default'] = '<i>NULL</i>';
248 } else {
249 $row['Default'] = htmlspecialchars($row['Default']);
251 $field_name = htmlspecialchars($row['Field']);
252 echo "\n";
254 <tr>
255 <td width="50" class="print" nowrap="nowrap">
256 <?php
257 if (isset($pk_array[$row['Field']])) {
258 echo ' <u>' . $field_name . '</u>&nbsp;' . "\n";
259 } else {
260 echo ' ' . $field_name . '&nbsp;' . "\n";
263 </td>
264 <td width="80" class="print"<?php echo $type_nowrap; ?>><?php echo $type; ?><bdo dir="ltr"></bdo></td>
265 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $strAttribute; ?></td>-->
266 <td width="40" class="print"><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?>&nbsp;</td>
267 <td width="70" class="print" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?>&nbsp;</td>
268 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?>&nbsp;</td>-->
269 <?php
270 echo "\n";
271 if ($have_rel) {
272 echo ' <td class="print">';
273 if (isset($res_rel[$field_name])) {
274 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] );
276 echo '&nbsp;</td>' . "\n";
278 if ($cfgRelation['commwork']) {
279 echo ' <td class="print">';
280 $comments = PMA_getComments($db, $table);
281 if (isset($comments[$field_name])) {
282 echo htmlspecialchars($comments[$field_name]);
284 echo '&nbsp;</td>' . "\n";
286 if ($cfgRelation['mimework']) {
287 $mime_map = PMA_getMIME($db, $table, true);
289 echo ' <td class="print">';
290 if (isset($mime_map[$field_name])) {
291 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
293 echo '&nbsp;</td>' . "\n";
296 </tr>
297 <?php
298 } // end while
299 mysql_free_result($result);
301 echo "\n";
303 </table>
306 <?php
308 * Displays indexes
310 $index_count = (isset($indexes))
311 ? count($indexes)
312 : 0;
313 if ($index_count > 0) {
314 echo "\n";
316 <br /><br />
318 <!-- Indexes -->
319 &nbsp;<big><?php echo $strIndexes . '&nbsp;:'; ?></big>
320 <table bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
321 <tr>
322 <th><?php echo $strKeyname; ?></th>
323 <th><?php echo $strType; ?></th>
324 <th><?php echo $strCardinality; ?></th>
325 <th colspan="2"><?php echo $strField; ?></th>
326 </tr>
327 <?php
328 echo "\n";
329 while (list($index_no, $index_name) = each($indexes)) {
330 $cell_bgd = (($index_no % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']);
331 $index_td = ' <td class="print" rowspan="' . count($indexes_info[$index_name]['Sequences']) . '">' . "\n";
332 echo ' <tr>' . "\n";
333 echo $index_td
334 . ' ' . htmlspecialchars($index_name) . "\n"
335 . ' </td>' . "\n";
337 if ($indexes_info[$index_name]['Comment'] == 'FULLTEXT') {
338 $index_type = 'FULLTEXT';
339 } else if ($index_name == 'PRIMARY') {
340 $index_type = 'PRIMARY';
341 } else if ($indexes_info[$index_name]['Non_unique'] == '0') {
342 $index_type = 'UNIQUE';
343 } else {
344 $index_type = 'INDEX';
346 echo $index_td
347 . ' ' . $index_type . "\n"
348 . ' </td>' . "\n";
350 echo $index_td
351 . ' ' . (isset($indexes_info[$index_name]['Cardinality']) ? $indexes_info[$index_name]['Cardinality'] : $strNone) . "\n"
352 . ' </td>' . "\n";
354 while (list($row_no, $seq_index) = each($indexes_info[$index_name]['Sequences'])) {
355 if ($row_no > 0) {
356 echo ' <tr>' . "\n";
358 if (!empty($indexes_data[$index_name][$seq_index]['Sub_part'])) {
359 echo ' <td class="print">' . "\n"
360 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
361 . ' </td>' . "\n";
362 echo ' <td align="right" class="print">' . "\n"
363 . ' ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n"
364 . ' </td>' . "\n";
365 echo ' </tr>' . "\n";
366 } else {
367 echo ' <td class="print" colspan="2">' . "\n"
368 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
369 . ' </td>' . "\n";
370 echo ' </tr>' . "\n";
372 } // end while
373 } // end while
374 echo "\n";
376 </table>
377 <?php
378 echo "\n";
379 } // end display indexes
383 * Displays Space usage and row statistics
385 * staybyte - 9 June 2001
387 if ($cfg['ShowStats']) {
388 $nonisam = FALSE;
389 if (isset($showtable['Type']) && !eregi('ISAM|HEAP', $showtable['Type'])) {
390 $nonisam = TRUE;
392 if (PMA_MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE) {
393 // Gets some sizes
394 $mergetable = FALSE;
395 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
396 $mergetable = TRUE;
398 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
399 if ($mergetable == FALSE) {
400 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
402 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
403 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
404 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
405 } else {
406 unset($free_size);
407 unset($free_unit);
408 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
410 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
411 if ($num_rows > 0) {
412 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
415 // Displays them
417 <br /><br />
419 <table border="0" cellspacing="0" cellpadding="0">
420 <tr>
422 <!-- Space usage -->
423 <td class="print" valign="top">
424 &nbsp;<big><?php echo $strSpaceUsage . '&nbsp;:'; ?></big>
425 <table width="100%" bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
426 <tr>
427 <th><?php echo $strType; ?></th>
428 <th colspan="2" align="center"><?php echo $strUsage; ?></th>
429 </tr>
430 <tr>
431 <td class="print" style="padding-right: 10px"><?php echo $strData; ?></td>
432 <td align="right" class="print" nowrap="nowrap"><?php echo $data_size; ?></td>
433 <td class="print"><?php echo $data_unit; ?></td>
434 </tr>
435 <?php
436 if (isset($index_size)) {
437 echo "\n";
439 <tr>
440 <td class="print" style="padding-right: 10px"><?php echo $strIndex; ?></td>
441 <td align="right" class="print" nowrap="nowrap"><?php echo $index_size; ?></td>
442 <td class="print"><?php echo $index_unit; ?></td>
443 </tr>
444 <?php
446 if (isset($free_size)) {
447 echo "\n";
449 <tr style="color: #bb0000">
450 <td class="print" style="padding-right: 10px"><?php echo $strOverhead; ?></td>
451 <td align="right" class="print" nowrap="nowrap"><?php echo $free_size; ?></td>
452 <td class="print"><?php echo $free_unit; ?></td>
453 </tr>
454 <tr>
455 <td class="print" style="padding-right: 10px"><?php echo $strEffective; ?></td>
456 <td align="right" class="print" nowrap="nowrap"><?php echo $effect_size; ?></td>
457 <td class="print"><?php echo $effect_unit; ?></td>
458 </tr>
459 <?php
461 if (isset($tot_size) && $mergetable == FALSE) {
462 echo "\n";
464 <tr>
465 <td class="print" style="padding-right: 10px"><?php echo $strTotalUC; ?></td>
466 <td align="right" class="print" nowrap="nowrap"><?php echo $tot_size; ?></td>
467 <td class="print"><?php echo $tot_unit; ?></td>
468 </tr>
469 <?php
471 echo "\n";
473 </table>
474 </td>
476 <td width="20" class="print">&nbsp;</td>
478 <!-- Rows Statistic -->
479 <td valign="top">
480 &nbsp;<big><?php echo $strRowsStatistic . '&nbsp;:'; ?></big>
481 <table width=100% bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
482 <tr>
483 <th><?php echo $strStatement; ?></th>
484 <th align="center"><?php echo $strValue; ?></th>
485 </tr>
486 <?php
487 $i = 0;
488 if (isset($showtable['Row_format'])) {
489 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
490 echo "\n";
492 <tr>
493 <td class="print"><?php echo ucfirst($strFormat); ?></td>
494 <td align="<?php echo $cell_align_left; ?>" class="print" nowrap="nowrap">
495 <?php
496 echo ' ';
497 if ($showtable['Row_format'] == 'Fixed') {
498 echo $strFixed;
499 } else if ($showtable['Row_format'] == 'Dynamic') {
500 echo $strDynamic;
501 } else {
502 echo $showtable['Row_format'];
504 echo "\n";
506 </td>
507 </tr>
508 <?php
510 if (isset($showtable['Rows'])) {
511 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
512 echo "\n";
514 <tr>
515 <td class="print"><?php echo ucfirst($strRows); ?></td>
516 <td align="right" class="print" nowrap="nowrap">
517 <?php echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
518 </td>
519 </tr>
520 <?php
522 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
523 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
524 echo "\n";
526 <tr>
527 <td class="print"><?php echo ucfirst($strRowLength); ?>&nbsp;&oslash;</td>
528 <td class="print" nowrap="nowrap">
529 <?php echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
530 </td>
531 </tr>
532 <?php
534 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == FALSE) {
535 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
536 echo "\n";
538 <tr>
539 <td class="print"><?php echo ucfirst($strRowSize); ?>&nbsp;&oslash;</td>
540 <td align="right" class="print" nowrap="nowrap">
541 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
542 </td>
543 </tr>
544 <?php
546 if (isset($showtable['Auto_increment'])) {
547 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
548 echo "\n";
550 <tr>
551 <td class="print"><?php echo ucfirst($strNext); ?>&nbsp;Autoindex</td>
552 <td align="right" class="print" nowrap="nowrap">
553 <?php echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
554 </td>
555 </tr>
556 <?php
558 echo "\n";
560 if (isset($showtable['Create_time'])) {
561 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
562 echo "\n";
564 <tr>
565 <td class="print"><?php echo $strStatCreateTime; ?></td>
566 <td align="right" class="print" nowrap="nowrap">
567 <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
568 </td>
569 </tr>
570 <?php
572 echo "\n";
574 if (isset($showtable['Update_time'])) {
575 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
576 echo "\n";
578 <tr>
579 <td class="print"><?php echo $strStatUpdateTime; ?></td>
580 <td align="right" class="print" nowrap="nowrap">
581 <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
582 </td>
583 </tr>
584 <?php
586 echo "\n";
588 if (isset($showtable['Check_time'])) {
589 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
590 echo "\n";
592 <tr>
593 <td class="print"><?php echo $strStatCheckTime; ?></td>
594 <td align="right" class="print" nowrap="nowrap">
595 <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
596 </td>
597 </tr>
598 <?php
600 echo "\n";
602 </table>
603 </td>
604 </tr>
605 </table>
607 <?php
608 } // end if (PMA_MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE)
609 } // end if ($cfg['ShowStats'])
611 echo "\n";
612 if ($multi_tables) {
613 unset($ret_keys);
614 unset($num_rows);
615 unset($show_comment);
616 echo '<hr />' . "\n";
617 } // end if
618 echo '</div>' . "\n";
620 } // end while
625 * Displays the footer
627 echo "\n";
629 <script type="text/javascript" language="javascript1.2">
630 <!--
631 function printPage()
633 document.getElementById('print').style.visibility = 'hidden';
634 // Do print the page
635 if (typeof(window.print) != 'undefined') {
636 window.print();
638 document.getElementById('print').style.visibility = '';
640 //-->
641 </script>
642 <?php
643 echo '<br /><br />&nbsp;<input type="button" style="visibility: ; width: 100px; height: 25px" id="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
645 require('./footer.inc.php3');