wordmove 1.3.0.pre2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1080 +1,1179 @@
1
- <?php
2
-
3
- $shared_key = '<%= password %>';
4
- if ($_GET['shared_key'] != $shared_key) {
5
- die();
6
- }
7
-
8
- // BigDump ver. 0.34b from 2011-09-04
9
-
10
- // Database configuration
11
-
12
- $db_port = '<%= escape_php db[:port] %>';
13
- if (!$db_port) {
14
- $db_port = ini_get("mysqli.default_port");
15
- }
16
- $db_server = '<%= escape_php db[:host] %>:' . $db_port;
17
- $db_user = '<%= escape_php db[:user] %>';
18
- $db_password = '<%= escape_php db[:password] %>';
19
- $db_name = '<%= escape_php db[:name] %>';
20
-
21
- // Other settings (optional)
22
-
23
- $filename = ''; // Specify the dump filename to suppress the file selection dialog
24
- $ajax = true; // AJAX mode: import will be done without refreshing the website
25
- $linespersession = 3000; // Lines to be executed per one import session
26
- $delaypersession = 0; // You can specify a sleep time in milliseconds after each session
27
- // Works only if JavaScript is activated. Use to reduce server overrun
28
-
29
- // CSV related settings (only if you use a CSV dump)
30
-
31
- $csv_insert_table = ''; // Destination table for CSV files
32
- $csv_preempty_table = false; // true: delete all entries from table specified in $csv_insert_table before processing
33
- $csv_delimiter = ','; // Field delimiter in CSV file
34
- $csv_add_quotes = true; // If your CSV data already have quotes around each field set it to false
35
- $csv_add_slashes = true; // If your CSV data already have slashes in front of ' and " set it to false
36
-
37
- // Allowed comment markers: lines starting with these strings will be ignored by BigDump
38
-
39
- $comment[]='#'; // Standard comment lines are dropped by default
40
- $comment[]='-- ';
41
- $comment[]='DELIMITER'; // Ignore DELIMITER switch as it's not a valid SQL statement
42
- // $comment[]='---'; // Uncomment this line if using proprietary dump created by outdated mysqldump
43
- // $comment[]='CREATE DATABASE'; // Uncomment this line if your dump contains create database queries in order to ignore them
44
- $comment[]='/*!'; // Or add your own string to leave out other proprietary things
45
-
46
- // Pre-queries: SQL queries to be executed at the beginning of each import session
47
-
48
- // $pre_query[]='SET foreign_key_checks = 0';
49
- // $pre_query[]='Add additional queries if you want here';
50
-
51
- // Connection charset should be the same as the dump file charset (utf8, latin1, cp1251, koi8r etc.)
52
- // See http://dev.mysql.com/doc/refman/5.0/en/charset-charsets.html for the full list
53
- // Change this if you have problems with non-latin letters
54
-
55
- $db_connection_charset = '<%= db[:charset] || 'utf8' %>';
56
-
57
- // Default query delimiter: this character at the line end tells Bigdump where a SQL statement ends
58
- // Can be changed by DELIMITER statement in the dump file (normally used when defining procedures/functions)
59
-
60
- $delimiter = ';';
61
-
62
- // String quotes character
63
-
64
- $string_quotes = '\''; // Change to '"' if your dump file uses double qoutes for strings
65
-
66
-
67
- // *******************************************************************************************
68
- // If not familiar with PHP please don't change anything below this line
69
- // *******************************************************************************************
70
-
71
- if ($ajax)
72
- ob_start();
73
-
74
- define ('VERSION','0.34b');
75
- define ('DATA_CHUNK_LENGTH',16384); // How many chars are read per time
76
- define ('MAX_QUERY_LINES',300); // How many lines may be considered to be one query (except text lines)
77
- define ('TESTMODE',false); // Set to true to process the file without actually accessing the database
78
-
79
- header("Expires: Mon, 1 Dec 2003 01:00:00 GMT");
80
- header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
81
- header("Cache-Control: no-store, no-cache, must-revalidate");
82
- header("Cache-Control: post-check=0, pre-check=0", false);
83
- header("Pragma: no-cache");
84
-
85
- @ini_set('auto_detect_line_endings', true);
86
- @set_time_limit(0);
87
-
88
- if (function_exists("date_default_timezone_set") && function_exists("date_default_timezone_get"))
89
- @date_default_timezone_set(@date_default_timezone_get());
90
-
91
- // Clean and strip anything we don't want from user's input [0.27b]
92
-
93
- foreach ($_REQUEST as $key => $val)
94
- {
95
- $val = preg_replace("/[^_A-Za-z0-9-\.&= ;\$]/i",'', $val);
96
- $_REQUEST[$key] = $val;
97
- }
98
-
99
- ?>
100
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
101
- <html>
102
- <head>
103
- <title>BigDump ver. <?php echo (VERSION); ?></title>
104
- <meta http-equiv="CONTENT-TYPE" content="text/html; charset=iso-8859-1"/>
105
- <meta http-equiv="CONTENT-LANGUAGE" content="EN"/>
106
-
107
- <meta http-equiv="Cache-Control" content="no-cache/"/>
108
- <meta http-equiv="Pragma" content="no-cache"/>
109
- <meta http-equiv="Expires" content="-1"/>
110
- <meta name="robots" content="noindex, nofollow">
111
-
112
- <style type="text/css">
113
- <!--
114
-
115
- body
116
- { background-color:#FFFFF0;
117
- }
118
-
119
- h1
120
- { font-size:20px;
121
- line-height:24px;
122
- font-family:Arial,Helvetica,sans-serif;
123
- margin-top:5px;
124
- margin-bottom:5px;
125
- }
126
-
127
- p,td,th
128
- { font-size:14px;
129
- line-height:18px;
130
- font-family:Arial,Helvetica,sans-serif;
131
- margin-top:5px;
132
- margin-bottom:5px;
133
- text-align:justify;
134
- vertical-align:top;
135
- }
136
-
137
- p.centr
138
- {
139
- text-align:center;
140
- }
141
-
142
- p.smlcentr
143
- { font-size:10px;
144
- line-height:14px;
145
- text-align:center;
146
- }
147
-
148
- p.error
149
- { color:#FF0000;
150
- font-weight:bold;
151
- }
152
-
153
- p.success
154
- { color:#00DD00;
155
- font-weight:bold;
156
- }
157
-
158
- p.successcentr
159
- { color:#00DD00;
160
- background-color:#DDDDFF;
161
- font-weight:bold;
162
- text-align:center;
163
- }
164
-
165
- td
166
- { background-color:#F8F8F8;
167
- text-align:left;
168
- }
169
-
170
- td.transparent
171
- { background-color:#FFFFF0;
172
- }
173
-
174
- th
175
- { font-weight:bold;
176
- color:#FFFFFF;
177
- background-color:#AAAAEE;
178
- text-align:left;
179
- }
180
-
181
- td.right
182
- { text-align:right;
183
- }
184
-
185
- form
186
- { margin-top:5px;
187
- margin-bottom:5px;
188
- }
189
-
190
- div.skin1
191
- {
192
- border-color:#3333EE;
193
- border-width:5px;
194
- border-style:solid;
195
- background-color:#AAAAEE;
196
- text-align:center;
197
- vertical-align:middle;
198
- padding:3px;
199
- margin:1px;
200
- }
201
-
202
- td.bg3
203
- { background-color:#EEEE99;
204
- text-align:left;
205
- vertical-align:top;
206
- width:20%;
207
- }
208
-
209
- th.bg4
210
- { background-color:#EEAA55;
211
- text-align:left;
212
- vertical-align:top;
213
- width:20%;
214
- }
215
-
216
- td.bgpctbar
217
- { background-color:#EEEEAA;
218
- text-align:left;
219
- vertical-align:middle;
220
- width:80%;
221
- }
222
-
223
- -->
224
- </style>
225
-
226
- </head>
227
-
228
- <body>
229
-
230
- <center>
231
-
232
- <table width="780" cellspacing="0" cellpadding="0">
233
- <tr><td class="transparent">
234
-
235
- <!-- <h1>BigDump: Staggered MySQL Dump Importer ver. <?php echo (VERSION); ?></h1> -->
236
-
237
- <?php
238
-
239
- function skin_open() {
240
- echo ('<div class="skin1">');
241
- }
242
-
243
- function skin_close() {
244
- echo ('</div>');
245
- }
246
-
247
- skin_open();
248
- echo ('<h1>BigDump: Staggered MySQL Dump Importer v'.VERSION.'</h1>');
249
- skin_close();
250
-
251
- $error = false;
252
- $file = false;
253
-
254
- // Check PHP version
255
-
256
- if (!$error && !function_exists('version_compare'))
257
- { echo ("<p class=\"error\">PHP version 4.1.0 is required for BigDump to proceed. You have PHP ".phpversion()." installed. Sorry!</p>\n");
258
- $error=true;
259
- }
260
-
261
- // Check if mysql extension is available
262
-
263
- if (!$error && !function_exists('mysql_connect'))
264
- { echo ("<p class=\"error\">There is no mySQL extension available in your PHP installation. Sorry!</p>\n");
265
- $error=true;
266
- }
267
-
268
- // Calculate PHP max upload size (handle settings like 10M or 100K)
269
-
270
- if (!$error)
271
- { $upload_max_filesize=ini_get("upload_max_filesize");
272
- if (preg_match("/([0-9]+)K/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024;
273
- if (preg_match("/([0-9]+)M/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024*1024;
274
- if (preg_match("/([0-9]+)G/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024*1024*1024;
275
- }
276
-
277
- // Get the current directory
278
-
279
- if (isset($_SERVER["CGIA"]))
280
- $upload_dir=dirname($_SERVER["CGIA"]);
281
- else if (isset($_SERVER["ORIG_PATH_TRANSLATED"]))
282
- $upload_dir=dirname($_SERVER["ORIG_PATH_TRANSLATED"]);
283
- else if (isset($_SERVER["ORIG_SCRIPT_FILENAME"]))
284
- $upload_dir=dirname($_SERVER["ORIG_SCRIPT_FILENAME"]);
285
- else if (isset($_SERVER["PATH_TRANSLATED"]))
286
- $upload_dir=dirname($_SERVER["PATH_TRANSLATED"]);
287
- else
288
- $upload_dir=dirname($_SERVER["SCRIPT_FILENAME"]);
289
-
290
- // Handle file upload
291
-
292
- if (!$error && isset($_REQUEST["uploadbutton"]))
293
- { if (is_uploaded_file($_FILES["dumpfile"]["tmp_name"]) && ($_FILES["dumpfile"]["error"])==0)
294
- {
295
- $uploaded_filename=str_replace(" ","_",$_FILES["dumpfile"]["name"]);
296
- $uploaded_filename=preg_replace("/[^_A-Za-z0-9-\.]/i",'',$uploaded_filename);
297
- $uploaded_filepath=str_replace("\\","/",$upload_dir."/".$uploaded_filename);
298
-
299
- if (file_exists($uploaded_filename))
300
- { echo ("<p class=\"error\">File $uploaded_filename already exist! Delete and upload again!</p>\n");
301
- }
302
- else if (!preg_match("/(\.(sql|gz|csv))$/i",$uploaded_filename))
303
- { echo ("<p class=\"error\">You may only upload .sql .gz or .csv files.</p>\n");
304
- }
305
- else if (!@move_uploaded_file($_FILES["dumpfile"]["tmp_name"],$uploaded_filepath))
306
- { echo ("<p class=\"error\">Error moving uploaded file ".$_FILES["dumpfile"]["tmp_name"]." to the $uploaded_filepath</p>\n");
307
- echo ("<p>Check the directory permissions for $upload_dir (must be 777)!</p>\n");
308
- }
309
- else
310
- { echo ("<p class=\"success\">Uploaded file saved as $uploaded_filename</p>\n");
311
- }
312
- }
313
- else
314
- { echo ("<p class=\"error\">Error uploading file ".$_FILES["dumpfile"]["name"]."</p>\n");
315
- }
316
- }
317
-
318
-
319
- // Handle file deletion (delete only in the current directory for security reasons)
320
-
321
- if (!$error && isset($_REQUEST["delete"]) && $_REQUEST["delete"]!=basename($_SERVER["SCRIPT_FILENAME"]))
322
- { if (preg_match("/(\.(sql|gz|csv))$/i",$_REQUEST["delete"]) && @unlink(basename($_REQUEST["delete"])))
323
- echo ("<p class=\"success\">".$_REQUEST["delete"]." was removed successfully</p>\n");
324
- else
325
- echo ("<p class=\"error\">Can't remove ".$_REQUEST["delete"]."</p>\n");
326
- }
327
-
328
- // Connect to the database, set charset and execute pre-queries
329
-
330
- if (!$error && !TESTMODE)
331
- { $dbconnection = @mysql_connect($db_server, $db_user, $db_password);
332
- if ($dbconnection)
333
- $db = mysql_select_db($db_name);
334
- if (!$dbconnection || !$db)
335
- { echo ("<p class=\"error\">Database connection failed due to ".mysql_error()."</p>\n");
336
- echo ("<p>Edit the database settings in ".$_SERVER["SCRIPT_FILENAME"]." or contact your database provider.</p>\n");
337
- $error=true;
338
- }
339
- if (!$error && $db_connection_charset!=='')
340
- @mysql_query("SET NAMES $db_connection_charset", $dbconnection);
341
-
342
- if (!$error && isset ($pre_query) && sizeof ($pre_query)>0)
343
- { reset($pre_query);
344
- foreach ($pre_query as $pre_query_value)
345
- { if (!@mysql_query($pre_query_value, $dbconnection))
346
- { echo ("<p class=\"error\">Error with pre-query.</p>\n");
347
- echo ("<p>Query: ".trim(nl2br(htmlentities($pre_query_value)))."</p>\n");
348
- echo ("<p>MySQL: ".mysql_error()."</p>\n");
349
- $error=true;
350
- break;
351
- }
352
- }
353
- }
354
- }
355
- else
356
- { $dbconnection = false;
357
- }
358
-
359
-
360
- // DIAGNOSTIC
361
- // echo("<h1>Checkpoint!</h1>");
362
-
363
- // List uploaded files in multifile mode
364
-
365
- if (!$error && !isset($_REQUEST["fn"]) && $filename=="")
366
- { if ($dirhandle = opendir($upload_dir))
367
- {
368
- $files=array();
369
- while (false !== ($files[] = readdir($dirhandle)));
370
- closedir($dirhandle);
371
- $dirhead=false;
372
-
373
- if (sizeof($files)>0)
374
- {
375
- sort($files);
376
- foreach ($files as $dirfile)
377
- {
378
- if ($dirfile != "." && $dirfile != ".." && $dirfile!=basename($_SERVER["SCRIPT_FILENAME"]) && preg_match("/\.(sql|gz|csv)$/i",$dirfile))
379
- { if (!$dirhead)
380
- { echo ("<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\">\n");
381
- echo ("<tr><th>Filename</th><th>Size</th><th>Date&amp;Time</th><th>Type</th><th>&nbsp;</th><th>&nbsp;</th>\n");
382
- $dirhead=true;
383
- }
384
- echo ("<tr><td>$dirfile</td><td class=\"right\">".filesize($dirfile)."</td><td>".date ("Y-m-d H:i:s", filemtime($dirfile))."</td>");
385
-
386
- if (preg_match("/\.sql$/i",$dirfile))
387
- echo ("<td>SQL</td>");
388
- elseif (preg_match("/\.gz$/i",$dirfile))
389
- echo ("<td>GZip</td>");
390
- elseif (preg_match("/\.csv$/i",$dirfile))
391
- echo ("<td>CSV</td>");
392
- else
393
- echo ("<td>Misc</td>");
394
-
395
- if ((preg_match("/\.gz$/i",$dirfile) && function_exists("gzopen")) || preg_match("/\.sql$/i",$dirfile) || preg_match("/\.csv$/i",$dirfile))
396
- echo ("<td><a href=\"".$_SERVER["PHP_SELF"]."?start=1&amp;fn=".urlencode($dirfile)."&amp;foffset=0&amp;totalqueries=0&amp;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");
397
- else
398
- echo ("<td>&nbsp;</td>\n <td>&nbsp;</td></tr>\n");
399
- }
400
- }
401
- }
402
-
403
- if ($dirhead)
404
- echo ("</table>\n");
405
- else
406
- echo ("<p>No uploaded SQL, GZ or CSV files found in the working directory</p>\n");
407
- }
408
- else
409
- { echo ("<p class=\"error\">Error listing directory $upload_dir</p>\n");
410
- $error=true;
411
- }
412
- }
413
-
414
-
415
- // Single file mode
416
-
417
- if (!$error && !isset ($_REQUEST["fn"]) && $filename!="")
418
- { echo ("<p><a href=\"".$_SERVER["PHP_SELF"]."?start=1&amp;fn=".urlencode($filename)."&amp;foffset=0&amp;totalqueries=0\">Start Import</a> from $filename into $db_name at $db_server</p>\n");
419
- }
420
-
421
-
422
- // File Upload Form
423
-
424
- if (!$error && !isset($_REQUEST["fn"]) && $filename=="")
425
- {
426
-
427
- // Test permissions on working directory
428
-
429
- do { $tempfilename=time().".tmp"; } while (file_exists($tempfilename));
430
- if (!($tempfile=@fopen($tempfilename,"w")))
431
- { 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 ");
432
- echo ("to upload files here. Alternatively you can upload your dump files via FTP.</p>\n");
433
- }
434
- else
435
- { fclose($tempfile);
436
- unlink ($tempfilename);
437
-
438
- echo ("<p>You can now upload your dump file up to $upload_max_filesize bytes (".round ($upload_max_filesize/1024/1024)." Mbytes) ");
439
- echo ("directly from your browser to the server. Alternatively you can upload your dump files of any size via FTP.</p>\n");
440
- ?>
441
- <form method="POST" action="<?php echo ($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data">
442
- <input type="hidden" name="MAX_FILE_SIZE" value="$upload_max_filesize">
443
- <p>Dump file: <input type="file" name="dumpfile" accept="*/*" size=60"></p>
444
- <p><input type="submit" name="uploadbutton" value="Upload"></p>
445
- </form>
446
- <?php
447
- }
448
- }
449
-
450
- // Print the current mySQL connection charset
451
-
452
- if (!$error && !TESTMODE && !isset($_REQUEST["fn"]))
453
- {
454
- $result = mysql_query("SHOW VARIABLES LIKE 'character_set_connection';");
455
- $row = mysql_fetch_assoc($result);
456
- if ($row)
457
- { $charset = $row['Value'];
458
- 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");
459
- }
460
- }
461
-
462
- // Open the file
463
-
464
- if (!$error && isset($_REQUEST["start"]))
465
- {
466
-
467
- // Set current filename ($filename overrides $_REQUEST["fn"] if set)
468
-
469
- if ($filename!="")
470
- $curfilename=$filename;
471
- else if (isset($_REQUEST["fn"]))
472
- $curfilename=urldecode($_REQUEST["fn"]);
473
- else
474
- $curfilename="";
475
-
476
- // Recognize GZip filename
477
-
478
- if (preg_match("/\.gz$/i",$curfilename))
479
- $gzipmode=true;
480
- else
481
- $gzipmode=false;
482
-
483
- if ((!$gzipmode && !$file=@fopen($curfilename,"r")) || ($gzipmode && !$file=@gzopen($curfilename,"r")))
484
- { echo ("<p class=\"error\">Can't open ".$curfilename." for import</p>\n");
485
- echo ("<p>Please, check that your dump file name contains only alphanumerical characters, and rename it accordingly, for example: $curfilename.".
486
- "<br>Or, specify \$filename in bigdump.php with the full filename. ".
487
- "<br>Or, you have to upload the $curfilename to the server first.</p>\n");
488
- $error=true;
489
- }
490
-
491
- // Get the file size (can't do it fast on gzipped files, no idea how)
492
-
493
- else if ((!$gzipmode && @fseek($file, 0, SEEK_END)==0) || ($gzipmode && @gzseek($file, 0)==0))
494
- { if (!$gzipmode) $filesize = ftell($file);
495
- else $filesize = gztell($file); // Always zero, ignore
496
- }
497
- else
498
- { echo ("<p class=\"error\">I can't seek into $curfilename</p>\n");
499
- $error=true;
500
- }
501
- }
502
-
503
- // Stop if csv file is used, but $csv_insert_table is not set
504
-
505
- if (($csv_insert_table == "") && (preg_match("/(\.csv)$/i",$curfilename)))
506
- { echo ("<p class=\"error\">You have to specify \$csv_insert_table when using a CSV file. </p>\n");
507
- $error=true;
508
- }
509
-
510
-
511
- // *******************************************************************************************
512
- // START IMPORT SESSION HERE
513
- // *******************************************************************************************
514
-
515
- if (!$error && isset($_REQUEST["start"]) && isset($_REQUEST["foffset"]) && preg_match("/(\.(sql|gz|csv))$/i",$curfilename))
516
- {
517
-
518
- // Check start and foffset are numeric values
519
-
520
- if (!is_numeric($_REQUEST["start"]) || !is_numeric($_REQUEST["foffset"]))
521
- { echo ("<p class=\"error\">UNEXPECTED: Non-numeric values for start and foffset</p>\n");
522
- $error=true;
523
- }
524
- else
525
- { $_REQUEST["start"] = floor($_REQUEST["start"]);
526
- $_REQUEST["foffset"] = floor($_REQUEST["foffset"]);
527
- }
528
-
529
- // Set the current delimiter if defined
530
-
531
- if (isset($_REQUEST["delimiter"]))
532
- $delimiter = $_REQUEST["delimiter"];
533
-
534
- // Empty CSV table if requested
535
-
536
- if (!$error && $_REQUEST["start"]==1 && $csv_insert_table != "" && $csv_preempty_table)
537
- {
538
- $query = "DELETE FROM $csv_insert_table";
539
- if (!TESTMODE && !mysql_query(trim($query), $dbconnection))
540
- { echo ("<p class=\"error\">Error when deleting entries from $csv_insert_table.</p>\n");
541
- echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n");
542
- echo ("<p>MySQL: ".mysql_error()."</p>\n");
543
- $error=true;
544
- }
545
- }
546
-
547
- // Print start message
548
-
549
- if (!$error)
550
- { skin_open();
551
- if (TESTMODE)
552
- echo ("<p class=\"centr\">TEST MODE ENABLED</p>\n");
553
- echo ("<p class=\"centr\">Processing file: <b>".$curfilename."</b></p>\n");
554
- echo ("<p class=\"smlcentr\">Starting from line: ".$_REQUEST["start"]."</p>\n");
555
- skin_close();
556
- }
557
-
558
- // Check $_REQUEST["foffset"] upon $filesize (can't do it on gzipped files)
559
-
560
- if (!$error && !$gzipmode && $_REQUEST["foffset"]>$filesize)
561
- { echo ("<p class=\"error\">UNEXPECTED: Can't set file pointer behind the end of file</p>\n");
562
- $error=true;
563
- }
564
-
565
- // Set file pointer to $_REQUEST["foffset"]
566
-
567
- if (!$error && ((!$gzipmode && fseek($file, $_REQUEST["foffset"])!=0) || ($gzipmode && gzseek($file, $_REQUEST["foffset"])!=0)))
568
- { echo ("<p class=\"error\">UNEXPECTED: Can't set file pointer to offset: ".$_REQUEST["foffset"]."</p>\n");
569
- $error=true;
570
- }
571
-
572
- // Start processing queries from $file
573
-
574
- if (!$error)
575
- { $query="";
576
- $queries=0;
577
- $totalqueries=$_REQUEST["totalqueries"];
578
- $linenumber=$_REQUEST["start"];
579
- $querylines=0;
580
- $inparents=false;
581
-
582
- // Stay processing as long as the $linespersession is not reached or the query is still incomplete
583
-
584
- while ($linenumber<$_REQUEST["start"]+$linespersession || $query!="")
585
- {
586
-
587
- // Read the whole next line
588
-
589
- $dumpline = "";
590
- while (!feof($file) && substr ($dumpline, -1) != "\n" && substr ($dumpline, -1) != "\r")
591
- { if (!$gzipmode)
592
- $dumpline .= fgets($file, DATA_CHUNK_LENGTH);
593
- else
594
- $dumpline .= gzgets($file, DATA_CHUNK_LENGTH);
595
- }
596
- if ($dumpline==="") break;
597
-
598
- // Remove UTF8 Byte Order Mark at the file beginning if any
599
-
600
- if ($_REQUEST["foffset"]==0)
601
- $dumpline=preg_replace('|^\xEF\xBB\xBF|','',$dumpline);
602
-
603
- // Create an SQL query from CSV line
604
-
605
- if (($csv_insert_table != "") && (preg_match("/(\.csv)$/i",$curfilename)))
606
- {
607
- if ($csv_add_slashes)
608
- $dumpline = addslashes($dumpline);
609
- $dumpline = explode($csv_delimiter,$dumpline);
610
- if ($csv_add_quotes)
611
- $dumpline = "'".implode("','",$dumpline)."'";
612
- else
613
- $dumpline = implode(",",$dumpline);
614
- $dumpline = 'INSERT INTO '.$csv_insert_table.' VALUES ('.$dumpline.');';
615
- }
616
-
617
- // Handle DOS and Mac encoded linebreaks (I don't know if it really works on Win32 or Mac Servers)
618
-
619
- $dumpline=str_replace("\r\n", "\n", $dumpline);
620
- $dumpline=str_replace("\r", "\n", $dumpline);
621
-
622
- // DIAGNOSTIC
623
- // echo ("<p>Line $linenumber: $dumpline</p>\n");
624
-
625
- // Recognize delimiter statement
626
-
627
- if (!$inparents && strpos ($dumpline, "DELIMITER ") === 0)
628
- $delimiter = str_replace ("DELIMITER ","",trim($dumpline));
629
-
630
- // Skip comments and blank lines only if NOT in parents
631
-
632
- if (!$inparents)
633
- { $skipline=false;
634
- reset($comment);
635
- foreach ($comment as $comment_value)
636
- {
637
-
638
- // DIAGNOSTIC
639
- // echo ($comment_value);
640
- if (trim($dumpline)=="" || strpos (trim($dumpline), $comment_value) === 0)
641
- { $skipline=true;
642
- break;
643
- }
644
- }
645
- if ($skipline)
646
- { $linenumber++;
647
-
648
- // DIAGNOSTIC
649
- // echo ("<p>Comment line skipped</p>\n");
650
-
651
- continue;
652
- }
653
- }
654
-
655
- // Remove double back-slashes from the dumpline prior to count the quotes ('\\' can only be within strings)
656
-
657
- $dumpline_deslashed = str_replace ("\\\\","",$dumpline);
658
-
659
- // Count ' and \' (or " and \") in the dumpline to avoid query break within a text field ending by $delimiter
660
-
661
- $parents=substr_count ($dumpline_deslashed, $string_quotes)-substr_count ($dumpline_deslashed, "\\$string_quotes");
662
- if ($parents % 2 != 0)
663
- $inparents=!$inparents;
664
-
665
- // Add the line to query
666
-
667
- $query .= $dumpline;
668
-
669
- // Don't count the line if in parents (text fields may include unlimited linebreaks)
670
-
671
- if (!$inparents)
672
- $querylines++;
673
-
674
- // Stop if query contains more lines as defined by MAX_QUERY_LINES
675
-
676
- if ($querylines>MAX_QUERY_LINES)
677
- {
678
- echo ("<p class=\"error\">Stopped at the line $linenumber. </p>");
679
- echo ("<p>At this place the current query includes more than ".MAX_QUERY_LINES." dump lines. That can happen if your dump file was ");
680
- 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 ");
681
- echo ("extended inserts or very long procedure definitions. Please read the <a href=\"http://www.ozerov.de/bigdump/usage/\">BigDump usage notes</a> ");
682
- echo ("for more infos. Ask for our support services ");
683
- echo ("in order to handle dump files containing extended inserts.</p>\n");
684
- $error=true;
685
- break;
686
- }
687
-
688
- // Execute query if end of query detected ($delimiter as last character) AND NOT in parents
689
-
690
- // DIAGNOSTIC
691
- // echo ("<p>Regex: ".'/'.preg_quote($delimiter).'$/'."</p>\n");
692
- // echo ("<p>In Parents: ".($inparents?"true":"false")."</p>\n");
693
- // echo ("<p>Line: $dumpline</p>\n");
694
-
695
- if (preg_match('/'.preg_quote($delimiter).'$/',trim($dumpline)) && !$inparents)
696
- {
697
-
698
- // Cut off delimiter of the end of the query
699
-
700
- $query = substr(trim($query),0,-1*strlen($delimiter));
701
-
702
- // DIAGNOSTIC
703
- // echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n");
704
-
705
- if (!TESTMODE && !mysql_query($query, $dbconnection))
706
- { echo ("<p class=\"error\">Error at the line $linenumber: ". trim($dumpline)."</p>\n");
707
- echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n");
708
- echo ("<p>MySQL: ".mysql_error()."</p>\n");
709
- $error=true;
710
- break;
711
- }
712
- $totalqueries++;
713
- $queries++;
714
- $query="";
715
- $querylines=0;
716
- }
717
- $linenumber++;
718
- }
719
- }
720
-
721
- // Get the current file position
722
-
723
- if (!$error)
724
- { if (!$gzipmode)
725
- $foffset = ftell($file);
726
- else
727
- $foffset = gztell($file);
728
- if (!$foffset)
729
- { echo ("<p class=\"error\">UNEXPECTED: Can't read the file pointer offset</p>\n");
730
- $error=true;
731
- }
732
- }
733
-
734
- // Print statistics
735
-
736
- skin_open();
737
-
738
- // echo ("<p class=\"centr\"><b>Statistics</b></p>\n");
739
-
740
- if (!$error)
741
- {
742
- $lines_this = $linenumber-$_REQUEST["start"];
743
- $lines_done = $linenumber-1;
744
- $lines_togo = ' ? ';
745
- $lines_tota = ' ? ';
746
-
747
- $queries_this = $queries;
748
- $queries_done = $totalqueries;
749
- $queries_togo = ' ? ';
750
- $queries_tota = ' ? ';
751
-
752
- $bytes_this = $foffset-$_REQUEST["foffset"];
753
- $bytes_done = $foffset;
754
- $kbytes_this = round($bytes_this/1024,2);
755
- $kbytes_done = round($bytes_done/1024,2);
756
- $mbytes_this = round($kbytes_this/1024,2);
757
- $mbytes_done = round($kbytes_done/1024,2);
758
-
759
- if (!$gzipmode)
760
- {
761
- $bytes_togo = $filesize-$foffset;
762
- $bytes_tota = $filesize;
763
- $kbytes_togo = round($bytes_togo/1024,2);
764
- $kbytes_tota = round($bytes_tota/1024,2);
765
- $mbytes_togo = round($kbytes_togo/1024,2);
766
- $mbytes_tota = round($kbytes_tota/1024,2);
767
-
768
- $pct_this = ceil($bytes_this/$filesize*100);
769
- $pct_done = ceil($foffset/$filesize*100);
770
- $pct_togo = 100 - $pct_done;
771
- $pct_tota = 100;
772
-
773
- if ($bytes_togo==0)
774
- { $lines_togo = '0';
775
- $lines_tota = $linenumber-1;
776
- $queries_togo = '0';
777
- $queries_tota = $totalqueries;
778
- }
779
-
780
- $pct_bar = "<div style=\"height:15px;width:$pct_done%;background-color:#000080;margin:0px;\"></div>";
781
- }
782
- else
783
- {
784
- $bytes_togo = ' ? ';
785
- $bytes_tota = ' ? ';
786
- $kbytes_togo = ' ? ';
787
- $kbytes_tota = ' ? ';
788
- $mbytes_togo = ' ? ';
789
- $mbytes_tota = ' ? ';
790
-
791
- $pct_this = ' ? ';
792
- $pct_done = ' ? ';
793
- $pct_togo = ' ? ';
794
- $pct_tota = 100;
795
- $pct_bar = str_replace(' ','&nbsp;','<tt>[ Not available for gzipped files ]</tt>');
796
- }
797
-
798
- echo ("
799
- <center>
800
- <table width=\"520\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\">
801
- <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>
802
- <tr><th class=\"bg4\">Lines</th><td class=\"bg3\">$lines_this</td><td class=\"bg3\">$lines_done</td><td class=\"bg3\">$lines_togo</td><td class=\"bg3\">$lines_tota</td></tr>
803
- <tr><th class=\"bg4\">Queries</th><td class=\"bg3\">$queries_this</td><td class=\"bg3\">$queries_done</td><td class=\"bg3\">$queries_togo</td><td class=\"bg3\">$queries_tota</td></tr>
804
- <tr><th class=\"bg4\">Bytes</th><td class=\"bg3\">$bytes_this</td><td class=\"bg3\">$bytes_done</td><td class=\"bg3\">$bytes_togo</td><td class=\"bg3\">$bytes_tota</td></tr>
805
- <tr><th class=\"bg4\">KB</th><td class=\"bg3\">$kbytes_this</td><td class=\"bg3\">$kbytes_done</td><td class=\"bg3\">$kbytes_togo</td><td class=\"bg3\">$kbytes_tota</td></tr>
806
- <tr><th class=\"bg4\">MB</th><td class=\"bg3\">$mbytes_this</td><td class=\"bg3\">$mbytes_done</td><td class=\"bg3\">$mbytes_togo</td><td class=\"bg3\">$mbytes_tota</td></tr>
807
- <tr><th class=\"bg4\">%</th><td class=\"bg3\">$pct_this</td><td class=\"bg3\">$pct_done</td><td class=\"bg3\">$pct_togo</td><td class=\"bg3\">$pct_tota</td></tr>
808
- <tr><th class=\"bg4\">% bar</th><td class=\"bgpctbar\" colspan=\"4\">$pct_bar</td></tr>
809
- </table>
810
- </center>
811
- \n");
812
-
813
- // Finish message and restart the script
814
-
815
- if ($linenumber<$_REQUEST["start"]+$linespersession)
816
- { echo ("<p class=\"successcentr\">Congratulations: End of file reached, assuming OK</p>\n");
817
- echo ("<p class=\"successcentr\">IMPORTANT: REMOVE YOUR DUMP FILE and BIGDUMP SCRIPT FROM SERVER NOW!</p>\n");
818
- 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");
819
- echo ("<p class=\"centr\">You can send me some bucks or euros as appreciation via PayPal. Thank you!</p>\n");
820
- ?>
821
-
822
- <!-- Start Paypal donation code -->
823
- <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
824
- <input type="hidden" name="cmd" value="_xclick" />
825
- <input type="hidden" name="business" value="alexey@ozerov.de" />
826
- <input type="hidden" name="item_name" value="BigDump Donation" />
827
- <input type="hidden" name="no_shipping" value="1" />
828
- <input type="hidden" name="no_note" value="0" />
829
- <input type="hidden" name="tax" value="0" />
830
- <input type="hidden" name="bn" value="PP-DonationsBF" />
831
- <input type="hidden" name="lc" value="US" />
832
- <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but04.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!" />
833
- <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
834
- </form>
835
- <!-- End Paypal donation code -->
836
-
837
- <?php
838
-
839
- $error=true; // This is a semi-error telling the script is finished
840
- }
841
- else
842
- { if ($delaypersession!=0)
843
- echo ("<p class=\"centr\">Now I'm <b>waiting $delaypersession milliseconds</b> before starting next session...</p>\n");
844
- if (!$ajax)
845
- 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");
846
-
847
- echo ("<noscript>\n");
848
- echo ("<p class=\"centr\"><a href=\"".$_SERVER["PHP_SELF"]."?start=$linenumber&amp;fn=".urlencode($curfilename)."&amp;foffset=$foffset&amp;totalqueries=$totalqueries&amp;delimiter=".urlencode($delimiter)."\">Continue from the line $linenumber</a> (Enable JavaScript to do it automatically)</p>\n");
849
- echo ("</noscript>\n");
850
-
851
- echo ("<p class=\"centr\">Press <b><a href=\"".$_SERVER["PHP_SELF"]."\">STOP</a></b> to abort the import <b>OR WAIT!</b></p>\n");
852
- }
853
- }
854
- else
855
- echo ("<p class=\"error\">Stopped on error</p>\n");
856
-
857
- skin_close();
858
-
859
- }
860
-
861
- if ($error)
862
- echo ("<p class=\"centr\"><a href=\"".$_SERVER["PHP_SELF"]."\">Start from the beginning</a> (DROP the old tables before restarting)</p>\n");
863
-
864
- if ($dbconnection) mysql_close($dbconnection);
865
- if ($file && !$gzipmode) fclose($file);
866
- else if ($file && $gzipmode) gzclose($file);
867
-
868
- ?>
869
-
870
- <p class="centr">&copy; 2003-2011 <a href="mailto:alexey@ozerov.de">Alexey Ozerov</a></p>
871
-
872
- </td></tr></table>
873
-
874
- </center>
875
-
876
- </body>
877
- </html>
878
-
879
- <?php
880
-
881
- // If error or finished put out the whole output from above and stop
882
-
883
- if ($error)
884
- {
885
- $out1 = ob_get_contents();
886
- ob_end_clean();
887
- echo $out1;
888
- die;
889
- }
890
-
891
- // If Ajax enabled and in import progress creates responses (XML response or script for the initial page)
892
-
893
- if ($ajax && isset($_REQUEST['start']))
894
- {
895
- if (isset($_REQUEST['ajaxrequest']))
896
- { ob_end_clean();
897
- create_xml_response();
898
- die;
899
- }
900
- else
901
- create_ajax_script();
902
- }
903
-
904
- // Anyway put out the output from above
905
-
906
- ob_flush();
907
-
908
- // THE MAIN SCRIPT ENDS HERE
909
-
910
-
911
- // *******************************************************************************************
912
- // AJAX utilities
913
- // *******************************************************************************************
914
-
915
- function create_xml_response()
916
- {
917
- global $linenumber, $foffset, $totalqueries, $curfilename, $delimiter,
918
- $lines_this, $lines_done, $lines_togo, $lines_tota,
919
- $queries_this, $queries_done, $queries_togo, $queries_tota,
920
- $bytes_this, $bytes_done, $bytes_togo, $bytes_tota,
921
- $kbytes_this, $kbytes_done, $kbytes_togo, $kbytes_tota,
922
- $mbytes_this, $mbytes_done, $mbytes_togo, $mbytes_tota,
923
- $pct_this, $pct_done, $pct_togo, $pct_tota,$pct_bar;
924
-
925
- header('Content-Type: application/xml');
926
- header('Cache-Control: no-cache');
927
-
928
- echo '<?xml version="1.0" encoding="ISO-8859-1"?>';
929
- echo "<root>";
930
-
931
- // data - for calculations
932
-
933
- echo "<linenumber>$linenumber</linenumber>";
934
- echo "<foffset>$foffset</foffset>";
935
- echo "<fn>$curfilename</fn>";
936
- echo "<totalqueries>$totalqueries</totalqueries>";
937
- echo "<delimiter>$delimiter</delimiter>";
938
-
939
- // results - for page update
940
-
941
- echo "<elem1>$lines_this</elem1>";
942
- echo "<elem2>$lines_done</elem2>";
943
- echo "<elem3>$lines_togo</elem3>";
944
- echo "<elem4>$lines_tota</elem4>";
945
-
946
- echo "<elem5>$queries_this</elem5>";
947
- echo "<elem6>$queries_done</elem6>";
948
- echo "<elem7>$queries_togo</elem7>";
949
- echo "<elem8>$queries_tota</elem8>";
950
-
951
- echo "<elem9>$bytes_this</elem9>";
952
- echo "<elem10>$bytes_done</elem10>";
953
- echo "<elem11>$bytes_togo</elem11>";
954
- echo "<elem12>$bytes_tota</elem12>";
955
-
956
- echo "<elem13>$kbytes_this</elem13>";
957
- echo "<elem14>$kbytes_done</elem14>";
958
- echo "<elem15>$kbytes_togo</elem15>";
959
- echo "<elem16>$kbytes_tota</elem16>";
960
-
961
- echo "<elem17>$mbytes_this</elem17>";
962
- echo "<elem18>$mbytes_done</elem18>";
963
- echo "<elem19>$mbytes_togo</elem19>";
964
- echo "<elem20>$mbytes_tota</elem20>";
965
-
966
- echo "<elem21>$pct_this</elem21>";
967
- echo "<elem22>$pct_done</elem22>";
968
- echo "<elem23>$pct_togo</elem23>";
969
- echo "<elem24>$pct_tota</elem24>";
970
- echo "<elem_bar>".htmlentities($pct_bar)."</elem_bar>";
971
-
972
- echo "</root>";
973
- }
974
-
975
-
976
- function create_ajax_script()
977
- {
978
- global $linenumber, $foffset, $totalqueries, $delaypersession, $curfilename, $delimiter;
979
- ?>
980
-
981
- <script type="text/javascript" language="javascript">
982
-
983
- // creates next action url (upload page, or XML response)
984
- function get_url(linenumber,fn,foffset,totalqueries,delimiter) {
985
- return "<?php echo $_SERVER['PHP_SELF'] ?>?start="+linenumber+"&fn="+fn+"&foffset="+foffset+"&totalqueries="+totalqueries+"&delimiter="+delimiter+"&ajaxrequest=true";
986
- }
987
-
988
- // extracts text from XML element (itemname must be unique)
989
- function get_xml_data(itemname,xmld) {
990
- return xmld.getElementsByTagName(itemname).item(0).firstChild.data;
991
- }
992
-
993
- function makeRequest(url) {
994
- http_request = false;
995
- if (window.XMLHttpRequest) {
996
- // Mozilla etc.
997
- http_request = new XMLHttpRequest();
998
- if (http_request.overrideMimeType) {
999
- http_request.overrideMimeType("text/xml");
1000
- }
1001
- } else if (window.ActiveXObject) {
1002
- // IE
1003
- try {
1004
- http_request = new ActiveXObject("Msxml2.XMLHTTP");
1005
- } catch(e) {
1006
- try {
1007
- http_request = new ActiveXObject("Microsoft.XMLHTTP");
1008
- } catch(e) {}
1009
- }
1010
- }
1011
- if (!http_request) {
1012
- alert("Cannot create an XMLHTTP instance");
1013
- return false;
1014
- }
1015
- http_request.onreadystatechange = server_response;
1016
- http_request.open("GET", url, true);
1017
- http_request.send(null);
1018
- }
1019
-
1020
- function server_response()
1021
- {
1022
-
1023
- // waiting for correct response
1024
- if (http_request.readyState != 4)
1025
- return;
1026
-
1027
- if (http_request.status != 200)
1028
- {
1029
- alert("Page unavailable, or wrong url!")
1030
- return;
1031
- }
1032
-
1033
- // r = xml response
1034
- var r = http_request.responseXML;
1035
-
1036
- //if received not XML but HTML with new page to show
1037
- if (!r || r.getElementsByTagName('root').length == 0)
1038
- { var text = http_request.responseText;
1039
- document.open();
1040
- document.write(text);
1041
- document.close();
1042
- return;
1043
- }
1044
-
1045
- // update "Starting from line: "
1046
- document.getElementsByTagName('p').item(1).innerHTML =
1047
- "Starting from line: " +
1048
- r.getElementsByTagName('linenumber').item(0).firstChild.nodeValue;
1049
-
1050
- // update table with new values
1051
- for(i = 1; i <= 24; i++)
1052
- document.getElementsByTagName('td').item(i).firstChild.data = get_xml_data('elem'+i,r);
1053
-
1054
- // update color bar
1055
- document.getElementsByTagName('td').item(25).innerHTML =
1056
- r.getElementsByTagName('elem_bar').item(0).firstChild.nodeValue;
1057
-
1058
- // action url (XML response)
1059
- url_request = get_url(
1060
- get_xml_data('linenumber',r),
1061
- get_xml_data('fn',r),
1062
- get_xml_data('foffset',r),
1063
- get_xml_data('totalqueries',r),
1064
- get_xml_data('delimiter',r));
1065
-
1066
- // ask for XML response
1067
- window.setTimeout("makeRequest(url_request)",500+<?php echo $delaypersession; ?>);
1068
- }
1069
-
1070
- // First Ajax request from initial page
1071
-
1072
- var http_request = false;
1073
- var url_request = get_url(<?php echo ($linenumber.',"'.urlencode($curfilename).'",'.$foffset.','.$totalqueries.',"'.urlencode($delimiter).'"') ;?>);
1074
- window.setTimeout("makeRequest(url_request)",500+<?php echo $delaypersession; ?>);
1075
- </script>
1076
-
1077
- <?php
1078
- }
1079
-
1080
- ?>
1
+ <?php
2
+
3
+ $shared_key = '<%= password %>';
4
+ if ($_GET['shared_key'] != $shared_key) {
5
+ die();
6
+ }
7
+
8
+ error_reporting(E_ALL);
9
+
10
+ // BigDump ver. 0.35b from 2012-12-26
11
+ // Staggered import of an large MySQL Dump (like phpMyAdmin 2.x Dump)
12
+ // Even through the webservers with hard runtime limit and those in safe mode
13
+ // Works fine with Internet Explorer 7.0 and Firefox 2.x
14
+
15
+ // Author: Alexey Ozerov (alexey at ozerov dot de)
16
+ // AJAX & CSV functionalities: Krzysiek Herod (kr81uni at wp dot pl)
17
+ // Copyright: GPL (C) 2003-2013
18
+ // More Infos: http://www.ozerov.de/bigdump
19
+
20
+ // This program is free software; you can redistribute it and/or modify it under the
21
+ // terms of the GNU General Public License as published by the Free Software Foundation;
22
+ // either version 2 of the License, or (at your option) any later version.
23
+
24
+ // THIS SCRIPT IS PROVIDED AS IS, WITHOUT ANY WARRANTY OR GUARANTEE OF ANY KIND
25
+
26
+ // USAGE
27
+
28
+ // 1. Adjust the database configuration and charset in this file
29
+ // 2. Remove the old tables on the target database if your dump doesn't contain "DROP TABLE"
30
+ // 3. Create the working directory (e.g. dump) on your web server
31
+ // 4. Upload bigdump.php and your dump files (.sql, .gz) via FTP to the working directory
32
+ // 5. Run the bigdump.php from your browser via URL like http://www.yourdomain.com/dump/bigdump.php
33
+ // 6. BigDump can start the next import session automatically if you enable the JavaScript
34
+ // 7. Wait for the script to finish, do not close the browser window
35
+ // 8. IMPORTANT: Remove bigdump.php and your dump files from the web server
36
+
37
+ // If Timeout errors still occure you may need to adjust the $linepersession setting in this file
38
+
39
+ // LAST CHANGES
40
+
41
+ // *** First ideas about adding plugin interface
42
+ // *** Fix // delimiter bug
43
+ // *** Minor fix to avoid Undefined variable curfilename notice
44
+ // *** Handle empty delimiter setting
45
+ // *** New way to determine the upload directory
46
+ // *** Set UTF8 as default connection charset
47
+
48
+ // Database configuration
49
+
50
+ $db_port = '<%= db[:port] %>';
51
+ if (!$db_port) {
52
+ $db_port = ini_get("mysqli.default_port");
53
+ }
54
+ $db_server = '<%= escape_php db[:host] %>:' . $db_port;
55
+ $db_username = '<%= escape_php db[:user] %>';
56
+ $db_password = '<%= escape_php db[:password] %>';
57
+ $db_name = '<%= escape_php db[:name] %>';
58
+
59
+ // Connection charset should be the same as the dump file charset (utf8, latin1, cp1251, koi8r etc.)
60
+ // See http://dev.mysql.com/doc/refman/5.0/en/charset-charsets.html for the full list
61
+ // Change this if you have problems with non-latin letters
62
+
63
+ $db_connection_charset = '<%= db[:charset] || 'utf8' %>';
64
+
65
+ // OPTIONAL SETTINGS
66
+
67
+ $filename = ''; // Specify the dump filename to suppress the file selection dialog
68
+ $ajax = true; // AJAX mode: import will be done without refreshing the website
69
+ $linespersession = 3000; // Lines to be executed per one import session
70
+ $delaypersession = 0; // You can specify a sleep time in milliseconds after each session
71
+ // Works only if JavaScript is activated. Use to reduce server overrun
72
+
73
+ // CSV related settings (only if you use a CSV dump)
74
+
75
+ $csv_insert_table = ''; // Destination table for CSV files
76
+ $csv_preempty_table = false; // true: delete all entries from table specified in $csv_insert_table before processing
77
+ $csv_delimiter = ','; // Field delimiter in CSV file
78
+ $csv_add_quotes = true; // If your CSV data already have quotes around each field set it to false
79
+ $csv_add_slashes = true; // If your CSV data already have slashes in front of ' and " set it to false
80
+
81
+ // Allowed comment markers: lines starting with these strings will be ignored by BigDump
82
+
83
+ $comment[]='#'; // Standard comment lines are dropped by default
84
+ $comment[]='-- ';
85
+ $comment[]='DELIMITER'; // Ignore DELIMITER switch as it's not a valid SQL statement
86
+ // $comment[]='---'; // Uncomment this line if using proprietary dump created by outdated mysqldump
87
+ // $comment[]='CREATE DATABASE'; // Uncomment this line if your dump contains create database queries in order to ignore them
88
+ $comment[]='/*!'; // Or add your own string to leave out other proprietary things
89
+
90
+ // Pre-queries: SQL queries to be executed at the beginning of each import session
91
+
92
+ // $pre_query[]='SET foreign_key_checks = 0';
93
+ // $pre_query[]='Add additional queries if you want here';
94
+
95
+ // Default query delimiter: this character at the line end tells Bigdump where a SQL statement ends
96
+ // Can be changed by DELIMITER statement in the dump file (normally used when defining procedures/functions)
97
+
98
+ $delimiter = ';';
99
+
100
+ // String quotes character
101
+
102
+ $string_quotes = '\''; // Change to '"' if your dump file uses double qoutes for strings
103
+
104
+ // How many lines may be considered to be one query (except text lines)
105
+
106
+ $max_query_lines = 300;
107
+
108
+ // Where to put the upload files into (default: bigdump folder)
109
+
110
+ $upload_dir = dirname(__FILE__);
111
+
112
+ // *******************************************************************************************
113
+ // If not familiar with PHP please don't change anything below this line
114
+ // *******************************************************************************************
115
+
116
+ if ($ajax)
117
+ ob_start();
118
+
119
+ define ('VERSION','0.35b');
120
+ define ('DATA_CHUNK_LENGTH',16384); // How many chars are read per time
121
+ define ('TESTMODE',false); // Set to true to process the file without actually accessing the database
122
+ define ('BIGDUMP_DIR',dirname(__FILE__));
123
+ define ('PLUGIN_DIR',BIGDUMP_DIR.'/plugins/');
124
+
125
+ header("Expires: Mon, 1 Dec 2003 01:00:00 GMT");
126
+ header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
127
+ header("Cache-Control: no-store, no-cache, must-revalidate");
128
+ header("Cache-Control: post-check=0, pre-check=0", false);
129
+ header("Pragma: no-cache");
130
+
131
+ @ini_set('auto_detect_line_endings', true);
132
+ @set_time_limit(0);
133
+
134
+ if (function_exists("date_default_timezone_set") && function_exists("date_default_timezone_get"))
135
+ @date_default_timezone_set(@date_default_timezone_get());
136
+
137
+ // Clean and strip anything we don't want from user's input [0.27b]
138
+
139
+ foreach ($_REQUEST as $key => $val)
140
+ {
141
+ $val = preg_replace("/[^_A-Za-z0-9-\.&= ;\$]/i",'', $val);
142
+ $_REQUEST[$key] = $val;
143
+ }
144
+
145
+ // Plugin handling is still EXPERIMENTAL and DISABLED
146
+ // Register plugins by including plugin_name.php from each ./plugins/plugin_name
147
+ /*
148
+ if (is_dir(PLUGIN_DIR))
149
+ { if ($dh = opendir(PLUGIN_DIR))
150
+ {
151
+ while (($file = readdir($dh)) !== false)
152
+ { if (is_dir(PLUGIN_DIR.$file) && $file!='.' && $file!='..' && file_exists(PLUGIN_DIR.$file.'/'.$file.'.php'))
153
+ include (PLUGIN_DIR.$file.'/'.$file.'.php');
154
+ }
155
+ closedir($dh);
156
+ }
157
+ }
158
+ */
159
+
160
+ do_action('header');
161
+
162
+ ?>
163
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
164
+ <html>
165
+ <head>
166
+ <title>BigDump ver. <?php echo (VERSION); ?></title>
167
+ <meta http-equiv="CONTENT-TYPE" content="text/html; charset=iso-8859-1"/>
168
+ <meta http-equiv="CONTENT-LANGUAGE" content="EN"/>
169
+
170
+ <meta http-equiv="Cache-Control" content="no-cache/"/>
171
+ <meta http-equiv="Pragma" content="no-cache"/>
172
+ <meta http-equiv="Expires" content="-1"/>
173
+ <meta name="robots" content="noindex, nofollow">
174
+
175
+ <?php do_action('head_meta'); ?>
176
+
177
+ <style type="text/css">
178
+ <!--
179
+
180
+ body
181
+ { background-color:#FFFFF0;
182
+ }
183
+
184
+ h1
185
+ { font-size:20px;
186
+ line-height:24px;
187
+ font-family:Arial,Helvetica,sans-serif;
188
+ margin-top:5px;
189
+ margin-bottom:5px;
190
+ }
191
+
192
+ p,td,th
193
+ { font-size:14px;
194
+ line-height:18px;
195
+ font-family:Arial,Helvetica,sans-serif;
196
+ margin-top:5px;
197
+ margin-bottom:5px;
198
+ text-align:justify;
199
+ vertical-align:top;
200
+ }
201
+
202
+ p.centr
203
+ {
204
+ text-align:center;
205
+ }
206
+
207
+ p.smlcentr
208
+ { font-size:10px;
209
+ line-height:14px;
210
+ text-align:center;
211
+ }
212
+
213
+ p.error
214
+ { color:#FF0000;
215
+ font-weight:bold;
216
+ }
217
+
218
+ p.success
219
+ { color:#00DD00;
220
+ font-weight:bold;
221
+ }
222
+
223
+ p.successcentr
224
+ { color:#00DD00;
225
+ background-color:#DDDDFF;
226
+ font-weight:bold;
227
+ text-align:center;
228
+ }
229
+
230
+ td
231
+ { background-color:#F8F8F8;
232
+ text-align:left;
233
+ }
234
+
235
+ td.transparent
236
+ { background-color:#FFFFF0;
237
+ }
238
+
239
+ th
240
+ { font-weight:bold;
241
+ color:#FFFFFF;
242
+ background-color:#AAAAEE;
243
+ text-align:left;
244
+ }
245
+
246
+ td.right
247
+ { text-align:right;
248
+ }
249
+
250
+ form
251
+ { margin-top:5px;
252
+ margin-bottom:5px;
253
+ }
254
+
255
+ div.skin1
256
+ {
257
+ border-color:#3333EE;
258
+ border-width:5px;
259
+ border-style:solid;
260
+ background-color:#AAAAEE;
261
+ text-align:center;
262
+ vertical-align:middle;
263
+ padding:3px;
264
+ margin:1px;
265
+ }
266
+
267
+ td.bg3
268
+ { background-color:#EEEE99;
269
+ text-align:left;
270
+ vertical-align:top;
271
+ width:20%;
272
+ }
273
+
274
+ th.bg4
275
+ { background-color:#EEAA55;
276
+ text-align:left;
277
+ vertical-align:top;
278
+ width:20%;
279
+ }
280
+
281
+ td.bgpctbar
282
+ { background-color:#EEEEAA;
283
+ text-align:left;
284
+ vertical-align:middle;
285
+ width:80%;
286
+ }
287
+
288
+ <?php do_action('head_style'); ?>
289
+
290
+ -->
291
+ </style>
292
+
293
+ </head>
294
+
295
+ <body>
296
+
297
+ <center>
298
+
299
+ <table width="780" cellspacing="0" cellpadding="0">
300
+ <tr><td class="transparent">
301
+
302
+ <!-- <h1>BigDump: Staggered MySQL Dump Importer ver. <?php echo (VERSION); ?></h1> -->
303
+
304
+ <?php
305
+
306
+ function skin_open()
307
+ {
308
+ echo ('<div class="skin1">');
309
+ }
310
+
311
+ function skin_close()
312
+ {
313
+ echo ('</div>');
314
+ }
315
+
316
+ skin_open();
317
+ echo ('<h1>BigDump: Staggered MySQL Dump Importer v'.VERSION.'</h1>');
318
+ skin_close();
319
+
320
+ do_action('after_headline');
321
+
322
+ $error = false;
323
+ $file = false;
324
+
325
+ // Check PHP version
326
+
327
+ if (!$error && !function_exists('version_compare'))
328
+ { echo ("<p class=\"error\">PHP version 4.1.0 is required for BigDump to proceed. You have PHP ".phpversion()." installed. Sorry!</p>\n");
329
+ $error=true;
330
+ }
331
+
332
+ // Check if mysql extension is available
333
+
334
+ if (!$error && !function_exists('mysql_connect'))
335
+ { echo ("<p class=\"error\">There is no mySQL extension available in your PHP installation. Sorry!</p>\n");
336
+ $error=true;
337
+ }
338
+
339
+ // Calculate PHP max upload size (handle settings like 10M or 100K)
340
+
341
+ if (!$error)
342
+ { $upload_max_filesize=ini_get("upload_max_filesize");
343
+ if (preg_match("/([0-9]+)K/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024;
344
+ if (preg_match("/([0-9]+)M/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024*1024;
345
+ if (preg_match("/([0-9]+)G/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024*1024*1024;
346
+ }
347
+
348
+ // Get the current directory
349
+ /*
350
+ if (isset($_SERVER["CGIA"]))
351
+ $upload_dir=dirname($_SERVER["CGIA"]);
352
+ else if (isset($_SERVER["ORIG_PATH_TRANSLATED"]))
353
+ $upload_dir=dirname($_SERVER["ORIG_PATH_TRANSLATED"]);
354
+ else if (isset($_SERVER["ORIG_SCRIPT_FILENAME"]))
355
+ $upload_dir=dirname($_SERVER["ORIG_SCRIPT_FILENAME"]);
356
+ else if (isset($_SERVER["PATH_TRANSLATED"]))
357
+ $upload_dir=dirname($_SERVER["PATH_TRANSLATED"]);
358
+ else
359
+ $upload_dir=dirname($_SERVER["SCRIPT_FILENAME"]);
360
+ */
361
+
362
+ do_action ('script_runs');
363
+
364
+ // Handle file upload
365
+
366
+ if (!$error && isset($_REQUEST["uploadbutton"]))
367
+ { if (is_uploaded_file($_FILES["dumpfile"]["tmp_name"]) && ($_FILES["dumpfile"]["error"])==0)
368
+ {
369
+ $uploaded_filename=str_replace(" ","_",$_FILES["dumpfile"]["name"]);
370
+ $uploaded_filename=preg_replace("/[^_A-Za-z0-9-\.]/i",'',$uploaded_filename);
371
+ $uploaded_filepath=str_replace("\\","/",$upload_dir."/".$uploaded_filename);
372
+
373
+ do_action('file_uploaded');
374
+
375
+ if (file_exists($uploaded_filename))
376
+ { echo ("<p class=\"error\">File $uploaded_filename already exist! Delete and upload again!</p>\n");
377
+ }
378
+ else if (!preg_match("/(\.(sql|gz|csv))$/i",$uploaded_filename))
379
+ { echo ("<p class=\"error\">You may only upload .sql .gz or .csv files.</p>\n");
380
+ }
381
+ else if (!@move_uploaded_file($_FILES["dumpfile"]["tmp_name"],$uploaded_filepath))
382
+ { echo ("<p class=\"error\">Error moving uploaded file ".$_FILES["dumpfile"]["tmp_name"]." to the $uploaded_filepath</p>\n");
383
+ echo ("<p>Check the directory permissions for $upload_dir (must be 777)!</p>\n");
384
+ }
385
+ else
386
+ { echo ("<p class=\"success\">Uploaded file saved as $uploaded_filename</p>\n");
387
+ }
388
+ }
389
+ else
390
+ { echo ("<p class=\"error\">Error uploading file ".$_FILES["dumpfile"]["name"]."</p>\n");
391
+ }
392
+ }
393
+
394
+
395
+ // Handle file deletion (delete only in the current directory for security reasons)
396
+
397
+ if (!$error && isset($_REQUEST["delete"]) && $_REQUEST["delete"]!=basename($_SERVER["SCRIPT_FILENAME"]))
398
+ { if (preg_match("/(\.(sql|gz|csv))$/i",$_REQUEST["delete"]) && @unlink($upload_dir.'/'.$_REQUEST["delete"]))
399
+ echo ("<p class=\"success\">".$_REQUEST["delete"]." was removed successfully</p>\n");
400
+ else
401
+ echo ("<p class=\"error\">Can't remove ".$_REQUEST["delete"]."</p>\n");
402
+ }
403
+
404
+ // Connect to the database, set charset and execute pre-queries
405
+
406
+ if (!$error && !TESTMODE)
407
+ { $dbconnection = @mysql_connect($db_server,$db_username,$db_password);
408
+ if ($dbconnection)
409
+ $db = mysql_select_db($db_name);
410
+ if (!$dbconnection || !$db)
411
+ { echo ("<p class=\"error\">Database connection failed due to ".mysql_error()."</p>\n");
412
+ echo ("<p>Edit the database settings in BigDump configuration, or contact your database provider.</p>\n");
413
+ $error=true;
414
+ }
415
+ if (!$error && $db_connection_charset!=='')
416
+ @mysql_query("SET NAMES $db_connection_charset", $dbconnection);
417
+
418
+ if (!$error && isset ($pre_query) && sizeof ($pre_query)>0)
419
+ { reset($pre_query);
420
+ foreach ($pre_query as $pre_query_value)
421
+ { if (!@mysql_query($pre_query_value, $dbconnection))
422
+ { echo ("<p class=\"error\">Error with pre-query.</p>\n");
423
+ echo ("<p>Query: ".trim(nl2br(htmlentities($pre_query_value)))."</p>\n");
424
+ echo ("<p>MySQL: ".mysql_error()."</p>\n");
425
+ $error=true;
426
+ break;
427
+ }
428
+ }
429
+ }
430
+ }
431
+ else
432
+ { $dbconnection = false;
433
+ }
434
+
435
+ do_action('database_connected');
436
+
437
+ // DIAGNOSTIC
438
+ // echo("<h1>Checkpoint!</h1>");
439
+
440
+ // List uploaded files in multifile mode
441
+
442
+ if (!$error && !isset($_REQUEST["fn"]) && $filename=="")
443
+ { if ($dirhandle = opendir($upload_dir))
444
+ {
445
+ $files=array();
446
+ while (false !== ($files[] = readdir($dirhandle)));
447
+ closedir($dirhandle);
448
+ $dirhead=false;
449
+
450
+ if (sizeof($files)>0)
451
+ {
452
+ sort($files);
453
+ foreach ($files as $dirfile)
454
+ {
455
+ if ($dirfile != "." && $dirfile != ".." && $dirfile!=basename($_SERVER["SCRIPT_FILENAME"]) && preg_match("/\.(sql|gz|csv)$/i",$dirfile))
456
+ { if (!$dirhead)
457
+ { echo ("<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\">\n");
458
+ echo ("<tr><th>Filename</th><th>Size</th><th>Date&amp;Time</th><th>Type</th><th>&nbsp;</th><th>&nbsp;</th>\n");
459
+ $dirhead=true;
460
+ }
461
+ echo ("<tr><td>$dirfile</td><td class=\"right\">".filesize($upload_dir.'/'.$dirfile)."</td><td>".date ("Y-m-d H:i:s", filemtime($upload_dir.'/'.$dirfile))."</td>");
462
+
463
+ if (preg_match("/\.sql$/i",$dirfile))
464
+ echo ("<td>SQL</td>");
465
+ elseif (preg_match("/\.gz$/i",$dirfile))
466
+ echo ("<td>GZip</td>");
467
+ elseif (preg_match("/\.csv$/i",$dirfile))
468
+ echo ("<td>CSV</td>");
469
+ else
470
+ echo ("<td>Misc</td>");
471
+
472
+ if ((preg_match("/\.gz$/i",$dirfile) && function_exists("gzopen")) || preg_match("/\.sql$/i",$dirfile) || preg_match("/\.csv$/i",$dirfile))
473
+ echo ("<td><a href=\"".$_SERVER["PHP_SELF"]."?start=1&amp;fn=".urlencode($dirfile)."&amp;foffset=0&amp;totalqueries=0&amp;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");
474
+ // TODO: echo ("<td><a href=\"".$_SERVER["PHP_SELF"]."?start=1&amp;fn=".urlencode($dirfile)."&amp;foffset=0&amp;totalqueries=0&amp;delimiter=".urlencode($delimiter)."\">Start Import</a></td>\n <td><a href=\"".$_SERVER["PHP_SELF"]."?delete=".urlencode($dirfile)."\">Delete file</a></td></tr>\n");
475
+ else
476
+ echo ("<td>&nbsp;</td>\n <td>&nbsp;</td></tr>\n");
477
+ }
478
+ }
479
+ }
480
+
481
+ if ($dirhead)
482
+ echo ("</table>\n");
483
+ else
484
+ echo ("<p>No uploaded SQL, GZ or CSV files found in the working directory</p>\n");
485
+ }
486
+ else
487
+ { echo ("<p class=\"error\">Error listing directory $upload_dir</p>\n");
488
+ $error=true;
489
+ }
490
+ }
491
+
492
+
493
+ // Single file mode
494
+
495
+ if (!$error && !isset ($_REQUEST["fn"]) && $filename!="")
496
+ { echo ("<p><a href=\"".$_SERVER["PHP_SELF"]."?start=1&amp;fn=".urlencode($filename)."&amp;foffset=0&amp;totalqueries=0\">Start Import</a> from $filename into $db_name at $db_server</p>\n");
497
+ }
498
+
499
+
500
+ // File Upload Form
501
+
502
+ if (!$error && !isset($_REQUEST["fn"]) && $filename=="")
503
+ {
504
+
505
+ // Test permissions on working directory
506
+
507
+ do { $tempfilename=$upload_dir.'/'.time().".tmp"; } while (file_exists($tempfilename));
508
+ if (!($tempfile=@fopen($tempfilename,"w")))
509
+ { 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 ");
510
+ echo ("to upload files here. Alternatively you can upload your dump files via FTP.</p>\n");
511
+ }
512
+ else
513
+ { fclose($tempfile);
514
+ unlink ($tempfilename);
515
+
516
+ echo ("<p>You can now upload your dump file up to $upload_max_filesize bytes (".round ($upload_max_filesize/1024/1024)." Mbytes) ");
517
+ echo ("directly from your browser to the server. Alternatively you can upload your dump files of any size via FTP.</p>\n");
518
+ ?>
519
+ <form method="POST" action="<?php echo ($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data">
520
+ <input type="hidden" name="MAX_FILE_SIZE" value="$upload_max_filesize">
521
+ <p>Dump file: <input type="file" name="dumpfile" accept="*/*" size=60"></p>
522
+ <p><input type="submit" name="uploadbutton" value="Upload"></p>
523
+ </form>
524
+ <?php
525
+ }
526
+ }
527
+
528
+ // Print the current mySQL connection charset
529
+
530
+ if (!$error && !TESTMODE && !isset($_REQUEST["fn"]))
531
+ {
532
+ $result = mysql_query("SHOW VARIABLES LIKE 'character_set_connection';");
533
+ $row = mysql_fetch_assoc($result);
534
+ if ($row)
535
+ { $charset = $row['Value'];
536
+ 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");
537
+ }
538
+ }
539
+
540
+ // Open the file
541
+
542
+ if (!$error && isset($_REQUEST["start"]))
543
+ {
544
+
545
+ // Set current filename ($filename overrides $_REQUEST["fn"] if set)
546
+
547
+ if ($filename!="")
548
+ $curfilename=$filename;
549
+ else if (isset($_REQUEST["fn"]))
550
+ $curfilename=urldecode($_REQUEST["fn"]);
551
+ else
552
+ $curfilename="";
553
+
554
+ // Recognize GZip filename
555
+
556
+ if (preg_match("/\.gz$/i",$curfilename))
557
+ $gzipmode=true;
558
+ else
559
+ $gzipmode=false;
560
+
561
+ if ((!$gzipmode && !$file=@fopen($upload_dir.'/'.$curfilename,"r")) || ($gzipmode && !$file=@gzopen($upload_dir.'/'.$curfilename,"r")))
562
+ { echo ("<p class=\"error\">Can't open ".$curfilename." for import</p>\n");
563
+ echo ("<p>Please, check that your dump file name contains only alphanumerical characters, and rename it accordingly, for example: $curfilename.".
564
+ "<br>Or, specify \$filename in bigdump.php with the full filename. ".
565
+ "<br>Or, you have to upload the $curfilename to the server first.</p>\n");
566
+ $error=true;
567
+ }
568
+
569
+ // Get the file size (can't do it fast on gzipped files, no idea how)
570
+
571
+ else if ((!$gzipmode && @fseek($file, 0, SEEK_END)==0) || ($gzipmode && @gzseek($file, 0)==0))
572
+ { if (!$gzipmode) $filesize = ftell($file);
573
+ else $filesize = gztell($file); // Always zero, ignore
574
+ }
575
+ else
576
+ { echo ("<p class=\"error\">I can't seek into $curfilename</p>\n");
577
+ $error=true;
578
+ }
579
+
580
+ // Stop if csv file is used, but $csv_insert_table is not set
581
+
582
+ if (!$error && ($csv_insert_table == "") && (preg_match("/(\.csv)$/i",$curfilename)))
583
+ { echo ("<p class=\"error\">You have to specify \$csv_insert_table when using a CSV file. </p>\n");
584
+ $error=true;
585
+ }
586
+ }
587
+
588
+
589
+ // *******************************************************************************************
590
+ // START IMPORT SESSION HERE
591
+ // *******************************************************************************************
592
+
593
+ if (!$error && isset($_REQUEST["start"]) && isset($_REQUEST["foffset"]) && preg_match("/(\.(sql|gz|csv))$/i",$curfilename))
594
+ {
595
+
596
+ do_action('session_start');
597
+
598
+ // Check start and foffset are numeric values
599
+
600
+ if (!is_numeric($_REQUEST["start"]) || !is_numeric($_REQUEST["foffset"]))
601
+ { echo ("<p class=\"error\">UNEXPECTED: Non-numeric values for start and foffset</p>\n");
602
+ $error=true;
603
+ }
604
+ else
605
+ { $_REQUEST["start"] = floor($_REQUEST["start"]);
606
+ $_REQUEST["foffset"] = floor($_REQUEST["foffset"]);
607
+ }
608
+
609
+ // Set the current delimiter if defined
610
+
611
+ if (isset($_REQUEST["delimiter"]))
612
+ $delimiter = $_REQUEST["delimiter"];
613
+
614
+ // Empty CSV table if requested
615
+
616
+ if (!$error && $_REQUEST["start"]==1 && $csv_insert_table != "" && $csv_preempty_table)
617
+ {
618
+ $query = "DELETE FROM `$csv_insert_table`";
619
+ if (!TESTMODE && !mysql_query(trim($query), $dbconnection))
620
+ { echo ("<p class=\"error\">Error when deleting entries from $csv_insert_table.</p>\n");
621
+ echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n");
622
+ echo ("<p>MySQL: ".mysql_error()."</p>\n");
623
+ $error=true;
624
+ }
625
+ }
626
+
627
+ // Print start message
628
+
629
+ if (!$error)
630
+ { skin_open();
631
+ if (TESTMODE)
632
+ echo ("<p class=\"centr\">TEST MODE ENABLED</p>\n");
633
+ echo ("<p class=\"centr\">Processing file: <b>".$curfilename."</b></p>\n");
634
+ echo ("<p class=\"smlcentr\">Starting from line: ".$_REQUEST["start"]."</p>\n");
635
+ skin_close();
636
+ }
637
+
638
+ // Check $_REQUEST["foffset"] upon $filesize (can't do it on gzipped files)
639
+
640
+ if (!$error && !$gzipmode && $_REQUEST["foffset"]>$filesize)
641
+ { echo ("<p class=\"error\">UNEXPECTED: Can't set file pointer behind the end of file</p>\n");
642
+ $error=true;
643
+ }
644
+
645
+ // Set file pointer to $_REQUEST["foffset"]
646
+
647
+ if (!$error && ((!$gzipmode && fseek($file, $_REQUEST["foffset"])!=0) || ($gzipmode && gzseek($file, $_REQUEST["foffset"])!=0)))
648
+ { echo ("<p class=\"error\">UNEXPECTED: Can't set file pointer to offset: ".$_REQUEST["foffset"]."</p>\n");
649
+ $error=true;
650
+ }
651
+
652
+ // Start processing queries from $file
653
+
654
+ if (!$error)
655
+ { $query="";
656
+ $queries=0;
657
+ $totalqueries=$_REQUEST["totalqueries"];
658
+ $linenumber=$_REQUEST["start"];
659
+ $querylines=0;
660
+ $inparents=false;
661
+
662
+ // Stay processing as long as the $linespersession is not reached or the query is still incomplete
663
+
664
+ while ($linenumber<$_REQUEST["start"]+$linespersession || $query!="")
665
+ {
666
+
667
+ // Read the whole next line
668
+
669
+ $dumpline = "";
670
+ while (!feof($file) && substr ($dumpline, -1) != "\n" && substr ($dumpline, -1) != "\r")
671
+ { if (!$gzipmode)
672
+ $dumpline .= fgets($file, DATA_CHUNK_LENGTH);
673
+ else
674
+ $dumpline .= gzgets($file, DATA_CHUNK_LENGTH);
675
+ }
676
+ if ($dumpline==="") break;
677
+
678
+ // Remove UTF8 Byte Order Mark at the file beginning if any
679
+
680
+ if ($_REQUEST["foffset"]==0)
681
+ $dumpline=preg_replace('|^\xEF\xBB\xBF|','',$dumpline);
682
+
683
+ // Create an SQL query from CSV line
684
+
685
+ if (($csv_insert_table != "") && (preg_match("/(\.csv)$/i",$curfilename)))
686
+ {
687
+ if ($csv_add_slashes)
688
+ $dumpline = addslashes($dumpline);
689
+ $dumpline = explode($csv_delimiter,$dumpline);
690
+ if ($csv_add_quotes)
691
+ $dumpline = "'".implode("','",$dumpline)."'";
692
+ else
693
+ $dumpline = implode(",",$dumpline);
694
+ $dumpline = 'INSERT INTO '.$csv_insert_table.' VALUES ('.$dumpline.');';
695
+ }
696
+
697
+ // Handle DOS and Mac encoded linebreaks (I don't know if it really works on Win32 or Mac Servers)
698
+
699
+ $dumpline=str_replace("\r\n", "\n", $dumpline);
700
+ $dumpline=str_replace("\r", "\n", $dumpline);
701
+
702
+ // DIAGNOSTIC
703
+ // echo ("<p>Line $linenumber: $dumpline</p>\n");
704
+
705
+ // Recognize delimiter statement
706
+
707
+ if (!$inparents && strpos ($dumpline, "DELIMITER ") === 0)
708
+ $delimiter = str_replace ("DELIMITER ","",trim($dumpline));
709
+
710
+ // Skip comments and blank lines only if NOT in parents
711
+
712
+ if (!$inparents)
713
+ { $skipline=false;
714
+ reset($comment);
715
+ foreach ($comment as $comment_value)
716
+ {
717
+
718
+ // DIAGNOSTIC
719
+ // echo ($comment_value);
720
+ if (trim($dumpline)=="" || strpos (trim($dumpline), $comment_value) === 0)
721
+ { $skipline=true;
722
+ break;
723
+ }
724
+ }
725
+ if ($skipline)
726
+ { $linenumber++;
727
+
728
+ // DIAGNOSTIC
729
+ // echo ("<p>Comment line skipped</p>\n");
730
+
731
+ continue;
732
+ }
733
+ }
734
+
735
+ // Remove double back-slashes from the dumpline prior to count the quotes ('\\' can only be within strings)
736
+
737
+ $dumpline_deslashed = str_replace ("\\\\","",$dumpline);
738
+
739
+ // Count ' and \' (or " and \") in the dumpline to avoid query break within a text field ending by $delimiter
740
+
741
+ $parents=substr_count ($dumpline_deslashed, $string_quotes)-substr_count ($dumpline_deslashed, "\\$string_quotes");
742
+ if ($parents % 2 != 0)
743
+ $inparents=!$inparents;
744
+
745
+ // Add the line to query
746
+
747
+ $query .= $dumpline;
748
+
749
+ // Don't count the line if in parents (text fields may include unlimited linebreaks)
750
+
751
+ if (!$inparents)
752
+ $querylines++;
753
+
754
+ // Stop if query contains more lines as defined by $max_query_lines
755
+
756
+ if ($querylines>$max_query_lines)
757
+ {
758
+ echo ("<p class=\"error\">Stopped at the line $linenumber. </p>");
759
+ echo ("<p>At this place the current query includes more than ".$max_query_lines." dump lines. That can happen if your dump file was ");
760
+ 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 ");
761
+ echo ("extended inserts or very long procedure definitions. Please read the <a href=\"http://www.ozerov.de/bigdump/usage/\">BigDump usage notes</a> ");
762
+ echo ("for more infos. Ask for our support services ");
763
+ echo ("in order to handle dump files containing extended inserts.</p>\n");
764
+ $error=true;
765
+ break;
766
+ }
767
+
768
+ // Execute query if end of query detected ($delimiter as last character) AND NOT in parents
769
+
770
+ // DIAGNOSTIC
771
+ // echo ("<p>Regex: ".'/'.preg_quote($delimiter).'$/'."</p>\n");
772
+ // echo ("<p>In Parents: ".($inparents?"true":"false")."</p>\n");
773
+ // echo ("<p>Line: $dumpline</p>\n");
774
+
775
+ if ((preg_match('/'.preg_quote($delimiter,'/').'$/',trim($dumpline)) || $delimiter=='') && !$inparents)
776
+ {
777
+
778
+ // Cut off delimiter of the end of the query
779
+
780
+ $query = substr(trim($query),0,-1*strlen($delimiter));
781
+
782
+ // DIAGNOSTIC
783
+ // echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n");
784
+
785
+ if (!TESTMODE && !mysql_query($query, $dbconnection))
786
+ { echo ("<p class=\"error\">Error at the line $linenumber: ". trim($dumpline)."</p>\n");
787
+ echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n");
788
+ echo ("<p>MySQL: ".mysql_error()."</p>\n");
789
+ $error=true;
790
+ break;
791
+ }
792
+ $totalqueries++;
793
+ $queries++;
794
+ $query="";
795
+ $querylines=0;
796
+ }
797
+ $linenumber++;
798
+ }
799
+ }
800
+
801
+ // Get the current file position
802
+
803
+ if (!$error)
804
+ { if (!$gzipmode)
805
+ $foffset = ftell($file);
806
+ else
807
+ $foffset = gztell($file);
808
+ if (!$foffset)
809
+ { echo ("<p class=\"error\">UNEXPECTED: Can't read the file pointer offset</p>\n");
810
+ $error=true;
811
+ }
812
+ }
813
+
814
+ // Print statistics
815
+
816
+ skin_open();
817
+
818
+ // echo ("<p class=\"centr\"><b>Statistics</b></p>\n");
819
+
820
+ if (!$error)
821
+ {
822
+ $lines_this = $linenumber-$_REQUEST["start"];
823
+ $lines_done = $linenumber-1;
824
+ $lines_togo = ' ? ';
825
+ $lines_tota = ' ? ';
826
+
827
+ $queries_this = $queries;
828
+ $queries_done = $totalqueries;
829
+ $queries_togo = ' ? ';
830
+ $queries_tota = ' ? ';
831
+
832
+ $bytes_this = $foffset-$_REQUEST["foffset"];
833
+ $bytes_done = $foffset;
834
+ $kbytes_this = round($bytes_this/1024,2);
835
+ $kbytes_done = round($bytes_done/1024,2);
836
+ $mbytes_this = round($kbytes_this/1024,2);
837
+ $mbytes_done = round($kbytes_done/1024,2);
838
+
839
+ if (!$gzipmode)
840
+ {
841
+ $bytes_togo = $filesize-$foffset;
842
+ $bytes_tota = $filesize;
843
+ $kbytes_togo = round($bytes_togo/1024,2);
844
+ $kbytes_tota = round($bytes_tota/1024,2);
845
+ $mbytes_togo = round($kbytes_togo/1024,2);
846
+ $mbytes_tota = round($kbytes_tota/1024,2);
847
+
848
+ $pct_this = ceil($bytes_this/$filesize*100);
849
+ $pct_done = ceil($foffset/$filesize*100);
850
+ $pct_togo = 100 - $pct_done;
851
+ $pct_tota = 100;
852
+
853
+ if ($bytes_togo==0)
854
+ { $lines_togo = '0';
855
+ $lines_tota = $linenumber-1;
856
+ $queries_togo = '0';
857
+ $queries_tota = $totalqueries;
858
+ }
859
+
860
+ $pct_bar = "<div style=\"height:15px;width:$pct_done%;background-color:#000080;margin:0px;\"></div>";
861
+ }
862
+ else
863
+ {
864
+ $bytes_togo = ' ? ';
865
+ $bytes_tota = ' ? ';
866
+ $kbytes_togo = ' ? ';
867
+ $kbytes_tota = ' ? ';
868
+ $mbytes_togo = ' ? ';
869
+ $mbytes_tota = ' ? ';
870
+
871
+ $pct_this = ' ? ';
872
+ $pct_done = ' ? ';
873
+ $pct_togo = ' ? ';
874
+ $pct_tota = 100;
875
+ $pct_bar = str_replace(' ','&nbsp;','<tt>[ Not available for gzipped files ]</tt>');
876
+ }
877
+
878
+ echo ("
879
+ <center>
880
+ <table width=\"520\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\">
881
+ <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>
882
+ <tr><th class=\"bg4\">Lines</th><td class=\"bg3\">$lines_this</td><td class=\"bg3\">$lines_done</td><td class=\"bg3\">$lines_togo</td><td class=\"bg3\">$lines_tota</td></tr>
883
+ <tr><th class=\"bg4\">Queries</th><td class=\"bg3\">$queries_this</td><td class=\"bg3\">$queries_done</td><td class=\"bg3\">$queries_togo</td><td class=\"bg3\">$queries_tota</td></tr>
884
+ <tr><th class=\"bg4\">Bytes</th><td class=\"bg3\">$bytes_this</td><td class=\"bg3\">$bytes_done</td><td class=\"bg3\">$bytes_togo</td><td class=\"bg3\">$bytes_tota</td></tr>
885
+ <tr><th class=\"bg4\">KB</th><td class=\"bg3\">$kbytes_this</td><td class=\"bg3\">$kbytes_done</td><td class=\"bg3\">$kbytes_togo</td><td class=\"bg3\">$kbytes_tota</td></tr>
886
+ <tr><th class=\"bg4\">MB</th><td class=\"bg3\">$mbytes_this</td><td class=\"bg3\">$mbytes_done</td><td class=\"bg3\">$mbytes_togo</td><td class=\"bg3\">$mbytes_tota</td></tr>
887
+ <tr><th class=\"bg4\">%</th><td class=\"bg3\">$pct_this</td><td class=\"bg3\">$pct_done</td><td class=\"bg3\">$pct_togo</td><td class=\"bg3\">$pct_tota</td></tr>
888
+ <tr><th class=\"bg4\">% bar</th><td class=\"bgpctbar\" colspan=\"4\">$pct_bar</td></tr>
889
+ </table>
890
+ </center>
891
+ \n");
892
+
893
+ // Finish message and restart the script
894
+
895
+ if ($linenumber<$_REQUEST["start"]+$linespersession)
896
+ { echo ("<p class=\"successcentr\">Congratulations: End of file reached, assuming OK</p>\n");
897
+ echo ("<p class=\"successcentr\">IMPORTANT: REMOVE YOUR DUMP FILE and BIGDUMP SCRIPT FROM SERVER NOW!</p>\n");
898
+ 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");
899
+ echo ("<p class=\"centr\">You can send me some bucks or euros as appreciation via PayPal. Thank you!</p>\n");
900
+ ?>
901
+
902
+ <!-- Start Paypal donation code -->
903
+ <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
904
+ <input type="hidden" name="cmd" value="_xclick" />
905
+ <input type="hidden" name="business" value="alexey@ozerov.de" />
906
+ <input type="hidden" name="item_name" value="BigDump Donation" />
907
+ <input type="hidden" name="no_shipping" value="1" />
908
+ <input type="hidden" name="no_note" value="0" />
909
+ <input type="hidden" name="tax" value="0" />
910
+ <input type="hidden" name="bn" value="PP-DonationsBF" />
911
+ <input type="hidden" name="lc" value="US" />
912
+ <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but04.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!" />
913
+ <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
914
+ </form>
915
+ <!-- End Paypal donation code -->
916
+
917
+ <?php
918
+ do_action('script_finished');
919
+ $error=true; // This is a semi-error telling the script is finished
920
+ }
921
+ else
922
+ { if ($delaypersession!=0)
923
+ echo ("<p class=\"centr\">Now I'm <b>waiting $delaypersession milliseconds</b> before starting next session...</p>\n");
924
+ if (!$ajax)
925
+ 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");
926
+
927
+ echo ("<noscript>\n");
928
+ echo ("<p class=\"centr\"><a href=\"".$_SERVER["PHP_SELF"]."?start=$linenumber&amp;fn=".urlencode($curfilename)."&amp;foffset=$foffset&amp;totalqueries=$totalqueries&amp;delimiter=".urlencode($delimiter)."\">Continue from the line $linenumber</a> (Enable JavaScript to do it automatically)</p>\n");
929
+ echo ("</noscript>\n");
930
+
931
+ echo ("<p class=\"centr\">Press <b><a href=\"".$_SERVER["PHP_SELF"]."\">STOP</a></b> to abort the import <b>OR WAIT!</b></p>\n");
932
+ }
933
+ }
934
+ else
935
+ echo ("<p class=\"error\">Stopped on error</p>\n");
936
+
937
+ skin_close();
938
+
939
+ }
940
+
941
+ if ($error)
942
+ echo ("<p class=\"centr\"><a href=\"".$_SERVER["PHP_SELF"]."\">Start from the beginning</a> (DROP the old tables before restarting)</p>\n");
943
+
944
+ if ($dbconnection) mysql_close($dbconnection);
945
+ if ($file && !$gzipmode) fclose($file);
946
+ else if ($file && $gzipmode) gzclose($file);
947
+
948
+ ?>
949
+
950
+ <p class="centr">&copy; 2003-2013 <a href="mailto:alexey@ozerov.de">Alexey Ozerov</a></p>
951
+
952
+ </td></tr></table>
953
+
954
+ </center>
955
+ <?php do_action('end_of_body'); ?>
956
+ </body>
957
+ </html>
958
+
959
+ <?php
960
+
961
+ // If error or finished put out the whole output from above and stop
962
+
963
+ if ($error)
964
+ {
965
+ $out1 = ob_get_contents();
966
+ ob_end_clean();
967
+ echo $out1;
968
+ die;
969
+ }
970
+
971
+ // If Ajax enabled and in import progress creates responses (XML response or script for the initial page)
972
+
973
+ if ($ajax && isset($_REQUEST['start']))
974
+ {
975
+ if (isset($_REQUEST['ajaxrequest']))
976
+ { ob_end_clean();
977
+ create_xml_response();
978
+ die;
979
+ }
980
+ else
981
+ create_ajax_script();
982
+ }
983
+
984
+ // Anyway put out the output from above
985
+
986
+ ob_flush();
987
+
988
+ // THE MAIN SCRIPT ENDS HERE
989
+
990
+ // *******************************************************************************************
991
+ // Plugin handling (EXPERIMENTAL)
992
+ // *******************************************************************************************
993
+
994
+ function do_action($tag)
995
+ { global $plugin_actions;
996
+
997
+ if (isset($plugin_actions[$tag]))
998
+ { reset ($plugin_actions[$tag]);
999
+ foreach ($plugin_actions[$tag] as $action)
1000
+ call_user_func_array($action, array());
1001
+ }
1002
+ }
1003
+
1004
+ function add_action($tag, $function)
1005
+ {
1006
+ global $plugin_actions;
1007
+ $plugin_actions[$tag][] = $function;
1008
+ }
1009
+
1010
+ // *******************************************************************************************
1011
+ // AJAX utilities
1012
+ // *******************************************************************************************
1013
+
1014
+ function create_xml_response()
1015
+ {
1016
+ global $linenumber, $foffset, $totalqueries, $curfilename, $delimiter,
1017
+ $lines_this, $lines_done, $lines_togo, $lines_tota,
1018
+ $queries_this, $queries_done, $queries_togo, $queries_tota,
1019
+ $bytes_this, $bytes_done, $bytes_togo, $bytes_tota,
1020
+ $kbytes_this, $kbytes_done, $kbytes_togo, $kbytes_tota,
1021
+ $mbytes_this, $mbytes_done, $mbytes_togo, $mbytes_tota,
1022
+ $pct_this, $pct_done, $pct_togo, $pct_tota,$pct_bar;
1023
+
1024
+ header('Content-Type: application/xml');
1025
+ header('Cache-Control: no-cache');
1026
+
1027
+ echo '<?xml version="1.0" encoding="ISO-8859-1"?>';
1028
+ echo "<root>";
1029
+
1030
+ // data - for calculations
1031
+
1032
+ echo "<linenumber>$linenumber</linenumber>";
1033
+ echo "<foffset>$foffset</foffset>";
1034
+ echo "<fn>$curfilename</fn>";
1035
+ echo "<totalqueries>$totalqueries</totalqueries>";
1036
+ echo "<delimiter>$delimiter</delimiter>";
1037
+
1038
+ // results - for page update
1039
+
1040
+ echo "<elem1>$lines_this</elem1>";
1041
+ echo "<elem2>$lines_done</elem2>";
1042
+ echo "<elem3>$lines_togo</elem3>";
1043
+ echo "<elem4>$lines_tota</elem4>";
1044
+
1045
+ echo "<elem5>$queries_this</elem5>";
1046
+ echo "<elem6>$queries_done</elem6>";
1047
+ echo "<elem7>$queries_togo</elem7>";
1048
+ echo "<elem8>$queries_tota</elem8>";
1049
+
1050
+ echo "<elem9>$bytes_this</elem9>";
1051
+ echo "<elem10>$bytes_done</elem10>";
1052
+ echo "<elem11>$bytes_togo</elem11>";
1053
+ echo "<elem12>$bytes_tota</elem12>";
1054
+
1055
+ echo "<elem13>$kbytes_this</elem13>";
1056
+ echo "<elem14>$kbytes_done</elem14>";
1057
+ echo "<elem15>$kbytes_togo</elem15>";
1058
+ echo "<elem16>$kbytes_tota</elem16>";
1059
+
1060
+ echo "<elem17>$mbytes_this</elem17>";
1061
+ echo "<elem18>$mbytes_done</elem18>";
1062
+ echo "<elem19>$mbytes_togo</elem19>";
1063
+ echo "<elem20>$mbytes_tota</elem20>";
1064
+
1065
+ echo "<elem21>$pct_this</elem21>";
1066
+ echo "<elem22>$pct_done</elem22>";
1067
+ echo "<elem23>$pct_togo</elem23>";
1068
+ echo "<elem24>$pct_tota</elem24>";
1069
+ echo "<elem_bar>".htmlentities($pct_bar)."</elem_bar>";
1070
+
1071
+ echo "</root>";
1072
+ }
1073
+
1074
+
1075
+ function create_ajax_script()
1076
+ {
1077
+ global $linenumber, $foffset, $totalqueries, $delaypersession, $curfilename, $delimiter;
1078
+ ?>
1079
+
1080
+ <script type="text/javascript" language="javascript">
1081
+
1082
+ // creates next action url (upload page, or XML response)
1083
+ function get_url(linenumber,fn,foffset,totalqueries,delimiter) {
1084
+ return "<?php echo $_SERVER['PHP_SELF'] ?>?start="+linenumber+"&fn="+fn+"&foffset="+foffset+"&totalqueries="+totalqueries+"&delimiter="+delimiter+"&ajaxrequest=true";
1085
+ }
1086
+
1087
+ // extracts text from XML element (itemname must be unique)
1088
+ function get_xml_data(itemname,xmld) {
1089
+ return xmld.getElementsByTagName(itemname).item(0).firstChild.data;
1090
+ }
1091
+
1092
+ function makeRequest(url) {
1093
+ http_request = false;
1094
+ if (window.XMLHttpRequest) {
1095
+ // Mozilla etc.
1096
+ http_request = new XMLHttpRequest();
1097
+ if (http_request.overrideMimeType) {
1098
+ http_request.overrideMimeType("text/xml");
1099
+ }
1100
+ } else if (window.ActiveXObject) {
1101
+ // IE
1102
+ try {
1103
+ http_request = new ActiveXObject("Msxml2.XMLHTTP");
1104
+ } catch(e) {
1105
+ try {
1106
+ http_request = new ActiveXObject("Microsoft.XMLHTTP");
1107
+ } catch(e) {}
1108
+ }
1109
+ }
1110
+ if (!http_request) {
1111
+ alert("Cannot create an XMLHTTP instance");
1112
+ return false;
1113
+ }
1114
+ http_request.onreadystatechange = server_response;
1115
+ http_request.open("GET", url, true);
1116
+ http_request.send(null);
1117
+ }
1118
+
1119
+ function server_response()
1120
+ {
1121
+
1122
+ // waiting for correct response
1123
+ if (http_request.readyState != 4)
1124
+ return;
1125
+
1126
+ if (http_request.status != 200)
1127
+ {
1128
+ alert("Page unavailable, or wrong url!")
1129
+ return;
1130
+ }
1131
+
1132
+ // r = xml response
1133
+ var r = http_request.responseXML;
1134
+
1135
+ //if received not XML but HTML with new page to show
1136
+ if (!r || r.getElementsByTagName('root').length == 0)
1137
+ { var text = http_request.responseText;
1138
+ document.open();
1139
+ document.write(text);
1140
+ document.close();
1141
+ return;
1142
+ }
1143
+
1144
+ // update "Starting from line: "
1145
+ document.getElementsByTagName('p').item(1).innerHTML =
1146
+ "Starting from line: " +
1147
+ r.getElementsByTagName('linenumber').item(0).firstChild.nodeValue;
1148
+
1149
+ // update table with new values
1150
+ for(i = 1; i <= 24; i++)
1151
+ document.getElementsByTagName('td').item(i).firstChild.data = get_xml_data('elem'+i,r);
1152
+
1153
+ // update color bar
1154
+ document.getElementsByTagName('td').item(25).innerHTML =
1155
+ r.getElementsByTagName('elem_bar').item(0).firstChild.nodeValue;
1156
+
1157
+ // action url (XML response)
1158
+ url_request = get_url(
1159
+ get_xml_data('linenumber',r),
1160
+ get_xml_data('fn',r),
1161
+ get_xml_data('foffset',r),
1162
+ get_xml_data('totalqueries',r),
1163
+ get_xml_data('delimiter',r));
1164
+
1165
+ // ask for XML response
1166
+ window.setTimeout("makeRequest(url_request)",500+<?php echo $delaypersession; ?>);
1167
+ }
1168
+
1169
+ // First Ajax request from initial page
1170
+
1171
+ var http_request = false;
1172
+ var url_request = get_url(<?php echo ($linenumber.',"'.urlencode($curfilename).'",'.$foffset.','.$totalqueries.',"'.urlencode($delimiter).'"') ;?>);
1173
+ window.setTimeout("makeRequest(url_request)",500+<?php echo $delaypersession; ?>);
1174
+ </script>
1175
+
1176
+ <?php
1177
+ }
1178
+
1179
+ ?>