Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/HuasoFoundries/phpPgAdmin6.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmenadiel <amenadiel@gmail.com>2018-11-13 21:07:08 +0300
committerAmenadiel <amenadiel@gmail.com>2018-11-13 21:44:10 +0300
commita0149862d09f567c6cf2b41517010c1df0c62dfd (patch)
treebc5fecd37a55cf494661d933c9fd307b4c60c05c /src/controllers
parent4be14949b445a4953a5e77c154c4013139e1c63d (diff)
simplification of nested loops
config for cs_fixer csfixer fixes index.php
Diffstat (limited to 'src/controllers')
-rw-r--r--src/controllers/DataexportController.php89
-rw-r--r--src/controllers/DataimportController.php216
-rw-r--r--src/controllers/MaterializedviewpropertiesController.php2
-rw-r--r--src/controllers/TablesController.php3
-rw-r--r--src/controllers/TblpropertiesController.php65
-rw-r--r--src/controllers/TypesController.php4
-rw-r--r--src/controllers/ViewpropertiesController.php2
7 files changed, 191 insertions, 190 deletions
diff --git a/src/controllers/DataexportController.php b/src/controllers/DataexportController.php
index 559e94ed..f303efd4 100644
--- a/src/controllers/DataexportController.php
+++ b/src/controllers/DataexportController.php
@@ -36,7 +36,7 @@ class DataexportController extends BaseController
$format = 'N/A';
// force behavior to assume there is no pg_dump in the system
- $forcemimic = false;
+ $forcemimic = isset($_REQUEST['forcemimic']) ? $_REQUEST['forcemimic'] : false;
// If format is set, then perform the export
if (!isset($_REQUEST['what'])) {
@@ -89,11 +89,12 @@ class DataexportController extends BaseController
break;
}
+ $cleanprefix = $clean ? '' : '-- ';
- return $this->mimicDumpFeature($format, $clean, $oids);
+ return $this->mimicDumpFeature($format, $cleanprefix, $oids);
}
- protected function mimicDumpFeature($format, $clean, $oids)
+ protected function mimicDumpFeature($format, $cleanprefix, $oids)
{
$data = $this->misc->getDatabaseAccessor();
@@ -111,34 +112,8 @@ class DataexportController extends BaseController
// Include application functions
$this->setNoOutput(true);
- $clean = false;
- $response = $this
- ->container
- ->responseobj;
- // Make it do a download, if necessary
- if ('download' == $_REQUEST['output']) {
- // Set headers. MSIE is totally broken for SSL downloading, so
- // we need to have it download in-place as plain text
- if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && isset($_SERVER['HTTPS'])) {
- $response = $response
- ->withHeader('Content-type', 'text/plain');
- } else {
- $response = $response
- ->withHeader('Content-type', 'application/download');
-
- if (isset($this->extensions[$format])) {
- $ext = $this->extensions[$format];
- } else {
- $ext = 'txt';
- }
- $response = $response
- ->withHeader('Content-Disposition', 'attachment; filename=dump.'.$ext);
- }
- } else {
- $response = $response
- ->withHeader('Content-type', 'text/plain');
- }
+ $response = $this->_getResponse($format);
$this->coalesceArr($_REQUEST, 'query', '');
@@ -164,7 +139,7 @@ class DataexportController extends BaseController
// If the dump is not dataonly then dump the structure prefix
if ('dataonly' != $_REQUEST['what']) {
- $tabledefprefix = $data->getTableDefPrefix($object, $clean);
+ $tabledefprefix = $data->getTableDefPrefix($object, $cleanprefix);
$this->prtrace('tabledefprefix', $tabledefprefix);
echo $tabledefprefix;
}
@@ -178,12 +153,7 @@ class DataexportController extends BaseController
$data->conn->setFetchMode(\ADODB_FETCH_NUM);
// Execute the query, if set, otherwise grab all rows from the table
- if ($object) {
- $rs = $data->dumpRelation($object, $oids);
- } else {
- $rs = $data->conn->Execute($_REQUEST['query']);
- $this->prtrace('$_REQUEST[query]', $_REQUEST['query']);
- }
+ $rs = $this->_getRS($data, $object, $oids);
$response = $this->pickFormat($data, $object, $oids, $rs, $format, $response);
}
@@ -200,7 +170,47 @@ class DataexportController extends BaseController
return $response;
}
- public function pickFormat($data, $object, $oids, $rs, $format, $response)
+ private function _getRS($data, $object, $oids)
+ {
+ if ($object) {
+ return $data->dumpRelation($object, $oids);
+ }
+
+ $this->prtrace('$_REQUEST[query]', $_REQUEST['query']);
+
+ return $data->conn->Execute($_REQUEST['query']);
+ }
+
+ private function _getResponse($format)
+ {
+ $response = $this
+ ->container
+ ->responseobj;
+
+ // Make it do a download, if necessary
+ if ('download' !== $_REQUEST['output']) {
+ return $response
+ ->withHeader('Content-type', 'text/plain');
+ }
+ // Set headers. MSIE is totally broken for SSL downloading, so
+ // we need to have it download in-place as plain text
+ if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && isset($_SERVER['HTTPS'])) {
+ return $response
+ ->withHeader('Content-type', 'text/plain');
+ }
+ $response = $response
+ ->withHeader('Content-type', 'application/download');
+
+ $ext = 'txt';
+ if (isset($this->extensions[$format])) {
+ $ext = $this->extensions[$format];
+ }
+
+ return $response
+ ->withHeader('Content-Disposition', 'attachment; filename=dump.'.$ext);
+ }
+
+ private function pickFormat($data, $object, $oids, $rs, $format, $response)
{
if ('copy' == $format) {
$this->_mimicCopy($data, $object, $oids, $rs);
@@ -214,9 +224,8 @@ class DataexportController extends BaseController
$this->_mimicXml($data, $object, $oids, $rs);
} elseif ('sql' == $format) {
$this->_mimicSQL($data, $object, $oids, $rs);
- } else {
- $this->_csvOrTab($data, $object, $oids, $rs, $format);
}
+ $this->_csvOrTab($data, $object, $oids, $rs, $format);
return $response;
}
diff --git a/src/controllers/DataimportController.php b/src/controllers/DataimportController.php
index 82f518b9..fdeb5f70 100644
--- a/src/controllers/DataimportController.php
+++ b/src/controllers/DataimportController.php
@@ -27,7 +27,7 @@ class DataimportController extends BaseController
$this->printHeader();
$this->printTrail('table');
- $this->printTabs('table', 'import');
+ $tabs = $this->printTabs('table', 'import');
// Default state for XML parser
$state = 'XML';
@@ -179,127 +179,129 @@ class DataimportController extends BaseController
};
// Check that file is specified and is an uploaded file
- if (isset($_FILES['source']) && is_uploaded_file($_FILES['source']['tmp_name']) && is_readable($_FILES['source']['tmp_name'])) {
- $fd = fopen($_FILES['source']['tmp_name'], 'rb');
- // Check that file was opened successfully
- if (false !== $fd) {
- $null_array = self::loadNULLArray();
- $status = $data->beginTransaction();
- if (0 != $status) {
- $this->halt($this->lang['strimporterror']);
- }
+ if (!isset($_FILES['source']) || !is_uploaded_file($_FILES['source']['tmp_name']) || !is_readable($_FILES['source']['tmp_name'])) {
+ // Upload went wrong
+ $this->printMsg($this->lang['strimporterror-uploadedfile']);
- // If format is set to 'auto', then determine format automatically from file name
- if ('auto' == $_REQUEST['format']) {
- $extension = substr(strrchr($_FILES['source']['name'], '.'), 1);
- switch ($extension) {
- case 'csv':
- $_REQUEST['format'] = 'csv';
-
- break;
- case 'txt':
- $_REQUEST['format'] = 'tab';
-
- break;
- case 'xml':
- $_REQUEST['format'] = 'xml';
-
- break;
- default:
- $data->rollbackTransaction();
- $this->halt($this->lang['strimporterror-fileformat']);
- }
- }
+ return $this->printFooter();
+ }
+ $fd = fopen($_FILES['source']['tmp_name'], 'rb');
+ // Check that file was opened successfully
+ if (false === $fd) {
+ // File could not be opened
+ $this->printMsg($this->lang['strimporterror']);
- // Do different import technique depending on file format
- switch ($_REQUEST['format']) {
- case 'csv':
- case 'tab':
- // XXX: Length of CSV lines limited to 100k
- $csv_max_line = 100000;
- // Set delimiter to tabs or commas
- if ('csv' == $_REQUEST['format']) {
- $csv_delimiter = ',';
- } else {
- $csv_delimiter = "\t";
- }
+ return $this->printFooter();
+ }
+ $null_array = self::loadNULLArray();
+ $status = $data->beginTransaction();
+ if (0 != $status) {
+ $this->halt($this->lang['strimporterror']);
+ }
- // Get first line of field names
- $fields = fgetcsv($fd, $csv_max_line, $csv_delimiter);
- $row = 2; //We start on the line AFTER the field names
- while ($line = fgetcsv($fd, $csv_max_line, $csv_delimiter)) {
- // Build value map
- $t_fields = [];
- $vars = [];
- $nulls = [];
- $format = [];
- $types = [];
- $i = 0;
- foreach ($fields as $f) {
- // Check that there is a column
- if (!isset($line[$i])) {
- $this->halt(sprintf($this->lang['strimporterrorline-badcolumnnum'], $row));
- }
- $t_fields[$i] = $f;
-
- // Check for nulls
- if (self::determineNull($line[$i], $null_array)) {
- $nulls[$i] = 'on';
- }
- // Add to value array
- $vars[$i] = $line[$i];
- // Format is always VALUE
- $format[$i] = 'VALUE';
- // Type is always text
- $types[$i] = 'text';
- ++$i;
- }
-
- $status = $data->insertRow($_REQUEST['table'], $t_fields, $vars, $nulls, $format, $types);
- if (0 != $status) {
- $data->rollbackTransaction();
- $this->halt(sprintf($this->lang['strimporterrorline'], $row));
- }
- ++$row;
- }
+ // If format is set to 'auto', then determine format automatically from file name
+ if ('auto' == $_REQUEST['format']) {
+ $extension = substr(strrchr($_FILES['source']['name'], '.'), 1);
+ switch ($extension) {
+ case 'csv':
+ $_REQUEST['format'] = 'csv';
- break;
- case 'xml':
- $parser = xml_parser_create();
- xml_set_element_handler($parser, $_startElement, $_endElement);
- xml_set_character_data_handler($parser, $_charHandler);
+ break;
+ case 'txt':
+ $_REQUEST['format'] = 'tab';
+
+ break;
+ case 'xml':
+ $_REQUEST['format'] = 'xml';
+
+ break;
+ default:
+ $data->rollbackTransaction();
+ $this->halt($this->lang['strimporterror-fileformat']);
+ }
+ }
+
+ // Do different import technique depending on file format
+ switch ($_REQUEST['format']) {
+ case 'csv':
+ case 'tab':
+ // XXX: Length of CSV lines limited to 100k
+ $csv_max_line = 100000;
+ // Set delimiter to tabs or commas
+ if ('csv' == $_REQUEST['format']) {
+ $csv_delimiter = ',';
+ } else {
+ $csv_delimiter = "\t";
+ }
- while (!feof($fd)) {
- $line = fgets($fd, 4096);
- xml_parse($parser, $line);
+ // Get first line of field names
+ $fields = fgetcsv($fd, $csv_max_line, $csv_delimiter);
+ $row = 2; //We start on the line AFTER the field names
+ while ($line = fgetcsv($fd, $csv_max_line, $csv_delimiter)) {
+ // Build value map
+ $t_fields = [];
+ $vars = [];
+ $nulls = [];
+ $format = [];
+ $types = [];
+ $i = 0;
+ foreach ($fields as $f) {
+ // Check that there is a column
+ if (!isset($line[$i])) {
+ $this->halt(sprintf($this->lang['strimporterrorline-badcolumnnum'], $row));
}
+ $t_fields[$i] = $f;
- xml_parser_free($parser);
+ // Check for nulls
+ if (self::determineNull($line[$i], $null_array)) {
+ $nulls[$i] = 'on';
+ }
+ // Add to value array
+ $vars[$i] = $line[$i];
+ // Format is always VALUE
+ $format[$i] = 'VALUE';
+ // Type is always text
+ $types[$i] = 'text';
+ ++$i;
+ }
- break;
- default:
- // Unknown type
+ $status = $data->insertRow($_REQUEST['table'], $t_fields, $vars, $nulls, $format, $types);
+ if (0 != $status) {
$data->rollbackTransaction();
- $this->halt($this->lang['strinvalidparam']);
+ $this->halt(sprintf($this->lang['strimporterrorline'], $row));
+ }
+ ++$row;
}
- $status = $data->endTransaction();
- if (0 != $status) {
- $this->halt($this->lang['strimporterror']);
+ break;
+ case 'xml':
+ $parser = xml_parser_create();
+ xml_set_element_handler($parser, $_startElement, $_endElement);
+ xml_set_character_data_handler($parser, $_charHandler);
+
+ while (!feof($fd)) {
+ $line = fgets($fd, 4096);
+ xml_parse($parser, $line);
}
- fclose($fd);
- $this->printMsg($this->lang['strfileimported']);
- } else {
- // File could not be opened
- $this->printMsg($this->lang['strimporterror']);
- }
- } else {
- // Upload went wrong
- $this->printMsg($this->lang['strimporterror-uploadedfile']);
+ xml_parser_free($parser);
+
+ break;
+ default:
+ // Unknown type
+ $data->rollbackTransaction();
+ $this->halt($this->lang['strinvalidparam']);
}
- $this->printFooter();
+ $status = $data->endTransaction();
+ if (0 != $status) {
+ $this->printMsg($this->lang['strimporterror']);
+ }
+ fclose($fd);
+
+ $this->printMsg($this->lang['strfileimported']);
+
+ return $this->printFooter();
}
public static function loadNULLArray()
diff --git a/src/controllers/MaterializedviewpropertiesController.php b/src/controllers/MaterializedviewpropertiesController.php
index 55cf482f..91086e30 100644
--- a/src/controllers/MaterializedviewpropertiesController.php
+++ b/src/controllers/MaterializedviewpropertiesController.php
@@ -182,7 +182,6 @@ class MaterializedviewpropertiesController extends BaseController
switch ($_REQUEST['stage']) {
case 1:
-
$this->printTrail('column');
$this->printTitle($this->lang['stralter'], 'pg.column.alter');
$this->printMsg($msg);
@@ -224,7 +223,6 @@ class MaterializedviewpropertiesController extends BaseController
break;
case 2:
-
// Check inputs
if ('' == trim($_REQUEST['field'])) {
$_REQUEST['stage'] = 1;
diff --git a/src/controllers/TablesController.php b/src/controllers/TablesController.php
index 07e04927..b47ad507 100644
--- a/src/controllers/TablesController.php
+++ b/src/controllers/TablesController.php
@@ -42,7 +42,6 @@ class TablesController extends BaseController
switch ($this->action) {
case 'create':
-
if (isset($_POST['cancel'])) {
$this->doDefault();
} else {
@@ -515,7 +514,6 @@ class TablesController extends BaseController
break;
case 2:
-
// Check inputs
$fields = trim($_REQUEST['fields']);
if ('' == trim($_REQUEST['name'])) {
@@ -636,7 +634,6 @@ class TablesController extends BaseController
break;
case 3:
-
$this->coalesceArr($_REQUEST, 'notnull', []);
$this->coalesceArr($_REQUEST, 'uniquekey', []);
diff --git a/src/controllers/TblpropertiesController.php b/src/controllers/TblpropertiesController.php
index 67752f00..ca13bfdc 100644
--- a/src/controllers/TblpropertiesController.php
+++ b/src/controllers/TblpropertiesController.php
@@ -594,37 +594,38 @@ class TblpropertiesController extends BaseController
$this->printMsg($msg);
// Check that file uploads are enabled
- if (ini_get('file_uploads')) {
- // Don't show upload option if max size of uploads is zero
- $max_size = $misc->inisizeToBytes(ini_get('upload_max_filesize'));
- if (is_double($max_size) && $max_size > 0) {
- echo '<form action="'.\SUBFOLDER.'/src/views/dataimport" method="post" enctype="multipart/form-data">'.PHP_EOL;
- echo '<table>'.PHP_EOL;
- echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strformat']}</th>".PHP_EOL;
- echo "\t\t<td><select name=\"format\">".PHP_EOL;
- echo "\t\t\t<option value=\"auto\">{$this->lang['strauto']}</option>".PHP_EOL;
- echo "\t\t\t<option value=\"csv\">CSV</option>".PHP_EOL;
- echo "\t\t\t<option value=\"tab\">{$this->lang['strtabbed']}</option>".PHP_EOL;
- if (function_exists('xml_parser_create')) {
- echo "\t\t\t<option value=\"xml\">XML</option>".PHP_EOL;
- }
- echo "\t\t</select></td>\n\t</tr>".PHP_EOL;
- echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strallowednulls']}</th>".PHP_EOL;
- echo "\t\t<td><label><input type=\"checkbox\" name=\"allowednulls[0]\" value=\"\\N\" checked=\"checked\" />{$this->lang['strbackslashn']}</label><br />".PHP_EOL;
- echo "\t\t<label><input type=\"checkbox\" name=\"allowednulls[1]\" value=\"NULL\" />NULL</label><br />".PHP_EOL;
- echo "\t\t<label><input type=\"checkbox\" name=\"allowednulls[2]\" value=\"\" />{$this->lang['stremptystring']}</label></td>\n\t</tr>".PHP_EOL;
- echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strfile']}</th>".PHP_EOL;
- echo "\t\t<td><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"{$max_size}\" />";
- echo "<input type=\"file\" name=\"source\" /></td>\n\t</tr>".PHP_EOL;
- echo '</table>'.PHP_EOL;
- echo '<p><input type="hidden" name="action" value="import" />'.PHP_EOL;
- echo $misc->form;
- echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), '" />'.PHP_EOL;
- echo "<input type=\"submit\" value=\"{$this->lang['strimport']}\" /></p>".PHP_EOL;
- echo '</form>'.PHP_EOL;
- }
- } else {
+ if (!ini_get('file_uploads')) {
echo "<p>{$this->lang['strnouploads']}</p>".PHP_EOL;
+
+ return;
+ }
+ // Don't show upload option if max size of uploads is zero
+ $max_size = $misc->inisizeToBytes(ini_get('upload_max_filesize'));
+ if (is_double($max_size) && $max_size > 0) {
+ echo '<form action="'.\SUBFOLDER.'/src/views/dataimport" method="post" enctype="multipart/form-data">'.PHP_EOL;
+ echo '<table>'.PHP_EOL;
+ echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strformat']}</th>".PHP_EOL;
+ echo "\t\t<td><select name=\"format\">".PHP_EOL;
+ echo "\t\t\t<option value=\"auto\">{$this->lang['strauto']}</option>".PHP_EOL;
+ echo "\t\t\t<option value=\"csv\">CSV</option>".PHP_EOL;
+ echo "\t\t\t<option value=\"tab\">{$this->lang['strtabbed']}</option>".PHP_EOL;
+ if (function_exists('xml_parser_create')) {
+ echo "\t\t\t<option value=\"xml\">XML</option>".PHP_EOL;
+ }
+ echo "\t\t</select></td>\n\t</tr>".PHP_EOL;
+ echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strallowednulls']}</th>".PHP_EOL;
+ echo "\t\t<td><label><input type=\"checkbox\" name=\"allowednulls[0]\" value=\"\\N\" checked=\"checked\" />{$this->lang['strbackslashn']}</label><br />".PHP_EOL;
+ echo "\t\t<label><input type=\"checkbox\" name=\"allowednulls[1]\" value=\"NULL\" />NULL</label><br />".PHP_EOL;
+ echo "\t\t<label><input type=\"checkbox\" name=\"allowednulls[2]\" value=\"\" />{$this->lang['stremptystring']}</label></td>\n\t</tr>".PHP_EOL;
+ echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strfile']}</th>".PHP_EOL;
+ echo "\t\t<td><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"{$max_size}\" />";
+ echo "<input type=\"file\" name=\"source\" /></td>\n\t</tr>".PHP_EOL;
+ echo '</table>'.PHP_EOL;
+ echo '<p><input type="hidden" name="action" value="import" />'.PHP_EOL;
+ echo $misc->form;
+ echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), '" />'.PHP_EOL;
+ echo "<input type=\"submit\" value=\"{$this->lang['strimport']}\" /></p>".PHP_EOL;
+ echo '</form>'.PHP_EOL;
}
}
@@ -743,7 +744,7 @@ class TblpropertiesController extends BaseController
}
$this->coalesceArr($_POST, 'length', '');
- $status = $data->addColumn(
+ list($status, $sql) = $data->addColumn(
$_POST['table'],
$_POST['field'],
$_POST['type'],
@@ -755,7 +756,7 @@ class TblpropertiesController extends BaseController
);
if (0 == $status) {
$misc->setReloadBrowser(true);
- $this->doDefault($this->lang['strcolumnadded']);
+ $this->doDefault(sprintf('%s %s %s', $sql, PHP_EOL, $this->lang['strcolumnadded']));
} else {
$_REQUEST['stage'] = 1;
$this->doAddColumn($this->lang['strcolumnaddedbad']);
diff --git a/src/controllers/TypesController.php b/src/controllers/TypesController.php
index bc0a2de2..a382349e 100644
--- a/src/controllers/TypesController.php
+++ b/src/controllers/TypesController.php
@@ -406,7 +406,6 @@ class TypesController extends BaseController
break;
case 2:
-
// Check inputs
$fields = trim($_REQUEST['fields']);
if ('' == trim($_REQUEST['name'])) {
@@ -486,7 +485,6 @@ class TypesController extends BaseController
break;
case 3:
-
// Check inputs
$fields = trim($_REQUEST['fields']);
if ('' == trim($_REQUEST['name'])) {
@@ -579,7 +577,6 @@ class TypesController extends BaseController
break;
case 2:
-
// Check inputs
$values = trim($_REQUEST['values']);
if ('' == trim($_REQUEST['name'])) {
@@ -627,7 +624,6 @@ class TypesController extends BaseController
break;
case 3:
-
// Check inputs
$values = trim($_REQUEST['values']);
if ('' == trim($_REQUEST['name'])) {
diff --git a/src/controllers/ViewpropertiesController.php b/src/controllers/ViewpropertiesController.php
index e89b5817..acdb54df 100644
--- a/src/controllers/ViewpropertiesController.php
+++ b/src/controllers/ViewpropertiesController.php
@@ -162,7 +162,6 @@ class ViewpropertiesController extends BaseController
switch ($_REQUEST['stage']) {
case 1:
-
$this->printTrail('column');
$this->printTitle($this->lang['stralter'], 'pg.column.alter');
$this->printMsg($msg);
@@ -204,7 +203,6 @@ class ViewpropertiesController extends BaseController
break;
case 2:
-
// Check inputs
if ('' == trim($_REQUEST['field'])) {
$_REQUEST['stage'] = 1;