2016-10-22 14:57:10 +00:00
|
|
|
<?php
|
|
|
|
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
|
|
|
/**
|
|
|
|
* Normalization process (temporarily specific to 1NF)
|
|
|
|
*
|
|
|
|
* @package PhpMyAdmin
|
|
|
|
*/
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
use PhpMyAdmin\Core;
|
|
|
|
use PhpMyAdmin\Normalization;
|
|
|
|
use PhpMyAdmin\Response;
|
|
|
|
use PhpMyAdmin\Url;
|
|
|
|
|
2016-10-22 14:57:10 +00:00
|
|
|
require_once 'libraries/common.inc.php';
|
2018-04-14 09:18:00 +00:00
|
|
|
|
|
|
|
$normalization = new Normalization($GLOBALS['dbi']);
|
2016-10-22 14:57:10 +00:00
|
|
|
|
2018-12-16 14:31:03 +00:00
|
|
|
if (isset($_POST['getColumns'])) {
|
2016-10-22 14:57:10 +00:00
|
|
|
$html = '<option selected disabled>' . __('Select one…') . '</option>'
|
|
|
|
. '<option value="no_such_col">' . __('No such column') . '</option>';
|
|
|
|
//get column whose datatype falls under string category
|
2018-04-14 09:18:00 +00:00
|
|
|
$html .= $normalization->getHtmlForColumnsList(
|
2016-10-22 14:57:10 +00:00
|
|
|
$db,
|
|
|
|
$table,
|
|
|
|
_pgettext('string types', 'String')
|
|
|
|
);
|
|
|
|
echo $html;
|
|
|
|
exit;
|
|
|
|
}
|
2018-12-16 14:31:03 +00:00
|
|
|
if (isset($_POST['splitColumn'])) {
|
|
|
|
$num_fields = min(4096, intval($_POST['numFields']));
|
2018-04-14 09:18:00 +00:00
|
|
|
$html = $normalization->getHtmlForCreateNewColumn($num_fields, $db, $table);
|
|
|
|
$html .= Url::getHiddenInputs($db, $table);
|
2016-10-22 14:57:10 +00:00
|
|
|
echo $html;
|
|
|
|
exit;
|
|
|
|
}
|
2018-12-16 14:31:03 +00:00
|
|
|
if (isset($_POST['addNewPrimary'])) {
|
2016-10-22 14:57:10 +00:00
|
|
|
$num_fields = 1;
|
|
|
|
$columnMeta = array('Field'=>$table . "_id", 'Extra'=>'auto_increment');
|
2018-04-14 09:18:00 +00:00
|
|
|
$html = $normalization->getHtmlForCreateNewColumn(
|
2016-10-22 14:57:10 +00:00
|
|
|
$num_fields, $db, $table, $columnMeta
|
|
|
|
);
|
2018-04-14 09:18:00 +00:00
|
|
|
$html .= Url::getHiddenInputs($db, $table);
|
2016-10-22 14:57:10 +00:00
|
|
|
echo $html;
|
|
|
|
exit;
|
|
|
|
}
|
2018-12-16 14:31:03 +00:00
|
|
|
if (isset($_POST['findPdl'])) {
|
2018-04-14 09:18:00 +00:00
|
|
|
$html = $normalization->findPartialDependencies($table, $db);
|
2016-10-22 14:57:10 +00:00
|
|
|
echo $html;
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2018-12-16 14:31:03 +00:00
|
|
|
if (isset($_POST['getNewTables2NF'])) {
|
|
|
|
$partialDependencies = json_decode($_POST['pd']);
|
2018-04-14 09:18:00 +00:00
|
|
|
$html = $normalization->getHtmlForNewTables2NF($partialDependencies, $table);
|
2016-10-22 14:57:10 +00:00
|
|
|
echo $html;
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2017-04-20 10:55:30 +00:00
|
|
|
$response = Response::getInstance();
|
|
|
|
|
2018-12-16 14:31:03 +00:00
|
|
|
if (isset($_POST['getNewTables3NF'])) {
|
|
|
|
$dependencies = json_decode($_POST['pd']);
|
|
|
|
$tables = json_decode($_POST['tables']);
|
2018-04-14 09:18:00 +00:00
|
|
|
$newTables = $normalization->getHtmlForNewTables3NF($dependencies, $tables, $db);
|
2017-04-20 10:55:30 +00:00
|
|
|
$response->disable();
|
2018-04-14 09:18:00 +00:00
|
|
|
Core::headerJSON();
|
2016-10-22 14:57:10 +00:00
|
|
|
echo json_encode($newTables);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$header = $response->getHeader();
|
|
|
|
$scripts = $header->getScripts();
|
|
|
|
$scripts->addFile('normalization.js');
|
2018-04-14 09:18:00 +00:00
|
|
|
$scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
|
2016-10-22 14:57:10 +00:00
|
|
|
$normalForm = '1nf';
|
2018-12-16 14:31:03 +00:00
|
|
|
if (Core::isValid($_POST['normalizeTo'], array('1nf', '2nf', '3nf'))) {
|
|
|
|
$normalForm = $_POST['normalizeTo'];
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
2018-12-16 14:31:03 +00:00
|
|
|
if (isset($_POST['createNewTables2NF'])) {
|
|
|
|
$partialDependencies = json_decode($_POST['pd']);
|
|
|
|
$tablesName = json_decode($_POST['newTablesName']);
|
2018-04-14 09:18:00 +00:00
|
|
|
$res = $normalization->createNewTablesFor2NF($partialDependencies, $tablesName, $table, $db);
|
2016-10-22 14:57:10 +00:00
|
|
|
$response->addJSON($res);
|
|
|
|
exit;
|
|
|
|
}
|
2018-12-16 14:31:03 +00:00
|
|
|
if (isset($_POST['createNewTables3NF'])) {
|
|
|
|
$newtables = json_decode($_POST['newTables']);
|
2018-04-14 09:18:00 +00:00
|
|
|
$res = $normalization->createNewTablesFor3NF($newtables, $db);
|
2016-10-22 14:57:10 +00:00
|
|
|
$response->addJSON($res);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
if (isset($_POST['repeatingColumns'])) {
|
|
|
|
$repeatingColumns = $_POST['repeatingColumns'];
|
|
|
|
$newTable = $_POST['newTable'];
|
|
|
|
$newColumn = $_POST['newColumn'];
|
|
|
|
$primary_columns = $_POST['primary_columns'];
|
2018-04-14 09:18:00 +00:00
|
|
|
$res = $normalization->moveRepeatingGroup(
|
2016-10-22 14:57:10 +00:00
|
|
|
$repeatingColumns, $primary_columns, $newTable, $newColumn, $table, $db
|
|
|
|
);
|
|
|
|
$response->addJSON($res);
|
|
|
|
exit;
|
|
|
|
}
|
2018-12-16 14:31:03 +00:00
|
|
|
if (isset($_POST['step1'])) {
|
2018-04-14 09:18:00 +00:00
|
|
|
$html = $normalization->getHtmlFor1NFStep1($db, $table, $normalForm);
|
2016-10-22 14:57:10 +00:00
|
|
|
$response->addHTML($html);
|
2018-12-16 14:31:03 +00:00
|
|
|
} elseif (isset($_POST['step2'])) {
|
2018-04-14 09:18:00 +00:00
|
|
|
$res = $normalization->getHtmlContentsFor1NFStep2($db, $table);
|
2016-10-22 14:57:10 +00:00
|
|
|
$response->addJSON($res);
|
2018-12-16 14:31:03 +00:00
|
|
|
} elseif (isset($_POST['step3'])) {
|
2018-04-14 09:18:00 +00:00
|
|
|
$res = $normalization->getHtmlContentsFor1NFStep3($db, $table);
|
2016-10-22 14:57:10 +00:00
|
|
|
$response->addJSON($res);
|
2018-12-16 14:31:03 +00:00
|
|
|
} elseif (isset($_POST['step4'])) {
|
2018-04-14 09:18:00 +00:00
|
|
|
$res = $normalization->getHtmlContentsFor1NFStep4($db, $table);
|
2016-10-22 14:57:10 +00:00
|
|
|
$response->addJSON($res);
|
2018-12-16 14:31:03 +00:00
|
|
|
} elseif (isset($_POST['step']) && $_POST['step'] == '2.1') {
|
2018-04-14 09:18:00 +00:00
|
|
|
$res = $normalization->getHtmlFor2NFstep1($db, $table);
|
2016-10-22 14:57:10 +00:00
|
|
|
$response->addJSON($res);
|
2018-12-16 14:31:03 +00:00
|
|
|
} elseif (isset($_POST['step']) && $_POST['step'] == '3.1') {
|
|
|
|
$tables = $_POST['tables'];
|
2018-04-14 09:18:00 +00:00
|
|
|
$res = $normalization->getHtmlFor3NFstep1($db, $tables);
|
2016-10-22 14:57:10 +00:00
|
|
|
$response->addJSON($res);
|
|
|
|
} else {
|
2018-04-14 09:18:00 +00:00
|
|
|
$response->addHTML($normalization->getHtmlForNormalizeTable());
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|