devilbox/.devilbox/www/htdocs/vendor/phpmyadmin-4.8/normalization.php

126 lines
4.1 KiB
PHP
Raw Normal View History

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
if (isset($_REQUEST['getColumns'])) {
$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;
}
if (isset($_REQUEST['splitColumn'])) {
$num_fields = min(4096, intval($_REQUEST['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;
}
if (isset($_REQUEST['addNewPrimary'])) {
$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;
}
if (isset($_REQUEST['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;
}
if (isset($_REQUEST['getNewTables2NF'])) {
$partialDependencies = json_decode($_REQUEST['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;
}
$response = Response::getInstance();
2016-10-22 14:57:10 +00:00
if (isset($_REQUEST['getNewTables3NF'])) {
$dependencies = json_decode($_REQUEST['pd']);
$tables = json_decode($_REQUEST['tables']);
2018-04-14 09:18:00 +00:00
$newTables = $normalization->getHtmlForNewTables3NF($dependencies, $tables, $db);
$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-04-14 09:18:00 +00:00
if (Core::isValid($_REQUEST['normalizeTo'], array('1nf', '2nf', '3nf'))) {
2016-10-22 14:57:10 +00:00
$normalForm = $_REQUEST['normalizeTo'];
}
if (isset($_REQUEST['createNewTables2NF'])) {
$partialDependencies = json_decode($_REQUEST['pd']);
$tablesName = json_decode($_REQUEST['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;
}
if (isset($_REQUEST['createNewTables3NF'])) {
$newtables = json_decode($_REQUEST['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;
}
if (isset($_REQUEST['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-04-14 09:18:00 +00:00
} elseif (isset($_REQUEST['step2'])) {
$res = $normalization->getHtmlContentsFor1NFStep2($db, $table);
2016-10-22 14:57:10 +00:00
$response->addJSON($res);
2018-04-14 09:18:00 +00:00
} elseif (isset($_REQUEST['step3'])) {
$res = $normalization->getHtmlContentsFor1NFStep3($db, $table);
2016-10-22 14:57:10 +00:00
$response->addJSON($res);
2018-04-14 09:18:00 +00:00
} elseif (isset($_REQUEST['step4'])) {
$res = $normalization->getHtmlContentsFor1NFStep4($db, $table);
2016-10-22 14:57:10 +00:00
$response->addJSON($res);
2018-04-14 09:18:00 +00:00
} elseif (isset($_REQUEST['step']) && $_REQUEST['step'] == '2.1') {
$res = $normalization->getHtmlFor2NFstep1($db, $table);
2016-10-22 14:57:10 +00:00
$response->addJSON($res);
2018-04-14 09:18:00 +00:00
} elseif (isset($_REQUEST['step']) && $_REQUEST['step'] == '3.1') {
2016-10-22 14:57:10 +00:00
$tables = $_REQUEST['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
}