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\Normalization
;
12 use PhpMyAdmin\Response
;
15 if (! defined('ROOT_PATH')) {
16 define('ROOT_PATH', __DIR__
. DIRECTORY_SEPARATOR
);
19 require_once ROOT_PATH
. 'libraries/common.inc.php';
21 $normalization = new Normalization($GLOBALS['dbi']);
23 if (isset($_POST['getColumns'])) {
24 $html = '<option selected disabled>' . __('Select oneā¦') . '</option>'
25 . '<option value="no_such_col">' . __('No such column') . '</option>';
26 //get column whose datatype falls under string category
27 $html .= $normalization->getHtmlForColumnsList(
30 _pgettext('string types', 'String')
35 if (isset($_POST['splitColumn'])) {
36 $num_fields = min(4096, intval($_POST['numFields']));
37 $html = $normalization->getHtmlForCreateNewColumn($num_fields, $db, $table);
38 $html .= Url
::getHiddenInputs($db, $table);
42 if (isset($_POST['addNewPrimary'])) {
45 'Field' => $table . "_id",
46 'Extra' => 'auto_increment',
48 $html = $normalization->getHtmlForCreateNewColumn(
54 $html .= Url
::getHiddenInputs($db, $table);
58 if (isset($_POST['findPdl'])) {
59 $html = $normalization->findPartialDependencies($table, $db);
64 if (isset($_POST['getNewTables2NF'])) {
65 $partialDependencies = json_decode($_POST['pd']);
66 $html = $normalization->getHtmlForNewTables2NF($partialDependencies, $table);
71 $response = Response
::getInstance();
73 if (isset($_POST['getNewTables3NF'])) {
74 $dependencies = json_decode($_POST['pd']);
75 $tables = json_decode($_POST['tables']);
76 $newTables = $normalization->getHtmlForNewTables3NF($dependencies, $tables, $db);
79 echo json_encode($newTables);
83 $header = $response->getHeader();
84 $scripts = $header->getScripts();
85 $scripts->addFile('normalization.js');
86 $scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
88 if (Core
::isValid($_POST['normalizeTo'], ['1nf', '2nf', '3nf'])) {
89 $normalForm = $_POST['normalizeTo'];
91 if (isset($_POST['createNewTables2NF'])) {
92 $partialDependencies = json_decode($_POST['pd']);
93 $tablesName = json_decode($_POST['newTablesName']);
94 $res = $normalization->createNewTablesFor2NF($partialDependencies, $tablesName, $table, $db);
95 $response->addJSON($res);
98 if (isset($_POST['createNewTables3NF'])) {
99 $newtables = json_decode($_POST['newTables']);
100 $res = $normalization->createNewTablesFor3NF($newtables, $db);
101 $response->addJSON($res);
104 if (isset($_POST['repeatingColumns'])) {
105 $repeatingColumns = $_POST['repeatingColumns'];
106 $newTable = $_POST['newTable'];
107 $newColumn = $_POST['newColumn'];
108 $primary_columns = $_POST['primary_columns'];
109 $res = $normalization->moveRepeatingGroup(
117 $response->addJSON($res);
120 if (isset($_POST['step1'])) {
121 $html = $normalization->getHtmlFor1NFStep1($db, $table, $normalForm);
122 $response->addHTML($html);
123 } elseif (isset($_POST['step2'])) {
124 $res = $normalization->getHtmlContentsFor1NFStep2($db, $table);
125 $response->addJSON($res);
126 } elseif (isset($_POST['step3'])) {
127 $res = $normalization->getHtmlContentsFor1NFStep3($db, $table);
128 $response->addJSON($res);
129 } elseif (isset($_POST['step4'])) {
130 $res = $normalization->getHtmlContentsFor1NFStep4($db, $table);
131 $response->addJSON($res);
132 } elseif (isset($_POST['step']) && $_POST['step'] == '2.1') {
133 $res = $normalization->getHtmlFor2NFstep1($db, $table);
134 $response->addJSON($res);
135 } elseif (isset($_POST['step']) && $_POST['step'] == '3.1') {
136 $tables = $_POST['tables'];
137 $res = $normalization->getHtmlFor3NFstep1($db, $tables);
138 $response->addJSON($res);
140 $response->addHTML($normalization->getHtmlForNormalizeTable());