Czech translation update.
[phpmyadmin/crack.git] / tbl_printview.php
blob3dc914ca9346a179976e4c3dd5d14d299873e85e
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 */
8 /**
11 require_once './libraries/common.inc.php';
13 require './libraries/tbl_common.php';
15 /**
16 * Gets the variables sent or posted to this script, then displays headers
18 $print_view = true;
19 if (! isset($selected_tbl)) {
20 require_once './libraries/header.inc.php';
23 // Check parameters
25 if (! isset($the_tables) || ! is_array($the_tables)) {
26 $the_tables = array();
29 /**
30 * Gets the relations settings
32 require_once './libraries/relation.lib.php';
33 require_once './libraries/transformations.lib.php';
34 require_once './libraries/Index.class.php';
36 $cfgRelation = PMA_getRelationsParam();
38 /**
39 * Defines the url to return to in case of error in a sql statement
41 if (strlen($table)) {
42 $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
43 } else {
44 $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
48 /**
49 * Selects the database
51 PMA_DBI_select_db($db);
54 /**
55 * Multi-tables printview thanks to Christophe Gesche from the "MySQL Form
56 * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
58 if (isset($selected_tbl) && is_array($selected_tbl)) {
59 $the_tables = $selected_tbl;
60 } elseif (strlen($table)) {
61 $the_tables[] = $table;
63 $multi_tables = (count($the_tables) > 1);
65 if ($multi_tables) {
66 if (empty($GLOBALS['is_header_sent'])) {
67 require_once './libraries/header.inc.php';
69 $tbl_list = '';
70 foreach ($the_tables as $key => $table) {
71 $tbl_list .= (empty($tbl_list) ? '' : ', ')
72 . PMA_backquote(urldecode($table));
74 echo '<b>'. $strShowTables . ': ' . $tbl_list . '</b>' . "\n";
75 echo '<hr />' . "\n";
76 } // end if
78 $tables_cnt = count($the_tables);
79 $counter = 0;
81 foreach ($the_tables as $key => $table) {
82 $table = urldecode($table);
83 if ($counter + 1 >= $tables_cnt) {
84 $breakstyle = '';
85 } else {
86 $breakstyle = ' style="page-break-after: always;"';
88 $counter++;
89 echo '<div' . $breakstyle . '>' . "\n";
90 echo '<h1>' . $table . '</h1>' . "\n";
92 /**
93 * Gets table informations
95 $result = PMA_DBI_query(
96 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, true) . '\';');
97 $showtable = PMA_DBI_fetch_assoc($result);
98 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
99 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
100 PMA_DBI_free_result($result);
102 $tbl_is_view = PMA_Table::isView($db, $table);
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);
113 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
114 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
115 // and SHOW CREATE TABLE says NOT NULL (tested
116 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
118 $show_create_table = PMA_DBI_fetch_value(
119 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
120 0, 1);
121 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
123 // Check if we can use Relations (Mike Beck)
124 if (!empty($cfgRelation['relation'])) {
125 // Find which tables are related with the current one and write it in
126 // an array
127 $res_rel = PMA_getForeigners($db, $table);
129 if (count($res_rel) > 0) {
130 $have_rel = true;
131 } else {
132 $have_rel = false;
134 } else {
135 $have_rel = false;
136 } // end if
140 * Displays the comments of the table if MySQL >= 3.23
142 if (!empty($show_comment)) {
143 echo $strTableComments . ': ' . $show_comment . '<br /><br />';
147 * Displays the table structure
151 <!-- TABLE INFORMATIONS -->
152 <table style="width: 100%;">
153 <thead>
154 <tr>
155 <th><?php echo $strField; ?></th>
156 <th><?php echo $strType; ?></th>
157 <!--<th><?php echo $strAttr; ?></th>-->
158 <th><?php echo $strNull; ?></th>
159 <th><?php echo $strDefault; ?></th>
160 <!--<th><?php echo $strExtra; ?></th>-->
161 <?php
162 if ($have_rel) {
163 echo '<th>' . $strLinksTo . '</th>' . "\n";
165 echo ' <th>' . $strComments . '</th>' . "\n";
166 if ($cfgRelation['mimework']) {
167 echo ' <th>MIME</th>' . "\n";
170 </tr>
171 </thead>
172 <tbody>
173 <?php
174 while ($row = PMA_DBI_fetch_assoc($result)) {
175 $type = $row['Type'];
176 // reformat mysql query output - staybyte - 9. June 2001
177 // loic1: set or enum types: slashes single quotes inside options
178 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
179 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'',
180 ',' . $tmp[2]), 1);
181 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
183 $binary = 0;
184 $unsigned = 0;
185 $zerofill = 0;
186 } else {
187 $type = preg_replace('@BINARY@i', '', $type);
188 $type = preg_replace('@ZEROFILL@i', '', $type);
189 $type = preg_replace('@UNSIGNED@i', '', $type);
190 if (empty($type)) {
191 $type = '&nbsp;';
194 $binary = stristr($row['Type'], 'binary');
195 $unsigned = stristr($row['Type'], 'unsigned');
196 $zerofill = stristr($row['Type'], 'zerofill');
198 $strAttribute = '&nbsp;';
199 if ($binary) {
200 $strAttribute = 'BINARY';
202 if ($unsigned) {
203 $strAttribute = 'UNSIGNED';
205 if ($zerofill) {
206 $strAttribute = 'UNSIGNED ZEROFILL';
208 if (!isset($row['Default'])) {
209 if ($row['Null'] != '' && $row['Null'] != 'NO') {
210 $row['Default'] = '<i>NULL</i>';
212 } else {
213 $row['Default'] = htmlspecialchars($row['Default']);
215 $field_name = htmlspecialchars($row['Field']);
217 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
218 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
219 // the latter.
221 * @todo merge this logic with the one in tbl_structure.php
222 * or move it in a function similar to PMA_DBI_get_columns_full()
223 * but based on SHOW CREATE TABLE because information_schema
224 * cannot be trusted in this case (MySQL bug)
226 if (!empty($analyzed_sql[0]['create_table_fields'][$field_name]['type']) && $analyzed_sql[0]['create_table_fields'][$field_name]['type'] == 'TIMESTAMP' && $analyzed_sql[0]['create_table_fields'][$field_name]['timestamp_not_null']) {
227 $row['Null'] = '';
231 <tr><td>
232 <?php
233 if (isset($pk_array[$row['Field']])) {
234 echo ' <u>' . $field_name . '</u>' . "\n";
235 } else {
236 echo ' ' . $field_name . "\n";
239 </td>
240 <td><?php echo $type; ?><bdo dir="ltr"></bdo></td>
241 <!--<td><?php echo $strAttribute; ?></td>-->
242 <td><?php echo (($row['Null'] == '' || $row['Null'] == 'NO') ? $strNo : $strYes); ?>&nbsp;</td>
243 <td><?php if (isset($row['Default'])) { echo $row['Default']; } ?>&nbsp;</td>
244 <!--<td><?php echo $row['Extra']; ?>&nbsp;</td>-->
245 <?php
246 if ($have_rel) {
247 echo ' <td>';
248 if (isset($res_rel[$field_name])) {
249 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
251 echo '&nbsp;</td>' . "\n";
253 echo ' <td>';
254 $comments = PMA_getComments($db, $table);
255 if (isset($comments[$field_name])) {
256 echo htmlspecialchars($comments[$field_name]);
258 echo '&nbsp;</td>' . "\n";
259 if ($cfgRelation['mimework']) {
260 $mime_map = PMA_getMIME($db, $table, true);
262 echo ' <td>';
263 if (isset($mime_map[$field_name])) {
264 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
266 echo '&nbsp;</td>' . "\n";
269 </tr>
270 <?php
271 } // end while
272 PMA_DBI_free_result($result);
274 </tbody>
275 </table>
276 <?php
277 if (! $tbl_is_view && $db != 'information_schema') {
279 * Displays indexes
281 echo PMA_Index::getView($table, $db, true);
284 * Displays Space usage and row statistics
286 * staybyte - 9 June 2001
288 if ($cfg['ShowStats']) {
289 $nonisam = false;
290 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
291 $nonisam = true;
293 if ($nonisam == false) {
294 // Gets some sizes
295 $mergetable = false;
296 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
297 $mergetable = true;
299 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
300 if ($mergetable == false) {
301 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
303 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
304 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
305 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
306 } else {
307 unset($free_size);
308 unset($free_unit);
309 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
311 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
312 if ($num_rows > 0) {
313 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
316 // Displays them
318 <br /><br />
320 <table border="0" cellspacing="0" cellpadding="0" class="noborder">
321 <tr>
323 <!-- Space usage -->
324 <td valign="top">
325 <big><?php echo $strSpaceUsage . ':'; ?></big>
326 <table width="100%">
327 <tr>
328 <th><?php echo $strType; ?></th>
329 <th colspan="2" align="center"><?php echo $strUsage; ?></th>
330 </tr>
331 <tr>
332 <td style="padding-right: 10px"><?php echo $strData; ?></td>
333 <td align="right"><?php echo $data_size; ?></td>
334 <td><?php echo $data_unit; ?></td>
335 </tr>
336 <?php
337 if (isset($index_size)) {
338 echo "\n";
340 <tr>
341 <td style="padding-right: 10px"><?php echo $strIndex; ?></td>
342 <td align="right"><?php echo $index_size; ?></td>
343 <td><?php echo $index_unit; ?></td>
344 </tr>
345 <?php
347 if (isset($free_size)) {
348 echo "\n";
350 <tr style="color: #bb0000">
351 <td style="padding-right: 10px"><?php echo $strOverhead; ?></td>
352 <td align="right"><?php echo $free_size; ?></td>
353 <td><?php echo $free_unit; ?></td>
354 </tr>
355 <tr>
356 <td style="padding-right: 10px"><?php echo $strEffective; ?></td>
357 <td align="right"><?php echo $effect_size; ?></td>
358 <td><?php echo $effect_unit; ?></td>
359 </tr>
360 <?php
362 if (isset($tot_size) && $mergetable == false) {
363 echo "\n";
365 <tr>
366 <td style="padding-right: 10px"><?php echo $strTotalUC; ?></td>
367 <td align="right"><?php echo $tot_size; ?></td>
368 <td><?php echo $tot_unit; ?></td>
369 </tr>
370 <?php
372 echo "\n";
374 </table>
375 </td>
377 <td width="20">&nbsp;</td>
379 <!-- Rows Statistic -->
380 <td valign="top">
381 <big><?php echo $strRowsStatistic . ':'; ?></big>
382 <table width="100%">
383 <tr>
384 <th><?php echo $strStatement; ?></th>
385 <th align="center"><?php echo $strValue; ?></th>
386 </tr>
387 <?php
388 if (isset($showtable['Row_format'])) {
390 <tr>
391 <td><?php echo ucfirst($strFormat); ?></td>
392 <td align="<?php echo $cell_align_left; ?>">
393 <?php
394 if ($showtable['Row_format'] == 'Fixed') {
395 echo $strFixed;
396 } elseif ($showtable['Row_format'] == 'Dynamic') {
397 echo $strDynamic;
398 } else {
399 echo $showtable['Row_format'];
402 </td>
403 </tr>
404 <?php
406 if (isset($showtable['Rows'])) {
408 <tr>
409 <td><?php echo ucfirst($strRows); ?></td>
410 <td align="right">
411 <?php echo PMA_formatNumber($showtable['Rows'], 0) . "\n"; ?>
412 </td>
413 </tr>
414 <?php
416 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
418 <tr>
419 <td><?php echo ucfirst($strRowLength); ?>&nbsp;&oslash;</td>
420 <td>
421 <?php echo PMA_formatNumber($showtable['Avg_row_length'], 0) . "\n"; ?>
422 </td>
423 </tr>
424 <?php
426 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
428 <tr>
429 <td><?php echo ucfirst($strRowSize); ?>&nbsp;&oslash;</td>
430 <td align="right">
431 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
432 </td>
433 </tr>
434 <?php
436 if (isset($showtable['Auto_increment'])) {
438 <tr>
439 <td><?php echo ucfirst($strNext); ?>&nbsp;Autoindex</td>
440 <td align="right">
441 <?php echo PMA_formatNumber($showtable['Auto_increment'], 0) . "\n"; ?>
442 </td>
443 </tr>
444 <?php
446 if (isset($showtable['Create_time'])) {
448 <tr>
449 <td><?php echo $strStatCreateTime; ?></td>
450 <td align="right">
451 <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
452 </td>
453 </tr>
454 <?php
456 if (isset($showtable['Update_time'])) {
458 <tr>
459 <td><?php echo $strStatUpdateTime; ?></td>
460 <td align="right">
461 <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
462 </td>
463 </tr>
464 <?php
466 if (isset($showtable['Check_time'])) {
468 <tr>
469 <td><?php echo $strStatCheckTime; ?></td>
470 <td align="right">
471 <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
472 </td>
473 </tr>
474 <?php
478 </table>
479 </td>
480 </tr>
481 </table>
483 <?php
484 } // end if ($nonisam == false)
485 } // end if ($cfg['ShowStats'])
487 if ($multi_tables) {
488 unset($num_rows, $show_comment);
489 echo '<hr />' . "\n";
490 } // end if
491 echo '</div>' . "\n";
493 } // end while
496 * Displays the footer
500 <script type="text/javascript">
501 //<![CDATA[
502 function printPage()
504 // Do print the page
505 if (typeof(window.print) != 'undefined') {
506 window.print();
509 //]]>
510 </script>
512 <p class="print_ignore">
513 <input type="button" id="print" value="<?php echo $strPrint; ?>"
514 onclick="printPage()" /></p>
516 <?php
517 require_once './libraries/footer.inc.php';