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