Translated using Weblate (Slovenian)
[phpmyadmin.git] / normalization.php
blob437f4d0fdc6ebc6138b4cde3b98618438b418326
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Normalization process (temporarily specific to 1NF)
6 * @package PhpMyAdmin
7 */
8 declare(strict_types=1);
10 use PhpMyAdmin\Core;
11 use PhpMyAdmin\Normalization;
12 use PhpMyAdmin\Response;
13 use PhpMyAdmin\Url;
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(
28 $db,
29 $table,
30 _pgettext('string types', 'String')
32 echo $html;
33 exit;
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);
39 echo $html;
40 exit;
42 if (isset($_POST['addNewPrimary'])) {
43 $num_fields = 1;
44 $columnMeta = [
45 'Field' => $table . "_id",
46 'Extra' => 'auto_increment',
48 $html = $normalization->getHtmlForCreateNewColumn(
49 $num_fields,
50 $db,
51 $table,
52 $columnMeta
54 $html .= Url::getHiddenInputs($db, $table);
55 echo $html;
56 exit;
58 if (isset($_POST['findPdl'])) {
59 $html = $normalization->findPartialDependencies($table, $db);
60 echo $html;
61 exit;
64 if (isset($_POST['getNewTables2NF'])) {
65 $partialDependencies = json_decode($_POST['pd']);
66 $html = $normalization->getHtmlForNewTables2NF($partialDependencies, $table);
67 echo $html;
68 exit;
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);
77 $response->disable();
78 Core::headerJSON();
79 echo json_encode($newTables);
80 exit;
83 $header = $response->getHeader();
84 $scripts = $header->getScripts();
85 $scripts->addFile('normalization.js');
86 $scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
87 $normalForm = '1nf';
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);
96 exit;
98 if (isset($_POST['createNewTables3NF'])) {
99 $newtables = json_decode($_POST['newTables']);
100 $res = $normalization->createNewTablesFor3NF($newtables, $db);
101 $response->addJSON($res);
102 exit;
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(
110 $repeatingColumns,
111 $primary_columns,
112 $newTable,
113 $newColumn,
114 $table,
117 $response->addJSON($res);
118 exit;
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);
139 } else {
140 $response->addHTML($normalization->getHtmlForNormalizeTable());