Translated using Weblate (French)
[phpmyadmin.git] / normalization.php
blob6ca8330700d971b3bd1f83a0627ab2ab84dbef41
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 require_once 'libraries/common.inc.php';
17 $normalization = new Normalization($GLOBALS['dbi']);
19 if (isset($_REQUEST['getColumns'])) {
20 $html = '<option selected disabled>' . __('Select oneā€¦') . '</option>'
21 . '<option value="no_such_col">' . __('No such column') . '</option>';
22 //get column whose datatype falls under string category
23 $html .= $normalization->getHtmlForColumnsList(
24 $db,
25 $table,
26 _pgettext('string types', 'String')
28 echo $html;
29 exit;
31 if (isset($_REQUEST['splitColumn'])) {
32 $num_fields = min(4096, intval($_REQUEST['numFields']));
33 $html = $normalization->getHtmlForCreateNewColumn($num_fields, $db, $table);
34 $html .= Url::getHiddenInputs($db, $table);
35 echo $html;
36 exit;
38 if (isset($_REQUEST['addNewPrimary'])) {
39 $num_fields = 1;
40 $columnMeta = ['Field' => $table . "_id", 'Extra' => 'auto_increment'];
41 $html = $normalization->getHtmlForCreateNewColumn(
42 $num_fields,
43 $db,
44 $table,
45 $columnMeta
47 $html .= Url::getHiddenInputs($db, $table);
48 echo $html;
49 exit;
51 if (isset($_REQUEST['findPdl'])) {
52 $html = $normalization->findPartialDependencies($table, $db);
53 echo $html;
54 exit;
57 if (isset($_REQUEST['getNewTables2NF'])) {
58 $partialDependencies = json_decode($_REQUEST['pd']);
59 $html = $normalization->getHtmlForNewTables2NF($partialDependencies, $table);
60 echo $html;
61 exit;
64 $response = Response::getInstance();
66 if (isset($_REQUEST['getNewTables3NF'])) {
67 $dependencies = json_decode($_REQUEST['pd']);
68 $tables = json_decode($_REQUEST['tables']);
69 $newTables = $normalization->getHtmlForNewTables3NF($dependencies, $tables, $db);
70 $response->disable();
71 Core::headerJSON();
72 echo json_encode($newTables);
73 exit;
76 $header = $response->getHeader();
77 $scripts = $header->getScripts();
78 $scripts->addFile('normalization.js');
79 $scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
80 $normalForm = '1nf';
81 if (Core::isValid($_REQUEST['normalizeTo'], ['1nf', '2nf', '3nf'])) {
82 $normalForm = $_REQUEST['normalizeTo'];
84 if (isset($_REQUEST['createNewTables2NF'])) {
85 $partialDependencies = json_decode($_REQUEST['pd']);
86 $tablesName = json_decode($_REQUEST['newTablesName']);
87 $res = $normalization->createNewTablesFor2NF($partialDependencies, $tablesName, $table, $db);
88 $response->addJSON($res);
89 exit;
91 if (isset($_REQUEST['createNewTables3NF'])) {
92 $newtables = json_decode($_REQUEST['newTables']);
93 $res = $normalization->createNewTablesFor3NF($newtables, $db);
94 $response->addJSON($res);
95 exit;
97 if (isset($_POST['repeatingColumns'])) {
98 $repeatingColumns = $_POST['repeatingColumns'];
99 $newTable = $_POST['newTable'];
100 $newColumn = $_POST['newColumn'];
101 $primary_columns = $_POST['primary_columns'];
102 $res = $normalization->moveRepeatingGroup(
103 $repeatingColumns,
104 $primary_columns,
105 $newTable,
106 $newColumn,
107 $table,
110 $response->addJSON($res);
111 exit;
113 if (isset($_REQUEST['step1'])) {
114 $html = $normalization->getHtmlFor1NFStep1($db, $table, $normalForm);
115 $response->addHTML($html);
116 } elseif (isset($_REQUEST['step2'])) {
117 $res = $normalization->getHtmlContentsFor1NFStep2($db, $table);
118 $response->addJSON($res);
119 } elseif (isset($_REQUEST['step3'])) {
120 $res = $normalization->getHtmlContentsFor1NFStep3($db, $table);
121 $response->addJSON($res);
122 } elseif (isset($_REQUEST['step4'])) {
123 $res = $normalization->getHtmlContentsFor1NFStep4($db, $table);
124 $response->addJSON($res);
125 } elseif (isset($_REQUEST['step']) && $_REQUEST['step'] == '2.1') {
126 $res = $normalization->getHtmlFor2NFstep1($db, $table);
127 $response->addJSON($res);
128 } elseif (isset($_REQUEST['step']) && $_REQUEST['step'] == '3.1') {
129 $tables = $_REQUEST['tables'];
130 $res = $normalization->getHtmlFor3NFstep1($db, $tables);
131 $response->addJSON($res);
132 } else {
133 $response->addHTML($normalization->getHtmlForNormalizeTable());