PageRenderTime 51ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/pma/tbl_printview.php

https://bitbucket.org/StasPiv/playzone
PHP | 505 lines | 390 code | 43 blank | 72 comment | 83 complexity | 0662bbf21657a26ef4ddef5ef238fa14 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, GPL-2.0, LGPL-2.1
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. *
  5. * @version $Id: tbl_printview.php 12223 2009-02-08 13:46:53Z lem9 $
  6. * @package phpMyAdmin
  7. */
  8. /**
  9. *
  10. */
  11. require_once './libraries/common.inc.php';
  12. require './libraries/tbl_common.php';
  13. /**
  14. * Gets the variables sent or posted to this script, then displays headers
  15. */
  16. $print_view = true;
  17. if (! isset($selected_tbl)) {
  18. require_once './libraries/header.inc.php';
  19. }
  20. // Check parameters
  21. if (! isset($the_tables) || ! is_array($the_tables)) {
  22. $the_tables = array();
  23. }
  24. /**
  25. * Gets the relations settings
  26. */
  27. require_once './libraries/relation.lib.php';
  28. require_once './libraries/transformations.lib.php';
  29. require_once './libraries/Index.class.php';
  30. $cfgRelation = PMA_getRelationsParam();
  31. /**
  32. * Defines the url to return to in case of error in a sql statement
  33. */
  34. if (strlen($table)) {
  35. $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
  36. } else {
  37. $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
  38. }
  39. /**
  40. * Selects the database
  41. */
  42. PMA_DBI_select_db($db);
  43. /**
  44. * Multi-tables printview thanks to Christophe Gesche from the "MySQL Form
  45. * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
  46. */
  47. if (isset($selected_tbl) && is_array($selected_tbl)) {
  48. $the_tables = $selected_tbl;
  49. } elseif (strlen($table)) {
  50. $the_tables[] = $table;
  51. }
  52. $multi_tables = (count($the_tables) > 1);
  53. if ($multi_tables) {
  54. if (empty($GLOBALS['is_header_sent'])) {
  55. require_once './libraries/header.inc.php';
  56. }
  57. $tbl_list = '';
  58. foreach ($the_tables as $key => $table) {
  59. $tbl_list .= (empty($tbl_list) ? '' : ', ')
  60. . PMA_backquote($table);
  61. }
  62. echo '<strong>'. $strShowTables . ': ' . $tbl_list . '</strong>' . "\n";
  63. echo '<hr />' . "\n";
  64. } // end if
  65. $tables_cnt = count($the_tables);
  66. $counter = 0;
  67. foreach ($the_tables as $key => $table) {
  68. if ($counter + 1 >= $tables_cnt) {
  69. $breakstyle = '';
  70. } else {
  71. $breakstyle = ' style="page-break-after: always;"';
  72. }
  73. $counter++;
  74. echo '<div' . $breakstyle . '>' . "\n";
  75. echo '<h1>' . $table . '</h1>' . "\n";
  76. /**
  77. * Gets table informations
  78. */
  79. $showtable = PMA_Table::sGetStatusInfo($db, $table);
  80. $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
  81. $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
  82. $tbl_is_view = PMA_Table::isView($db, $table);
  83. /**
  84. * Gets fields properties
  85. */
  86. $result = PMA_DBI_query(
  87. 'SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null,
  88. PMA_DBI_QUERY_STORE);
  89. $fields_cnt = PMA_DBI_num_rows($result);
  90. // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
  91. // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
  92. // and SHOW CREATE TABLE says NOT NULL (tested
  93. // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
  94. $show_create_table = PMA_DBI_fetch_value(
  95. 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
  96. 0, 1);
  97. $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
  98. // Check if we can use Relations (Mike Beck)
  99. // Find which tables are related with the current one and write it in
  100. // an array
  101. $res_rel = PMA_getForeigners($db, $table);
  102. $have_rel = (bool) count($res_rel);
  103. /**
  104. * Displays the comments of the table if MySQL >= 3.23
  105. */
  106. if (!empty($show_comment)) {
  107. echo $strTableComments . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
  108. }
  109. /**
  110. * Displays the table structure
  111. */
  112. ?>
  113. <!-- TABLE INFORMATIONS -->
  114. <table style="width: 100%;">
  115. <thead>
  116. <tr>
  117. <th><?php echo $strField; ?></th>
  118. <th><?php echo $strType; ?></th>
  119. <!--<th><?php echo $strAttr; ?></th>-->
  120. <th><?php echo $strNull; ?></th>
  121. <th><?php echo $strDefault; ?></th>
  122. <!--<th><?php echo $strExtra; ?></th>-->
  123. <?php
  124. if ($have_rel) {
  125. echo '<th>' . $strLinksTo . '</th>' . "\n";
  126. }
  127. echo ' <th>' . $strComments . '</th>' . "\n";
  128. if ($cfgRelation['mimework']) {
  129. echo ' <th>MIME</th>' . "\n";
  130. }
  131. ?>
  132. </tr>
  133. </thead>
  134. <tbody>
  135. <?php
  136. while ($row = PMA_DBI_fetch_assoc($result)) {
  137. $type = $row['Type'];
  138. // reformat mysql query output - staybyte - 9. June 2001
  139. // loic1: set or enum types: slashes single quotes inside options
  140. if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
  141. $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'',
  142. ',' . $tmp[2]), 1);
  143. $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
  144. $binary = 0;
  145. $unsigned = 0;
  146. $zerofill = 0;
  147. } else {
  148. $type = preg_replace('@BINARY@i', '', $type);
  149. $type = preg_replace('@ZEROFILL@i', '', $type);
  150. $type = preg_replace('@UNSIGNED@i', '', $type);
  151. if (empty($type)) {
  152. $type = '&nbsp;';
  153. }
  154. $binary = stristr($row['Type'], 'binary');
  155. $unsigned = stristr($row['Type'], 'unsigned');
  156. $zerofill = stristr($row['Type'], 'zerofill');
  157. }
  158. $strAttribute = '&nbsp;';
  159. if ($binary) {
  160. $strAttribute = 'BINARY';
  161. }
  162. if ($unsigned) {
  163. $strAttribute = 'UNSIGNED';
  164. }
  165. if ($zerofill) {
  166. $strAttribute = 'UNSIGNED ZEROFILL';
  167. }
  168. if (!isset($row['Default'])) {
  169. if ($row['Null'] != '' && $row['Null'] != 'NO') {
  170. $row['Default'] = '<i>NULL</i>';
  171. }
  172. } else {
  173. $row['Default'] = htmlspecialchars($row['Default']);
  174. }
  175. $field_name = htmlspecialchars($row['Field']);
  176. // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
  177. // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
  178. // the latter.
  179. /**
  180. * @todo merge this logic with the one in tbl_structure.php
  181. * or move it in a function similar to PMA_DBI_get_columns_full()
  182. * but based on SHOW CREATE TABLE because information_schema
  183. * cannot be trusted in this case (MySQL bug)
  184. */
  185. 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']) {
  186. $row['Null'] = '';
  187. }
  188. ?>
  189. <tr><td>
  190. <?php
  191. if (isset($pk_array[$row['Field']])) {
  192. echo ' <u>' . $field_name . '</u>' . "\n";
  193. } else {
  194. echo ' ' . $field_name . "\n";
  195. }
  196. ?>
  197. </td>
  198. <td><?php echo $type; ?><bdo dir="ltr"></bdo></td>
  199. <!--<td><?php echo $strAttribute; ?></td>-->
  200. <td><?php echo (($row['Null'] == '' || $row['Null'] == 'NO') ? $strNo : $strYes); ?>&nbsp;</td>
  201. <td><?php if (isset($row['Default'])) { echo $row['Default']; } ?>&nbsp;</td>
  202. <!--<td><?php echo $row['Extra']; ?>&nbsp;</td>-->
  203. <?php
  204. if ($have_rel) {
  205. echo ' <td>';
  206. if (isset($res_rel[$field_name])) {
  207. echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
  208. }
  209. echo '&nbsp;</td>' . "\n";
  210. }
  211. echo ' <td>';
  212. $comments = PMA_getComments($db, $table);
  213. if (isset($comments[$field_name])) {
  214. echo htmlspecialchars($comments[$field_name]);
  215. }
  216. echo '&nbsp;</td>' . "\n";
  217. if ($cfgRelation['mimework']) {
  218. $mime_map = PMA_getMIME($db, $table, true);
  219. echo ' <td>';
  220. if (isset($mime_map[$field_name])) {
  221. echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
  222. }
  223. echo '&nbsp;</td>' . "\n";
  224. }
  225. ?>
  226. </tr>
  227. <?php
  228. } // end while
  229. PMA_DBI_free_result($result);
  230. ?>
  231. </tbody>
  232. </table>
  233. <?php
  234. if (! $tbl_is_view && $db != 'information_schema') {
  235. /**
  236. * Displays indexes
  237. */
  238. echo PMA_Index::getView($table, $db, true);
  239. /**
  240. * Displays Space usage and row statistics
  241. *
  242. * staybyte - 9 June 2001
  243. */
  244. if ($cfg['ShowStats']) {
  245. $nonisam = false;
  246. if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
  247. $nonisam = true;
  248. }
  249. if ($nonisam == false) {
  250. // Gets some sizes
  251. $mergetable = false;
  252. if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
  253. $mergetable = true;
  254. }
  255. list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
  256. if ($mergetable == false) {
  257. list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
  258. }
  259. if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
  260. list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
  261. list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
  262. } else {
  263. unset($free_size);
  264. unset($free_unit);
  265. list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
  266. }
  267. list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
  268. if ($num_rows > 0) {
  269. list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
  270. }
  271. // Displays them
  272. ?>
  273. <br /><br />
  274. <table border="0" cellspacing="0" cellpadding="0" class="noborder">
  275. <tr>
  276. <!-- Space usage -->
  277. <td valign="top">
  278. <big><?php echo $strSpaceUsage . ':'; ?></big>
  279. <table width="100%">
  280. <tr>
  281. <th><?php echo $strType; ?></th>
  282. <th colspan="2" align="center"><?php echo $strUsage; ?></th>
  283. </tr>
  284. <tr>
  285. <td style="padding-right: 10px"><?php echo $strData; ?></td>
  286. <td align="right"><?php echo $data_size; ?></td>
  287. <td><?php echo $data_unit; ?></td>
  288. </tr>
  289. <?php
  290. if (isset($index_size)) {
  291. echo "\n";
  292. ?>
  293. <tr>
  294. <td style="padding-right: 10px"><?php echo $strIndex; ?></td>
  295. <td align="right"><?php echo $index_size; ?></td>
  296. <td><?php echo $index_unit; ?></td>
  297. </tr>
  298. <?php
  299. }
  300. if (isset($free_size)) {
  301. echo "\n";
  302. ?>
  303. <tr style="color: #bb0000">
  304. <td style="padding-right: 10px"><?php echo $strOverhead; ?></td>
  305. <td align="right"><?php echo $free_size; ?></td>
  306. <td><?php echo $free_unit; ?></td>
  307. </tr>
  308. <tr>
  309. <td style="padding-right: 10px"><?php echo $strEffective; ?></td>
  310. <td align="right"><?php echo $effect_size; ?></td>
  311. <td><?php echo $effect_unit; ?></td>
  312. </tr>
  313. <?php
  314. }
  315. if (isset($tot_size) && $mergetable == false) {
  316. echo "\n";
  317. ?>
  318. <tr>
  319. <td style="padding-right: 10px"><?php echo $strTotalUC; ?></td>
  320. <td align="right"><?php echo $tot_size; ?></td>
  321. <td><?php echo $tot_unit; ?></td>
  322. </tr>
  323. <?php
  324. }
  325. echo "\n";
  326. ?>
  327. </table>
  328. </td>
  329. <td width="20">&nbsp;</td>
  330. <!-- Rows Statistic -->
  331. <td valign="top">
  332. <big><?php echo $strRowsStatistic . ':'; ?></big>
  333. <table width="100%">
  334. <tr>
  335. <th><?php echo $strStatement; ?></th>
  336. <th align="center"><?php echo $strValue; ?></th>
  337. </tr>
  338. <?php
  339. if (isset($showtable['Row_format'])) {
  340. ?>
  341. <tr>
  342. <td><?php echo ucfirst($strFormat); ?></td>
  343. <td align="<?php echo $cell_align_left; ?>">
  344. <?php
  345. if ($showtable['Row_format'] == 'Fixed') {
  346. echo $strStatic;
  347. } elseif ($showtable['Row_format'] == 'Dynamic') {
  348. echo $strDynamic;
  349. } else {
  350. echo $showtable['Row_format'];
  351. }
  352. ?>
  353. </td>
  354. </tr>
  355. <?php
  356. }
  357. if (isset($showtable['Rows'])) {
  358. ?>
  359. <tr>
  360. <td><?php echo ucfirst($strRows); ?></td>
  361. <td align="right">
  362. <?php echo PMA_formatNumber($showtable['Rows'], 0) . "\n"; ?>
  363. </td>
  364. </tr>
  365. <?php
  366. }
  367. if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
  368. ?>
  369. <tr>
  370. <td><?php echo ucfirst($strRowLength); ?>&nbsp;&oslash;</td>
  371. <td>
  372. <?php echo PMA_formatNumber($showtable['Avg_row_length'], 0) . "\n"; ?>
  373. </td>
  374. </tr>
  375. <?php
  376. }
  377. if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
  378. ?>
  379. <tr>
  380. <td><?php echo ucfirst($strRowSize); ?>&nbsp;&oslash;</td>
  381. <td align="right">
  382. <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
  383. </td>
  384. </tr>
  385. <?php
  386. }
  387. if (isset($showtable['Auto_increment'])) {
  388. ?>
  389. <tr>
  390. <td><?php echo ucfirst($strNext); ?>&nbsp;Autoindex</td>
  391. <td align="right">
  392. <?php echo PMA_formatNumber($showtable['Auto_increment'], 0) . "\n"; ?>
  393. </td>
  394. </tr>
  395. <?php
  396. }
  397. if (isset($showtable['Create_time'])) {
  398. ?>
  399. <tr>
  400. <td><?php echo $strStatCreateTime; ?></td>
  401. <td align="right">
  402. <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
  403. </td>
  404. </tr>
  405. <?php
  406. }
  407. if (isset($showtable['Update_time'])) {
  408. ?>
  409. <tr>
  410. <td><?php echo $strStatUpdateTime; ?></td>
  411. <td align="right">
  412. <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
  413. </td>
  414. </tr>
  415. <?php
  416. }
  417. if (isset($showtable['Check_time'])) {
  418. ?>
  419. <tr>
  420. <td><?php echo $strStatCheckTime; ?></td>
  421. <td align="right">
  422. <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
  423. </td>
  424. </tr>
  425. <?php
  426. }
  427. ?>
  428. </table>
  429. </td>
  430. </tr>
  431. </table>
  432. <?php
  433. } // end if ($nonisam == false)
  434. } // end if ($cfg['ShowStats'])
  435. }
  436. if ($multi_tables) {
  437. unset($num_rows, $show_comment);
  438. echo '<hr />' . "\n";
  439. } // end if
  440. echo '</div>' . "\n";
  441. } // end while
  442. /**
  443. * Displays the footer
  444. */
  445. ?>
  446. <script type="text/javascript">
  447. //<![CDATA[
  448. function printPage()
  449. {
  450. // Do print the page
  451. if (typeof(window.print) != 'undefined') {
  452. window.print();
  453. }
  454. }
  455. //]]>
  456. </script>
  457. <p class="print_ignore">
  458. <input type="button" id="print" value="<?php echo $strPrint; ?>"
  459. onclick="printPage()" /></p>
  460. <?php
  461. require_once './libraries/footer.inc.php';
  462. ?>