OSDN Git Service

move sqlite
[nucleus-jp/nucleus-plugins.git] / sqlite / tags / sqlite0903 / sqlite / nucleus / plugins / sqlite / restore.php
1 <?php
2     /***************************************
3     * SQLite-MySQL database transfer tool  *
4     *                           ver 0.8.0  *
5     * Written by Katsumi                   *
6     ***************************************/
7     
8 // This library is GPL.
9
10 error_reporting(E_ERROR | E_WARNING);
11 chdir('../../../');
12 if (!file_exists('./nucleus/sqlite/sqlite.php')) exit;
13
14 if (!isset($_GET['dbfile'])) exit;
15
16 $dbfile=str_replace(array('\\','/'),array('',''),$_GET['dbfile']);
17 if (isset($_GET['numatonce'])) $numatonce=(int)$_GET['numatonce'];
18 else $numatonce=20;
19 if (isset($_GET['refreshwait'])) $refreshwait=(int)$_GET['refreshwait'];
20 else $refreshwait=1;
21
22 // Check $dbfile
23 if (substr($dbfile,0,1)=='.') exit;
24 if (preg_match('/\.php$/i',$dbfile)) exit;
25 if (preg_match('/\.htm$/i',$dbfile)) exit;
26 if (preg_match('/\.html$/i',$dbfile)) exit;
27 if (!file_exists('./nucleus/sqlite/'.$dbfile)) exit;
28
29 include ('./nucleus/sqlite/sqlite.php');
30
31 $dbarray=file('./nucleus/sqlite/'.$dbfile);
32 if (isset($_GET['dbpoint'])) $dbpoint=(int)$_GET['dbpoint'];
33 else $dbpoint=0;
34 $ret='';
35 $err=false;
36
37 while ($numatonce--) {
38         $query='';
39         $instring=false;
40         $cont=true;
41         
42         //Remove comment
43         while (@is_string(($t=$dbarray[$dbpoint]))) {
44                 if (trim($t)!='' && substr($t,0,1)!='#' && substr($t,0,2)!='--') break;
45                 $dbpoint++;
46         }
47         
48         //Get query string from array
49         while ($cont && @is_string($dbarray[$dbpoint])) {
50                 $t=$dbarray[$dbpoint++];
51                 while ($t) {
52                         if ($instring) {
53                                 for ($i=0;$i<strlen($t);$i++) {
54                                         $query.=($c=$t[0]);
55                                         $t=substr($t,1);
56                                         if ($c=="'") {
57                                                 $instring=false;
58                                                 break;
59                                         } else if ($c=="\\") {
60                                                 $query.=$t[0];
61                                                 $t=substr($t,1);
62                                         }
63                                 }
64                                 continue;
65                         }
66                         if (($c=$t[0])==';') {
67                                 $cont=false;
68                                 break;
69                         }
70                         $query.=$c;
71                         $t=substr($t,1);
72                         if ($c=="'") $instring=true;
73                 }
74         }
75         if ($query) {
76                 if (nucleus_mysql_query($query)) $ret.="OK<br/>".htmlspecialchars(substr($query,0,200)).".....<hr />\n";
77                 else $err=true;
78         }
79 }
80 nucleus_mysql_close();
81
82 //Set 'dbtotal'
83 $dbtotal=$dbpoint;
84 while (@is_string(($dbarray[$dbtotal]))) $dbtotal++;
85
86 if ($dbtotal==$dbpoint)  { // All done.
87         unlink('./nucleus/sqlite/'.$dbfile);
88         if (@include('./nucleus/language/japanese-utf8.php')) $lng='UTF-8';
89         else if (@include('./nucleus/language/japanese-euc.php')) $lng='EUC-JP';
90         else $lng='';
91         echo "<html><head><title>Restore Complete</title>\n";
92         if ($lng) echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=$lng\" />\n";
93         echo "</head><body>\n";
94         if ($lng) {
95                 echo '<p>'._RESTORE_COMPLETE.'</p>';
96                 echo '<p><a href="../../">'._BACKTOMANAGE.'</a></p>';
97         } else {
98                 echo '<p>Restore Complete</p>';
99                 echo '<p><a href="../../">Back to Nucleus management</a></p>';
100         }
101         echo "\n</body></html>";
102         exit;
103 }
104
105 $f=(int)((float)100*$dbpoint/$dbtotal);
106 $ret="$f % done.<hr>\n".$ret;
107
108 if (isset($_GET['numatonce'])) $numatonce=$_GET['numatonce'];
109 else $numatonce=20;
110 $url="?dbfile=$dbfile&amp;numatonce=$numatonce&amp;refreshwait=$refreshwait&amp;dbpoint=$dbpoint";
111 if ($err) $refresh='';
112 else $refresh="<meta http-equiv=\"refresh\" content=\"$refreshwait; url=$url\">";
113
114 ?><html><head>
115 <title>Creating database file</title>
116 <?php echo $refresh; ?>
117 </head><body>
118 <a href="<?php echo $url; ?>">Continue</a><hr />
119 <?php echo $ret;
120 ?></body></html>