normalization.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. use PhpMyAdmin\Core;
  9. use PhpMyAdmin\Normalization;
  10. use PhpMyAdmin\Response;
  11. use PhpMyAdmin\Url;
  12. require_once 'libraries/common.inc.php';
  13. $normalization = new Normalization($GLOBALS['dbi']);
  14. if (isset($_POST['getColumns'])) {
  15. $html = '<option selected disabled>' . __('Select one…') . '</option>'
  16. . '<option value="no_such_col">' . __('No such column') . '</option>';
  17. //get column whose datatype falls under string category
  18. $html .= $normalization->getHtmlForColumnsList(
  19. $db,
  20. $table,
  21. _pgettext('string types', 'String')
  22. );
  23. echo $html;
  24. exit;
  25. }
  26. if (isset($_POST['splitColumn'])) {
  27. $num_fields = min(4096, intval($_POST['numFields']));
  28. $html = $normalization->getHtmlForCreateNewColumn($num_fields, $db, $table);
  29. $html .= Url::getHiddenInputs($db, $table);
  30. echo $html;
  31. exit;
  32. }
  33. if (isset($_POST['addNewPrimary'])) {
  34. $num_fields = 1;
  35. $columnMeta = array('Field'=>$table . "_id", 'Extra'=>'auto_increment');
  36. $html = $normalization->getHtmlForCreateNewColumn(
  37. $num_fields, $db, $table, $columnMeta
  38. );
  39. $html .= Url::getHiddenInputs($db, $table);
  40. echo $html;
  41. exit;
  42. }
  43. if (isset($_POST['findPdl'])) {
  44. $html = $normalization->findPartialDependencies($table, $db);
  45. echo $html;
  46. exit;
  47. }
  48. if (isset($_POST['getNewTables2NF'])) {
  49. $partialDependencies = json_decode($_POST['pd']);
  50. $html = $normalization->getHtmlForNewTables2NF($partialDependencies, $table);
  51. echo $html;
  52. exit;
  53. }
  54. $response = Response::getInstance();
  55. if (isset($_POST['getNewTables3NF'])) {
  56. $dependencies = json_decode($_POST['pd']);
  57. $tables = json_decode($_POST['tables']);
  58. $newTables = $normalization->getHtmlForNewTables3NF($dependencies, $tables, $db);
  59. $response->disable();
  60. Core::headerJSON();
  61. echo json_encode($newTables);
  62. exit;
  63. }
  64. $header = $response->getHeader();
  65. $scripts = $header->getScripts();
  66. $scripts->addFile('normalization.js');
  67. $scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
  68. $normalForm = '1nf';
  69. if (Core::isValid($_POST['normalizeTo'], array('1nf', '2nf', '3nf'))) {
  70. $normalForm = $_POST['normalizeTo'];
  71. }
  72. if (isset($_POST['createNewTables2NF'])) {
  73. $partialDependencies = json_decode($_POST['pd']);
  74. $tablesName = json_decode($_POST['newTablesName']);
  75. $res = $normalization->createNewTablesFor2NF($partialDependencies, $tablesName, $table, $db);
  76. $response->addJSON($res);
  77. exit;
  78. }
  79. if (isset($_POST['createNewTables3NF'])) {
  80. $newtables = json_decode($_POST['newTables']);
  81. $res = $normalization->createNewTablesFor3NF($newtables, $db);
  82. $response->addJSON($res);
  83. exit;
  84. }
  85. if (isset($_POST['repeatingColumns'])) {
  86. $repeatingColumns = $_POST['repeatingColumns'];
  87. $newTable = $_POST['newTable'];
  88. $newColumn = $_POST['newColumn'];
  89. $primary_columns = $_POST['primary_columns'];
  90. $res = $normalization->moveRepeatingGroup(
  91. $repeatingColumns, $primary_columns, $newTable, $newColumn, $table, $db
  92. );
  93. $response->addJSON($res);
  94. exit;
  95. }
  96. if (isset($_POST['step1'])) {
  97. $html = $normalization->getHtmlFor1NFStep1($db, $table, $normalForm);
  98. $response->addHTML($html);
  99. } elseif (isset($_POST['step2'])) {
  100. $res = $normalization->getHtmlContentsFor1NFStep2($db, $table);
  101. $response->addJSON($res);
  102. } elseif (isset($_POST['step3'])) {
  103. $res = $normalization->getHtmlContentsFor1NFStep3($db, $table);
  104. $response->addJSON($res);
  105. } elseif (isset($_POST['step4'])) {
  106. $res = $normalization->getHtmlContentsFor1NFStep4($db, $table);
  107. $response->addJSON($res);
  108. } elseif (isset($_POST['step']) && $_POST['step'] == '2.1') {
  109. $res = $normalization->getHtmlFor2NFstep1($db, $table);
  110. $response->addJSON($res);
  111. } elseif (isset($_POST['step']) && $_POST['step'] == '3.1') {
  112. $tables = $_POST['tables'];
  113. $res = $normalization->getHtmlFor3NFstep1($db, $tables);
  114. $response->addJSON($res);
  115. } else {
  116. $response->addHTML($normalization->getHtmlForNormalizeTable());
  117. }