Correctly handle unix timestamp (RFE #1440386).
[phpmyadmin/crack.git] / tbl_printview.php
blob3b3e3b9f3c6ed53d70db903509b58ef05c66f87f
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 Gesche 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);
95 $tbl_is_view = PMA_Table::isView($db, $table);
97 // Gets table keys and store them in arrays
98 $indexes = array();
99 $indexes_info = array();
100 $indexes_data = array();
101 $ret_keys = PMA_get_indexes($table, $err_url_0);
103 PMA_extract_indexes($ret_keys, $indexes, $indexes_info, $indexes_data);
106 * Gets fields properties
108 $result = PMA_DBI_query(
109 'SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null,
110 PMA_DBI_QUERY_STORE);
111 $fields_cnt = PMA_DBI_num_rows($result);
114 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
115 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
116 // and SHOW CREATE TABLE says NOT NULL (tested
117 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
119 $show_create_table = PMA_DBI_fetch_value(
120 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
121 0, 1);
122 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
124 // Check if we can use Relations (Mike Beck)
125 if (!empty($cfgRelation['relation'])) {
126 // Find which tables are related with the current one and write it in
127 // an array
128 $res_rel = PMA_getForeigners($db, $table);
130 if (count($res_rel) > 0) {
131 $have_rel = true;
132 } else {
133 $have_rel = false;
135 } else {
136 $have_rel = false;
137 } // end if
141 * Displays the comments of the table if MySQL >= 3.23
143 if (!empty($show_comment)) {
144 echo $strTableComments . ': ' . $show_comment . '<br /><br />';
148 * Displays the table structure
152 <!-- TABLE INFORMATIONS -->
153 <table style="width: 100%;">
154 <thead>
155 <tr>
156 <th><?php echo $strField; ?></th>
157 <th><?php echo $strType; ?></th>
158 <!--<th><?php echo $strAttr; ?></th>-->
159 <th><?php echo $strNull; ?></th>
160 <th><?php echo $strDefault; ?></th>
161 <!--<th><?php echo $strExtra; ?></th>-->
162 <?php
163 if ($have_rel) {
164 echo '<th>' . $strLinksTo . '</th>' . "\n";
166 if ($cfgRelation['commwork']) {
167 echo ' <th>' . $strComments . '</th>' . "\n";
169 if ($cfgRelation['mimework']) {
170 echo ' <th>MIME</th>' . "\n";
173 </tr>
174 </thead>
175 <tbody>
176 <?php
177 while ($row = PMA_DBI_fetch_assoc($result)) {
178 $type = $row['Type'];
179 // reformat mysql query output - staybyte - 9. June 2001
180 // loic1: set or enum types: slashes single quotes inside options
181 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
182 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'',
183 ',' . $tmp[2]), 1);
184 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
186 $binary = 0;
187 $unsigned = 0;
188 $zerofill = 0;
189 } else {
190 $type = preg_replace('@BINARY@i', '', $type);
191 $type = preg_replace('@ZEROFILL@i', '', $type);
192 $type = preg_replace('@UNSIGNED@i', '', $type);
193 if (empty($type)) {
194 $type = '&nbsp;';
197 $binary = stristr($row['Type'], 'binary');
198 $unsigned = stristr($row['Type'], 'unsigned');
199 $zerofill = stristr($row['Type'], 'zerofill');
201 $strAttribute = '&nbsp;';
202 if ($binary) {
203 $strAttribute = 'BINARY';
205 if ($unsigned) {
206 $strAttribute = 'UNSIGNED';
208 if ($zerofill) {
209 $strAttribute = 'UNSIGNED ZEROFILL';
211 if (!isset($row['Default'])) {
212 if ($row['Null'] != '' && $row['Null'] != 'NO') {
213 $row['Default'] = '<i>NULL</i>';
215 } else {
216 $row['Default'] = htmlspecialchars($row['Default']);
218 $field_name = htmlspecialchars($row['Field']);
220 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
221 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
222 // the latter.
224 * @todo merge this logic with the one in tbl_properties_structure.php
225 * or move it in a function similar to PMA_DBI_get_columns_full()
226 * but based on SHOW CREATE TABLE because information_schema
227 * cannot be trusted in this case (MySQL bug)
229 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']) {
230 $row['Null'] = '';
234 <tr><td>
235 <?php
236 if (isset($pk_array[$row['Field']])) {
237 echo ' <u>' . $field_name . '</u>' . "\n";
238 } else {
239 echo ' ' . $field_name . "\n";
242 </td>
243 <td><?php echo $type; ?><bdo dir="ltr"></bdo></td>
244 <!--<td><?php echo $strAttribute; ?></td>-->
245 <td><?php echo (($row['Null'] == '' || $row['Null'] == 'NO') ? $strNo : $strYes); ?>&nbsp;</td>
246 <td><?php if (isset($row['Default'])) { echo $row['Default']; } ?>&nbsp;</td>
247 <!--<td><?php echo $row['Extra']; ?>&nbsp;</td>-->
248 <?php
249 if ($have_rel) {
250 echo ' <td>';
251 if (isset($res_rel[$field_name])) {
252 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] );
254 echo '&nbsp;</td>' . "\n";
256 if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
257 echo ' <td>';
258 $comments = PMA_getComments($db, $table);
259 if (isset($comments[$field_name])) {
260 echo htmlspecialchars($comments[$field_name]);
262 echo '&nbsp;</td>' . "\n";
264 if ($cfgRelation['mimework']) {
265 $mime_map = PMA_getMIME($db, $table, true);
267 echo ' <td>';
268 if (isset($mime_map[$field_name])) {
269 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
271 echo '&nbsp;</td>' . "\n";
274 </tr>
275 <?php
276 } // end while
277 PMA_DBI_free_result($result);
279 </tbody>
280 </table>
282 <?php
284 if ( ! $tbl_is_view
285 && ( $db != 'information_schema'
286 || PMA_MYSQL_INT_VERSION < 50002 ) ) {
289 * Displays indexes
291 $index_count = (isset($indexes))
292 ? count($indexes)
293 : 0;
294 if ($index_count > 0) {
295 echo "\n";
297 <br /><br />
299 <!-- Indexes -->
300 <big><?php echo $strIndexes . ':'; ?></big>
301 <table>
302 <tr>
303 <th><?php echo $strKeyname; ?></th>
304 <th><?php echo $strType; ?></th>
305 <th><?php echo $strCardinality; ?></th>
306 <th colspan="2"><?php echo $strField; ?></th>
307 </tr>
308 <?php
309 echo "\n";
310 PMA_show_indexes($table, $indexes, $indexes_info, $indexes_data, true, true);
311 echo "\n";
313 </table>
314 <?php
315 echo "\n";
316 } // end display indexes
320 * Displays Space usage and row statistics
322 * staybyte - 9 June 2001
324 if ($cfg['ShowStats']) {
325 $nonisam = false;
326 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
327 $nonisam = true;
329 if ($nonisam == false) {
330 // Gets some sizes
331 $mergetable = false;
332 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
333 $mergetable = true;
335 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
336 if ($mergetable == false) {
337 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
339 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
340 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
341 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
342 } else {
343 unset($free_size);
344 unset($free_unit);
345 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
347 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
348 if ($num_rows > 0) {
349 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
352 // Displays them
354 <br /><br />
356 <table border="0" cellspacing="0" cellpadding="0" class="noborder">
357 <tr>
359 <!-- Space usage -->
360 <td valign="top">
361 <big><?php echo $strSpaceUsage . ':'; ?></big>
362 <table width="100%">
363 <tr>
364 <th><?php echo $strType; ?></th>
365 <th colspan="2" align="center"><?php echo $strUsage; ?></th>
366 </tr>
367 <tr>
368 <td style="padding-right: 10px"><?php echo $strData; ?></td>
369 <td align="right"><?php echo $data_size; ?></td>
370 <td><?php echo $data_unit; ?></td>
371 </tr>
372 <?php
373 if (isset($index_size)) {
374 echo "\n";
376 <tr>
377 <td style="padding-right: 10px"><?php echo $strIndex; ?></td>
378 <td align="right"><?php echo $index_size; ?></td>
379 <td><?php echo $index_unit; ?></td>
380 </tr>
381 <?php
383 if (isset($free_size)) {
384 echo "\n";
386 <tr style="color: #bb0000">
387 <td style="padding-right: 10px"><?php echo $strOverhead; ?></td>
388 <td align="right"><?php echo $free_size; ?></td>
389 <td><?php echo $free_unit; ?></td>
390 </tr>
391 <tr>
392 <td style="padding-right: 10px"><?php echo $strEffective; ?></td>
393 <td align="right"><?php echo $effect_size; ?></td>
394 <td><?php echo $effect_unit; ?></td>
395 </tr>
396 <?php
398 if (isset($tot_size) && $mergetable == false) {
399 echo "\n";
401 <tr>
402 <td style="padding-right: 10px"><?php echo $strTotalUC; ?></td>
403 <td align="right"><?php echo $tot_size; ?></td>
404 <td><?php echo $tot_unit; ?></td>
405 </tr>
406 <?php
408 echo "\n";
410 </table>
411 </td>
413 <td width="20">&nbsp;</td>
415 <!-- Rows Statistic -->
416 <td valign="top">
417 <big><?php echo $strRowsStatistic . ':'; ?></big>
418 <table width="100%">
419 <tr>
420 <th><?php echo $strStatement; ?></th>
421 <th align="center"><?php echo $strValue; ?></th>
422 </tr>
423 <?php
424 if (isset($showtable['Row_format'])) {
426 <tr>
427 <td><?php echo ucfirst($strFormat); ?></td>
428 <td align="<?php echo $cell_align_left; ?>">
429 <?php
430 if ($showtable['Row_format'] == 'Fixed') {
431 echo $strFixed;
432 } elseif ($showtable['Row_format'] == 'Dynamic') {
433 echo $strDynamic;
434 } else {
435 echo $showtable['Row_format'];
438 </td>
439 </tr>
440 <?php
442 if (isset($showtable['Rows'])) {
444 <tr>
445 <td><?php echo ucfirst($strRows); ?></td>
446 <td align="right">
447 <?php echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
448 </td>
449 </tr>
450 <?php
452 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
454 <tr>
455 <td><?php echo ucfirst($strRowLength); ?>&nbsp;&oslash;</td>
456 <td>
457 <?php echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
458 </td>
459 </tr>
460 <?php
462 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
464 <tr>
465 <td><?php echo ucfirst($strRowSize); ?>&nbsp;&oslash;</td>
466 <td align="right">
467 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
468 </td>
469 </tr>
470 <?php
472 if (isset($showtable['Auto_increment'])) {
474 <tr>
475 <td><?php echo ucfirst($strNext); ?>&nbsp;Autoindex</td>
476 <td align="right">
477 <?php echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
478 </td>
479 </tr>
480 <?php
482 if (isset($showtable['Create_time'])) {
484 <tr>
485 <td><?php echo $strStatCreateTime; ?></td>
486 <td align="right">
487 <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
488 </td>
489 </tr>
490 <?php
492 if (isset($showtable['Update_time'])) {
494 <tr>
495 <td><?php echo $strStatUpdateTime; ?></td>
496 <td align="right">
497 <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
498 </td>
499 </tr>
500 <?php
502 if (isset($showtable['Check_time'])) {
504 <tr>
505 <td><?php echo $strStatCheckTime; ?></td>
506 <td align="right">
507 <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
508 </td>
509 </tr>
510 <?php
514 </table>
515 </td>
516 </tr>
517 </table>
519 <?php
520 } // end if ($nonisam == false)
521 } // end if ($cfg['ShowStats'])
523 if ($multi_tables) {
524 unset($ret_keys, $num_rows, $show_comment);
525 echo '<hr />' . "\n";
526 } // end if
527 echo '</div>' . "\n";
529 } // end while
532 * Displays the footer
536 <script type="text/javascript" language="javascript">
537 //<![CDATA[
538 function printPage()
540 // Do print the page
541 if (typeof(window.print) != 'undefined') {
542 window.print();
545 //]]>
546 </script>
548 <p class="print_ignore">
549 <input type="button" id="print" value="<?php echo $strPrint; ?>"
550 onclick="printPage()" /></p>
552 <?php
553 require_once './libraries/footer.inc.php';