updated acknowledgments
[openemr.git] / phpmyadmin / tbl_printview.php
blob78bb961015789a6bcb38cedfd2e0f4066b5d0c25
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Print view for table
6 * @package PhpMyAdmin
7 */
9 /**
12 require_once 'libraries/common.inc.php';
14 $response = PMA_Response::getInstance();
15 $response->getHeader()->enablePrintView();
17 require 'libraries/tbl_common.inc.php';
19 // Check parameters
21 if (! isset($the_tables) || ! is_array($the_tables)) {
22 $the_tables = array();
25 /**
26 * Gets the relations settings
28 require_once 'libraries/transformations.lib.php';
29 require_once 'libraries/Index.class.php';
31 $cfgRelation = PMA_getRelationsParam();
33 /**
34 * Defines the url to return to in case of error in a sql statement
36 if (strlen($table)) {
37 $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
38 } else {
39 $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
43 /**
44 * Selects the database
46 PMA_DBI_select_db($db);
49 /**
50 * Multi-tables printview
52 if (isset($selected_tbl) && is_array($selected_tbl)) {
53 $the_tables = $selected_tbl;
54 } elseif (strlen($table)) {
55 $the_tables[] = $table;
57 $multi_tables = (count($the_tables) > 1);
59 if ($multi_tables) {
60 $tbl_list = '';
61 foreach ($the_tables as $key => $table) {
62 $tbl_list .= (empty($tbl_list) ? '' : ', ')
63 . PMA_Util::backquote($table);
65 echo '<strong>'. __('Showing tables') . ': '
66 . htmlspecialchars($tbl_list) . '</strong>' . "\n";
67 echo '<hr />' . "\n";
68 } // end if
70 $tables_cnt = count($the_tables);
71 $counter = 0;
73 foreach ($the_tables as $key => $table) {
74 if ($counter + 1 >= $tables_cnt) {
75 $breakstyle = '';
76 } else {
77 $breakstyle = ' style="page-break-after: always;"';
79 $counter++;
80 echo '<div' . $breakstyle . '>' . "\n";
81 echo '<h1>' . htmlspecialchars($table) . '</h1>' . "\n";
83 /**
84 * Gets table informations
86 $showtable = PMA_Table::sGetStatusInfo($db, $table);
87 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
88 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
90 $tbl_is_view = PMA_Table::isView($db, $table);
92 /**
93 * Gets fields properties
95 $columns = PMA_DBI_get_columns($db, $table);
98 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
99 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
100 // and SHOW CREATE TABLE says NOT NULL (tested
101 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
103 $show_create_table = PMA_DBI_fetch_value(
104 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.'
105 . PMA_Util::backquote($table),
106 0, 1
108 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
110 // Check if we can use Relations
111 // Find which tables are related with the current one and write it in
112 // an array
113 $res_rel = PMA_getForeigners($db, $table);
114 $have_rel = (bool) count($res_rel);
117 * Displays the comments of the table if MySQL >= 3.23
119 if (!empty($show_comment)) {
120 echo __('Table comments') . ': '
121 . htmlspecialchars($show_comment) . '<br /><br />';
125 * Displays the table structure
127 echo '<table style="width: 100%;">';
128 echo '<thead>';
129 echo '<tr>';
130 echo '<th>' . __('Column') . '</th>';
131 echo '<th>' . __('Type') . '</th>';
132 echo '<th>' . __('Null') . '</th>';
133 echo '<th>' . __('Default') . '</th>';
134 if ($have_rel) {
135 echo '<th>' . __('Links to') . '</th>' . "\n";
137 echo ' <th>' . __('Comments') . '</th>' . "\n";
138 if ($cfgRelation['mimework']) {
139 echo ' <th>MIME</th>' . "\n";
141 echo '</tr>';
142 echo '</thead>';
143 echo '<tbody>';
144 foreach ($columns as $row) {
145 $extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']);
146 $type = $extracted_columnspec['print_type'];
147 $attribute = $extracted_columnspec['attribute'];
149 if (! isset($row['Default'])) {
150 if ($row['Null'] != '' && $row['Null'] != 'NO') {
151 $row['Default'] = '<i>NULL</i>';
153 } else {
154 $row['Default'] = htmlspecialchars($row['Default']);
156 $field_name = htmlspecialchars($row['Field']);
158 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
159 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
160 // the latter.
162 * @todo merge this logic with the one in tbl_structure.php
163 * or move it in a function similar to PMA_DBI_get_columns_full()
164 * but based on SHOW CREATE TABLE because information_schema
165 * cannot be trusted in this case (MySQL bug)
167 if (! empty($analyzed_sql[0]['create_table_fields'][$field_name]['type'])
168 && $analyzed_sql[0]['create_table_fields'][$field_name]['type'] == 'TIMESTAMP'
169 && $analyzed_sql[0]['create_table_fields'][$field_name]['timestamp_not_null']
171 $row['Null'] = '';
174 echo "\n";
175 echo '<tr><td>';
177 if (isset($pk_array[$row['Field']])) {
178 echo ' <u>' . $field_name . '</u>' . "\n";
179 } else {
180 echo ' ' . $field_name . "\n";
182 echo '</td>';
183 echo '<td>' . $type. '<bdo dir="ltr"></bdo></td>';
184 echo '<td>';
185 echo (($row['Null'] == '' || $row['Null'] == 'NO')
186 ? __('No')
187 : __('Yes'));
188 echo '&nbsp;</td>';
189 echo '<td>';
190 if (isset($row['Default'])) {
191 echo $row['Default'];
193 echo '&nbsp;</td>';
194 if ($have_rel) {
195 echo ' <td>';
196 if (isset($res_rel[$field_name])) {
197 echo htmlspecialchars(
198 $res_rel[$field_name]['foreign_table']
199 . ' -> ' . $res_rel[$field_name]['foreign_field']
202 echo '&nbsp;</td>' . "\n";
204 echo ' <td>';
205 $comments = PMA_getComments($db, $table);
206 if (isset($comments[$field_name])) {
207 echo htmlspecialchars($comments[$field_name]);
209 echo '&nbsp;</td>' . "\n";
210 if ($cfgRelation['mimework']) {
211 $mime_map = PMA_getMIME($db, $table, true);
213 echo ' <td>';
214 if (isset($mime_map[$field_name])) {
215 echo htmlspecialchars(
216 str_replace('_', '/', $mime_map[$field_name]['mimetype'])
219 echo '&nbsp;</td>' . "\n";
221 echo '</tr>';
222 } // end foreach
223 echo '</tbody>';
224 echo '</table>';
225 if (! $tbl_is_view && !PMA_is_system_schema($db)) {
227 * Displays indexes
229 echo PMA_Index::getView($table, $db, true);
232 * Displays Space usage and row statistics
235 if ($cfg['ShowStats']) {
236 $nonisam = false;
237 if (isset($showtable['Type'])
238 && ! preg_match('@ISAM|HEAP@i', $showtable['Type'])
240 $nonisam = true;
242 if ($nonisam == false) {
243 // Gets some sizes
245 $mergetable = PMA_Table::isMerge($db, $table);
247 list($data_size, $data_unit) = PMA_Util::formatByteDown(
248 $showtable['Data_length']
250 if ($mergetable == false) {
251 list($index_size, $index_unit)
252 = PMA_Util::formatByteDown(
253 $showtable['Index_length']
256 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
257 list($free_size, $free_unit)
258 = PMA_Util::formatByteDown(
259 $showtable['Data_free']
261 list($effect_size, $effect_unit)
262 = PMA_Util::formatByteDown(
263 $showtable['Data_length'] + $showtable['Index_length']
264 - $showtable['Data_free']
266 } else {
267 unset($free_size);
268 unset($free_unit);
269 list($effect_size, $effect_unit)
270 = PMA_Util::formatByteDown(
271 $showtable['Data_length'] + $showtable['Index_length']
274 list($tot_size, $tot_unit) = PMA_Util::formatByteDown(
275 $showtable['Data_length'] + $showtable['Index_length']
277 if ($num_rows > 0) {
278 list($avg_size, $avg_unit)
279 = PMA_Util::formatByteDown(
280 ($showtable['Data_length'] + $showtable['Index_length'])
281 / $showtable['Rows'],
287 // Displays them
288 echo '<br /><br />';
290 echo '<table cellspacing="0" cellpadding="0">';
291 echo "\n";
292 echo '<tr>';
294 // Space usage
295 echo '<td class="vtop">';
296 echo '<big>' . __('Space usage') . ':</big>';
297 echo '<table width="100%">';
298 echo '<tr>';
299 echo '<td style="padding-right: 10px">' . __('Data') . '</td>';
300 echo '<td class="right">' . $data_size . '</td>';
301 echo '<td>' . $data_unit . '</td>';
302 echo '</tr>';
303 if (isset($index_size)) {
304 echo "\n";
305 echo '<tr>';
306 echo '<td style="padding-right: 10px">' . __('Index') . '</td>';
307 echo '<td class="right">' . $index_size . '</td>';
308 echo '<td>' . $index_unit. '</td>';
309 echo '</tr>';
311 if (isset($free_size)) {
312 echo "\n";
313 echo '<tr style="color: #bb0000">';
314 echo '<td style="padding-right: 10px">';
315 echo __('Overhead');
316 echo '</td>';
317 echo '<td class="right">' . $free_size . '</td>';
318 echo '<td>' . $free_unit . '</td>';
319 echo '</tr>';
320 echo '<tr>';
321 echo '<td style="padding-right: 10px">';
322 echo __('Effective');
323 echo '</td>';
324 echo '<td class="right">' . $effect_size . '</td>';
325 echo '<td>' . $effect_unit . '</td>';
326 echo '</tr>';
328 if (isset($tot_size) && $mergetable == false) {
329 echo "\n";
330 echo '<tr>';
331 echo '<td style="padding-right: 10px">' . __('Total') . '</td>';
332 echo '<td class="right">' . $tot_size . '</td>';
333 echo '<td>' . $tot_unit . '</td>';
334 echo '</tr>';
336 echo "\n";
337 echo '</table>';
338 echo '</td>';
340 echo '<td width="20">&nbsp;</td>';
342 // Rows Statistic
343 echo "\n";
344 echo '<td class="vtop">';
345 echo '<big>' . __('Row Statistics') . ':</big>';
346 echo '<table width="100%">';
347 if (isset($showtable['Row_format'])) {
348 echo "\n";
349 echo '<tr>';
350 echo '<td>' . __('Format') . '</td>';
351 echo '<td class="' . $cell_align_left . '">';
352 if ($showtable['Row_format'] == 'Fixed') {
353 echo __('static');
354 } elseif ($showtable['Row_format'] == 'Dynamic') {
355 echo __('dynamic');
356 } else {
357 echo $showtable['Row_format'];
359 echo '</td>';
360 echo '</tr>';
362 if (isset($showtable['Rows'])) {
363 echo "\n";
364 echo '<tr>';
365 echo '<td>' . __('Rows') . '</td>';
366 echo '<td class="right">';
367 echo PMA_Util::formatNumber($showtable['Rows'], 0);
368 echo '</td>';
369 echo '</tr>';
371 if (isset($showtable['Avg_row_length'])
372 && $showtable['Avg_row_length'] > 0
374 echo "\n";
375 echo '<tr>';
376 echo '<td>' . __('Row length') . '&nbsp;&oslash;</td>';
377 echo '<td>';
378 echo PMA_Util::formatNumber(
379 $showtable['Avg_row_length'], 0
381 echo '</td>';
382 echo '</tr>';
384 if (isset($showtable['Data_length'])
385 && $showtable['Rows'] > 0
386 && $mergetable == false
388 echo "\n";
389 echo '<tr>';
390 echo '<td>' . __('Row size') . '&nbsp;&oslash;</td>';
391 echo '<td class="right">';
392 echo $avg_size . ' ' . $avg_unit;
393 echo '</td>';
394 echo '</tr>';
396 if (isset($showtable['Auto_increment'])) {
397 echo "\n";
398 echo '<tr>';
399 echo '<td>' . __('Next autoindex'). ' </td>';
400 echo '<td class="right">';
401 echo PMA_Util::formatNumber(
402 $showtable['Auto_increment'], 0
404 echo '</td>';
405 echo '</tr>';
407 if (isset($showtable['Create_time'])) {
408 echo "\n";
409 echo '<tr>';
410 echo '<td>' . __('Creation') . '</td>';
411 echo '<td class="right">';
412 echo PMA_Util::localisedDate(
413 strtotime($showtable['Create_time'])
415 echo '</td>';
416 echo '</tr>';
418 if (isset($showtable['Update_time'])) {
419 echo "\n";
420 echo '<tr>';
421 echo '<td>' . __('Last update') . '</td>';
422 echo '<td class="right">';
423 echo PMA_Util::localisedDate(
424 strtotime($showtable['Update_time'])
426 echo '</td>';
427 echo '</tr>';
429 if (isset($showtable['Check_time'])) {
430 echo "\n";
431 echo '<tr>';
432 echo '<td>' . __('Last check') . '</td>';
433 echo '<td class="right">';
434 echo PMA_Util::localisedDate(
435 strtotime($showtable['Check_time'])
437 echo '</td>';
438 echo '</tr>';
441 echo "\n";
442 echo '</table>';
443 echo '</td>';
444 echo '</tr>';
445 echo '</table>';
446 } // end if ($nonisam == false)
447 } // end if ($cfg['ShowStats'])
449 if ($multi_tables) {
450 unset($num_rows, $show_comment);
451 echo '<hr />' . "\n";
452 } // end if
453 echo '</div>' . "\n";
455 } // end while
458 * Displays the footer
460 echo PMA_Util::getButton();
462 echo "<div id='PMA_disable_floating_menubar'></div>\n";