2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Normalization process (temporarily specific to 1NF)
8 declare(strict_types
=1);
11 use PhpMyAdmin\DatabaseInterface
;
12 use PhpMyAdmin\Di\Container
;
13 use PhpMyAdmin\Normalization
;
14 use PhpMyAdmin\Response
;
17 if (! defined('ROOT_PATH')) {
18 define('ROOT_PATH', __DIR__
. DIRECTORY_SEPARATOR
);
23 require_once ROOT_PATH
. 'libraries/common.inc.php';
25 $container = Container
::getDefaultContainer();
26 $container->set(Response
::class, Response
::getInstance());
28 /** @var Response $response */
29 $response = $container->get(Response
::class);
31 /** @var DatabaseInterface $dbi */
32 $dbi = $container->get(DatabaseInterface
::class);
34 /** @var Normalization $normalization */
35 $normalization = $containerBuilder->get('normalization');
37 if (isset($_POST['getColumns'])) {
38 $html = '<option selected disabled>' . __('Select oneā¦') . '</option>'
39 . '<option value="no_such_col">' . __('No such column') . '</option>';
40 //get column whose datatype falls under string category
41 $html .= $normalization->getHtmlForColumnsList(
44 _pgettext('string types', 'String')
49 if (isset($_POST['splitColumn'])) {
50 $num_fields = min(4096, intval($_POST['numFields']));
51 $html = $normalization->getHtmlForCreateNewColumn($num_fields, $db, $table);
52 $html .= Url
::getHiddenInputs($db, $table);
56 if (isset($_POST['addNewPrimary'])) {
59 'Field' => $table . "_id",
60 'Extra' => 'auto_increment',
62 $html = $normalization->getHtmlForCreateNewColumn(
68 $html .= Url
::getHiddenInputs($db, $table);
72 if (isset($_POST['findPdl'])) {
73 $html = $normalization->findPartialDependencies($table, $db);
78 if (isset($_POST['getNewTables2NF'])) {
79 $partialDependencies = json_decode($_POST['pd']);
80 $html = $normalization->getHtmlForNewTables2NF($partialDependencies, $table);
85 if (isset($_POST['getNewTables3NF'])) {
86 $dependencies = json_decode($_POST['pd']);
87 $tables = json_decode($_POST['tables']);
88 $newTables = $normalization->getHtmlForNewTables3NF($dependencies, $tables, $db);
91 echo json_encode($newTables);
95 $header = $response->getHeader();
96 $scripts = $header->getScripts();
97 $scripts->addFile('normalization.js');
98 $scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
100 if (Core
::isValid($_POST['normalizeTo'], ['1nf', '2nf', '3nf'])) {
101 $normalForm = $_POST['normalizeTo'];
103 if (isset($_POST['createNewTables2NF'])) {
104 $partialDependencies = json_decode($_POST['pd']);
105 $tablesName = json_decode($_POST['newTablesName']);
106 $res = $normalization->createNewTablesFor2NF($partialDependencies, $tablesName, $table, $db);
107 $response->addJSON($res);
110 if (isset($_POST['createNewTables3NF'])) {
111 $newtables = json_decode($_POST['newTables']);
112 $res = $normalization->createNewTablesFor3NF($newtables, $db);
113 $response->addJSON($res);
116 if (isset($_POST['repeatingColumns'])) {
117 $repeatingColumns = $_POST['repeatingColumns'];
118 $newTable = $_POST['newTable'];
119 $newColumn = $_POST['newColumn'];
120 $primary_columns = $_POST['primary_columns'];
121 $res = $normalization->moveRepeatingGroup(
129 $response->addJSON($res);
132 if (isset($_POST['step1'])) {
133 $html = $normalization->getHtmlFor1NFStep1($db, $table, $normalForm);
134 $response->addHTML($html);
135 } elseif (isset($_POST['step2'])) {
136 $res = $normalization->getHtmlContentsFor1NFStep2($db, $table);
137 $response->addJSON($res);
138 } elseif (isset($_POST['step3'])) {
139 $res = $normalization->getHtmlContentsFor1NFStep3($db, $table);
140 $response->addJSON($res);
141 } elseif (isset($_POST['step4'])) {
142 $res = $normalization->getHtmlContentsFor1NFStep4($db, $table);
143 $response->addJSON($res);
144 } elseif (isset($_POST['step']) && $_POST['step'] == '2.1') {
145 $res = $normalization->getHtmlFor2NFstep1($db, $table);
146 $response->addJSON($res);
147 } elseif (isset($_POST['step']) && $_POST['step'] == '3.1') {
148 $tables = $_POST['tables'];
149 $res = $normalization->getHtmlFor3NFstep1($db, $tables);
150 $response->addJSON($res);
152 $response->addHTML($normalization->getHtmlForNormalizeTable());