oops forgot to remove FIXME comments
[phpmyadmin/last10db.git] / tbl_printview.php
blob275c4c6cda2d228bbea7f3349151f83a8a5df008
1 <?php
2 /* $Id$ */
4 require_once './libraries/common.lib.php';
6 require './libraries/tbl_properties_common.php';
8 /**
9 * Gets the variables sent or posted to this script, then displays headers
11 $print_view = true;
12 if (! isset($selected_tbl)) {
13 require_once './libraries/header.inc.php';
16 // Check parameters
18 if (! isset($the_tables) || ! is_array($the_tables)) {
19 $the_tables = array();
22 /**
23 * Gets the relations settings
25 require_once './libraries/relation.lib.php';
26 require_once './libraries/transformations.lib.php';
27 require_once './libraries/tbl_indexes.lib.php';
29 $cfgRelation = PMA_getRelationsParam();
31 /**
32 * Defines the url to return to in case of error in a sql statement
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);
41 /**
42 * Selects the database
44 PMA_DBI_select_db($db);
47 /**
48 * Multi-tables printview thanks to Christophe Gesch� from the "MySQL Form
49 * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
51 if (isset($selected_tbl) && is_array($selected_tbl)) {
52 $the_tables = $selected_tbl;
53 } elseif (isset($table)) {
54 $the_tables[] = $table;
56 $multi_tables = (count($the_tables) > 1);
58 if ($multi_tables) {
59 if (empty($GLOBALS['is_header_sent'])) {
60 require_once './libraries/header.inc.php';
62 $tbl_list = '';
63 foreach ($the_tables as $key => $table) {
64 $tbl_list .= (empty($tbl_list) ? '' : ', ')
65 . PMA_backquote(urldecode($table));
67 echo '<b>'. $strShowTables . ': ' . $tbl_list . '</b>' . "\n";
68 echo '<hr />' . "\n";
69 } // end if
71 $tables_cnt = count($the_tables);
72 $counter = 0;
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;"';
81 $counter++;
82 echo '<div' . $breakstyle . '>' . "\n";
83 echo '<h1>' . $table . '</h1>' . "\n";
85 /**
86 * Gets table informations
88 $result = PMA_DBI_query(
89 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, true) . '\';');
90 $showtable = PMA_DBI_fetch_assoc($result);
91 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
92 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
93 PMA_DBI_free_result($result);
96 // Gets table keys and store them in arrays
97 $indexes = array();
98 $indexes_info = array();
99 $indexes_data = array();
100 $ret_keys = PMA_get_indexes($table, $err_url_0);
102 PMA_extract_indexes($ret_keys, $indexes, $indexes_info, $indexes_data);
105 * Gets fields properties
107 $result = PMA_DBI_query(
108 'SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null,
109 PMA_DBI_QUERY_STORE);
110 $fields_cnt = PMA_DBI_num_rows($result);
112 // Check if we can use Relations (Mike Beck)
113 if (!empty($cfgRelation['relation'])) {
114 // Find which tables are related with the current one and write it in
115 // an array
116 $res_rel = PMA_getForeigners($db, $table);
118 if (count($res_rel) > 0) {
119 $have_rel = true;
120 } else {
121 $have_rel = false;
123 } else {
124 $have_rel = false;
125 } // end if
129 * Displays the comments of the table if MySQL >= 3.23
131 if (!empty($show_comment)) {
132 echo $strTableComments . ': ' . $show_comment . '<br /><br />';
136 * Displays the table structure
140 <!-- TABLE INFORMATIONS -->
141 <table style="width: 100%;">
142 <thead>
143 <tr>
144 <th><?php echo $strField; ?></th>
145 <th><?php echo $strType; ?></th>
146 <!--<th><?php echo $strAttr; ?></th>-->
147 <th><?php echo $strNull; ?></th>
148 <th><?php echo $strDefault; ?></th>
149 <!--<th><?php echo $strExtra; ?></th>-->
150 <?php
151 if ($have_rel) {
152 echo '<th>' . $strLinksTo . '</th>' . "\n";
154 if ($cfgRelation['commwork']) {
155 echo ' <th>' . $strComments . '</th>' . "\n";
157 if ($cfgRelation['mimework']) {
158 echo ' <th>MIME</th>' . "\n";
161 </tr>
162 </thead>
163 <tbody>
164 <?php
165 while ($row = PMA_DBI_fetch_assoc($result)) {
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\\\'',
171 ',' . $tmp[2]), 1);
172 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
174 $binary = 0;
175 $unsigned = 0;
176 $zerofill = 0;
177 } else {
178 $type = preg_replace('@BINARY@i', '', $type);
179 $type = preg_replace('@ZEROFILL@i', '', $type);
180 $type = preg_replace('@UNSIGNED@i', '', $type);
181 if (empty($type)) {
182 $type = '&nbsp;';
185 $binary = stristr($row['Type'], 'binary');
186 $unsigned = stristr($row['Type'], 'unsigned');
187 $zerofill = stristr($row['Type'], 'zerofill');
189 $strAttribute = '&nbsp;';
190 if ($binary) {
191 $strAttribute = 'BINARY';
193 if ($unsigned) {
194 $strAttribute = 'UNSIGNED';
196 if ($zerofill) {
197 $strAttribute = 'UNSIGNED ZEROFILL';
199 if (!isset($row['Default'])) {
200 if ($row['Null'] != '' && $row['Null'] != 'NO') {
201 $row['Default'] = '<i>NULL</i>';
203 } else {
204 $row['Default'] = htmlspecialchars($row['Default']);
206 $field_name = htmlspecialchars($row['Field']);
209 <tr><td>
210 <?php
211 if (isset($pk_array[$row['Field']])) {
212 echo ' <u>' . $field_name . '</u>' . "\n";
213 } else {
214 echo ' ' . $field_name . "\n";
217 </td>
218 <td><?php echo $type; ?><bdo dir="ltr"></bdo></td>
219 <!--<td><?php echo $strAttribute; ?></td>-->
220 <td><?php echo (($row['Null'] == '' || $row['Null'] == 'NO') ? $strNo : $strYes); ?>&nbsp;</td>
221 <td><?php if (isset($row['Default'])) { echo $row['Default']; } ?>&nbsp;</td>
222 <!--<td><?php echo $row['Extra']; ?>&nbsp;</td>-->
223 <?php
224 if ($have_rel) {
225 echo ' <td>';
226 if (isset($res_rel[$field_name])) {
227 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] );
229 echo '&nbsp;</td>' . "\n";
231 if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
232 echo ' <td>';
233 $comments = PMA_getComments($db, $table);
234 if (isset($comments[$field_name])) {
235 echo htmlspecialchars($comments[$field_name]);
237 echo '&nbsp;</td>' . "\n";
239 if ($cfgRelation['mimework']) {
240 $mime_map = PMA_getMIME($db, $table, true);
242 echo ' <td>';
243 if (isset($mime_map[$field_name])) {
244 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
246 echo '&nbsp;</td>' . "\n";
249 </tr>
250 <?php
251 } // end while
252 PMA_DBI_free_result($result);
254 </tbody>
255 </table>
257 <?php
259 if ( ! $tbl_is_view
260 && ( $db != 'information_schema'
261 || PMA_MYSQL_INT_VERSION < 50002 ) ) {
264 * Displays indexes
266 $index_count = (isset($indexes))
267 ? count($indexes)
268 : 0;
269 if ($index_count > 0) {
270 echo "\n";
272 <br /><br />
274 <!-- Indexes -->
275 <big><?php echo $strIndexes . ':'; ?></big>
276 <table>
277 <tr>
278 <th><?php echo $strKeyname; ?></th>
279 <th><?php echo $strType; ?></th>
280 <th><?php echo $strCardinality; ?></th>
281 <th colspan="2"><?php echo $strField; ?></th>
282 </tr>
283 <?php
284 echo "\n";
285 PMA_show_indexes($table, $indexes, $indexes_info, $indexes_data, true, true);
286 echo "\n";
288 </table>
289 <?php
290 echo "\n";
291 } // end display indexes
295 * Displays Space usage and row statistics
297 * staybyte - 9 June 2001
299 if ($cfg['ShowStats']) {
300 $nonisam = false;
301 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
302 $nonisam = true;
304 if ($nonisam == false) {
305 // Gets some sizes
306 $mergetable = false;
307 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
308 $mergetable = true;
310 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
311 if ($mergetable == false) {
312 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
314 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
315 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
316 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
317 } else {
318 unset($free_size);
319 unset($free_unit);
320 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
322 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
323 if ($num_rows > 0) {
324 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
327 // Displays them
329 <br /><br />
331 <table border="0" cellspacing="0" cellpadding="0" class="noborder">
332 <tr>
334 <!-- Space usage -->
335 <td valign="top">
336 <big><?php echo $strSpaceUsage . ':'; ?></big>
337 <table width="100%">
338 <tr>
339 <th><?php echo $strType; ?></th>
340 <th colspan="2" align="center"><?php echo $strUsage; ?></th>
341 </tr>
342 <tr>
343 <td style="padding-right: 10px"><?php echo $strData; ?></td>
344 <td align="right"><?php echo $data_size; ?></td>
345 <td><?php echo $data_unit; ?></td>
346 </tr>
347 <?php
348 if (isset($index_size)) {
349 echo "\n";
351 <tr>
352 <td style="padding-right: 10px"><?php echo $strIndex; ?></td>
353 <td align="right"><?php echo $index_size; ?></td>
354 <td><?php echo $index_unit; ?></td>
355 </tr>
356 <?php
358 if (isset($free_size)) {
359 echo "\n";
361 <tr style="color: #bb0000">
362 <td style="padding-right: 10px"><?php echo $strOverhead; ?></td>
363 <td align="right"><?php echo $free_size; ?></td>
364 <td><?php echo $free_unit; ?></td>
365 </tr>
366 <tr>
367 <td style="padding-right: 10px"><?php echo $strEffective; ?></td>
368 <td align="right"><?php echo $effect_size; ?></td>
369 <td><?php echo $effect_unit; ?></td>
370 </tr>
371 <?php
373 if (isset($tot_size) && $mergetable == false) {
374 echo "\n";
376 <tr>
377 <td style="padding-right: 10px"><?php echo $strTotalUC; ?></td>
378 <td align="right"><?php echo $tot_size; ?></td>
379 <td><?php echo $tot_unit; ?></td>
380 </tr>
381 <?php
383 echo "\n";
385 </table>
386 </td>
388 <td width="20">&nbsp;</td>
390 <!-- Rows Statistic -->
391 <td valign="top">
392 <big><?php echo $strRowsStatistic . ':'; ?></big>
393 <table width="100%">
394 <tr>
395 <th><?php echo $strStatement; ?></th>
396 <th align="center"><?php echo $strValue; ?></th>
397 </tr>
398 <?php
399 if (isset($showtable['Row_format'])) {
401 <tr>
402 <td><?php echo ucfirst($strFormat); ?></td>
403 <td align="<?php echo $cell_align_left; ?>">
404 <?php
405 if ($showtable['Row_format'] == 'Fixed') {
406 echo $strFixed;
407 } elseif ($showtable['Row_format'] == 'Dynamic') {
408 echo $strDynamic;
409 } else {
410 echo $showtable['Row_format'];
413 </td>
414 </tr>
415 <?php
417 if (isset($showtable['Rows'])) {
419 <tr>
420 <td><?php echo ucfirst($strRows); ?></td>
421 <td align="right">
422 <?php echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
423 </td>
424 </tr>
425 <?php
427 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
429 <tr>
430 <td><?php echo ucfirst($strRowLength); ?>&nbsp;&oslash;</td>
431 <td>
432 <?php echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
433 </td>
434 </tr>
435 <?php
437 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
439 <tr>
440 <td><?php echo ucfirst($strRowSize); ?>&nbsp;&oslash;</td>
441 <td align="right">
442 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
443 </td>
444 </tr>
445 <?php
447 if (isset($showtable['Auto_increment'])) {
449 <tr>
450 <td><?php echo ucfirst($strNext); ?>&nbsp;Autoindex</td>
451 <td align="right">
452 <?php echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
453 </td>
454 </tr>
455 <?php
457 if (isset($showtable['Create_time'])) {
459 <tr>
460 <td><?php echo $strStatCreateTime; ?></td>
461 <td align="right">
462 <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
463 </td>
464 </tr>
465 <?php
467 if (isset($showtable['Update_time'])) {
469 <tr>
470 <td><?php echo $strStatUpdateTime; ?></td>
471 <td align="right">
472 <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
473 </td>
474 </tr>
475 <?php
477 if (isset($showtable['Check_time'])) {
479 <tr>
480 <td><?php echo $strStatCheckTime; ?></td>
481 <td align="right">
482 <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
483 </td>
484 </tr>
485 <?php
489 </table>
490 </td>
491 </tr>
492 </table>
494 <?php
495 } // end if ($nonisam == false)
496 } // end if ($cfg['ShowStats'])
498 if ($multi_tables) {
499 unset($ret_keys, $num_rows, $show_comment);
500 echo '<hr />' . "\n";
501 } // end if
502 echo '</div>' . "\n";
504 } // end while
507 * Displays the footer
511 <script type="text/javascript" language="javascript">
512 //<![CDATA[
513 function printPage()
515 // Do print the page
516 if (typeof(window.print) != 'undefined') {
517 window.print();
520 //]]>
521 </script>
523 <p class="print_ignore">
524 <input type="button" id="print" value="<?php echo $strPrint; ?>"
525 onclick="printPage()" /></p>
527 <?php
528 require_once './libraries/footer.inc.php';