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
;
15 * Gets some core libraries
17 require_once 'libraries/common.inc.php';
18 require_once 'libraries/check_user_privileges.lib.php';
19 require_once 'libraries/bookmark.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 . '?' . PMA_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);
149 if ($table != $table_from_sql && !empty($table_from_sql)) {
150 $table = $table_from_sql;
155 * Check rights in case of DROP DATABASE
157 * This test may be bypassed if $is_js_confirmed = 1 (already checked with js)
158 * but since a malicious user may pass this variable by url/form, we don't take
159 * into account this case.
161 if (PMA_hasNoRightsToDropDatabase(
162 $analyzed_sql_results, $cfg['AllowUserDropDatabase'], $is_superuser
165 __('"DROP DATABASE" statements are disabled.'),
173 * Need to find the real end of rows?
175 if (isset($find_real_end) && $find_real_end) {
176 $unlim_num_rows = PMA_findRealEndOfRows($db, $table);
183 if (isset($_POST['store_bkm'])) {
184 PMA_addBookmark($goto);
185 // script has exited at this point
190 * Sets or modifies the $goto variable if required
192 if ($goto == 'sql.php') {
193 $is_gotofile = false;
194 $goto = 'sql.php' . PMA_URL_getCommon(
198 'sql_query' => $sql_query
203 PMA_executeQueryAndSendQueryResponse(
204 $analyzed_sql_results, // analyzed_sql_results
205 $is_gotofile, // is_gotofile
208 isset($find_real_end) ?
$find_real_end : null, // find_real_end
209 isset($import_text) ?
$import_text : null, // sql_query_for_bookmark
210 isset($extra_data) ?
$extra_data : null, // extra_data
211 isset($message_to_show) ?
$message_to_show : null, // message_to_show
212 isset($message) ?
$message : null, // message
213 isset($sql_data) ?
$sql_data : null, // sql_data
215 $pmaThemeImage, // pmaThemeImage
216 isset($disp_query) ?
$display_query : null, // disp_query
217 isset($disp_message) ?
$disp_message : null, // disp_message
218 isset($query_type) ?
$query_type : null, // query_type
219 $sql_query, // sql_query
220 isset($selected) ?
$selected : null, // selectedTables
221 isset($complete_query) ?
$complete_query : null // complete_query