Fix left frame reloading after dropping table (bug #1034531).
[phpmyadmin/crack.git] / tbl_printview.php
blob647481a8d5fbf8f04e6d56e7ac2bd0a462638b16
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 require_once('./libraries/grab_globals.lib.php');
10 require_once('./header.inc.php');
13 // Check parameters
15 if (!isset($the_tables) || !is_array($the_tables)) {
16 $the_tables = array();
19 /**
20 * Gets the relations settings
22 require_once('./libraries/relation.lib.php');
23 require_once('./libraries/transformations.lib.php');
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.php?' . PMA_generate_common_url($db, $table);
33 } else {
34 $err_url = 'db_details.php?' . PMA_generate_common_url($db);
38 /**
39 * Selects the database
41 PMA_DBI_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 foreach ($the_tables AS $key => $table) {
58 $tbl_list .= (empty($tbl_list) ? '' : ', ')
59 . PMA_backquote(urldecode($table));
61 echo '<b>'. $strShowTables . ':&nbsp;' . $tbl_list . '</b>' . "\n";
62 echo '<hr />' . "\n";
63 } // end if
65 $tables_cnt = count($the_tables);
66 $counter = 0;
68 foreach ($the_tables AS $key => $table) {
69 $table = urldecode($table);
70 if ($counter + 1 >= $tables_cnt) {
71 $breakstyle = '';
72 } else {
73 $breakstyle = ' style="page-break-after: always;"';
75 $counter++;
76 echo '<div' . $breakstyle . '>' . "\n";
77 echo '<h1>' . $table . '</h1>' . "\n";
79 /**
80 * Gets table informations
82 $result = PMA_DBI_query('SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';');
83 $showtable = PMA_DBI_fetch_assoc($result);
84 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
85 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
86 PMA_DBI_free_result($result);
89 /**
90 * Gets table keys and retains them
92 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
93 $primary = '';
94 $indexes = array();
95 $lastIndex = '';
96 $indexes_info = array();
97 $indexes_data = array();
98 $pk_array = array(); // will be use to emphasis prim. keys in the table
99 // view
100 while ($row = PMA_DBI_fetch_assoc($result)) {
101 // Backups the list of primary keys
102 if ($row['Key_name'] == 'PRIMARY') {
103 $primary .= $row['Column_name'] . ', ';
104 $pk_array[$row['Column_name']] = 1;
106 // Retains keys informations
107 if ($row['Key_name'] != $lastIndex ){
108 $indexes[] = $row['Key_name'];
109 $lastIndex = $row['Key_name'];
111 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
112 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
113 if (isset($row['Cardinality'])) {
114 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
116 // I don't know what does following column mean....
117 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
118 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
120 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
121 if (isset($row['Sub_part'])) {
122 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
125 } // end while
126 if ($result) {
127 PMA_DBI_free_result($result);
132 * Gets fields properties
134 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', NULL, PMA_DBI_QUERY_STORE);
135 $fields_cnt = PMA_DBI_num_rows($result);
137 // Check if we can use Relations (Mike Beck)
138 if (!empty($cfgRelation['relation'])) {
139 // Find which tables are related with the current one and write it in
140 // an array
141 $res_rel = PMA_getForeigners($db, $table);
143 if (count($res_rel) > 0) {
144 $have_rel = TRUE;
145 } else {
146 $have_rel = FALSE;
149 else {
150 $have_rel = FALSE;
151 } // end if
155 * Displays the comments of the table if MySQL >= 3.23
157 if (!empty($show_comment)) {
158 echo $strTableComments . ':&nbsp;' . $show_comment . '<br /><br />';
162 * Displays the table structure
166 <!-- TABLE INFORMATIONS -->
167 <table width="95%" bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
168 <tr>
169 <th width="50"><?php echo $strField; ?></th>
170 <th width="80"><?php echo $strType; ?></th>
171 <!--<th width="50"><?php echo $strAttr; ?></th>-->
172 <th width="40"><?php echo $strNull; ?></th>
173 <th width="70"><?php echo $strDefault; ?></th>
174 <!--<th width="50"><?php echo $strExtra; ?></th>-->
175 <?php
176 echo "\n";
177 if ($have_rel) {
178 echo ' <th>' . $strLinksTo . '</th>' . "\n";
180 if ($cfgRelation['commwork']) {
181 echo ' <th>' . $strComments . '</th>' . "\n";
183 if ($cfgRelation['mimework']) {
184 echo ' <th>MIME</th>' . "\n";
187 </tr>
189 <?php
190 $i = 0;
191 while ($row = PMA_DBI_fetch_assoc($result)) {
192 $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
193 $i++;
195 $type = $row['Type'];
196 // reformat mysql query output - staybyte - 9. June 2001
197 // loic1: set or enum types: slashes single quotes inside options
198 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
199 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
200 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
201 $type_nowrap = '';
203 $binary = 0;
204 $unsigned = 0;
205 $zerofill = 0;
206 } else {
207 $type_nowrap = ' nowrap="nowrap"';
208 $type = preg_replace('@BINARY@i', '', $type);
209 $type = preg_replace('@ZEROFILL@i', '', $type);
210 $type = preg_replace('@UNSIGNED@i', '', $type);
211 if (empty($type)) {
212 $type = '&nbsp;';
215 $binary = stristr($row['Type'], 'binary');
216 $unsigned = stristr($row['Type'], 'unsigned');
217 $zerofill = stristr($row['Type'], 'zerofill');
219 $strAttribute = '&nbsp;';
220 if ($binary) {
221 $strAttribute = 'BINARY';
223 if ($unsigned) {
224 $strAttribute = 'UNSIGNED';
226 if ($zerofill) {
227 $strAttribute = 'UNSIGNED ZEROFILL';
229 if (!isset($row['Default'])) {
230 if ($row['Null'] != '') {
231 $row['Default'] = '<i>NULL</i>';
233 } else {
234 $row['Default'] = htmlspecialchars($row['Default']);
236 $field_name = htmlspecialchars($row['Field']);
237 echo "\n";
239 <tr>
240 <td width="50" class="print" nowrap="nowrap">
241 <?php
242 if (isset($pk_array[$row['Field']])) {
243 echo ' <u>' . $field_name . '</u>&nbsp;' . "\n";
244 } else {
245 echo ' ' . $field_name . '&nbsp;' . "\n";
248 </td>
249 <td width="80" class="print"<?php echo $type_nowrap; ?>><?php echo $type; ?><bdo dir="ltr"></bdo></td>
250 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $strAttribute; ?></td>-->
251 <td width="40" class="print"><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?>&nbsp;</td>
252 <td width="70" class="print" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?>&nbsp;</td>
253 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?>&nbsp;</td>-->
254 <?php
255 echo "\n";
256 if ($have_rel) {
257 echo ' <td class="print">';
258 if (isset($res_rel[$field_name])) {
259 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] );
261 echo '&nbsp;</td>' . "\n";
263 if ($cfgRelation['commwork']) {
264 echo ' <td class="print">';
265 $comments = PMA_getComments($db, $table);
266 if (isset($comments[$field_name])) {
267 echo htmlspecialchars($comments[$field_name]);
269 echo '&nbsp;</td>' . "\n";
271 if ($cfgRelation['mimework']) {
272 $mime_map = PMA_getMIME($db, $table, true);
274 echo ' <td class="print">';
275 if (isset($mime_map[$field_name])) {
276 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
278 echo '&nbsp;</td>' . "\n";
281 </tr>
282 <?php
283 } // end while
284 PMA_DBI_free_result($result);
286 echo "\n";
288 </table>
291 <?php
293 * Displays indexes
295 $index_count = (isset($indexes))
296 ? count($indexes)
297 : 0;
298 if ($index_count > 0) {
299 echo "\n";
301 <br /><br />
303 <!-- Indexes -->
304 &nbsp;<big><?php echo $strIndexes . ':'; ?></big>
305 <table bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
306 <tr>
307 <th><?php echo $strKeyname; ?></th>
308 <th><?php echo $strType; ?></th>
309 <th><?php echo $strCardinality; ?></th>
310 <th colspan="2"><?php echo $strField; ?></th>
311 </tr>
312 <?php
313 echo "\n";
314 foreach ($indexes AS $index_no => $index_name) {
315 $cell_bgd = (($index_no % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']);
316 $index_td = ' <td class="print" rowspan="' . count($indexes_info[$index_name]['Sequences']) . '">' . "\n";
317 echo ' <tr>' . "\n";
318 echo $index_td
319 . ' ' . htmlspecialchars($index_name) . "\n"
320 . ' </td>' . "\n";
322 if ($indexes_info[$index_name]['Comment'] == 'FULLTEXT') {
323 $index_type = 'FULLTEXT';
324 } else if ($index_name == 'PRIMARY') {
325 $index_type = 'PRIMARY';
326 } else if ($indexes_info[$index_name]['Non_unique'] == '0') {
327 $index_type = 'UNIQUE';
328 } else {
329 $index_type = 'INDEX';
331 echo $index_td
332 . ' ' . $index_type . "\n"
333 . ' </td>' . "\n";
335 echo $index_td
336 . ' ' . (isset($indexes_info[$index_name]['Cardinality']) ? $indexes_info[$index_name]['Cardinality'] : $strNone) . "\n"
337 . ' </td>' . "\n";
339 foreach ($indexes_info[$index_name]['Sequences'] AS $row_no => $seq_index) {
340 if ($row_no > 0) {
341 echo ' <tr>' . "\n";
343 if (!empty($indexes_data[$index_name][$seq_index]['Sub_part'])) {
344 echo ' <td class="print">' . "\n"
345 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
346 . ' </td>' . "\n";
347 echo ' <td align="right" class="print">' . "\n"
348 . ' ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n"
349 . ' </td>' . "\n";
350 echo ' </tr>' . "\n";
351 } else {
352 echo ' <td class="print" colspan="2">' . "\n"
353 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
354 . ' </td>' . "\n";
355 echo ' </tr>' . "\n";
357 } // end while
358 } // end while
359 echo "\n";
361 </table>
362 <?php
363 echo "\n";
364 } // end display indexes
368 * Displays Space usage and row statistics
370 * staybyte - 9 June 2001
372 if ($cfg['ShowStats']) {
373 $nonisam = FALSE;
374 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
375 $nonisam = TRUE;
377 if ($nonisam == FALSE) {
378 // Gets some sizes
379 $mergetable = FALSE;
380 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
381 $mergetable = TRUE;
383 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
384 if ($mergetable == FALSE) {
385 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
387 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
388 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
389 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
390 } else {
391 unset($free_size);
392 unset($free_unit);
393 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
395 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
396 if ($num_rows > 0) {
397 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
400 // Displays them
402 <br /><br />
404 <table border="0" cellspacing="0" cellpadding="0">
405 <tr>
407 <!-- Space usage -->
408 <td class="print" valign="top">
409 &nbsp;<big><?php echo $strSpaceUsage . ':'; ?></big>
410 <table width="100%" bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
411 <tr>
412 <th><?php echo $strType; ?></th>
413 <th colspan="2" align="center"><?php echo $strUsage; ?></th>
414 </tr>
415 <tr>
416 <td class="print" style="padding-right: 10px"><?php echo $strData; ?></td>
417 <td align="right" class="print" nowrap="nowrap"><?php echo $data_size; ?></td>
418 <td class="print"><?php echo $data_unit; ?></td>
419 </tr>
420 <?php
421 if (isset($index_size)) {
422 echo "\n";
424 <tr>
425 <td class="print" style="padding-right: 10px"><?php echo $strIndex; ?></td>
426 <td align="right" class="print" nowrap="nowrap"><?php echo $index_size; ?></td>
427 <td class="print"><?php echo $index_unit; ?></td>
428 </tr>
429 <?php
431 if (isset($free_size)) {
432 echo "\n";
434 <tr style="color: #bb0000">
435 <td class="print" style="padding-right: 10px"><?php echo $strOverhead; ?></td>
436 <td align="right" class="print" nowrap="nowrap"><?php echo $free_size; ?></td>
437 <td class="print"><?php echo $free_unit; ?></td>
438 </tr>
439 <tr>
440 <td class="print" style="padding-right: 10px"><?php echo $strEffective; ?></td>
441 <td align="right" class="print" nowrap="nowrap"><?php echo $effect_size; ?></td>
442 <td class="print"><?php echo $effect_unit; ?></td>
443 </tr>
444 <?php
446 if (isset($tot_size) && $mergetable == FALSE) {
447 echo "\n";
449 <tr>
450 <td class="print" style="padding-right: 10px"><?php echo $strTotalUC; ?></td>
451 <td align="right" class="print" nowrap="nowrap"><?php echo $tot_size; ?></td>
452 <td class="print"><?php echo $tot_unit; ?></td>
453 </tr>
454 <?php
456 echo "\n";
458 </table>
459 </td>
461 <td width="20" class="print">&nbsp;</td>
463 <!-- Rows Statistic -->
464 <td valign="top">
465 &nbsp;<big><?php echo $strRowsStatistic . ':'; ?></big>
466 <table width=100% bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
467 <tr>
468 <th><?php echo $strStatement; ?></th>
469 <th align="center"><?php echo $strValue; ?></th>
470 </tr>
471 <?php
472 $i = 0;
473 if (isset($showtable['Row_format'])) {
474 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
475 echo "\n";
477 <tr>
478 <td class="print"><?php echo ucfirst($strFormat); ?></td>
479 <td align="<?php echo $cell_align_left; ?>" class="print" nowrap="nowrap">
480 <?php
481 echo ' ';
482 if ($showtable['Row_format'] == 'Fixed') {
483 echo $strFixed;
484 } else if ($showtable['Row_format'] == 'Dynamic') {
485 echo $strDynamic;
486 } else {
487 echo $showtable['Row_format'];
489 echo "\n";
491 </td>
492 </tr>
493 <?php
495 if (isset($showtable['Rows'])) {
496 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
497 echo "\n";
499 <tr>
500 <td class="print"><?php echo ucfirst($strRows); ?></td>
501 <td align="right" class="print" nowrap="nowrap">
502 <?php echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
503 </td>
504 </tr>
505 <?php
507 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
508 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
509 echo "\n";
511 <tr>
512 <td class="print"><?php echo ucfirst($strRowLength); ?>&nbsp;&oslash;</td>
513 <td class="print" nowrap="nowrap">
514 <?php echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
515 </td>
516 </tr>
517 <?php
519 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == FALSE) {
520 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
521 echo "\n";
523 <tr>
524 <td class="print"><?php echo ucfirst($strRowSize); ?>&nbsp;&oslash;</td>
525 <td align="right" class="print" nowrap="nowrap">
526 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
527 </td>
528 </tr>
529 <?php
531 if (isset($showtable['Auto_increment'])) {
532 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
533 echo "\n";
535 <tr>
536 <td class="print"><?php echo ucfirst($strNext); ?>&nbsp;Autoindex</td>
537 <td align="right" class="print" nowrap="nowrap">
538 <?php echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
539 </td>
540 </tr>
541 <?php
543 echo "\n";
545 if (isset($showtable['Create_time'])) {
546 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
547 echo "\n";
549 <tr>
550 <td class="print"><?php echo $strStatCreateTime; ?></td>
551 <td align="right" class="print" nowrap="nowrap">
552 <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
553 </td>
554 </tr>
555 <?php
557 echo "\n";
559 if (isset($showtable['Update_time'])) {
560 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
561 echo "\n";
563 <tr>
564 <td class="print"><?php echo $strStatUpdateTime; ?></td>
565 <td align="right" class="print" nowrap="nowrap">
566 <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
567 </td>
568 </tr>
569 <?php
571 echo "\n";
573 if (isset($showtable['Check_time'])) {
574 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
575 echo "\n";
577 <tr>
578 <td class="print"><?php echo $strStatCheckTime; ?></td>
579 <td align="right" class="print" nowrap="nowrap">
580 <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
581 </td>
582 </tr>
583 <?php
585 echo "\n";
587 </table>
588 </td>
589 </tr>
590 </table>
592 <?php
593 } // end if ($nonisam == FALSE)
594 } // end if ($cfg['ShowStats'])
596 echo "\n";
597 if ($multi_tables) {
598 unset($ret_keys);
599 unset($num_rows);
600 unset($show_comment);
601 echo '<hr />' . "\n";
602 } // end if
603 echo '</div>' . "\n";
605 } // end while
610 * Displays the footer
612 echo "\n";
614 <script type="text/javascript" language="javascript1.2">
615 <!--
616 function printPage()
618 document.getElementById('print').style.visibility = 'hidden';
619 // Do print the page
620 if (typeof(window.print) != 'undefined') {
621 window.print();
623 document.getElementById('print').style.visibility = '';
625 //-->
626 </script>
627 <?php
628 echo '<br /><br />&nbsp;<input type="button" style="visibility: ; width: 100px; height: 25px" id="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
630 require_once('./footer.inc.php');