Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 259 lines (230 sloc) 7.607 kb
dd6345c Display a (javascript) based query window as a new frame below the left
Garvin Hicking authored
1 <?php
03f2245 bug #1664212 querywindow loses url encoded characters
Sebastian Mendel authored
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
f8f4754 @lem9 gettext conversion
lem9 authored
4 * this file is register_globals safe
e8f3519 documentation;
Sebastian Mendel authored
5 *
03f2245 bug #1664212 querywindow loses url encoded characters
Sebastian Mendel authored
6 * @todo move JavaScript out of here into .js files
e8f3519 documentation;
Sebastian Mendel authored
7 * @uses $cfg['QueryWindowDefTab']
8 * @uses $cfg['PropertiesIconic']
9 * @uses $cfg['QueryHistoryDB']
10 * @uses $cfg['Server']['user']
11 * @uses $cfg['AllowUserDropDatabase']
12 * @uses $cfg['Confirm']
13 * @uses $GLOBALS['db']
14 * @uses $GLOBALS['table']
15 * @uses PMA_isSuperuser()
16 * @uses PMA_outBufferPre()
17 * @uses PMA_getRelationsParam()
18 * @uses PMA_isValid()
19 * @uses PMA_ifSetOr()
20 * @uses PMA_getHistory()
21 * @uses PMA_generate_common_url()
22 * @uses PMA_generate_common_hidden_inputs()
23 * @uses PMA_escapeJsString()
8480ffb @lem9 improve function names
lem9 authored
24 * @uses PMA_generate_html_tabs()
e8f3519 documentation;
Sebastian Mendel authored
25 * @uses PMA_sqlQueryForm()
26 * @uses PMA_jsFormat()
27 * @uses in_array()
28 * @uses strlen()
29 * @uses preg_replace()
30 * @uses htmlspecialchars()
56941e5 @nijel Adding @package, second part.
nijel authored
31 * @package phpMyAdmin
03f2245 bug #1664212 querywindow loses url encoded characters
Sebastian Mendel authored
32 */
dd6345c Display a (javascript) based query window as a new frame below the left
Garvin Hicking authored
33
03f2245 bug #1664212 querywindow loses url encoded characters
Sebastian Mendel authored
34 /**
35 *
36 */
d0facc3 splitted common.lib.php into common.inc.php, core.lib.php and common.lib...
Sebastian Mendel authored
37 require_once './libraries/common.inc.php';
dd6345c Display a (javascript) based query window as a new frame below the left
Garvin Hicking authored
38
c8eaea4 @lem9 is_superuser not defined
lem9 authored
39 $is_superuser = PMA_isSuperuser();
40
dd6345c Display a (javascript) based query window as a new frame below the left
Garvin Hicking authored
41 /**
e8f3519 documentation;
Sebastian Mendel authored
42 * Gets a core script and starts output buffering work
dd6345c Display a (javascript) based query window as a new frame below the left
Garvin Hicking authored
43 */
e8f3519 documentation;
Sebastian Mendel authored
44 require_once './libraries/sql_query_form.lib.php';
dd6345c Display a (javascript) based query window as a new frame below the left
Garvin Hicking authored
45
46 /**
e8f3519 documentation;
Sebastian Mendel authored
47 * starts output buffering if requested and supported
dd6345c Display a (javascript) based query window as a new frame below the left
Garvin Hicking authored
48 */
03f2245 bug #1664212 querywindow loses url encoded characters
Sebastian Mendel authored
49 require_once './libraries/ob.lib.php';
e8f3519 documentation;
Sebastian Mendel authored
50 PMA_outBufferPre();
dd6345c Display a (javascript) based query window as a new frame below the left
Garvin Hicking authored
51
e8f3519 documentation;
Sebastian Mendel authored
52 /**
ee767e2 @nijel No need to explicitely include relation.lib its anyway included in commo...
nijel authored
53 * load relation params
e8f3519 documentation;
Sebastian Mendel authored
54 */
dd6345c Display a (javascript) based query window as a new frame below the left
Garvin Hicking authored
55 $cfgRelation = PMA_getRelationsParam();
56
e8f3519 documentation;
Sebastian Mendel authored
57 /**
58 * load bookmark support
59 */
60 require_once './libraries/bookmark.lib.php';
071a068 wrong handling of linebreaks in query: bug #1243888
Sebastian Mendel authored
61
e8f3519 documentation;
Sebastian Mendel authored
62 $querydisplay_tabs = array(
63 'sql',
64 'files',
65 'history',
66 'full',
67 );
8fc4a4c moved styles into css
Sebastian Mendel authored
68
e8f3519 documentation;
Sebastian Mendel authored
69 if (isset($_REQUEST['querydisplay_tab'])
70 && in_array($_REQUEST['querydisplay_tab'], $querydisplay_tabs)) {
71 $querydisplay_tab = $_REQUEST['querydisplay_tab'];
3143135 XHTML 1.0 trans. compliance and more semantic XHTML output
Sebastian Mendel authored
72 } else {
e8f3519 documentation;
Sebastian Mendel authored
73 $querydisplay_tab = $GLOBALS['cfg']['QueryWindowDefTab'];
64bd56d @nijel Support for browsing selected columns (RFE #1275909).
nijel authored
74 }
dd6345c Display a (javascript) based query window as a new frame below the left
Garvin Hicking authored
75
e8f3519 documentation;
Sebastian Mendel authored
76 /**
77 * $_REQUEST['no_js'] is set if open new window by JavaScript failed
78 * so this page is loaded in main frame
79 */
80 $no_js = PMA_ifSetOr($_REQUEST['no_js'], false);
37d50c1 @derrabus Huge set of optimizations, please test!
derrabus authored
81
e8f3519 documentation;
Sebastian Mendel authored
82 if ($no_js) {
83 $querydisplay_tab = 'full';
84 $tabs = false;
85 } else {
5de17e7 @lem9 patch #1252031, CSS for navigation tabs
lem9 authored
86 $tabs = array();
87 $tabs['sql']['icon'] = 'b_sql.png';
f8f4754 @lem9 gettext conversion
lem9 authored
88 $tabs['sql']['text'] = __('SQL');
e8f3519 documentation;
Sebastian Mendel authored
89 $tabs['sql']['fragment'] = '#';
90 $tabs['sql']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'sql\');return false;"';
03f2245 bug #1664212 querywindow loses url encoded characters
Sebastian Mendel authored
91 $tabs['sql']['active'] = (bool) ($querydisplay_tab == 'sql');
5de17e7 @lem9 patch #1252031, CSS for navigation tabs
lem9 authored
92 $tabs['import']['icon'] = 'b_import.png';
f8f4754 @lem9 gettext conversion
lem9 authored
93 $tabs['import']['text'] = __('Import files');
e8f3519 documentation;
Sebastian Mendel authored
94 $tabs['import']['fragment'] = '#';
95 $tabs['import']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'files\');return false;"';
03f2245 bug #1664212 querywindow loses url encoded characters
Sebastian Mendel authored
96 $tabs['import']['active'] = (bool) ($querydisplay_tab == 'files');
0be9c38 @nijel Make drop and empty tabs lead to structure instead of SQL.
nijel authored
97 $tabs['history']['icon'] = 'b_bookmark.png';
f8f4754 @lem9 gettext conversion
lem9 authored
98 $tabs['history']['text'] = __('SQL history');
e8f3519 documentation;
Sebastian Mendel authored
99 $tabs['history']['fragment'] = '#';
100 $tabs['history']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'history\');return false;"';
03f2245 bug #1664212 querywindow loses url encoded characters
Sebastian Mendel authored
101 $tabs['history']['active'] = (bool) ($querydisplay_tab == 'history');
4d878ae See Changelog: Lightweight tabs, DB-based SQL history, tabbed querywindo...
Garvin Hicking authored
102
03f2245 bug #1664212 querywindow loses url encoded characters
Sebastian Mendel authored
103 if ($GLOBALS['cfg']['QueryWindowDefTab'] == 'full') {
f8f4754 @lem9 gettext conversion
lem9 authored
104 $tabs['all']['text'] = __('All');
e8f3519 documentation;
Sebastian Mendel authored
105 $tabs['all']['fragment'] = '#';
106 $tabs['all']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'full\');return false;"';
03f2245 bug #1664212 querywindow loses url encoded characters
Sebastian Mendel authored
107 $tabs['all']['active'] = (bool) ($querydisplay_tab == 'full');
210576b Fixed Bug #723955, 723736, 723713 (Query Frame)
Garvin Hicking authored
108 }
4d878ae See Changelog: Lightweight tabs, DB-based SQL history, tabbed querywindo...
Garvin Hicking authored
109 }
110
e8f3519 documentation;
Sebastian Mendel authored
111 if ($GLOBALS['cfg']['PropertiesIconic']) {
8fc4a4c moved styles into css
Sebastian Mendel authored
112 $titles['Change'] =
071a068 wrong handling of linebreaks in query: bug #1243888
Sebastian Mendel authored
113 '<img class="icon" width="16" height="16" src="' . $pmaThemeImage
f8f4754 @lem9 gettext conversion
lem9 authored
114 . 'b_edit.png" alt="' . __('Change') . '" title="' . __('Change')
071a068 wrong handling of linebreaks in query: bug #1243888
Sebastian Mendel authored
115 . '" />';
a199e51 @lem9 clarification
lem9 authored
116
03f2245 bug #1664212 querywindow loses url encoded characters
Sebastian Mendel authored
117 if ('both' === $GLOBALS['cfg']['PropertiesIconic']) {
3e3f5f6 @lem9 Link is too near the rest of the text
lem9 authored
118 $titles['Change'] .= __('Change') . ' ';
a199e51 @lem9 clarification
lem9 authored
119 }
120 } else {
3e3f5f6 @lem9 Link is too near the rest of the text
lem9 authored
121 $titles['Change'] = __('Change') . ' ';
a199e51 @lem9 clarification
lem9 authored
122 }
123
e8f3519 documentation;
Sebastian Mendel authored
124 $url_query = PMA_generate_common_url($db, $table);
dd6345c Display a (javascript) based query window as a new frame below the left
Garvin Hicking authored
125
b2f3ae5 make $sql_query persistent (init it, never unset it, always assume it is...
Sebastian Mendel authored
126 if (! empty($sql_query)) {
e8f3519 documentation;
Sebastian Mendel authored
127 $show_query = 1;
dd6345c Display a (javascript) based query window as a new frame below the left
Garvin Hicking authored
128 }
129
e8f3519 documentation;
Sebastian Mendel authored
130 if ($no_js) {
b874154 moved all code for queryboxes into libraries/sql_query_form.lib.php, rep...
Sebastian Mendel authored
131 // ... we redirect to appropriate query sql page
132 // works only full if $db and $table is also stored/grabbed from $_COOKIE
e8f3519 documentation;
Sebastian Mendel authored
133 if (strlen($table)) {
ad06b4a @nijel Rename tbl_* files to drop useless _properties part.
nijel authored
134 require './tbl_sql.php';
e8f3519 documentation;
Sebastian Mendel authored
135 } elseif (strlen($db)) {
cac4247 @nijel Rename db_* files to drop useless _details part.
nijel authored
136 require './db_sql.php';
7358f5a allow 0 as name for database, table collumn, alias and index
Sebastian Mendel authored
137 } else {
7ae4646 @nijel Fix including of files when search path does not contain current directo...
nijel authored
138 require './server_sql.php';
b874154 moved all code for queryboxes into libraries/sql_query_form.lib.php, rep...
Sebastian Mendel authored
139 }
140 exit;
141 }
142
143 /**
144 * Defines the query to be displayed in the query textarea
145 */
03f2245 bug #1664212 querywindow loses url encoded characters
Sebastian Mendel authored
146 if (! empty($show_query)) {
b874154 moved all code for queryboxes into libraries/sql_query_form.lib.php, rep...
Sebastian Mendel authored
147 $query_to_display = $sql_query;
148 } else {
149 $query_to_display = '';
150 }
b2f3ae5 make $sql_query persistent (init it, never unset it, always assume it is...
Sebastian Mendel authored
151 $sql_query = '';
b874154 moved all code for queryboxes into libraries/sql_query_form.lib.php, rep...
Sebastian Mendel authored
152
e8f3519 documentation;
Sebastian Mendel authored
153 /**
98c8a77 refactored JavaScript handling
Sebastian Mendel authored
154 * prepare JavaScript functionality
e8f3519 documentation;
Sebastian Mendel authored
155 */
98c8a77 refactored JavaScript handling
Sebastian Mendel authored
156 $js_include[] = 'common.js';
157 $js_include[] = 'querywindow.js';
e8f3519 documentation;
Sebastian Mendel authored
158
159 if (PMA_isValid($_REQUEST['auto_commit'], 'identical', 'true')) {
98c8a77 refactored JavaScript handling
Sebastian Mendel authored
160 $js_events[] = array(
161 'event' => 'load',
162 'function' => 'PMA_queryAutoCommit',
163 );
e8f3519 documentation;
Sebastian Mendel authored
164 }
165 if (PMA_isValid($_REQUEST['init'])) {
98c8a77 refactored JavaScript handling
Sebastian Mendel authored
166 $js_events[] = array(
167 'event' => 'load',
168 'function' => 'PMA_querywindowResize',
169 );
e8f3519 documentation;
Sebastian Mendel authored
170 }
ad8dc8e @lem9 bug #1805102, TextareaAutoSelect issues
lem9 authored
171 // always set focus to the textarea
7bb8edd @lem9 patch #1837691 [query window] js errors, thanks to Victor Volkov
lem9 authored
172 if ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full') {
173 $js_events[] = array(
174 'event' => 'load',
175 'function' => 'PMA_querywindowSetFocus',
176 );
177 }
e8f3519 documentation;
Sebastian Mendel authored
178
98c8a77 refactored JavaScript handling
Sebastian Mendel authored
179 /**
180 * start HTTP/HTML output
181 */
182 require_once './libraries/header_http.inc.php';
183 require_once './libraries/header_meta_style.inc.php';
184 require_once './libraries/header_scripts.inc.php';
185 ?>
e8f3519 documentation;
Sebastian Mendel authored
186 </head>
187
98c8a77 refactored JavaScript handling
Sebastian Mendel authored
188 <body id="bodyquerywindow">
e8f3519 documentation;
Sebastian Mendel authored
189 <div id="querywindowcontainer">
9889178 @lem9 new query window behavior
lem9 authored
190 <?php
e8f3519 documentation;
Sebastian Mendel authored
191
192 if ($tabs) {
8480ffb @lem9 improve function names
lem9 authored
193 echo PMA_generate_html_tabs($tabs, array());
e8f3519 documentation;
Sebastian Mendel authored
194 unset($tabs);
9889178 @lem9 new query window behavior
lem9 authored
195 }
37d50c1 @derrabus Huge set of optimizations, please test!
derrabus authored
196
e8f3519 documentation;
Sebastian Mendel authored
197 PMA_sqlQueryForm($query_to_display, $querydisplay_tab);
198
199 // Hidden forms and query frame interaction stuff
200
201 $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']);
202 if (! empty($_sql_history)
203 && ($querydisplay_tab == 'history' || $querydisplay_tab == 'full')) {
204 $tab = $querydisplay_tab != 'full' ? 'sql' : 'full';
f8f4754 @lem9 gettext conversion
lem9 authored
205 echo __('SQL history') . ':<br />'
206 . '<ul>';
e8f3519 documentation;
Sebastian Mendel authored
207 foreach ($_sql_history as $query) {
9889178 @lem9 new query window behavior
lem9 authored
208 echo '<li>' . "\n";
d27b8ef removed unnecessary JavaScript code (due to session based history)
Sebastian Mendel authored
209
9889178 @lem9 new query window behavior
lem9 authored
210 // edit link
d27b8ef removed unnecessary JavaScript code (due to session based history)
Sebastian Mendel authored
211 $url_params = array(
212 'querydisplay_tab' => $tab,
213 'sql_query' => $query['sqlquery'],
214 'db' => $query['db'],
215 'table' => $query['table'],
216 );
217 echo '<a href="querywindow.php' . PMA_generate_common_url($url_params)
218 . '">' . $titles['Change'] . '</a>';
219
e8f3519 documentation;
Sebastian Mendel authored
220 // execute link
d27b8ef removed unnecessary JavaScript code (due to session based history)
Sebastian Mendel authored
221 $url_params['auto_commit'] = 'true';
222 echo '<a href="import.php' . PMA_generate_common_url($url_params) . '"'
223 . ' target="frame_content">';
224
e8f3519 documentation;
Sebastian Mendel authored
225 if (! empty($query['db'])) {
226 echo '[';
227 echo htmlspecialchars(PMA_backquote($query['db']));
228 if (! empty($query['table'])) {
229 echo '.' . htmlspecialchars(PMA_backquote($query['table']));
230 }
231 echo '] ';
232 }
233 if (strlen($query['sqlquery']) > 120) {
234 echo '<span title="' . htmlspecialchars($query['sqlquery']) . '">';
235 echo htmlspecialchars(substr($query['sqlquery'], 0, 50)) . ' [...] ';
236 echo htmlspecialchars(substr($query['sqlquery'], -50));
237 echo '</span>';
238 } else {
239 echo htmlspecialchars($query['sqlquery']);
240 }
241 echo '</a>' . "\n";
9889178 @lem9 new query window behavior
lem9 authored
242 echo '</li>' . "\n";
dd6345c Display a (javascript) based query window as a new frame below the left
Garvin Hicking authored
243 }
e8f3519 documentation;
Sebastian Mendel authored
244 unset($tab, $_sql_history, $query);
9889178 @lem9 new query window behavior
lem9 authored
245 echo '</ul>' . "\n";
246 }
247 ?>
e8f3519 documentation;
Sebastian Mendel authored
248 <form action="querywindow.php" method="post" name="hiddenqueryform"
249 id="hiddenqueryform">
250 <?php echo PMA_generate_common_hidden_inputs('', ''); ?>
251 <input type="hidden" name="db" value="<?php echo htmlspecialchars($db); ?>" />
252 <input type="hidden" name="table" value="<?php echo htmlspecialchars($table); ?>" />
d27b8ef removed unnecessary JavaScript code (due to session based history)
Sebastian Mendel authored
253 <input type="hidden" name="sql_query" value="" />
4d878ae See Changelog: Lightweight tabs, DB-based SQL history, tabbed querywindo...
Garvin Hicking authored
254 <input type="hidden" name="querydisplay_tab" value="<?php echo $querydisplay_tab; ?>" />
dd6345c Display a (javascript) based query window as a new frame below the left
Garvin Hicking authored
255 </form>
64bd56d @nijel Support for browsing selected columns (RFE #1275909).
nijel authored
256 </div>
dd6345c Display a (javascript) based query window as a new frame below the left
Garvin Hicking authored
257 </body>
258 </html>
Something went wrong with that request. Please try again.