Rev Author Line No. Line
250 kaklik 1 <?php
2 /* $Id: tbl_printview.php,v 2.21.2.1 2006/04/12 15:23:31 cybot_tm Exp $ */
3  
4 require_once('./libraries/common.lib.php');
5 require './libraries/tbl_properties_common.php';
6  
7 /**
8 * Gets the variables sent or posted to this script, then displays headers
9 */
10 $print_view = TRUE;
11 if (!isset($selected_tbl)) {
12 require_once('./libraries/header.inc.php');
13 }
14  
15 // Check parameters
16  
17 if (!isset($the_tables) || !is_array($the_tables)) {
18 $the_tables = array();
19 }
20  
21 /**
22 * Gets the relations settings
23 */
24 require_once('./libraries/relation.lib.php');
25 require_once('./libraries/transformations.lib.php');
26 require_once('./libraries/tbl_indexes.lib.php');
27  
28 $cfgRelation = PMA_getRelationsParam();
29  
30  
31 /**
32 * Defines the url to return to in case of error in a sql statement
33 */
34 if (isset($table)) {
35 $err_url = 'tbl_properties.php?' . PMA_generate_common_url($db, $table);
36 } else {
37 $err_url = 'db_details.php?' . PMA_generate_common_url($db);
38 }
39  
40  
41 /**
42 * Selects the database
43 */
44 PMA_DBI_select_db($db);
45  
46  
47 /**
48 * Multi-tables printview thanks to Christophe Gesch� from the "MySQL Form
49 * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
50 */
51 if (isset($selected_tbl) && is_array($selected_tbl)) {
52 $the_tables = $selected_tbl;
53 } elseif (isset($table)) {
54 $the_tables[] = $table;
55 }
56 $multi_tables = (count($the_tables) > 1);
57  
58 if ($multi_tables) {
59 if (empty($GLOBALS['is_header_sent'])) {
60 require_once('./libraries/header.inc.php');
61 }
62 $tbl_list = '';
63 foreach ($the_tables AS $key => $table) {
64 $tbl_list .= (empty($tbl_list) ? '' : ', ')
65 . PMA_backquote(urldecode($table));
66 }
67 echo '<b>'. $strShowTables . ':&nbsp;' . $tbl_list . '</b>' . "\n";
68 echo '<hr />' . "\n";
69 } // end if
70  
71 $tables_cnt = count($the_tables);
72 $counter = 0;
73  
74 foreach ($the_tables AS $key => $table) {
75 $table = urldecode($table);
76 if ($counter + 1 >= $tables_cnt) {
77 $breakstyle = '';
78 } else {
79 $breakstyle = ' style="page-break-after: always;"';
80 }
81 $counter++;
82 echo '<div' . $breakstyle . '>' . "\n";
83 echo '<h1>' . $table . '</h1>' . "\n";
84  
85 /**
86 * Gets table informations
87 */
88 $result = PMA_DBI_query('SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';');
89 $showtable = PMA_DBI_fetch_assoc($result);
90 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
91 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
92 PMA_DBI_free_result($result);
93  
94  
95 // Gets table keys and store them in arrays
96 $indexes = array();
97 $indexes_info = array();
98 $indexes_data = array();
99 $ret_keys = PMA_get_indexes($table, $err_url_0);
100  
101 PMA_extract_indexes($ret_keys, $indexes, $indexes_info, $indexes_data);
102  
103 /**
104 * Gets fields properties
105 */
106 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
107 $fields_cnt = PMA_DBI_num_rows($result);
108  
109 // Check if we can use Relations (Mike Beck)
110 if (!empty($cfgRelation['relation'])) {
111 // Find which tables are related with the current one and write it in
112 // an array
113 $res_rel = PMA_getForeigners($db, $table);
114  
115 if (count($res_rel) > 0) {
116 $have_rel = TRUE;
117 } else {
118 $have_rel = FALSE;
119 }
120 } else {
121 $have_rel = FALSE;
122 } // end if
123  
124  
125 /**
126 * Displays the comments of the table if MySQL >= 3.23
127 */
128 if (!empty($show_comment)) {
129 echo $strTableComments . ':&nbsp;' . $show_comment . '<br /><br />';
130 }
131  
132 /**
133 * Displays the table structure
134 */
135 ?>
136  
137 <!-- TABLE INFORMATIONS -->
138 <table width="95%" bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
139 <tr>
140 <th width="50"><?php echo $strField; ?></th>
141 <th width="80"><?php echo $strType; ?></th>
142 <!--<th width="50"><?php echo $strAttr; ?></th>-->
143 <th width="40"><?php echo $strNull; ?></th>
144 <th width="70"><?php echo $strDefault; ?></th>
145 <!--<th width="50"><?php echo $strExtra; ?></th>-->
146 <?php
147 echo "\n";
148 if ($have_rel) {
149 echo ' <th>' . $strLinksTo . '</th>' . "\n";
150 }
151 if ($cfgRelation['commwork']) {
152 echo ' <th>' . $strComments . '</th>' . "\n";
153 }
154 if ($cfgRelation['mimework']) {
155 echo ' <th>MIME</th>' . "\n";
156 }
157 ?>
158 </tr>
159  
160 <?php
161 $i = 0;
162 while ($row = PMA_DBI_fetch_assoc($result)) {
163 $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
164 $i++;
165  
166 $type = $row['Type'];
167 // reformat mysql query output - staybyte - 9. June 2001
168 // loic1: set or enum types: slashes single quotes inside options
169 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
170 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
171 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
172 $type_nowrap = '';
173  
174 $binary = 0;
175 $unsigned = 0;
176 $zerofill = 0;
177 } else {
178 $type_nowrap = ' nowrap="nowrap"';
179 $type = preg_replace('@BINARY@i', '', $type);
180 $type = preg_replace('@ZEROFILL@i', '', $type);
181 $type = preg_replace('@UNSIGNED@i', '', $type);
182 if (empty($type)) {
183 $type = '&nbsp;';
184 }
185  
186 $binary = stristr($row['Type'], 'binary');
187 $unsigned = stristr($row['Type'], 'unsigned');
188 $zerofill = stristr($row['Type'], 'zerofill');
189 }
190 $strAttribute = '&nbsp;';
191 if ($binary) {
192 $strAttribute = 'BINARY';
193 }
194 if ($unsigned) {
195 $strAttribute = 'UNSIGNED';
196 }
197 if ($zerofill) {
198 $strAttribute = 'UNSIGNED ZEROFILL';
199 }
200 if (!isset($row['Default'])) {
201 if ($row['Null'] != '' && $row['Null'] != 'NO') {
202 $row['Default'] = '<i>NULL</i>';
203 }
204 } else {
205 $row['Default'] = htmlspecialchars($row['Default']);
206 }
207 $field_name = htmlspecialchars($row['Field']);
208 echo "\n";
209 ?>
210 <tr>
211 <td width="50" class="print" nowrap="nowrap">
212 <?php
213 if (isset($pk_array[$row['Field']])) {
214 echo ' <u>' . $field_name . '</u>&nbsp;' . "\n";
215 } else {
216 echo ' ' . $field_name . '&nbsp;' . "\n";
217 }
218 ?>
219 </td>
220 <td width="80" class="print"<?php echo $type_nowrap; ?>><?php echo $type; ?><bdo dir="ltr"></bdo></td>
221 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $strAttribute; ?></td>-->
222 <td width="40" class="print"><?php echo (($row['Null'] == '' || $row['Null'] == 'NO') ? $strNo : $strYes); ?>&nbsp;</td>
223 <td width="70" class="print" nowrap="nowrap"><?php if (isset($row['Default'])) { echo $row['Default']; } ?>&nbsp;</td>
224 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?>&nbsp;</td>-->
225 <?php
226 echo "\n";
227 if ($have_rel) {
228 echo ' <td class="print">';
229 if (isset($res_rel[$field_name])) {
230 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] );
231 }
232 echo '&nbsp;</td>' . "\n";
233 }
234 if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
235 echo ' <td class="print">';
236 $comments = PMA_getComments($db, $table);
237 if (isset($comments[$field_name])) {
238 echo htmlspecialchars($comments[$field_name]);
239 }
240 echo '&nbsp;</td>' . "\n";
241 }
242 if ($cfgRelation['mimework']) {
243 $mime_map = PMA_getMIME($db, $table, true);
244  
245 echo ' <td class="print">';
246 if (isset($mime_map[$field_name])) {
247 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
248 }
249 echo '&nbsp;</td>' . "\n";
250 }
251 ?>
252 </tr>
253 <?php
254 } // end while
255 PMA_DBI_free_result($result);
256  
257 echo "\n";
258 ?>
259 </table>
260  
261  
262 <?php
263  
264 if ( ! $tbl_is_view
265 && ( $db != 'information_schema'
266 || PMA_MYSQL_INT_VERSION < 50002 ) ) {
267  
268 /**
269 * Displays indexes
270 */
271 $index_count = (isset($indexes))
272 ? count($indexes)
273 : 0;
274 if ($index_count > 0) {
275 echo "\n";
276 ?>
277 <br /><br />
278  
279 <!-- Indexes -->
280 &nbsp;<big><?php echo $strIndexes . ':'; ?></big>
281 <table bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
282 <tr>
283 <th><?php echo $strKeyname; ?></th>
284 <th><?php echo $strType; ?></th>
285 <th><?php echo $strCardinality; ?></th>
286 <th colspan="2"><?php echo $strField; ?></th>
287 </tr>
288 <?php
289 echo "\n";
290 PMA_show_indexes($table, $indexes, $indexes_info, $indexes_data, true, true);
291 echo "\n";
292 ?>
293 </table>
294 <?php
295 echo "\n";
296 } // end display indexes
297  
298  
299 /**
300 * Displays Space usage and row statistics
301 *
302 * staybyte - 9 June 2001
303 */
304 if ($cfg['ShowStats']) {
305 $nonisam = FALSE;
306 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
307 $nonisam = TRUE;
308 }
309 if ($nonisam == FALSE) {
310 // Gets some sizes
311 $mergetable = FALSE;
312 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
313 $mergetable = TRUE;
314 }
315 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
316 if ($mergetable == FALSE) {
317 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
318 }
319 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
320 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
321 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
322 } else {
323 unset($free_size);
324 unset($free_unit);
325 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
326 }
327 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
328 if ($num_rows > 0) {
329 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
330 }
331  
332 // Displays them
333 ?>
334 <br /><br />
335  
336 <table border="0" cellspacing="0" cellpadding="0" class="noborder">
337 <tr>
338  
339 <!-- Space usage -->
340 <td class="print" valign="top">
341 &nbsp;<big><?php echo $strSpaceUsage . ':'; ?></big>
342 <table width="100%" bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
343 <tr>
344 <th><?php echo $strType; ?></th>
345 <th colspan="2" align="center"><?php echo $strUsage; ?></th>
346 </tr>
347 <tr>
348 <td class="print" style="padding-right: 10px"><?php echo $strData; ?></td>
349 <td align="right" class="print" nowrap="nowrap"><?php echo $data_size; ?></td>
350 <td class="print"><?php echo $data_unit; ?></td>
351 </tr>
352 <?php
353 if (isset($index_size)) {
354 echo "\n";
355 ?>
356 <tr>
357 <td class="print" style="padding-right: 10px"><?php echo $strIndex; ?></td>
358 <td align="right" class="print" nowrap="nowrap"><?php echo $index_size; ?></td>
359 <td class="print"><?php echo $index_unit; ?></td>
360 </tr>
361 <?php
362 }
363 if (isset($free_size)) {
364 echo "\n";
365 ?>
366 <tr style="color: #bb0000">
367 <td class="print" style="padding-right: 10px"><?php echo $strOverhead; ?></td>
368 <td align="right" class="print" nowrap="nowrap"><?php echo $free_size; ?></td>
369 <td class="print"><?php echo $free_unit; ?></td>
370 </tr>
371 <tr>
372 <td class="print" style="padding-right: 10px"><?php echo $strEffective; ?></td>
373 <td align="right" class="print" nowrap="nowrap"><?php echo $effect_size; ?></td>
374 <td class="print"><?php echo $effect_unit; ?></td>
375 </tr>
376 <?php
377 }
378 if (isset($tot_size) && $mergetable == FALSE) {
379 echo "\n";
380 ?>
381 <tr>
382 <td class="print" style="padding-right: 10px"><?php echo $strTotalUC; ?></td>
383 <td align="right" class="print" nowrap="nowrap"><?php echo $tot_size; ?></td>
384 <td class="print"><?php echo $tot_unit; ?></td>
385 </tr>
386 <?php
387 }
388 echo "\n";
389 ?>
390 </table>
391 </td>
392  
393 <td width="20" class="print">&nbsp;</td>
394  
395 <!-- Rows Statistic -->
396 <td valign="top">
397 &nbsp;<big><?php echo $strRowsStatistic . ':'; ?></big>
398 <table width=100% bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
399 <tr>
400 <th><?php echo $strStatement; ?></th>
401 <th align="center"><?php echo $strValue; ?></th>
402 </tr>
403 <?php
404 $i = 0;
405 if (isset($showtable['Row_format'])) {
406 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
407 echo "\n";
408 ?>
409 <tr>
410 <td class="print"><?php echo ucfirst($strFormat); ?></td>
411 <td align="<?php echo $cell_align_left; ?>" class="print" nowrap="nowrap">
412 <?php
413 echo ' ';
414 if ($showtable['Row_format'] == 'Fixed') {
415 echo $strFixed;
416 } elseif ($showtable['Row_format'] == 'Dynamic') {
417 echo $strDynamic;
418 } else {
419 echo $showtable['Row_format'];
420 }
421 echo "\n";
422 ?>
423 </td>
424 </tr>
425 <?php
426 }
427 if (isset($showtable['Rows'])) {
428 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
429 echo "\n";
430 ?>
431 <tr>
432 <td class="print"><?php echo ucfirst($strRows); ?></td>
433 <td align="right" class="print" nowrap="nowrap">
434 <?php echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
435 </td>
436 </tr>
437 <?php
438 }
439 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
440 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
441 echo "\n";
442 ?>
443 <tr>
444 <td class="print"><?php echo ucfirst($strRowLength); ?>&nbsp;&oslash;</td>
445 <td class="print" nowrap="nowrap">
446 <?php echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
447 </td>
448 </tr>
449 <?php
450 }
451 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == FALSE) {
452 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
453 echo "\n";
454 ?>
455 <tr>
456 <td class="print"><?php echo ucfirst($strRowSize); ?>&nbsp;&oslash;</td>
457 <td align="right" class="print" nowrap="nowrap">
458 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
459 </td>
460 </tr>
461 <?php
462 }
463 if (isset($showtable['Auto_increment'])) {
464 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
465 echo "\n";
466 ?>
467 <tr>
468 <td class="print"><?php echo ucfirst($strNext); ?>&nbsp;Autoindex</td>
469 <td align="right" class="print" nowrap="nowrap">
470 <?php echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
471 </td>
472 </tr>
473 <?php
474 }
475 echo "\n";
476  
477 if (isset($showtable['Create_time'])) {
478 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
479 echo "\n";
480 ?>
481 <tr>
482 <td class="print"><?php echo $strStatCreateTime; ?></td>
483 <td align="right" class="print" nowrap="nowrap">
484 <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
485 </td>
486 </tr>
487 <?php
488 }
489 echo "\n";
490  
491 if (isset($showtable['Update_time'])) {
492 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
493 echo "\n";
494 ?>
495 <tr>
496 <td class="print"><?php echo $strStatUpdateTime; ?></td>
497 <td align="right" class="print" nowrap="nowrap">
498 <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
499 </td>
500 </tr>
501 <?php
502 }
503 echo "\n";
504  
505 if (isset($showtable['Check_time'])) {
506 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
507 echo "\n";
508 ?>
509 <tr>
510 <td class="print"><?php echo $strStatCheckTime; ?></td>
511 <td align="right" class="print" nowrap="nowrap">
512 <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
513 </td>
514 </tr>
515 <?php
516 }
517 echo "\n";
518 ?>
519 </table>
520 </td>
521 </tr>
522 </table>
523  
524 <?php
525 } // end if ($nonisam == FALSE)
526 } // end if ($cfg['ShowStats'])
527 }
528 echo "\n";
529 if ($multi_tables) {
530 unset($ret_keys);
531 unset($num_rows);
532 unset($show_comment);
533 echo '<hr />' . "\n";
534 } // end if
535 echo '</div>' . "\n";
536  
537 } // end while
538  
539  
540  
541 /**
542 * Displays the footer
543 */
544 echo "\n";
545 ?>
546 <script type="text/javascript" language="javascript">
547 //<![CDATA[
548 function printPage()
549 {
550 // Do print the page
551 if (typeof(window.print) != 'undefined') {
552 window.print();
553 }
554 }
555 //]]>
556 </script>
557 <?php
558 echo '<br /><br />&nbsp;<input type="button" class="print_ignore" style="width: 100px; height: 25px" id="print" value="' . $strPrint . '" onclick="printPage()" />' . "\n";
559  
560 require_once('./libraries/footer.inc.php');
561 ?>