@@ -27,6 +27,9 @@ discard block |
||
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | + /** |
|
| 31 | + * @param string $function |
|
| 32 | + */ |
|
| 30 | 33 | function _applyPlugin($function, $args) { |
| 31 | 34 | foreach ($this->plugins as $plugin) { |
| 32 | 35 | if (method_exists($plugin, $function)) { |
@@ -46,6 +49,9 @@ discard block |
||
| 46 | 49 | return $this->_callParent($function, $args); |
| 47 | 50 | } |
| 48 | 51 | |
| 52 | + /** |
|
| 53 | + * @param string $function |
|
| 54 | + */ |
|
| 49 | 55 | function _appendPlugin($function, $args) { |
| 50 | 56 | $return = $this->_callParent($function, $args); |
| 51 | 57 | foreach ($this->plugins as $plugin) { |
@@ -9,8 +9,8 @@ |
||
| 9 | 9 | var $plugins; |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | - * @param array |
|
| 13 | - */ |
|
| 12 | + * @param array |
|
| 13 | + */ |
|
| 14 | 14 | function AdminerPlugin($plugins) { |
| 15 | 15 | $this->plugins = $plugins; |
| 16 | 16 | // it is possible to use ReflectionObject in PHP 5 to find out which plugins defines which methods at once |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if ( !include("../../mainfile.php") ) { |
| 21 | - die("XOOPS root path not defined"); |
|
| 21 | + die("XOOPS root path not defined"); |
|
| 22 | 22 | } |
| 23 | 23 | $module_dirname = basename( dirname( __FILE__ ) ) ; |
| 24 | 24 | if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) exit( _NOPERM ); |
@@ -17,14 +17,14 @@ |
||
| 17 | 17 | * @version $Id $ |
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | -if ( !include("../../mainfile.php") ) { |
|
| 20 | +if (!include("../../mainfile.php")) { |
|
| 21 | 21 | die("XOOPS root path not defined"); |
| 22 | 22 | } |
| 23 | -$module_dirname = basename( dirname( __FILE__ ) ) ; |
|
| 24 | -if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) exit( _NOPERM ); |
|
| 23 | +$module_dirname = basename(dirname(__FILE__)); |
|
| 24 | +if (!is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid())) exit(_NOPERM); |
|
| 25 | 25 | $xoopsOption["template_main"] = $module_dirname . "_index.html"; |
| 26 | 26 | |
| 27 | -include(XOOPS_ROOT_PATH."/header.php"); |
|
| 27 | +include(XOOPS_ROOT_PATH . "/header.php"); |
|
| 28 | 28 | |
| 29 | -include(XOOPS_ROOT_PATH."/footer.php"); |
|
| 29 | +include(XOOPS_ROOT_PATH . "/footer.php"); |
|
| 30 | 30 | ?> |
@@ -21,7 +21,9 @@ |
||
| 21 | 21 | die("XOOPS root path not defined"); |
| 22 | 22 | } |
| 23 | 23 | $module_dirname = basename( dirname( __FILE__ ) ) ; |
| 24 | -if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) exit( _NOPERM ); |
|
| 24 | +if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) { |
|
| 25 | + exit( _NOPERM ); |
|
| 26 | +} |
|
| 25 | 27 | $xoopsOption["template_main"] = $module_dirname . "_index.html"; |
| 26 | 28 | |
| 27 | 29 | include(XOOPS_ROOT_PATH."/header.php"); |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | * @author Kris <http://www.xoofoo.org> |
| 17 | 17 | * @version $Id $ |
| 18 | 18 | **/ |
| 19 | -$module_dirname = basename( dirname( __FILE__ ) ) ; |
|
| 19 | +$module_dirname = basename(dirname(__FILE__)); |
|
| 20 | 20 | $modversion['name'] = _MI_ADMINER_NAME; |
| 21 | 21 | $modversion['version'] = 3.0; |
| 22 | 22 | $modversion['description'] = _MI_ADMINER_DESC; |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | **/ |
| 19 | 19 | // connect xoops database |
| 20 | 20 | if ( !include("../../mainfile.php") ) { |
| 21 | - die("XOOPS root path not defined"); |
|
| 21 | + die("XOOPS root path not defined"); |
|
| 22 | 22 | } |
| 23 | 23 | $module_dirname = basename( dirname( __FILE__ ) ) ; |
| 24 | 24 | include(XOOPS_ROOT_PATH."/header.php"); |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | * @version $Id $ |
| 18 | 18 | **/ |
| 19 | 19 | // connect xoops database |
| 20 | -if ( !include("../../mainfile.php") ) { |
|
| 20 | +if (!include("../../mainfile.php")) { |
|
| 21 | 21 | die("XOOPS root path not defined"); |
| 22 | 22 | } |
| 23 | -$module_dirname = basename( dirname( __FILE__ ) ) ; |
|
| 24 | -include(XOOPS_ROOT_PATH."/header.php"); |
|
| 25 | -if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) exit( _NOPERM ); |
|
| 23 | +$module_dirname = basename(dirname(__FILE__)); |
|
| 24 | +include(XOOPS_ROOT_PATH . "/header.php"); |
|
| 25 | +if (!is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid())) exit(_NOPERM); |
|
| 26 | 26 | |
| 27 | 27 | function adminer_object() { |
| 28 | 28 | class AdminerKfr extends Adminer { |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | return 'XOOPS Admin'; |
| 31 | 31 | } |
| 32 | 32 | function credentials() { |
| 33 | - return array(XOOPS_DB_HOST,XOOPS_DB_USER,XOOPS_DB_PASS); |
|
| 33 | + return array(XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS); |
|
| 34 | 34 | } |
| 35 | 35 | function database() { |
| 36 | 36 | return XOOPS_DB_NAME; |
@@ -22,7 +22,9 @@ |
||
| 22 | 22 | } |
| 23 | 23 | $module_dirname = basename( dirname( __FILE__ ) ) ; |
| 24 | 24 | include(XOOPS_ROOT_PATH."/header.php"); |
| 25 | -if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) exit( _NOPERM ); |
|
| 25 | +if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) { |
|
| 26 | + exit( _NOPERM ); |
|
| 27 | +} |
|
| 26 | 28 | |
| 27 | 29 | function adminer_object() { |
| 28 | 30 | class AdminerKfr extends Adminer { |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | $ajax = true; // AJAX mode: import will be done without refreshing the website |
| 52 | 52 | $linespersession = 3000; // Lines to be executed per one import session |
| 53 | 53 | $delaypersession = 0; // You can specify a sleep time in milliseconds after each session |
| 54 | - // Works only if JavaScript is activated. Use to reduce server overrun |
|
| 54 | + // Works only if JavaScript is activated. Use to reduce server overrun |
|
| 55 | 55 | |
| 56 | 56 | // CSV related settings (only if you use a CSV dump) |
| 57 | 57 | |
@@ -319,23 +319,23 @@ discard block |
||
| 319 | 319 | if (!$error && isset($_REQUEST["uploadbutton"])) |
| 320 | 320 | { if (is_uploaded_file($_FILES["dumpfile"]["tmp_name"]) && ($_FILES["dumpfile"]["error"])==0) |
| 321 | 321 | { |
| 322 | - $uploaded_filename=str_replace(" ","_",$_FILES["dumpfile"]["name"]); |
|
| 323 | - $uploaded_filename=preg_replace("/[^_A-Za-z0-9-\.]/i",'',$uploaded_filename); |
|
| 324 | - $uploaded_filepath=str_replace("\\","/",$upload_dir."/".$uploaded_filename); |
|
| 325 | - |
|
| 326 | - if (file_exists($uploaded_filename)) |
|
| 327 | - { echo ("<p class=\"error\">File $uploaded_filename already exist! Delete and upload again!</p>\n"); |
|
| 328 | - } |
|
| 329 | - else if (!preg_match("/(\.(sql|gz|csv))$/i",$uploaded_filename)) |
|
| 330 | - { echo ("<p class=\"error\">You may only upload .sql .gz or .csv files.</p>\n"); |
|
| 331 | - } |
|
| 332 | - else if (!@move_uploaded_file($_FILES["dumpfile"]["tmp_name"],$uploaded_filepath)) |
|
| 333 | - { echo ("<p class=\"error\">Error moving uploaded file ".$_FILES["dumpfile"]["tmp_name"]." to the $uploaded_filepath</p>\n"); |
|
| 334 | - echo ("<p>Check the directory permissions for $upload_dir (must be 777)!</p>\n"); |
|
| 335 | - } |
|
| 336 | - else |
|
| 337 | - { echo ("<p class=\"success\">Uploaded file saved as $uploaded_filename</p>\n"); |
|
| 338 | - } |
|
| 322 | + $uploaded_filename=str_replace(" ","_",$_FILES["dumpfile"]["name"]); |
|
| 323 | + $uploaded_filename=preg_replace("/[^_A-Za-z0-9-\.]/i",'',$uploaded_filename); |
|
| 324 | + $uploaded_filepath=str_replace("\\","/",$upload_dir."/".$uploaded_filename); |
|
| 325 | + |
|
| 326 | + if (file_exists($uploaded_filename)) |
|
| 327 | + { echo ("<p class=\"error\">File $uploaded_filename already exist! Delete and upload again!</p>\n"); |
|
| 328 | + } |
|
| 329 | + else if (!preg_match("/(\.(sql|gz|csv))$/i",$uploaded_filename)) |
|
| 330 | + { echo ("<p class=\"error\">You may only upload .sql .gz or .csv files.</p>\n"); |
|
| 331 | + } |
|
| 332 | + else if (!@move_uploaded_file($_FILES["dumpfile"]["tmp_name"],$uploaded_filepath)) |
|
| 333 | + { echo ("<p class=\"error\">Error moving uploaded file ".$_FILES["dumpfile"]["tmp_name"]." to the $uploaded_filepath</p>\n"); |
|
| 334 | + echo ("<p>Check the directory permissions for $upload_dir (must be 777)!</p>\n"); |
|
| 335 | + } |
|
| 336 | + else |
|
| 337 | + { echo ("<p class=\"success\">Uploaded file saved as $uploaded_filename</p>\n"); |
|
| 338 | + } |
|
| 339 | 339 | } |
| 340 | 340 | else |
| 341 | 341 | { echo ("<p class=\"error\">Error uploading file ".$_FILES["dumpfile"]["name"]."</p>\n"); |
@@ -347,9 +347,9 @@ discard block |
||
| 347 | 347 | |
| 348 | 348 | if (!$error && isset($_REQUEST["delete"]) && $_REQUEST["delete"]!=basename($_SERVER["SCRIPT_FILENAME"])) |
| 349 | 349 | { if (preg_match("/(\.(sql|gz|csv))$/i",$_REQUEST["delete"]) && @unlink(basename($_REQUEST["delete"]))) |
| 350 | - echo ("<p class=\"success\">".$_REQUEST["delete"]." was removed successfully</p>\n"); |
|
| 350 | + echo ("<p class=\"success\">".$_REQUEST["delete"]." was removed successfully</p>\n"); |
|
| 351 | 351 | else |
| 352 | - echo ("<p class=\"error\">Can't remove ".$_REQUEST["delete"]."</p>\n"); |
|
| 352 | + echo ("<p class=\"error\">Can't remove ".$_REQUEST["delete"]."</p>\n"); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | // Connect to the database, set charset and execute pre-queries |
@@ -357,26 +357,26 @@ discard block |
||
| 357 | 357 | if (!$error && !TESTMODE) |
| 358 | 358 | { $dbconnection = @mysql_connect($db_server,$db_username,$db_password); |
| 359 | 359 | if ($dbconnection) |
| 360 | - $db = mysql_select_db($db_name); |
|
| 360 | + $db = mysql_select_db($db_name); |
|
| 361 | 361 | if (!$dbconnection || !$db) |
| 362 | 362 | { echo ("<p class=\"error\">Database connection failed due to ".mysql_error()."</p>\n"); |
| 363 | - echo ("<p>Edit the database settings in ".$_SERVER["SCRIPT_FILENAME"]." or contact your database provider.</p>\n"); |
|
| 364 | - $error=true; |
|
| 363 | + echo ("<p>Edit the database settings in ".$_SERVER["SCRIPT_FILENAME"]." or contact your database provider.</p>\n"); |
|
| 364 | + $error=true; |
|
| 365 | 365 | } |
| 366 | 366 | if (!$error && $db_connection_charset!=='') |
| 367 | - @mysql_query("SET NAMES $db_connection_charset", $dbconnection); |
|
| 367 | + @mysql_query("SET NAMES $db_connection_charset", $dbconnection); |
|
| 368 | 368 | |
| 369 | 369 | if (!$error && isset ($pre_query) && sizeof ($pre_query)>0) |
| 370 | 370 | { reset($pre_query); |
| 371 | - foreach ($pre_query as $pre_query_value) |
|
| 372 | - { if (!@mysql_query($pre_query_value, $dbconnection)) |
|
| 373 | - { echo ("<p class=\"error\">Error with pre-query.</p>\n"); |
|
| 374 | - echo ("<p>Query: ".trim(nl2br(htmlentities($pre_query_value)))."</p>\n"); |
|
| 375 | - echo ("<p>MySQL: ".mysql_error()."</p>\n"); |
|
| 376 | - $error=true; |
|
| 377 | - break; |
|
| 378 | - } |
|
| 379 | - } |
|
| 371 | + foreach ($pre_query as $pre_query_value) |
|
| 372 | + { if (!@mysql_query($pre_query_value, $dbconnection)) |
|
| 373 | + { echo ("<p class=\"error\">Error with pre-query.</p>\n"); |
|
| 374 | + echo ("<p>Query: ".trim(nl2br(htmlentities($pre_query_value)))."</p>\n"); |
|
| 375 | + echo ("<p>MySQL: ".mysql_error()."</p>\n"); |
|
| 376 | + $error=true; |
|
| 377 | + break; |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | 380 | } |
| 381 | 381 | } |
| 382 | 382 | else |
@@ -392,49 +392,49 @@ discard block |
||
| 392 | 392 | if (!$error && !isset($_REQUEST["fn"]) && $filename=="") |
| 393 | 393 | { if ($dirhandle = opendir($upload_dir)) |
| 394 | 394 | { |
| 395 | - $files=array(); |
|
| 396 | - while (false !== ($files[] = readdir($dirhandle))); |
|
| 397 | - closedir($dirhandle); |
|
| 398 | - $dirhead=false; |
|
| 399 | - |
|
| 400 | - if (sizeof($files)>0) |
|
| 401 | - { |
|
| 402 | - sort($files); |
|
| 403 | - foreach ($files as $dirfile) |
|
| 404 | - { |
|
| 405 | - if ($dirfile != "." && $dirfile != ".." && $dirfile!=basename($_SERVER["SCRIPT_FILENAME"]) && preg_match("/\.(sql|gz|csv)$/i",$dirfile)) |
|
| 406 | - { if (!$dirhead) |
|
| 407 | - { echo ("<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\">\n"); |
|
| 408 | - echo ("<tr><th>Filename</th><th>Size</th><th>Date&Time</th><th>Type</th><th> </th><th> </th>\n"); |
|
| 409 | - $dirhead=true; |
|
| 410 | - } |
|
| 411 | - echo ("<tr><td>$dirfile</td><td class=\"right\">".filesize($dirfile)."</td><td>".date ("Y-m-d H:i:s", filemtime($dirfile))."</td>"); |
|
| 412 | - |
|
| 413 | - if (preg_match("/\.sql$/i",$dirfile)) |
|
| 414 | - echo ("<td>SQL</td>"); |
|
| 415 | - elseif (preg_match("/\.gz$/i",$dirfile)) |
|
| 416 | - echo ("<td>GZip</td>"); |
|
| 417 | - elseif (preg_match("/\.csv$/i",$dirfile)) |
|
| 418 | - echo ("<td>CSV</td>"); |
|
| 419 | - else |
|
| 420 | - echo ("<td>Misc</td>"); |
|
| 421 | - |
|
| 422 | - if ((preg_match("/\.gz$/i",$dirfile) && function_exists("gzopen")) || preg_match("/\.sql$/i",$dirfile) || preg_match("/\.csv$/i",$dirfile)) |
|
| 423 | - echo ("<td><a href=\"".$_SERVER["PHP_SELF"]."?start=1&fn=".urlencode($dirfile)."&foffset=0&totalqueries=0&delimiter=".urlencode($delimiter)."\">Start Import</a> into $db_name at $db_server</td>\n <td><a href=\"".$_SERVER["PHP_SELF"]."?delete=".urlencode($dirfile)."\">Delete file</a></td></tr>\n"); |
|
| 424 | - else |
|
| 425 | - echo ("<td> </td>\n <td> </td></tr>\n"); |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - if ($dirhead) |
|
| 431 | - echo ("</table>\n"); |
|
| 432 | - else |
|
| 433 | - echo ("<p>No uploaded SQL, GZ or CSV files found in the working directory</p>\n"); |
|
| 395 | + $files=array(); |
|
| 396 | + while (false !== ($files[] = readdir($dirhandle))); |
|
| 397 | + closedir($dirhandle); |
|
| 398 | + $dirhead=false; |
|
| 399 | + |
|
| 400 | + if (sizeof($files)>0) |
|
| 401 | + { |
|
| 402 | + sort($files); |
|
| 403 | + foreach ($files as $dirfile) |
|
| 404 | + { |
|
| 405 | + if ($dirfile != "." && $dirfile != ".." && $dirfile!=basename($_SERVER["SCRIPT_FILENAME"]) && preg_match("/\.(sql|gz|csv)$/i",$dirfile)) |
|
| 406 | + { if (!$dirhead) |
|
| 407 | + { echo ("<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\">\n"); |
|
| 408 | + echo ("<tr><th>Filename</th><th>Size</th><th>Date&Time</th><th>Type</th><th> </th><th> </th>\n"); |
|
| 409 | + $dirhead=true; |
|
| 410 | + } |
|
| 411 | + echo ("<tr><td>$dirfile</td><td class=\"right\">".filesize($dirfile)."</td><td>".date ("Y-m-d H:i:s", filemtime($dirfile))."</td>"); |
|
| 412 | + |
|
| 413 | + if (preg_match("/\.sql$/i",$dirfile)) |
|
| 414 | + echo ("<td>SQL</td>"); |
|
| 415 | + elseif (preg_match("/\.gz$/i",$dirfile)) |
|
| 416 | + echo ("<td>GZip</td>"); |
|
| 417 | + elseif (preg_match("/\.csv$/i",$dirfile)) |
|
| 418 | + echo ("<td>CSV</td>"); |
|
| 419 | + else |
|
| 420 | + echo ("<td>Misc</td>"); |
|
| 421 | + |
|
| 422 | + if ((preg_match("/\.gz$/i",$dirfile) && function_exists("gzopen")) || preg_match("/\.sql$/i",$dirfile) || preg_match("/\.csv$/i",$dirfile)) |
|
| 423 | + echo ("<td><a href=\"".$_SERVER["PHP_SELF"]."?start=1&fn=".urlencode($dirfile)."&foffset=0&totalqueries=0&delimiter=".urlencode($delimiter)."\">Start Import</a> into $db_name at $db_server</td>\n <td><a href=\"".$_SERVER["PHP_SELF"]."?delete=".urlencode($dirfile)."\">Delete file</a></td></tr>\n"); |
|
| 424 | + else |
|
| 425 | + echo ("<td> </td>\n <td> </td></tr>\n"); |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + if ($dirhead) |
|
| 431 | + echo ("</table>\n"); |
|
| 432 | + else |
|
| 433 | + echo ("<p>No uploaded SQL, GZ or CSV files found in the working directory</p>\n"); |
|
| 434 | 434 | } |
| 435 | 435 | else |
| 436 | 436 | { echo ("<p class=\"error\">Error listing directory $upload_dir</p>\n"); |
| 437 | - $error=true; |
|
| 437 | + $error=true; |
|
| 438 | 438 | } |
| 439 | 439 | } |
| 440 | 440 | |
@@ -456,14 +456,14 @@ discard block |
||
| 456 | 456 | do { $tempfilename=time().".tmp"; } while (file_exists($tempfilename)); |
| 457 | 457 | if (!($tempfile=@fopen($tempfilename,"w"))) |
| 458 | 458 | { echo ("<p>Upload form disabled. Permissions for the working directory <i>$upload_dir</i> <b>must be set writable for the webserver</b> in order "); |
| 459 | - echo ("to upload files here. Alternatively you can upload your dump files via FTP.</p>\n"); |
|
| 459 | + echo ("to upload files here. Alternatively you can upload your dump files via FTP.</p>\n"); |
|
| 460 | 460 | } |
| 461 | 461 | else |
| 462 | 462 | { fclose($tempfile); |
| 463 | - unlink ($tempfilename); |
|
| 463 | + unlink ($tempfilename); |
|
| 464 | 464 | |
| 465 | - echo ("<p>You can now upload your dump file up to $upload_max_filesize bytes (".round ($upload_max_filesize/1024/1024)." Mbytes) "); |
|
| 466 | - echo ("directly from your browser to the server. Alternatively you can upload your dump files of any size via FTP.</p>\n"); |
|
| 465 | + echo ("<p>You can now upload your dump file up to $upload_max_filesize bytes (".round ($upload_max_filesize/1024/1024)." Mbytes) "); |
|
| 466 | + echo ("directly from your browser to the server. Alternatively you can upload your dump files of any size via FTP.</p>\n"); |
|
| 467 | 467 | ?> |
| 468 | 468 | <form method="POST" action="<?php echo ($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data"> |
| 469 | 469 | <input type="hidden" name="MAX_FILE_SIZE" value="$upload_max_filesize"> |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | $row = mysql_fetch_assoc($result); |
| 483 | 483 | if ($row) |
| 484 | 484 | { $charset = $row['Value']; |
| 485 | - echo ("<p>Note: The current mySQL connection charset is <i>$charset</i>. Your dump file must be encoded in <i>$charset</i> in order to avoid problems with non-latin characters. You can change the connection charset using the \$db_connection_charset variable in bigdump.php</p>\n"); |
|
| 485 | + echo ("<p>Note: The current mySQL connection charset is <i>$charset</i>. Your dump file must be encoded in <i>$charset</i> in order to avoid problems with non-latin characters. You can change the connection charset using the \$db_connection_charset variable in bigdump.php</p>\n"); |
|
| 486 | 486 | } |
| 487 | 487 | } |
| 488 | 488 | |
@@ -494,36 +494,36 @@ discard block |
||
| 494 | 494 | // Set current filename ($filename overrides $_REQUEST["fn"] if set) |
| 495 | 495 | |
| 496 | 496 | if ($filename!="") |
| 497 | - $curfilename=$filename; |
|
| 497 | + $curfilename=$filename; |
|
| 498 | 498 | else if (isset($_REQUEST["fn"])) |
| 499 | - $curfilename=urldecode($_REQUEST["fn"]); |
|
| 499 | + $curfilename=urldecode($_REQUEST["fn"]); |
|
| 500 | 500 | else |
| 501 | - $curfilename=""; |
|
| 501 | + $curfilename=""; |
|
| 502 | 502 | |
| 503 | 503 | // Recognize GZip filename |
| 504 | 504 | |
| 505 | 505 | if (preg_match("/\.gz$/i",$curfilename)) |
| 506 | - $gzipmode=true; |
|
| 506 | + $gzipmode=true; |
|
| 507 | 507 | else |
| 508 | - $gzipmode=false; |
|
| 508 | + $gzipmode=false; |
|
| 509 | 509 | |
| 510 | 510 | if ((!$gzipmode && !$file=@fopen($curfilename,"r")) || ($gzipmode && !$file=@gzopen($curfilename,"r"))) |
| 511 | 511 | { echo ("<p class=\"error\">Can't open ".$curfilename." for import</p>\n"); |
| 512 | - echo ("<p>Please, check that your dump file name contains only alphanumerical characters, and rename it accordingly, for example: $curfilename.". |
|
| 513 | - "<br>Or, specify \$filename in bigdump.php with the full filename. ". |
|
| 514 | - "<br>Or, you have to upload the $curfilename to the server first.</p>\n"); |
|
| 515 | - $error=true; |
|
| 512 | + echo ("<p>Please, check that your dump file name contains only alphanumerical characters, and rename it accordingly, for example: $curfilename.". |
|
| 513 | + "<br>Or, specify \$filename in bigdump.php with the full filename. ". |
|
| 514 | + "<br>Or, you have to upload the $curfilename to the server first.</p>\n"); |
|
| 515 | + $error=true; |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | // Get the file size (can't do it fast on gzipped files, no idea how) |
| 519 | 519 | |
| 520 | 520 | else if ((!$gzipmode && @fseek($file, 0, SEEK_END)==0) || ($gzipmode && @gzseek($file, 0)==0)) |
| 521 | 521 | { if (!$gzipmode) $filesize = ftell($file); |
| 522 | - else $filesize = gztell($file); // Always zero, ignore |
|
| 522 | + else $filesize = gztell($file); // Always zero, ignore |
|
| 523 | 523 | } |
| 524 | 524 | else |
| 525 | 525 | { echo ("<p class=\"error\">I can't seek into $curfilename</p>\n"); |
| 526 | - $error=true; |
|
| 526 | + $error=true; |
|
| 527 | 527 | } |
| 528 | 528 | } |
| 529 | 529 | |
@@ -546,171 +546,171 @@ discard block |
||
| 546 | 546 | |
| 547 | 547 | if (!is_numeric($_REQUEST["start"]) || !is_numeric($_REQUEST["foffset"])) |
| 548 | 548 | { echo ("<p class=\"error\">UNEXPECTED: Non-numeric values for start and foffset</p>\n"); |
| 549 | - $error=true; |
|
| 549 | + $error=true; |
|
| 550 | 550 | } |
| 551 | 551 | else |
| 552 | 552 | { $_REQUEST["start"] = floor($_REQUEST["start"]); |
| 553 | - $_REQUEST["foffset"] = floor($_REQUEST["foffset"]); |
|
| 553 | + $_REQUEST["foffset"] = floor($_REQUEST["foffset"]); |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | // Set the current delimiter if defined |
| 557 | 557 | |
| 558 | 558 | if (isset($_REQUEST["delimiter"])) |
| 559 | - $delimiter = $_REQUEST["delimiter"]; |
|
| 559 | + $delimiter = $_REQUEST["delimiter"]; |
|
| 560 | 560 | |
| 561 | 561 | // Empty CSV table if requested |
| 562 | 562 | |
| 563 | 563 | if (!$error && $_REQUEST["start"]==1 && $csv_insert_table != "" && $csv_preempty_table) |
| 564 | 564 | { |
| 565 | - $query = "DELETE FROM $csv_insert_table"; |
|
| 566 | - if (!TESTMODE && !mysql_query(trim($query), $dbconnection)) |
|
| 567 | - { echo ("<p class=\"error\">Error when deleting entries from $csv_insert_table.</p>\n"); |
|
| 568 | - echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n"); |
|
| 569 | - echo ("<p>MySQL: ".mysql_error()."</p>\n"); |
|
| 570 | - $error=true; |
|
| 571 | - } |
|
| 565 | + $query = "DELETE FROM $csv_insert_table"; |
|
| 566 | + if (!TESTMODE && !mysql_query(trim($query), $dbconnection)) |
|
| 567 | + { echo ("<p class=\"error\">Error when deleting entries from $csv_insert_table.</p>\n"); |
|
| 568 | + echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n"); |
|
| 569 | + echo ("<p>MySQL: ".mysql_error()."</p>\n"); |
|
| 570 | + $error=true; |
|
| 571 | + } |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | // Print start message |
| 575 | 575 | |
| 576 | 576 | if (!$error) |
| 577 | 577 | { skin_open(); |
| 578 | - if (TESTMODE) |
|
| 579 | - echo ("<p class=\"centr\">TEST MODE ENABLED</p>\n"); |
|
| 580 | - echo ("<p class=\"centr\">Processing file: <b>".$curfilename."</b></p>\n"); |
|
| 581 | - echo ("<p class=\"smlcentr\">Starting from line: ".$_REQUEST["start"]."</p>\n"); |
|
| 582 | - skin_close(); |
|
| 578 | + if (TESTMODE) |
|
| 579 | + echo ("<p class=\"centr\">TEST MODE ENABLED</p>\n"); |
|
| 580 | + echo ("<p class=\"centr\">Processing file: <b>".$curfilename."</b></p>\n"); |
|
| 581 | + echo ("<p class=\"smlcentr\">Starting from line: ".$_REQUEST["start"]."</p>\n"); |
|
| 582 | + skin_close(); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | // Check $_REQUEST["foffset"] upon $filesize (can't do it on gzipped files) |
| 586 | 586 | |
| 587 | 587 | if (!$error && !$gzipmode && $_REQUEST["foffset"]>$filesize) |
| 588 | 588 | { echo ("<p class=\"error\">UNEXPECTED: Can't set file pointer behind the end of file</p>\n"); |
| 589 | - $error=true; |
|
| 589 | + $error=true; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | // Set file pointer to $_REQUEST["foffset"] |
| 593 | 593 | |
| 594 | 594 | if (!$error && ((!$gzipmode && fseek($file, $_REQUEST["foffset"])!=0) || ($gzipmode && gzseek($file, $_REQUEST["foffset"])!=0))) |
| 595 | 595 | { echo ("<p class=\"error\">UNEXPECTED: Can't set file pointer to offset: ".$_REQUEST["foffset"]."</p>\n"); |
| 596 | - $error=true; |
|
| 596 | + $error=true; |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | // Start processing queries from $file |
| 600 | 600 | |
| 601 | 601 | if (!$error) |
| 602 | 602 | { $query=""; |
| 603 | - $queries=0; |
|
| 604 | - $totalqueries=$_REQUEST["totalqueries"]; |
|
| 605 | - $linenumber=$_REQUEST["start"]; |
|
| 606 | - $querylines=0; |
|
| 607 | - $inparents=false; |
|
| 603 | + $queries=0; |
|
| 604 | + $totalqueries=$_REQUEST["totalqueries"]; |
|
| 605 | + $linenumber=$_REQUEST["start"]; |
|
| 606 | + $querylines=0; |
|
| 607 | + $inparents=false; |
|
| 608 | 608 | |
| 609 | 609 | // Stay processing as long as the $linespersession is not reached or the query is still incomplete |
| 610 | 610 | |
| 611 | - while ($linenumber<$_REQUEST["start"]+$linespersession || $query!="") |
|
| 612 | - { |
|
| 611 | + while ($linenumber<$_REQUEST["start"]+$linespersession || $query!="") |
|
| 612 | + { |
|
| 613 | 613 | |
| 614 | 614 | // Read the whole next line |
| 615 | 615 | |
| 616 | - $dumpline = ""; |
|
| 617 | - while (!feof($file) && substr ($dumpline, -1) != "\n" && substr ($dumpline, -1) != "\r") |
|
| 618 | - { if (!$gzipmode) |
|
| 619 | - $dumpline .= fgets($file, DATA_CHUNK_LENGTH); |
|
| 620 | - else |
|
| 621 | - $dumpline .= gzgets($file, DATA_CHUNK_LENGTH); |
|
| 622 | - } |
|
| 623 | - if ($dumpline==="") break; |
|
| 616 | + $dumpline = ""; |
|
| 617 | + while (!feof($file) && substr ($dumpline, -1) != "\n" && substr ($dumpline, -1) != "\r") |
|
| 618 | + { if (!$gzipmode) |
|
| 619 | + $dumpline .= fgets($file, DATA_CHUNK_LENGTH); |
|
| 620 | + else |
|
| 621 | + $dumpline .= gzgets($file, DATA_CHUNK_LENGTH); |
|
| 622 | + } |
|
| 623 | + if ($dumpline==="") break; |
|
| 624 | 624 | |
| 625 | 625 | // Remove UTF8 Byte Order Mark at the file beginning if any |
| 626 | 626 | |
| 627 | - if ($_REQUEST["foffset"]==0) |
|
| 628 | - $dumpline=preg_replace('|^\xEF\xBB\xBF|','',$dumpline); |
|
| 627 | + if ($_REQUEST["foffset"]==0) |
|
| 628 | + $dumpline=preg_replace('|^\xEF\xBB\xBF|','',$dumpline); |
|
| 629 | 629 | |
| 630 | 630 | // Create an SQL query from CSV line |
| 631 | 631 | |
| 632 | - if (($csv_insert_table != "") && (preg_match("/(\.csv)$/i",$curfilename))) |
|
| 633 | - { |
|
| 634 | - if ($csv_add_slashes) |
|
| 635 | - $dumpline = addslashes($dumpline); |
|
| 636 | - $dumpline = explode($csv_delimiter,$dumpline); |
|
| 637 | - if ($csv_add_quotes) |
|
| 638 | - $dumpline = "'".implode("','",$dumpline)."'"; |
|
| 639 | - else |
|
| 640 | - $dumpline = implode(",",$dumpline); |
|
| 641 | - $dumpline = 'INSERT INTO '.$csv_insert_table.' VALUES ('.$dumpline.');'; |
|
| 642 | - } |
|
| 632 | + if (($csv_insert_table != "") && (preg_match("/(\.csv)$/i",$curfilename))) |
|
| 633 | + { |
|
| 634 | + if ($csv_add_slashes) |
|
| 635 | + $dumpline = addslashes($dumpline); |
|
| 636 | + $dumpline = explode($csv_delimiter,$dumpline); |
|
| 637 | + if ($csv_add_quotes) |
|
| 638 | + $dumpline = "'".implode("','",$dumpline)."'"; |
|
| 639 | + else |
|
| 640 | + $dumpline = implode(",",$dumpline); |
|
| 641 | + $dumpline = 'INSERT INTO '.$csv_insert_table.' VALUES ('.$dumpline.');'; |
|
| 642 | + } |
|
| 643 | 643 | |
| 644 | 644 | // Handle DOS and Mac encoded linebreaks (I don't know if it really works on Win32 or Mac Servers) |
| 645 | 645 | |
| 646 | - $dumpline=str_replace("\r\n", "\n", $dumpline); |
|
| 647 | - $dumpline=str_replace("\r", "\n", $dumpline); |
|
| 646 | + $dumpline=str_replace("\r\n", "\n", $dumpline); |
|
| 647 | + $dumpline=str_replace("\r", "\n", $dumpline); |
|
| 648 | 648 | |
| 649 | 649 | // DIAGNOSTIC |
| 650 | 650 | // echo ("<p>Line $linenumber: $dumpline</p>\n"); |
| 651 | 651 | |
| 652 | 652 | // Recognize delimiter statement |
| 653 | 653 | |
| 654 | - if (!$inparents && strpos ($dumpline, "DELIMITER ") === 0) |
|
| 655 | - $delimiter = str_replace ("DELIMITER ","",trim($dumpline)); |
|
| 654 | + if (!$inparents && strpos ($dumpline, "DELIMITER ") === 0) |
|
| 655 | + $delimiter = str_replace ("DELIMITER ","",trim($dumpline)); |
|
| 656 | 656 | |
| 657 | 657 | // Skip comments and blank lines only if NOT in parents |
| 658 | 658 | |
| 659 | - if (!$inparents) |
|
| 660 | - { $skipline=false; |
|
| 661 | - reset($comment); |
|
| 662 | - foreach ($comment as $comment_value) |
|
| 663 | - { |
|
| 659 | + if (!$inparents) |
|
| 660 | + { $skipline=false; |
|
| 661 | + reset($comment); |
|
| 662 | + foreach ($comment as $comment_value) |
|
| 663 | + { |
|
| 664 | 664 | |
| 665 | 665 | // DIAGNOSTIC |
| 666 | 666 | // echo ($comment_value); |
| 667 | - if (trim($dumpline)=="" || strpos (trim($dumpline), $comment_value) === 0) |
|
| 668 | - { $skipline=true; |
|
| 669 | - break; |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - if ($skipline) |
|
| 673 | - { $linenumber++; |
|
| 667 | + if (trim($dumpline)=="" || strpos (trim($dumpline), $comment_value) === 0) |
|
| 668 | + { $skipline=true; |
|
| 669 | + break; |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + if ($skipline) |
|
| 673 | + { $linenumber++; |
|
| 674 | 674 | |
| 675 | 675 | // DIAGNOSTIC |
| 676 | 676 | // echo ("<p>Comment line skipped</p>\n"); |
| 677 | 677 | |
| 678 | - continue; |
|
| 679 | - } |
|
| 680 | - } |
|
| 678 | + continue; |
|
| 679 | + } |
|
| 680 | + } |
|
| 681 | 681 | |
| 682 | 682 | // Remove double back-slashes from the dumpline prior to count the quotes ('\\' can only be within strings) |
| 683 | 683 | |
| 684 | - $dumpline_deslashed = str_replace ("\\\\","",$dumpline); |
|
| 684 | + $dumpline_deslashed = str_replace ("\\\\","",$dumpline); |
|
| 685 | 685 | |
| 686 | 686 | // Count ' and \' (or " and \") in the dumpline to avoid query break within a text field ending by $delimiter |
| 687 | 687 | |
| 688 | - $parents=substr_count ($dumpline_deslashed, $string_quotes)-substr_count ($dumpline_deslashed, "\\$string_quotes"); |
|
| 689 | - if ($parents % 2 != 0) |
|
| 690 | - $inparents=!$inparents; |
|
| 688 | + $parents=substr_count ($dumpline_deslashed, $string_quotes)-substr_count ($dumpline_deslashed, "\\$string_quotes"); |
|
| 689 | + if ($parents % 2 != 0) |
|
| 690 | + $inparents=!$inparents; |
|
| 691 | 691 | |
| 692 | 692 | // Add the line to query |
| 693 | 693 | |
| 694 | - $query .= $dumpline; |
|
| 694 | + $query .= $dumpline; |
|
| 695 | 695 | |
| 696 | 696 | // Don't count the line if in parents (text fields may include unlimited linebreaks) |
| 697 | 697 | |
| 698 | - if (!$inparents) |
|
| 699 | - $querylines++; |
|
| 698 | + if (!$inparents) |
|
| 699 | + $querylines++; |
|
| 700 | 700 | |
| 701 | 701 | // Stop if query contains more lines as defined by MAX_QUERY_LINES |
| 702 | 702 | |
| 703 | - if ($querylines>MAX_QUERY_LINES) |
|
| 704 | - { |
|
| 705 | - echo ("<p class=\"error\">Stopped at the line $linenumber. </p>"); |
|
| 706 | - echo ("<p>At this place the current query includes more than ".MAX_QUERY_LINES." dump lines. That can happen if your dump file was "); |
|
| 707 | - echo ("created by some tool which doesn't place a semicolon followed by a linebreak at the end of each query, or if your dump contains "); |
|
| 708 | - echo ("extended inserts or very long procedure definitions. Please read the <a href=\"http://www.ozerov.de/bigdump/usage/\">BigDump usage notes</a> "); |
|
| 709 | - echo ("for more infos. Ask for our support services "); |
|
| 710 | - echo ("in order to handle dump files containing extended inserts.</p>\n"); |
|
| 711 | - $error=true; |
|
| 712 | - break; |
|
| 713 | - } |
|
| 703 | + if ($querylines>MAX_QUERY_LINES) |
|
| 704 | + { |
|
| 705 | + echo ("<p class=\"error\">Stopped at the line $linenumber. </p>"); |
|
| 706 | + echo ("<p>At this place the current query includes more than ".MAX_QUERY_LINES." dump lines. That can happen if your dump file was "); |
|
| 707 | + echo ("created by some tool which doesn't place a semicolon followed by a linebreak at the end of each query, or if your dump contains "); |
|
| 708 | + echo ("extended inserts or very long procedure definitions. Please read the <a href=\"http://www.ozerov.de/bigdump/usage/\">BigDump usage notes</a> "); |
|
| 709 | + echo ("for more infos. Ask for our support services "); |
|
| 710 | + echo ("in order to handle dump files containing extended inserts.</p>\n"); |
|
| 711 | + $error=true; |
|
| 712 | + break; |
|
| 713 | + } |
|
| 714 | 714 | |
| 715 | 715 | // Execute query if end of query detected ($delimiter as last character) AND NOT in parents |
| 716 | 716 | |
@@ -719,43 +719,43 @@ discard block |
||
| 719 | 719 | // echo ("<p>In Parents: ".($inparents?"true":"false")."</p>\n"); |
| 720 | 720 | // echo ("<p>Line: $dumpline</p>\n"); |
| 721 | 721 | |
| 722 | - if (preg_match('/'.preg_quote($delimiter).'$/',trim($dumpline)) && !$inparents) |
|
| 723 | - { |
|
| 722 | + if (preg_match('/'.preg_quote($delimiter).'$/',trim($dumpline)) && !$inparents) |
|
| 723 | + { |
|
| 724 | 724 | |
| 725 | 725 | // Cut off delimiter of the end of the query |
| 726 | 726 | |
| 727 | - $query = substr(trim($query),0,-1*strlen($delimiter)); |
|
| 727 | + $query = substr(trim($query),0,-1*strlen($delimiter)); |
|
| 728 | 728 | |
| 729 | 729 | // DIAGNOSTIC |
| 730 | 730 | // echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n"); |
| 731 | 731 | |
| 732 | - if (!TESTMODE && !mysql_query($query, $dbconnection)) |
|
| 733 | - { echo ("<p class=\"error\">Error at the line $linenumber: ". trim($dumpline)."</p>\n"); |
|
| 734 | - echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n"); |
|
| 735 | - echo ("<p>MySQL: ".mysql_error()."</p>\n"); |
|
| 736 | - $error=true; |
|
| 737 | - break; |
|
| 738 | - } |
|
| 739 | - $totalqueries++; |
|
| 740 | - $queries++; |
|
| 741 | - $query=""; |
|
| 742 | - $querylines=0; |
|
| 743 | - } |
|
| 744 | - $linenumber++; |
|
| 745 | - } |
|
| 732 | + if (!TESTMODE && !mysql_query($query, $dbconnection)) |
|
| 733 | + { echo ("<p class=\"error\">Error at the line $linenumber: ". trim($dumpline)."</p>\n"); |
|
| 734 | + echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n"); |
|
| 735 | + echo ("<p>MySQL: ".mysql_error()."</p>\n"); |
|
| 736 | + $error=true; |
|
| 737 | + break; |
|
| 738 | + } |
|
| 739 | + $totalqueries++; |
|
| 740 | + $queries++; |
|
| 741 | + $query=""; |
|
| 742 | + $querylines=0; |
|
| 743 | + } |
|
| 744 | + $linenumber++; |
|
| 745 | + } |
|
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | // Get the current file position |
| 749 | 749 | |
| 750 | 750 | if (!$error) |
| 751 | 751 | { if (!$gzipmode) |
| 752 | - $foffset = ftell($file); |
|
| 753 | - else |
|
| 754 | - $foffset = gztell($file); |
|
| 755 | - if (!$foffset) |
|
| 756 | - { echo ("<p class=\"error\">UNEXPECTED: Can't read the file pointer offset</p>\n"); |
|
| 757 | - $error=true; |
|
| 758 | - } |
|
| 752 | + $foffset = ftell($file); |
|
| 753 | + else |
|
| 754 | + $foffset = gztell($file); |
|
| 755 | + if (!$foffset) |
|
| 756 | + { echo ("<p class=\"error\">UNEXPECTED: Can't read the file pointer offset</p>\n"); |
|
| 757 | + $error=true; |
|
| 758 | + } |
|
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | // Print statistics |
@@ -766,63 +766,63 @@ discard block |
||
| 766 | 766 | |
| 767 | 767 | if (!$error) |
| 768 | 768 | { |
| 769 | - $lines_this = $linenumber-$_REQUEST["start"]; |
|
| 770 | - $lines_done = $linenumber-1; |
|
| 771 | - $lines_togo = ' ? '; |
|
| 772 | - $lines_tota = ' ? '; |
|
| 769 | + $lines_this = $linenumber-$_REQUEST["start"]; |
|
| 770 | + $lines_done = $linenumber-1; |
|
| 771 | + $lines_togo = ' ? '; |
|
| 772 | + $lines_tota = ' ? '; |
|
| 773 | 773 | |
| 774 | - $queries_this = $queries; |
|
| 775 | - $queries_done = $totalqueries; |
|
| 776 | - $queries_togo = ' ? '; |
|
| 777 | - $queries_tota = ' ? '; |
|
| 778 | - |
|
| 779 | - $bytes_this = $foffset-$_REQUEST["foffset"]; |
|
| 780 | - $bytes_done = $foffset; |
|
| 781 | - $kbytes_this = round($bytes_this/1024,2); |
|
| 782 | - $kbytes_done = round($bytes_done/1024,2); |
|
| 783 | - $mbytes_this = round($kbytes_this/1024,2); |
|
| 784 | - $mbytes_done = round($kbytes_done/1024,2); |
|
| 774 | + $queries_this = $queries; |
|
| 775 | + $queries_done = $totalqueries; |
|
| 776 | + $queries_togo = ' ? '; |
|
| 777 | + $queries_tota = ' ? '; |
|
| 778 | + |
|
| 779 | + $bytes_this = $foffset-$_REQUEST["foffset"]; |
|
| 780 | + $bytes_done = $foffset; |
|
| 781 | + $kbytes_this = round($bytes_this/1024,2); |
|
| 782 | + $kbytes_done = round($bytes_done/1024,2); |
|
| 783 | + $mbytes_this = round($kbytes_this/1024,2); |
|
| 784 | + $mbytes_done = round($kbytes_done/1024,2); |
|
| 785 | 785 | |
| 786 | - if (!$gzipmode) |
|
| 787 | - { |
|
| 788 | - $bytes_togo = $filesize-$foffset; |
|
| 789 | - $bytes_tota = $filesize; |
|
| 790 | - $kbytes_togo = round($bytes_togo/1024,2); |
|
| 791 | - $kbytes_tota = round($bytes_tota/1024,2); |
|
| 792 | - $mbytes_togo = round($kbytes_togo/1024,2); |
|
| 793 | - $mbytes_tota = round($kbytes_tota/1024,2); |
|
| 786 | + if (!$gzipmode) |
|
| 787 | + { |
|
| 788 | + $bytes_togo = $filesize-$foffset; |
|
| 789 | + $bytes_tota = $filesize; |
|
| 790 | + $kbytes_togo = round($bytes_togo/1024,2); |
|
| 791 | + $kbytes_tota = round($bytes_tota/1024,2); |
|
| 792 | + $mbytes_togo = round($kbytes_togo/1024,2); |
|
| 793 | + $mbytes_tota = round($kbytes_tota/1024,2); |
|
| 794 | 794 | |
| 795 | - $pct_this = ceil($bytes_this/$filesize*100); |
|
| 796 | - $pct_done = ceil($foffset/$filesize*100); |
|
| 797 | - $pct_togo = 100 - $pct_done; |
|
| 798 | - $pct_tota = 100; |
|
| 799 | - |
|
| 800 | - if ($bytes_togo==0) |
|
| 801 | - { $lines_togo = '0'; |
|
| 802 | - $lines_tota = $linenumber-1; |
|
| 803 | - $queries_togo = '0'; |
|
| 804 | - $queries_tota = $totalqueries; |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - $pct_bar = "<div style=\"height:15px;width:$pct_done%;background-color:#000080;margin:0px;\"></div>"; |
|
| 808 | - } |
|
| 809 | - else |
|
| 810 | - { |
|
| 811 | - $bytes_togo = ' ? '; |
|
| 812 | - $bytes_tota = ' ? '; |
|
| 813 | - $kbytes_togo = ' ? '; |
|
| 814 | - $kbytes_tota = ' ? '; |
|
| 815 | - $mbytes_togo = ' ? '; |
|
| 816 | - $mbytes_tota = ' ? '; |
|
| 795 | + $pct_this = ceil($bytes_this/$filesize*100); |
|
| 796 | + $pct_done = ceil($foffset/$filesize*100); |
|
| 797 | + $pct_togo = 100 - $pct_done; |
|
| 798 | + $pct_tota = 100; |
|
| 799 | + |
|
| 800 | + if ($bytes_togo==0) |
|
| 801 | + { $lines_togo = '0'; |
|
| 802 | + $lines_tota = $linenumber-1; |
|
| 803 | + $queries_togo = '0'; |
|
| 804 | + $queries_tota = $totalqueries; |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + $pct_bar = "<div style=\"height:15px;width:$pct_done%;background-color:#000080;margin:0px;\"></div>"; |
|
| 808 | + } |
|
| 809 | + else |
|
| 810 | + { |
|
| 811 | + $bytes_togo = ' ? '; |
|
| 812 | + $bytes_tota = ' ? '; |
|
| 813 | + $kbytes_togo = ' ? '; |
|
| 814 | + $kbytes_tota = ' ? '; |
|
| 815 | + $mbytes_togo = ' ? '; |
|
| 816 | + $mbytes_tota = ' ? '; |
|
| 817 | 817 | |
| 818 | - $pct_this = ' ? '; |
|
| 819 | - $pct_done = ' ? '; |
|
| 820 | - $pct_togo = ' ? '; |
|
| 821 | - $pct_tota = 100; |
|
| 822 | - $pct_bar = str_replace(' ',' ','<tt>[ Not available for gzipped files ]</tt>'); |
|
| 823 | - } |
|
| 818 | + $pct_this = ' ? '; |
|
| 819 | + $pct_done = ' ? '; |
|
| 820 | + $pct_togo = ' ? '; |
|
| 821 | + $pct_tota = 100; |
|
| 822 | + $pct_bar = str_replace(' ',' ','<tt>[ Not available for gzipped files ]</tt>'); |
|
| 823 | + } |
|
| 824 | 824 | |
| 825 | - echo (" |
|
| 825 | + echo (" |
|
| 826 | 826 | <center> |
| 827 | 827 | <table width=\"520\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\"> |
| 828 | 828 | <tr><th class=\"bg4\"> </th><th class=\"bg4\">Session</th><th class=\"bg4\">Done</th><th class=\"bg4\">To go</th><th class=\"bg4\">Total</th></tr> |
@@ -839,11 +839,11 @@ discard block |
||
| 839 | 839 | |
| 840 | 840 | // Finish message and restart the script |
| 841 | 841 | |
| 842 | - if ($linenumber<$_REQUEST["start"]+$linespersession) |
|
| 843 | - { echo ("<p class=\"successcentr\">Congratulations: End of file reached, assuming OK</p>\n"); |
|
| 844 | - echo ("<p class=\"successcentr\">IMPORTANT: REMOVE YOUR DUMP FILE and BIGDUMP SCRIPT FROM SERVER NOW!</p>\n"); |
|
| 845 | - echo ("<p class=\"centr\">Thank you for using this tool! Please rate <a href=\"http://www.hotscripts.com/listing/bigdump/?RID=403\" target=\"_blank\">Bigdump at Hotscripts.com</a></p>\n"); |
|
| 846 | - echo ("<p class=\"centr\">You can send me some bucks or euros as appreciation via PayPal. Thank you!</p>\n"); |
|
| 842 | + if ($linenumber<$_REQUEST["start"]+$linespersession) |
|
| 843 | + { echo ("<p class=\"successcentr\">Congratulations: End of file reached, assuming OK</p>\n"); |
|
| 844 | + echo ("<p class=\"successcentr\">IMPORTANT: REMOVE YOUR DUMP FILE and BIGDUMP SCRIPT FROM SERVER NOW!</p>\n"); |
|
| 845 | + echo ("<p class=\"centr\">Thank you for using this tool! Please rate <a href=\"http://www.hotscripts.com/listing/bigdump/?RID=403\" target=\"_blank\">Bigdump at Hotscripts.com</a></p>\n"); |
|
| 846 | + echo ("<p class=\"centr\">You can send me some bucks or euros as appreciation via PayPal. Thank you!</p>\n"); |
|
| 847 | 847 | ?> |
| 848 | 848 | |
| 849 | 849 | <!-- Start Paypal donation code --> |
@@ -863,23 +863,23 @@ discard block |
||
| 863 | 863 | |
| 864 | 864 | <?php |
| 865 | 865 | |
| 866 | - $error=true; // This is a semi-error telling the script is finished |
|
| 867 | - } |
|
| 868 | - else |
|
| 869 | - { if ($delaypersession!=0) |
|
| 870 | - echo ("<p class=\"centr\">Now I'm <b>waiting $delaypersession milliseconds</b> before starting next session...</p>\n"); |
|
| 871 | - if (!$ajax) |
|
| 872 | - echo ("<script language=\"JavaScript\" type=\"text/javascript\">window.setTimeout('location.href=\"".$_SERVER["PHP_SELF"]."?start=$linenumber&fn=".urlencode($curfilename)."&foffset=$foffset&totalqueries=$totalqueries&delimiter=".urlencode($delimiter)."\";',500+$delaypersession);</script>\n"); |
|
| 873 | - |
|
| 874 | - echo ("<noscript>\n"); |
|
| 875 | - echo ("<p class=\"centr\"><a href=\"".$_SERVER["PHP_SELF"]."?start=$linenumber&fn=".urlencode($curfilename)."&foffset=$foffset&totalqueries=$totalqueries&delimiter=".urlencode($delimiter)."\">Continue from the line $linenumber</a> (Enable JavaScript to do it automatically)</p>\n"); |
|
| 876 | - echo ("</noscript>\n"); |
|
| 866 | + $error=true; // This is a semi-error telling the script is finished |
|
| 867 | + } |
|
| 868 | + else |
|
| 869 | + { if ($delaypersession!=0) |
|
| 870 | + echo ("<p class=\"centr\">Now I'm <b>waiting $delaypersession milliseconds</b> before starting next session...</p>\n"); |
|
| 871 | + if (!$ajax) |
|
| 872 | + echo ("<script language=\"JavaScript\" type=\"text/javascript\">window.setTimeout('location.href=\"".$_SERVER["PHP_SELF"]."?start=$linenumber&fn=".urlencode($curfilename)."&foffset=$foffset&totalqueries=$totalqueries&delimiter=".urlencode($delimiter)."\";',500+$delaypersession);</script>\n"); |
|
| 873 | + |
|
| 874 | + echo ("<noscript>\n"); |
|
| 875 | + echo ("<p class=\"centr\"><a href=\"".$_SERVER["PHP_SELF"]."?start=$linenumber&fn=".urlencode($curfilename)."&foffset=$foffset&totalqueries=$totalqueries&delimiter=".urlencode($delimiter)."\">Continue from the line $linenumber</a> (Enable JavaScript to do it automatically)</p>\n"); |
|
| 876 | + echo ("</noscript>\n"); |
|
| 877 | 877 | |
| 878 | - echo ("<p class=\"centr\">Press <b><a href=\"".$_SERVER["PHP_SELF"]."\">STOP</a></b> to abort the import <b>OR WAIT!</b></p>\n"); |
|
| 879 | - } |
|
| 878 | + echo ("<p class=\"centr\">Press <b><a href=\"".$_SERVER["PHP_SELF"]."\">STOP</a></b> to abort the import <b>OR WAIT!</b></p>\n"); |
|
| 879 | + } |
|
| 880 | 880 | } |
| 881 | 881 | else |
| 882 | - echo ("<p class=\"error\">Stopped on error</p>\n"); |
|
| 882 | + echo ("<p class=\"error\">Stopped on error</p>\n"); |
|
| 883 | 883 | |
| 884 | 884 | skin_close(); |
| 885 | 885 | |
@@ -925,7 +925,7 @@ discard block |
||
| 925 | 925 | die; |
| 926 | 926 | } |
| 927 | 927 | else |
| 928 | - create_ajax_script(); |
|
| 928 | + create_ajax_script(); |
|
| 929 | 929 | } |
| 930 | 930 | |
| 931 | 931 | // Anyway put out the output from above |
@@ -47,28 +47,28 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | // Other settings (optional) |
| 49 | 49 | |
| 50 | -$filename = ''; // Specify the dump filename to suppress the file selection dialog |
|
| 51 | -$ajax = true; // AJAX mode: import will be done without refreshing the website |
|
| 52 | -$linespersession = 3000; // Lines to be executed per one import session |
|
| 53 | -$delaypersession = 0; // You can specify a sleep time in milliseconds after each session |
|
| 50 | +$filename = ''; // Specify the dump filename to suppress the file selection dialog |
|
| 51 | +$ajax = true; // AJAX mode: import will be done without refreshing the website |
|
| 52 | +$linespersession = 3000; // Lines to be executed per one import session |
|
| 53 | +$delaypersession = 0; // You can specify a sleep time in milliseconds after each session |
|
| 54 | 54 | // Works only if JavaScript is activated. Use to reduce server overrun |
| 55 | 55 | |
| 56 | 56 | // CSV related settings (only if you use a CSV dump) |
| 57 | 57 | |
| 58 | -$csv_insert_table = ''; // Destination table for CSV files |
|
| 59 | -$csv_preempty_table = false; // true: delete all entries from table specified in $csv_insert_table before processing |
|
| 60 | -$csv_delimiter = ','; // Field delimiter in CSV file |
|
| 61 | -$csv_add_quotes = true; // If your CSV data already have quotes around each field set it to false |
|
| 62 | -$csv_add_slashes = true; // If your CSV data already have slashes in front of ' and " set it to false |
|
| 58 | +$csv_insert_table = ''; // Destination table for CSV files |
|
| 59 | +$csv_preempty_table = false; // true: delete all entries from table specified in $csv_insert_table before processing |
|
| 60 | +$csv_delimiter = ','; // Field delimiter in CSV file |
|
| 61 | +$csv_add_quotes = true; // If your CSV data already have quotes around each field set it to false |
|
| 62 | +$csv_add_slashes = true; // If your CSV data already have slashes in front of ' and " set it to false |
|
| 63 | 63 | |
| 64 | 64 | // Allowed comment markers: lines starting with these strings will be ignored by BigDump |
| 65 | 65 | |
| 66 | -$comment[]='#'; // Standard comment lines are dropped by default |
|
| 67 | -$comment[]='-- '; |
|
| 68 | -$comment[]='DELIMITER'; // Ignore DELIMITER switch as it's not a valid SQL statement |
|
| 66 | +$comment[] = '#'; // Standard comment lines are dropped by default |
|
| 67 | +$comment[] = '-- '; |
|
| 68 | +$comment[] = 'DELIMITER'; // Ignore DELIMITER switch as it's not a valid SQL statement |
|
| 69 | 69 | // $comment[]='---'; // Uncomment this line if using proprietary dump created by outdated mysqldump |
| 70 | 70 | // $comment[]='CREATE DATABASE'; // Uncomment this line if your dump contains create database queries in order to ignore them |
| 71 | -$comment[]='/*!'; // Or add your own string to leave out other proprietary things |
|
| 71 | +$comment[] = '/*!'; // Or add your own string to leave out other proprietary things |
|
| 72 | 72 | |
| 73 | 73 | // Pre-queries: SQL queries to be executed at the beginning of each import session |
| 74 | 74 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | // String quotes character |
| 90 | 90 | |
| 91 | -$string_quotes = '\''; // Change to '"' if your dump file uses double qoutes for strings |
|
| 91 | +$string_quotes = '\''; // Change to '"' if your dump file uses double qoutes for strings |
|
| 92 | 92 | |
| 93 | 93 | |
| 94 | 94 | // ******************************************************************************************* |
@@ -98,10 +98,10 @@ discard block |
||
| 98 | 98 | if ($ajax) |
| 99 | 99 | ob_start(); |
| 100 | 100 | |
| 101 | -define ('VERSION','0.34b'); |
|
| 102 | -define ('DATA_CHUNK_LENGTH',16384); // How many chars are read per time |
|
| 103 | -define ('MAX_QUERY_LINES',300); // How many lines may be considered to be one query (except text lines) |
|
| 104 | -define ('TESTMODE',false); // Set to true to process the file without actually accessing the database |
|
| 101 | +define('VERSION', '0.34b'); |
|
| 102 | +define('DATA_CHUNK_LENGTH', 16384); // How many chars are read per time |
|
| 103 | +define('MAX_QUERY_LINES', 300); // How many lines may be considered to be one query (except text lines) |
|
| 104 | +define('TESTMODE', false); // Set to true to process the file without actually accessing the database |
|
| 105 | 105 | |
| 106 | 106 | header("Expires: Mon, 1 Dec 2003 01:00:00 GMT"); |
| 107 | 107 | header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | foreach ($_REQUEST as $key => $val) |
| 121 | 121 | { |
| 122 | - $val = preg_replace("/[^_A-Za-z0-9-\.&= ;\$]/i",'', $val); |
|
| 122 | + $val = preg_replace("/[^_A-Za-z0-9-\.&= ;\$]/i", '', $val); |
|
| 123 | 123 | $_REQUEST[$key] = $val; |
| 124 | 124 | } |
| 125 | 125 | |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | skin_open(); |
| 275 | -echo ('<h1>BigDump: Staggered MySQL Dump Importer v'.VERSION.'</h1>'); |
|
| 275 | +echo ('<h1>BigDump: Staggered MySQL Dump Importer v' . VERSION . '</h1>'); |
|
| 276 | 276 | skin_close(); |
| 277 | 277 | |
| 278 | 278 | $error = false; |
@@ -281,56 +281,56 @@ discard block |
||
| 281 | 281 | // Check PHP version |
| 282 | 282 | |
| 283 | 283 | if (!$error && !function_exists('version_compare')) |
| 284 | -{ echo ("<p class=\"error\">PHP version 4.1.0 is required for BigDump to proceed. You have PHP ".phpversion()." installed. Sorry!</p>\n"); |
|
| 285 | - $error=true; |
|
| 284 | +{ echo ("<p class=\"error\">PHP version 4.1.0 is required for BigDump to proceed. You have PHP " . phpversion() . " installed. Sorry!</p>\n"); |
|
| 285 | + $error = true; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // Check if mysql extension is available |
| 289 | 289 | |
| 290 | 290 | if (!$error && !function_exists('mysql_connect')) |
| 291 | 291 | { echo ("<p class=\"error\">There is no mySQL extension available in your PHP installation. Sorry!</p>\n"); |
| 292 | - $error=true; |
|
| 292 | + $error = true; |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | // Calculate PHP max upload size (handle settings like 10M or 100K) |
| 296 | 296 | |
| 297 | 297 | if (!$error) |
| 298 | -{ $upload_max_filesize=ini_get("upload_max_filesize"); |
|
| 299 | - if (preg_match("/([0-9]+)K/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024; |
|
| 300 | - if (preg_match("/([0-9]+)M/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024*1024; |
|
| 301 | - if (preg_match("/([0-9]+)G/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024*1024*1024; |
|
| 298 | +{ $upload_max_filesize = ini_get("upload_max_filesize"); |
|
| 299 | + if (preg_match("/([0-9]+)K/i", $upload_max_filesize, $tempregs)) $upload_max_filesize = $tempregs[1] * 1024; |
|
| 300 | + if (preg_match("/([0-9]+)M/i", $upload_max_filesize, $tempregs)) $upload_max_filesize = $tempregs[1] * 1024 * 1024; |
|
| 301 | + if (preg_match("/([0-9]+)G/i", $upload_max_filesize, $tempregs)) $upload_max_filesize = $tempregs[1] * 1024 * 1024 * 1024; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | // Get the current directory |
| 305 | 305 | |
| 306 | 306 | if (isset($_SERVER["CGIA"])) |
| 307 | - $upload_dir=dirname($_SERVER["CGIA"]); |
|
| 307 | + $upload_dir = dirname($_SERVER["CGIA"]); |
|
| 308 | 308 | else if (isset($_SERVER["ORIG_PATH_TRANSLATED"])) |
| 309 | - $upload_dir=dirname($_SERVER["ORIG_PATH_TRANSLATED"]); |
|
| 309 | + $upload_dir = dirname($_SERVER["ORIG_PATH_TRANSLATED"]); |
|
| 310 | 310 | else if (isset($_SERVER["ORIG_SCRIPT_FILENAME"])) |
| 311 | - $upload_dir=dirname($_SERVER["ORIG_SCRIPT_FILENAME"]); |
|
| 311 | + $upload_dir = dirname($_SERVER["ORIG_SCRIPT_FILENAME"]); |
|
| 312 | 312 | else if (isset($_SERVER["PATH_TRANSLATED"])) |
| 313 | - $upload_dir=dirname($_SERVER["PATH_TRANSLATED"]); |
|
| 313 | + $upload_dir = dirname($_SERVER["PATH_TRANSLATED"]); |
|
| 314 | 314 | else |
| 315 | - $upload_dir=dirname($_SERVER["SCRIPT_FILENAME"]); |
|
| 315 | + $upload_dir = dirname($_SERVER["SCRIPT_FILENAME"]); |
|
| 316 | 316 | |
| 317 | 317 | // Handle file upload |
| 318 | 318 | |
| 319 | 319 | if (!$error && isset($_REQUEST["uploadbutton"])) |
| 320 | -{ if (is_uploaded_file($_FILES["dumpfile"]["tmp_name"]) && ($_FILES["dumpfile"]["error"])==0) |
|
| 320 | +{ if (is_uploaded_file($_FILES["dumpfile"]["tmp_name"]) && ($_FILES["dumpfile"]["error"]) == 0) |
|
| 321 | 321 | { |
| 322 | - $uploaded_filename=str_replace(" ","_",$_FILES["dumpfile"]["name"]); |
|
| 323 | - $uploaded_filename=preg_replace("/[^_A-Za-z0-9-\.]/i",'',$uploaded_filename); |
|
| 324 | - $uploaded_filepath=str_replace("\\","/",$upload_dir."/".$uploaded_filename); |
|
| 322 | + $uploaded_filename = str_replace(" ", "_", $_FILES["dumpfile"]["name"]); |
|
| 323 | + $uploaded_filename = preg_replace("/[^_A-Za-z0-9-\.]/i", '', $uploaded_filename); |
|
| 324 | + $uploaded_filepath = str_replace("\\", "/", $upload_dir . "/" . $uploaded_filename); |
|
| 325 | 325 | |
| 326 | 326 | if (file_exists($uploaded_filename)) |
| 327 | 327 | { echo ("<p class=\"error\">File $uploaded_filename already exist! Delete and upload again!</p>\n"); |
| 328 | 328 | } |
| 329 | - else if (!preg_match("/(\.(sql|gz|csv))$/i",$uploaded_filename)) |
|
| 329 | + else if (!preg_match("/(\.(sql|gz|csv))$/i", $uploaded_filename)) |
|
| 330 | 330 | { echo ("<p class=\"error\">You may only upload .sql .gz or .csv files.</p>\n"); |
| 331 | 331 | } |
| 332 | - else if (!@move_uploaded_file($_FILES["dumpfile"]["tmp_name"],$uploaded_filepath)) |
|
| 333 | - { echo ("<p class=\"error\">Error moving uploaded file ".$_FILES["dumpfile"]["tmp_name"]." to the $uploaded_filepath</p>\n"); |
|
| 332 | + else if (!@move_uploaded_file($_FILES["dumpfile"]["tmp_name"], $uploaded_filepath)) |
|
| 333 | + { echo ("<p class=\"error\">Error moving uploaded file " . $_FILES["dumpfile"]["tmp_name"] . " to the $uploaded_filepath</p>\n"); |
|
| 334 | 334 | echo ("<p>Check the directory permissions for $upload_dir (must be 777)!</p>\n"); |
| 335 | 335 | } |
| 336 | 336 | else |
@@ -338,42 +338,42 @@ discard block |
||
| 338 | 338 | } |
| 339 | 339 | } |
| 340 | 340 | else |
| 341 | - { echo ("<p class=\"error\">Error uploading file ".$_FILES["dumpfile"]["name"]."</p>\n"); |
|
| 341 | + { echo ("<p class=\"error\">Error uploading file " . $_FILES["dumpfile"]["name"] . "</p>\n"); |
|
| 342 | 342 | } |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | |
| 346 | 346 | // Handle file deletion (delete only in the current directory for security reasons) |
| 347 | 347 | |
| 348 | -if (!$error && isset($_REQUEST["delete"]) && $_REQUEST["delete"]!=basename($_SERVER["SCRIPT_FILENAME"])) |
|
| 349 | -{ if (preg_match("/(\.(sql|gz|csv))$/i",$_REQUEST["delete"]) && @unlink(basename($_REQUEST["delete"]))) |
|
| 350 | - echo ("<p class=\"success\">".$_REQUEST["delete"]." was removed successfully</p>\n"); |
|
| 348 | +if (!$error && isset($_REQUEST["delete"]) && $_REQUEST["delete"] != basename($_SERVER["SCRIPT_FILENAME"])) |
|
| 349 | +{ if (preg_match("/(\.(sql|gz|csv))$/i", $_REQUEST["delete"]) && @unlink(basename($_REQUEST["delete"]))) |
|
| 350 | + echo ("<p class=\"success\">" . $_REQUEST["delete"] . " was removed successfully</p>\n"); |
|
| 351 | 351 | else |
| 352 | - echo ("<p class=\"error\">Can't remove ".$_REQUEST["delete"]."</p>\n"); |
|
| 352 | + echo ("<p class=\"error\">Can't remove " . $_REQUEST["delete"] . "</p>\n"); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | // Connect to the database, set charset and execute pre-queries |
| 356 | 356 | |
| 357 | 357 | if (!$error && !TESTMODE) |
| 358 | -{ $dbconnection = @mysql_connect($db_server,$db_username,$db_password); |
|
| 358 | +{ $dbconnection = @mysql_connect($db_server, $db_username, $db_password); |
|
| 359 | 359 | if ($dbconnection) |
| 360 | 360 | $db = mysql_select_db($db_name); |
| 361 | 361 | if (!$dbconnection || !$db) |
| 362 | - { echo ("<p class=\"error\">Database connection failed due to ".mysql_error()."</p>\n"); |
|
| 363 | - echo ("<p>Edit the database settings in ".$_SERVER["SCRIPT_FILENAME"]." or contact your database provider.</p>\n"); |
|
| 364 | - $error=true; |
|
| 362 | + { echo ("<p class=\"error\">Database connection failed due to " . mysql_error() . "</p>\n"); |
|
| 363 | + echo ("<p>Edit the database settings in " . $_SERVER["SCRIPT_FILENAME"] . " or contact your database provider.</p>\n"); |
|
| 364 | + $error = true; |
|
| 365 | 365 | } |
| 366 | - if (!$error && $db_connection_charset!=='') |
|
| 366 | + if (!$error && $db_connection_charset !== '') |
|
| 367 | 367 | @mysql_query("SET NAMES $db_connection_charset", $dbconnection); |
| 368 | 368 | |
| 369 | - if (!$error && isset ($pre_query) && sizeof ($pre_query)>0) |
|
| 369 | + if (!$error && isset ($pre_query) && sizeof($pre_query) > 0) |
|
| 370 | 370 | { reset($pre_query); |
| 371 | 371 | foreach ($pre_query as $pre_query_value) |
| 372 | 372 | { if (!@mysql_query($pre_query_value, $dbconnection)) |
| 373 | 373 | { echo ("<p class=\"error\">Error with pre-query.</p>\n"); |
| 374 | - echo ("<p>Query: ".trim(nl2br(htmlentities($pre_query_value)))."</p>\n"); |
|
| 375 | - echo ("<p>MySQL: ".mysql_error()."</p>\n"); |
|
| 376 | - $error=true; |
|
| 374 | + echo ("<p>Query: " . trim(nl2br(htmlentities($pre_query_value))) . "</p>\n"); |
|
| 375 | + echo ("<p>MySQL: " . mysql_error() . "</p>\n"); |
|
| 376 | + $error = true; |
|
| 377 | 377 | break; |
| 378 | 378 | } |
| 379 | 379 | } |
@@ -389,38 +389,38 @@ discard block |
||
| 389 | 389 | |
| 390 | 390 | // List uploaded files in multifile mode |
| 391 | 391 | |
| 392 | -if (!$error && !isset($_REQUEST["fn"]) && $filename=="") |
|
| 392 | +if (!$error && !isset($_REQUEST["fn"]) && $filename == "") |
|
| 393 | 393 | { if ($dirhandle = opendir($upload_dir)) |
| 394 | 394 | { |
| 395 | - $files=array(); |
|
| 395 | + $files = array(); |
|
| 396 | 396 | while (false !== ($files[] = readdir($dirhandle))); |
| 397 | 397 | closedir($dirhandle); |
| 398 | - $dirhead=false; |
|
| 398 | + $dirhead = false; |
|
| 399 | 399 | |
| 400 | - if (sizeof($files)>0) |
|
| 400 | + if (sizeof($files) > 0) |
|
| 401 | 401 | { |
| 402 | 402 | sort($files); |
| 403 | 403 | foreach ($files as $dirfile) |
| 404 | 404 | { |
| 405 | - if ($dirfile != "." && $dirfile != ".." && $dirfile!=basename($_SERVER["SCRIPT_FILENAME"]) && preg_match("/\.(sql|gz|csv)$/i",$dirfile)) |
|
| 405 | + if ($dirfile != "." && $dirfile != ".." && $dirfile != basename($_SERVER["SCRIPT_FILENAME"]) && preg_match("/\.(sql|gz|csv)$/i", $dirfile)) |
|
| 406 | 406 | { if (!$dirhead) |
| 407 | 407 | { echo ("<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\">\n"); |
| 408 | 408 | echo ("<tr><th>Filename</th><th>Size</th><th>Date&Time</th><th>Type</th><th> </th><th> </th>\n"); |
| 409 | - $dirhead=true; |
|
| 409 | + $dirhead = true; |
|
| 410 | 410 | } |
| 411 | - echo ("<tr><td>$dirfile</td><td class=\"right\">".filesize($dirfile)."</td><td>".date ("Y-m-d H:i:s", filemtime($dirfile))."</td>"); |
|
| 411 | + echo ("<tr><td>$dirfile</td><td class=\"right\">" . filesize($dirfile) . "</td><td>" . date("Y-m-d H:i:s", filemtime($dirfile)) . "</td>"); |
|
| 412 | 412 | |
| 413 | - if (preg_match("/\.sql$/i",$dirfile)) |
|
| 413 | + if (preg_match("/\.sql$/i", $dirfile)) |
|
| 414 | 414 | echo ("<td>SQL</td>"); |
| 415 | - elseif (preg_match("/\.gz$/i",$dirfile)) |
|
| 415 | + elseif (preg_match("/\.gz$/i", $dirfile)) |
|
| 416 | 416 | echo ("<td>GZip</td>"); |
| 417 | - elseif (preg_match("/\.csv$/i",$dirfile)) |
|
| 417 | + elseif (preg_match("/\.csv$/i", $dirfile)) |
|
| 418 | 418 | echo ("<td>CSV</td>"); |
| 419 | 419 | else |
| 420 | 420 | echo ("<td>Misc</td>"); |
| 421 | 421 | |
| 422 | - if ((preg_match("/\.gz$/i",$dirfile) && function_exists("gzopen")) || preg_match("/\.sql$/i",$dirfile) || preg_match("/\.csv$/i",$dirfile)) |
|
| 423 | - echo ("<td><a href=\"".$_SERVER["PHP_SELF"]."?start=1&fn=".urlencode($dirfile)."&foffset=0&totalqueries=0&delimiter=".urlencode($delimiter)."\">Start Import</a> into $db_name at $db_server</td>\n <td><a href=\"".$_SERVER["PHP_SELF"]."?delete=".urlencode($dirfile)."\">Delete file</a></td></tr>\n"); |
|
| 422 | + if ((preg_match("/\.gz$/i", $dirfile) && function_exists("gzopen")) || preg_match("/\.sql$/i", $dirfile) || preg_match("/\.csv$/i", $dirfile)) |
|
| 423 | + echo ("<td><a href=\"" . $_SERVER["PHP_SELF"] . "?start=1&fn=" . urlencode($dirfile) . "&foffset=0&totalqueries=0&delimiter=" . urlencode($delimiter) . "\">Start Import</a> into $db_name at $db_server</td>\n <td><a href=\"" . $_SERVER["PHP_SELF"] . "?delete=" . urlencode($dirfile) . "\">Delete file</a></td></tr>\n"); |
|
| 424 | 424 | else |
| 425 | 425 | echo ("<td> </td>\n <td> </td></tr>\n"); |
| 426 | 426 | } |
@@ -434,35 +434,35 @@ discard block |
||
| 434 | 434 | } |
| 435 | 435 | else |
| 436 | 436 | { echo ("<p class=\"error\">Error listing directory $upload_dir</p>\n"); |
| 437 | - $error=true; |
|
| 437 | + $error = true; |
|
| 438 | 438 | } |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | |
| 442 | 442 | // Single file mode |
| 443 | 443 | |
| 444 | -if (!$error && !isset ($_REQUEST["fn"]) && $filename!="") |
|
| 445 | -{ echo ("<p><a href=\"".$_SERVER["PHP_SELF"]."?start=1&fn=".urlencode($filename)."&foffset=0&totalqueries=0\">Start Import</a> from $filename into $db_name at $db_server</p>\n"); |
|
| 444 | +if (!$error && !isset ($_REQUEST["fn"]) && $filename != "") |
|
| 445 | +{ echo ("<p><a href=\"" . $_SERVER["PHP_SELF"] . "?start=1&fn=" . urlencode($filename) . "&foffset=0&totalqueries=0\">Start Import</a> from $filename into $db_name at $db_server</p>\n"); |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | |
| 449 | 449 | // File Upload Form |
| 450 | 450 | |
| 451 | -if (!$error && !isset($_REQUEST["fn"]) && $filename=="") |
|
| 451 | +if (!$error && !isset($_REQUEST["fn"]) && $filename == "") |
|
| 452 | 452 | { |
| 453 | 453 | |
| 454 | 454 | // Test permissions on working directory |
| 455 | 455 | |
| 456 | - do { $tempfilename=time().".tmp"; } while (file_exists($tempfilename)); |
|
| 457 | - if (!($tempfile=@fopen($tempfilename,"w"))) |
|
| 456 | + do { $tempfilename = time() . ".tmp"; } while (file_exists($tempfilename)); |
|
| 457 | + if (!($tempfile = @fopen($tempfilename, "w"))) |
|
| 458 | 458 | { echo ("<p>Upload form disabled. Permissions for the working directory <i>$upload_dir</i> <b>must be set writable for the webserver</b> in order "); |
| 459 | 459 | echo ("to upload files here. Alternatively you can upload your dump files via FTP.</p>\n"); |
| 460 | 460 | } |
| 461 | 461 | else |
| 462 | 462 | { fclose($tempfile); |
| 463 | - unlink ($tempfilename); |
|
| 463 | + unlink($tempfilename); |
|
| 464 | 464 | |
| 465 | - echo ("<p>You can now upload your dump file up to $upload_max_filesize bytes (".round ($upload_max_filesize/1024/1024)." Mbytes) "); |
|
| 465 | + echo ("<p>You can now upload your dump file up to $upload_max_filesize bytes (" . round($upload_max_filesize / 1024 / 1024) . " Mbytes) "); |
|
| 466 | 466 | echo ("directly from your browser to the server. Alternatively you can upload your dump files of any size via FTP.</p>\n"); |
| 467 | 467 | ?> |
| 468 | 468 | <form method="POST" action="<?php echo ($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data"> |
@@ -493,45 +493,45 @@ discard block |
||
| 493 | 493 | |
| 494 | 494 | // Set current filename ($filename overrides $_REQUEST["fn"] if set) |
| 495 | 495 | |
| 496 | - if ($filename!="") |
|
| 497 | - $curfilename=$filename; |
|
| 496 | + if ($filename != "") |
|
| 497 | + $curfilename = $filename; |
|
| 498 | 498 | else if (isset($_REQUEST["fn"])) |
| 499 | - $curfilename=urldecode($_REQUEST["fn"]); |
|
| 499 | + $curfilename = urldecode($_REQUEST["fn"]); |
|
| 500 | 500 | else |
| 501 | - $curfilename=""; |
|
| 501 | + $curfilename = ""; |
|
| 502 | 502 | |
| 503 | 503 | // Recognize GZip filename |
| 504 | 504 | |
| 505 | - if (preg_match("/\.gz$/i",$curfilename)) |
|
| 506 | - $gzipmode=true; |
|
| 505 | + if (preg_match("/\.gz$/i", $curfilename)) |
|
| 506 | + $gzipmode = true; |
|
| 507 | 507 | else |
| 508 | - $gzipmode=false; |
|
| 508 | + $gzipmode = false; |
|
| 509 | 509 | |
| 510 | - if ((!$gzipmode && !$file=@fopen($curfilename,"r")) || ($gzipmode && !$file=@gzopen($curfilename,"r"))) |
|
| 511 | - { echo ("<p class=\"error\">Can't open ".$curfilename." for import</p>\n"); |
|
| 512 | - echo ("<p>Please, check that your dump file name contains only alphanumerical characters, and rename it accordingly, for example: $curfilename.". |
|
| 513 | - "<br>Or, specify \$filename in bigdump.php with the full filename. ". |
|
| 510 | + if ((!$gzipmode && !$file = @fopen($curfilename, "r")) || ($gzipmode && !$file = @gzopen($curfilename, "r"))) |
|
| 511 | + { echo ("<p class=\"error\">Can't open " . $curfilename . " for import</p>\n"); |
|
| 512 | + echo ("<p>Please, check that your dump file name contains only alphanumerical characters, and rename it accordingly, for example: $curfilename." . |
|
| 513 | + "<br>Or, specify \$filename in bigdump.php with the full filename. " . |
|
| 514 | 514 | "<br>Or, you have to upload the $curfilename to the server first.</p>\n"); |
| 515 | - $error=true; |
|
| 515 | + $error = true; |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | // Get the file size (can't do it fast on gzipped files, no idea how) |
| 519 | 519 | |
| 520 | - else if ((!$gzipmode && @fseek($file, 0, SEEK_END)==0) || ($gzipmode && @gzseek($file, 0)==0)) |
|
| 520 | + else if ((!$gzipmode && @fseek($file, 0, SEEK_END) == 0) || ($gzipmode && @gzseek($file, 0) == 0)) |
|
| 521 | 521 | { if (!$gzipmode) $filesize = ftell($file); |
| 522 | - else $filesize = gztell($file); // Always zero, ignore |
|
| 522 | + else $filesize = gztell($file); // Always zero, ignore |
|
| 523 | 523 | } |
| 524 | 524 | else |
| 525 | 525 | { echo ("<p class=\"error\">I can't seek into $curfilename</p>\n"); |
| 526 | - $error=true; |
|
| 526 | + $error = true; |
|
| 527 | 527 | } |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | // Stop if csv file is used, but $csv_insert_table is not set |
| 531 | 531 | |
| 532 | -if (($csv_insert_table == "") && (preg_match("/(\.csv)$/i",$curfilename))) |
|
| 532 | +if (($csv_insert_table == "") && (preg_match("/(\.csv)$/i", $curfilename))) |
|
| 533 | 533 | { echo ("<p class=\"error\">You have to specify \$csv_insert_table when using a CSV file. </p>\n"); |
| 534 | - $error=true; |
|
| 534 | + $error = true; |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | |
@@ -539,14 +539,14 @@ discard block |
||
| 539 | 539 | // START IMPORT SESSION HERE |
| 540 | 540 | // ******************************************************************************************* |
| 541 | 541 | |
| 542 | -if (!$error && isset($_REQUEST["start"]) && isset($_REQUEST["foffset"]) && preg_match("/(\.(sql|gz|csv))$/i",$curfilename)) |
|
| 542 | +if (!$error && isset($_REQUEST["start"]) && isset($_REQUEST["foffset"]) && preg_match("/(\.(sql|gz|csv))$/i", $curfilename)) |
|
| 543 | 543 | { |
| 544 | 544 | |
| 545 | 545 | // Check start and foffset are numeric values |
| 546 | 546 | |
| 547 | 547 | if (!is_numeric($_REQUEST["start"]) || !is_numeric($_REQUEST["foffset"])) |
| 548 | 548 | { echo ("<p class=\"error\">UNEXPECTED: Non-numeric values for start and foffset</p>\n"); |
| 549 | - $error=true; |
|
| 549 | + $error = true; |
|
| 550 | 550 | } |
| 551 | 551 | else |
| 552 | 552 | { $_REQUEST["start"] = floor($_REQUEST["start"]); |
@@ -560,14 +560,14 @@ discard block |
||
| 560 | 560 | |
| 561 | 561 | // Empty CSV table if requested |
| 562 | 562 | |
| 563 | - if (!$error && $_REQUEST["start"]==1 && $csv_insert_table != "" && $csv_preempty_table) |
|
| 563 | + if (!$error && $_REQUEST["start"] == 1 && $csv_insert_table != "" && $csv_preempty_table) |
|
| 564 | 564 | { |
| 565 | 565 | $query = "DELETE FROM $csv_insert_table"; |
| 566 | 566 | if (!TESTMODE && !mysql_query(trim($query), $dbconnection)) |
| 567 | 567 | { echo ("<p class=\"error\">Error when deleting entries from $csv_insert_table.</p>\n"); |
| 568 | - echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n"); |
|
| 569 | - echo ("<p>MySQL: ".mysql_error()."</p>\n"); |
|
| 570 | - $error=true; |
|
| 568 | + echo ("<p>Query: " . trim(nl2br(htmlentities($query))) . "</p>\n"); |
|
| 569 | + echo ("<p>MySQL: " . mysql_error() . "</p>\n"); |
|
| 570 | + $error = true; |
|
| 571 | 571 | } |
| 572 | 572 | } |
| 573 | 573 | |
@@ -577,95 +577,95 @@ discard block |
||
| 577 | 577 | { skin_open(); |
| 578 | 578 | if (TESTMODE) |
| 579 | 579 | echo ("<p class=\"centr\">TEST MODE ENABLED</p>\n"); |
| 580 | - echo ("<p class=\"centr\">Processing file: <b>".$curfilename."</b></p>\n"); |
|
| 581 | - echo ("<p class=\"smlcentr\">Starting from line: ".$_REQUEST["start"]."</p>\n"); |
|
| 580 | + echo ("<p class=\"centr\">Processing file: <b>" . $curfilename . "</b></p>\n"); |
|
| 581 | + echo ("<p class=\"smlcentr\">Starting from line: " . $_REQUEST["start"] . "</p>\n"); |
|
| 582 | 582 | skin_close(); |
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | // Check $_REQUEST["foffset"] upon $filesize (can't do it on gzipped files) |
| 586 | 586 | |
| 587 | - if (!$error && !$gzipmode && $_REQUEST["foffset"]>$filesize) |
|
| 587 | + if (!$error && !$gzipmode && $_REQUEST["foffset"] > $filesize) |
|
| 588 | 588 | { echo ("<p class=\"error\">UNEXPECTED: Can't set file pointer behind the end of file</p>\n"); |
| 589 | - $error=true; |
|
| 589 | + $error = true; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | // Set file pointer to $_REQUEST["foffset"] |
| 593 | 593 | |
| 594 | - if (!$error && ((!$gzipmode && fseek($file, $_REQUEST["foffset"])!=0) || ($gzipmode && gzseek($file, $_REQUEST["foffset"])!=0))) |
|
| 595 | - { echo ("<p class=\"error\">UNEXPECTED: Can't set file pointer to offset: ".$_REQUEST["foffset"]."</p>\n"); |
|
| 596 | - $error=true; |
|
| 594 | + if (!$error && ((!$gzipmode && fseek($file, $_REQUEST["foffset"]) != 0) || ($gzipmode && gzseek($file, $_REQUEST["foffset"]) != 0))) |
|
| 595 | + { echo ("<p class=\"error\">UNEXPECTED: Can't set file pointer to offset: " . $_REQUEST["foffset"] . "</p>\n"); |
|
| 596 | + $error = true; |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | // Start processing queries from $file |
| 600 | 600 | |
| 601 | 601 | if (!$error) |
| 602 | - { $query=""; |
|
| 603 | - $queries=0; |
|
| 604 | - $totalqueries=$_REQUEST["totalqueries"]; |
|
| 605 | - $linenumber=$_REQUEST["start"]; |
|
| 606 | - $querylines=0; |
|
| 607 | - $inparents=false; |
|
| 602 | + { $query = ""; |
|
| 603 | + $queries = 0; |
|
| 604 | + $totalqueries = $_REQUEST["totalqueries"]; |
|
| 605 | + $linenumber = $_REQUEST["start"]; |
|
| 606 | + $querylines = 0; |
|
| 607 | + $inparents = false; |
|
| 608 | 608 | |
| 609 | 609 | // Stay processing as long as the $linespersession is not reached or the query is still incomplete |
| 610 | 610 | |
| 611 | - while ($linenumber<$_REQUEST["start"]+$linespersession || $query!="") |
|
| 611 | + while ($linenumber < $_REQUEST["start"] + $linespersession || $query != "") |
|
| 612 | 612 | { |
| 613 | 613 | |
| 614 | 614 | // Read the whole next line |
| 615 | 615 | |
| 616 | 616 | $dumpline = ""; |
| 617 | - while (!feof($file) && substr ($dumpline, -1) != "\n" && substr ($dumpline, -1) != "\r") |
|
| 617 | + while (!feof($file) && substr($dumpline, -1) != "\n" && substr($dumpline, -1) != "\r") |
|
| 618 | 618 | { if (!$gzipmode) |
| 619 | 619 | $dumpline .= fgets($file, DATA_CHUNK_LENGTH); |
| 620 | 620 | else |
| 621 | 621 | $dumpline .= gzgets($file, DATA_CHUNK_LENGTH); |
| 622 | 622 | } |
| 623 | - if ($dumpline==="") break; |
|
| 623 | + if ($dumpline === "") break; |
|
| 624 | 624 | |
| 625 | 625 | // Remove UTF8 Byte Order Mark at the file beginning if any |
| 626 | 626 | |
| 627 | - if ($_REQUEST["foffset"]==0) |
|
| 628 | - $dumpline=preg_replace('|^\xEF\xBB\xBF|','',$dumpline); |
|
| 627 | + if ($_REQUEST["foffset"] == 0) |
|
| 628 | + $dumpline = preg_replace('|^\xEF\xBB\xBF|', '', $dumpline); |
|
| 629 | 629 | |
| 630 | 630 | // Create an SQL query from CSV line |
| 631 | 631 | |
| 632 | - if (($csv_insert_table != "") && (preg_match("/(\.csv)$/i",$curfilename))) |
|
| 632 | + if (($csv_insert_table != "") && (preg_match("/(\.csv)$/i", $curfilename))) |
|
| 633 | 633 | { |
| 634 | 634 | if ($csv_add_slashes) |
| 635 | 635 | $dumpline = addslashes($dumpline); |
| 636 | - $dumpline = explode($csv_delimiter,$dumpline); |
|
| 636 | + $dumpline = explode($csv_delimiter, $dumpline); |
|
| 637 | 637 | if ($csv_add_quotes) |
| 638 | - $dumpline = "'".implode("','",$dumpline)."'"; |
|
| 638 | + $dumpline = "'" . implode("','", $dumpline) . "'"; |
|
| 639 | 639 | else |
| 640 | - $dumpline = implode(",",$dumpline); |
|
| 641 | - $dumpline = 'INSERT INTO '.$csv_insert_table.' VALUES ('.$dumpline.');'; |
|
| 640 | + $dumpline = implode(",", $dumpline); |
|
| 641 | + $dumpline = 'INSERT INTO ' . $csv_insert_table . ' VALUES (' . $dumpline . ');'; |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | // Handle DOS and Mac encoded linebreaks (I don't know if it really works on Win32 or Mac Servers) |
| 645 | 645 | |
| 646 | - $dumpline=str_replace("\r\n", "\n", $dumpline); |
|
| 647 | - $dumpline=str_replace("\r", "\n", $dumpline); |
|
| 646 | + $dumpline = str_replace("\r\n", "\n", $dumpline); |
|
| 647 | + $dumpline = str_replace("\r", "\n", $dumpline); |
|
| 648 | 648 | |
| 649 | 649 | // DIAGNOSTIC |
| 650 | 650 | // echo ("<p>Line $linenumber: $dumpline</p>\n"); |
| 651 | 651 | |
| 652 | 652 | // Recognize delimiter statement |
| 653 | 653 | |
| 654 | - if (!$inparents && strpos ($dumpline, "DELIMITER ") === 0) |
|
| 655 | - $delimiter = str_replace ("DELIMITER ","",trim($dumpline)); |
|
| 654 | + if (!$inparents && strpos($dumpline, "DELIMITER ") === 0) |
|
| 655 | + $delimiter = str_replace("DELIMITER ", "", trim($dumpline)); |
|
| 656 | 656 | |
| 657 | 657 | // Skip comments and blank lines only if NOT in parents |
| 658 | 658 | |
| 659 | 659 | if (!$inparents) |
| 660 | - { $skipline=false; |
|
| 660 | + { $skipline = false; |
|
| 661 | 661 | reset($comment); |
| 662 | 662 | foreach ($comment as $comment_value) |
| 663 | 663 | { |
| 664 | 664 | |
| 665 | 665 | // DIAGNOSTIC |
| 666 | 666 | // echo ($comment_value); |
| 667 | - if (trim($dumpline)=="" || strpos (trim($dumpline), $comment_value) === 0) |
|
| 668 | - { $skipline=true; |
|
| 667 | + if (trim($dumpline) == "" || strpos(trim($dumpline), $comment_value) === 0) |
|
| 668 | + { $skipline = true; |
|
| 669 | 669 | break; |
| 670 | 670 | } |
| 671 | 671 | } |
@@ -681,13 +681,13 @@ discard block |
||
| 681 | 681 | |
| 682 | 682 | // Remove double back-slashes from the dumpline prior to count the quotes ('\\' can only be within strings) |
| 683 | 683 | |
| 684 | - $dumpline_deslashed = str_replace ("\\\\","",$dumpline); |
|
| 684 | + $dumpline_deslashed = str_replace("\\\\", "", $dumpline); |
|
| 685 | 685 | |
| 686 | 686 | // Count ' and \' (or " and \") in the dumpline to avoid query break within a text field ending by $delimiter |
| 687 | 687 | |
| 688 | - $parents=substr_count ($dumpline_deslashed, $string_quotes)-substr_count ($dumpline_deslashed, "\\$string_quotes"); |
|
| 688 | + $parents = substr_count($dumpline_deslashed, $string_quotes) - substr_count($dumpline_deslashed, "\\$string_quotes"); |
|
| 689 | 689 | if ($parents % 2 != 0) |
| 690 | - $inparents=!$inparents; |
|
| 690 | + $inparents = !$inparents; |
|
| 691 | 691 | |
| 692 | 692 | // Add the line to query |
| 693 | 693 | |
@@ -700,15 +700,15 @@ discard block |
||
| 700 | 700 | |
| 701 | 701 | // Stop if query contains more lines as defined by MAX_QUERY_LINES |
| 702 | 702 | |
| 703 | - if ($querylines>MAX_QUERY_LINES) |
|
| 703 | + if ($querylines > MAX_QUERY_LINES) |
|
| 704 | 704 | { |
| 705 | 705 | echo ("<p class=\"error\">Stopped at the line $linenumber. </p>"); |
| 706 | - echo ("<p>At this place the current query includes more than ".MAX_QUERY_LINES." dump lines. That can happen if your dump file was "); |
|
| 706 | + echo ("<p>At this place the current query includes more than " . MAX_QUERY_LINES . " dump lines. That can happen if your dump file was "); |
|
| 707 | 707 | echo ("created by some tool which doesn't place a semicolon followed by a linebreak at the end of each query, or if your dump contains "); |
| 708 | 708 | echo ("extended inserts or very long procedure definitions. Please read the <a href=\"http://www.ozerov.de/bigdump/usage/\">BigDump usage notes</a> "); |
| 709 | 709 | echo ("for more infos. Ask for our support services "); |
| 710 | 710 | echo ("in order to handle dump files containing extended inserts.</p>\n"); |
| 711 | - $error=true; |
|
| 711 | + $error = true; |
|
| 712 | 712 | break; |
| 713 | 713 | } |
| 714 | 714 | |
@@ -719,27 +719,27 @@ discard block |
||
| 719 | 719 | // echo ("<p>In Parents: ".($inparents?"true":"false")."</p>\n"); |
| 720 | 720 | // echo ("<p>Line: $dumpline</p>\n"); |
| 721 | 721 | |
| 722 | - if (preg_match('/'.preg_quote($delimiter).'$/',trim($dumpline)) && !$inparents) |
|
| 722 | + if (preg_match('/' . preg_quote($delimiter) . '$/', trim($dumpline)) && !$inparents) |
|
| 723 | 723 | { |
| 724 | 724 | |
| 725 | 725 | // Cut off delimiter of the end of the query |
| 726 | 726 | |
| 727 | - $query = substr(trim($query),0,-1*strlen($delimiter)); |
|
| 727 | + $query = substr(trim($query), 0, -1 * strlen($delimiter)); |
|
| 728 | 728 | |
| 729 | 729 | // DIAGNOSTIC |
| 730 | 730 | // echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n"); |
| 731 | 731 | |
| 732 | 732 | if (!TESTMODE && !mysql_query($query, $dbconnection)) |
| 733 | - { echo ("<p class=\"error\">Error at the line $linenumber: ". trim($dumpline)."</p>\n"); |
|
| 734 | - echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n"); |
|
| 735 | - echo ("<p>MySQL: ".mysql_error()."</p>\n"); |
|
| 736 | - $error=true; |
|
| 733 | + { echo ("<p class=\"error\">Error at the line $linenumber: " . trim($dumpline) . "</p>\n"); |
|
| 734 | + echo ("<p>Query: " . trim(nl2br(htmlentities($query))) . "</p>\n"); |
|
| 735 | + echo ("<p>MySQL: " . mysql_error() . "</p>\n"); |
|
| 736 | + $error = true; |
|
| 737 | 737 | break; |
| 738 | 738 | } |
| 739 | 739 | $totalqueries++; |
| 740 | 740 | $queries++; |
| 741 | - $query=""; |
|
| 742 | - $querylines=0; |
|
| 741 | + $query = ""; |
|
| 742 | + $querylines = 0; |
|
| 743 | 743 | } |
| 744 | 744 | $linenumber++; |
| 745 | 745 | } |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | $foffset = gztell($file); |
| 755 | 755 | if (!$foffset) |
| 756 | 756 | { echo ("<p class=\"error\">UNEXPECTED: Can't read the file pointer offset</p>\n"); |
| 757 | - $error=true; |
|
| 757 | + $error = true; |
|
| 758 | 758 | } |
| 759 | 759 | } |
| 760 | 760 | |
@@ -766,8 +766,8 @@ discard block |
||
| 766 | 766 | |
| 767 | 767 | if (!$error) |
| 768 | 768 | { |
| 769 | - $lines_this = $linenumber-$_REQUEST["start"]; |
|
| 770 | - $lines_done = $linenumber-1; |
|
| 769 | + $lines_this = $linenumber - $_REQUEST["start"]; |
|
| 770 | + $lines_done = $linenumber - 1; |
|
| 771 | 771 | $lines_togo = ' ? '; |
| 772 | 772 | $lines_tota = ' ? '; |
| 773 | 773 | |
@@ -776,35 +776,35 @@ discard block |
||
| 776 | 776 | $queries_togo = ' ? '; |
| 777 | 777 | $queries_tota = ' ? '; |
| 778 | 778 | |
| 779 | - $bytes_this = $foffset-$_REQUEST["foffset"]; |
|
| 779 | + $bytes_this = $foffset - $_REQUEST["foffset"]; |
|
| 780 | 780 | $bytes_done = $foffset; |
| 781 | - $kbytes_this = round($bytes_this/1024,2); |
|
| 782 | - $kbytes_done = round($bytes_done/1024,2); |
|
| 783 | - $mbytes_this = round($kbytes_this/1024,2); |
|
| 784 | - $mbytes_done = round($kbytes_done/1024,2); |
|
| 781 | + $kbytes_this = round($bytes_this / 1024, 2); |
|
| 782 | + $kbytes_done = round($bytes_done / 1024, 2); |
|
| 783 | + $mbytes_this = round($kbytes_this / 1024, 2); |
|
| 784 | + $mbytes_done = round($kbytes_done / 1024, 2); |
|
| 785 | 785 | |
| 786 | 786 | if (!$gzipmode) |
| 787 | 787 | { |
| 788 | - $bytes_togo = $filesize-$foffset; |
|
| 788 | + $bytes_togo = $filesize - $foffset; |
|
| 789 | 789 | $bytes_tota = $filesize; |
| 790 | - $kbytes_togo = round($bytes_togo/1024,2); |
|
| 791 | - $kbytes_tota = round($bytes_tota/1024,2); |
|
| 792 | - $mbytes_togo = round($kbytes_togo/1024,2); |
|
| 793 | - $mbytes_tota = round($kbytes_tota/1024,2); |
|
| 790 | + $kbytes_togo = round($bytes_togo / 1024, 2); |
|
| 791 | + $kbytes_tota = round($bytes_tota / 1024, 2); |
|
| 792 | + $mbytes_togo = round($kbytes_togo / 1024, 2); |
|
| 793 | + $mbytes_tota = round($kbytes_tota / 1024, 2); |
|
| 794 | 794 | |
| 795 | - $pct_this = ceil($bytes_this/$filesize*100); |
|
| 796 | - $pct_done = ceil($foffset/$filesize*100); |
|
| 795 | + $pct_this = ceil($bytes_this / $filesize * 100); |
|
| 796 | + $pct_done = ceil($foffset / $filesize * 100); |
|
| 797 | 797 | $pct_togo = 100 - $pct_done; |
| 798 | 798 | $pct_tota = 100; |
| 799 | 799 | |
| 800 | - if ($bytes_togo==0) |
|
| 800 | + if ($bytes_togo == 0) |
|
| 801 | 801 | { $lines_togo = '0'; |
| 802 | - $lines_tota = $linenumber-1; |
|
| 802 | + $lines_tota = $linenumber - 1; |
|
| 803 | 803 | $queries_togo = '0'; |
| 804 | 804 | $queries_tota = $totalqueries; |
| 805 | 805 | } |
| 806 | 806 | |
| 807 | - $pct_bar = "<div style=\"height:15px;width:$pct_done%;background-color:#000080;margin:0px;\"></div>"; |
|
| 807 | + $pct_bar = "<div style=\"height:15px;width:$pct_done%;background-color:#000080;margin:0px;\"></div>"; |
|
| 808 | 808 | } |
| 809 | 809 | else |
| 810 | 810 | { |
@@ -819,7 +819,7 @@ discard block |
||
| 819 | 819 | $pct_done = ' ? '; |
| 820 | 820 | $pct_togo = ' ? '; |
| 821 | 821 | $pct_tota = 100; |
| 822 | - $pct_bar = str_replace(' ',' ','<tt>[ Not available for gzipped files ]</tt>'); |
|
| 822 | + $pct_bar = str_replace(' ', ' ', '<tt>[ Not available for gzipped files ]</tt>'); |
|
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | echo (" |
@@ -839,7 +839,7 @@ discard block |
||
| 839 | 839 | |
| 840 | 840 | // Finish message and restart the script |
| 841 | 841 | |
| 842 | - if ($linenumber<$_REQUEST["start"]+$linespersession) |
|
| 842 | + if ($linenumber < $_REQUEST["start"] + $linespersession) |
|
| 843 | 843 | { echo ("<p class=\"successcentr\">Congratulations: End of file reached, assuming OK</p>\n"); |
| 844 | 844 | echo ("<p class=\"successcentr\">IMPORTANT: REMOVE YOUR DUMP FILE and BIGDUMP SCRIPT FROM SERVER NOW!</p>\n"); |
| 845 | 845 | echo ("<p class=\"centr\">Thank you for using this tool! Please rate <a href=\"http://www.hotscripts.com/listing/bigdump/?RID=403\" target=\"_blank\">Bigdump at Hotscripts.com</a></p>\n"); |
@@ -863,19 +863,19 @@ discard block |
||
| 863 | 863 | |
| 864 | 864 | <?php |
| 865 | 865 | |
| 866 | - $error=true; // This is a semi-error telling the script is finished |
|
| 866 | + $error = true; // This is a semi-error telling the script is finished |
|
| 867 | 867 | } |
| 868 | 868 | else |
| 869 | - { if ($delaypersession!=0) |
|
| 869 | + { if ($delaypersession != 0) |
|
| 870 | 870 | echo ("<p class=\"centr\">Now I'm <b>waiting $delaypersession milliseconds</b> before starting next session...</p>\n"); |
| 871 | 871 | if (!$ajax) |
| 872 | - echo ("<script language=\"JavaScript\" type=\"text/javascript\">window.setTimeout('location.href=\"".$_SERVER["PHP_SELF"]."?start=$linenumber&fn=".urlencode($curfilename)."&foffset=$foffset&totalqueries=$totalqueries&delimiter=".urlencode($delimiter)."\";',500+$delaypersession);</script>\n"); |
|
| 872 | + echo ("<script language=\"JavaScript\" type=\"text/javascript\">window.setTimeout('location.href=\"" . $_SERVER["PHP_SELF"] . "?start=$linenumber&fn=" . urlencode($curfilename) . "&foffset=$foffset&totalqueries=$totalqueries&delimiter=" . urlencode($delimiter) . "\";',500+$delaypersession);</script>\n"); |
|
| 873 | 873 | |
| 874 | 874 | echo ("<noscript>\n"); |
| 875 | - echo ("<p class=\"centr\"><a href=\"".$_SERVER["PHP_SELF"]."?start=$linenumber&fn=".urlencode($curfilename)."&foffset=$foffset&totalqueries=$totalqueries&delimiter=".urlencode($delimiter)."\">Continue from the line $linenumber</a> (Enable JavaScript to do it automatically)</p>\n"); |
|
| 875 | + echo ("<p class=\"centr\"><a href=\"" . $_SERVER["PHP_SELF"] . "?start=$linenumber&fn=" . urlencode($curfilename) . "&foffset=$foffset&totalqueries=$totalqueries&delimiter=" . urlencode($delimiter) . "\">Continue from the line $linenumber</a> (Enable JavaScript to do it automatically)</p>\n"); |
|
| 876 | 876 | echo ("</noscript>\n"); |
| 877 | 877 | |
| 878 | - echo ("<p class=\"centr\">Press <b><a href=\"".$_SERVER["PHP_SELF"]."\">STOP</a></b> to abort the import <b>OR WAIT!</b></p>\n"); |
|
| 878 | + echo ("<p class=\"centr\">Press <b><a href=\"" . $_SERVER["PHP_SELF"] . "\">STOP</a></b> to abort the import <b>OR WAIT!</b></p>\n"); |
|
| 879 | 879 | } |
| 880 | 880 | } |
| 881 | 881 | else |
@@ -886,7 +886,7 @@ discard block |
||
| 886 | 886 | } |
| 887 | 887 | |
| 888 | 888 | if ($error) |
| 889 | - echo ("<p class=\"centr\"><a href=\"".$_SERVER["PHP_SELF"]."\">Start from the beginning</a> (DROP the old tables before restarting)</p>\n"); |
|
| 889 | + echo ("<p class=\"centr\"><a href=\"" . $_SERVER["PHP_SELF"] . "\">Start from the beginning</a> (DROP the old tables before restarting)</p>\n"); |
|
| 890 | 890 | |
| 891 | 891 | if ($dbconnection) mysql_close($dbconnection); |
| 892 | 892 | if ($file && !$gzipmode) fclose($file); |
@@ -947,7 +947,7 @@ discard block |
||
| 947 | 947 | $bytes_this, $bytes_done, $bytes_togo, $bytes_tota, |
| 948 | 948 | $kbytes_this, $kbytes_done, $kbytes_togo, $kbytes_tota, |
| 949 | 949 | $mbytes_this, $mbytes_done, $mbytes_togo, $mbytes_tota, |
| 950 | - $pct_this, $pct_done, $pct_togo, $pct_tota,$pct_bar; |
|
| 950 | + $pct_this, $pct_done, $pct_togo, $pct_tota, $pct_bar; |
|
| 951 | 951 | |
| 952 | 952 | header('Content-Type: application/xml'); |
| 953 | 953 | header('Cache-Control: no-cache'); |
@@ -994,7 +994,7 @@ discard block |
||
| 994 | 994 | echo "<elem22>$pct_done</elem22>"; |
| 995 | 995 | echo "<elem23>$pct_togo</elem23>"; |
| 996 | 996 | echo "<elem24>$pct_tota</elem24>"; |
| 997 | - echo "<elem_bar>".htmlentities($pct_bar)."</elem_bar>"; |
|
| 997 | + echo "<elem_bar>" . htmlentities($pct_bar) . "</elem_bar>"; |
|
| 998 | 998 | |
| 999 | 999 | echo "</root>"; |
| 1000 | 1000 | } |
@@ -1097,7 +1097,7 @@ discard block |
||
| 1097 | 1097 | // First Ajax request from initial page |
| 1098 | 1098 | |
| 1099 | 1099 | var http_request = false; |
| 1100 | - var url_request = get_url(<?php echo ($linenumber.',"'.urlencode($curfilename).'",'.$foffset.','.$totalqueries.',"'.urlencode($delimiter).'"') ;?>); |
|
| 1100 | + var url_request = get_url(<?php echo ($linenumber . ',"' . urlencode($curfilename) . '",' . $foffset . ',' . $totalqueries . ',"' . urlencode($delimiter) . '"'); ?>); |
|
| 1101 | 1101 | window.setTimeout("makeRequest(url_request)",500+<?php echo $delaypersession; ?>); |
| 1102 | 1102 | </script> |
| 1103 | 1103 | |
@@ -95,8 +95,9 @@ discard block |
||
| 95 | 95 | // If not familiar with PHP please don't change anything below this line |
| 96 | 96 | // ******************************************************************************************* |
| 97 | 97 | |
| 98 | -if ($ajax) |
|
| 98 | +if ($ajax) { |
|
| 99 | 99 | ob_start(); |
| 100 | +} |
|
| 100 | 101 | |
| 101 | 102 | define ('VERSION','0.34b'); |
| 102 | 103 | define ('DATA_CHUNK_LENGTH',16384); // How many chars are read per time |
@@ -112,8 +113,9 @@ discard block |
||
| 112 | 113 | @ini_set('auto_detect_line_endings', true); |
| 113 | 114 | @set_time_limit(0); |
| 114 | 115 | |
| 115 | -if (function_exists("date_default_timezone_set") && function_exists("date_default_timezone_get")) |
|
| 116 | +if (function_exists("date_default_timezone_set") && function_exists("date_default_timezone_get")) { |
|
| 116 | 117 | @date_default_timezone_set(@date_default_timezone_get()); |
| 118 | +} |
|
| 117 | 119 | |
| 118 | 120 | // Clean and strip anything we don't want from user's input [0.27b] |
| 119 | 121 | |
@@ -296,23 +298,30 @@ discard block |
||
| 296 | 298 | |
| 297 | 299 | if (!$error) |
| 298 | 300 | { $upload_max_filesize=ini_get("upload_max_filesize"); |
| 299 | - if (preg_match("/([0-9]+)K/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024; |
|
| 300 | - if (preg_match("/([0-9]+)M/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024*1024; |
|
| 301 | - if (preg_match("/([0-9]+)G/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024*1024*1024; |
|
| 302 | -} |
|
| 301 | + if (preg_match("/([0-9]+)K/i",$upload_max_filesize,$tempregs)) { |
|
| 302 | + $upload_max_filesize=$tempregs[1]*1024; |
|
| 303 | + } |
|
| 304 | + if (preg_match("/([0-9]+)M/i",$upload_max_filesize,$tempregs)) { |
|
| 305 | + $upload_max_filesize=$tempregs[1]*1024*1024; |
|
| 306 | + } |
|
| 307 | + if (preg_match("/([0-9]+)G/i",$upload_max_filesize,$tempregs)) { |
|
| 308 | + $upload_max_filesize=$tempregs[1]*1024*1024*1024; |
|
| 309 | + } |
|
| 310 | + } |
|
| 303 | 311 | |
| 304 | 312 | // Get the current directory |
| 305 | 313 | |
| 306 | -if (isset($_SERVER["CGIA"])) |
|
| 314 | +if (isset($_SERVER["CGIA"])) { |
|
| 307 | 315 | $upload_dir=dirname($_SERVER["CGIA"]); |
| 308 | -else if (isset($_SERVER["ORIG_PATH_TRANSLATED"])) |
|
| 316 | +} else if (isset($_SERVER["ORIG_PATH_TRANSLATED"])) { |
|
| 309 | 317 | $upload_dir=dirname($_SERVER["ORIG_PATH_TRANSLATED"]); |
| 310 | -else if (isset($_SERVER["ORIG_SCRIPT_FILENAME"])) |
|
| 318 | +} else if (isset($_SERVER["ORIG_SCRIPT_FILENAME"])) { |
|
| 311 | 319 | $upload_dir=dirname($_SERVER["ORIG_SCRIPT_FILENAME"]); |
| 312 | -else if (isset($_SERVER["PATH_TRANSLATED"])) |
|
| 320 | +} else if (isset($_SERVER["PATH_TRANSLATED"])) { |
|
| 313 | 321 | $upload_dir=dirname($_SERVER["PATH_TRANSLATED"]); |
| 314 | -else |
|
| 322 | +} else { |
|
| 315 | 323 | $upload_dir=dirname($_SERVER["SCRIPT_FILENAME"]); |
| 324 | +} |
|
| 316 | 325 | |
| 317 | 326 | // Handle file upload |
| 318 | 327 | |
@@ -325,19 +334,15 @@ discard block |
||
| 325 | 334 | |
| 326 | 335 | if (file_exists($uploaded_filename)) |
| 327 | 336 | { echo ("<p class=\"error\">File $uploaded_filename already exist! Delete and upload again!</p>\n"); |
| 328 | - } |
|
| 329 | - else if (!preg_match("/(\.(sql|gz|csv))$/i",$uploaded_filename)) |
|
| 337 | + } else if (!preg_match("/(\.(sql|gz|csv))$/i",$uploaded_filename)) |
|
| 330 | 338 | { echo ("<p class=\"error\">You may only upload .sql .gz or .csv files.</p>\n"); |
| 331 | - } |
|
| 332 | - else if (!@move_uploaded_file($_FILES["dumpfile"]["tmp_name"],$uploaded_filepath)) |
|
| 339 | + } else if (!@move_uploaded_file($_FILES["dumpfile"]["tmp_name"],$uploaded_filepath)) |
|
| 333 | 340 | { echo ("<p class=\"error\">Error moving uploaded file ".$_FILES["dumpfile"]["tmp_name"]." to the $uploaded_filepath</p>\n"); |
| 334 | 341 | echo ("<p>Check the directory permissions for $upload_dir (must be 777)!</p>\n"); |
| 335 | - } |
|
| 336 | - else |
|
| 342 | + } else |
|
| 337 | 343 | { echo ("<p class=\"success\">Uploaded file saved as $uploaded_filename</p>\n"); |
| 338 | 344 | } |
| 339 | - } |
|
| 340 | - else |
|
| 345 | + } else |
|
| 341 | 346 | { echo ("<p class=\"error\">Error uploading file ".$_FILES["dumpfile"]["name"]."</p>\n"); |
| 342 | 347 | } |
| 343 | 348 | } |
@@ -346,25 +351,28 @@ discard block |
||
| 346 | 351 | // Handle file deletion (delete only in the current directory for security reasons) |
| 347 | 352 | |
| 348 | 353 | if (!$error && isset($_REQUEST["delete"]) && $_REQUEST["delete"]!=basename($_SERVER["SCRIPT_FILENAME"])) |
| 349 | -{ if (preg_match("/(\.(sql|gz|csv))$/i",$_REQUEST["delete"]) && @unlink(basename($_REQUEST["delete"]))) |
|
| 354 | +{ if (preg_match("/(\.(sql|gz|csv))$/i",$_REQUEST["delete"]) && @unlink(basename($_REQUEST["delete"]))) { |
|
| 350 | 355 | echo ("<p class=\"success\">".$_REQUEST["delete"]." was removed successfully</p>\n"); |
| 351 | - else |
|
| 352 | - echo ("<p class=\"error\">Can't remove ".$_REQUEST["delete"]."</p>\n"); |
|
| 353 | -} |
|
| 356 | +} else { |
|
| 357 | + echo ("<p class=\"error\">Can't remove ".$_REQUEST["delete"]."</p>\n"); |
|
| 358 | + } |
|
| 359 | + } |
|
| 354 | 360 | |
| 355 | 361 | // Connect to the database, set charset and execute pre-queries |
| 356 | 362 | |
| 357 | 363 | if (!$error && !TESTMODE) |
| 358 | 364 | { $dbconnection = @mysql_connect($db_server,$db_username,$db_password); |
| 359 | - if ($dbconnection) |
|
| 360 | - $db = mysql_select_db($db_name); |
|
| 365 | + if ($dbconnection) { |
|
| 366 | + $db = mysql_select_db($db_name); |
|
| 367 | + } |
|
| 361 | 368 | if (!$dbconnection || !$db) |
| 362 | 369 | { echo ("<p class=\"error\">Database connection failed due to ".mysql_error()."</p>\n"); |
| 363 | 370 | echo ("<p>Edit the database settings in ".$_SERVER["SCRIPT_FILENAME"]." or contact your database provider.</p>\n"); |
| 364 | 371 | $error=true; |
| 365 | 372 | } |
| 366 | - if (!$error && $db_connection_charset!=='') |
|
| 367 | - @mysql_query("SET NAMES $db_connection_charset", $dbconnection); |
|
| 373 | + if (!$error && $db_connection_charset!=='') { |
|
| 374 | + @mysql_query("SET NAMES $db_connection_charset", $dbconnection); |
|
| 375 | + } |
|
| 368 | 376 | |
| 369 | 377 | if (!$error && isset ($pre_query) && sizeof ($pre_query)>0) |
| 370 | 378 | { reset($pre_query); |
@@ -378,8 +386,7 @@ discard block |
||
| 378 | 386 | } |
| 379 | 387 | } |
| 380 | 388 | } |
| 381 | -} |
|
| 382 | -else |
|
| 389 | +} else |
|
| 383 | 390 | { $dbconnection = false; |
| 384 | 391 | } |
| 385 | 392 | |
@@ -410,29 +417,31 @@ discard block |
||
| 410 | 417 | } |
| 411 | 418 | echo ("<tr><td>$dirfile</td><td class=\"right\">".filesize($dirfile)."</td><td>".date ("Y-m-d H:i:s", filemtime($dirfile))."</td>"); |
| 412 | 419 | |
| 413 | - if (preg_match("/\.sql$/i",$dirfile)) |
|
| 414 | - echo ("<td>SQL</td>"); |
|
| 415 | - elseif (preg_match("/\.gz$/i",$dirfile)) |
|
| 416 | - echo ("<td>GZip</td>"); |
|
| 417 | - elseif (preg_match("/\.csv$/i",$dirfile)) |
|
| 418 | - echo ("<td>CSV</td>"); |
|
| 419 | - else |
|
| 420 | - echo ("<td>Misc</td>"); |
|
| 421 | - |
|
| 422 | - if ((preg_match("/\.gz$/i",$dirfile) && function_exists("gzopen")) || preg_match("/\.sql$/i",$dirfile) || preg_match("/\.csv$/i",$dirfile)) |
|
| 423 | - echo ("<td><a href=\"".$_SERVER["PHP_SELF"]."?start=1&fn=".urlencode($dirfile)."&foffset=0&totalqueries=0&delimiter=".urlencode($delimiter)."\">Start Import</a> into $db_name at $db_server</td>\n <td><a href=\"".$_SERVER["PHP_SELF"]."?delete=".urlencode($dirfile)."\">Delete file</a></td></tr>\n"); |
|
| 424 | - else |
|
| 425 | - echo ("<td> </td>\n <td> </td></tr>\n"); |
|
| 420 | + if (preg_match("/\.sql$/i",$dirfile)) { |
|
| 421 | + echo ("<td>SQL</td>"); |
|
| 422 | + } elseif (preg_match("/\.gz$/i",$dirfile)) { |
|
| 423 | + echo ("<td>GZip</td>"); |
|
| 424 | + } elseif (preg_match("/\.csv$/i",$dirfile)) { |
|
| 425 | + echo ("<td>CSV</td>"); |
|
| 426 | + } else { |
|
| 427 | + echo ("<td>Misc</td>"); |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + if ((preg_match("/\.gz$/i",$dirfile) && function_exists("gzopen")) || preg_match("/\.sql$/i",$dirfile) || preg_match("/\.csv$/i",$dirfile)) { |
|
| 431 | + echo ("<td><a href=\"".$_SERVER["PHP_SELF"]."?start=1&fn=".urlencode($dirfile)."&foffset=0&totalqueries=0&delimiter=".urlencode($delimiter)."\">Start Import</a> into $db_name at $db_server</td>\n <td><a href=\"".$_SERVER["PHP_SELF"]."?delete=".urlencode($dirfile)."\">Delete file</a></td></tr>\n"); |
|
| 432 | + } else { |
|
| 433 | + echo ("<td> </td>\n <td> </td></tr>\n"); |
|
| 434 | + } |
|
| 426 | 435 | } |
| 427 | 436 | } |
| 428 | 437 | } |
| 429 | 438 | |
| 430 | - if ($dirhead) |
|
| 431 | - echo ("</table>\n"); |
|
| 432 | - else |
|
| 433 | - echo ("<p>No uploaded SQL, GZ or CSV files found in the working directory</p>\n"); |
|
| 434 | - } |
|
| 435 | - else |
|
| 439 | + if ($dirhead) { |
|
| 440 | + echo ("</table>\n"); |
|
| 441 | + } else { |
|
| 442 | + echo ("<p>No uploaded SQL, GZ or CSV files found in the working directory</p>\n"); |
|
| 443 | + } |
|
| 444 | + } else |
|
| 436 | 445 | { echo ("<p class=\"error\">Error listing directory $upload_dir</p>\n"); |
| 437 | 446 | $error=true; |
| 438 | 447 | } |
@@ -457,8 +466,7 @@ discard block |
||
| 457 | 466 | if (!($tempfile=@fopen($tempfilename,"w"))) |
| 458 | 467 | { echo ("<p>Upload form disabled. Permissions for the working directory <i>$upload_dir</i> <b>must be set writable for the webserver</b> in order "); |
| 459 | 468 | echo ("to upload files here. Alternatively you can upload your dump files via FTP.</p>\n"); |
| 460 | - } |
|
| 461 | - else |
|
| 469 | + } else |
|
| 462 | 470 | { fclose($tempfile); |
| 463 | 471 | unlink ($tempfilename); |
| 464 | 472 | |
@@ -493,19 +501,21 @@ discard block |
||
| 493 | 501 | |
| 494 | 502 | // Set current filename ($filename overrides $_REQUEST["fn"] if set) |
| 495 | 503 | |
| 496 | - if ($filename!="") |
|
| 497 | - $curfilename=$filename; |
|
| 498 | - else if (isset($_REQUEST["fn"])) |
|
| 499 | - $curfilename=urldecode($_REQUEST["fn"]); |
|
| 500 | - else |
|
| 501 | - $curfilename=""; |
|
| 504 | + if ($filename!="") { |
|
| 505 | + $curfilename=$filename; |
|
| 506 | + } else if (isset($_REQUEST["fn"])) { |
|
| 507 | + $curfilename=urldecode($_REQUEST["fn"]); |
|
| 508 | + } else { |
|
| 509 | + $curfilename=""; |
|
| 510 | + } |
|
| 502 | 511 | |
| 503 | 512 | // Recognize GZip filename |
| 504 | 513 | |
| 505 | - if (preg_match("/\.gz$/i",$curfilename)) |
|
| 506 | - $gzipmode=true; |
|
| 507 | - else |
|
| 508 | - $gzipmode=false; |
|
| 514 | + if (preg_match("/\.gz$/i",$curfilename)) { |
|
| 515 | + $gzipmode=true; |
|
| 516 | + } else { |
|
| 517 | + $gzipmode=false; |
|
| 518 | + } |
|
| 509 | 519 | |
| 510 | 520 | if ((!$gzipmode && !$file=@fopen($curfilename,"r")) || ($gzipmode && !$file=@gzopen($curfilename,"r"))) |
| 511 | 521 | { echo ("<p class=\"error\">Can't open ".$curfilename." for import</p>\n"); |
@@ -518,10 +528,13 @@ discard block |
||
| 518 | 528 | // Get the file size (can't do it fast on gzipped files, no idea how) |
| 519 | 529 | |
| 520 | 530 | else if ((!$gzipmode && @fseek($file, 0, SEEK_END)==0) || ($gzipmode && @gzseek($file, 0)==0)) |
| 521 | - { if (!$gzipmode) $filesize = ftell($file); |
|
| 522 | - else $filesize = gztell($file); // Always zero, ignore |
|
| 523 | - } |
|
| 524 | - else |
|
| 531 | + { if (!$gzipmode) { |
|
| 532 | + $filesize = ftell($file); |
|
| 533 | + } else { |
|
| 534 | + $filesize = gztell($file); |
|
| 535 | + } |
|
| 536 | + // Always zero, ignore |
|
| 537 | + } else |
|
| 525 | 538 | { echo ("<p class=\"error\">I can't seek into $curfilename</p>\n"); |
| 526 | 539 | $error=true; |
| 527 | 540 | } |
@@ -547,16 +560,16 @@ discard block |
||
| 547 | 560 | if (!is_numeric($_REQUEST["start"]) || !is_numeric($_REQUEST["foffset"])) |
| 548 | 561 | { echo ("<p class=\"error\">UNEXPECTED: Non-numeric values for start and foffset</p>\n"); |
| 549 | 562 | $error=true; |
| 550 | - } |
|
| 551 | - else |
|
| 563 | + } else |
|
| 552 | 564 | { $_REQUEST["start"] = floor($_REQUEST["start"]); |
| 553 | 565 | $_REQUEST["foffset"] = floor($_REQUEST["foffset"]); |
| 554 | 566 | } |
| 555 | 567 | |
| 556 | 568 | // Set the current delimiter if defined |
| 557 | 569 | |
| 558 | - if (isset($_REQUEST["delimiter"])) |
|
| 559 | - $delimiter = $_REQUEST["delimiter"]; |
|
| 570 | + if (isset($_REQUEST["delimiter"])) { |
|
| 571 | + $delimiter = $_REQUEST["delimiter"]; |
|
| 572 | + } |
|
| 560 | 573 | |
| 561 | 574 | // Empty CSV table if requested |
| 562 | 575 | |
@@ -575,8 +588,9 @@ discard block |
||
| 575 | 588 | |
| 576 | 589 | if (!$error) |
| 577 | 590 | { skin_open(); |
| 578 | - if (TESTMODE) |
|
| 579 | - echo ("<p class=\"centr\">TEST MODE ENABLED</p>\n"); |
|
| 591 | + if (TESTMODE) { |
|
| 592 | + echo ("<p class=\"centr\">TEST MODE ENABLED</p>\n"); |
|
| 593 | + } |
|
| 580 | 594 | echo ("<p class=\"centr\">Processing file: <b>".$curfilename."</b></p>\n"); |
| 581 | 595 | echo ("<p class=\"smlcentr\">Starting from line: ".$_REQUEST["start"]."</p>\n"); |
| 582 | 596 | skin_close(); |
@@ -615,29 +629,35 @@ discard block |
||
| 615 | 629 | |
| 616 | 630 | $dumpline = ""; |
| 617 | 631 | while (!feof($file) && substr ($dumpline, -1) != "\n" && substr ($dumpline, -1) != "\r") |
| 618 | - { if (!$gzipmode) |
|
| 619 | - $dumpline .= fgets($file, DATA_CHUNK_LENGTH); |
|
| 620 | - else |
|
| 621 | - $dumpline .= gzgets($file, DATA_CHUNK_LENGTH); |
|
| 632 | + { if (!$gzipmode) { |
|
| 633 | + $dumpline .= fgets($file, DATA_CHUNK_LENGTH); |
|
| 634 | + } else { |
|
| 635 | + $dumpline .= gzgets($file, DATA_CHUNK_LENGTH); |
|
| 636 | + } |
|
| 637 | + } |
|
| 638 | + if ($dumpline==="") { |
|
| 639 | + break; |
|
| 622 | 640 | } |
| 623 | - if ($dumpline==="") break; |
|
| 624 | 641 | |
| 625 | 642 | // Remove UTF8 Byte Order Mark at the file beginning if any |
| 626 | 643 | |
| 627 | - if ($_REQUEST["foffset"]==0) |
|
| 628 | - $dumpline=preg_replace('|^\xEF\xBB\xBF|','',$dumpline); |
|
| 644 | + if ($_REQUEST["foffset"]==0) { |
|
| 645 | + $dumpline=preg_replace('|^\xEF\xBB\xBF|','',$dumpline); |
|
| 646 | + } |
|
| 629 | 647 | |
| 630 | 648 | // Create an SQL query from CSV line |
| 631 | 649 | |
| 632 | 650 | if (($csv_insert_table != "") && (preg_match("/(\.csv)$/i",$curfilename))) |
| 633 | 651 | { |
| 634 | - if ($csv_add_slashes) |
|
| 635 | - $dumpline = addslashes($dumpline); |
|
| 652 | + if ($csv_add_slashes) { |
|
| 653 | + $dumpline = addslashes($dumpline); |
|
| 654 | + } |
|
| 636 | 655 | $dumpline = explode($csv_delimiter,$dumpline); |
| 637 | - if ($csv_add_quotes) |
|
| 638 | - $dumpline = "'".implode("','",$dumpline)."'"; |
|
| 639 | - else |
|
| 640 | - $dumpline = implode(",",$dumpline); |
|
| 656 | + if ($csv_add_quotes) { |
|
| 657 | + $dumpline = "'".implode("','",$dumpline)."'"; |
|
| 658 | + } else { |
|
| 659 | + $dumpline = implode(",",$dumpline); |
|
| 660 | + } |
|
| 641 | 661 | $dumpline = 'INSERT INTO '.$csv_insert_table.' VALUES ('.$dumpline.');'; |
| 642 | 662 | } |
| 643 | 663 | |
@@ -651,8 +671,9 @@ discard block |
||
| 651 | 671 | |
| 652 | 672 | // Recognize delimiter statement |
| 653 | 673 | |
| 654 | - if (!$inparents && strpos ($dumpline, "DELIMITER ") === 0) |
|
| 655 | - $delimiter = str_replace ("DELIMITER ","",trim($dumpline)); |
|
| 674 | + if (!$inparents && strpos ($dumpline, "DELIMITER ") === 0) { |
|
| 675 | + $delimiter = str_replace ("DELIMITER ","",trim($dumpline)); |
|
| 676 | + } |
|
| 656 | 677 | |
| 657 | 678 | // Skip comments and blank lines only if NOT in parents |
| 658 | 679 | |
@@ -686,8 +707,9 @@ discard block |
||
| 686 | 707 | // Count ' and \' (or " and \") in the dumpline to avoid query break within a text field ending by $delimiter |
| 687 | 708 | |
| 688 | 709 | $parents=substr_count ($dumpline_deslashed, $string_quotes)-substr_count ($dumpline_deslashed, "\\$string_quotes"); |
| 689 | - if ($parents % 2 != 0) |
|
| 690 | - $inparents=!$inparents; |
|
| 710 | + if ($parents % 2 != 0) { |
|
| 711 | + $inparents=!$inparents; |
|
| 712 | + } |
|
| 691 | 713 | |
| 692 | 714 | // Add the line to query |
| 693 | 715 | |
@@ -695,8 +717,9 @@ discard block |
||
| 695 | 717 | |
| 696 | 718 | // Don't count the line if in parents (text fields may include unlimited linebreaks) |
| 697 | 719 | |
| 698 | - if (!$inparents) |
|
| 699 | - $querylines++; |
|
| 720 | + if (!$inparents) { |
|
| 721 | + $querylines++; |
|
| 722 | + } |
|
| 700 | 723 | |
| 701 | 724 | // Stop if query contains more lines as defined by MAX_QUERY_LINES |
| 702 | 725 | |
@@ -748,10 +771,11 @@ discard block |
||
| 748 | 771 | // Get the current file position |
| 749 | 772 | |
| 750 | 773 | if (!$error) |
| 751 | - { if (!$gzipmode) |
|
| 752 | - $foffset = ftell($file); |
|
| 753 | - else |
|
| 754 | - $foffset = gztell($file); |
|
| 774 | + { if (!$gzipmode) { |
|
| 775 | + $foffset = ftell($file); |
|
| 776 | + } else { |
|
| 777 | + $foffset = gztell($file); |
|
| 778 | + } |
|
| 755 | 779 | if (!$foffset) |
| 756 | 780 | { echo ("<p class=\"error\">UNEXPECTED: Can't read the file pointer offset</p>\n"); |
| 757 | 781 | $error=true; |
@@ -805,8 +829,7 @@ discard block |
||
| 805 | 829 | } |
| 806 | 830 | |
| 807 | 831 | $pct_bar = "<div style=\"height:15px;width:$pct_done%;background-color:#000080;margin:0px;\"></div>"; |
| 808 | - } |
|
| 809 | - else |
|
| 832 | + } else |
|
| 810 | 833 | { |
| 811 | 834 | $bytes_togo = ' ? '; |
| 812 | 835 | $bytes_tota = ' ? '; |
@@ -864,12 +887,13 @@ discard block |
||
| 864 | 887 | <?php |
| 865 | 888 | |
| 866 | 889 | $error=true; // This is a semi-error telling the script is finished |
| 890 | + } else |
|
| 891 | + { if ($delaypersession!=0) { |
|
| 892 | + echo ("<p class=\"centr\">Now I'm <b>waiting $delaypersession milliseconds</b> before starting next session...</p>\n"); |
|
| 867 | 893 | } |
| 868 | - else |
|
| 869 | - { if ($delaypersession!=0) |
|
| 870 | - echo ("<p class=\"centr\">Now I'm <b>waiting $delaypersession milliseconds</b> before starting next session...</p>\n"); |
|
| 871 | - if (!$ajax) |
|
| 872 | - echo ("<script language=\"JavaScript\" type=\"text/javascript\">window.setTimeout('location.href=\"".$_SERVER["PHP_SELF"]."?start=$linenumber&fn=".urlencode($curfilename)."&foffset=$foffset&totalqueries=$totalqueries&delimiter=".urlencode($delimiter)."\";',500+$delaypersession);</script>\n"); |
|
| 894 | + if (!$ajax) { |
|
| 895 | + echo ("<script language=\"JavaScript\" type=\"text/javascript\">window.setTimeout('location.href=\"".$_SERVER["PHP_SELF"]."?start=$linenumber&fn=".urlencode($curfilename)."&foffset=$foffset&totalqueries=$totalqueries&delimiter=".urlencode($delimiter)."\";',500+$delaypersession);</script>\n"); |
|
| 896 | + } |
|
| 873 | 897 | |
| 874 | 898 | echo ("<noscript>\n"); |
| 875 | 899 | echo ("<p class=\"centr\"><a href=\"".$_SERVER["PHP_SELF"]."?start=$linenumber&fn=".urlencode($curfilename)."&foffset=$foffset&totalqueries=$totalqueries&delimiter=".urlencode($delimiter)."\">Continue from the line $linenumber</a> (Enable JavaScript to do it automatically)</p>\n"); |
@@ -877,20 +901,26 @@ discard block |
||
| 877 | 901 | |
| 878 | 902 | echo ("<p class=\"centr\">Press <b><a href=\"".$_SERVER["PHP_SELF"]."\">STOP</a></b> to abort the import <b>OR WAIT!</b></p>\n"); |
| 879 | 903 | } |
| 904 | + } else { |
|
| 905 | + echo ("<p class=\"error\">Stopped on error</p>\n"); |
|
| 880 | 906 | } |
| 881 | - else |
|
| 882 | - echo ("<p class=\"error\">Stopped on error</p>\n"); |
|
| 883 | 907 | |
| 884 | 908 | skin_close(); |
| 885 | 909 | |
| 886 | 910 | } |
| 887 | 911 | |
| 888 | -if ($error) |
|
| 912 | +if ($error) { |
|
| 889 | 913 | echo ("<p class=\"centr\"><a href=\"".$_SERVER["PHP_SELF"]."\">Start from the beginning</a> (DROP the old tables before restarting)</p>\n"); |
| 914 | +} |
|
| 890 | 915 | |
| 891 | -if ($dbconnection) mysql_close($dbconnection); |
|
| 892 | -if ($file && !$gzipmode) fclose($file); |
|
| 893 | -else if ($file && $gzipmode) gzclose($file); |
|
| 916 | +if ($dbconnection) { |
|
| 917 | + mysql_close($dbconnection); |
|
| 918 | +} |
|
| 919 | +if ($file && !$gzipmode) { |
|
| 920 | + fclose($file); |
|
| 921 | +} else if ($file && $gzipmode) { |
|
| 922 | + gzclose($file); |
|
| 923 | +} |
|
| 894 | 924 | |
| 895 | 925 | ?> |
| 896 | 926 | |
@@ -923,10 +953,10 @@ discard block |
||
| 923 | 953 | { ob_end_clean(); |
| 924 | 954 | create_xml_response(); |
| 925 | 955 | die; |
| 926 | - } |
|
| 927 | - else |
|
| 928 | - create_ajax_script(); |
|
| 929 | -} |
|
| 956 | + } else { |
|
| 957 | + create_ajax_script(); |
|
| 958 | + } |
|
| 959 | + } |
|
| 930 | 960 | |
| 931 | 961 | // Anyway put out the output from above |
| 932 | 962 | |
@@ -9,8 +9,8 @@ |
||
| 9 | 9 | var $sameOrigin; |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | - * @param bool allow running from the same origin only |
|
| 13 | - */ |
|
| 12 | + * @param bool allow running from the same origin only |
|
| 13 | + */ |
|
| 14 | 14 | function AdminerFrames($sameOrigin = false) { |
| 15 | 15 | $this->sameOrigin = $sameOrigin; |
| 16 | 16 | } |
@@ -10,8 +10,8 @@ |
||
| 10 | 10 | var $path; |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * @param string |
|
| 14 | - */ |
|
| 13 | + * @param string |
|
| 14 | + */ |
|
| 15 | 15 | function AdminerTinymce($path = "tiny_mce/tiny_mce.js") { |
| 16 | 16 | $this->path = $path; |
| 17 | 17 | } |
@@ -18,8 +18,8 @@ |
||
| 18 | 18 | var $database; |
| 19 | 19 | |
| 20 | 20 | /** Set database of login table |
| 21 | - * @param string |
|
| 22 | - */ |
|
| 21 | + * @param string |
|
| 22 | + */ |
|
| 23 | 23 | function AdminerLoginTable($database) { |
| 24 | 24 | $this->database = $database; |
| 25 | 25 | } |
@@ -9,9 +9,9 @@ |
||
| 9 | 9 | var $uploadPath, $displayPath; |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | - * @param string prefix for uploading data (create writable subdirectory for each table containing uploadable fields) |
|
| 13 | - * @param string prefix for displaying data, null stands for $uploadPath |
|
| 14 | - */ |
|
| 12 | + * @param string prefix for uploading data (create writable subdirectory for each table containing uploadable fields) |
|
| 13 | + * @param string prefix for displaying data, null stands for $uploadPath |
|
| 14 | + */ |
|
| 15 | 15 | function AdminerFileUpload($uploadPath = "../static/data/", $displayPath = null) { |
| 16 | 16 | $this->uploadPath = $uploadPath; |
| 17 | 17 | $this->displayPath = (isset($displayPath) ? $displayPath : $uploadPath); |