PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/phpmyadmin/db_structure.php

https://github.com/drbowen/openemr
PHP | 335 lines | 233 code | 50 blank | 52 comment | 32 complexity | 6e9e748451b09869d5640bc0d01fb08d MD5 | raw file
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. *
  5. * @package PhpMyAdmin
  6. */
  7. /**
  8. *
  9. */
  10. require_once 'libraries/common.inc.php';
  11. /**
  12. * Function implementations for this script
  13. */
  14. require_once 'libraries/structure.lib.php';
  15. $response = PMA_Response::getInstance();
  16. $header = $response->getHeader();
  17. $scripts = $header->getScripts();
  18. $scripts->addFile('db_structure.js');
  19. $scripts->addFile('tbl_change.js');
  20. $scripts->addFile('jquery/jquery-ui-timepicker-addon.js');
  21. $post_params = array(
  22. 'error',
  23. 'is_info',
  24. 'message',
  25. 'mult_btn',
  26. 'selected_tbl',
  27. 'submit_mult'
  28. );
  29. foreach ($post_params as $one_post_param) {
  30. if (isset($_POST[$one_post_param])) {
  31. $GLOBALS[$one_post_param] = $_POST[$one_post_param];
  32. }
  33. }
  34. /**
  35. * Prepares the tables list if the user where not redirected to this script
  36. * because there is no table in the database ($is_info is true)
  37. */
  38. if (empty($_POST['is_info'])) {
  39. // Drops/deletes/etc. multiple tables if required
  40. if ((!empty($_POST['submit_mult']) && isset($_POST['selected_tbl']))
  41. || isset($_POST['mult_btn'])
  42. ) {
  43. $action = 'db_structure.php';
  44. $err_url = 'db_structure.php?'. PMA_generate_common_url($db);
  45. // see bug #2794840; in this case, code path is:
  46. // db_structure.php -> libraries/mult_submits.inc.php -> sql.php
  47. // -> db_structure.php and if we got an error on the multi submit,
  48. // we must display it here and not call again mult_submits.inc.php
  49. if (! isset($_POST['error']) || false === $_POST['error']) {
  50. include 'libraries/mult_submits.inc.php';
  51. }
  52. if (empty($_POST['message'])) {
  53. $_POST['message'] = PMA_Message::success();
  54. }
  55. }
  56. include 'libraries/db_common.inc.php';
  57. $url_query .= '&amp;goto=db_structure.php';
  58. // Gets the database structure
  59. $sub_part = '_structure';
  60. include 'libraries/db_info.inc.php';
  61. if (!PMA_DRIZZLE) {
  62. include_once 'libraries/replication.inc.php';
  63. } else {
  64. $server_slave_status = false;
  65. }
  66. }
  67. require_once 'libraries/bookmark.lib.php';
  68. require_once 'libraries/mysql_charsets.lib.php';
  69. $db_collation = PMA_getDbCollation($db);
  70. $titles = PMA_Util::buildActionTitles();
  71. // 1. No tables
  72. if ($num_tables == 0) {
  73. $response->addHTML(
  74. '<p>' . __('No tables found in database') . '</p>' . "\n"
  75. );
  76. if (empty($db_is_information_schema)) {
  77. ob_start();
  78. include 'libraries/display_create_table.lib.php';
  79. $content = ob_get_contents();
  80. ob_end_clean();
  81. $response->addHTML($content);
  82. unset($content);
  83. } // end if (Create Table dialog)
  84. exit;
  85. }
  86. // else
  87. // 2. Shows table informations
  88. /**
  89. * Displays the tables list
  90. */
  91. $response->addHTML('<div id="tableslistcontainer">');
  92. $_url_params = array(
  93. 'pos' => $pos,
  94. 'db' => $db);
  95. // Add the sort options if they exists
  96. if (isset($_REQUEST['sort'])) {
  97. $_url_params['sort'] = $_REQUEST['sort'];
  98. }
  99. if (isset($_REQUEST['sort_order'])) {
  100. $_url_params['sort_order'] = $_REQUEST['sort_order'];
  101. }
  102. $response->addHTML(
  103. PMA_Util::getListNavigator(
  104. $total_num_tables, $pos, $_url_params, 'db_structure.php',
  105. 'frame_content', $GLOBALS['cfg']['MaxTableList']
  106. )
  107. );
  108. // tables form
  109. $response->addHTML(
  110. '<form method="post" action="db_structure.php" '
  111. . 'name="tablesForm" id="tablesForm">'
  112. );
  113. $response->addHTML(PMA_generate_common_hidden_inputs($db));
  114. $response->addHTML(
  115. PMA_TableHeader($db_is_information_schema, $server_slave_status)
  116. );
  117. $i = $sum_entries = 0;
  118. $overhead_check = '';
  119. $create_time_all = '';
  120. $update_time_all = '';
  121. $check_time_all = '';
  122. $num_columns = $cfg['PropertiesNumColumns'] > 1
  123. ? ceil($num_tables / $cfg['PropertiesNumColumns']) + 1
  124. : 0;
  125. $row_count = 0;
  126. $sum_size = (double) 0;
  127. $overhead_size = (double) 0;
  128. $hidden_fields = array();
  129. $odd_row = true;
  130. $sum_row_count_pre = '';
  131. foreach ($tables as $keyname => $current_table) {
  132. // Get valid statistics whatever is the table type
  133. $drop_query = '';
  134. $drop_message = '';
  135. $overhead = '';
  136. $table_is_view = false;
  137. $table_encoded = urlencode($current_table['TABLE_NAME']);
  138. // Sets parameters for links
  139. $tbl_url_query = $url_query . '&amp;table=' . $table_encoded;
  140. // do not list the previous table's size info for a view
  141. list($current_table, $formatted_size, $unit, $formatted_overhead,
  142. $overhead_unit, $overhead_size, $table_is_view, $sum_size)
  143. = PMA_getStuffForEngineTypeTable(
  144. $current_table, $db_is_information_schema,
  145. $is_show_stats, $table_is_view, $sum_size, $overhead_size
  146. );
  147. if (! PMA_Table::isMerge($db, $current_table['TABLE_NAME'])) {
  148. $sum_entries += $current_table['TABLE_ROWS'];
  149. }
  150. if (isset($current_table['Collation'])) {
  151. $collation = '<dfn title="'
  152. . PMA_getCollationDescr($current_table['Collation']) . '">'
  153. . $current_table['Collation'] . '</dfn>';
  154. } else {
  155. $collation = '---';
  156. }
  157. if ($is_show_stats) {
  158. if ($formatted_overhead != '') {
  159. $overhead = '<a href="tbl_structure.php?'
  160. . $tbl_url_query . '#showusage">'
  161. . '<span>' . $formatted_overhead . '</span>'
  162. . '<span class="unit">' . $overhead_unit . '</span>'
  163. . '</a>' . "\n";
  164. $overhead_check .=
  165. "markAllRows('row_tbl_" . ($i + 1) . "');";
  166. } else {
  167. $overhead = '-';
  168. }
  169. } // end if
  170. unset($showtable);
  171. if ($GLOBALS['cfg']['ShowDbStructureCreation']) {
  172. list($create_time, $create_time_all) = PMA_getTimeForCreateUpdateCheck(
  173. $current_table, 'Create_time', $create_time_all
  174. );
  175. }
  176. if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) {
  177. // $showtable might already be set from ShowDbStructureCreation, see above
  178. list($update_time, $update_time_all) = PMA_getTimeForCreateUpdateCheck(
  179. $current_table, 'Update_time', $update_time_all
  180. );
  181. }
  182. if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) {
  183. // $showtable might already be set from ShowDbStructureCreation, see above
  184. list($check_time, $check_time_all) = PMA_getTimeForCreateUpdateCheck(
  185. $current_table, 'Check_time', $check_time_all
  186. );
  187. }
  188. list($alias, $truename) = PMA_getAliasAndTrueName(
  189. $tooltip_aliasname, $current_table, $tooltip_truename
  190. );
  191. $i++;
  192. $row_count++;
  193. if ($table_is_view) {
  194. $hidden_fields[] = '<input type="hidden" name="views[]" value="'
  195. . htmlspecialchars($current_table['TABLE_NAME']) . '" />';
  196. }
  197. /*
  198. * Always activate links for Browse, Search and Empty, even if
  199. * the icons are greyed, because
  200. * 1. for views, we don't know the number of rows at this point
  201. * 2. for tables, another source could have populated them since the
  202. * page was generated
  203. *
  204. * I could have used the PHP ternary conditional operator but I find
  205. * the code easier to read without this operator.
  206. */
  207. list($browse_table, $search_table, $browse_table_label, $empty_table,
  208. $tracking_icon) = PMA_getHtmlForActionLinks(
  209. $current_table, $table_is_view, $tbl_url_query,
  210. $titles, $truename, $db_is_information_schema, $url_query
  211. );
  212. if (! $db_is_information_schema) {
  213. list($drop_query, $drop_message)
  214. = PMA_getTableDropQueryAndMessage($table_is_view, $current_table);
  215. }
  216. if ($num_columns > 0
  217. && $num_tables > $num_columns
  218. && ($row_count % $num_columns) == 0
  219. ) {
  220. $row_count = 1;
  221. $odd_row = true;
  222. $response->addHTML(
  223. '</tr></tbody></table>'
  224. );
  225. $response->addHTML(PMA_TableHeader(false, $server_slave_status));
  226. }
  227. list($do, $ignored) = PMA_getServerSlaveStatus(
  228. $server_slave_status, $truename
  229. );
  230. list($html_output, $odd_row) = PMA_getHtmlForStructureTableRow(
  231. $i, $odd_row, $table_is_view, $current_table,
  232. $browse_table_label, $tracking_icon, $server_slave_status,
  233. $browse_table, $tbl_url_query, $search_table, $db_is_information_schema,
  234. $titles, $empty_table, $drop_query, $drop_message, $collation,
  235. $formatted_size, $unit, $overhead,
  236. (isset ($create_time) ? $create_time : ''),
  237. (isset ($update_time) ? $update_time : ''),
  238. (isset ($check_time) ? $check_time : ''),
  239. $is_show_stats, $ignored, $do, $colspan_for_structure
  240. );
  241. $response->addHTML($html_output);
  242. } // end foreach
  243. // Show Summary
  244. $response->addHTML('</tbody>');
  245. $response->addHTML(
  246. PMA_getHtmlBodyForTableSummary(
  247. $num_tables, $server_slave_status, $db_is_information_schema, $sum_entries,
  248. $db_collation, $is_show_stats, $sum_size, $overhead_size, $create_time_all,
  249. $update_time_all, $check_time_all, $sum_row_count_pre
  250. )
  251. );
  252. $response->addHTML('</table>');
  253. //check all
  254. $response->addHTML(
  255. PMA_getHtmlForCheckAllTables(
  256. $pmaThemeImage, $text_dir, $overhead_check,
  257. $db_is_information_schema, $hidden_fields
  258. )
  259. );
  260. $response->addHTML('</form>'); //end of form
  261. // display again the table list navigator
  262. $response->addHTML(
  263. PMA_Util::getListNavigator(
  264. $total_num_tables, $pos, $_url_params, 'db_structure.php',
  265. 'frame_content', $GLOBALS['cfg']['MaxTableList']
  266. )
  267. );
  268. $response->addHTML('</div><hr />');
  269. /**
  270. * Work on the database
  271. */
  272. /* DATABASE WORK */
  273. /* Printable view of a table */
  274. $response->addHTML(
  275. PMA_getHtmlForTablePrintViewLink($url_query)
  276. . PMA_getHtmlForDataDictionaryLink($url_query)
  277. );
  278. if (empty($db_is_information_schema)) {
  279. ob_start();
  280. include 'libraries/display_create_table.lib.php';
  281. $content = ob_get_contents();
  282. ob_end_clean();
  283. $response->addHTML($content);
  284. } // end if (Create Table dialog)
  285. ?>