Merge remote-tracking branch 'origin/master'
[phpmyadmin/madhuracj.git] / querywindow.php
blob2c28373552a4243fd763333b05af380b56d7722b
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 = PMA_isSuperuser();
17 /**
18 * Gets a core script and starts output buffering work
20 require_once './libraries/sql_query_form.lib.php';
22 /**
23 * starts output buffering if requested and supported
25 require_once './libraries/ob.lib.php';
26 PMA_outBufferPre();
28 /**
29 * load relation params
31 $cfgRelation = PMA_getRelationsParam();
33 /**
34 * load bookmark support
36 require_once './libraries/bookmark.lib.php';
38 $querydisplay_tabs = array(
39 'sql',
40 'files',
41 'history',
42 'full',
45 if (isset($_REQUEST['querydisplay_tab'])
46 && in_array($_REQUEST['querydisplay_tab'], $querydisplay_tabs)) {
47 $querydisplay_tab = $_REQUEST['querydisplay_tab'];
48 } else {
49 $querydisplay_tab = $GLOBALS['cfg']['QueryWindowDefTab'];
52 /**
53 * $_REQUEST['no_js'] is set if open new window by JavaScript failed
54 * so this page is loaded in main frame
56 $no_js = PMA_ifSetOr($_REQUEST['no_js'], false);
58 if ($no_js) {
59 $querydisplay_tab = 'full';
60 $tabs = false;
61 } else {
62 $tabs = array();
63 $tabs['sql']['icon'] = 'b_sql.png';
64 $tabs['sql']['text'] = __('SQL');
65 $tabs['sql']['fragment'] = '#';
66 $tabs['sql']['attr'] = 'onclick="PMA_querywindowCommit(\'sql\');return false;"';
67 $tabs['sql']['active'] = (bool) ($querydisplay_tab == 'sql');
68 $tabs['import']['icon'] = 'b_import.png';
69 $tabs['import']['text'] = __('Import files');
70 $tabs['import']['fragment'] = '#';
71 $tabs['import']['attr'] = 'onclick="PMA_querywindowCommit(\'files\');return false;"';
72 $tabs['import']['active'] = (bool) ($querydisplay_tab == 'files');
73 $tabs['history']['icon'] = 'b_bookmark.png';
74 $tabs['history']['text'] = __('SQL history');
75 $tabs['history']['fragment'] = '#';
76 $tabs['history']['attr'] = 'onclick="PMA_querywindowCommit(\'history\');return false;"';
77 $tabs['history']['active'] = (bool) ($querydisplay_tab == 'history');
79 if ($GLOBALS['cfg']['QueryWindowDefTab'] == 'full') {
80 $tabs['all']['text'] = __('All');
81 $tabs['all']['fragment'] = '#';
82 $tabs['all']['attr'] = 'onclick="PMA_querywindowCommit(\'full\');return false;"';
83 $tabs['all']['active'] = (bool) ($querydisplay_tab == 'full');
87 $titles['Change'] = PMA_getIcon('b_edit.png', __('Change'));
88 $url_query = PMA_generate_common_url($db, $table);
90 if (! empty($sql_query)) {
91 $show_query = 1;
94 if ($no_js) {
95 // ... we redirect to appropriate query sql page
96 // works only full if $db and $table is also stored/grabbed from $_COOKIE
97 if (strlen($table)) {
98 include './tbl_sql.php';
99 } elseif (strlen($db)) {
100 include './db_sql.php';
101 } else {
102 include './server_sql.php';
104 exit;
108 * Defines the query to be displayed in the query textarea
110 if (! empty($show_query)) {
111 $query_to_display = $sql_query;
112 } else {
113 $query_to_display = '';
115 $sql_query = '';
118 * prepare JavaScript functionality
120 $js_include[] = 'common.js';
121 $js_include[] = 'querywindow.js';
123 if (PMA_isValid($_REQUEST['auto_commit'], 'identical', 'true')) {
124 $js_events[] = array(
125 'event' => 'load',
126 'function' => 'PMA_queryAutoCommit',
129 if (PMA_isValid($_REQUEST['init'])) {
130 $js_events[] = array(
131 'event' => 'load',
132 'function' => 'PMA_querywindowResize',
135 // always set focus to the textarea
136 if ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full') {
137 $js_events[] = array(
138 'event' => 'load',
139 'function' => 'PMA_querywindowSetFocus',
144 * start HTTP/HTML output
146 require_once './libraries/header_http.inc.php';
147 require_once './libraries/header_meta_style.inc.php';
148 require_once './libraries/header_scripts.inc.php';
150 </head>
152 <body id="bodyquerywindow">
153 <div id="querywindowcontainer">
154 <?php
156 if ($tabs) {
157 echo PMA_generate_html_tabs($tabs, array());
158 unset($tabs);
161 PMA_sqlQueryForm($query_to_display, $querydisplay_tab);
163 // Hidden forms and query frame interaction stuff
165 $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']);
166 if (! empty($_sql_history)
167 && ($querydisplay_tab == 'history' || $querydisplay_tab == 'full')) {
168 $tab = $querydisplay_tab != 'full' ? 'sql' : 'full';
169 echo __('SQL history') . ':<br />'
170 . '<ul>';
171 foreach ($_sql_history as $query) {
172 echo '<li>' . "\n";
174 // edit link
175 $url_params = array(
176 'querydisplay_tab' => $tab,
177 'sql_query' => $query['sqlquery'],
178 'db' => $query['db'],
179 'table' => $query['table'],
181 echo '<a href="querywindow.php' . PMA_generate_common_url($url_params)
182 . '">' . $titles['Change'] . '</a>';
184 // execute link
185 $url_params['auto_commit'] = 'true';
186 echo '<a href="import.php' . PMA_generate_common_url($url_params) . '"'
187 . ' target="frame_content">';
189 if (! empty($query['db'])) {
190 echo '[';
191 echo htmlspecialchars(PMA_backquote($query['db']));
192 if (! empty($query['table'])) {
193 echo '.' . htmlspecialchars(PMA_backquote($query['table']));
195 echo '] ';
197 if (strlen($query['sqlquery']) > 120) {
198 echo '<span title="' . htmlspecialchars($query['sqlquery']) . '">';
199 echo htmlspecialchars(substr($query['sqlquery'], 0, 50)) . ' [...] ';
200 echo htmlspecialchars(substr($query['sqlquery'], -50));
201 echo '</span>';
202 } else {
203 echo htmlspecialchars($query['sqlquery']);
205 echo '</a>' . "\n";
206 echo '</li>' . "\n";
208 unset($tab, $_sql_history, $query);
209 echo '</ul>' . "\n";
212 <form action="querywindow.php" method="post" name="hiddenqueryform"
213 id="hiddenqueryform">
214 <?php echo PMA_generate_common_hidden_inputs('', ''); ?>
215 <input type="hidden" name="db" value="<?php echo htmlspecialchars($db); ?>" />
216 <input type="hidden" name="table" value="<?php echo htmlspecialchars($table); ?>" />
217 <input type="hidden" name="sql_query" value="" />
218 <input type="hidden" name="querydisplay_tab" value="<?php echo $querydisplay_tab; ?>" />
219 </form>
220 </div>
221 </body>
222 </html>