Translated using Weblate (Indonesian)
[phpmyadmin.git] / db_qbe.php
blobb571480be9348458d15f4d71889c24ec929bfd7e
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 use PhpMyAdmin\Relation;
9 use PhpMyAdmin\Response;
10 use PhpMyAdmin\SavedSearches;
11 use PhpMyAdmin\Sql;
12 use PhpMyAdmin\Url;
14 /**
15 * requirements
17 require_once 'libraries/common.inc.php';
19 $response = Response::getInstance();
21 // Gets the relation settings
22 $cfgRelation = Relation::getRelationsParam();
24 $savedSearchList = array();
25 $savedSearch = null;
26 $currentSearchId = null;
27 if ($cfgRelation['savedsearcheswork']) {
28 $header = $response->getHeader();
29 $scripts = $header->getScripts();
30 $scripts->addFile('db_qbe.js');
32 //Get saved search list.
33 $savedSearch = new SavedSearches($GLOBALS);
34 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
35 ->setDbname($_REQUEST['db']);
37 if (!empty($_REQUEST['searchId'])) {
38 $savedSearch->setId($_REQUEST['searchId']);
41 //Action field is sent.
42 if (isset($_REQUEST['action'])) {
43 $savedSearch->setSearchName($_REQUEST['searchName']);
44 if ('create' === $_REQUEST['action']) {
45 $saveResult = $savedSearch->setId(null)
46 ->setCriterias($_REQUEST)
47 ->save();
48 } elseif ('update' === $_REQUEST['action']) {
49 $saveResult = $savedSearch->setCriterias($_REQUEST)
50 ->save();
51 } elseif ('delete' === $_REQUEST['action']) {
52 $deleteResult = $savedSearch->delete();
53 //After deletion, reset search.
54 $savedSearch = new SavedSearches($GLOBALS);
55 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
56 ->setDbname($_REQUEST['db']);
57 $_REQUEST = array();
58 } elseif ('load' === $_REQUEST['action']) {
59 if (empty($_REQUEST['searchId'])) {
60 //when not loading a search, reset the object.
61 $savedSearch = new SavedSearches($GLOBALS);
62 $savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
63 ->setDbname($_REQUEST['db']);
64 $_REQUEST = array();
65 } else {
66 $loadResult = $savedSearch->load();
69 //Else, it's an "update query"
72 $savedSearchList = $savedSearch->getList();
73 $currentSearchId = $savedSearch->getId();
76 /**
77 * A query has been submitted -> (maybe) execute it
79 $message_to_display = false;
80 if (isset($_REQUEST['submit_sql']) && ! empty($sql_query)) {
81 if (! preg_match('@^SELECT@i', $sql_query)) {
82 $message_to_display = true;
83 } else {
84 $goto = 'db_sql.php';
85 Sql::executeQueryAndSendQueryResponse(
86 null, // analyzed_sql_results
87 false, // is_gotofile
88 $_REQUEST['db'], // db
89 null, // table
90 false, // find_real_end
91 null, // sql_query_for_bookmark
92 null, // extra_data
93 null, // message_to_show
94 null, // message
95 null, // sql_data
96 $goto, // goto
97 $pmaThemeImage, // pmaThemeImage
98 null, // disp_query
99 null, // disp_message
100 null, // query_type
101 $sql_query, // sql_query
102 null, // selectedTables
103 null // complete_query
108 $sub_part = '_qbe';
109 require 'libraries/db_common.inc.php';
110 $url_query .= '&amp;goto=db_qbe.php';
111 $url_params['goto'] = 'db_qbe.php';
113 list(
114 $tables,
115 $num_tables,
116 $total_num_tables,
117 $sub_part,
118 $is_show_stats,
119 $db_is_system_schema,
120 $tooltip_truename,
121 $tooltip_aliasname,
122 $pos
123 ) = PhpMyAdmin\Util::getDbInfo($db, isset($sub_part) ? $sub_part : '');
125 if ($message_to_display) {
126 PhpMyAdmin\Message::error(
127 __('You have to choose at least one column to display!')
129 ->display();
131 unset($message_to_display);
133 // create new qbe search instance
134 $db_qbe = new PhpMyAdmin\DbQbe($GLOBALS['db'], $savedSearchList, $savedSearch);
136 $url = 'db_designer.php' . Url::getCommon(
137 array_merge(
138 $url_params,
139 array('query' => 1)
142 $response->addHTML(
143 PhpMyAdmin\Message::notice(
144 sprintf(
145 __('Switch to %svisual builder%s'),
146 '<a href="' . $url . '">',
147 '</a>'
153 * Displays the Query by example form
155 $response->addHTML($db_qbe->getSelectionForm());