language translation smarty function global fix
[openemr.git] / phpmyadmin / querywindow.php
blob17e5d5cf8e0bdb88866d075ee210c92fb97aa260
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * this file is register_globals save
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 $GLOBALS['strSQL']
16 * @uses $GLOBALS['strImportFiles']
17 * @uses $GLOBALS['strQuerySQLHistory']
18 * @uses $GLOBALS['strAll']
19 * @uses $GLOBALS['strChange']
20 * @uses $GLOBALS['strFormEmpty']
21 * @uses $GLOBALS['strNotNumber']
22 * @uses $GLOBALS['strNoDropDatabases']
23 * @uses $GLOBALS['strDoYouReally']
24 * @uses $GLOBALS['strQuerySQLHistory']
25 * @uses PMA_isSuperuser()
26 * @uses PMA_outBufferPre()
27 * @uses PMA_getRelationsParam()
28 * @uses PMA_isValid()
29 * @uses PMA_ifSetOr()
30 * @uses PMA_getHistory()
31 * @uses PMA_generate_common_url()
32 * @uses PMA_generate_common_hidden_inputs()
33 * @uses PMA_escapeJsString()
34 * @uses PMA_getTabs()
35 * @uses PMA_sqlQueryForm()
36 * @uses PMA_jsFormat()
37 * @uses in_array()
38 * @uses strlen()
39 * @uses preg_replace()
40 * @uses htmlspecialchars()
41 * @version $Id$
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'] = $GLOBALS['strSQL'];
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'] = $GLOBALS['strImportFiles'];
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'] = $GLOBALS['strQuerySQLHistory'];
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'] = $GLOBALS['strAll'];
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="' . $GLOBALS['strChange'] . '" title="' . $GLOBALS['strChange']
126 . '" />';
128 if ('both' === $GLOBALS['cfg']['PropertiesIconic']) {
129 $titles['Change'] .= $GLOBALS['strChange'];
131 } else {
132 $titles['Change'] = $GLOBALS['strChange'];
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 * start HTML output
167 require_once './libraries/header_http.inc.php';
168 require_once './libraries/header_meta_style.inc.php';
170 <script type="text/javascript">
171 //<![CDATA[
172 var errorMsg0 = '<?php echo PMA_escapeJsString($GLOBALS['strFormEmpty']); ?>';
173 var errorMsg1 = '<?php echo PMA_escapeJsString($GLOBALS['strNotNumber']); ?>';
174 var noDropDbMsg = '<?php echo (!$is_superuser && !$GLOBALS['cfg']['AllowUserDropDatabase'])
175 ? PMA_escapeJsString($GLOBALS['strNoDropDatabases']) : ''; ?>';
176 var confirmMsg = '<?php echo $GLOBALS['cfg']['Confirm']
177 ? PMA_escapeJsString($GLOBALS['strDoYouReally']) : ''; ?>';
179 function PMA_queryAutoCommit() {
180 document.getElementById('sqlqueryform').target = window.opener.frame_content.name;
181 document.getElementById('sqlqueryform').submit();
182 return;
185 function PMA_querywindowCommit(tab) {
186 document.getElementById('hiddenqueryform').querydisplay_tab.value = tab;
187 document.getElementById('hiddenqueryform').submit();
188 return false;
191 function PMA_querywindowResize() {
192 // for Gecko
193 if (typeof(self.sizeToContent) == 'function') {
194 self.sizeToContent();
195 //self.scrollbars.visible = false;
196 // give some more space ... to prevent 'fli(pp/ck)ing'
197 self.resizeBy(10, 50);
198 return;
201 // for IE, Opera
202 if (document.getElementById && typeof(document.getElementById('querywindowcontainer')) != 'undefined') {
204 // get content size
205 var newWidth = document.getElementById('querywindowcontainer').offsetWidth;
206 var newHeight = document.getElementById('querywindowcontainer').offsetHeight;
208 // set size to contentsize
209 // plus some offset for scrollbars, borders, statusbar, menus ...
210 self.resizeTo(newWidth + 45, newHeight + 75);
214 function PMA_querywindowInit()
216 <?php
217 if (PMA_isValid($_REQUEST['auto_commit'], 'identical', 'true')) {
218 echo 'PMA_queryAutoCommit();' . "\n";
220 if (PMA_isValid($_REQUEST['init'])) {
221 echo 'PMA_querywindowResize();' . "\n";
223 if ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full') {
224 echo "document.getElementById('sqlquery').focus();" . "\n";
229 //]]>
230 </script>
231 <script src="./js/functions.js" type="text/javascript"></script>
232 </head>
234 <body id="bodyquerywindow" onload="PMA_querywindowInit();">
235 <div id="querywindowcontainer">
236 <?php
238 if ($tabs) {
239 echo PMA_getTabs($tabs);
240 unset($tabs);
243 PMA_sqlQueryForm($query_to_display, $querydisplay_tab);
245 // Hidden forms and query frame interaction stuff
247 $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']);
248 if (! empty($_sql_history)
249 && ($querydisplay_tab == 'history' || $querydisplay_tab == 'full')) {
250 $tab = $querydisplay_tab != 'full' ? 'sql' : 'full';
251 echo $GLOBALS['strQuerySQLHistory'] . ':<br />' . "\n"
252 .'<ul>';
253 foreach ($_sql_history as $query) {
254 echo '<li>' . "\n";
256 // edit link
257 $url_params = array(
258 'querydisplay_tab' => $tab,
259 'sql_query' => $query['sqlquery'],
260 'db' => $query['db'],
261 'table' => $query['table'],
263 echo '<a href="querywindow.php' . PMA_generate_common_url($url_params)
264 . '">' . $titles['Change'] . '</a>';
266 // execute link
267 $url_params['auto_commit'] = 'true';
268 echo '<a href="import.php' . PMA_generate_common_url($url_params) . '"'
269 . ' target="frame_content">';
271 if (! empty($query['db'])) {
272 echo '[';
273 echo htmlspecialchars(PMA_backquote($query['db']));
274 if (! empty($query['table'])) {
275 echo '.' . htmlspecialchars(PMA_backquote($query['table']));
277 echo '] ';
279 if (strlen($query['sqlquery']) > 120) {
280 echo '<span title="' . htmlspecialchars($query['sqlquery']) . '">';
281 echo htmlspecialchars(substr($query['sqlquery'], 0, 50)) . ' [...] ';
282 echo htmlspecialchars(substr($query['sqlquery'], -50));
283 echo '</span>';
284 } else {
285 echo htmlspecialchars($query['sqlquery']);
287 echo '</a>' . "\n";
288 echo '</li>' . "\n";
290 unset($tab, $_sql_history, $query);
291 echo '</ul>' . "\n";
294 <form action="querywindow.php" method="post" name="hiddenqueryform"
295 id="hiddenqueryform">
296 <?php echo PMA_generate_common_hidden_inputs('', ''); ?>
297 <input type="hidden" name="db" value="<?php echo htmlspecialchars($db); ?>" />
298 <input type="hidden" name="table" value="<?php echo htmlspecialchars($table); ?>" />
299 <input type="hidden" name="sql_query" value="" />
300 <input type="hidden" name="querydisplay_tab" value="<?php echo $querydisplay_tab; ?>" />
301 </form>
302 </div>
303 </body>
304 </html>
306 <?php
308 * Close MySql connections
310 if (! empty($controllink)) {
311 PMA_DBI_close($controllink);
313 if (! empty($userlink)) {
314 PMA_DBI_close($userlink);