Adding composer lock for 4.9.8
[phpmyadmin.git] / normalization.php
blobdee32917d26a76eeabd5879496266d22c6b8968d
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Normalization process (temporarily specific to 1NF)
6 * @package PhpMyAdmin
7 */
9 use PhpMyAdmin\Core;
10 use PhpMyAdmin\Normalization;
11 use PhpMyAdmin\Response;
12 use PhpMyAdmin\Url;
14 require_once 'libraries/common.inc.php';
16 $normalization = new Normalization($GLOBALS['dbi']);
18 if (isset($_POST['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(
23 $db,
24 $table,
25 _pgettext('string types', 'String')
27 echo $html;
28 exit;
30 if (isset($_POST['splitColumn'])) {
31 $num_fields = min(4096, intval($_POST['numFields']));
32 $html = $normalization->getHtmlForCreateNewColumn($num_fields, $db, $table);
33 $html .= Url::getHiddenInputs($db, $table);
34 echo $html;
35 exit;
37 if (isset($_POST['addNewPrimary'])) {
38 $num_fields = 1;
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);
44 echo $html;
45 exit;
47 if (isset($_POST['findPdl'])) {
48 $html = $normalization->findPartialDependencies($table, $db);
49 echo $html;
50 exit;
53 if (isset($_POST['getNewTables2NF'])) {
54 $partialDependencies = json_decode($_POST['pd']);
55 $html = $normalization->getHtmlForNewTables2NF($partialDependencies, $table);
56 echo $html;
57 exit;
60 $response = Response::getInstance();
62 if (isset($_POST['getNewTables3NF'])) {
63 $dependencies = json_decode($_POST['pd']);
64 $tables = json_decode($_POST['tables']);
65 $newTables = $normalization->getHtmlForNewTables3NF($dependencies, $tables, $db);
66 $response->disable();
67 Core::headerJSON();
68 echo json_encode($newTables);
69 exit;
72 $header = $response->getHeader();
73 $scripts = $header->getScripts();
74 $scripts->addFile('normalization.js');
75 $scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
76 $normalForm = '1nf';
77 if (Core::isValid($_POST['normalizeTo'], array('1nf', '2nf', '3nf'))) {
78 $normalForm = $_POST['normalizeTo'];
80 if (isset($_POST['createNewTables2NF'])) {
81 $partialDependencies = json_decode($_POST['pd']);
82 $tablesName = json_decode($_POST['newTablesName']);
83 $res = $normalization->createNewTablesFor2NF($partialDependencies, $tablesName, $table, $db);
84 $response->addJSON($res);
85 exit;
87 if (isset($_POST['createNewTables3NF'])) {
88 $newtables = json_decode($_POST['newTables']);
89 $res = $normalization->createNewTablesFor3NF($newtables, $db);
90 $response->addJSON($res);
91 exit;
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);
102 exit;
104 if (isset($_POST['step1'])) {
105 $html = $normalization->getHtmlFor1NFStep1($db, $table, $normalForm);
106 $response->addHTML($html);
107 } elseif (isset($_POST['step2'])) {
108 $res = $normalization->getHtmlContentsFor1NFStep2($db, $table);
109 $response->addJSON($res);
110 } elseif (isset($_POST['step3'])) {
111 $res = $normalization->getHtmlContentsFor1NFStep3($db, $table);
112 $response->addJSON($res);
113 } elseif (isset($_POST['step4'])) {
114 $res = $normalization->getHtmlContentsFor1NFStep4($db, $table);
115 $response->addJSON($res);
116 } elseif (isset($_POST['step']) && $_POST['step'] == '2.1') {
117 $res = $normalization->getHtmlFor2NFstep1($db, $table);
118 $response->addJSON($res);
119 } elseif (isset($_POST['step']) && $_POST['step'] == '3.1') {
120 $tables = $_POST['tables'];
121 $res = $normalization->getHtmlFor3NFstep1($db, $tables);
122 $response->addJSON($res);
123 } else {
124 $response->addHTML($normalization->getHtmlForNormalizeTable());