PageRenderTime 61ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/pma/tbl_structure.php

https://bitbucket.org/StasPiv/playzone
PHP | 820 lines | 647 code | 68 blank | 105 comment | 184 complexity | ea7791efc14fdad3749ea63279de9496 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. * Displays table structure infos like fields/columns, indexes, size, rows
  5. * and allows manipulation of indexes and columns/fields
  6. * @version $Id: tbl_structure.php 12284 2009-03-03 16:41:41Z nijel $
  7. * @package phpMyAdmin
  8. */
  9. /**
  10. *
  11. */
  12. require_once './libraries/common.inc.php';
  13. require_once './libraries/mysql_charsets.lib.php';
  14. require_once './libraries/relation.lib.php';
  15. $GLOBALS['js_include'][] = 'mootools.js';
  16. /**
  17. * handle multiple field commands if required
  18. *
  19. * submit_mult_*_x comes from IE if <input type="img" ...> is used
  20. */
  21. if (isset($_REQUEST['submit_mult_change_x'])) {
  22. $submit_mult = $strChange;
  23. } elseif (isset($_REQUEST['submit_mult_drop_x'])) {
  24. $submit_mult = $strDrop;
  25. } elseif (isset($_REQUEST['submit_mult_primary_x'])) {
  26. $submit_mult = $strPrimary;
  27. } elseif (isset($_REQUEST['submit_mult_index_x'])) {
  28. $submit_mult = $strIndex;
  29. } elseif (isset($_REQUEST['submit_mult_unique_x'])) {
  30. $submit_mult = $strUnique;
  31. } elseif (isset($_REQUEST['submit_mult_fulltext_x'])) {
  32. $submit_mult = $strIdxFulltext;
  33. } elseif (isset($_REQUEST['submit_mult_browse_x'])) {
  34. $submit_mult = $strBrowse;
  35. } elseif (isset($_REQUEST['submit_mult'])) {
  36. $submit_mult = $_REQUEST['submit_mult'];
  37. } elseif (isset($_REQUEST['mult_btn']) && $_REQUEST['mult_btn'] == $strYes) {
  38. $submit_mult = 'row_delete';
  39. if (isset($_REQUEST['selected'])) {
  40. $_REQUEST['selected_fld'] = $_REQUEST['selected'];
  41. }
  42. }
  43. if (! empty($submit_mult) && isset($_REQUEST['selected_fld'])) {
  44. $err_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table);
  45. if ($submit_mult == $strBrowse) {
  46. // browsing the table displaying only selected fields/columns
  47. $GLOBALS['active_page'] = 'sql.php';
  48. $sql_query = '';
  49. foreach ($_REQUEST['selected_fld'] as $idx => $sval) {
  50. if ($sql_query == '') {
  51. $sql_query .= 'SELECT ' . PMA_backquote($sval);
  52. } else {
  53. $sql_query .= ', ' . PMA_backquote($sval);
  54. }
  55. }
  56. // what is this htmlspecialchars() for??
  57. //$sql_query .= ' FROM ' . PMA_backquote(htmlspecialchars($table));
  58. $sql_query .= ' FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
  59. require './sql.php';
  60. exit;
  61. } else {
  62. // handle multiple field commands
  63. // handle confirmation of deleting multiple fields/columns
  64. $action = 'tbl_structure.php';
  65. require './libraries/mult_submits.inc.php';
  66. //require_once './libraries/header.inc.php';
  67. //require_once './libraries/tbl_links.inc.php';
  68. if (empty($message)) {
  69. $message = PMA_Message::success();
  70. }
  71. }
  72. }
  73. /**
  74. * Gets the relation settings
  75. */
  76. $cfgRelation = PMA_getRelationsParam();
  77. /**
  78. * Runs common work
  79. */
  80. require_once './libraries/tbl_common.php';
  81. $url_query .= '&amp;goto=tbl_structure.php&amp;back=tbl_structure.php';
  82. $url_params['goto'] = 'tbl_structure.php';
  83. $url_params['back'] = 'tbl_structure.php';
  84. /**
  85. * Prepares the table structure display
  86. */
  87. /**
  88. * Gets tables informations
  89. */
  90. require_once './libraries/tbl_info.inc.php';
  91. /**
  92. * Displays top menu links
  93. */
  94. require_once './libraries/tbl_links.inc.php';
  95. require_once './libraries/Index.class.php';
  96. // 2. Gets table keys and retains them
  97. // @todo should be: $server->db($db)->table($table)->primary()
  98. $primary = PMA_Index::getPrimary($table, $db);
  99. // 3. Get fields
  100. $fields_rs = PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
  101. $fields_cnt = PMA_DBI_num_rows($fields_rs);
  102. // Get more complete field information
  103. // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
  104. // but later, if the analyser returns more information, it
  105. // could be executed for any MySQL version and replace
  106. // the info given by SHOW FULL FIELDS FROM.
  107. //
  108. // We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
  109. // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
  110. // and SHOW CREATE TABLE says NOT NULL (tested
  111. // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
  112. $show_create_table = PMA_DBI_fetch_value(
  113. 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
  114. 0, 1);
  115. $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
  116. /**
  117. * prepare table infos
  118. */
  119. // action titles (image or string)
  120. $titles = array();
  121. $titles['Change'] = PMA_getIcon('b_edit.png', $strChange, true);
  122. $titles['Drop'] = PMA_getIcon('b_drop.png', $strDrop, true);
  123. $titles['NoDrop'] = PMA_getIcon('b_drop.png', $strDrop, true);
  124. $titles['Primary'] = PMA_getIcon('b_primary.png', $strPrimary, true);
  125. $titles['Index'] = PMA_getIcon('b_index.png', $strIndex, true);
  126. $titles['Unique'] = PMA_getIcon('b_unique.png', $strUnique, true);
  127. $titles['IdxFulltext'] = PMA_getIcon('b_ftext.png', $strIdxFulltext, true);
  128. $titles['NoPrimary'] = PMA_getIcon('bd_primary.png', $strPrimary, true);
  129. $titles['NoIndex'] = PMA_getIcon('bd_index.png', $strIndex, true);
  130. $titles['NoUnique'] = PMA_getIcon('bd_unique.png', $strUnique, true);
  131. $titles['NoIdxFulltext'] = PMA_getIcon('bd_ftext.png', $strIdxFulltext, true);
  132. $titles['BrowseDistinctValues'] = PMA_getIcon('b_browse.png', $strBrowseDistinctValues, true);
  133. /**
  134. * Displays the table structure ('show table' works correct since 3.23.03)
  135. */
  136. /* TABLE INFORMATION */
  137. // table header
  138. $i = 0;
  139. ?>
  140. <form method="post" action="tbl_structure.php" name="fieldsForm" id="fieldsForm">
  141. <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  142. <table id="tablestructure" class="data">
  143. <thead>
  144. <tr>
  145. <th id="th<?php echo ++$i; ?>"></th>
  146. <th id="th<?php echo ++$i; ?>"><?php echo $strField; ?></th>
  147. <th id="th<?php echo ++$i; ?>"><?php echo $strType; ?></th>
  148. <th id="th<?php echo ++$i; ?>"><?php echo $strCollation; ?></th>
  149. <th id="th<?php echo ++$i; ?>"><?php echo $strAttr; ?></th>
  150. <th id="th<?php echo ++$i; ?>"><?php echo $strNull; ?></th>
  151. <th id="th<?php echo ++$i; ?>"><?php echo $strDefault; ?></th>
  152. <th id="th<?php echo ++$i; ?>"><?php echo $strExtra; ?></th>
  153. <?php if ($db_is_information_schema || $tbl_is_view) { ?>
  154. <th id="th<?php echo ++$i; ?>"><?php echo $strView; ?></th>
  155. <?php } else { ?>
  156. <th colspan="7" id="th<?php echo ++$i; ?>"><?php echo $strAction; ?></th>
  157. <?php } ?>
  158. </tr>
  159. </thead>
  160. <tbody>
  161. <?php
  162. unset($i);
  163. // table body
  164. // prepare comments
  165. $comments_map = array();
  166. $mime_map = array();
  167. if ($GLOBALS['cfg']['ShowPropertyComments']) {
  168. require_once './libraries/relation.lib.php';
  169. require_once './libraries/transformations.lib.php';
  170. //$cfgRelation = PMA_getRelationsParam();
  171. $comments_map = PMA_getComments($db, $table);
  172. if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) {
  173. $mime_map = PMA_getMIME($db, $table, true);
  174. }
  175. }
  176. $rownum = 0;
  177. $aryFields = array();
  178. $checked = (!empty($checkall) ? ' checked="checked"' : '');
  179. $save_row = array();
  180. $odd_row = true;
  181. while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
  182. $save_row[] = $row;
  183. $rownum++;
  184. $aryFields[] = $row['Field'];
  185. $type = $row['Type'];
  186. $extracted_fieldspec = PMA_extractFieldSpec($row['Type']);
  187. if ('set' == $extracted_fieldspec['type'] || 'enum' == $extracted_fieldspec['type']) {
  188. $type = $extracted_fieldspec['type'] . '(' . $extracted_fieldspec['spec_in_brackets'] . ')';
  189. // for the case ENUM('&#8211;','&ldquo;')
  190. $type = htmlspecialchars($type);
  191. $type_nowrap = '';
  192. $binary = 0;
  193. $unsigned = 0;
  194. $zerofill = 0;
  195. } else {
  196. $type_nowrap = ' nowrap="nowrap"';
  197. // strip the "BINARY" attribute, except if we find "BINARY(" because
  198. // this would be a BINARY or VARBINARY field type
  199. if (!preg_match('@BINARY[\(]@i', $type)) {
  200. $type = preg_replace('@BINARY@i', '', $type);
  201. }
  202. $type = preg_replace('@ZEROFILL@i', '', $type);
  203. $type = preg_replace('@UNSIGNED@i', '', $type);
  204. if (empty($type)) {
  205. $type = ' ';
  206. }
  207. if (!preg_match('@BINARY[\(]@i', $row['Type'])) {
  208. $binary = stristr($row['Type'], 'blob') || stristr($row['Type'], 'binary');
  209. } else {
  210. $binary = false;
  211. }
  212. $unsigned = stristr($row['Type'], 'unsigned');
  213. $zerofill = stristr($row['Type'], 'zerofill');
  214. }
  215. unset($field_charset);
  216. if ((substr($type, 0, 4) == 'char'
  217. || substr($type, 0, 7) == 'varchar'
  218. || substr($type, 0, 4) == 'text'
  219. || substr($type, 0, 8) == 'tinytext'
  220. || substr($type, 0, 10) == 'mediumtext'
  221. || substr($type, 0, 8) == 'longtext'
  222. || substr($type, 0, 3) == 'set'
  223. || substr($type, 0, 4) == 'enum'
  224. ) && !$binary) {
  225. if (strpos($type, ' character set ')) {
  226. $type = substr($type, 0, strpos($type, ' character set '));
  227. }
  228. if (!empty($row['Collation'])) {
  229. $field_charset = $row['Collation'];
  230. } else {
  231. $field_charset = '';
  232. }
  233. } else {
  234. $field_charset = '';
  235. }
  236. // garvin: Display basic mimetype [MIME]
  237. if ($cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME'] && isset($mime_map[$row['Field']]['mimetype'])) {
  238. $type_mime = '<br />MIME: ' . str_replace('_', '/', $mime_map[$row['Field']]['mimetype']);
  239. } else {
  240. $type_mime = '';
  241. }
  242. $attribute = ' ';
  243. if ($binary) {
  244. $attribute = 'BINARY';
  245. }
  246. if ($unsigned) {
  247. $attribute = 'UNSIGNED';
  248. }
  249. if ($zerofill) {
  250. $attribute = 'UNSIGNED ZEROFILL';
  251. }
  252. // MySQL 4.1.2+ TIMESTAMP options
  253. // (if on_update_current_timestamp is set, then it's TRUE)
  254. if (isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])) {
  255. $attribute = 'on update CURRENT_TIMESTAMP';
  256. }
  257. // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
  258. // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
  259. // the latter.
  260. if (!empty($analyzed_sql[0]['create_table_fields'][$row['Field']]['type']) && $analyzed_sql[0]['create_table_fields'][$row['Field']]['type'] == 'TIMESTAMP' && $analyzed_sql[0]['create_table_fields'][$row['Field']]['timestamp_not_null']) {
  261. $row['Null'] = '';
  262. }
  263. if (!isset($row['Default'])) {
  264. if ($row['Null'] == 'YES') {
  265. $row['Default'] = '<i>NULL</i>';
  266. }
  267. } else {
  268. $row['Default'] = htmlspecialchars($row['Default']);
  269. }
  270. $field_encoded = urlencode($row['Field']);
  271. $field_name = htmlspecialchars($row['Field']);
  272. // garvin: underline commented fields and display a hover-title (CSS only)
  273. $comment_style = '';
  274. if (isset($comments_map[$row['Field']])) {
  275. $field_name = '<span style="border-bottom: 1px dashed black;" title="' . htmlspecialchars($comments_map[$row['Field']]) . '">' . $field_name . '</span>';
  276. }
  277. if ($primary && $primary->hasColumn($field_name)) {
  278. $field_name = '<u>' . $field_name . '</u>';
  279. }
  280. echo "\n";
  281. ?>
  282. <tr class="<?php echo $odd_row ? 'odd': 'even'; $odd_row = !$odd_row; ?>">
  283. <td align="center">
  284. <input type="checkbox" name="selected_fld[]" value="<?php echo htmlspecialchars($row['Field']); ?>" id="checkbox_row_<?php echo $rownum; ?>" <?php echo $checked; ?> />
  285. </td>
  286. <th nowrap="nowrap"><label for="checkbox_row_<?php echo $rownum; ?>"><?php echo $field_name; ?></label></th>
  287. <td<?php echo $type_nowrap; ?>><bdo dir="ltr" xml:lang="en"><?php echo $type; echo $type_mime; ?></bdo></td>
  288. <td><?php echo (empty($field_charset) ? '' : '<dfn title="' . PMA_getCollationDescr($field_charset) . '">' . $field_charset . '</dfn>'); ?></td>
  289. <td nowrap="nowrap" style="font-size: 70%"><?php echo $attribute; ?></td>
  290. <td><?php echo (($row['Null'] == 'YES') ? $strYes : $strNo); ?></td>
  291. <td nowrap="nowrap"><?php
  292. if (isset($row['Default'])) {
  293. if ($extracted_fieldspec['type'] == 'bit') {
  294. echo PMA_printable_bit_value($row['Default'], $extracted_fieldspec['spec_in_brackets']);
  295. } else {
  296. echo $row['Default'];
  297. }
  298. }
  299. else {
  300. echo '<i>' . $strNoneDefault . '</i>';
  301. } ?></td>
  302. <td nowrap="nowrap"><?php echo $row['Extra']; ?></td>
  303. <td align="center">
  304. <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('SELECT COUNT(*) AS ' . PMA_backquote($strRows) . ', ' . PMA_backquote($row['Field']) . ' FROM ' . PMA_backquote($table) . ' GROUP BY ' . PMA_backquote($row['Field']) . ' ORDER BY ' . PMA_backquote($row['Field'])); ?>">
  305. <?php echo $titles['BrowseDistinctValues']; ?></a>
  306. </td>
  307. <?php if (! $tbl_is_view && ! $db_is_information_schema) { ?>
  308. <td align="center">
  309. <a href="tbl_alter.php?<?php echo $url_query; ?>&amp;field=<?php echo $field_encoded; ?>">
  310. <?php echo $titles['Change']; ?></a>
  311. </td>
  312. <td align="center">
  313. <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' DROP ' . PMA_backquote($row['Field'])); ?>&amp;cpurge=1&amp;purgekey=<?php echo urlencode($row['Field']); ?>&amp;zero_rows=<?php echo urlencode(sprintf($strFieldHasBeenDropped, htmlspecialchars($row['Field']))); ?>"
  314. onclick="return confirmLink(this, 'ALTER TABLE <?php echo PMA_jsFormat($table); ?> DROP <?php echo PMA_jsFormat($row['Field']); ?>')">
  315. <?php echo $titles['Drop']; ?></a>
  316. </td>
  317. <td align="center">
  318. <?php
  319. if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_type) {
  320. echo $titles['NoPrimary'] . "\n";
  321. } else {
  322. echo "\n";
  323. ?>
  324. <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ($primary ? ' DROP PRIMARY KEY,' : '') . ' ADD PRIMARY KEY(' . PMA_backquote($row['Field']) . ')'); ?>&amp;zero_rows=<?php echo urlencode(sprintf($strAPrimaryKey, htmlspecialchars($row['Field']))); ?>"
  325. onclick="return confirmLink(this, 'ALTER TABLE <?php echo PMA_jsFormat($table) . ($primary ? ' DROP PRIMARY KEY,' : ''); ?> ADD PRIMARY KEY(<?php echo PMA_jsFormat($row['Field']); ?>)')">
  326. <?php echo $titles['Primary']; ?></a>
  327. <?php
  328. }
  329. echo "\n";
  330. ?>
  331. </td>
  332. <td align="center">
  333. <?php
  334. if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_type) {
  335. echo $titles['NoUnique'] . "\n";
  336. } else {
  337. echo "\n";
  338. ?>
  339. <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD UNIQUE(' . PMA_backquote($row['Field']) . ')'); ?>&amp;zero_rows=<?php echo urlencode(sprintf($strAnIndex, htmlspecialchars($row['Field']))); ?>">
  340. <?php echo $titles['Unique']; ?></a>
  341. <?php
  342. }
  343. echo "\n";
  344. ?>
  345. </td>
  346. <td align="center">
  347. <?php
  348. if ($type == 'text' || $type == 'blob' || 'ARCHIVE' == $tbl_type) {
  349. echo $titles['NoIndex'] . "\n";
  350. } else {
  351. echo "\n";
  352. ?>
  353. <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD INDEX(' . PMA_backquote($row['Field']) . ')'); ?>&amp;zero_rows=<?php echo urlencode(sprintf($strAnIndex, htmlspecialchars($row['Field']))); ?>">
  354. <?php echo $titles['Index']; ?></a>
  355. <?php
  356. }
  357. echo "\n";
  358. ?>
  359. </td>
  360. <?php
  361. if (! empty($tbl_type) && ($tbl_type == 'MYISAM' || $tbl_type == 'MARIA')
  362. // FULLTEXT is possible on TEXT, CHAR and VARCHAR
  363. && (strpos(' ' . $type, 'text') || strpos(' ' . $type, 'char'))) {
  364. echo "\n";
  365. ?>
  366. <td align="center" nowrap="nowrap">
  367. <a href="sql.php?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD FULLTEXT(' . PMA_backquote($row['Field']) . ')'); ?>&amp;zero_rows=<?php echo urlencode(sprintf($strAnIndex, htmlspecialchars($row['Field']))); ?>">
  368. <?php echo $titles['IdxFulltext']; ?></a>
  369. </td>
  370. <?php
  371. } else {
  372. echo "\n";
  373. ?>
  374. <td align="center" nowrap="nowrap">
  375. <?php echo $titles['NoIdxFulltext'] . "\n"; ?>
  376. </td>
  377. <?php
  378. } // end if... else...
  379. echo "\n";
  380. } // end if (! $tbl_is_view && ! $db_is_information_schema)
  381. ?>
  382. </tr>
  383. <?php
  384. unset($field_charset);
  385. } // end while
  386. echo '</tbody>' . "\n"
  387. .'</table>' . "\n";
  388. $checkall_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table);
  389. ?>
  390. <img class="selectallarrow" src="<?php echo $pmaThemeImage . 'arrow_' . $text_dir . '.png'; ?>"
  391. width="38" height="22" alt="<?php echo $strWithChecked; ?>" />
  392. <a href="<?php echo $checkall_url; ?>&amp;checkall=1"
  393. onclick="if (markAllRows('fieldsForm')) return false;">
  394. <?php echo $strCheckAll; ?></a>
  395. /
  396. <a href="<?php echo $checkall_url; ?>"
  397. onclick="if (unMarkAllRows('fieldsForm')) return false;">
  398. <?php echo $strUncheckAll; ?></a>
  399. <i><?php echo $strWithChecked; ?></i>
  400. <?php
  401. PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_browse', $strBrowse, 'b_browse.png');
  402. if (! $tbl_is_view && ! $db_is_information_schema) {
  403. PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_change', $strChange, 'b_edit.png');
  404. PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_drop', $strDrop, 'b_drop.png');
  405. if ('ARCHIVE' != $tbl_type) {
  406. PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_primary', $strPrimary, 'b_primary.png');
  407. PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_unique', $strUnique, 'b_unique.png');
  408. PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_index', $strIndex, 'b_index.png');
  409. }
  410. if (! empty($tbl_type) && ($tbl_type == 'MYISAM' || $tbl_type == 'MARIA')) {
  411. PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_fulltext', $strIdxFulltext, 'b_ftext.png');
  412. }
  413. }
  414. ?>
  415. </form>
  416. <hr />
  417. <?php
  418. /**
  419. * Work on the table
  420. */
  421. ?>
  422. <a href="tbl_printview.php?<?php echo $url_query; ?>"><?php
  423. if ($cfg['PropertiesIconic']) {
  424. echo '<img class="icon" src="' . $pmaThemeImage . 'b_print.png" width="16" height="16" alt="' . $strPrintView . '"/>';
  425. }
  426. echo $strPrintView;
  427. ?></a>
  428. <?php
  429. if (! $tbl_is_view && ! $db_is_information_schema) {
  430. // if internal relations are available, or foreign keys are supported
  431. // ($tbl_type comes from libraries/tbl_info.inc.php)
  432. if ($cfgRelation['relwork'] || PMA_foreignkey_supported($tbl_type)) {
  433. ?>
  434. <a href="tbl_relation.php?<?php echo $url_query; ?>"><?php
  435. if ($cfg['PropertiesIconic']) {
  436. echo '<img class="icon" src="' . $pmaThemeImage . 'b_relations.png" width="16" height="16" alt="' . $strRelationView . '"/>';
  437. }
  438. echo $strRelationView;
  439. ?></a>
  440. <?php
  441. }
  442. ?>
  443. <a href="sql.php?<?php echo $url_query; ?>&amp;session_max_rows=all&amp;sql_query=<?php echo urlencode('SELECT * FROM ' . PMA_backquote($table) . ' PROCEDURE ANALYSE()'); ?>"><?php
  444. if ($cfg['PropertiesIconic']) {
  445. echo '<img class="icon" src="' . $pmaThemeImage . 'b_tblanalyse.png" width="16" height="16" alt="' . $strStructPropose . '" />';
  446. }
  447. echo $strStructPropose;
  448. ?></a><?php
  449. echo PMA_showMySQLDocu('Extending_MySQL', 'procedure_analyse') . "\n";
  450. ?><br />
  451. <form method="post" action="tbl_addfield.php"
  452. onsubmit="return checkFormElementInRange(this, 'num_fields', '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidFieldAddCount']); ?>', 1)">
  453. <?php
  454. echo PMA_generate_common_hidden_inputs($db, $table);
  455. if ($cfg['PropertiesIconic']) {
  456. echo '<img class="icon" src="' . $pmaThemeImage . 'b_insrow.png" width="16" height="16" alt="' . $strAddNewField . '"/>';
  457. }
  458. echo sprintf($strAddFields, '<input type="text" name="num_fields" size="2" maxlength="2" value="1" style="vertical-align: middle" onfocus="this.select()" />');
  459. // I tried displaying the drop-down inside the label but with Firefox
  460. // the drop-down was blinking
  461. $fieldOptions = '<select name="after_field" style="vertical-align: middle" onclick="this.form.field_where[2].checked=true" onchange="this.form.field_where[2].checked=true">';
  462. foreach ($aryFields as $fieldname) {
  463. $fieldOptions .= '<option value="' . htmlspecialchars($fieldname) . '">' . htmlspecialchars($fieldname) . '</option>' . "\n";
  464. }
  465. unset($aryFields);
  466. $fieldOptions .= '</select>';
  467. $choices = array(
  468. 'last' => $strAtEndOfTable,
  469. 'first' => $strAtBeginningOfTable,
  470. 'after' => sprintf($strAfter, '')
  471. );
  472. PMA_generate_html_radio('field_where', $choices, 'last', false);
  473. echo $fieldOptions;
  474. unset($fieldOptions, $choices);
  475. ?>
  476. <input type="submit" value="<?php echo $strGo; ?>" style="vertical-align: middle" />
  477. </form>
  478. <hr />
  479. <?php
  480. }
  481. /**
  482. * If there are more than 20 rows, displays browse/select/insert/empty/drop
  483. * links again
  484. */
  485. if ($fields_cnt > 20) {
  486. require './libraries/tbl_links.inc.php';
  487. } // end if ($fields_cnt > 20)
  488. /**
  489. * Displays indexes
  490. */
  491. PMA_generate_slider_effect('tablestatistics_indexes', $strDetails);
  492. if (! $tbl_is_view && ! $db_is_information_schema && 'ARCHIVE' != $tbl_type) {
  493. /**
  494. * Display indexes
  495. */
  496. echo PMA_Index::getView($table, $db);
  497. ?>
  498. <br />
  499. <form action="./tbl_indexes.php" method="post"
  500. onsubmit="return checkFormElementInRange(this, 'idx_num_fields',
  501. '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidColumnCount']); ?>',
  502. 1)">
  503. <fieldset>
  504. <?php
  505. echo PMA_generate_common_hidden_inputs($db, $table);
  506. echo sprintf($strCreateIndex,
  507. '<input type="text" size="2" name="added_fields" value="1" />');
  508. ?>
  509. <input type="submit" name="create_index" value="<?php echo $strGo; ?>"
  510. onclick="return checkFormElementInRange(this.form,
  511. 'idx_num_fields',
  512. '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidColumnCount']); ?>',
  513. 1)" />
  514. </fieldset>
  515. </form>
  516. <br />
  517. <?php
  518. }
  519. echo '<div id="tablestatistics">' . "\n";
  520. /**
  521. * Displays Space usage and row statistics
  522. */
  523. // BEGIN - Calc Table Space - staybyte - 9 June 2001
  524. // loic1, 22 feb. 2002: updated with patch from
  525. // Joshua Nye <josh at boxcarmedia.com> to get valid
  526. // statistics whatever is the table type
  527. if ($cfg['ShowStats']) {
  528. if (empty($showtable)) {
  529. $showtable = PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], null, true);
  530. }
  531. $nonisam = false;
  532. $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
  533. if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
  534. $nonisam = true;
  535. }
  536. // Gets some sizes
  537. $mergetable = false;
  538. if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
  539. $mergetable = true;
  540. }
  541. // this is to display for example 261.2 MiB instead of 268k KiB
  542. $max_digits = 5;
  543. $decimals = 1;
  544. list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length'], $max_digits, $decimals);
  545. if ($mergetable == false) {
  546. list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length'], $max_digits, $decimals);
  547. }
  548. if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
  549. list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free'], $max_digits, $decimals);
  550. list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free'], $max_digits, $decimals);
  551. } else {
  552. list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
  553. }
  554. list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
  555. if ($table_info_num_rows > 0) {
  556. list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
  557. }
  558. // Displays them
  559. $odd_row = false;
  560. ?>
  561. <a name="showusage"></a>
  562. <?php if (! $tbl_is_view && ! $db_is_information_schema) { ?>
  563. <table id="tablespaceusage" class="data">
  564. <caption class="tblHeaders"><?php echo $strSpaceUsage; ?></caption>
  565. <thead>
  566. <tr>
  567. <th><?php echo $strType; ?></th>
  568. <th colspan="2"><?php echo $strUsage; ?></th>
  569. </tr>
  570. </thead>
  571. <tbody>
  572. <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
  573. <th class="name"><?php echo $strData; ?></th>
  574. <td class="value"><?php echo $data_size; ?></td>
  575. <td class="unit"><?php echo $data_unit; ?></td>
  576. </tr>
  577. <?php
  578. if (isset($index_size)) {
  579. ?>
  580. <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
  581. <th class="name"><?php echo $strIndex; ?></th>
  582. <td class="value"><?php echo $index_size; ?></td>
  583. <td class="unit"><?php echo $index_unit; ?></td>
  584. </tr>
  585. <?php
  586. }
  587. if (isset($free_size)) {
  588. ?>
  589. <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?> warning">
  590. <th class="name"><?php echo $strOverhead; ?></th>
  591. <td class="value"><?php echo $free_size; ?></td>
  592. <td class="unit"><?php echo $free_unit; ?></td>
  593. </tr>
  594. <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
  595. <th class="name"><?php echo $strEffective; ?></th>
  596. <td class="value"><?php echo $effect_size; ?></td>
  597. <td class="unit"><?php echo $effect_unit; ?></td>
  598. </tr>
  599. <?php
  600. }
  601. if (isset($tot_size) && $mergetable == false) {
  602. ?>
  603. <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
  604. <th class="name"><?php echo $strTotalUC; ?></th>
  605. <td class="value"><?php echo $tot_size; ?></td>
  606. <td class="unit"><?php echo $tot_unit; ?></td>
  607. </tr>
  608. <?php
  609. }
  610. // Optimize link if overhead
  611. if (isset($free_size) && ($tbl_type == 'MYISAM' || $tbl_type == 'MARIA' || $tbl_type == 'BDB')) {
  612. ?>
  613. <tr class="tblFooters">
  614. <td colspan="3" align="center">
  615. <a href="sql.php?<?php echo $url_query; ?>&pos=0&amp;sql_query=<?php echo urlencode('OPTIMIZE TABLE ' . PMA_backquote($table)); ?>"><?php
  616. if ($cfg['PropertiesIconic']) {
  617. echo '<img class="icon" src="' . $pmaThemeImage . 'b_tbloptimize.png" width="16" height="16" alt="' . $strOptimizeTable. '" />';
  618. }
  619. echo $strOptimizeTable;
  620. ?></a>
  621. </td>
  622. </tr>
  623. <?php
  624. }
  625. ?>
  626. </tbody>
  627. </table>
  628. <?php
  629. }
  630. $odd_row = false;
  631. ?>
  632. <table id="tablerowstats" class="data">
  633. <caption class="tblHeaders"><?php echo $strRowsStatistic; ?></caption>
  634. <thead>
  635. <tr>
  636. <th><?php echo $strStatement; ?></th>
  637. <th><?php echo $strValue; ?></th>
  638. </tr>
  639. </thead>
  640. <tbody>
  641. <?php
  642. if (isset($showtable['Row_format'])) {
  643. ?>
  644. <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
  645. <th class="name"><?php echo $strFormat; ?></th>
  646. <td class="value"><?php
  647. if ($showtable['Row_format'] == 'Fixed') {
  648. echo $strStatic;
  649. } elseif ($showtable['Row_format'] == 'Dynamic') {
  650. echo $strDynamic;
  651. } else {
  652. echo $showtable['Row_format'];
  653. }
  654. ?></td>
  655. </tr>
  656. <?php
  657. }
  658. if (! empty($showtable['Create_options'])) {
  659. ?>
  660. <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
  661. <th class="name"><?php echo $strOptions; ?></th>
  662. <td class="value"><?php
  663. if ($showtable['Create_options'] == 'partitioned') {
  664. echo $strPartitioned;
  665. } else {
  666. echo $showtable['Create_options'];
  667. }
  668. ?></td>
  669. </tr>
  670. <?php
  671. }
  672. if (!empty($tbl_collation)) {
  673. ?>
  674. <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
  675. <th class="name"><?php echo $strCollation; ?></th>
  676. <td class="value"><?php
  677. echo '<dfn title="' . PMA_getCollationDescr($tbl_collation) . '">' . $tbl_collation . '</dfn>';
  678. ?></td>
  679. </tr>
  680. <?php
  681. }
  682. if (!$is_innodb && isset($showtable['Rows'])) {
  683. ?>
  684. <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
  685. <th class="name"><?php echo $strRows; ?></th>
  686. <td class="value"><?php echo PMA_formatNumber($showtable['Rows'], 0); ?></td>
  687. </tr>
  688. <?php
  689. }
  690. if (!$is_innodb && isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
  691. ?>
  692. <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
  693. <th class="name"><?php echo $strRowLength; ?> &oslash;</th>
  694. <td class="value"><?php echo PMA_formatNumber($showtable['Avg_row_length'], 0); ?></td>
  695. </tr>
  696. <?php
  697. }
  698. if (!$is_innodb && isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
  699. ?>
  700. <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
  701. <th class="name"><?php echo $strRowSize; ?> &oslash;</th>
  702. <td class="value"><?php echo $avg_size . ' ' . $avg_unit; ?></td>
  703. </tr>
  704. <?php
  705. }
  706. if (isset($showtable['Auto_increment'])) {
  707. ?>
  708. <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
  709. <th class="name"><?php echo $strNext; ?> Autoindex</th>
  710. <td class="value"><?php echo PMA_formatNumber($showtable['Auto_increment'], 0); ?></td>
  711. </tr>
  712. <?php
  713. }
  714. if (isset($showtable['Create_time'])) {
  715. ?>
  716. <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
  717. <th class="name"><?php echo $strStatCreateTime; ?></th>
  718. <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Create_time'])); ?></td>
  719. </tr>
  720. <?php
  721. }
  722. if (isset($showtable['Update_time'])) {
  723. ?>
  724. <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
  725. <th class="name"><?php echo $strStatUpdateTime; ?></th>
  726. <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Update_time'])); ?></td>
  727. </tr>
  728. <?php
  729. }
  730. if (isset($showtable['Check_time'])) {
  731. ?>
  732. <tr class="<?php echo ($odd_row = !$odd_row) ? 'odd' : 'even'; ?>">
  733. <th class="name"><?php echo $strStatCheckTime; ?></th>
  734. <td class="value"><?php echo PMA_localisedDate(strtotime($showtable['Check_time'])); ?></td>
  735. </tr>
  736. <?php
  737. }
  738. ?>
  739. </tbody>
  740. </table>
  741. <?php
  742. }
  743. // END - Calc Table Space
  744. require './libraries/tbl_triggers.lib.php';
  745. echo '<div class="clearfloat"></div>' . "\n";
  746. echo '</div>' . "\n";
  747. echo '</div>' . "\n";
  748. /**
  749. * Displays the footer
  750. */
  751. require_once './libraries/footer.inc.php';
  752. ?>