normalization.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Normalization process (temporarily specific to 1NF)
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. /**
  9. *
  10. */
  11. require_once 'libraries/common.inc.php';
  12. require_once 'libraries/transformations.lib.php';
  13. require_once 'libraries/normalization.lib.php';
  14. require_once 'libraries/Index.class.php';
  15. if (isset($_REQUEST['getColumns'])) {
  16. $html = '<option selected disabled>' . __('Select one…') . '</option>'
  17. . '<option value="no_such_col">' . __('No such column') . '</option>';
  18. //get column whose datatype falls under string category
  19. $html .= PMA_getHtmlForColumnsList(
  20. $db,
  21. $table,
  22. _pgettext('string types', 'String')
  23. );
  24. echo $html;
  25. exit;
  26. }
  27. if (isset($_REQUEST['splitColumn'])) {
  28. $num_fields = $_REQUEST['numFields'];
  29. $html = PMA_getHtmlForCreateNewColumn($num_fields, $db, $table);
  30. $html .= PMA_URL_getHiddenInputs($db, $table);
  31. echo $html;
  32. exit;
  33. }
  34. if (isset($_REQUEST['addNewPrimary'])) {
  35. $num_fields = 1;
  36. $columnMeta = array('Field'=>$table . "_id", 'Extra'=>'auto_increment');
  37. $html = PMA_getHtmlForCreateNewColumn(
  38. $num_fields, $db, $table, $columnMeta
  39. );
  40. $html .= PMA_URL_getHiddenInputs($db, $table);
  41. echo $html;
  42. exit;
  43. }
  44. if (isset($_REQUEST['findPdl'])) {
  45. $html = PMA_findPartialDependencies($table, $db);
  46. echo $html;
  47. exit;
  48. }
  49. if (isset($_REQUEST['getNewTables2NF'])) {
  50. $partialDependencies = json_decode($_REQUEST['pd']);
  51. $html = PMA_getHtmlForNewTables2NF($partialDependencies, $table);
  52. echo $html;
  53. exit;
  54. }
  55. if (isset($_REQUEST['getNewTables3NF'])) {
  56. $dependencies = json_decode($_REQUEST['pd']);
  57. $tables = json_decode($_REQUEST['tables']);
  58. $newTables = PMA_getHtmlForNewTables3NF($dependencies, $tables, $db);
  59. PMA_Response::getInstance()->disable();
  60. PMA_headerJSON();
  61. echo json_encode($newTables);
  62. exit;
  63. }
  64. $response = PMA_Response::getInstance();
  65. $header = $response->getHeader();
  66. $scripts = $header->getScripts();
  67. $scripts->addFile('normalization.js');
  68. $scripts->addFile('jquery/jquery.uitablefilter.js');
  69. $normalForm = '1nf';
  70. if (isset($_REQUEST['normalizeTo'])) {
  71. $normalForm = $_REQUEST['normalizeTo'];
  72. }
  73. if (isset($_REQUEST['createNewTables2NF'])) {
  74. $partialDependencies = json_decode($_REQUEST['pd']);
  75. $tablesName = json_decode($_REQUEST['newTablesName']);
  76. $res = PMA_createNewTablesFor2NF($partialDependencies, $tablesName, $table, $db);
  77. $response->addJSON($res);
  78. exit;
  79. }
  80. if (isset($_REQUEST['createNewTables3NF'])) {
  81. $newtables = json_decode($_REQUEST['newTables']);
  82. $res = PMA_createNewTablesFor3NF($newtables, $db);
  83. $response->addJSON($res);
  84. exit;
  85. }
  86. if (isset($_POST['repeatingColumns'])) {
  87. $repeatingColumns = $_POST['repeatingColumns'];
  88. $newTable = $_POST['newTable'];
  89. $newColumn = $_POST['newColumn'];
  90. $primary_columns = $_POST['primary_columns'];
  91. $res = PMA_moveRepeatingGroup(
  92. $repeatingColumns, $primary_columns, $newTable, $newColumn, $table, $db
  93. );
  94. $response->addJSON($res);
  95. exit;
  96. }
  97. if (isset($_REQUEST['step1'])) {
  98. $html = PMA_getHtmlFor1NFStep1($db, $table, $normalForm);
  99. $response->addHTML($html);
  100. } else if (isset($_REQUEST['step2'])) {
  101. $res = PMA_getHtmlContentsFor1NFStep2($db, $table);
  102. $response->addJSON($res);
  103. } else if (isset($_REQUEST['step3'])) {
  104. $res = PMA_getHtmlContentsFor1NFStep3($db, $table);
  105. $response->addJSON($res);
  106. } else if (isset ($_REQUEST['step4'])) {
  107. $res = PMA_getHtmlContentsFor1NFStep4($db, $table);
  108. $response->addJSON($res);
  109. } else if (isset($_REQUEST['step']) && $_REQUEST['step'] == 2.1) {
  110. $res = PMA_getHtmlFor2NFstep1($db, $table);
  111. $response->addJSON($res);
  112. } else if (isset($_REQUEST['step']) && $_REQUEST['step'] == 3.1) {
  113. $tables = $_REQUEST['tables'];
  114. $res = PMA_getHtmlFor3NFstep1($db, $tables);
  115. $response->addJSON($res);
  116. } else {
  117. $response->addHTML(PMA_getHtmlForNormalizetable());
  118. }