00001 <?php
00002
00003
00004
00008 require_once('./libraries/read_dump.lib.php');
00009 require_once('./libraries/grab_globals.lib.php');
00010 require_once('./libraries/common.lib.php');
00011
00012 if (!isset($db)) {
00013 $db = '';
00014 }
00015
00019 @set_time_limit($cfg['ExecTimeLimit']);
00020
00021
00025 if (!isset($goto) || !preg_match('@^(db_details|tbl_properties)(_[a-z]*)?\.php$@i', $goto)) {
00026 $goto = 'db_details.php';
00027 }
00028 $err_url = $goto
00029 . '?' . PMA_generate_common_url($db)
00030 . (preg_match('@^tbl_properties(_[a-z]*)?\.php$@', $goto) ? '&table=' . urlencode($table) : '');
00031
00032
00036 $view_bookmark = 0;
00037 $sql_bookmark = isset($sql_bookmark) ? $sql_bookmark : '';
00038 $sql_query = isset($sql_query) ? $sql_query : '';
00039
00040 if (!empty($sql_localfile) && !empty($cfg['UploadDir'])) {
00041
00042
00043 $sql_localfile = PMA_securePath($sql_localfile);
00044
00045 if (substr($cfg['UploadDir'], -1) != '/') {
00046 $cfg['UploadDir'] .= '/';
00047 }
00048 $sql_file = $cfg['UploadDir'] . $sql_localfile;
00049 } else if (empty($sql_file)) {
00050 $sql_file = 'none';
00051 }
00052
00056 if (!empty($id_bookmark)) {
00057 require_once('./libraries/bookmark.lib.php');
00058 switch ($action_bookmark) {
00059 case 0:
00060 $sql_query = PMA_queryBookmarks($db, $cfg['Bookmark'], $id_bookmark,'id', (isset($action_bookmark_all) ? TRUE : FALSE));
00061 if (isset($bookmark_variable) && !empty($bookmark_variable)) {
00062 $sql_query = preg_replace('|/\*(.*)\[VARIABLE\](.*)\*/|imsU', '${1}' . PMA_sqlAddslashes($bookmark_variable) . '${2}', $sql_query);
00063 }
00064 break;
00065 case 1:
00066 $sql_query = PMA_queryBookmarks($db, $cfg['Bookmark'], $id_bookmark);
00067 $view_bookmark = 1;
00068 break;
00069 case 2:
00070 $sql_query = PMA_deleteBookmarks($db, $cfg['Bookmark'], $id_bookmark);
00071 break;
00072 }
00073 }
00074
00075
00079
00080 if ($sql_file != 'none') {
00081
00082
00083 if ((is_uploaded_file($sql_file))
00084 ||(isset($sql_localfile) && $sql_file == $cfg['UploadDir'] . $sql_localfile) && file_exists($sql_file)) {
00085
00086 $open_basedir = @ini_get('open_basedir');
00087
00088 if (!isset($sql_file_compression)) $sql_file_compression = '';
00089
00090
00091
00092
00093
00094 if (!empty($open_basedir)) {
00095
00096 $tmp_subdir = (PMA_IS_WINDOWS ? '.\\tmp\\' : './tmp/');
00097
00098
00099 if (!is_writeable($tmp_subdir)) {
00100 $sql_query = PMA_readFile($sql_file, $sql_file_compression);
00101 if ($sql_query == FALSE) {
00102 $message = $strFileCouldNotBeRead . ' (1)';
00103 }
00104 } else {
00105 $sql_file_new = $tmp_subdir . basename($sql_file);
00106 if (move_uploaded_file($sql_file, $sql_file_new)) {
00107 $sql_query = PMA_readFile($sql_file_new, $sql_file_compression);
00108 if ($sql_query == FALSE) {
00109 $message = $strFileCouldNotBeRead . ' (2)';
00110 }
00111 unlink($sql_file_new);
00112 } else {
00113
00114 $sql_query = PMA_readFile($sql_file, $sql_file_compression);
00115 if ($sql_query == FALSE) {
00116 $message = $strFileCouldNotBeRead . ' (3)';
00117 }
00118 }
00119 }
00120 } else {
00121
00122 $sql_query = PMA_readFile($sql_file, $sql_file_compression);
00123 if ($sql_query == FALSE) {
00124 $message = $strFileCouldNotBeRead . ' (4)';
00125 }
00126 }
00127
00128
00129 if (PMA_MYSQL_INT_VERSION < 40100
00130 && $cfg['AllowAnywhereRecoding'] && $allow_recoding
00131 && isset($charset_of_file) && $charset_of_file != $charset) {
00132 $sql_query = PMA_convert_string($charset_of_file, $charset, $sql_query);
00133 } else if (PMA_MYSQL_INT_VERSION >= 40100
00134 && isset($charset_of_file) && $charset_of_file != 'utf8') {
00135 $sql_query = 'SET NAMES \'' . $charset_of_file . "';\n"
00136 . $sql_query . "\n"
00137 . "SET CHARACTER SET utf8;\n"
00138 . "SET SESSION collation_connection ='" . $collation_connection . "';";
00139 }
00140 }
00141 }
00142
00143
00144 if (@function_exists('PMA_kanji_str_conv')) {
00145
00146
00147 $sql_tmp = $sql_query;
00148 PMA_change_enc_order();
00149 $sql_query = PMA_kanji_str_conv($sql_tmp, $knjenc, isset($xkana) ? $xkana : '');
00150 PMA_change_enc_order();
00151 }
00152
00153
00154
00155
00156
00157
00158 if (!empty($prev_sql_query)) {
00159 $prev_sql_query = urldecode($prev_sql_query);
00160 if ($sql_query == trim(htmlspecialchars($prev_sql_query))) {
00161 $sql_query = $prev_sql_query;
00162 }
00163 }
00164
00165
00166 if (!$cfg['AllowUserDropDatabase']
00167 && preg_match('@DROP[[:space:]]+(IF EXISTS[[:space:]]+)?DATABASE @i', $sql_query)) {
00168
00169
00170
00171 if (!($result = PMA_DBI_select_db('mysql'))) {
00172 require_once('./header.inc.php');
00173 PMA_mysqlDie($strNoDropDatabases, '', '', $err_url);
00174 }
00175 }
00176 define('PMA_CHK_DROP', 1);
00177
00181 if (isset($SQLbookmark) && $sql_query != '') {
00182 require_once('./libraries/bookmark.lib.php');
00183 $bfields = array(
00184 'dbase' => $db,
00185 'user' => $cfg['Bookmark']['user'],
00186 'query' => urlencode($sql_query),
00187 'label' => $bkm_label
00188 );
00189
00190 PMA_addBookmarks($bfields, $cfg['Bookmark'], (isset($bkm_all_users) && $bkm_all_users == 'true' ? true : false));
00191 }
00192
00196 if ($sql_query != '') {
00197 $pieces = array();
00198 PMA_splitSqlFile($pieces, $sql_query, PMA_MYSQL_INT_VERSION);
00199 $pieces_count = count($pieces);
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 if (!$cfg['VerboseMultiSubmit']) {
00210
00211 $max_nofile_length = 500;
00212 $max_nofile_pieces = 0;
00213
00214
00215 $max_file_length = 10000;
00216 $max_file_pieces = 10;
00217 } else {
00218
00219 $max_nofile_length = 0;
00220 $max_nofile_pieces = 50;
00221
00222
00223 $max_file_length = 50000;
00224 $max_file_pieces = 50;
00225 }
00226
00227 if ($sql_file != 'none' &&
00228 (($max_file_pieces != 0 && ($pieces_count > $max_file_pieces))
00229 ||
00230 ($max_file_length != 0 && (strlen($sql_query) > $max_file_length)))) {
00231
00232 $sql_query_cpy = $sql_query = '';
00233 $save_bandwidth = TRUE;
00234 $save_bandwidth_length = $max_file_length;
00235 $save_bandwidth_pieces = $max_file_pieces;
00236 } else {
00237
00238 $sql_query_cpy = $sql_query;
00239
00240
00241 if (($max_nofile_length != 0 && (strlen($sql_query_cpy) > $max_nofile_length))
00242 || ($max_nofile_pieces != 0 && $pieces_count > $max_nofile_pieces)) {
00243 $sql_query_cpy = $sql_query = '';
00244 $save_bandwidth = TRUE;
00245 $save_bandwidth_length = $max_nofile_length;
00246 $save_bandwidth_pieces = $max_nofile_pieces;
00247 }
00248 }
00249
00250 if ($view_bookmark == 0) {
00251
00252 if ($pieces_count == 1 && !empty($pieces[0]['query'])) {
00253 $sql_query = $pieces[0]['query'];
00254
00255 if (preg_match('@^((-- |#)[^\n]*\n|/\*.*?\*/)*(DROP|CREATE)[[:space:]]+(IF EXISTS[[:space:]]+)?(TABLE|DATABASE)[[:space:]]+(.+)@im', $sql_query)) {
00256 $reload = 1;
00257 }
00258 require('./sql.php');
00259 }
00260
00261
00262
00263
00264 else if (empty($db) || PMA_DBI_select_db($db)) {
00265 $mult = TRUE;
00266 $info_msg = '';
00267 $info_count = 0;
00268
00269
00270 $count = $pieces_count;
00271 if ($pieces[$count - 1]['empty']) $count--;
00272
00273 for ($i = 0; $i < $count; $i++) {
00274 $a_sql_query = $pieces[$i]['query'];
00275
00276
00277
00278 if ($i == $count - 1 && preg_match('@^((-- |#)[^\n]*\n|[\s]*\n|/\*.*?\*/)*(SELECT|SHOW)@i', $a_sql_query)) {
00279 $complete_query = $sql_query;
00280 $display_query = $sql_query;
00281 $sql_query = $a_sql_query;
00282 require('./sql.php');
00283 }
00284 $result = PMA_DBI_try_query($a_sql_query);
00285 if ($result == FALSE) {
00286 if (isset($my_die) && $cfg['IgnoreMultiSubmitErrors']) {
00287 $my_die[] = "\n\n" . $a_sql_query;
00288 } elseif ($cfg['IgnoreMultiSubmitErrors']) {
00289 $my_die = array();
00290 $my_die[] = $a_sql_query;
00291 } else {
00292 $my_die = $a_sql_query;
00293 }
00294
00295 if ($cfg['VerboseMultiSubmit']) {
00296 $info_msg .= $a_sql_query . '; # ' . $strError . "\n";
00297 $info_count++;
00298 }
00299
00300 if (!$cfg['IgnoreMultiSubmitErrors']) {
00301 break;
00302 }
00303 } else if ($cfg['VerboseMultiSubmit']) {
00304 $a_num_rows = (int)@PMA_DBI_num_rows($result);
00305 $a_aff_rows = (int)@PMA_DBI_affected_rows();
00306 if ($a_num_rows > 0) {
00307 $a_rows = $a_num_rows;
00308 $a_switch = $strRows . ': ';
00309 } elseif ($a_aff_rows > 0) {
00310 $a_rows = $a_aff_rows;
00311 $a_switch = $strAffectedRows;;
00312 } else {
00313 $a_rows = '';
00314 $a_switch = $strEmptyResultSet;
00315 }
00316
00317 $info_msg .= $a_sql_query . "; # " . $a_switch . $a_rows . "\n";
00318 $info_count++;
00319 }
00320
00321
00322
00323 if ($result != FALSE && preg_match('@^((-- |#)^[\n]*|/\*.*?\*/)*USE[[:space:]]*([\S]+)@i', $a_sql_query, $match)) {
00324 $db = trim($match[3]);
00325 $reload = 1;
00326 }
00327
00328
00329
00330
00331 if (!isset($reload) && preg_match('@^((-- |#)[^\n]*\n|/\*.*?\*/)*(DROP|CREATE)[\s]+(IF EXISTS[[:space:]]+)?(TABLE|DATABASE)[[:space:]]+(.+)@im', $a_sql_query)) {
00332 $reload = 1;
00333 }
00334 }
00335
00336 if ($cfg['VerboseMultiSubmit'] && strlen($info_msg) > 0 &&
00337 ((!isset($save_bandwidth) || $save_bandwidth == FALSE) ||
00338 ($save_bandwidth_pieces == 0 && strlen($info_msg) < $save_bandwidth_length) ||
00339 ($save_bandwidth_length == 0 && $info_count < $save_bandwidth_pieces))) {
00340 $sql_query = $info_msg;
00341 }
00342
00343 }
00344 }
00345 unset($pieces);
00346 }
00347
00348
00349
00353 if (isset($my_die)) {
00354 $js_to_run = 'functions.js';
00355 require_once('./header.inc.php');
00356 if (is_array($my_die)) {
00357 foreach ($my_die AS $key => $die_string) {
00358 PMA_mysqlDie('', $die_string, '', $err_url, FALSE);
00359 echo '<hr />';
00360 }
00361 } else {
00362 PMA_mysqlDie('', $my_die, '', $err_url, TRUE);
00363 }
00364 }
00365
00366
00370
00371 if (isset($table) && $table == '') {
00372 unset($table);
00373 }
00374 if (isset($db) && $db == '') {
00375 unset($db);
00376 }
00377
00378 $is_db = $is_table = FALSE;
00379 if ($goto == 'tbl_properties.php') {
00380 if (!isset($table)) {
00381 $goto = 'db_details.php';
00382 } else {
00383 PMA_DBI_select_db($db);
00384 $is_table = PMA_DBI_try_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'', NULL, PMA_DBI_QUERY_STORE);
00385 if (!($is_table && @PMA_DBI_num_rows($is_table))) {
00386 $goto = 'db_details.php';
00387 unset($table);
00388 }
00389 }
00390 }
00391 if ($goto == 'db_details.php') {
00392 if (isset($table)) {
00393 unset($table);
00394 }
00395 if (!isset($db)) {
00396 $goto = 'main.php';
00397 } else {
00398 $is_db = @PMA_DBI_select_db($db);
00399 if (!$is_db) {
00400 $goto = 'main.php';
00401 unset($db);
00402 }
00403 }
00404 }
00405
00406 if (!empty($id_bookmark) && $action_bookmark == 2) {
00407 $message = $strBookmarkDeleted;
00408 } else if (!isset($sql_query_cpy)) {
00409 if (empty($message)) {
00410 $message = $strNoQuery;
00411 }
00412 } else if ($sql_query_cpy == '') {
00413 $message = "$strSuccess:[br]$strTheContent ("
00414 . (isset($sql_file_name) ? $sql_file_name . ': ' : '')
00415 . "$pieces_count $strInstructions) ";
00416 } else {
00417 $message = $strSuccess;
00418 }
00419
00420 if ($goto == 'db_details.php' || $goto == 'tbl_properties.php' || $goto == 'tbl_properties_structure.php') {
00421
00422
00423
00424
00425
00426 $js_to_run = 'functions.js';
00427 }
00428 if ($goto != 'main.php') {
00429 require_once('./header.inc.php');
00430 }
00431 $active_page = $goto;
00432 require('./' . $goto);
00433 ?>