Translation update done using Pootle.
[phpmyadmin/dkf.git] / querywindow.php
blob0d15de5f7445b0b3c100eac946c020c1ae51fc6d
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 * @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 __('SQL')
16 * @uses __('Import files')
17 * @uses __('SQL history')
18 * @uses __('All')
19 * @uses __('Change')
20 * @uses __('Missing value in the form!')
21 * @uses __('This is not a number!')
22 * @uses __('"DROP DATABASE" statements are disabled.')
23 * @uses __('Do you really want to ')
24 * @uses PMA_isSuperuser()
25 * @uses PMA_outBufferPre()
26 * @uses PMA_getRelationsParam()
27 * @uses PMA_isValid()
28 * @uses PMA_ifSetOr()
29 * @uses PMA_getHistory()
30 * @uses PMA_generate_common_url()
31 * @uses PMA_generate_common_hidden_inputs()
32 * @uses PMA_escapeJsString()
33 * @uses PMA_generate_html_tabs()
34 * @uses PMA_sqlQueryForm()
35 * @uses PMA_jsFormat()
36 * @uses in_array()
37 * @uses strlen()
38 * @uses preg_replace()
39 * @uses htmlspecialchars()
40 * @version $Id$
41 * @package phpMyAdmin
44 /**
47 require_once './libraries/common.inc.php';
49 $is_superuser = PMA_isSuperuser();
51 /**
52 * Gets a core script and starts output buffering work
54 require_once './libraries/sql_query_form.lib.php';
56 /**
57 * starts output buffering if requested and supported
59 require_once './libraries/ob.lib.php';
60 PMA_outBufferPre();
62 /**
63 * load relations
65 require_once './libraries/relation.lib.php';
66 $cfgRelation = PMA_getRelationsParam();
68 /**
69 * load bookmark support
71 require_once './libraries/bookmark.lib.php';
73 $querydisplay_tabs = array(
74 'sql',
75 'files',
76 'history',
77 'full',
80 if (isset($_REQUEST['querydisplay_tab'])
81 && in_array($_REQUEST['querydisplay_tab'], $querydisplay_tabs)) {
82 $querydisplay_tab = $_REQUEST['querydisplay_tab'];
83 } else {
84 $querydisplay_tab = $GLOBALS['cfg']['QueryWindowDefTab'];
87 /**
88 * $_REQUEST['no_js'] is set if open new window by JavaScript failed
89 * so this page is loaded in main frame
91 $no_js = PMA_ifSetOr($_REQUEST['no_js'], false);
93 if ($no_js) {
94 $querydisplay_tab = 'full';
95 $tabs = false;
96 } else {
97 $tabs = array();
98 $tabs['sql']['icon'] = 'b_sql.png';
99 $tabs['sql']['text'] = __('SQL');
100 $tabs['sql']['fragment'] = '#';
101 $tabs['sql']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'sql\');return false;"';
102 $tabs['sql']['active'] = (bool) ($querydisplay_tab == 'sql');
103 $tabs['import']['icon'] = 'b_import.png';
104 $tabs['import']['text'] = __('Import files');
105 $tabs['import']['fragment'] = '#';
106 $tabs['import']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'files\');return false;"';
107 $tabs['import']['active'] = (bool) ($querydisplay_tab == 'files');
108 $tabs['history']['icon'] = 'b_bookmark.png';
109 $tabs['history']['text'] = __('SQL history');
110 $tabs['history']['fragment'] = '#';
111 $tabs['history']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'history\');return false;"';
112 $tabs['history']['active'] = (bool) ($querydisplay_tab == 'history');
114 if ($GLOBALS['cfg']['QueryWindowDefTab'] == 'full') {
115 $tabs['all']['text'] = __('All');
116 $tabs['all']['fragment'] = '#';
117 $tabs['all']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'full\');return false;"';
118 $tabs['all']['active'] = (bool) ($querydisplay_tab == 'full');
122 if ($GLOBALS['cfg']['PropertiesIconic']) {
123 $titles['Change'] =
124 '<img class="icon" width="16" height="16" src="' . $pmaThemeImage
125 . 'b_edit.png" alt="' . __('Change') . '" title="' . __('Change')
126 . '" />';
128 if ('both' === $GLOBALS['cfg']['PropertiesIconic']) {
129 $titles['Change'] .= __('Change');
131 } else {
132 $titles['Change'] = __('Change');
135 $url_query = PMA_generate_common_url($db, $table);
137 if (! empty($sql_query)) {
138 $show_query = 1;
141 if ($no_js) {
142 // ... we redirect to appropriate query sql page
143 // works only full if $db and $table is also stored/grabbed from $_COOKIE
144 if (strlen($table)) {
145 require './tbl_sql.php';
146 } elseif (strlen($db)) {
147 require './db_sql.php';
148 } else {
149 require './server_sql.php';
151 exit;
155 * Defines the query to be displayed in the query textarea
157 if (! empty($show_query)) {
158 $query_to_display = $sql_query;
159 } else {
160 $query_to_display = '';
162 $sql_query = '';
165 * prepare JavaScript functionality
167 $js_include[] = 'common.js';
168 $js_include[] = 'functions.js';
169 $js_include[] = 'querywindow.js';
171 if (PMA_isValid($_REQUEST['auto_commit'], 'identical', 'true')) {
172 $js_events[] = array(
173 'event' => 'load',
174 'function' => 'PMA_queryAutoCommit',
177 if (PMA_isValid($_REQUEST['init'])) {
178 $js_events[] = array(
179 'event' => 'load',
180 'function' => 'PMA_querywindowResize',
183 // always set focus to the textarea
184 if ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full') {
185 $js_events[] = array(
186 'event' => 'load',
187 'function' => 'PMA_querywindowSetFocus',
192 * start HTTP/HTML output
194 require_once './libraries/header_http.inc.php';
195 require_once './libraries/header_meta_style.inc.php';
196 require_once './libraries/header_scripts.inc.php';
198 </head>
200 <body id="bodyquerywindow">
201 <div id="querywindowcontainer">
202 <?php
204 if ($tabs) {
205 echo PMA_generate_html_tabs($tabs, array());
206 unset($tabs);
209 PMA_sqlQueryForm($query_to_display, $querydisplay_tab);
211 // Hidden forms and query frame interaction stuff
213 $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']);
214 if (! empty($_sql_history)
215 && ($querydisplay_tab == 'history' || $querydisplay_tab == 'full')) {
216 $tab = $querydisplay_tab != 'full' ? 'sql' : 'full';
217 echo __('SQL history') . ':<br />'
218 . '<ul>';
219 foreach ($_sql_history as $query) {
220 echo '<li>' . "\n";
222 // edit link
223 $url_params = array(
224 'querydisplay_tab' => $tab,
225 'sql_query' => $query['sqlquery'],
226 'db' => $query['db'],
227 'table' => $query['table'],
229 echo '<a href="querywindow.php' . PMA_generate_common_url($url_params)
230 . '">' . $titles['Change'] . '</a>';
232 // execute link
233 $url_params['auto_commit'] = 'true';
234 echo '<a href="import.php' . PMA_generate_common_url($url_params) . '"'
235 . ' target="frame_content">';
237 if (! empty($query['db'])) {
238 echo '[';
239 echo htmlspecialchars(PMA_backquote($query['db']));
240 if (! empty($query['table'])) {
241 echo '.' . htmlspecialchars(PMA_backquote($query['table']));
243 echo '] ';
245 if (strlen($query['sqlquery']) > 120) {
246 echo '<span title="' . htmlspecialchars($query['sqlquery']) . '">';
247 echo htmlspecialchars(substr($query['sqlquery'], 0, 50)) . ' [...] ';
248 echo htmlspecialchars(substr($query['sqlquery'], -50));
249 echo '</span>';
250 } else {
251 echo htmlspecialchars($query['sqlquery']);
253 echo '</a>' . "\n";
254 echo '</li>' . "\n";
256 unset($tab, $_sql_history, $query);
257 echo '</ul>' . "\n";
260 <form action="querywindow.php" method="post" name="hiddenqueryform"
261 id="hiddenqueryform">
262 <?php echo PMA_generate_common_hidden_inputs('', ''); ?>
263 <input type="hidden" name="db" value="<?php echo htmlspecialchars($db); ?>" />
264 <input type="hidden" name="table" value="<?php echo htmlspecialchars($table); ?>" />
265 <input type="hidden" name="sql_query" value="" />
266 <input type="hidden" name="querydisplay_tab" value="<?php echo $querydisplay_tab; ?>" />
267 </form>
268 </div>
269 </body>
270 </html>