querywindow.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * this file is register_globals safe
  5. *
  6. * @todo move JavaScript out of here into .js files
  7. * @package PhpMyAdmin
  8. */
  9. /**
  10. *
  11. */
  12. require_once 'libraries/common.inc.php';
  13. $is_superuser = $GLOBALS['dbi']->isSuperuser();
  14. /**
  15. * Gets a core script and starts output buffering work
  16. */
  17. require_once 'libraries/sql_query_form.lib.php';
  18. /**
  19. * load relation params
  20. */
  21. $cfgRelation = PMA_getRelationsParam();
  22. /**
  23. * load bookmark support
  24. */
  25. require_once 'libraries/bookmark.lib.php';
  26. $querydisplay_tabs = array(
  27. 'sql',
  28. 'files',
  29. 'history',
  30. 'full',
  31. );
  32. if (isset($_REQUEST['querydisplay_tab'])
  33. && in_array($_REQUEST['querydisplay_tab'], $querydisplay_tabs)
  34. ) {
  35. $querydisplay_tab = $_REQUEST['querydisplay_tab'];
  36. } else {
  37. $querydisplay_tab = $GLOBALS['cfg']['QueryWindowDefTab'];
  38. }
  39. /**
  40. * $_REQUEST['no_js'] is set if open new window by JavaScript failed
  41. * so this page is loaded in main frame
  42. */
  43. $no_js = PMA_ifSetOr($_REQUEST['no_js'], false);
  44. if ($no_js) {
  45. $querydisplay_tab = 'full';
  46. $tabs = false;
  47. } else {
  48. $tabs = array();
  49. $tabs['sql']['icon'] = 'b_sql.png';
  50. $tabs['sql']['text'] = __('SQL');
  51. $tabs['sql']['fragment'] = '#';
  52. $tabs['sql']['attr'] = 'onclick="PMA_querywindowCommit(\'sql\');return false;"';
  53. $tabs['sql']['active'] = (bool) ($querydisplay_tab == 'sql');
  54. $tabs['import']['icon'] = 'b_import.png';
  55. $tabs['import']['text'] = __('Import files');
  56. $tabs['import']['fragment'] = '#';
  57. $tabs['import']['attr']
  58. = 'onclick="PMA_querywindowCommit(\'files\');return false;"';
  59. $tabs['import']['active'] = (bool) ($querydisplay_tab == 'files');
  60. $tabs['history']['icon'] = 'b_bookmark.png';
  61. $tabs['history']['text'] = __('SQL history');
  62. $tabs['history']['fragment'] = '#';
  63. $tabs['history']['attr']
  64. = 'onclick="PMA_querywindowCommit(\'history\');return false;"';
  65. $tabs['history']['active'] = (bool) ($querydisplay_tab == 'history');
  66. if ($GLOBALS['cfg']['QueryWindowDefTab'] == 'full') {
  67. $tabs['all']['text'] = __('All');
  68. $tabs['all']['fragment'] = '#';
  69. $tabs['all']['attr']
  70. = 'onclick="PMA_querywindowCommit(\'full\');return false;"';
  71. $tabs['all']['active'] = (bool) ($querydisplay_tab == 'full');
  72. }
  73. }
  74. $titles['Change'] = PMA_Util::getIcon('b_edit.png', __('Change'));
  75. $url_query = PMA_URL_getCommon($db, $table);
  76. if (! empty($sql_query)) {
  77. $show_query = 1;
  78. }
  79. if ($no_js) {
  80. // ... we redirect to appropriate query sql page
  81. // works only full if $db and $table is also stored/grabbed from $_COOKIE
  82. if (strlen($table)) {
  83. include 'tbl_sql.php';
  84. } elseif (strlen($db)) {
  85. include 'db_sql.php';
  86. } else {
  87. include 'server_sql.php';
  88. }
  89. exit;
  90. }
  91. /**
  92. * Defines the query to be displayed in the query textarea
  93. */
  94. if (! empty($show_query)) {
  95. $query_to_display = $sql_query;
  96. } else if (! empty($_REQUEST['sql_query'])) {
  97. $query_to_display = htmlspecialchars($_REQUEST['sql_query']);
  98. $show_query = 1;
  99. } else {
  100. $query_to_display = '';
  101. }
  102. $sql_query = '';
  103. /**
  104. * prepare JavaScript functionality
  105. */
  106. $response = PMA_Response::getInstance();
  107. $response->getFooter()->setMinimal();
  108. $header = $response->getHeader();
  109. $header->disableMenu();
  110. $header->setBodyId('bodyquerywindow');
  111. $scripts = $header->getScripts();
  112. $scripts->addFile('common.js');
  113. $scripts->addFile('querywindow.js');
  114. if (PMA_isValid($_REQUEST['auto_commit'], 'identical', 'true')) {
  115. $scripts->addEvent('load', 'PMA_queryAutoCommit');
  116. }
  117. // always set focus to the textarea
  118. if ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full') {
  119. $scripts->addEvent('load', 'PMA_querywindowSetFocus');
  120. }
  121. echo '<div id="querywindowcontainer">';
  122. if ($tabs) {
  123. echo PMA_Util::getHtmlTabs($tabs, array(), 'topmenu', true);
  124. unset($tabs);
  125. }
  126. echo PMA_getHtmlForSqlQueryForm($query_to_display, $querydisplay_tab);
  127. // Hidden forms and query frame interaction stuff
  128. $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']);
  129. if (! empty($_sql_history)
  130. && ($querydisplay_tab == 'history' || $querydisplay_tab == 'full')
  131. ) {
  132. $tab = $querydisplay_tab != 'full' ? 'sql' : 'full';
  133. echo __('SQL history:') . '<br />'
  134. . '<ul>';
  135. foreach ($_sql_history as $query) {
  136. echo '<li>' . "\n";
  137. // edit link
  138. $url_params = array(
  139. 'querydisplay_tab' => $tab,
  140. 'sql_query' => $query['sqlquery'],
  141. 'db' => $query['db'],
  142. 'table' => $query['table'],
  143. );
  144. echo '<a href="querywindow.php' . PMA_URL_getCommon($url_params)
  145. . '">' . $titles['Change'] . '</a>';
  146. // execute link
  147. $url_params['auto_commit'] = 'true';
  148. echo '<a href="import.php' . PMA_URL_getCommon($url_params) . '"'
  149. . ' target="frame_content">';
  150. if (! empty($query['db'])) {
  151. echo '[';
  152. echo htmlspecialchars(PMA_Util::backquote($query['db']));
  153. if (! empty($query['table'])) {
  154. echo '.' . htmlspecialchars(PMA_Util::backquote($query['table']));
  155. }
  156. echo '] ';
  157. }
  158. if (strlen($query['sqlquery']) > 120) {
  159. echo '<span title="' . htmlspecialchars($query['sqlquery']) . '">';
  160. echo htmlspecialchars(substr($query['sqlquery'], 0, 50)) . ' [...] ';
  161. echo htmlspecialchars(substr($query['sqlquery'], -50));
  162. echo '</span>';
  163. } else {
  164. echo htmlspecialchars($query['sqlquery']);
  165. }
  166. echo '</a>' . "\n";
  167. echo '</li>' . "\n";
  168. }
  169. unset($tab, $_sql_history, $query);
  170. echo '</ul>' . "\n";
  171. }
  172. echo '<form action="querywindow.php" method="post" name="hiddenqueryform"';
  173. echo ' id="hiddenqueryform">';
  174. echo PMA_URL_getHiddenInputs('', '');
  175. echo '<input type="hidden" name="db" value="' . htmlspecialchars($db) . '" />';
  176. echo '<input type="hidden" name="table" value="'
  177. . htmlspecialchars($table) . '" />';
  178. echo '<input type="hidden" name="sql_query" value="" />';
  179. echo '<input type="hidden" name="querydisplay_tab" value="'
  180. . $querydisplay_tab . '" />';
  181. echo '</form>';
  182. echo '</div>';