2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Normalization process (temporarily specific to 1NF)
10 use PhpMyAdmin\Normalization
;
11 use PhpMyAdmin\Response
;
14 require_once 'libraries/common.inc.php';
16 $normalization = new Normalization($GLOBALS['dbi']);
18 if (isset($_REQUEST['getColumns'])) {
19 $html = '<option selected disabled>' . __('Select one…') . '</option>'
20 . '<option value="no_such_col">' . __('No such column') . '</option>';
21 //get column whose datatype falls under string category
22 $html .= $normalization->getHtmlForColumnsList(
25 _pgettext('string types', 'String')
30 if (isset($_REQUEST['splitColumn'])) {
31 $num_fields = min(4096, intval($_REQUEST['numFields']));
32 $html = $normalization->getHtmlForCreateNewColumn($num_fields, $db, $table);
33 $html .= Url
::getHiddenInputs($db, $table);
37 if (isset($_REQUEST['addNewPrimary'])) {
39 $columnMeta = array('Field'=>$table . "_id", 'Extra'=>'auto_increment');
40 $html = $normalization->getHtmlForCreateNewColumn(
41 $num_fields, $db, $table, $columnMeta
43 $html .= Url
::getHiddenInputs($db, $table);
47 if (isset($_REQUEST['findPdl'])) {
48 $html = $normalization->findPartialDependencies($table, $db);
53 if (isset($_REQUEST['getNewTables2NF'])) {
54 $partialDependencies = json_decode($_REQUEST['pd']);
55 $html = $normalization->getHtmlForNewTables2NF($partialDependencies, $table);
60 $response = Response
::getInstance();
62 if (isset($_REQUEST['getNewTables3NF'])) {
63 $dependencies = json_decode($_REQUEST['pd']);
64 $tables = json_decode($_REQUEST['tables']);
65 $newTables = $normalization->getHtmlForNewTables3NF($dependencies, $tables, $db);
68 echo json_encode($newTables);
72 $header = $response->getHeader();
73 $scripts = $header->getScripts();
74 $scripts->addFile('normalization.js');
75 $scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
77 if (Core
::isValid($_REQUEST['normalizeTo'], array('1nf', '2nf', '3nf'))) {
78 $normalForm = $_REQUEST['normalizeTo'];
80 if (isset($_REQUEST['createNewTables2NF'])) {
81 $partialDependencies = json_decode($_REQUEST['pd']);
82 $tablesName = json_decode($_REQUEST['newTablesName']);
83 $res = $normalization->createNewTablesFor2NF($partialDependencies, $tablesName, $table, $db);
84 $response->addJSON($res);
87 if (isset($_REQUEST['createNewTables3NF'])) {
88 $newtables = json_decode($_REQUEST['newTables']);
89 $res = $normalization->createNewTablesFor3NF($newtables, $db);
90 $response->addJSON($res);
93 if (isset($_POST['repeatingColumns'])) {
94 $repeatingColumns = $_POST['repeatingColumns'];
95 $newTable = $_POST['newTable'];
96 $newColumn = $_POST['newColumn'];
97 $primary_columns = $_POST['primary_columns'];
98 $res = $normalization->moveRepeatingGroup(
99 $repeatingColumns, $primary_columns, $newTable, $newColumn, $table, $db
101 $response->addJSON($res);
104 if (isset($_REQUEST['step1'])) {
105 $html = $normalization->getHtmlFor1NFStep1($db, $table, $normalForm);
106 $response->addHTML($html);
107 } elseif (isset($_REQUEST['step2'])) {
108 $res = $normalization->getHtmlContentsFor1NFStep2($db, $table);
109 $response->addJSON($res);
110 } elseif (isset($_REQUEST['step3'])) {
111 $res = $normalization->getHtmlContentsFor1NFStep3($db, $table);
112 $response->addJSON($res);
113 } elseif (isset($_REQUEST['step4'])) {
114 $res = $normalization->getHtmlContentsFor1NFStep4($db, $table);
115 $response->addJSON($res);
116 } elseif (isset($_REQUEST['step']) && $_REQUEST['step'] == '2.1') {
117 $res = $normalization->getHtmlFor2NFstep1($db, $table);
118 $response->addJSON($res);
119 } elseif (isset($_REQUEST['step']) && $_REQUEST['step'] == '3.1') {
120 $tables = $_REQUEST['tables'];
121 $res = $normalization->getHtmlFor3NFstep1($db, $tables);
122 $response->addJSON($res);
124 $response->addHTML($normalization->getHtmlForNormalizeTable());