There is no @protected...
[phpmyadmin/crack.git] / tbl_printview.php
blobeef2a2d9db2bb638f95d654fa1f9d34f993e18b4
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 $result = PMA_DBI_query(
96 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, true) . '\';');
97 $showtable = PMA_DBI_fetch_assoc($result);
98 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
99 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
100 PMA_DBI_free_result($result);
102 $tbl_is_view = PMA_Table::isView($db, $table);
105 * Gets fields properties
107 $result = PMA_DBI_query(
108 'SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null,
109 PMA_DBI_QUERY_STORE);
110 $fields_cnt = PMA_DBI_num_rows($result);
113 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
114 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
115 // and SHOW CREATE TABLE says NOT NULL (tested
116 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
118 $show_create_table = PMA_DBI_fetch_value(
119 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
120 0, 1);
121 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
123 // Check if we can use Relations (Mike Beck)
124 // Find which tables are related with the current one and write it in
125 // an array
126 $res_rel = PMA_getForeigners($db, $table);
127 $have_rel = (bool) count($res_rel);
130 * Displays the comments of the table if MySQL >= 3.23
132 if (!empty($show_comment)) {
133 echo $strTableComments . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
137 * Displays the table structure
141 <!-- TABLE INFORMATIONS -->
142 <table style="width: 100%;">
143 <thead>
144 <tr>
145 <th><?php echo $strField; ?></th>
146 <th><?php echo $strType; ?></th>
147 <!--<th><?php echo $strAttr; ?></th>-->
148 <th><?php echo $strNull; ?></th>
149 <th><?php echo $strDefault; ?></th>
150 <!--<th><?php echo $strExtra; ?></th>-->
151 <?php
152 if ($have_rel) {
153 echo '<th>' . $strLinksTo . '</th>' . "\n";
155 echo ' <th>' . $strComments . '</th>' . "\n";
156 if ($cfgRelation['mimework']) {
157 echo ' <th>MIME</th>' . "\n";
160 </tr>
161 </thead>
162 <tbody>
163 <?php
164 while ($row = PMA_DBI_fetch_assoc($result)) {
165 $type = $row['Type'];
166 // reformat mysql query output - staybyte - 9. June 2001
167 // loic1: set or enum types: slashes single quotes inside options
168 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
169 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'',
170 ',' . $tmp[2]), 1);
171 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
173 $binary = 0;
174 $unsigned = 0;
175 $zerofill = 0;
176 } else {
177 $type = preg_replace('@BINARY@i', '', $type);
178 $type = preg_replace('@ZEROFILL@i', '', $type);
179 $type = preg_replace('@UNSIGNED@i', '', $type);
180 if (empty($type)) {
181 $type = '&nbsp;';
184 $binary = stristr($row['Type'], 'binary');
185 $unsigned = stristr($row['Type'], 'unsigned');
186 $zerofill = stristr($row['Type'], 'zerofill');
188 $strAttribute = '&nbsp;';
189 if ($binary) {
190 $strAttribute = 'BINARY';
192 if ($unsigned) {
193 $strAttribute = 'UNSIGNED';
195 if ($zerofill) {
196 $strAttribute = 'UNSIGNED ZEROFILL';
198 if (!isset($row['Default'])) {
199 if ($row['Null'] != '' && $row['Null'] != 'NO') {
200 $row['Default'] = '<i>NULL</i>';
202 } else {
203 $row['Default'] = htmlspecialchars($row['Default']);
205 $field_name = htmlspecialchars($row['Field']);
207 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
208 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
209 // the latter.
211 * @todo merge this logic with the one in tbl_structure.php
212 * or move it in a function similar to PMA_DBI_get_columns_full()
213 * but based on SHOW CREATE TABLE because information_schema
214 * cannot be trusted in this case (MySQL bug)
216 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']) {
217 $row['Null'] = '';
221 <tr><td>
222 <?php
223 if (isset($pk_array[$row['Field']])) {
224 echo ' <u>' . $field_name . '</u>' . "\n";
225 } else {
226 echo ' ' . $field_name . "\n";
229 </td>
230 <td><?php echo $type; ?><bdo dir="ltr"></bdo></td>
231 <!--<td><?php echo $strAttribute; ?></td>-->
232 <td><?php echo (($row['Null'] == '' || $row['Null'] == 'NO') ? $strNo : $strYes); ?>&nbsp;</td>
233 <td><?php if (isset($row['Default'])) { echo $row['Default']; } ?>&nbsp;</td>
234 <!--<td><?php echo $row['Extra']; ?>&nbsp;</td>-->
235 <?php
236 if ($have_rel) {
237 echo ' <td>';
238 if (isset($res_rel[$field_name])) {
239 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
241 echo '&nbsp;</td>' . "\n";
243 echo ' <td>';
244 $comments = PMA_getComments($db, $table);
245 if (isset($comments[$field_name])) {
246 echo htmlspecialchars($comments[$field_name]);
248 echo '&nbsp;</td>' . "\n";
249 if ($cfgRelation['mimework']) {
250 $mime_map = PMA_getMIME($db, $table, true);
252 echo ' <td>';
253 if (isset($mime_map[$field_name])) {
254 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
256 echo '&nbsp;</td>' . "\n";
259 </tr>
260 <?php
261 } // end while
262 PMA_DBI_free_result($result);
264 </tbody>
265 </table>
266 <?php
267 if (! $tbl_is_view && $db != 'information_schema') {
269 * Displays indexes
271 echo PMA_Index::getView($table, $db, true);
274 * Displays Space usage and row statistics
276 * staybyte - 9 June 2001
278 if ($cfg['ShowStats']) {
279 $nonisam = false;
280 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
281 $nonisam = true;
283 if ($nonisam == false) {
284 // Gets some sizes
285 $mergetable = false;
286 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
287 $mergetable = true;
289 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
290 if ($mergetable == false) {
291 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
293 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
294 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
295 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
296 } else {
297 unset($free_size);
298 unset($free_unit);
299 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
301 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
302 if ($num_rows > 0) {
303 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
306 // Displays them
308 <br /><br />
310 <table border="0" cellspacing="0" cellpadding="0" class="noborder">
311 <tr>
313 <!-- Space usage -->
314 <td valign="top">
315 <big><?php echo $strSpaceUsage . ':'; ?></big>
316 <table width="100%">
317 <tr>
318 <th><?php echo $strType; ?></th>
319 <th colspan="2" align="center"><?php echo $strUsage; ?></th>
320 </tr>
321 <tr>
322 <td style="padding-right: 10px"><?php echo $strData; ?></td>
323 <td align="right"><?php echo $data_size; ?></td>
324 <td><?php echo $data_unit; ?></td>
325 </tr>
326 <?php
327 if (isset($index_size)) {
328 echo "\n";
330 <tr>
331 <td style="padding-right: 10px"><?php echo $strIndex; ?></td>
332 <td align="right"><?php echo $index_size; ?></td>
333 <td><?php echo $index_unit; ?></td>
334 </tr>
335 <?php
337 if (isset($free_size)) {
338 echo "\n";
340 <tr style="color: #bb0000">
341 <td style="padding-right: 10px"><?php echo $strOverhead; ?></td>
342 <td align="right"><?php echo $free_size; ?></td>
343 <td><?php echo $free_unit; ?></td>
344 </tr>
345 <tr>
346 <td style="padding-right: 10px"><?php echo $strEffective; ?></td>
347 <td align="right"><?php echo $effect_size; ?></td>
348 <td><?php echo $effect_unit; ?></td>
349 </tr>
350 <?php
352 if (isset($tot_size) && $mergetable == false) {
353 echo "\n";
355 <tr>
356 <td style="padding-right: 10px"><?php echo $strTotalUC; ?></td>
357 <td align="right"><?php echo $tot_size; ?></td>
358 <td><?php echo $tot_unit; ?></td>
359 </tr>
360 <?php
362 echo "\n";
364 </table>
365 </td>
367 <td width="20">&nbsp;</td>
369 <!-- Rows Statistic -->
370 <td valign="top">
371 <big><?php echo $strRowsStatistic . ':'; ?></big>
372 <table width="100%">
373 <tr>
374 <th><?php echo $strStatement; ?></th>
375 <th align="center"><?php echo $strValue; ?></th>
376 </tr>
377 <?php
378 if (isset($showtable['Row_format'])) {
380 <tr>
381 <td><?php echo ucfirst($strFormat); ?></td>
382 <td align="<?php echo $cell_align_left; ?>">
383 <?php
384 if ($showtable['Row_format'] == 'Fixed') {
385 echo $strFixed;
386 } elseif ($showtable['Row_format'] == 'Dynamic') {
387 echo $strDynamic;
388 } else {
389 echo $showtable['Row_format'];
392 </td>
393 </tr>
394 <?php
396 if (isset($showtable['Rows'])) {
398 <tr>
399 <td><?php echo ucfirst($strRows); ?></td>
400 <td align="right">
401 <?php echo PMA_formatNumber($showtable['Rows'], 0) . "\n"; ?>
402 </td>
403 </tr>
404 <?php
406 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
408 <tr>
409 <td><?php echo ucfirst($strRowLength); ?>&nbsp;&oslash;</td>
410 <td>
411 <?php echo PMA_formatNumber($showtable['Avg_row_length'], 0) . "\n"; ?>
412 </td>
413 </tr>
414 <?php
416 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
418 <tr>
419 <td><?php echo ucfirst($strRowSize); ?>&nbsp;&oslash;</td>
420 <td align="right">
421 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
422 </td>
423 </tr>
424 <?php
426 if (isset($showtable['Auto_increment'])) {
428 <tr>
429 <td><?php echo ucfirst($strNext); ?>&nbsp;Autoindex</td>
430 <td align="right">
431 <?php echo PMA_formatNumber($showtable['Auto_increment'], 0) . "\n"; ?>
432 </td>
433 </tr>
434 <?php
436 if (isset($showtable['Create_time'])) {
438 <tr>
439 <td><?php echo $strStatCreateTime; ?></td>
440 <td align="right">
441 <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
442 </td>
443 </tr>
444 <?php
446 if (isset($showtable['Update_time'])) {
448 <tr>
449 <td><?php echo $strStatUpdateTime; ?></td>
450 <td align="right">
451 <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
452 </td>
453 </tr>
454 <?php
456 if (isset($showtable['Check_time'])) {
458 <tr>
459 <td><?php echo $strStatCheckTime; ?></td>
460 <td align="right">
461 <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
462 </td>
463 </tr>
464 <?php
468 </table>
469 </td>
470 </tr>
471 </table>
473 <?php
474 } // end if ($nonisam == false)
475 } // end if ($cfg['ShowStats'])
477 if ($multi_tables) {
478 unset($num_rows, $show_comment);
479 echo '<hr />' . "\n";
480 } // end if
481 echo '</div>' . "\n";
483 } // end while
486 * Displays the footer
490 <script type="text/javascript">
491 //<![CDATA[
492 function printPage()
494 // Do print the page
495 if (typeof(window.print) != 'undefined') {
496 window.print();
499 //]]>
500 </script>
502 <p class="print_ignore">
503 <input type="button" id="print" value="<?php echo $strPrint; ?>"
504 onclick="printPage()" /></p>
506 <?php
507 require_once './libraries/footer.inc.php';