1 | <?php |
---|
2 | $stoppage = true; |
---|
3 | |
---|
4 | $struct = $opt = $data = array(); |
---|
5 | $dir = opendir('./sql'); |
---|
6 | while ($file = readdir($dir)) |
---|
7 | { |
---|
8 | if (strpos($file, 'sql_') !== false) |
---|
9 | { |
---|
10 | $table = str_replace(array('sql_tblstrct_', 'sql_tbldata_opt_', 'sql_tbldata_', '.sql'), '', $file); |
---|
11 | $table = 'kb3_'.preg_replace('/(_p\d{1,4})/', '', $table); |
---|
12 | if (strpos($file, 'tblstrct')) |
---|
13 | { |
---|
14 | $structc++; |
---|
15 | $struct[$table][] = $file; |
---|
16 | } |
---|
17 | elseif (strpos($file, '_opt_')) |
---|
18 | { |
---|
19 | $dcnt++; |
---|
20 | $optcnt++; |
---|
21 | $opt[$table][] = $file; |
---|
22 | } |
---|
23 | else |
---|
24 | { |
---|
25 | $dcnt++; |
---|
26 | $datacnt++; |
---|
27 | $data[$table][] = $file; |
---|
28 | } |
---|
29 | } |
---|
30 | } |
---|
31 | $db = mysql_pconnect($_SESSION['sql']['host'], $_SESSION['sql']['user'], $_SESSION['sql']['pass']); |
---|
32 | mysql_select_db($_SESSION['sql']['db']); |
---|
33 | $result = mysql_query('show tables'); |
---|
34 | while ($row = mysql_fetch_row($result)) |
---|
35 | { |
---|
36 | $table = $row[0]; |
---|
37 | unset($struct[$table]); |
---|
38 | } |
---|
39 | |
---|
40 | if ($_REQUEST['sub'] == 'struct') |
---|
41 | { |
---|
42 | foreach ($struct as $table => $files) |
---|
43 | { |
---|
44 | foreach ($files as $file) |
---|
45 | { |
---|
46 | echo 'Creating table '.$table.' from file '.$file.'...'; |
---|
47 | $query = file_get_contents('./sql/'.$file); |
---|
48 | $id = mysql_query($query); |
---|
49 | if ($id) |
---|
50 | { |
---|
51 | echo 'done<br/>'; |
---|
52 | } |
---|
53 | else |
---|
54 | { |
---|
55 | echo 'error: '.mysql_error().'<br/>'; |
---|
56 | } |
---|
57 | } |
---|
58 | unset($struct[$table]); |
---|
59 | } |
---|
60 | } |
---|
61 | if ($_REQUEST['do'] == 'reset') |
---|
62 | { |
---|
63 | unset($_SESSION['sqlinsert']); |
---|
64 | unset($_SESSION['doopt']); |
---|
65 | } |
---|
66 | |
---|
67 | if ($_REQUEST['sub'] == 'data') |
---|
68 | { |
---|
69 | if (!isset($_SESSION['sqlinsert'])) |
---|
70 | { |
---|
71 | $_SESSION['sqlinsert'] = 1; |
---|
72 | if (isset($_POST['opt'])) |
---|
73 | { |
---|
74 | $_SESSION['useopt'] = array(); |
---|
75 | foreach ($_POST['opt'] as $table => $value) |
---|
76 | { |
---|
77 | $_SESSION['useopt'][] = $table; |
---|
78 | } |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | $i = 0; |
---|
83 | $did = false; |
---|
84 | if (!isset($_SESSION['doopt'])) |
---|
85 | { |
---|
86 | foreach ($data as $table => $files) |
---|
87 | { |
---|
88 | foreach ($files as $file) |
---|
89 | { |
---|
90 | $i++; |
---|
91 | if ($_SESSION['sqlinsert'] > $i) |
---|
92 | { |
---|
93 | continue; |
---|
94 | } |
---|
95 | echo 'Inserting data ('.$i.'/'.$datacnt.') into '.$table.' from file '.$file.'...'; |
---|
96 | $querys = file('./sql/'.$file); |
---|
97 | foreach ($querys as $query) |
---|
98 | { |
---|
99 | $id = mysql_query($query); |
---|
100 | } |
---|
101 | if ($id) |
---|
102 | { |
---|
103 | echo 'done<br/>'; |
---|
104 | } |
---|
105 | else |
---|
106 | { |
---|
107 | echo 'error: '.mysql_error().'<br/>'; |
---|
108 | } |
---|
109 | $_SESSION['sqlinsert']++; |
---|
110 | echo '<meta http-equiv="refresh" content="1; URL=?step=4&sub=data" />'; |
---|
111 | echo 'Automatic reload in 1s for next chunk. <a href="?step=4&sub=data">Manual Link</a><br/>'; |
---|
112 | $did = true; |
---|
113 | break 2; |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | if (isset($_SESSION['useopt']) && !$did) |
---|
119 | { |
---|
120 | $i = 0; |
---|
121 | if (!isset($_SESSION['doopt'])) |
---|
122 | { |
---|
123 | $_SESSION['doopt'] = true; |
---|
124 | $_SESSION['sqlinsert'] = 1; |
---|
125 | } |
---|
126 | foreach ($opt as $table => $files) |
---|
127 | { |
---|
128 | if (!in_array($table, $_SESSION['useopt'])) |
---|
129 | { |
---|
130 | continue; |
---|
131 | } |
---|
132 | foreach ($files as $file) |
---|
133 | { |
---|
134 | $optsel++; |
---|
135 | } |
---|
136 | } |
---|
137 | foreach ($opt as $table => $files) |
---|
138 | { |
---|
139 | if (!in_array($table, $_SESSION['useopt'])) |
---|
140 | { |
---|
141 | continue; |
---|
142 | } |
---|
143 | foreach ($files as $file) |
---|
144 | { |
---|
145 | $i++; |
---|
146 | if ($_SESSION['sqlinsert'] > $i) |
---|
147 | { |
---|
148 | continue; |
---|
149 | } |
---|
150 | echo 'Inserting optional data ('.$i.'/'.$optsel.') into '.$table.' from file '.$file.'...'; |
---|
151 | $querys = file('./sql/'.$file); |
---|
152 | foreach ($querys as $query) |
---|
153 | { |
---|
154 | $id = mysql_query($query); |
---|
155 | } |
---|
156 | if ($id) |
---|
157 | { |
---|
158 | echo 'done<br/>'; |
---|
159 | } |
---|
160 | else |
---|
161 | { |
---|
162 | echo 'error: '.mysql_error().'<br/>'; |
---|
163 | } |
---|
164 | $_SESSION['sqlinsert']++; |
---|
165 | echo '<meta http-equiv="refresh" content="1; URL=?step=4&sub=data" />'; |
---|
166 | echo 'Automatic reload in 1s for next chunk. <a href="?step=4&sub=data">Manual Reload</a><br/>'; |
---|
167 | $did = true; |
---|
168 | break 2; |
---|
169 | } |
---|
170 | } |
---|
171 | } |
---|
172 | if (!$did) |
---|
173 | { |
---|
174 | echo 'All tables imported. You can now create or search your corporation/alliance: <a href="?step=5">Continue</a><br/>'; |
---|
175 | $stoppage = false; |
---|
176 | } |
---|
177 | echo '<a href="?step=4&sub=datasel&do=reset">Reset</a><br/>'; |
---|
178 | } |
---|
179 | ?> |
---|
180 | <div class="block-header2">MySQL Data Import</div> |
---|
181 | Found <?php echo $structc; ?> table structures and <?php echo $dcnt; ?> data files for <?php echo count($opt)+count($data); ?> tables.<br/> |
---|
182 | <?php |
---|
183 | |
---|
184 | $structadd = 0; |
---|
185 | foreach ($struct as $table => $file) |
---|
186 | { |
---|
187 | echo 'Table struct has to be added: '.$table.'<br/>'; |
---|
188 | $structadd++; |
---|
189 | } |
---|
190 | if (!$structadd && $_REQUEST['sub'] != 'datasel' && $_REQUEST['sub'] != 'data') |
---|
191 | { |
---|
192 | echo 'All table structures seem to be in the database, please continue with <a href="?step=4&sub=datasel">Importing Data</a><br/>'; |
---|
193 | echo '<br/><br/>In case you aborted the install and you got already data in those table you can bypass the import now by with <a href="?step=5">this link</a><br/>'; |
---|
194 | } |
---|
195 | elseif ($structadd) |
---|
196 | { |
---|
197 | echo 'Some table structures have to be added, please continue with <a href="?step=4&sub=struct">Creating Tables</a><br/>'; |
---|
198 | } |
---|
199 | |
---|
200 | if ($_REQUEST['sub'] == 'datasel') |
---|
201 | { |
---|
202 | ?> |
---|
203 | <p>Please select optional SQL data to be inserted into the database:<br/></p> |
---|
204 | <form id="options" name="options" method="post" action="?step=4"> |
---|
205 | <input type="hidden" name="step" value="4"> |
---|
206 | <input type="hidden" name="sub" value="data"> |
---|
207 | <table class="kb-subtable"> |
---|
208 | <?php |
---|
209 | foreach ($opt as $table => $files) |
---|
210 | { |
---|
211 | ?> |
---|
212 | <tr><td width="120"><b><?php echo $table; ?></b></td><td><input type="checkbox" name="opt[<?php echo $table; ?>]"></td></tr> |
---|
213 | <?php |
---|
214 | } |
---|
215 | ?> |
---|
216 | <tr><td width="120"></td><td><input type=submit name=submit value="Ok"></td></tr> |
---|
217 | </table> |
---|
218 | <?php |
---|
219 | } |
---|
220 | ?> |
---|
221 | <?php if ($stoppage) |
---|
222 | { |
---|
223 | return; |
---|
224 | }?> |
---|
225 | <p><a href="?step=<?php echo ($_SESSION['state']+1); ?>">Next Step</a></p> |
---|