db_designer.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * phpMyAdmin designer general code
  5. *
  6. * @package PhpMyAdmin-Designer
  7. */
  8. use PhpMyAdmin\Database\Designer;
  9. use PhpMyAdmin\Database\Designer\Common;
  10. use PhpMyAdmin\Response;
  11. require_once 'libraries/common.inc.php';
  12. $response = Response::getInstance();
  13. $databaseDesigner = new Designer();
  14. $designerCommon = new Common();
  15. if (isset($_POST['dialog'])) {
  16. if ($_POST['dialog'] == 'edit') {
  17. $html = $databaseDesigner->getHtmlForEditOrDeletePages($_POST['db'], 'editPage');
  18. } elseif ($_POST['dialog'] == 'delete') {
  19. $html = $databaseDesigner->getHtmlForEditOrDeletePages($_POST['db'], 'deletePage');
  20. } elseif ($_POST['dialog'] == 'save_as') {
  21. $html = $databaseDesigner->getHtmlForPageSaveAs($_POST['db']);
  22. } elseif ($_POST['dialog'] == 'export') {
  23. $html = $databaseDesigner->getHtmlForSchemaExport(
  24. $_POST['db'], $_POST['selected_page']
  25. );
  26. } elseif ($_POST['dialog'] == 'add_table') {
  27. // Pass the db and table to the getTablesInfo so we only have the table we asked for
  28. $script_display_field = $designerCommon->getTablesInfo($_POST['db'], $_POST['table']);
  29. $tab_column = $designerCommon->getColumnsInfo($script_display_field);
  30. $tables_all_keys = $designerCommon->getAllKeys($script_display_field);
  31. $tables_pk_or_unique_keys = $designerCommon->getPkOrUniqueKeys($script_display_field);
  32. $html = $databaseDesigner->getDatabaseTables(
  33. $_POST['db'],
  34. $script_display_field,
  35. array(), -1, $tab_column,
  36. $tables_all_keys, $tables_pk_or_unique_keys
  37. );
  38. }
  39. if (! empty($html)) {
  40. $response->addHTML($html);
  41. }
  42. return;
  43. }
  44. if (isset($_POST['operation'])) {
  45. if ($_POST['operation'] == 'deletePage') {
  46. $success = $designerCommon->deletePage($_POST['selected_page']);
  47. $response->setRequestStatus($success);
  48. } elseif ($_POST['operation'] == 'savePage') {
  49. if ($_POST['save_page'] == 'same') {
  50. $page = $_POST['selected_page'];
  51. } else { // new
  52. $page = $designerCommon->createNewPage($_POST['selected_value'], $_POST['db']);
  53. $response->addJSON('id', $page);
  54. }
  55. $success = $designerCommon->saveTablePositions($page);
  56. $response->setRequestStatus($success);
  57. } elseif ($_POST['operation'] == 'setDisplayField') {
  58. list(
  59. $success,
  60. $message,
  61. ) = $designerCommon->saveDisplayField(
  62. $_POST['db'],
  63. $_POST['table'],
  64. $_POST['field']
  65. );
  66. $response->setRequestStatus($success);
  67. $response->addJSON('message', $message);
  68. } elseif ($_POST['operation'] == 'addNewRelation') {
  69. list($success, $message) = $designerCommon->addNewRelation(
  70. $_POST['db'],
  71. $_POST['T1'],
  72. $_POST['F1'],
  73. $_POST['T2'],
  74. $_POST['F2'],
  75. $_POST['on_delete'],
  76. $_POST['on_update'],
  77. $_POST['DB1'],
  78. $_POST['DB2']
  79. );
  80. $response->setRequestStatus($success);
  81. $response->addJSON('message', $message);
  82. } elseif ($_POST['operation'] == 'removeRelation') {
  83. list($success, $message) = $designerCommon->removeRelation(
  84. $_POST['T1'],
  85. $_POST['F1'],
  86. $_POST['T2'],
  87. $_POST['F2']
  88. );
  89. $response->setRequestStatus($success);
  90. $response->addJSON('message', $message);
  91. } elseif ($_POST['operation'] == 'save_setting_value') {
  92. $success = $designerCommon->saveSetting($_POST['index'], $_POST['value']);
  93. $response->setRequestStatus($success);
  94. }
  95. return;
  96. }
  97. require 'libraries/db_common.inc.php';
  98. $script_display_field = $designerCommon->getTablesInfo();
  99. $display_page = -1;
  100. $selected_page = null;
  101. if (isset($_GET['query'])) {
  102. $display_page = $designerCommon->getDefaultPage($_GET['db']);
  103. } else {
  104. if (! empty($_GET['page'])) {
  105. $display_page = $_GET['page'];
  106. } else {
  107. $display_page = $designerCommon->getLoadingPage($_GET['db']);
  108. }
  109. }
  110. if ($display_page != -1) {
  111. $selected_page = $designerCommon->getPageName($display_page);
  112. }
  113. $tab_pos = $designerCommon->getTablePositions($display_page);
  114. $fullTableNames = [];
  115. foreach($script_display_field as $designerTable) {
  116. $fullTableNames[] = $designerTable->getDbTableString();
  117. }
  118. foreach($tab_pos as $position) {
  119. if (! in_array($position['dbName'] . '.' . $position['tableName'], $fullTableNames)) {
  120. foreach($designerCommon->getTablesInfo($position['dbName'], $position['tableName']) as $designerTable) {
  121. $script_display_field[] = $designerTable;
  122. }
  123. }
  124. }
  125. $tab_column = $designerCommon->getColumnsInfo($script_display_field);
  126. $script_tables = $designerCommon->getScriptTabs($script_display_field);
  127. $tables_pk_or_unique_keys = $designerCommon->getPkOrUniqueKeys($script_display_field);
  128. $tables_all_keys = $designerCommon->getAllKeys($script_display_field);
  129. $classes_side_menu = $databaseDesigner->returnClassNamesFromMenuButtons();
  130. $script_contr = $designerCommon->getScriptContr($script_display_field);
  131. $params = array('lang' => $GLOBALS['lang']);
  132. if (isset($_GET['db'])) {
  133. $params['db'] = $_GET['db'];
  134. }
  135. $response = Response::getInstance();
  136. $response->getFooter()->setMinimal();
  137. $header = $response->getHeader();
  138. $header->setBodyId('designer_body');
  139. $scripts = $header->getScripts();
  140. $scripts->addFile('vendor/jquery/jquery.fullscreen.js');
  141. $scripts->addFile('designer/database.js');
  142. $scripts->addFile('designer/objects.js');
  143. $scripts->addFile('designer/page.js');
  144. $scripts->addFile('designer/history.js');
  145. $scripts->addFile('designer/move.js');
  146. $scripts->addFile('designer/init.js');
  147. list(
  148. $tables,
  149. $num_tables,
  150. $total_num_tables,
  151. $sub_part,
  152. $is_show_stats,
  153. $db_is_system_schema,
  154. $tooltip_truename,
  155. $tooltip_aliasname,
  156. $pos
  157. ) = PhpMyAdmin\Util::getDbInfo($db, isset($sub_part) ? $sub_part : '');
  158. // Embed some data into HTML, later it will be read
  159. // by designer/init.js and converted to JS variables.
  160. $response->addHTML(
  161. $databaseDesigner->getHtmlForJsFields(
  162. $script_tables, $script_contr, $script_display_field, $display_page
  163. )
  164. );
  165. $response->addHTML(
  166. $databaseDesigner->getPageMenu(
  167. isset($_GET['query']),
  168. $selected_page,
  169. $classes_side_menu
  170. )
  171. );
  172. $response->addHTML('<div id="canvas_outer">');
  173. $response->addHTML(
  174. '<form action="" id="container-form" method="post">'
  175. );
  176. $response->addHTML($databaseDesigner->getHtmlCanvas());
  177. $response->addHTML($databaseDesigner->getHtmlTableList());
  178. $response->addHTML(
  179. $databaseDesigner->getDatabaseTables(
  180. $_GET['db'],
  181. $script_display_field,
  182. $tab_pos, $display_page, $tab_column,
  183. $tables_all_keys, $tables_pk_or_unique_keys
  184. )
  185. );
  186. $response->addHTML('</form>');
  187. $response->addHTML('</div>'); // end canvas_outer
  188. $response->addHTML('<div id="designer_hint"></div>');
  189. $response->addHTML($databaseDesigner->getNewRelationPanel());
  190. $response->addHTML($databaseDesigner->getDeleteRelationPanel());
  191. if (isset($_GET['query'])) {
  192. $response->addHTML($databaseDesigner->getOptionsPanel());
  193. $response->addHTML($databaseDesigner->getRenameToPanel());
  194. $response->addHTML($databaseDesigner->getHavingQueryPanel());
  195. $response->addHTML($databaseDesigner->getAggregateQueryPanel());
  196. $response->addHTML($databaseDesigner->getWhereQueryPanel());
  197. $response->addHTML($databaseDesigner->getQueryDetails($_GET['db']));
  198. }
  199. $response->addHTML('<div id="PMA_disable_floating_menubar"></div>');