Chinese Simplified update
[phpmyadmin/crack.git] / tbl_printview.php
blob949a78a119f072cb5caedc66a1584f0ad2ce36fc
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 * @package phpMyAdmin
7 */
9 /**
12 require_once './libraries/common.inc.php';
14 require './libraries/tbl_common.php';
16 /**
17 * Gets the variables sent or posted to this script, then displays headers
19 $print_view = true;
20 if (! isset($selected_tbl)) {
21 require_once './libraries/header.inc.php';
24 // Check parameters
26 if (! isset($the_tables) || ! is_array($the_tables)) {
27 $the_tables = array();
30 /**
31 * Gets the relations settings
33 require_once './libraries/relation.lib.php';
34 require_once './libraries/transformations.lib.php';
35 require_once './libraries/Index.class.php';
37 $cfgRelation = PMA_getRelationsParam();
39 /**
40 * Defines the url to return to in case of error in a sql statement
42 if (strlen($table)) {
43 $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
44 } else {
45 $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
49 /**
50 * Selects the database
52 PMA_DBI_select_db($db);
55 /**
56 * Multi-tables printview thanks to Christophe Gesche from the "MySQL Form
57 * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
59 if (isset($selected_tbl) && is_array($selected_tbl)) {
60 $the_tables = $selected_tbl;
61 } elseif (strlen($table)) {
62 $the_tables[] = $table;
64 $multi_tables = (count($the_tables) > 1);
66 if ($multi_tables) {
67 if (empty($GLOBALS['is_header_sent'])) {
68 require_once './libraries/header.inc.php';
70 $tbl_list = '';
71 foreach ($the_tables as $key => $table) {
72 $tbl_list .= (empty($tbl_list) ? '' : ', ')
73 . PMA_backquote($table);
75 echo '<strong>'. $strShowTables . ': ' . $tbl_list . '</strong>' . "\n";
76 echo '<hr />' . "\n";
77 } // end if
79 $tables_cnt = count($the_tables);
80 $counter = 0;
82 foreach ($the_tables as $key => $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 $showtable = PMA_Table::sGetStatusInfo($db, $table);
96 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
97 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
99 $tbl_is_view = PMA_Table::isView($db, $table);
102 * Gets fields properties
104 $result = PMA_DBI_query(
105 'SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null,
106 PMA_DBI_QUERY_STORE);
107 $fields_cnt = PMA_DBI_num_rows($result);
110 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
111 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
112 // and SHOW CREATE TABLE says NOT NULL (tested
113 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
115 $show_create_table = PMA_DBI_fetch_value(
116 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
117 0, 1);
118 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
120 // Check if we can use Relations (Mike Beck)
121 // Find which tables are related with the current one and write it in
122 // an array
123 $res_rel = PMA_getForeigners($db, $table);
124 $have_rel = (bool) count($res_rel);
127 * Displays the comments of the table if MySQL >= 3.23
129 if (!empty($show_comment)) {
130 echo $strTableComments . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
134 * Displays the table structure
138 <!-- TABLE INFORMATIONS -->
139 <table style="width: 100%;">
140 <thead>
141 <tr>
142 <th><?php echo $strField; ?></th>
143 <th><?php echo $strType; ?></th>
144 <!--<th><?php echo $strAttr; ?></th>-->
145 <th><?php echo $strNull; ?></th>
146 <th><?php echo $strDefault; ?></th>
147 <!--<th><?php echo $strExtra; ?></th>-->
148 <?php
149 if ($have_rel) {
150 echo '<th>' . $strLinksTo . '</th>' . "\n";
152 echo ' <th>' . $strComments . '</th>' . "\n";
153 if ($cfgRelation['mimework']) {
154 echo ' <th>MIME</th>' . "\n";
157 </tr>
158 </thead>
159 <tbody>
160 <?php
161 while ($row = PMA_DBI_fetch_assoc($result)) {
162 $type = $row['Type'];
163 // reformat mysql query output - staybyte - 9. June 2001
164 // loic1: set or enum types: slashes single quotes inside options
165 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
166 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'',
167 ',' . $tmp[2]), 1);
168 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
170 $binary = 0;
171 $unsigned = 0;
172 $zerofill = 0;
173 } else {
174 $type = preg_replace('@BINARY@i', '', $type);
175 $type = preg_replace('@ZEROFILL@i', '', $type);
176 $type = preg_replace('@UNSIGNED@i', '', $type);
177 if (empty($type)) {
178 $type = '&nbsp;';
181 $binary = stristr($row['Type'], 'binary');
182 $unsigned = stristr($row['Type'], 'unsigned');
183 $zerofill = stristr($row['Type'], 'zerofill');
185 $strAttribute = '&nbsp;';
186 if ($binary) {
187 $strAttribute = 'BINARY';
189 if ($unsigned) {
190 $strAttribute = 'UNSIGNED';
192 if ($zerofill) {
193 $strAttribute = 'UNSIGNED ZEROFILL';
195 if (!isset($row['Default'])) {
196 if ($row['Null'] != '' && $row['Null'] != 'NO') {
197 $row['Default'] = '<i>NULL</i>';
199 } else {
200 $row['Default'] = htmlspecialchars($row['Default']);
202 $field_name = htmlspecialchars($row['Field']);
204 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
205 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
206 // the latter.
208 * @todo merge this logic with the one in tbl_structure.php
209 * or move it in a function similar to PMA_DBI_get_columns_full()
210 * but based on SHOW CREATE TABLE because information_schema
211 * cannot be trusted in this case (MySQL bug)
213 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']) {
214 $row['Null'] = '';
218 <tr><td>
219 <?php
220 if (isset($pk_array[$row['Field']])) {
221 echo ' <u>' . $field_name . '</u>' . "\n";
222 } else {
223 echo ' ' . $field_name . "\n";
226 </td>
227 <td><?php echo $type; ?><bdo dir="ltr"></bdo></td>
228 <!--<td><?php echo $strAttribute; ?></td>-->
229 <td><?php echo (($row['Null'] == '' || $row['Null'] == 'NO') ? $strNo : $strYes); ?>&nbsp;</td>
230 <td><?php if (isset($row['Default'])) { echo $row['Default']; } ?>&nbsp;</td>
231 <!--<td><?php echo $row['Extra']; ?>&nbsp;</td>-->
232 <?php
233 if ($have_rel) {
234 echo ' <td>';
235 if (isset($res_rel[$field_name])) {
236 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
238 echo '&nbsp;</td>' . "\n";
240 echo ' <td>';
241 $comments = PMA_getComments($db, $table);
242 if (isset($comments[$field_name])) {
243 echo htmlspecialchars($comments[$field_name]);
245 echo '&nbsp;</td>' . "\n";
246 if ($cfgRelation['mimework']) {
247 $mime_map = PMA_getMIME($db, $table, true);
249 echo ' <td>';
250 if (isset($mime_map[$field_name])) {
251 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
253 echo '&nbsp;</td>' . "\n";
256 </tr>
257 <?php
258 } // end while
259 PMA_DBI_free_result($result);
261 </tbody>
262 </table>
263 <?php
264 if (! $tbl_is_view && $db != 'information_schema') {
266 * Displays indexes
268 echo PMA_Index::getView($table, $db, true);
271 * Displays Space usage and row statistics
273 * staybyte - 9 June 2001
275 if ($cfg['ShowStats']) {
276 $nonisam = false;
277 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
278 $nonisam = true;
280 if ($nonisam == false) {
281 // Gets some sizes
282 $mergetable = false;
283 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
284 $mergetable = true;
286 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
287 if ($mergetable == false) {
288 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
290 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
291 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
292 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
293 } else {
294 unset($free_size);
295 unset($free_unit);
296 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
298 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
299 if ($num_rows > 0) {
300 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
303 // Displays them
305 <br /><br />
307 <table border="0" cellspacing="0" cellpadding="0" class="noborder">
308 <tr>
310 <!-- Space usage -->
311 <td valign="top">
312 <big><?php echo $strSpaceUsage . ':'; ?></big>
313 <table width="100%">
314 <tr>
315 <th><?php echo $strType; ?></th>
316 <th colspan="2" align="center"><?php echo $strUsage; ?></th>
317 </tr>
318 <tr>
319 <td style="padding-right: 10px"><?php echo $strData; ?></td>
320 <td align="right"><?php echo $data_size; ?></td>
321 <td><?php echo $data_unit; ?></td>
322 </tr>
323 <?php
324 if (isset($index_size)) {
325 echo "\n";
327 <tr>
328 <td style="padding-right: 10px"><?php echo $strIndex; ?></td>
329 <td align="right"><?php echo $index_size; ?></td>
330 <td><?php echo $index_unit; ?></td>
331 </tr>
332 <?php
334 if (isset($free_size)) {
335 echo "\n";
337 <tr style="color: #bb0000">
338 <td style="padding-right: 10px"><?php echo $strOverhead; ?></td>
339 <td align="right"><?php echo $free_size; ?></td>
340 <td><?php echo $free_unit; ?></td>
341 </tr>
342 <tr>
343 <td style="padding-right: 10px"><?php echo $strEffective; ?></td>
344 <td align="right"><?php echo $effect_size; ?></td>
345 <td><?php echo $effect_unit; ?></td>
346 </tr>
347 <?php
349 if (isset($tot_size) && $mergetable == false) {
350 echo "\n";
352 <tr>
353 <td style="padding-right: 10px"><?php echo $strTotalUC; ?></td>
354 <td align="right"><?php echo $tot_size; ?></td>
355 <td><?php echo $tot_unit; ?></td>
356 </tr>
357 <?php
359 echo "\n";
361 </table>
362 </td>
364 <td width="20">&nbsp;</td>
366 <!-- Rows Statistic -->
367 <td valign="top">
368 <big><?php echo $strRowsStatistic . ':'; ?></big>
369 <table width="100%">
370 <tr>
371 <th><?php echo $strStatement; ?></th>
372 <th align="center"><?php echo $strValue; ?></th>
373 </tr>
374 <?php
375 if (isset($showtable['Row_format'])) {
377 <tr>
378 <td><?php echo ucfirst($strFormat); ?></td>
379 <td align="<?php echo $cell_align_left; ?>">
380 <?php
381 if ($showtable['Row_format'] == 'Fixed') {
382 echo $strStatic;
383 } elseif ($showtable['Row_format'] == 'Dynamic') {
384 echo $strDynamic;
385 } else {
386 echo $showtable['Row_format'];
389 </td>
390 </tr>
391 <?php
393 if (isset($showtable['Rows'])) {
395 <tr>
396 <td><?php echo ucfirst($strRows); ?></td>
397 <td align="right">
398 <?php echo PMA_formatNumber($showtable['Rows'], 0) . "\n"; ?>
399 </td>
400 </tr>
401 <?php
403 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
405 <tr>
406 <td><?php echo ucfirst($strRowLength); ?>&nbsp;&oslash;</td>
407 <td>
408 <?php echo PMA_formatNumber($showtable['Avg_row_length'], 0) . "\n"; ?>
409 </td>
410 </tr>
411 <?php
413 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
415 <tr>
416 <td><?php echo ucfirst($strRowSize); ?>&nbsp;&oslash;</td>
417 <td align="right">
418 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
419 </td>
420 </tr>
421 <?php
423 if (isset($showtable['Auto_increment'])) {
425 <tr>
426 <td><?php echo ucfirst($strNext); ?>&nbsp;Autoindex</td>
427 <td align="right">
428 <?php echo PMA_formatNumber($showtable['Auto_increment'], 0) . "\n"; ?>
429 </td>
430 </tr>
431 <?php
433 if (isset($showtable['Create_time'])) {
435 <tr>
436 <td><?php echo $strStatCreateTime; ?></td>
437 <td align="right">
438 <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
439 </td>
440 </tr>
441 <?php
443 if (isset($showtable['Update_time'])) {
445 <tr>
446 <td><?php echo $strStatUpdateTime; ?></td>
447 <td align="right">
448 <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
449 </td>
450 </tr>
451 <?php
453 if (isset($showtable['Check_time'])) {
455 <tr>
456 <td><?php echo $strStatCheckTime; ?></td>
457 <td align="right">
458 <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
459 </td>
460 </tr>
461 <?php
465 </table>
466 </td>
467 </tr>
468 </table>
470 <?php
471 } // end if ($nonisam == false)
472 } // end if ($cfg['ShowStats'])
474 if ($multi_tables) {
475 unset($num_rows, $show_comment);
476 echo '<hr />' . "\n";
477 } // end if
478 echo '</div>' . "\n";
480 } // end while
483 * Displays the footer
487 <script type="text/javascript">
488 //<![CDATA[
489 function printPage()
491 // Do print the page
492 if (typeof(window.print) != 'undefined') {
493 window.print();
496 //]]>
497 </script>
499 <p class="print_ignore">
500 <input type="button" id="print" value="<?php echo $strPrint; ?>"
501 onclick="printPage()" /></p>
503 <?php
504 require_once './libraries/footer.inc.php';