Translated using Weblate (Hungarian)
[phpmyadmin.git] / querywindow.php
blob5090e3d14dee05b15fce0b3b74385e6957a27132
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * this file is register_globals safe
6 * @todo move JavaScript out of here into .js files
7 * @package PhpMyAdmin
8 */
10 /**
13 require_once 'libraries/common.inc.php';
15 $is_superuser = $GLOBALS['dbi']->isSuperuser();
17 /**
18 * Gets a core script and starts output buffering work
20 require_once 'libraries/sql_query_form.lib.php';
22 /**
23 * load relation params
25 $cfgRelation = PMA_getRelationsParam();
27 /**
28 * load bookmark support
30 require_once 'libraries/bookmark.lib.php';
32 $querydisplay_tabs = array(
33 'sql',
34 'files',
35 'history',
36 'full',
39 if (isset($_REQUEST['querydisplay_tab'])
40 && in_array($_REQUEST['querydisplay_tab'], $querydisplay_tabs)
41 ) {
42 $querydisplay_tab = $_REQUEST['querydisplay_tab'];
43 } else {
44 $querydisplay_tab = $GLOBALS['cfg']['QueryWindowDefTab'];
47 /**
48 * $_REQUEST['no_js'] is set if open new window by JavaScript failed
49 * so this page is loaded in main frame
51 $no_js = PMA_ifSetOr($_REQUEST['no_js'], false);
53 if ($no_js) {
54 $querydisplay_tab = 'full';
55 $tabs = false;
56 } else {
57 $tabs = array();
58 $tabs['sql']['icon'] = 'b_sql.png';
59 $tabs['sql']['text'] = __('SQL');
60 $tabs['sql']['fragment'] = '#';
61 $tabs['sql']['attr'] = 'onclick="PMA_querywindowCommit(\'sql\');return false;"';
62 $tabs['sql']['active'] = (bool) ($querydisplay_tab == 'sql');
63 $tabs['import']['icon'] = 'b_import.png';
64 $tabs['import']['text'] = __('Import files');
65 $tabs['import']['fragment'] = '#';
66 $tabs['import']['attr']
67 = 'onclick="PMA_querywindowCommit(\'files\');return false;"';
68 $tabs['import']['active'] = (bool) ($querydisplay_tab == 'files');
69 $tabs['history']['icon'] = 'b_bookmark.png';
70 $tabs['history']['text'] = __('SQL history');
71 $tabs['history']['fragment'] = '#';
72 $tabs['history']['attr']
73 = 'onclick="PMA_querywindowCommit(\'history\');return false;"';
74 $tabs['history']['active'] = (bool) ($querydisplay_tab == 'history');
76 if ($GLOBALS['cfg']['QueryWindowDefTab'] == 'full') {
77 $tabs['all']['text'] = __('All');
78 $tabs['all']['fragment'] = '#';
79 $tabs['all']['attr']
80 = 'onclick="PMA_querywindowCommit(\'full\');return false;"';
81 $tabs['all']['active'] = (bool) ($querydisplay_tab == 'full');
85 $titles['Change'] = PMA_Util::getIcon('b_edit.png', __('Change'));
86 $url_query = PMA_URL_getCommon($db, $table);
88 if (! empty($sql_query)) {
89 $show_query = 1;
92 if ($no_js) {
93 // ... we redirect to appropriate query sql page
94 // works only full if $db and $table is also stored/grabbed from $_COOKIE
95 if (strlen($table)) {
96 include 'tbl_sql.php';
97 } elseif (strlen($db)) {
98 include 'db_sql.php';
99 } else {
100 include 'server_sql.php';
102 exit;
106 * Defines the query to be displayed in the query textarea
108 if (! empty($show_query)) {
109 $query_to_display = $sql_query;
110 } else if (! empty($_REQUEST['sql_query'])) {
111 $query_to_display = htmlspecialchars($_REQUEST['sql_query']);
112 $show_query = 1;
113 } else {
114 $query_to_display = '';
116 $sql_query = '';
119 * prepare JavaScript functionality
121 $response = PMA_Response::getInstance();
122 $response->getFooter()->setMinimal();
123 $header = $response->getHeader();
124 $header->disableMenu();
125 $header->setBodyId('bodyquerywindow');
126 $scripts = $header->getScripts();
127 $scripts->addFile('common.js');
128 $scripts->addFile('querywindow.js');
130 if (PMA_isValid($_REQUEST['auto_commit'], 'identical', 'true')) {
131 $scripts->addEvent('load', 'PMA_queryAutoCommit');
133 // always set focus to the textarea
134 if ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full') {
135 $scripts->addEvent('load', 'PMA_querywindowSetFocus');
138 echo '<div id="querywindowcontainer">';
140 if ($tabs) {
141 echo PMA_Util::getHtmlTabs($tabs, array(), 'topmenu', true);
142 unset($tabs);
145 echo PMA_getHtmlForSqlQueryForm($query_to_display, $querydisplay_tab);
147 // Hidden forms and query frame interaction stuff
149 $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']);
150 if (! empty($_sql_history)
151 && ($querydisplay_tab == 'history' || $querydisplay_tab == 'full')
153 $tab = $querydisplay_tab != 'full' ? 'sql' : 'full';
154 echo __('SQL history:') . '<br />'
155 . '<ul>';
156 foreach ($_sql_history as $query) {
157 echo '<li>' . "\n";
159 // edit link
160 $url_params = array(
161 'querydisplay_tab' => $tab,
162 'sql_query' => $query['sqlquery'],
163 'db' => $query['db'],
164 'table' => $query['table'],
166 echo '<a href="querywindow.php' . PMA_URL_getCommon($url_params)
167 . '">' . $titles['Change'] . '</a>';
169 // execute link
170 $url_params['auto_commit'] = 'true';
171 echo '<a href="import.php' . PMA_URL_getCommon($url_params) . '"'
172 . ' target="frame_content">';
174 if (! empty($query['db'])) {
175 echo '[';
176 echo htmlspecialchars(PMA_Util::backquote($query['db']));
177 if (! empty($query['table'])) {
178 echo '.' . htmlspecialchars(PMA_Util::backquote($query['table']));
180 echo '] ';
182 if (strlen($query['sqlquery']) > 120) {
183 echo '<span title="' . htmlspecialchars($query['sqlquery']) . '">';
184 echo htmlspecialchars(substr($query['sqlquery'], 0, 50)) . ' [...] ';
185 echo htmlspecialchars(substr($query['sqlquery'], -50));
186 echo '</span>';
187 } else {
188 echo htmlspecialchars($query['sqlquery']);
190 echo '</a>' . "\n";
191 echo '</li>' . "\n";
193 unset($tab, $_sql_history, $query);
194 echo '</ul>' . "\n";
197 echo '<form action="querywindow.php" method="post" name="hiddenqueryform"';
198 echo ' id="hiddenqueryform">';
199 echo PMA_URL_getHiddenInputs('', '');
200 echo '<input type="hidden" name="db" value="' . htmlspecialchars($db) . '" />';
201 echo '<input type="hidden" name="table" value="'
202 . htmlspecialchars($table) . '" />';
203 echo '<input type="hidden" name="sql_query" value="" />';
204 echo '<input type="hidden" name="querydisplay_tab" value="'
205 . $querydisplay_tab . '" />';
206 echo '</form>';
207 echo '</div>';