3.4.8 release
[phpmyadmin/alexukf.git] / tbl_printview.php
blob554608aaefd741bd6d7dd486d2d4d130121a3a19
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 include_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 include_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>'. __('Showing tables') . ': ' . htmlspecialchars($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>' . htmlspecialchars($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 $columns = PMA_DBI_get_columns($db, $table);
104 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
105 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
106 // and SHOW CREATE TABLE says NOT NULL (tested
107 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
109 $show_create_table = PMA_DBI_fetch_value(
110 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
111 0, 1);
112 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
114 // Check if we can use Relations
115 // Find which tables are related with the current one and write it in
116 // an array
117 $res_rel = PMA_getForeigners($db, $table);
118 $have_rel = (bool) count($res_rel);
121 * Displays the comments of the table if MySQL >= 3.23
123 if (!empty($show_comment)) {
124 echo __('Table comments') . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
128 * Displays the table structure
132 <!-- TABLE INFORMATIONS -->
133 <table style="width: 100%;">
134 <thead>
135 <tr>
136 <th><?php echo __('Column'); ?></th>
137 <th><?php echo __('Type'); ?></th>
138 <th><?php echo __('Null'); ?></th>
139 <th><?php echo __('Default'); ?></th>
140 <?php
141 if ($have_rel) {
142 echo '<th>' . __('Links to') . '</th>' . "\n";
144 echo ' <th>' . __('Comments') . '</th>' . "\n";
145 if ($cfgRelation['mimework']) {
146 echo ' <th>MIME</th>' . "\n";
149 </tr>
150 </thead>
151 <tbody>
152 <?php
153 foreach ($columns as $row) {
154 $extracted_fieldspec = PMA_extractFieldSpec($row['Type']);
155 $type = $extracted_fieldspec['print_type'];
156 $attribute = $extracted_fieldspec['attribute'];
158 if (! isset($row['Default'])) {
159 if ($row['Null'] != '' && $row['Null'] != 'NO') {
160 $row['Default'] = '<i>NULL</i>';
162 } else {
163 $row['Default'] = htmlspecialchars($row['Default']);
165 $field_name = htmlspecialchars($row['Field']);
167 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
168 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
169 // the latter.
171 * @todo merge this logic with the one in tbl_structure.php
172 * or move it in a function similar to PMA_DBI_get_columns_full()
173 * but based on SHOW CREATE TABLE because information_schema
174 * cannot be trusted in this case (MySQL bug)
176 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']) {
177 $row['Null'] = '';
180 echo '<tr><td>';
182 if (isset($pk_array[$row['Field']])) {
183 echo ' <u>' . $field_name . '</u>' . "\n";
184 } else {
185 echo ' ' . $field_name . "\n";
188 </td>
189 <td><?php echo $type; ?><bdo dir="ltr"></bdo></td>
190 <td><?php echo (($row['Null'] == '' || $row['Null'] == 'NO') ? __('No') : __('Yes')); ?>&nbsp;</td>
191 <td><?php if (isset($row['Default'])) { echo $row['Default']; } ?>&nbsp;</td>
192 <?php
193 if ($have_rel) {
194 echo ' <td>';
195 if (isset($res_rel[$field_name])) {
196 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
198 echo '&nbsp;</td>' . "\n";
200 echo ' <td>';
201 $comments = PMA_getComments($db, $table);
202 if (isset($comments[$field_name])) {
203 echo htmlspecialchars($comments[$field_name]);
205 echo '&nbsp;</td>' . "\n";
206 if ($cfgRelation['mimework']) {
207 $mime_map = PMA_getMIME($db, $table, true);
209 echo ' <td>';
210 if (isset($mime_map[$field_name])) {
211 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
213 echo '&nbsp;</td>' . "\n";
216 </tr>
217 <?php
218 } // end foreach
220 </tbody>
221 </table>
222 <?php
223 if (! $tbl_is_view && !PMA_is_system_schema($db)) {
225 * Displays indexes
227 echo PMA_Index::getView($table, $db, true);
230 * Displays Space usage and row statistics
233 if ($cfg['ShowStats']) {
234 $nonisam = false;
235 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
236 $nonisam = true;
238 if ($nonisam == false) {
239 // Gets some sizes
241 $mergetable = PMA_Table::isMerge($db, $table);
243 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
244 if ($mergetable == false) {
245 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
247 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
248 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
249 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
250 } else {
251 unset($free_size);
252 unset($free_unit);
253 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
255 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
256 if ($num_rows > 0) {
257 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
260 // Displays them
262 <br /><br />
264 <table border="0" cellspacing="0" cellpadding="0" class="noborder">
265 <tr>
267 <!-- Space usage -->
268 <td valign="top">
269 <big><?php echo __('Space usage') . ':'; ?></big>
270 <table width="100%">
271 <tr>
272 <th><?php echo __('Type'); ?></th>
273 <th colspan="2" align="center"><?php echo __('Usage'); ?></th>
274 </tr>
275 <tr>
276 <td style="padding-right: 10px"><?php echo __('Data'); ?></td>
277 <td align="right"><?php echo $data_size; ?></td>
278 <td><?php echo $data_unit; ?></td>
279 </tr>
280 <?php
281 if (isset($index_size)) {
282 echo "\n";
284 <tr>
285 <td style="padding-right: 10px"><?php echo __('Index'); ?></td>
286 <td align="right"><?php echo $index_size; ?></td>
287 <td><?php echo $index_unit; ?></td>
288 </tr>
289 <?php
291 if (isset($free_size)) {
292 echo "\n";
294 <tr style="color: #bb0000">
295 <td style="padding-right: 10px"><?php echo __('Overhead'); ?></td>
296 <td align="right"><?php echo $free_size; ?></td>
297 <td><?php echo $free_unit; ?></td>
298 </tr>
299 <tr>
300 <td style="padding-right: 10px"><?php echo __('Effective'); ?></td>
301 <td align="right"><?php echo $effect_size; ?></td>
302 <td><?php echo $effect_unit; ?></td>
303 </tr>
304 <?php
306 if (isset($tot_size) && $mergetable == false) {
307 echo "\n";
309 <tr>
310 <td style="padding-right: 10px"><?php echo __('Total'); ?></td>
311 <td align="right"><?php echo $tot_size; ?></td>
312 <td><?php echo $tot_unit; ?></td>
313 </tr>
314 <?php
316 echo "\n";
318 </table>
319 </td>
321 <td width="20">&nbsp;</td>
323 <!-- Rows Statistic -->
324 <td valign="top">
325 <big><?php echo __('Row Statistics') . ':'; ?></big>
326 <table width="100%">
327 <tr>
328 <th><?php echo __('Statements'); ?></th>
329 <th align="center"><?php echo __('Value'); ?></th>
330 </tr>
331 <?php
332 if (isset($showtable['Row_format'])) {
334 <tr>
335 <td><?php echo __('Format'); ?></td>
336 <td align="<?php echo $cell_align_left; ?>">
337 <?php
338 if ($showtable['Row_format'] == 'Fixed') {
339 echo __('static');
340 } elseif ($showtable['Row_format'] == 'Dynamic') {
341 echo __('dynamic');
342 } else {
343 echo $showtable['Row_format'];
346 </td>
347 </tr>
348 <?php
350 if (isset($showtable['Rows'])) {
352 <tr>
353 <td><?php echo __('Rows'); ?></td>
354 <td align="right">
355 <?php echo PMA_formatNumber($showtable['Rows'], 0) . "\n"; ?>
356 </td>
357 </tr>
358 <?php
360 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
362 <tr>
363 <td><?php echo __('Row length'); ?>&nbsp;&oslash;</td>
364 <td>
365 <?php echo PMA_formatNumber($showtable['Avg_row_length'], 0) . "\n"; ?>
366 </td>
367 </tr>
368 <?php
370 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
372 <tr>
373 <td><?php echo __('Row size'); ?>&nbsp;&oslash;</td>
374 <td align="right">
375 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
376 </td>
377 </tr>
378 <?php
380 if (isset($showtable['Auto_increment'])) {
382 <tr>
383 <td><?php echo __('Next autoindex'); ?></td>
384 <td align="right">
385 <?php echo PMA_formatNumber($showtable['Auto_increment'], 0) . "\n"; ?>
386 </td>
387 </tr>
388 <?php
390 if (isset($showtable['Create_time'])) {
392 <tr>
393 <td><?php echo __('Creation'); ?></td>
394 <td align="right">
395 <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
396 </td>
397 </tr>
398 <?php
400 if (isset($showtable['Update_time'])) {
402 <tr>
403 <td><?php echo __('Last update'); ?></td>
404 <td align="right">
405 <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
406 </td>
407 </tr>
408 <?php
410 if (isset($showtable['Check_time'])) {
412 <tr>
413 <td><?php echo __('Last check'); ?></td>
414 <td align="right">
415 <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
416 </td>
417 </tr>
418 <?php
422 </table>
423 </td>
424 </tr>
425 </table>
427 <?php
428 } // end if ($nonisam == false)
429 } // end if ($cfg['ShowStats'])
431 if ($multi_tables) {
432 unset($num_rows, $show_comment);
433 echo '<hr />' . "\n";
434 } // end if
435 echo '</div>' . "\n";
437 } // end while
440 * Displays the footer
442 PMA_printButton();
444 echo "<div id='PMA_disable_floating_menubar'></div>\n";
446 require './libraries/footer.inc.php';