Translated using Weblate (Turkish)
[phpmyadmin.git] / normalization.php
bloba93c1176e3087c869cb78d83a2079eb473c0e383
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\DatabaseInterface;
12 use PhpMyAdmin\Normalization;
13 use PhpMyAdmin\Response;
14 use PhpMyAdmin\Url;
16 if (! defined('ROOT_PATH')) {
17 define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
20 global $db, $table;
22 require_once ROOT_PATH . 'libraries/common.inc.php';
24 /** @var Response $response */
25 $response = $containerBuilder->get(Response::class);
27 /** @var DatabaseInterface $dbi */
28 $dbi = $containerBuilder->get(DatabaseInterface::class);
30 /** @var Normalization $normalization */
31 $normalization = $containerBuilder->get('normalization');
33 if (isset($_POST['getColumns'])) {
34 $html = '<option selected disabled>' . __('Select oneā€¦') . '</option>'
35 . '<option value="no_such_col">' . __('No such column') . '</option>';
36 //get column whose datatype falls under string category
37 $html .= $normalization->getHtmlForColumnsList(
38 $db,
39 $table,
40 _pgettext('string types', 'String')
42 echo $html;
43 exit;
45 if (isset($_POST['splitColumn'])) {
46 $num_fields = min(4096, intval($_POST['numFields']));
47 $html = $normalization->getHtmlForCreateNewColumn($num_fields, $db, $table);
48 $html .= Url::getHiddenInputs($db, $table);
49 echo $html;
50 exit;
52 if (isset($_POST['addNewPrimary'])) {
53 $num_fields = 1;
54 $columnMeta = [
55 'Field' => $table . "_id",
56 'Extra' => 'auto_increment',
58 $html = $normalization->getHtmlForCreateNewColumn(
59 $num_fields,
60 $db,
61 $table,
62 $columnMeta
64 $html .= Url::getHiddenInputs($db, $table);
65 echo $html;
66 exit;
68 if (isset($_POST['findPdl'])) {
69 $html = $normalization->findPartialDependencies($table, $db);
70 echo $html;
71 exit;
74 if (isset($_POST['getNewTables2NF'])) {
75 $partialDependencies = json_decode($_POST['pd']);
76 $html = $normalization->getHtmlForNewTables2NF($partialDependencies, $table);
77 echo $html;
78 exit;
81 if (isset($_POST['getNewTables3NF'])) {
82 $dependencies = json_decode($_POST['pd']);
83 $tables = json_decode($_POST['tables']);
84 $newTables = $normalization->getHtmlForNewTables3NF($dependencies, $tables, $db);
85 $response->disable();
86 Core::headerJSON();
87 echo json_encode($newTables);
88 exit;
91 $header = $response->getHeader();
92 $scripts = $header->getScripts();
93 $scripts->addFile('normalization.js');
94 $scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
95 $normalForm = '1nf';
96 if (Core::isValid($_POST['normalizeTo'], ['1nf', '2nf', '3nf'])) {
97 $normalForm = $_POST['normalizeTo'];
99 if (isset($_POST['createNewTables2NF'])) {
100 $partialDependencies = json_decode($_POST['pd']);
101 $tablesName = json_decode($_POST['newTablesName']);
102 $res = $normalization->createNewTablesFor2NF($partialDependencies, $tablesName, $table, $db);
103 $response->addJSON($res);
104 exit;
106 if (isset($_POST['createNewTables3NF'])) {
107 $newtables = json_decode($_POST['newTables']);
108 $res = $normalization->createNewTablesFor3NF($newtables, $db);
109 $response->addJSON($res);
110 exit;
112 if (isset($_POST['repeatingColumns'])) {
113 $repeatingColumns = $_POST['repeatingColumns'];
114 $newTable = $_POST['newTable'];
115 $newColumn = $_POST['newColumn'];
116 $primary_columns = $_POST['primary_columns'];
117 $res = $normalization->moveRepeatingGroup(
118 $repeatingColumns,
119 $primary_columns,
120 $newTable,
121 $newColumn,
122 $table,
125 $response->addJSON($res);
126 exit;
128 if (isset($_POST['step1'])) {
129 $html = $normalization->getHtmlFor1NFStep1($db, $table, $normalForm);
130 $response->addHTML($html);
131 } elseif (isset($_POST['step2'])) {
132 $res = $normalization->getHtmlContentsFor1NFStep2($db, $table);
133 $response->addJSON($res);
134 } elseif (isset($_POST['step3'])) {
135 $res = $normalization->getHtmlContentsFor1NFStep3($db, $table);
136 $response->addJSON($res);
137 } elseif (isset($_POST['step4'])) {
138 $res = $normalization->getHtmlContentsFor1NFStep4($db, $table);
139 $response->addJSON($res);
140 } elseif (isset($_POST['step']) && $_POST['step'] == '2.1') {
141 $res = $normalization->getHtmlFor2NFstep1($db, $table);
142 $response->addJSON($res);
143 } elseif (isset($_POST['step']) && $_POST['step'] == '3.1') {
144 $tables = $_POST['tables'];
145 $res = $normalization->getHtmlFor3NFstep1($db, $tables);
146 $response->addJSON($res);
147 } else {
148 $response->addHTML($normalization->getHtmlForNormalizeTable());