devilbox/.devilbox/www/htdocs/vendor/phpmyadmin-4.9.3/db_qbe.php

179 lines
4.7 KiB
PHP
Raw Normal View History

2016-10-22 14:57:10 +00:00
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* query by example the whole database
*
* @package PhpMyAdmin
*/
2018-04-14 09:18:00 +00:00
use PhpMyAdmin\Database\Qbe;
use PhpMyAdmin\Message;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Response;
use PhpMyAdmin\SavedSearches;
use PhpMyAdmin\Sql;
2018-12-16 14:31:03 +00:00
use PhpMyAdmin\Template;
2018-04-14 09:18:00 +00:00
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
2016-10-22 14:57:10 +00:00
/**
* requirements
*/
require_once 'libraries/common.inc.php';
$response = Response::getInstance();
2018-12-16 14:31:03 +00:00
$relation = new Relation();
2016-10-22 14:57:10 +00:00
// Gets the relation settings
2018-04-14 09:18:00 +00:00
$cfgRelation = $relation->getRelationsParam();
2016-10-22 14:57:10 +00:00
$savedSearchList = array();
$savedSearch = null;
$currentSearchId = null;
if ($cfgRelation['savedsearcheswork']) {
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('db_qbe.js');
//Get saved search list.
$savedSearch = new SavedSearches($GLOBALS);
$savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
2018-12-16 14:31:03 +00:00
->setDbname($GLOBALS['db']);
2016-10-22 14:57:10 +00:00
2018-12-16 14:31:03 +00:00
if (!empty($_POST['searchId'])) {
$savedSearch->setId($_POST['searchId']);
2016-10-22 14:57:10 +00:00
}
//Action field is sent.
2018-12-16 14:31:03 +00:00
if (isset($_POST['action'])) {
$savedSearch->setSearchName($_POST['searchName']);
if ('create' === $_POST['action']) {
2016-10-22 14:57:10 +00:00
$saveResult = $savedSearch->setId(null)
2018-12-16 14:31:03 +00:00
->setCriterias($_POST)
2016-10-22 14:57:10 +00:00
->save();
2018-12-16 14:31:03 +00:00
} elseif ('update' === $_POST['action']) {
$saveResult = $savedSearch->setCriterias($_POST)
2016-10-22 14:57:10 +00:00
->save();
2018-12-16 14:31:03 +00:00
} elseif ('delete' === $_POST['action']) {
2016-10-22 14:57:10 +00:00
$deleteResult = $savedSearch->delete();
//After deletion, reset search.
$savedSearch = new SavedSearches($GLOBALS);
$savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
2018-12-16 14:31:03 +00:00
->setDbname($GLOBALS['db']);
$_POST = array();
} elseif ('load' === $_POST['action']) {
if (empty($_POST['searchId'])) {
2016-10-22 14:57:10 +00:00
//when not loading a search, reset the object.
$savedSearch = new SavedSearches($GLOBALS);
$savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
2018-12-16 14:31:03 +00:00
->setDbname($GLOBALS['db']);
$_POST = array();
2016-10-22 14:57:10 +00:00
} else {
$loadResult = $savedSearch->load();
}
}
//Else, it's an "update query"
}
$savedSearchList = $savedSearch->getList();
$currentSearchId = $savedSearch->getId();
}
/**
* A query has been submitted -> (maybe) execute it
*/
$message_to_display = false;
2018-12-16 14:31:03 +00:00
if (isset($_POST['submit_sql']) && ! empty($sql_query)) {
2016-10-22 14:57:10 +00:00
if (! preg_match('@^SELECT@i', $sql_query)) {
$message_to_display = true;
} else {
$goto = 'db_sql.php';
2018-04-14 09:18:00 +00:00
$sql = new Sql();
$sql->executeQueryAndSendQueryResponse(
2016-10-22 14:57:10 +00:00
null, // analyzed_sql_results
false, // is_gotofile
2018-12-16 14:31:03 +00:00
$_POST['db'], // db
2016-10-22 14:57:10 +00:00
null, // table
false, // find_real_end
null, // sql_query_for_bookmark
null, // extra_data
null, // message_to_show
null, // message
null, // sql_data
$goto, // goto
$pmaThemeImage, // pmaThemeImage
null, // disp_query
null, // disp_message
null, // query_type
$sql_query, // sql_query
null, // selectedTables
null // complete_query
);
}
}
$sub_part = '_qbe';
require 'libraries/db_common.inc.php';
$url_query .= '&amp;goto=db_qbe.php';
$url_params['goto'] = 'db_qbe.php';
list(
$tables,
$num_tables,
$total_num_tables,
$sub_part,
$is_show_stats,
$db_is_system_schema,
$tooltip_truename,
$tooltip_aliasname,
$pos
2018-04-14 09:18:00 +00:00
) = Util::getDbInfo($db, isset($sub_part) ? $sub_part : '');
2016-10-22 14:57:10 +00:00
if ($message_to_display) {
2018-04-14 09:18:00 +00:00
Message::error(
2016-10-22 14:57:10 +00:00
__('You have to choose at least one column to display!')
)
->display();
}
unset($message_to_display);
// create new qbe search instance
2018-04-14 09:18:00 +00:00
$db_qbe = new Qbe($GLOBALS['db'], $savedSearchList, $savedSearch);
2016-10-22 14:57:10 +00:00
2018-12-16 14:31:03 +00:00
$secondaryTabs = [
'multi' => [
'link' => 'db_multi_table_query.php',
'text' => __('Multi-table query'),
],
'qbe' => [
'link' => 'db_qbe.php',
'text' => __('Query by example'),
],
];
$response->addHTML(
Template::get('secondary_tabs')->render([
'url_params' => $url_params,
'sub_tabs' => $secondaryTabs,
])
);
2018-04-14 09:18:00 +00:00
$url = 'db_designer.php' . Url::getCommon(
2016-10-22 14:57:10 +00:00
array_merge(
$url_params,
array('query' => 1)
)
);
$response->addHTML(
2018-04-14 09:18:00 +00:00
Message::notice(
2016-10-22 14:57:10 +00:00
sprintf(
__('Switch to %svisual builder%s'),
'<a href="' . $url . '">',
'</a>'
)
)
);
/**
* Displays the Query by example form
*/
$response->addHTML($db_qbe->getSelectionForm());