removed unused function
[openemr.git] / phpmyadmin / db_qbe.php
blob842d46b4029c895d88be5cb5f92645f39e586703
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * query by example the whole database
6 * @package PhpMyAdmin
7 */
9 /**
10 * requirements
12 require_once 'libraries/common.inc.php';
13 require_once 'libraries/DBQbe.class.php';
14 require_once 'libraries/bookmark.lib.php';
15 require_once 'libraries/sql.lib.php';
17 $response = PMA_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 include 'libraries/SavedSearches.class.php';
27 $header = $response->getHeader();
28 $scripts = $header->getScripts();
29 $scripts->addFile('db_qbe.js');
31 //Get saved search list.
32 $savedSearch = new PMA_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 PMA_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 PMA_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';
85 // Parse and analyze the query
86 include_once 'libraries/parse_analyze.inc.php';
88 PMA_executeQueryAndSendQueryResponse(
89 $analyzed_sql_results, // analyzed_sql_results
90 false, // is_gotofile
91 $_REQUEST['db'], // db
92 null, // table
93 false, // find_real_end
94 null, // sql_query_for_bookmark
95 null, // extra_data
96 null, // message_to_show
97 null, // message
98 null, // sql_data
99 $goto, // goto
100 $pmaThemeImage, // pmaThemeImage
101 null, // disp_query
102 null, // disp_message
103 null, // query_type
104 $sql_query, // sql_query
105 null, // selectedTables
106 null // complete_query
111 $sub_part = '_qbe';
112 require 'libraries/db_common.inc.php';
113 $url_query .= '&amp;goto=db_qbe.php';
114 $url_params['goto'] = 'db_qbe.php';
116 list(
117 $tables,
118 $num_tables,
119 $total_num_tables,
120 $sub_part,
121 $is_show_stats,
122 $db_is_system_schema,
123 $tooltip_truename,
124 $tooltip_aliasname,
125 $pos
126 ) = PMA_Util::getDbInfo($db, isset($sub_part) ? $sub_part : '');
128 if ($message_to_display) {
129 PMA_Message::error(__('You have to choose at least one column to display!'))
130 ->display();
132 unset($message_to_display);
134 // create new qbe search instance
135 $db_qbe = new PMA_DbQbe($GLOBALS['db'], $savedSearchList, $savedSearch);
137 $url = 'db_designer.php' . PMA_URL_getCommon(
138 array_merge(
139 $url_params,
140 array('query' => 1)
143 $response->addHTML(
144 PMA_Message::notice(
145 sprintf(
146 __('Switch to %svisual builder%s'),
147 '<a href="' . $url . '">',
148 '</a>'
154 * Displays the Query by example form
156 $response->addHTML($db_qbe->getSelectionForm());