Add table alias in PMA_DBI_get_tables_full to avoid ambiguous field names in filtered...
[phpmyadmin/crack.git] / tbl_printview.php
blob5a2f02b30874640e9f9f37a4d738b282909ee651
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package phpMyAdmin
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/transformations.lib.php';
33 require_once './libraries/Index.class.php';
35 $cfgRelation = PMA_getRelationsParam();
37 /**
38 * Defines the url to return to in case of error in a sql statement
40 if (strlen($table)) {
41 $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
42 } else {
43 $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
47 /**
48 * Selects the database
50 PMA_DBI_select_db($db);
53 /**
54 * Multi-tables printview
56 if (isset($selected_tbl) && is_array($selected_tbl)) {
57 $the_tables = $selected_tbl;
58 } elseif (strlen($table)) {
59 $the_tables[] = $table;
61 $multi_tables = (count($the_tables) > 1);
63 if ($multi_tables) {
64 if (empty($GLOBALS['is_header_sent'])) {
65 require_once './libraries/header.inc.php';
67 $tbl_list = '';
68 foreach ($the_tables as $key => $table) {
69 $tbl_list .= (empty($tbl_list) ? '' : ', ')
70 . PMA_backquote($table);
72 echo '<strong>'. __('Show tables') . ': ' . $tbl_list . '</strong>' . "\n";
73 echo '<hr />' . "\n";
74 } // end if
76 $tables_cnt = count($the_tables);
77 $counter = 0;
79 foreach ($the_tables as $key => $table) {
80 if ($counter + 1 >= $tables_cnt) {
81 $breakstyle = '';
82 } else {
83 $breakstyle = ' style="page-break-after: always;"';
85 $counter++;
86 echo '<div' . $breakstyle . '>' . "\n";
87 echo '<h1>' . $table . '</h1>' . "\n";
89 /**
90 * Gets table informations
92 $showtable = PMA_Table::sGetStatusInfo($db, $table);
93 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
94 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
96 $tbl_is_view = PMA_Table::isView($db, $table);
98 /**
99 * Gets fields properties
101 $result = PMA_DBI_query(
102 'SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null,
103 PMA_DBI_QUERY_STORE);
104 $fields_cnt = PMA_DBI_num_rows($result);
107 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
108 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
109 // and SHOW CREATE TABLE says NOT NULL (tested
110 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
112 $show_create_table = PMA_DBI_fetch_value(
113 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
114 0, 1);
115 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
117 // Check if we can use Relations (Mike Beck)
118 // Find which tables are related with the current one and write it in
119 // an array
120 $res_rel = PMA_getForeigners($db, $table);
121 $have_rel = (bool) count($res_rel);
124 * Displays the comments of the table if MySQL >= 3.23
126 if (!empty($show_comment)) {
127 echo __('Table comments') . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
131 * Displays the table structure
135 <!-- TABLE INFORMATIONS -->
136 <table style="width: 100%;">
137 <thead>
138 <tr>
139 <th><?php echo __('Column'); ?></th>
140 <th><?php echo __('Type'); ?></th>
141 <!--<th><?php echo __('Attributes'); ?></th>-->
142 <th><?php echo __('Null'); ?></th>
143 <th><?php echo __('Default'); ?></th>
144 <!--<th><?php echo __('Extra'); ?></th>-->
145 <?php
146 if ($have_rel) {
147 echo '<th>' . __('Links to') . '</th>' . "\n";
149 echo ' <th>' . __('Comments') . '</th>' . "\n";
150 if ($cfgRelation['mimework']) {
151 echo ' <th>MIME</th>' . "\n";
154 </tr>
155 </thead>
156 <tbody>
157 <?php
158 while ($row = PMA_DBI_fetch_assoc($result)) {
159 $type = $row['Type'];
160 // reformat mysql query output
161 // set or enum types: slashes single quotes inside options
162 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
163 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'',
164 ',' . $tmp[2]), 1);
165 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
167 $binary = 0;
168 $unsigned = 0;
169 $zerofill = 0;
170 } else {
171 $type = preg_replace('@BINARY@i', '', $type);
172 $type = preg_replace('@ZEROFILL@i', '', $type);
173 $type = preg_replace('@UNSIGNED@i', '', $type);
174 if (empty($type)) {
175 $type = '&nbsp;';
178 $binary = stristr($row['Type'], 'binary');
179 $unsigned = stristr($row['Type'], 'unsigned');
180 $zerofill = stristr($row['Type'], 'zerofill');
182 $attribute = '&nbsp;';
183 if ($binary) {
184 $attribute = 'BINARY';
186 if ($unsigned) {
187 $attribute = 'UNSIGNED';
189 if ($zerofill) {
190 $attribute = 'UNSIGNED ZEROFILL';
192 if (! isset($row['Default'])) {
193 if ($row['Null'] != '' && $row['Null'] != 'NO') {
194 $row['Default'] = '<i>NULL</i>';
196 } else {
197 $row['Default'] = htmlspecialchars($row['Default']);
199 $field_name = htmlspecialchars($row['Field']);
201 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
202 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
203 // the latter.
205 * @todo merge this logic with the one in tbl_structure.php
206 * or move it in a function similar to PMA_DBI_get_columns_full()
207 * but based on SHOW CREATE TABLE because information_schema
208 * cannot be trusted in this case (MySQL bug)
210 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']) {
211 $row['Null'] = '';
215 <tr><td>
216 <?php
217 if (isset($pk_array[$row['Field']])) {
218 echo ' <u>' . $field_name . '</u>' . "\n";
219 } else {
220 echo ' ' . $field_name . "\n";
223 </td>
224 <td><?php echo $type; ?><bdo dir="ltr"></bdo></td>
225 <!--<td><?php echo $attribute; ?></td>-->
226 <td><?php echo (($row['Null'] == '' || $row['Null'] == 'NO') ? __('No') : __('Yes')); ?>&nbsp;</td>
227 <td><?php if (isset($row['Default'])) { echo $row['Default']; } ?>&nbsp;</td>
228 <!--<td><?php echo $row['Extra']; ?>&nbsp;</td>-->
229 <?php
230 if ($have_rel) {
231 echo ' <td>';
232 if (isset($res_rel[$field_name])) {
233 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
235 echo '&nbsp;</td>' . "\n";
237 echo ' <td>';
238 $comments = PMA_getComments($db, $table);
239 if (isset($comments[$field_name])) {
240 echo htmlspecialchars($comments[$field_name]);
242 echo '&nbsp;</td>' . "\n";
243 if ($cfgRelation['mimework']) {
244 $mime_map = PMA_getMIME($db, $table, true);
246 echo ' <td>';
247 if (isset($mime_map[$field_name])) {
248 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
250 echo '&nbsp;</td>' . "\n";
253 </tr>
254 <?php
255 } // end while
256 PMA_DBI_free_result($result);
258 </tbody>
259 </table>
260 <?php
261 if (! $tbl_is_view && strtolower($db) != 'information_schema'
262 && (!PMA_DRIZZLE || strtolower($db) != 'data_dictionary')) {
264 * Displays indexes
266 echo PMA_Index::getView($table, $db, true);
269 * Displays Space usage and row statistics
272 if ($cfg['ShowStats']) {
273 $nonisam = false;
274 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
275 $nonisam = true;
277 if ($nonisam == false) {
278 // Gets some sizes
280 $mergetable = PMA_Table::isMerge($db, $table);
282 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
283 if ($mergetable == false) {
284 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
286 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
287 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
288 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
289 } else {
290 unset($free_size);
291 unset($free_unit);
292 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
294 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
295 if ($num_rows > 0) {
296 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
299 // Displays them
301 <br /><br />
303 <table border="0" cellspacing="0" cellpadding="0" class="noborder">
304 <tr>
306 <!-- Space usage -->
307 <td valign="top">
308 <big><?php echo __('Space usage') . ':'; ?></big>
309 <table width="100%">
310 <tr>
311 <th><?php echo __('Type'); ?></th>
312 <th colspan="2" align="center"><?php echo __('Usage'); ?></th>
313 </tr>
314 <tr>
315 <td style="padding-right: 10px"><?php echo __('Data'); ?></td>
316 <td align="right"><?php echo $data_size; ?></td>
317 <td><?php echo $data_unit; ?></td>
318 </tr>
319 <?php
320 if (isset($index_size)) {
321 echo "\n";
323 <tr>
324 <td style="padding-right: 10px"><?php echo __('Index'); ?></td>
325 <td align="right"><?php echo $index_size; ?></td>
326 <td><?php echo $index_unit; ?></td>
327 </tr>
328 <?php
330 if (isset($free_size)) {
331 echo "\n";
333 <tr style="color: #bb0000">
334 <td style="padding-right: 10px"><?php echo __('Overhead'); ?></td>
335 <td align="right"><?php echo $free_size; ?></td>
336 <td><?php echo $free_unit; ?></td>
337 </tr>
338 <tr>
339 <td style="padding-right: 10px"><?php echo __('Effective'); ?></td>
340 <td align="right"><?php echo $effect_size; ?></td>
341 <td><?php echo $effect_unit; ?></td>
342 </tr>
343 <?php
345 if (isset($tot_size) && $mergetable == false) {
346 echo "\n";
348 <tr>
349 <td style="padding-right: 10px"><?php echo __('Total'); ?></td>
350 <td align="right"><?php echo $tot_size; ?></td>
351 <td><?php echo $tot_unit; ?></td>
352 </tr>
353 <?php
355 echo "\n";
357 </table>
358 </td>
360 <td width="20">&nbsp;</td>
362 <!-- Rows Statistic -->
363 <td valign="top">
364 <big><?php echo __('Row Statistics') . ':'; ?></big>
365 <table width="100%">
366 <tr>
367 <th><?php echo __('Statements'); ?></th>
368 <th align="center"><?php echo __('Value'); ?></th>
369 </tr>
370 <?php
371 if (isset($showtable['Row_format'])) {
373 <tr>
374 <td><?php echo ucfirst(__('Format')); ?></td>
375 <td align="<?php echo $cell_align_left; ?>">
376 <?php
377 if ($showtable['Row_format'] == 'Fixed') {
378 echo __('static');
379 } elseif ($showtable['Row_format'] == 'Dynamic') {
380 echo __('dynamic');
381 } else {
382 echo $showtable['Row_format'];
385 </td>
386 </tr>
387 <?php
389 if (isset($showtable['Rows'])) {
391 <tr>
392 <td><?php echo ucfirst(__('Rows')); ?></td>
393 <td align="right">
394 <?php echo PMA_formatNumber($showtable['Rows'], 0) . "\n"; ?>
395 </td>
396 </tr>
397 <?php
399 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
401 <tr>
402 <td><?php echo ucfirst(__('Row length')); ?>&nbsp;&oslash;</td>
403 <td>
404 <?php echo PMA_formatNumber($showtable['Avg_row_length'], 0) . "\n"; ?>
405 </td>
406 </tr>
407 <?php
409 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
411 <tr>
412 <td><?php echo ucfirst(__(' Row size ')); ?>&nbsp;&oslash;</td>
413 <td align="right">
414 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
415 </td>
416 </tr>
417 <?php
419 if (isset($showtable['Auto_increment'])) {
421 <tr>
422 <td><?php echo ucfirst(__('Next')); ?>&nbsp;Autoindex</td>
423 <td align="right">
424 <?php echo PMA_formatNumber($showtable['Auto_increment'], 0) . "\n"; ?>
425 </td>
426 </tr>
427 <?php
429 if (isset($showtable['Create_time'])) {
431 <tr>
432 <td><?php echo __('Creation'); ?></td>
433 <td align="right">
434 <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
435 </td>
436 </tr>
437 <?php
439 if (isset($showtable['Update_time'])) {
441 <tr>
442 <td><?php echo __('Last update'); ?></td>
443 <td align="right">
444 <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
445 </td>
446 </tr>
447 <?php
449 if (isset($showtable['Check_time'])) {
451 <tr>
452 <td><?php echo __('Last check'); ?></td>
453 <td align="right">
454 <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
455 </td>
456 </tr>
457 <?php
461 </table>
462 </td>
463 </tr>
464 </table>
466 <?php
467 } // end if ($nonisam == false)
468 } // end if ($cfg['ShowStats'])
470 if ($multi_tables) {
471 unset($num_rows, $show_comment);
472 echo '<hr />' . "\n";
473 } // end if
474 echo '</div>' . "\n";
476 } // end while
479 * Displays the footer
483 <script type="text/javascript">
484 //<![CDATA[
485 function printPage()
487 // Do print the page
488 if (typeof(window.print) != 'undefined') {
489 window.print();
492 //]]>
493 </script>
495 <p class="print_ignore">
496 <input type="button" id="print" value="<?php echo __('Print'); ?>"
497 onclick="printPage()" /></p>
499 <?php
500 require './libraries/footer.inc.php';