source: trunk/export/export.php@ 231

Last change on this file since 231 was 231, checked in by maron, 16 years ago

úprava exportu sql podle verze, u exportu mangosu exportuje pouze tabulky mangosu

File size: 15.4 KB
Line 
1<?php
2
3function ExportToMangosSQL($Setting)
4{
5 global $Database, $Config, $TranslationTree, $LanguageList;
6
7 $AnoNe = array('Ne', 'Ano');
8 if($_SESSION['UserID'] != '')
9 {
10 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE ID='.$_SESSION['UserID']);
11 $User = mysql_fetch_assoc($DbResult);
12 } else $User = array('user' => 'Neznámý');
13
14 $WhereLang = '';
15 foreach($LanguageList as $Language)
16 if($Language['Enabled'] == 1)
17 if(isset($Setting['language'.$Language['Id']])) $WhereLang .= ' OR (Language = '.$Language['Id'].')';
18 if($WhereLang == '') $WhereLang = 1;
19 else $WhereLang = '('.substr($WhereLang, 4).')';
20
21 $SelectedUsers = '';
22 foreach($Setting['users-selection'] as $Item)
23 $SelectedUsers .= ','.$Item;
24 $SelectedUsers = substr($SelectedUsers, 1);
25
26 if($SelectedUsers == '') $Where = 0;
27 else $Where = 'ID IN ('.$SelectedUsers.')';
28
29 $UserNames = '';
30 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE '.$Where);
31 while($DbRow = mysql_fetch_assoc($DbResult))
32 $UserNames .= ','.$DbRow['user'];
33 $UserNames = substr($UserNames, 1);
34
35 if($SelectedUsers == '') $WhereUsers = 1;
36 else $WhereUsers = '(User IN ('.$SelectedUsers.'))';
37
38 $Buffer =
39 "-- Generováno projektem wowpreklad.zdechov.net\n".
40 "-- ===========================================\n".
41 "--\n".
42 "-- Web projektu: ".$Config['Web']['BaseURL']."\n".
43 "-- Datum exportu: ".date("j.n.Y H:i:s")."\n".
44 "-- Znaková sada: ".$Config['Database']['Charset']." / ".$Config['Web']['Charset']."\n".
45 "-- Diakritika: ".$AnoNe[$Setting['Diacritics']]."\n".
46 "-- Vygeneroval uživatel: ".$User['user']."\n".
47 "-- Vzato od uživatelů: ".$UserNames."\n".
48 "-- Generované tabulky: ";
49 foreach($TranslationTree as $Group)
50 if($Group['MangosTable'] != '')
51 if(in_array($Group['Id'], $Setting['groups']))
52 $Buffer .= $Group['MangosTable'].', ';
53 $Buffer .= "\n\n";
54
55 foreach($TranslationTree as $Group)
56 if(in_array($Group['Id'], $Setting['groups']))
57 {
58 if($Group['MangosTable'] != '')
59 {
60 $Query = 'SELECT * FROM (SELECT * FROM '.$Group['TablePrefix'].' WHERE (Complete = 1) AND VersionStart <= '.GetBuildNumber($Setting['Version']).' AND VersionEnd >= '.GetBuildNumber($Setting['Version']).' AND '.$WhereLang.' AND '.$WhereUsers.' ORDER BY FIELD(User, '.$SelectedUsers.')) AS T GROUP BY T.entry';
61 //echo($Query);
62 $Buffer .= "\n\n-- ".$Group['Name']."\n\n";
63 $ID = $Database->SQLCommand($Query);
64 while($Line = mysql_fetch_array($ID))
65 {
66 $Values = '';
67 foreach($Group['Items'] as $GroupItem)
68 {
69 if($GroupItem['MangosColumn'] == '') $GroupItem['MangosColumn'] = $GroupItem['Column'];
70 $Values .= ', `'.$GroupItem['MangosColumn'].'`="'.addslashes($Line[$GroupItem['Column']]).'"';
71 }
72 $Values = substr($Values, 2);
73 $Buffer .= 'UPDATE `'.$Group['MangosTable'].'` SET '.$Values.' WHERE `'.$Group['MangosTableIndex'].'` = '.$Line['entry'].';'."\n";
74 }
75 }
76 }
77 if($Setting['Diacritics'] != 1) $Buffer = utf2ascii($Buffer);
78 return($Buffer);
79}
80
81function ExportToAoWoWSQL($Setting)
82{
83 global $Database, $Config, $TranslationTree, $AoWoWconf, $LanguageList;
84
85 require_once('../aowow/configs/config.php');
86
87 $Buffer = ExportToMangosSQL($Setting);
88
89 $AnoNe = array('Ne', 'Ano');
90 if($_SESSION['UserID'] != '')
91 {
92 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE ID='.$_SESSION['UserID']);
93 $User = mysql_fetch_assoc($DbResult);
94 } else $User = array('user' => 'Neznámý');
95
96 $WhereLang = '';
97 foreach($LanguageList as $Language)
98 if($Language['Enabled'] == 1)
99 if(isset($Setting['language'.$Language['Id']])) $WhereLang .= ' OR (Language = '.$Language['Id'].')';
100 if($WhereLang == '') $WhereLang = 1;
101 else $WhereLang = '('.substr($WhereLang, 4).')';
102
103 $SelectedUsers = '';
104 foreach($Setting['users-selection'] as $Item)
105 $SelectedUsers .= ','.$Item;
106 $SelectedUsers = substr($SelectedUsers, 1);
107
108 if($SelectedUsers == '') $Where = 0;
109 else $Where = 'ID IN ('.$SelectedUsers.')';
110
111 $UserNames = '';
112 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE '.$Where);
113 while($DbRow = mysql_fetch_assoc($DbResult))
114 $UserNames .= ','.$DbRow['user'];
115 $UserNames = substr($UserNames, 1);
116
117 if($SelectedUsers == '') $WhereUsers = 1;
118 else $WhereUsers = '(User IN ('.$SelectedUsers.'))';
119
120 // Data to aowow
121
122 $Database->SelectDatabase($AoWoWconf['mangos']['db']);
123 $Database->SQLCommand('SET NAMES '.$Config['Database']['Charset']);
124 $AoWoWTables = array('aowow_resistances' => 'Id', 'aowow_spelldispeltype' => 'Id', 'aowow_skill' => 'skillID');
125 foreach($AoWoWTables as $AoWoWTable => $IndexColum)
126 {
127 $Buffer .= '--'.$AoWoWTable.', ';
128 $Buffer .= "\n\n";
129 $Query = 'SELECT name,'.$IndexColum.' FROM '.$AoWoWTable;
130 $ID = $Database->SQLCommand($Query);
131 while($Line = mysql_fetch_assoc($ID))
132 {
133 $Ori_text = $Line['name'];
134 $Tran = mysql_fetch_assoc($Database->SQLCommand('SELECT text as en,
135 (SELECT text FROM '.$Config['Database']['Database'].'.global_strings as tabletran
136 WHERE tableen.entry = tabletran.entry AND (Complete = 1) AND '.$WhereLang.'
137 AND '.$WhereUsers.' ORDER BY FIELD(User, '.$SelectedUsers.') LIMIT 1) as tran
138 FROM '.$Config['Database']['Database'].'.global_strings as tableen WHERE
139 text = "'.addslashes($Ori_text).'" LIMIT 1'));
140 //echo ($Line['name'].'='.$Tran['tran']);
141 if ($Tran['tran'] == '')
142 {
143 $Tran = mysql_fetch_assoc($Database->SQLCommand('SELECT OptionText as en,
144 (SELECT OptionText FROM '.$Config['Database']['Database'].'.npc_option as tabletran
145 WHERE tableen.entry = tabletran.entry AND (Complete = 1) AND '.$WhereLang.'
146 AND '.$WhereUsers.' ORDER BY FIELD(User, '.$SelectedUsers.') LIMIT 1) as tran
147 FROM '.$Config['Database']['Database'].'.npc_option as tableen WHERE
148 OptionText = "'.addslashes($Ori_text).'" LIMIT 1'));
149 }
150 if ($Tran['tran'] <> '')
151 $Buffer .= 'UPDATE `'.$AoWoWTable.'` SET name = "'.addslashes($Tran['tran']).'" WHERE '.$IndexColum.' = '.$Line[$IndexColum].' ;'."\n";
152 }
153 $Buffer .= "\n\n";
154 }
155 if($Setting['Diacritics'] != 1) $Buffer = utf2ascii($Buffer);
156 return($Buffer);
157}
158
159
160function ExportToXML($Setting)
161{
162 global $Database, $Config, $TranslationTree, $LanguageList;
163
164 $AnoNe = array('Ne', 'Ano');
165 if($_SESSION['UserID'] != '')
166 {
167 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE ID='.$_SESSION['UserID']);
168 $User = mysql_fetch_assoc($DbResult);
169 } else $User = array('user' => 'Neznámý');
170
171 $WhereLang = '';
172 foreach($LanguageList as $Language)
173 if($Language['Enabled'] == 1)
174 if(isset($Setting['language'.$Language['Id']])) $WhereLang .= ' OR (Language = '.$Language['Id'].')';
175 if($WhereLang == '') $WhereLang = 1;
176 else $WhereLang = '('.substr($WhereLang, 4).')';
177
178 $SelectedUsers = '';
179 foreach($Setting['users-selection'] as $Item)
180 $SelectedUsers .= ','.$Item;
181 $SelectedUsers = substr($SelectedUsers, 1);
182
183 if($SelectedUsers == '') $Where = 0;
184 else $Where = 'ID IN ('.$SelectedUsers.')';
185
186 $UserNames = '';
187 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE '.$Where);
188 while($DbRow = mysql_fetch_assoc($DbResult))
189 $UserNames .= ','.$DbRow['user'];
190 $UserNames = substr($UserNames, 1);
191
192 if($SelectedUsers == '') $WhereUsers = 1;
193 else $WhereUsers = '(User IN ('.$SelectedUsers.'))';
194
195 $Buffer = '<?xml version="1.0" encoding="utf-8"?>'."\n".
196 "<document>\n".
197 " <meta>\n".
198 " <projecturl>".$Config['Web']['BaseURL']."</projecturl>\n".
199 " <time>".date('r')."</time>\n".
200 " <diacritics mode=".'"'.$Setting['Diacritics'].'"'." />\n".
201 " <author>".$User['user']."</author>\n".
202 " <contributors>\n";
203 foreach(explode(',', $UserNames) as $UserName)
204 $Buffer .= " <user>".$UserName."</user>\n";
205 $Buffer .=
206 " </contributors>\n".
207 " </meta>\n".
208 " <translation>\n";
209
210 foreach($TranslationTree as $Group)
211 if(in_array($Group['Id'], $Setting['groups']))
212 {
213 if($Group['MangosTable'] == '')
214 {
215 $Group['MangosTable'] = $Group['TablePrefix'];
216 $Group['MangosTableIndex'] = 'entry';
217 }
218 $Query = 'SELECT *,(SELECT user FROM user WHERE user.ID=T.User) as UserName FROM (SELECT * FROM '.$Group['TablePrefix'].' WHERE (Complete = 1) AND VersionStart <= '.GetBuildNumber($Setting['Version']).' AND VersionEnd >= '.GetBuildNumber($Setting['Version']).' AND '.$WhereLang.' AND '.$WhereUsers.' ORDER BY FIELD(User, '.$SelectedUsers.')) AS T GROUP BY T.entry';
219 //echo($Query);
220 $Buffer .= ' <group id="'.$Group['Id'].'" name="'.$Group['TablePrefix'].'">'."\n";
221 $ID = $Database->SQLCommand($Query);
222 while($Line = mysql_fetch_array($ID))
223 {
224 $Buffer .= ' <item id="'.$Line['entry'].'" user="'.$Line['UserName'].'">'."\n";
225 $Values = '';
226 foreach($Group['Items'] as $GroupItem)
227 {
228 if($GroupItem['MangosColumn'] == '') $GroupItem['MangosColumn'] = $GroupItem['Column'];
229 if($Line[$GroupItem['Column']] != '')
230 $Buffer .= ' <text index="'.$GroupItem['Id'].'" name="'.$GroupItem['Column'].'">'.addslashes($Line[$GroupItem['Column']]).'</text>'."\n";
231 }
232 $Buffer .= " </item>\n";
233 }
234 $Buffer .= " </group>\n";
235 }
236 if($Setting['Diacritics'] != 1) $Buffer = utf2ascii($Buffer);
237 $Buffer .= " </translation>\n".
238 "</document>";
239 return($Buffer);
240}
241
242function ExportToDBC($Setting)
243{
244 global $Database, $Config, $TranslationTree, $LanguageList;
245
246 $TempDir = $Config['Web']['TempFolder'].$_SESSION['User'].'/dbc/';
247 if(!file_exists($TempDir)) mkdir($TempDir, 0777, true);
248
249 if($_SESSION['UserID'] != '')
250 {
251 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE ID='.$_SESSION['UserID']);
252 $User = mysql_fetch_assoc($DbResult);
253 } else $User = array('user' => 'Neznámý');
254
255 $WhereLang = '';
256 foreach($LanguageList as $Language)
257 if($Language['Enabled'] == 1)
258 if(isset($Setting['language'.$Language['Id']])) $WhereLang .= ' OR (Language = '.$Language['Id'].')';
259 if($WhereLang == '') $WhereLang = 1;
260 else $WhereLang = '('.substr($WhereLang, 4).')';
261
262 $SelectedUsers = '';
263 foreach($Setting['users-selection'] as $Item)
264 $SelectedUsers .= ','.$Item;
265 $SelectedUsers = substr($SelectedUsers, 1);
266
267 if($SelectedUsers == '') $Where = 0;
268 else $Where = 'ID IN ('.$SelectedUsers.')';
269
270 $UserNames = '';
271 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE '.$Where);
272 while($DbRow = mysql_fetch_assoc($DbResult))
273 $UserNames .= ','.$DbRow['user'];
274 $UserNames = substr($UserNames, 1);
275
276 if($SelectedUsers == '') $WhereUsers = 1;
277 else $WhereUsers = '(User IN ('.$SelectedUsers.'))';
278
279 foreach($TranslationTree as $Group)
280 if(in_array($Group['Id'], $Setting['groups']) and ($Group['DBCFileName'] != ''))
281 {
282 echo($Group['Name'].'... ');
283 $DBCFile = new DBCFile();
284 $DBCFile->OpenFile('../source/'.$Setting['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc', GetDBCColumns($Setting['Version'],$Group['DBCFileName']));
285 $DBCFile2 = new DBCFile();
286 $DBCFile2->CreateFile($TempDir.$Group['DBCFileName'].'.dbc', GetDBCColumns($Setting['Version'],$Group['DBCFileName']));
287 $Count = $DBCFile->GetRecordCount();
288 //if($Group['DBCFileName'] == 'Spell') $Count = 1000;
289 $Line = $DBCFile->GetLine(0);
290 $DBCFile2->SetRecordCount($Count);
291 for($I = 0; $I < $Count; $I++)
292 {
293 $Line = $DBCFile->GetLine($I);
294 $Query = 'SELECT * FROM (SELECT * FROM '.$Group['TablePrefix'].' WHERE (Complete = 1) AND '.$WhereLang.' AND '.$WhereUsers.' AND (entry='.$Line[0].') AND VersionStart <= '.GetBuildNumber($Setting['Version']).' AND VersionEnd >= '.GetBuildNumber($Setting['Version']).' ORDER BY FIELD(User, '.$SelectedUsers.')) AS T GROUP BY T.entry';
295 $DbResult = $Database->SQLCommand($Query);
296 if(mysql_num_rows($DbResult) > 0)
297 {
298 $DbRow = mysql_fetch_assoc($DbResult);
299 // if($Setting['Diacritics'] != 1) $Buffer = utf2ascii($Buffer);
300
301 foreach($Group['Items'] as $GroupItem)
302 if($GroupItem['DBCColumnIndex'] != '')
303 $Line[$GroupItem['DBCColumnIndex']] = $DbRow[$GroupItem['Column']];
304 //print_r($Line);
305 }
306 $DBCFile2->SetLine($I, $Line);
307 echo('.');
308 }
309 $DBCFile2->Commit();
310 echo('Hotovo <br />');
311 }
312}
313
314function ExportToLua($Setting)
315{
316 global $Database, $Config, $TranslationTree, $LanguageList;
317
318 $TempDir = $Config['Web']['TempFolder'].$_SESSION['User'].'/lua/';
319 if(!file_exists($TempDir)) mkdir($TempDir, 0777, true);
320
321 if($_SESSION['UserID'] != '')
322 {
323 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE ID='.$_SESSION['UserID']);
324 $User = mysql_fetch_assoc($DbResult);
325 } else $User = array('user' => 'Neznámý');
326
327 $WhereLang = '';
328 foreach($LanguageList as $Language)
329 if($Language['Enabled'] == 1)
330 if(isset($Setting['language'.$Language['Id']])) $WhereLang .= ' OR (Language = '.$Language['Id'].')';
331 if($WhereLang == '') $WhereLang = 1;
332 else $WhereLang = '('.substr($WhereLang, 4).')';
333
334 $SelectedUsers = '';
335 foreach($Setting['users-selection'] as $Item)
336 $SelectedUsers .= ','.$Item;
337 $SelectedUsers = substr($SelectedUsers, 1);
338
339 if($SelectedUsers == '') $Where = 0;
340 else $Where = 'ID IN ('.$SelectedUsers.')';
341
342 $UserNames = '';
343 $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE '.$Where);
344 while($DbRow = mysql_fetch_assoc($DbResult))
345 $UserNames .= ','.$DbRow['user'];
346 $UserNames = substr($UserNames, 1);
347
348 if($SelectedUsers == '') $WhereUsers = 1;
349 else $WhereUsers = '(User IN ('.$SelectedUsers.'))';
350
351 foreach($TranslationTree as $Group)
352 if(in_array($Group['Id'], $Setting['groups']) and ($Group['LuaFileName'] != ''))
353 {
354 echo($Group['Name'].'... ');
355 $File = new FileStream();
356 $File->OpenFile('../source/'.$Setting['Version'].'/lua/'.$Group['LuaFileName'].'.lua');
357 $File2 = new FileStream();
358 $File2->CreateFile($TempDir.''.$Group['LuaFileName'].'.lua');
359
360 while(!$File->EOF())
361 {
362 $Line = $File->ReadLine();
363 if(strpos($Line, '=') !== false)
364 {
365 $LineParts = explode(';', $Line);
366 $LineParts2 = explode('=', $LineParts[0]);
367 $Value['ShortCut'] = trim($LineParts2[0]);
368 $Value['Text'] = substr(trim($LineParts2[1]), 1, -1);
369 $Value['Comment'] = addslashes(substr(trim($LineParts[1]), 3));
370
371 $Query = 'SELECT * FROM (SELECT * FROM '.$Group['TablePrefix'].' WHERE (Complete = 1) AND '.$WhereLang.' AND '.$WhereUsers.' AND (ShortCut="'.$Value['ShortCut'].'") AND VersionStart <= '.GetBuildNumber($Setting['Version']).' AND VersionEnd >= '.GetBuildNumber($Setting['Version']).' ORDER BY FIELD(User, '.$SelectedUsers.')) AS T GROUP BY T.entry';
372 //echo($Query);
373 $DbResult = $Database->SQLCommand($Query);
374 if(mysql_num_rows($DbResult) > 0)
375 {
376 $DbRow = mysql_fetch_assoc($DbResult);
377 $Value['Text'] = $DbRow['Text'];
378 $Value['Comment'] = $DbRow['Comment'];
379 //echo('.');
380 }
381 $NewLine = $Value['ShortCut'].' = "'.$Value['Text'].'";';
382 if($Value['Comment'] != '') $NewLine .= ' -- '.$Value['Comment'];
383 $NewLine .= "\n";
384 $File2->WriteLine($NewLine);
385 } else $File2->WriteLine($Line."\n");
386 }
387 echo('Hotovo <br />');
388 }
389}
390
391?>
Note: See TracBrowser for help on using the repository browser.