2 /* vim: set expandtab sw=4 ts=4 sts=4: */
6 * @todo we must handle the case if sql.php is called directly with a query
7 * that returns 0 rows - to prevent cyclic redirects or includes
10 use PMA\libraries\config\PageSettings
;
11 use PMA\libraries\Response
;
12 use PMA\libraries\Util
;
13 use PMA\libraries\URL
;
16 * Gets some core libraries
18 require_once 'libraries/common.inc.php';
19 require_once 'libraries/check_user_privileges.lib.php';
20 require_once 'libraries/sql.lib.php';
21 require_once 'libraries/config/user_preferences.forms.php';
22 require_once 'libraries/config/page_settings.forms.php';
24 PageSettings
::showGroup('Browse');
27 $response = Response
::getInstance();
28 $header = $response->getHeader();
29 $scripts = $header->getScripts();
30 $scripts->addFile('jquery/jquery-ui-timepicker-addon.js');
31 $scripts->addFile('jquery/jquery.uitablefilter.js');
32 $scripts->addFile('tbl_change.js');
33 $scripts->addFile('indexes.js');
34 $scripts->addFile('gis_data_editor.js');
35 $scripts->addFile('multi_column_sort.js');
38 * Set ajax_reload in the response if it was already set
40 if (isset($ajax_reload) && $ajax_reload['reload'] === true) {
41 $response->addJSON('ajax_reload', $ajax_reload);
46 * Defines the url to return to in case of error in a sql statement
51 $goto = Util
::getScriptNameForOption(
52 $GLOBALS['cfg']['DefaultTabDatabase'], 'database'
55 $goto = Util
::getScriptNameForOption(
56 $GLOBALS['cfg']['DefaultTabTable'], 'table'
61 if (! isset($err_url)) {
62 $err_url = (! empty($back) ?
$back : $goto)
63 . '?' . URL
::getCommon(array('db' => $GLOBALS['db']))
64 . ((mb_strpos(' ' . $goto, 'db_') != 1
66 ?
'&table=' . urlencode($table)
71 // Coming from a bookmark dialog
72 if (isset($_POST['bkm_fields']['bkm_sql_query'])) {
73 $sql_query = $_POST['bkm_fields']['bkm_sql_query'];
74 } elseif (isset($_GET['sql_query'])) {
75 $sql_query = $_GET['sql_query'];
78 // This one is just to fill $db
79 if (isset($_POST['bkm_fields']['bkm_database'])) {
80 $db = $_POST['bkm_fields']['bkm_database'];
84 // During grid edit, if we have a relational field, show the dropdown for it.
85 if (isset($_REQUEST['get_relational_values'])
86 && $_REQUEST['get_relational_values'] == true
88 PMA_getRelationalValues($db, $table);
89 // script has exited at this point
92 // Just like above, find possible values for enum fields during grid edit.
93 if (isset($_REQUEST['get_enum_values']) && $_REQUEST['get_enum_values'] == true) {
94 PMA_getEnumOrSetValues($db, $table, "enum");
95 // script has exited at this point
99 // Find possible values for set fields during grid edit.
100 if (isset($_REQUEST['get_set_values']) && $_REQUEST['get_set_values'] == true) {
101 PMA_getEnumOrSetValues($db, $table, "set");
102 // script has exited at this point
105 if (isset($_REQUEST['get_default_fk_check_value'])
106 && $_REQUEST['get_default_fk_check_value'] == true
108 $response = Response
::getInstance();
110 'default_fk_check_value', Util
::isForeignKeyCheck()
116 * Check ajax request to set the column order and visibility
118 if (isset($_REQUEST['set_col_prefs']) && $_REQUEST['set_col_prefs'] == true) {
119 PMA_setColumnOrderOrVisibility($table, $db);
120 // script has exited at this point
123 // Default to browse if no query set and we have table
124 // (needed for browsing from DefaultTabTable)
125 $tableLength = mb_strlen($table);
126 $dbLength = mb_strlen($db);
127 if (empty($sql_query) && $tableLength && $dbLength) {
128 $sql_query = PMA_getDefaultSqlQueryForBrowse($db, $table);
130 // set $goto to what will be displayed if query returns 0 rows
133 // Now we can check the parameters
134 Util
::checkParameters(array('sql_query'));
138 * Parse and analyze the query
140 require_once 'libraries/parse_analyze.lib.php';
142 $analyzed_sql_results,
145 ) = PMA_parseAnalyze($sql_query, $db);
146 // @todo: possibly refactor
147 extract($analyzed_sql_results);
151 * Check rights in case of DROP DATABASE
153 * This test may be bypassed if $is_js_confirmed = 1 (already checked with js)
154 * but since a malicious user may pass this variable by url/form, we don't take
155 * into account this case.
157 if (PMA_hasNoRightsToDropDatabase(
158 $analyzed_sql_results, $cfg['AllowUserDropDatabase'], $is_superuser
161 __('"DROP DATABASE" statements are disabled.'),
169 * Need to find the real end of rows?
171 if (isset($find_real_end) && $find_real_end) {
172 $unlim_num_rows = PMA_findRealEndOfRows($db, $table);
179 if (isset($_POST['store_bkm'])) {
180 PMA_addBookmark($goto);
181 // script has exited at this point
186 * Sets or modifies the $goto variable if required
188 if ($goto == 'sql.php') {
189 $is_gotofile = false;
190 $goto = 'sql.php' . URL
::getCommon(
194 'sql_query' => $sql_query
199 PMA_executeQueryAndSendQueryResponse(
200 $analyzed_sql_results, // analyzed_sql_results
201 $is_gotofile, // is_gotofile
204 isset($find_real_end) ?
$find_real_end : null, // find_real_end
205 isset($import_text) ?
$import_text : null, // sql_query_for_bookmark
206 isset($extra_data) ?
$extra_data : null, // extra_data
207 isset($message_to_show) ?
$message_to_show : null, // message_to_show
208 isset($message) ?
$message : null, // message
209 isset($sql_data) ?
$sql_data : null, // sql_data
211 $pmaThemeImage, // pmaThemeImage
212 isset($disp_query) ?
$display_query : null, // disp_query
213 isset($disp_message) ?
$disp_message : null, // disp_message
214 isset($query_type) ?
$query_type : null, // query_type
215 $sql_query, // sql_query
216 isset($selected) ?
$selected : null, // selectedTables
217 isset($complete_query) ?
$complete_query : null // complete_query