tbl_printview.php 16 KB

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