1: <?php
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45: chdir("..");
46: require ("include/classes/db/config_db.php");
47: $db_server = DB_SERVER;
48: $db_name = DB_NAME;
49: $db_username = DB_USER;
50: $db_password = DB_PASS;
51:
52:
53:
54: include("locale/localization.php");
55: include("include/functions/common.php");
56: $allowed_langs = array ('de', 'en');
57: $lang = get_browser_language($allowed_langs, 'de', null, false);
58: $filename = 'sql/OpenHomeopath.sql.gz';
59: $ajax = true;
60: $linespersession = 3000;
61: $delaypersession = 0;
62:
63:
64:
65:
66: $csv_insert_table = '';
67: $csv_preempty_table = false;
68: $csv_delimiter = ',';
69: $csv_add_quotes = true;
70: $csv_add_slashes = true;
71:
72:
73:
74: $comment[]='#';
75: $comment[]='-- ';
76: $comment[]='DELIMITER';
77:
78:
79: $comment[]='/*!';
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90: $db_connection_charset = 'utf8';
91:
92:
93:
94:
95: $delimiter = ';';
96:
97:
98:
99: $string_quotes = '\'';
100:
101:
102:
103:
104:
105:
106: if ($ajax)
107: ob_start();
108:
109: define ('VERSION','0.34b');
110: define ('DATA_CHUNK_LENGTH',16384);
111: define ('MAX_QUERY_LINES',300);
112: define ('TESTMODE',false);
113:
114: header("Expires: Mon, 1 Dec 2003 01:00:00 GMT");
115: header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
116: header("Cache-Control: no-store, no-cache, must-revalidate");
117: header("Cache-Control: post-check=0, pre-check=0", false);
118: header("Pragma: no-cache");
119: header("Content-Type: text/html;charset=utf-8");
120:
121: @ini_set('auto_detect_line_endings', true);
122: @set_time_limit(0);
123: @ignore_user_abort(true);
124:
125: if (function_exists("date_default_timezone_set") && function_exists("date_default_timezone_get"))
126: @date_default_timezone_set(@date_default_timezone_get());
127:
128:
129:
130: foreach ($_REQUEST as $key => $val)
131: {
132: $val = preg_replace("/[^_A-Za-z0-9-\.&= ;\$]/i",'', $val);
133: $_REQUEST[$key] = $val;
134: }
135:
136: ?>
137: <!DOCTYPE html>
138: <html>
139: <head>
140: <title><?php echo _("OpenHomeopath - Data Maintenance Administration"); ?></title>
141: <meta charset="utf-8">
142: <link rel="stylesheet" href="../skins/original/css/openhomeopath.css" media="screen">
143: <link rel="stylesheet" href="../css/styles_screen.css" media="screen">
144: <meta http-equiv="Cache-Control" content="no-cache/">
145: <meta http-equiv="Pragma" content="no-cache">
146: <meta http-equiv="Expires" content="-1">
147: <meta name="robots" content="noindex, nofollow">
148:
149: <style>
150: <!--
151: p,td,th
152: { font-size:14px;
153: line-height:18px;
154: font-family:Arial,Helvetica,sans-serif;
155: margin-top:5px;
156: margin-bottom:5px;
157: text-align:justify;
158: vertical-align:top;
159: }
160:
161: p.centr
162: {
163: text-align:center;
164: }
165:
166: p.smlcentr
167: { font-size:10px;
168: line-height:14px;
169: text-align:center;
170: }
171:
172: p.error
173: { color:
174: font-weight:bold;
175: }
176:
177: p.success
178: { color:
179: font-weight:bold;
180: }
181:
182: p.successcentr
183: { color:
184: background-color:
185: font-weight:bold;
186: text-align:center;
187: }
188:
189: td
190: { background-color:
191: text-align:left;
192: }
193:
194: td.transparent
195: { background-color:
196: }
197:
198: th
199: { font-weight:bold;
200: color:
201: background-color:
202: text-align:left;
203: }
204:
205: td.right
206: { text-align:right;
207: }
208:
209: form
210: { margin-top:5px;
211: margin-bottom:5px;
212: }
213:
214: div.skin1
215: {
216: border-color:
217: border-width:5px;
218: border-style:solid;
219: background-color:
220: text-align:center;
221: vertical-align:middle;
222: padding:3px;
223: margin:1px;
224: }
225:
226: td.bg3
227: { background-color:
228: text-align:left;
229: vertical-align:top;
230: width:20%;
231: }
232:
233: th.bg4
234: { background-color:
235: text-align:left;
236: vertical-align:top;
237: width:20%;
238: }
239:
240: td.bgpctbar
241: { background-color:
242: text-align:left;
243: vertical-align:middle;
244: width:80%;
245: }
246:
247: -->
248: </style>
249: <script>
250: function zweifel () {
251: return confirm ("<?php echo _("Are you sure ?"); ?>");
252: }
253: </script>
254: </head>
255: <body>
256: <div id="container">
257: <div id="ornateFrame">
258: <img src="../skins/original/img/hahnemann.jpg" width="90" height="120" alt="Samuel Hahnemann">
259: </div>
260: <div id="top">
261: <a name="up" title="<?php echo _("Top of the page"); ?>"></a>
262: <div id="banner">
263: <img src="../skins/original/img/openhomeopath.gif" width="480" height="76" alt="OpenHomeopath">
264: </div>
265: </div>
266: <div id="middle">
267: <table cellspacing="0" id="middle_tbl">
268: <tr>
269: <td id="middle_cell01">
270: <ul class="Navigation">
271: <li>
272:
273: </li>
274: <li>
275:
276: </li>
277: <li>
278: <a href="../index.php"><?php echo _("Repertorization"); ?></a>
279: </li>
280: <li>
281: <a href="../index.php?tab=2"><?php echo _("Materia Medica"); ?></a>
282: </li>
283: <li>
284: <a href="../datadmin.php"><?php echo _("Data maintenance"); ?></a>
285: </li>
286: <li>
287: <a href="../help/<?php echo $lang; ?>/index.php"><?php echo _("Help"); ?></a>
288: </li>
289: <li>
290: <a href="../doc/<?php echo $lang; ?>/info.php"><?php echo _("Info"); ?></a>
291: </li>
292: </ul>
293: </td>
294: <td id="middle_cell02">
295: <div id="pagecontent">
296: <br>
297: <br>
298: <table class="main_table" cellpadding="10">
299: <tr>
300: <td valign="top">
301: <br>
302: <h1><?php echo _("OpenHomeopath - Install database"); ?></h1>
303: <br>
304:
305: <table width="780" cellspacing="0" cellpadding="0">
306: <tr><td class="transparent">
307:
308:
309: <?php
310: function skin_open() {
311: echo ('<div class="skin1">');
312: }
313:
314: function skin_close() {
315: echo ('</div>');
316: }
317:
318: $error = false;
319: $file = false;
320:
321:
322:
323: if (!$error && !function_exists('version_compare'))
324: { echo ("<p class=\"error\">PHP version 4.1.0 is required for BigDump to proceed. You have PHP ".phpversion()." installed. Sorry!</p>\n");
325: $error=true;
326: }
327:
328:
329:
330: if (!$error && !function_exists('mysql_connect'))
331: { echo ("<p class=\"error\">There is no mySQL extension available in your PHP installation. Sorry!</p>\n");
332: $error=true;
333: }
334:
335:
336:
337: if (!$error)
338: { $upload_max_filesize=ini_get("upload_max_filesize");
339: if (preg_match("/([0-9]+)K/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024;
340: if (preg_match("/([0-9]+)M/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024*1024;
341: if (preg_match("/([0-9]+)G/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024*1024*1024;
342: }
343:
344:
345:
346: if (isset($_SERVER["CGIA"]))
347: $upload_dir=dirname($_SERVER["CGIA"]);
348: elseif (isset($_SERVER["ORIG_PATH_TRANSLATED"]))
349: $upload_dir=dirname($_SERVER["ORIG_PATH_TRANSLATED"]);
350: elseif (isset($_SERVER["ORIG_SCRIPT_FILENAME"]))
351: $upload_dir=dirname($_SERVER["ORIG_SCRIPT_FILENAME"]);
352: elseif (isset($_SERVER["PATH_TRANSLATED"]))
353: $upload_dir=dirname($_SERVER["PATH_TRANSLATED"]);
354: else
355: $upload_dir=dirname($_SERVER["SCRIPT_FILENAME"]);
356:
357:
358:
359: if (!$error && isset($_REQUEST["uploadbutton"]))
360: { if (is_uploaded_file($_FILES["dumpfile"]["tmp_name"]) && ($_FILES["dumpfile"]["error"])==0)
361: {
362: $uploaded_filename=str_replace(" ","_",$_FILES["dumpfile"]["name"]);
363: $uploaded_filename=preg_replace("/[^_A-Za-z0-9-\.]/i",'',$uploaded_filename);
364: $uploaded_filepath=str_replace("\\","/",$upload_dir."/".$uploaded_filename);
365:
366: if (file_exists($uploaded_filename))
367: { echo ("<p class=\"error\">File $uploaded_filename already exist! Delete and upload again!</p>\n");
368: }
369: elseif (!preg_match("/(\.(sql|gz|csv))$/i",$uploaded_filename))
370: { echo ("<p class=\"error\">You may only upload .sql .gz or .csv files.</p>\n");
371: }
372: elseif (!@move_uploaded_file($_FILES["dumpfile"]["tmp_name"],$uploaded_filepath))
373: { echo ("<p class=\"error\">Error moving uploaded file ".$_FILES["dumpfile"]["tmp_name"]." to the $uploaded_filepath</p>\n");
374: echo ("<p>Check the directory permissions for $upload_dir (must be 777)!</p>\n");
375: }
376: else
377: { echo ("<p class=\"success\">Uploaded file saved as $uploaded_filename</p>\n");
378: }
379: }
380: else
381: { echo ("<p class=\"error\">Error uploading file ".$_FILES["dumpfile"]["name"]."</p>\n");
382: }
383: }
384:
385:
386:
387:
388: if (!$error && isset($_REQUEST["delete"]) && $_REQUEST["delete"]!=basename($_SERVER["SCRIPT_FILENAME"]))
389: { if (preg_match("/(\.(sql|gz|csv))$/i",$_REQUEST["delete"]) && @unlink(basename($_REQUEST["delete"])))
390: echo ("<p class=\"success\">".$_REQUEST["delete"]." was removed successfully</p>\n");
391: else
392: echo ("<p class=\"error\">Can't remove ".$_REQUEST["delete"]."</p>\n");
393: }
394:
395:
396:
397: if (!$error && !TESTMODE)
398: { $dbconnection = @mysql_connect($db_server,$db_username,$db_password);
399: if ($dbconnection)
400: $db = mysql_select_db($db_name);
401: if (!$dbconnection || !$db)
402: { echo ("<p class=\"error\">Database connection failed due to ".mysql_error()."</p>\n");
403: echo ("<p>Edit the database settings in ".$_SERVER["SCRIPT_FILENAME"]." or contact your database provider.</p>\n");
404: $error=true;
405: }
406: if (!$error && $db_connection_charset!=='')
407: @mysql_query("SET NAMES $db_connection_charset", $dbconnection);
408:
409: if (!$error && isset ($pre_query) && sizeof ($pre_query)>0)
410: { reset($pre_query);
411: foreach ($pre_query as $pre_query_value)
412: { if (!@mysql_query($pre_query_value, $dbconnection))
413: { echo ("<p class=\"error\">Error with pre-query.</p>\n");
414: echo ("<p>Query: ".trim(nl2br(htmlentities($pre_query_value)))."</p>\n");
415: echo ("<p>MySQL: ".mysql_error()."</p>\n");
416: $error=true;
417: break;
418: }
419: }
420: }
421: }
422: else
423: { $dbconnection = false;
424: }
425:
426:
427:
428:
429:
430:
431:
432: if (!$error && !isset($_REQUEST["fn"]) && $filename=="")
433: { if ($dirhandle = opendir($upload_dir))
434: {
435: $files=array();
436: while (false !== ($files[] = readdir($dirhandle)));
437: closedir($dirhandle);
438: $dirhead=false;
439:
440: if (sizeof($files)>0)
441: {
442: sort($files);
443: foreach ($files as $dirfile)
444: {
445: if ($dirfile != "." && $dirfile != ".." && $dirfile!=basename($_SERVER["SCRIPT_FILENAME"]) && preg_match("/\.(sql|gz|csv)$/i",$dirfile))
446: { if (!$dirhead)
447: { echo ("<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\">\n");
448: echo ("<tr><th>Filename</th><th>Size</th><th>Date&Time</th><th>Type</th><th> </th><th> </th>\n");
449: $dirhead=true;
450: }
451: echo ("<tr><td>$dirfile</td><td class=\"right\">".filesize($dirfile)."</td><td>".date ("Y-m-d H:i:s", filemtime($dirfile))."</td>");
452:
453: if (preg_match("/\.sql$/i",$dirfile))
454: echo ("<td>SQL</td>");
455: elseif (preg_match("/\.gz$/i",$dirfile))
456: echo ("<td>GZip</td>");
457: elseif (preg_match("/\.csv$/i",$dirfile))
458: echo ("<td>CSV</td>");
459: else
460: echo ("<td>Misc</td>");
461:
462: if ((preg_match("/\.gz$/i",$dirfile) && function_exists("gzopen")) || preg_match("/\.sql$/i",$dirfile) || preg_match("/\.csv$/i",$dirfile))
463: echo ("<td><a href=\"".$_SERVER["PHP_SELF"]."?start=1&fn=".urlencode($dirfile)."&foffset=0&totalqueries=0&delimiter=".urlencode($delimiter)."\">" . _("Install database") . "</td>\n <td><a href=\"".$_SERVER["PHP_SELF"]."?delete=".urlencode($dirfile)."\">Delete file</a></td></tr>\n");
464: else
465: echo ("<td> </td>\n <td> </td></tr>\n");
466: }
467: }
468: }
469:
470: if ($dirhead)
471: echo ("</table>\n");
472: else
473: echo ("<p>No uploaded SQL, GZ or CSV files found in the working directory</p>\n");
474: }
475: else
476: { echo ("<p class=\"error\">Error listing directory $upload_dir</p>\n");
477: $error=true;
478: }
479: }
480:
481:
482:
483:
484: if (!$error && !isset ($_REQUEST["fn"]) && $filename!="")
485: {
486: ?>
487: <div class='center'>
488: <form action='<?php echo $_SERVER["PHP_SELF"];?>' method='post' onsubmit='return zweifel()'>
489: <input type='hidden' name='start' value='1'>
490: <input type='hidden' name='fn' value=<?php echo urlencode($filename);?>>
491: <input type='hidden' name='foffset' value='0'>
492: <input type='hidden' name='totalqueries' value='0'>
493: <input type='submit' value='<?php echo _("Install database");?>'>
494: </form>
495: <br><p><strong><?php echo _("Be careful! An existing OpenHomeopath-database will be overwritten!");?></strong></p>
496: <p><strong><?php echo _("The installation of the database needs some time. Please be patient!");?></strong></p>
497: </div>
498: <br><br>
499: <?php
500: }
501:
502:
503:
504:
505: if (!$error && !isset($_REQUEST["fn"]) && $filename=="")
506: {
507:
508:
509:
510: do { $tempfilename=time().".tmp"; } while (file_exists($tempfilename));
511: if (!($tempfile=@fopen($tempfilename,"w")))
512: { 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 ");
513: echo ("to upload files here. Alternatively you can upload your dump files via FTP.</p>\n");
514: }
515: else
516: { fclose($tempfile);
517: unlink ($tempfilename);
518:
519: echo ("<p>You can now upload your dump file up to $upload_max_filesize bytes (".round ($upload_max_filesize/1024/1024)." Mbytes) ");
520: echo ("directly from your browser to the server. Alternatively you can upload your dump files of any size via FTP.</p>\n");
521: ?>
522: <form method="POST" action="<?php echo ($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data">
523: <input type="hidden" name="MAX_FILE_SIZE" value="$upload_max_filesize">
524: <p>Dump file: <input type="file" name="dumpfile" accept="*/*" size=60"></p>
525: <p><input type="submit" name="uploadbutton" value="Upload"></p>
526: </form>
527: <?php
528: }
529: }
530:
531: // Print the current mySQL connection charset
532:
533: // if (!$error && !TESTMODE && !isset($_REQUEST["fn"]))
534: // {
535: // $result = mysql_query("SHOW VARIABLES LIKE 'character_set_connection';");
536: // $row = mysql_fetch_assoc($result);
537: // if ($row)
538: // { $charset = $row['Value'];
539: // 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 install_db.php</p>\n");
540: // }
541: // }
542:
543: // Open the file
544:
545: if (!$error && isset($_REQUEST["start"]))
546: {
547:
548: // Set current filename ($filename overrides $_REQUEST["fn"] if set)
549:
550: if ($filename!="")
551: $curfilename=$filename;
552: elseif (isset($_REQUEST["fn"]))
553: $curfilename=urldecode($_REQUEST["fn"]);
554: else
555: $curfilename="";
556:
557: // Recognize GZip filename
558:
559: if (preg_match("/\.gz$/i",$curfilename))
560: $gzipmode=true;
561: else
562: $gzipmode=false;
563:
564: if ((!$gzipmode && !$file=@fopen($curfilename,"r")) || ($gzipmode && !$file=@gzopen($curfilename,"r")))
565: { echo ("<p class=\"error\">Can't open ".$curfilename." for import</p>\n");
566: echo ("<p>Please, check that your dump file name contains only alphanumerical characters, and rename it accordingly, for example: $curfilename.".
567: "<br>Or, specify \$filename in install_db.php with the full filename. ".
568: "<br>Or, you have to upload the $curfilename to the server first.</p>\n");
569: $error=true;
570: }
571:
572:
573:
574: elseif ((!$gzipmode && @fseek($file, 0, SEEK_END)==0) || ($gzipmode && @gzseek($file, 0)==0))
575: { if (!$gzipmode) $filesize = ftell($file);
576: else $filesize = gztell($file);
577: }
578: else
579: { echo ("<p class=\"error\">I can't seek into $curfilename</p>\n");
580: $error=true;
581: }
582: }
583:
584:
585:
586: if (($csv_insert_table == "") && (preg_match("/(\.csv)$/i",$filename)))
587: { echo ("<p class=\"error\">You have to specify \$csv_insert_table when using a CSV file. </p>\n");
588: $error=true;
589: }
590:
591:
592:
593:
594:
595:
596: if (!$error && isset($_REQUEST["start"]) && isset($_REQUEST["foffset"]) && preg_match("/(\.(sql|gz|csv))$/i",$curfilename))
597: {
598:
599:
600:
601: if (!is_numeric($_REQUEST["start"]) || !is_numeric($_REQUEST["foffset"]))
602: { echo ("<p class=\"error\">UNEXPECTED: Non-numeric values for start and foffset</p>\n");
603: $error=true;
604: }
605: else
606: { $_REQUEST["start"] = floor($_REQUEST["start"]);
607: $_REQUEST["foffset"] = floor($_REQUEST["foffset"]);
608: }
609:
610:
611:
612: if (isset($_REQUEST["delimiter"]))
613: $delimiter = $_REQUEST["delimiter"];
614:
615:
616:
617: if (!$error && $_REQUEST["start"]==1 && $csv_insert_table != "" && $csv_preempty_table)
618: {
619: $query = "DELETE FROM $csv_insert_table";
620: if (!TESTMODE && !mysql_query(trim($query), $dbconnection))
621: { echo ("<p class=\"error\">Error when deleting entries from $csv_insert_table.</p>\n");
622: echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n");
623: echo ("<p>MySQL: ".mysql_error()."</p>\n");
624: $error=true;
625: }
626: }
627:
628:
629:
630: if (!$error)
631: { skin_open();
632: if (TESTMODE)
633: echo ("<p class=\"centr\">TEST MODE ENABLED</p>\n");
634: echo ("<p class=\"centr\">Processing file: <b>".$curfilename."</b></p>\n");
635: echo ("<p class=\"smlcentr\">Starting from line: ".$_REQUEST["start"]."</p>\n");
636: skin_close();
637: }
638:
639:
640:
641: if (!$error && !$gzipmode && $_REQUEST["foffset"]>$filesize)
642: { echo ("<p class=\"error\">UNEXPECTED: Can't set file pointer behind the end of file</p>\n");
643: $error=true;
644: }
645:
646:
647:
648: if (!$error && ((!$gzipmode && fseek($file, $_REQUEST["foffset"])!=0) || ($gzipmode && gzseek($file, $_REQUEST["foffset"])!=0)))
649: { echo ("<p class=\"error\">UNEXPECTED: Can't set file pointer to offset: ".$_REQUEST["foffset"]."</p>\n");
650: $error=true;
651: }
652:
653:
654:
655: if (!$error)
656: { $query="";
657: $queries=0;
658: $totalqueries=$_REQUEST["totalqueries"];
659: $linenumber=$_REQUEST["start"];
660: $querylines=0;
661: $inparents=false;
662:
663:
664:
665: while ($linenumber<$_REQUEST["start"]+$linespersession || $query!="")
666: {
667:
668:
669:
670: $dumpline = "";
671: while (!feof($file) && substr ($dumpline, -1) != "\n" && substr ($dumpline, -1) != "\r")
672: { if (!$gzipmode)
673: $dumpline .= fgets($file, DATA_CHUNK_LENGTH);
674: else
675: $dumpline .= gzgets($file, DATA_CHUNK_LENGTH);
676: }
677: if ($dumpline==="") break;
678:
679:
680:
681: if ($_REQUEST["foffset"]==0)
682: $dumpline=preg_replace('|^\xEF\xBB\xBF|','',$dumpline);
683:
684:
685:
686: if (($csv_insert_table != "") && (preg_match("/(\.csv)$/i",$curfilename)))
687: {
688: if ($csv_add_slashes)
689: $dumpline = addslashes($dumpline);
690: $dumpline = explode($csv_delimiter,$dumpline);
691: if ($csv_add_quotes)
692: $dumpline = "'".implode("','",$dumpline)."'";
693: else
694: $dumpline = implode(",",$dumpline);
695: $dumpline = 'INSERT INTO '.$csv_insert_table.' VALUES ('.$dumpline.');';
696: }
697:
698:
699:
700: $dumpline=str_replace("\r\n", "\n", $dumpline);
701: $dumpline=str_replace("\r", "\n", $dumpline);
702:
703:
704:
705:
706:
707:
708: if (!$inparents && strpos ($dumpline, "DELIMITER ") === 0)
709: $delimiter = str_replace ("DELIMITER ","",trim($dumpline));
710:
711:
712:
713: if (!$inparents)
714: { $skipline=false;
715: reset($comment);
716: foreach ($comment as $comment_value)
717: {
718:
719:
720:
721: if (trim($dumpline)=="" || strpos (trim($dumpline), $comment_value) === 0)
722: { $skipline=true;
723: break;
724: }
725: }
726: if ($skipline)
727: { $linenumber++;
728:
729:
730:
731:
732: continue;
733: }
734: }
735:
736:
737:
738: $dumpline_deslashed = str_replace ("\\\\","",$dumpline);
739:
740:
741:
742: $parents=substr_count ($dumpline_deslashed, $string_quotes)-substr_count ($dumpline_deslashed, "\\$string_quotes");
743: if ($parents % 2 != 0)
744: $inparents=!$inparents;
745:
746:
747:
748: $query .= $dumpline;
749:
750:
751:
752: if (!$inparents)
753: $querylines++;
754:
755:
756:
757: if ($querylines>MAX_QUERY_LINES)
758: {
759: echo ("<p class=\"error\">Stopped at the line $linenumber. </p>");
760: echo ("<p>At this place the current query includes more than ".MAX_QUERY_LINES." dump lines. That can happen if your dump file was ");
761: 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 ");
762: echo ("extended inserts or very long procedure definitions. Please read the <a href=\"http://www.ozerov.de/bigdump/usage/\">BigDump usage notes</a> ");
763: echo ("for more infos. Ask for our support services ");
764: echo ("in order to handle dump files containing extended inserts.</p>\n");
765: $error=true;
766: break;
767: }
768:
769:
770:
771:
772:
773:
774:
775:
776: if (preg_match('/'.preg_quote($delimiter).'$/',trim($dumpline)) && !$inparents)
777: {
778:
779:
780:
781: $query = substr(trim($query),0,-1*strlen($delimiter));
782:
783:
784:
785:
786: if (!TESTMODE && !mysql_query($query, $dbconnection))
787: { echo ("<p class=\"error\">Error at the line $linenumber: ". trim($dumpline)."</p>\n");
788: echo ("<p>Query: ".trim(nl2br(htmlentities($query)))."</p>\n");
789: echo ("<p>MySQL: ".mysql_error()."</p>\n");
790: $error=true;
791: break;
792: }
793: $totalqueries++;
794: $queries++;
795: $query="";
796: $querylines=0;
797: }
798: $linenumber++;
799: }
800: }
801:
802:
803:
804: if (!$error)
805: { if (!$gzipmode)
806: $foffset = ftell($file);
807: else
808: $foffset = gztell($file);
809: if (!$foffset)
810: { echo ("<p class=\"error\">UNEXPECTED: Can't read the file pointer offset</p>\n");
811: $error=true;
812: }
813: }
814:
815:
816:
817: skin_open();
818:
819:
820:
821: if (!$error)
822: {
823: $lines_this = $linenumber-$_REQUEST["start"];
824: $lines_done = $linenumber-1;
825: $lines_togo = ' ? ';
826: $lines_tota = ' ? ';
827:
828: $queries_this = $queries;
829: $queries_done = $totalqueries;
830: $queries_togo = ' ? ';
831: $queries_tota = ' ? ';
832:
833: $bytes_this = $foffset-$_REQUEST["foffset"];
834: $bytes_done = $foffset;
835: $kbytes_this = round($bytes_this/1024,2);
836: $kbytes_done = round($bytes_done/1024,2);
837: $mbytes_this = round($kbytes_this/1024,2);
838: $mbytes_done = round($kbytes_done/1024,2);
839:
840: if (!$gzipmode)
841: {
842: $bytes_togo = $filesize-$foffset;
843: $bytes_tota = $filesize;
844: $kbytes_togo = round($bytes_togo/1024,2);
845: $kbytes_tota = round($bytes_tota/1024,2);
846: $mbytes_togo = round($kbytes_togo/1024,2);
847: $mbytes_tota = round($kbytes_tota/1024,2);
848:
849: $pct_this = ceil($bytes_this/$filesize*100);
850: $pct_done = ceil($foffset/$filesize*100);
851: $pct_togo = 100 - $pct_done;
852: $pct_tota = 100;
853:
854: if ($bytes_togo==0)
855: { $lines_togo = '0';
856: $lines_tota = $linenumber-1;
857: $queries_togo = '0';
858: $queries_tota = $totalqueries;
859: }
860:
861: $pct_bar = "<div style=\"height:15px;width:$pct_done%;background-color:#000080;margin:0;\"></div>";
862: }
863: else
864: {
865: $bytes_togo = ' ? ';
866: $bytes_tota = ' ? ';
867: $kbytes_togo = ' ? ';
868: $kbytes_tota = ' ? ';
869: $mbytes_togo = ' ? ';
870: $mbytes_tota = ' ? ';
871:
872: $pct_this = ' ? ';
873: $pct_done = ' ? ';
874: $pct_togo = ' ? ';
875: $pct_tota = 100;
876: $pct_bar = str_replace(' ',' ','<tt>[ Not available for gzipped files ]</tt>');
877: }
878:
879: echo ("
880: <div class='center'>
881: <table width=\"520\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\">
882: <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>
883: <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>
884: <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>
885: <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>
886: <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>
887: <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>
888: <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>
889: <tr><th class=\"bg4\">% bar</th><td class=\"bgpctbar\" colspan=\"4\">$pct_bar</td></tr>
890: </table>
891: </div>
892: \n");
893:
894:
895:
896: if ($linenumber<$_REQUEST["start"]+$linespersession) {
897: echo ("<p class='successcentr'>" . _("Congratulations:") . " " . _("the file was parsed and everything seems alright!") . "</p>\n");
898: echo ("<p> " . _("You should delete now the file 'install/OpenHomeopath.sql.gz' on the server.") . "\n");
899: echo ("<br> " . _("First the file need some discspace and second when you run 'install_db.php' all new data will be deleted.") . "\n");
900: ?>
901:
902: <?php
903:
904: $error=true;
905: }
906: else
907: { if ($delaypersession!=0) {
908: printf ("<p class='centr'>" . _("Now I'm <b>waiting %d milliseconds</b> before starting next session...") . "</p>\n", $delaypersession);
909: }
910: if (!$ajax)
911: echo ("<script language=\"JavaScript\">window.setTimeout('location.href=\"".$_SERVER["PHP_SELF"]."?start=$linenumber&fn=".urlencode($curfilename)."&foffset=$foffset&totalqueries=$totalqueries&delimiter=".urlencode($delimiter)."\";',500+$delaypersession);</script>\n");
912:
913: echo ("<noscript>\n");
914: 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");
915: echo ("</noscript>\n");
916:
917: echo ("<p class='centr'>" . _("Press") . " <b><a href='".$_SERVER["PHP_SELF"]."'>" . _("STOP</a></b> to stop the import or be <b>passioned!</b><") . "/p>\n");
918: }
919: }
920: else
921: echo ("<p class='error'>" . _("Stopped because of an error") . "</p>\n");
922:
923: skin_close();
924:
925: }
926:
927: if ($error)
928: echo ("<p class=\"centr\"><a href=\"".$_SERVER["PHP_SELF"]."\">Start from the beginning</a> (DROP the old tables before restarting)</p>\n");
929:
930: if ($dbconnection) mysql_close($dbconnection);
931: if ($file && !$gzipmode) fclose($file);
932: elseif ($file && $gzipmode) gzclose($file);
933:
934: ?>
935:
936: </td></tr></table>
937:
938: </div>
939:
940: <div id="footer">
941: <a href="../doc/<?php echo $lang; ?>/info.php#license">Copyright</a> © 2007-2012 by Henri Schumacher <br><?php echo _("OpenHomeopath is distributed under the terms of the <a href='../doc/en/agpl3.php'>AGPL-License</a>"); ?> <br><a title="<?php echo _("Contact to the author"); ?>" href="mailto:henri.hulski@gazeta.pl?subject=Homeopath"><?php echo _("Contact to the author"); ?></a>
942: </div>
943: </body>
944: </html>
945:
946: <?php
947:
948:
949:
950: if ($error)
951: {
952: $out1 = ob_get_contents();
953: ob_end_clean();
954: echo $out1;
955: die;
956: }
957:
958:
959:
960: if ($ajax && isset($_REQUEST['start']))
961: {
962: if (isset($_REQUEST['ajaxrequest']))
963: { ob_end_clean();
964: create_xml_response();
965: die;
966: }
967: else
968: create_ajax_script();
969: }
970:
971:
972:
973: ob_flush();
974:
975:
976:
977:
978:
979:
980:
981:
982: function create_xml_response()
983: {
984: global $linenumber, $foffset, $totalqueries, $curfilename, $delimiter,
985: $lines_this, $lines_done, $lines_togo, $lines_tota,
986: $queries_this, $queries_done, $queries_togo, $queries_tota,
987: $bytes_this, $bytes_done, $bytes_togo, $bytes_tota,
988: $kbytes_this, $kbytes_done, $kbytes_togo, $kbytes_tota,
989: $mbytes_this, $mbytes_done, $mbytes_togo, $mbytes_tota,
990: $pct_this, $pct_done, $pct_togo, $pct_tota,$pct_bar;
991:
992: header('Content-Type: application/xml');
993: header('Cache-Control: no-cache');
994:
995: echo '<?xml version="1.0" encoding="ISO-8859-1"?>';
996: echo "<root>";
997:
998:
999:
1000: echo "<linenumber>$linenumber</linenumber>";
1001: echo "<foffset>$foffset</foffset>";
1002: echo "<fn>$curfilename</fn>";
1003: echo "<totalqueries>$totalqueries</totalqueries>";
1004: echo "<delimiter>$delimiter</delimiter>";
1005:
1006:
1007:
1008: echo "<elem1>$lines_this</elem1>";
1009: echo "<elem2>$lines_done</elem2>";
1010: echo "<elem3>$lines_togo</elem3>";
1011: echo "<elem4>$lines_tota</elem4>";
1012:
1013: echo "<elem5>$queries_this</elem5>";
1014: echo "<elem6>$queries_done</elem6>";
1015: echo "<elem7>$queries_togo</elem7>";
1016: echo "<elem8>$queries_tota</elem8>";
1017:
1018: echo "<elem9>$bytes_this</elem9>";
1019: echo "<elem10>$bytes_done</elem10>";
1020: echo "<elem11>$bytes_togo</elem11>";
1021: echo "<elem12>$bytes_tota</elem12>";
1022:
1023: echo "<elem13>$kbytes_this</elem13>";
1024: echo "<elem14>$kbytes_done</elem14>";
1025: echo "<elem15>$kbytes_togo</elem15>";
1026: echo "<elem16>$kbytes_tota</elem16>";
1027:
1028: echo "<elem17>$mbytes_this</elem17>";
1029: echo "<elem18>$mbytes_done</elem18>";
1030: echo "<elem19>$mbytes_togo</elem19>";
1031: echo "<elem20>$mbytes_tota</elem20>";
1032:
1033: echo "<elem21>$pct_this</elem21>";
1034: echo "<elem22>$pct_done</elem22>";
1035: echo "<elem23>$pct_togo</elem23>";
1036: echo "<elem24>$pct_tota</elem24>";
1037: echo "<elem_bar>".htmlentities($pct_bar)."</elem_bar>";
1038:
1039: echo "</root>";
1040: }
1041:
1042:
1043: function create_ajax_script()
1044: {
1045: global $linenumber, $foffset, $totalqueries, $delaypersession, $curfilename, $delimiter;
1046: ?>
1047:
1048: <script language="javascript">
1049:
1050:
1051: function get_url(linenumber,fn,foffset,totalqueries,delimiter) {
1052: return "<?php echo $_SERVER['PHP_SELF'] ?>?start="+linenumber+"&fn="+fn+"&foffset="+foffset+"&totalqueries="+totalqueries+"&delimiter="+delimiter+"&ajaxrequest=true";
1053: }
1054:
1055:
1056: function get_xml_data(itemname,xmld) {
1057: return xmld.getElementsByTagName(itemname).item(0).firstChild.data;
1058: }
1059:
1060: function makeRequest(url) {
1061: http_request = false;
1062: if (window.XMLHttpRequest) {
1063:
1064: http_request = new XMLHttpRequest();
1065: if (http_request.overrideMimeType) {
1066: http_request.overrideMimeType("text/xml");
1067: }
1068: } else if (window.ActiveXObject) {
1069:
1070: try {
1071: http_request = new ActiveXObject("Msxml2.XMLHTTP");
1072: } catch(e) {
1073: try {
1074: http_request = new ActiveXObject("Microsoft.XMLHTTP");
1075: } catch(e) {}
1076: }
1077: }
1078: if (!http_request) {
1079: alert("Cannot create an XMLHTTP instance");
1080: return false;
1081: }
1082: http_request.onreadystatechange = server_response;
1083: http_request.open("GET", url, true);
1084: http_request.send(null);
1085: }
1086:
1087: function server_response()
1088: {
1089:
1090:
1091: if (http_request.readyState != 4)
1092: return;
1093:
1094: if (http_request.status != 200)
1095: {
1096: alert("Page unavailable, or wrong url!");
1097: return;
1098: }
1099:
1100:
1101: var r = http_request.responseXML;
1102:
1103:
1104: if (!r || r.getElementsByTagName('root').length == 0)
1105: { var text = http_request.responseText;
1106: document.open();
1107: document.write(text);
1108: document.close();
1109: return;
1110: }
1111:
1112:
1113: document.getElementsByTagName('p').item(1).innerHTML =
1114: "Starting from line: " +
1115: r.getElementsByTagName('linenumber').item(0).firstChild.nodeValue;
1116:
1117:
1118: for(var i = 1; i <= 24; i++)
1119: document.getElementsByTagName('td').item(i).firstChild.data = get_xml_data('elem'+i,r);
1120:
1121:
1122: document.getElementsByTagName('td').item(25).innerHTML =
1123: r.getElementsByTagName('elem_bar').item(0).firstChild.nodeValue;
1124:
1125:
1126: url_request = get_url(
1127: get_xml_data('linenumber',r),
1128: get_xml_data('fn',r),
1129: get_xml_data('foffset',r),
1130: get_xml_data('totalqueries',r),
1131: get_xml_data('delimiter',r));
1132:
1133:
1134: window.setTimeout("makeRequest(url_request)",500+<?php echo $delaypersession; ?>);
1135: }
1136:
1137:
1138:
1139: var http_request = false;
1140: var url_request = get_url(<?php echo ($linenumber.',"'.urlencode($curfilename).'",'.$foffset.','.$totalqueries.',"'.urlencode($delimiter).'"') ;?>);
1141: window.setTimeout("makeRequest(url_request)",500+<?php echo $delaypersession; ?>);
1142: </script>
1143:
1144: <?php
1145: }
1146:
1147: ?>
1148: