Translated using Weblate (Ukrainian)
[phpmyadmin.git] / db_qbe.php
blob82a8d3b98029db964462888d28ed27fdf9061909
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * query by example the whole database
6 * @package PhpMyAdmin
7 */
8 declare(strict_types=1);
10 use PhpMyAdmin\Database\Qbe;
11 use PhpMyAdmin\Message;
12 use PhpMyAdmin\Relation;
13 use PhpMyAdmin\Response;
14 use PhpMyAdmin\SavedSearches;
15 use PhpMyAdmin\Sql;
16 use PhpMyAdmin\Url;
17 use PhpMyAdmin\Util;
19 /**
20 * requirements
22 require_once 'libraries/common.inc.php';
24 $response = Response::getInstance();
26 // Gets the relation settings
27 $relation = new Relation($GLOBALS['dbi']);
28 $cfgRelation = $relation->getRelationsParam();
30 $savedSearchList = [];
31 $savedSearch = null;
32 $currentSearchId = null;
33 if ($cfgRelation['savedsearcheswork']) {
34 $header = $response->getHeader();
35 $scripts = $header->getScripts();
36 $scripts->addFile('db_qbe.js');
38 //Get saved search list.
39 $savedSearch = new SavedSearches($GLOBALS);
40 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
41 ->setDbname($_REQUEST['db']);
43 if (!empty($_REQUEST['searchId'])) {
44 $savedSearch->setId($_REQUEST['searchId']);
47 //Action field is sent.
48 if (isset($_REQUEST['action'])) {
49 $savedSearch->setSearchName($_REQUEST['searchName']);
50 if ('create' === $_REQUEST['action']) {
51 $saveResult = $savedSearch->setId(null)
52 ->setCriterias($_REQUEST)
53 ->save();
54 } elseif ('update' === $_REQUEST['action']) {
55 $saveResult = $savedSearch->setCriterias($_REQUEST)
56 ->save();
57 } elseif ('delete' === $_REQUEST['action']) {
58 $deleteResult = $savedSearch->delete();
59 //After deletion, reset search.
60 $savedSearch = new SavedSearches($GLOBALS);
61 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
62 ->setDbname($_REQUEST['db']);
63 $_REQUEST = [];
64 } elseif ('load' === $_REQUEST['action']) {
65 if (empty($_REQUEST['searchId'])) {
66 //when not loading a search, reset the object.
67 $savedSearch = new SavedSearches($GLOBALS);
68 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
69 ->setDbname($_REQUEST['db']);
70 $_REQUEST = [];
71 } else {
72 $loadResult = $savedSearch->load();
75 //Else, it's an "update query"
78 $savedSearchList = $savedSearch->getList();
79 $currentSearchId = $savedSearch->getId();
82 /**
83 * A query has been submitted -> (maybe) execute it
85 $message_to_display = false;
86 if (isset($_REQUEST['submit_sql']) && ! empty($sql_query)) {
87 if (! preg_match('@^SELECT@i', $sql_query)) {
88 $message_to_display = true;
89 } else {
90 $goto = 'db_sql.php';
91 $sql = new Sql();
92 $sql->executeQueryAndSendQueryResponse(
93 null, // analyzed_sql_results
94 false, // is_gotofile
95 $_REQUEST['db'], // db
96 null, // table
97 false, // find_real_end
98 null, // sql_query_for_bookmark
99 null, // extra_data
100 null, // message_to_show
101 null, // message
102 null, // sql_data
103 $goto, // goto
104 $pmaThemeImage, // pmaThemeImage
105 null, // disp_query
106 null, // disp_message
107 null, // query_type
108 $sql_query, // sql_query
109 null, // selectedTables
110 null // complete_query
115 $sub_part = '_qbe';
116 require 'libraries/db_common.inc.php';
117 $url_query .= '&amp;goto=db_qbe.php';
118 $url_params['goto'] = 'db_qbe.php';
120 list(
121 $tables,
122 $num_tables,
123 $total_num_tables,
124 $sub_part,
125 $is_show_stats,
126 $db_is_system_schema,
127 $tooltip_truename,
128 $tooltip_aliasname,
129 $pos
130 ) = Util::getDbInfo($db, is_null($sub_part) ? '' : $sub_part);
132 if ($message_to_display) {
133 Message::error(
134 __('You have to choose at least one column to display!')
136 ->display();
138 unset($message_to_display);
140 // create new qbe search instance
141 $db_qbe = new Qbe($GLOBALS['dbi'], $GLOBALS['db'], $savedSearchList, $savedSearch);
143 $url = 'db_designer.php' . Url::getCommon(
144 array_merge(
145 $url_params,
146 ['query' => 1]
149 $response->addHTML(
150 Message::notice(
151 sprintf(
152 __('Switch to %svisual builder%s'),
153 '<a href="' . $url . '">',
154 '</a>'
160 * Displays the Query by example form
162 $response->addHTML($db_qbe->getSelectionForm());