More concise descriptions for MySQL column types
[phpmyadmin.git] / querywindow.php
blob2f8a0dc178989ebf4e3dbcfd1d85cb9d542e6bd7
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 ) {
48 $querydisplay_tab = $_REQUEST['querydisplay_tab'];
49 } else {
50 $querydisplay_tab = $GLOBALS['cfg']['QueryWindowDefTab'];
53 /**
54 * $_REQUEST['no_js'] is set if open new window by JavaScript failed
55 * so this page is loaded in main frame
57 $no_js = PMA_ifSetOr($_REQUEST['no_js'], false);
59 if ($no_js) {
60 $querydisplay_tab = 'full';
61 $tabs = false;
62 } else {
63 $tabs = array();
64 $tabs['sql']['icon'] = 'b_sql.png';
65 $tabs['sql']['text'] = __('SQL');
66 $tabs['sql']['fragment'] = '#';
67 $tabs['sql']['attr'] = 'onclick="PMA_querywindowCommit(\'sql\');return false;"';
68 $tabs['sql']['active'] = (bool) ($querydisplay_tab == 'sql');
69 $tabs['import']['icon'] = 'b_import.png';
70 $tabs['import']['text'] = __('Import files');
71 $tabs['import']['fragment'] = '#';
72 $tabs['import']['attr'] = 'onclick="PMA_querywindowCommit(\'files\');return false;"';
73 $tabs['import']['active'] = (bool) ($querydisplay_tab == 'files');
74 $tabs['history']['icon'] = 'b_bookmark.png';
75 $tabs['history']['text'] = __('SQL history');
76 $tabs['history']['fragment'] = '#';
77 $tabs['history']['attr'] = 'onclick="PMA_querywindowCommit(\'history\');return false;"';
78 $tabs['history']['active'] = (bool) ($querydisplay_tab == 'history');
80 if ($GLOBALS['cfg']['QueryWindowDefTab'] == 'full') {
81 $tabs['all']['text'] = __('All');
82 $tabs['all']['fragment'] = '#';
83 $tabs['all']['attr'] = 'onclick="PMA_querywindowCommit(\'full\');return false;"';
84 $tabs['all']['active'] = (bool) ($querydisplay_tab == 'full');
88 $titles['Change'] = PMA_getIcon('b_edit.png', __('Change'));
89 $url_query = PMA_generate_common_url($db, $table);
91 if (! empty($sql_query)) {
92 $show_query = 1;
95 if ($no_js) {
96 // ... we redirect to appropriate query sql page
97 // works only full if $db and $table is also stored/grabbed from $_COOKIE
98 if (strlen($table)) {
99 include 'tbl_sql.php';
100 } elseif (strlen($db)) {
101 include 'db_sql.php';
102 } else {
103 include 'server_sql.php';
105 exit;
109 * Defines the query to be displayed in the query textarea
111 if (! empty($show_query)) {
112 $query_to_display = $sql_query;
113 } else {
114 $query_to_display = '';
116 $sql_query = '';
119 * prepare JavaScript functionality
121 $js_include[] = 'common.js';
122 $js_include[] = 'querywindow.js';
124 if ($GLOBALS['cfg']['CodemirrorEnable']) {
125 $GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js';
126 $GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js';
129 if (PMA_isValid($_REQUEST['auto_commit'], 'identical', 'true')) {
130 $js_events[] = array(
131 'event' => 'load',
132 'function' => 'PMA_queryAutoCommit',
135 if (PMA_isValid($_REQUEST['init'])) {
136 $js_events[] = array(
137 'event' => 'load',
138 'function' => 'PMA_querywindowResize',
141 // always set focus to the textarea
142 if ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full') {
143 $js_events[] = array(
144 'event' => 'load',
145 'function' => 'PMA_querywindowSetFocus',
150 * start HTTP/HTML output
152 require_once 'libraries/header_http.inc.php';
153 require_once 'libraries/header_meta_style.inc.php';
154 require_once 'libraries/header_scripts.inc.php';
156 </head>
158 <body id="bodyquerywindow">
159 <div id="querywindowcontainer">
160 <?php
162 if ($tabs) {
163 echo PMA_generate_html_tabs($tabs, array());
164 unset($tabs);
167 PMA_sqlQueryForm($query_to_display, $querydisplay_tab);
169 // Hidden forms and query frame interaction stuff
171 $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']);
172 if (! empty($_sql_history)
173 && ($querydisplay_tab == 'history' || $querydisplay_tab == 'full')
175 $tab = $querydisplay_tab != 'full' ? 'sql' : 'full';
176 echo __('SQL history') . ':<br />'
177 . '<ul>';
178 foreach ($_sql_history as $query) {
179 echo '<li>' . "\n";
181 // edit link
182 $url_params = array(
183 'querydisplay_tab' => $tab,
184 'sql_query' => $query['sqlquery'],
185 'db' => $query['db'],
186 'table' => $query['table'],
188 echo '<a href="querywindow.php' . PMA_generate_common_url($url_params)
189 . '">' . $titles['Change'] . '</a>';
191 // execute link
192 $url_params['auto_commit'] = 'true';
193 echo '<a href="import.php' . PMA_generate_common_url($url_params) . '"'
194 . ' target="frame_content">';
196 if (! empty($query['db'])) {
197 echo '[';
198 echo htmlspecialchars(PMA_backquote($query['db']));
199 if (! empty($query['table'])) {
200 echo '.' . htmlspecialchars(PMA_backquote($query['table']));
202 echo '] ';
204 if (strlen($query['sqlquery']) > 120) {
205 echo '<span title="' . htmlspecialchars($query['sqlquery']) . '">';
206 echo htmlspecialchars(substr($query['sqlquery'], 0, 50)) . ' [...] ';
207 echo htmlspecialchars(substr($query['sqlquery'], -50));
208 echo '</span>';
209 } else {
210 echo htmlspecialchars($query['sqlquery']);
212 echo '</a>' . "\n";
213 echo '</li>' . "\n";
215 unset($tab, $_sql_history, $query);
216 echo '</ul>' . "\n";
219 <form action="querywindow.php" method="post" name="hiddenqueryform"
220 id="hiddenqueryform">
221 <?php echo PMA_generate_common_hidden_inputs('', ''); ?>
222 <input type="hidden" name="db" value="<?php echo htmlspecialchars($db); ?>" />
223 <input type="hidden" name="table" value="<?php echo htmlspecialchars($table); ?>" />
224 <input type="hidden" name="sql_query" value="" />
225 <input type="hidden" name="querydisplay_tab" value="<?php echo $querydisplay_tab; ?>" />
226 </form>
227 </div>
228 </body>
229 </html>