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