[630] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | include_once(dirname(__FILE__).'/../../includes/dbc.php');
|
---|
[551] | 4 | include_once(dirname(__FILE__).'/Manage.php');
|
---|
| 5 |
|
---|
[630] | 6 |
|
---|
[551] | 7 | class ModuleImport extends AppModule
|
---|
| 8 | {
|
---|
| 9 | function __construct($System)
|
---|
| 10 | {
|
---|
| 11 | parent::__construct($System);
|
---|
| 12 | $this->Name = 'Import';
|
---|
| 13 | $this->Version = '1.0';
|
---|
| 14 | $this->Creator = 'Chronos';
|
---|
| 15 | $this->License = 'GNU/GPL';
|
---|
| 16 | $this->Description = 'Support for import of data.';
|
---|
[630] | 17 | $this->Dependencies = array();
|
---|
[551] | 18 | }
|
---|
| 19 |
|
---|
| 20 | function Start()
|
---|
[630] | 21 | {
|
---|
| 22 | $this->System->RegisterPage('import', 'PageImport');
|
---|
[551] | 23 | }
|
---|
[630] | 24 | }
|
---|
| 25 |
|
---|
| 26 | class Import
|
---|
| 27 | {
|
---|
| 28 | var $Version;
|
---|
| 29 | var $Group;
|
---|
| 30 | var $NewItemCount;
|
---|
| 31 | var $System;
|
---|
| 32 |
|
---|
| 33 | function __construct($System)
|
---|
| 34 | {
|
---|
| 35 | $this->System = &$System;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | function SetVersion($Version)
|
---|
| 39 | {
|
---|
| 40 | global $System;
|
---|
| 41 |
|
---|
| 42 | $DbResult = $System->Database->query('SELECT * FROM `ClientVersion` WHERE `Version` = "'.$Version.'"');
|
---|
| 43 | $this->Version = $DbResult->fetch_assoc();
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | function InsertItem($Value)
|
---|
| 47 | {
|
---|
[681] | 48 | $insert = true;
|
---|
[630] | 49 | $Columns = '';
|
---|
[680] | 50 | //$Values = '';
|
---|
[630] | 51 | foreach($this->Group['Items'] as $GroupItem)
|
---|
| 52 | {
|
---|
| 53 | $Columns .= ', `'.$GroupItem['Column'].'` ';
|
---|
[680] | 54 | // $Values .= ', "'.$Value[$GroupItem['Column']].'"';
|
---|
[630] | 55 | }
|
---|
[680] | 56 | // echo $Values;
|
---|
[630] | 57 | $Columns = substr($Columns, 1);
|
---|
[680] | 58 | $Where = ' (`'.$this->Group['PrimaryKeyItem'].'` = "'.$Value[$this->Group['PrimaryKeyItem']].'") AND (`Language`=0) ' ;
|
---|
[630] | 59 | //print_r($Value);
|
---|
| 60 |
|
---|
[681] | 61 | $DbResultMiddle = $this->System->Database->query('SELECT `VersionEnd`,`VersionStart`, `ID`, `Entry`, '.$Columns.' FROM `'.$this->Group['TablePrefix'].'` WHERE '.$Where.' AND `VersionStart` <= '.$this->Version['BuildNumber'].' AND `VersionEnd` >= '.$this->Version['BuildNumber'].' ORDER BY `VersionEnd` DESC LIMIT 1');
|
---|
| 62 | $DbResultBefore = $this->System->Database->query('SELECT `VersionEnd`,`VersionStart`, `ID`, `Entry`, '.$Columns.' FROM `'.$this->Group['TablePrefix'].'` WHERE '.$Where.' AND `VersionEnd` <= '.$this->Version['BuildNumber'].' ORDER BY `VersionEnd` DESC LIMIT 1');
|
---|
| 63 | $DbResultAfter = $this->System->Database->query('SELECT `VersionEnd`,`VersionStart`, `ID`, `Entry`, '.$Columns.' FROM `'.$this->Group['TablePrefix'].'` WHERE '.$Where.' AND `VersionStart` >= '.$this->Version['BuildNumber'].' ORDER BY `VersionStart` LIMIT 1');
|
---|
[630] | 64 | //echo('SELECT `VersionEnd`, `ID`, `Entry`, '.$Columns.' FROM `'.$this->Group['TablePrefix'].'` WHERE '.$Where.' AND (`Language`=0) ORDER BY `VersionStart` DESC LIMIT 1');
|
---|
[681] | 65 | if(($DbResultMiddle->num_rows > 0) or ($DbResultBefore->num_rows > 0) or ($DbResultAfter->num_rows > 0))
|
---|
[630] | 66 | {
|
---|
| 67 | // Update existed text
|
---|
[681] | 68 | $DbRowMiddle = $DbResultMiddle->fetch_assoc();
|
---|
[680] | 69 | $DbRowAfter = $DbResultAfter->fetch_assoc();
|
---|
| 70 | $DbRowBefore = $DbResultBefore->fetch_assoc();
|
---|
[681] | 71 |
|
---|
[680] | 72 | if($this->HaveSameText($this->Group, $DbRowBefore, $Value) and ($DbResultBefore->num_rows > 0) )
|
---|
[630] | 73 | {
|
---|
[682] | 74 | $insert = false;
|
---|
| 75 | if ($this->Group['Id'] == 1) {
|
---|
| 76 | $set = ' , EndText = "'.$Value['EndText'].'" , ObjectiveText1 = "'.$Value['ObjectiveText1'].'"'.' , ObjectiveText2 = "'.$Value['ObjectiveText2'].'"'.' , ObjectiveText3 = "'.$Value['ObjectiveText3'].'"'.' , ObjectiveText4 = "'.$Value['ObjectiveText4'].'"';
|
---|
| 77 | } else $set = '';
|
---|
| 78 | $this->System->Database->query('UPDATE `'.$this->Group['TablePrefix'].'` SET `VersionEnd` = "'.$this->Version['BuildNumber'].'" '.$set.' WHERE `ID`='.$DbRowBefore['ID']);
|
---|
[681] | 79 | echo('b ');
|
---|
[682] | 80 |
|
---|
[630] | 81 | } else
|
---|
[680] | 82 | if($this->HaveSameText($this->Group, $DbRowAfter, $Value) and ($DbResultAfter->num_rows > 0))
|
---|
| 83 | {
|
---|
[682] | 84 | $insert = false;
|
---|
| 85 | if ($this->Group['Id'] == 1) {
|
---|
| 86 | $set = ' , EndText = "'.$Value['EndText'].'" , ObjectiveText1 = "'.$Value['ObjectiveText1'].'"'.' , ObjectiveText2 = "'.$Value['ObjectiveText2'].'"'.' , ObjectiveText3 = "'.$Value['ObjectiveText3'].'"'.' , ObjectiveText4 = "'.$Value['ObjectiveText4'].'"';
|
---|
| 87 | } else $set = '';
|
---|
| 88 | $this->System->Database->query('UPDATE `'.$this->Group['TablePrefix'].'` SET `VersionStart` = "'.$this->Version['BuildNumber'].'" '.$set.' WHERE `ID`='.$DbRowAfter['ID']);
|
---|
[681] | 89 | echo('a ');
|
---|
| 90 |
|
---|
[680] | 91 | } else
|
---|
[630] | 92 | {
|
---|
[681] | 93 |
|
---|
| 94 | if (isset($DbRowAfter['VersionStart'])) {
|
---|
| 95 | if ($DbRowAfter['VersionStart'] <= $this->Version['BuildNumber']) {
|
---|
[680] | 96 | echo('Allready imported '.$DbRowBefore['Entry'].' ');
|
---|
[681] | 97 | $insert = false;
|
---|
[680] | 98 | }
|
---|
[681] | 99 | }
|
---|
| 100 | if (isset($DbRowBefore['VersionEnd'])) {
|
---|
| 101 | if ($DbRowBefore['VersionEnd'] >= $this->Version['BuildNumber']) {
|
---|
[680] | 102 | echo('Allready imported '.$DbRowBefore['Entry'].' ');
|
---|
[681] | 103 | $inserted = false;
|
---|
[680] | 104 | }
|
---|
[681] | 105 | }
|
---|
[680] | 106 |
|
---|
[681] | 107 | //if [DEPRECATED] do not import
|
---|
| 108 | foreach($this->Group['Items'] as $GroupItem) {
|
---|
[682] | 109 | if (false !== strpos($Value[$GroupItem['Column']],'[DEPRECATED')) {
|
---|
| 110 | echo('d '.$DbRowBefore['Entry'].' ');
|
---|
[681] | 111 | $insert = false;
|
---|
[682] | 112 | }
|
---|
[681] | 113 | }
|
---|
| 114 |
|
---|
[720] | 115 | if ($insert) {
|
---|
| 116 | $insert = false;
|
---|
| 117 | foreach($this->Group['Items'] as $GroupItem)
|
---|
| 118 | {
|
---|
| 119 | if ($Value[$GroupItem['Column']] <> '') $insert = true;
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
[681] | 122 |
|
---|
| 123 | if (isset($DbRowMiddle['Entry'])) $insert = false;
|
---|
| 124 | if (isset($DbRowAfter['Entry'])) $Value['Entry'] = $DbRowAfter['Entry'];
|
---|
| 125 | if (isset($DbRowBefore['Entry'])) $Value['Entry'] = $DbRowBefore['Entry'];
|
---|
| 126 |
|
---|
| 127 | if ($insert)
|
---|
[680] | 128 | {
|
---|
[681] | 129 |
|
---|
[630] | 130 | $Columns = '`Entry`, `Language`, `VersionStart`, `VersionEnd`';
|
---|
[680] | 131 | $Values = $Value['Entry'].', 0, '.$this->Version['BuildNumber'].', '.$this->Version['BuildNumber'];
|
---|
[630] | 132 | foreach($this->Group['Items'] as $GroupItem)
|
---|
| 133 | {
|
---|
| 134 | $Columns .= ', `'.$GroupItem['Column'].'`';
|
---|
| 135 | $Values .= ', "'.$Value[$GroupItem['Column']].'"';
|
---|
| 136 | }
|
---|
| 137 | $this->System->Database->query('INSERT `'.$this->Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')');
|
---|
[681] | 138 |
|
---|
[720] | 139 | echo '
|
---|
| 140 | '.$Value['Entry'].' = '.$DbRowBefore['VersionStart'].'.'.$DbRowBefore['VersionEnd'].'< '.$this->Version['BuildNumber'].' <'.$DbRowAfter['VersionStart'].'.'.$DbRowAfter['VersionEnd'].'... '.$DbRowMiddle['VersionStart'].' '.$DbRowMiddle['VersionEnd'].'
|
---|
| 141 | ';
|
---|
[681] | 142 |
|
---|
[720] | 143 | if (false !== strpos($Values,'[DEPRECATED'))
|
---|
| 144 | echo $Values;
|
---|
[681] | 145 |
|
---|
[630] | 146 | echo('# ');
|
---|
| 147 | $InsertId = $this->System->Database->insert_id;
|
---|
[680] | 148 | $this->System->ModuleManager->Modules['Log']->WriteLog('Text <a href="form.php?group='.$this->Group['Id'].'&ID='.$InsertId.'">'.$InsertId.'</a> ('.$Value['Entry'].') ze skupiny '.$this->Group['Name'].' byl v nové verzi '.$this->Version['Version'].' změněn.', LOG_TYPE_IMPORT);
|
---|
| 149 | }
|
---|
[630] | 150 | }
|
---|
| 151 | } else
|
---|
| 152 | {
|
---|
| 153 | // Insert new text
|
---|
| 154 | if(is_numeric($Value[$this->Group['PrimaryKeyItem']])) $Value['Entry'] = $Value[$this->Group['PrimaryKeyItem']];
|
---|
| 155 | else
|
---|
| 156 | {
|
---|
| 157 | // Get new unused Entry for tables without numeric id
|
---|
| 158 | $Value['Entry'] = 1;
|
---|
| 159 | $DbResult = $this->System->Database->query('SELECT MAX(`Entry`) FROM `'.$this->Group['TablePrefix'].'`');
|
---|
| 160 | if($DbResult->num_rows > 0)
|
---|
| 161 | {
|
---|
| 162 | $DbRow = $DbResult->fetch_row();
|
---|
| 163 | $Value['Entry'] += $DbRow[0];
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 | $Columns = '`Entry`, `Language`, `VersionStart`, `VersionEnd`';
|
---|
| 167 | $Values = $Value['Entry'].', 0, '.$this->Version['BuildNumber'].', '.$this->Version['BuildNumber'];
|
---|
[720] | 168 | $insert = false;
|
---|
[630] | 169 | foreach($this->Group['Items'] as $GroupItem)
|
---|
| 170 | {
|
---|
| 171 | $Columns .= ', `'.$GroupItem['Column'].'`';
|
---|
| 172 | $Values .= ', "'.$Value[$GroupItem['Column']].'"';
|
---|
[720] | 173 | if ($Value[$GroupItem['Column']] <> '') $insert = true;
|
---|
[630] | 174 | }
|
---|
[720] | 175 | if ($insert) {
|
---|
| 176 | $this->System->Database->query('INSERT `'.$this->Group['TablePrefix'].'` ('.$Columns.') VALUES ('.$Values.')');
|
---|
| 177 | $InsertId = $this->System->Database->insert_id;
|
---|
| 178 | echo('+ ');
|
---|
| 179 | $this->NewItemCount++;
|
---|
| 180 | $this->System->ModuleManager->Modules['Log']->WriteLog('Text <a href="form.php?group='.$this->Group['Id'].'&ID='.$InsertId.'">'.$InsertId.'</a> ('.$Value['Entry'].') ze skupiny '.$this->Group['Name'].' byl v nové verzi '.$this->Version['Version'].' přidán.', LOG_TYPE_IMPORT);
|
---|
| 181 | }
|
---|
[630] | 182 | }
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | function ImportLUA()
|
---|
| 186 | {
|
---|
| 187 | global $TranslationTree, $PatchVersion;
|
---|
| 188 | $Output = 'Načítání textů z LUA souboru...';
|
---|
| 189 |
|
---|
| 190 | if(($this->Group['LuaFileName'] != '') and ($this->Group['TablePrefix'] != ''))
|
---|
| 191 | {
|
---|
| 192 |
|
---|
| 193 | $Output .= '<br />'.$this->Group['Name'].'<br />';
|
---|
[681] | 194 | // if($this->Group['LastVersion'] < $this->Version['BuildNumber'] + 1)
|
---|
[630] | 195 | {
|
---|
| 196 | $File = new FileStream();
|
---|
| 197 |
|
---|
| 198 | $File->OpenFile(dirname(__FILE__).'/../../source/'.$this->Version['Version'].'/lua/'.$this->Group['LuaFileName'].'.lua');
|
---|
| 199 | $this->NewItemCount = 0;
|
---|
| 200 | $Count = 0;
|
---|
| 201 | while(!$File->EOF())
|
---|
| 202 | {
|
---|
| 203 | $Line = $File->ReadLine();
|
---|
| 204 | if(strpos($Line, '=') !== false)
|
---|
| 205 | {
|
---|
| 206 | $LineParts = explode('=', $Line, 2);
|
---|
| 207 | $Value['ShortCut'] = trim($LineParts[0]);
|
---|
| 208 | $Line = trim($LineParts[1]);
|
---|
| 209 | if($Line[0] == '"')
|
---|
| 210 | {
|
---|
| 211 | // Quoted string value
|
---|
| 212 | $Line = substr($Line, 1); // Skip start qoute
|
---|
| 213 | $TempLine = str_replace('\"', ' ', $Line); // Temporary remove slashed quotes
|
---|
| 214 | $Value['Text'] = substr($Line, 0, strpos($TempLine, '"'));
|
---|
| 215 | $Value['Text'] = str_replace('\n', "\n", $Value['Text']);
|
---|
| 216 | $Value['Text'] = addslashes(stripslashes($Value['Text']));
|
---|
| 217 | $Line = trim(substr($Line, strpos($TempLine, '"') + 1)); // Skip closing quote and semicolon
|
---|
| 218 | } else
|
---|
| 219 | {
|
---|
| 220 | // Nonstring value
|
---|
| 221 | $Value['Text'] = substr($Line, 0, strpos($Line, ';'));
|
---|
| 222 | }
|
---|
| 223 | $Line = substr($Line, strpos($Line, ';') + 1);
|
---|
| 224 | $Value['Comment'] = addslashes(stripslashes(substr($Line, 3))); // Skip " --"
|
---|
| 225 | //print_r($Value);
|
---|
| 226 |
|
---|
| 227 | $this->InsertItem($Value);
|
---|
| 228 | };
|
---|
| 229 | $Count++;
|
---|
| 230 | }
|
---|
| 231 | $Output .= '<br />Celkem: '.$Count.' Nových: '.$this->NewItemCount.'<br />';
|
---|
| 232 | $this->System->Database->query('UPDATE `Group` SET `LastVersion` = "'.$this->Version['BuildNumber'].'", `LastImport` = NOW() WHERE `Id`='.$this->Group['Id']);
|
---|
[681] | 233 | }
|
---|
| 234 | // else $Output .= ShowMessage('Již importován pro verzi '.$this->Version['Version'], MESSAGE_CRITICAL);
|
---|
[630] | 235 | } else $Output .= ShowMessage('Není definováno jméno zdrojového souboru', MESSAGE_CRITICAL);
|
---|
| 236 | $Output .= ShowMessage('Dokončeno.');
|
---|
| 237 | return ($Output);
|
---|
| 238 | }
|
---|
| 239 |
|
---|
| 240 | function UpdateTranslated()
|
---|
| 241 | {
|
---|
| 242 | global $TranslationTree, $PatchVersion, $Config;
|
---|
| 243 |
|
---|
| 244 | $Output = '<br /><br />Začínám se synchronizací VersionEnd u přeložených textů<br />';
|
---|
| 245 | foreach($TranslationTree as $Group)
|
---|
| 246 | {
|
---|
| 247 | $Output .= '<br />'.$Group['Name'].' ';
|
---|
| 248 | $do = true;
|
---|
| 249 | while($do)
|
---|
[680] | 250 | {
|
---|
[630] | 251 | $DbResult = $this->System->Database->query('SELECT `gs_tran`.`ID`, '.
|
---|
| 252 | '`gs_tran`.`VersionEnd` AS `VersionEnd_tran`, '.
|
---|
[680] | 253 | '`gs_tran`.`VersionStart` AS `VersionStart_tran`, '.
|
---|
| 254 | '`gs_orig`.`VersionEnd` AS `VersionEnd_orig`, '.
|
---|
| 255 | '`gs_orig`.`VersionStart` AS `VersionStart_orig` FROM `'.
|
---|
[630] | 256 | $Group['TablePrefix'].'` AS `gs_tran` JOIN `'.$Group['TablePrefix'].
|
---|
| 257 | '` AS `gs_orig` ON `gs_orig`.`ID` = `gs_tran`.`Take` WHERE '.
|
---|
[680] | 258 | '`gs_tran`.`VersionEnd` <> `gs_orig`.`VersionEnd` OR `gs_tran`.`VersionStart` <> `gs_orig`.`VersionStart`');
|
---|
[630] | 259 | $do = ($DbResult->num_rows > 0);
|
---|
| 260 | while($DbRow = $DbResult->fetch_assoc())
|
---|
| 261 | {
|
---|
[680] | 262 | echo '`';
|
---|
| 263 | $this->System->Database->query('UPDATE `'.$Group['TablePrefix'].'` SET `VersionEnd` = '.$DbRow['VersionEnd_orig'].', `VersionStart` = '.$DbRow['VersionStart_orig'].' WHERE `ID` = '.$DbRow['ID']);
|
---|
[630] | 264 | $Output .= '. ';
|
---|
| 265 | }
|
---|
| 266 | }
|
---|
| 267 | $Output .= '<strong>Dokončeno.</strong>';
|
---|
| 268 | }
|
---|
| 269 | return($Output);
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 | function HaveSameText($Group, $DbRow2, $Value)
|
---|
| 273 | {
|
---|
| 274 | $result = true;
|
---|
| 275 | foreach($Group['Items'] as $GroupItem)
|
---|
| 276 | {
|
---|
| 277 | $old = $DbRow2[$GroupItem['Column']];
|
---|
| 278 | $old = str_replace(chr(10), '', $old);
|
---|
| 279 | $old = str_replace(chr(13), '', $old);
|
---|
| 280 | $old = str_replace('\n', '', $old);
|
---|
| 281 | $old = str_replace('\r', '', $old);
|
---|
| 282 | $old = str_replace('\"', '"', $old);
|
---|
| 283 | $old = str_replace('\\\\', '\\', $old);
|
---|
| 284 | $old = str_replace('\32', '32', $old);
|
---|
| 285 | $old = str_replace('\124', '124', $old);
|
---|
| 286 | $old = str_replace("\'", "'", $old);
|
---|
| 287 | $old = str_replace("Â", "", $old);
|
---|
| 288 | $old = str_replace("�", "", $old);
|
---|
[681] | 289 | $old = str_replace('-', '', $old);
|
---|
| 290 | $old = str_replace(' ', '', $old);
|
---|
[680] | 291 | $old = strtolower($old);
|
---|
[681] | 292 | $old = str_replace('$b', '', $old);
|
---|
[682] | 293 |
|
---|
[688] | 294 | if ($this->Group['Id'] == 1)
|
---|
| 295 | while ($part = substr($old, strpos($old, '<'), strpos($old, '>')-strpos($old, '<')))
|
---|
[682] | 296 | if ($part <> '') {
|
---|
| 297 | $old = str_replace($part.'>', '', $old);
|
---|
| 298 | }
|
---|
[630] | 299 |
|
---|
| 300 | if (($GroupItem['MangosColumn'] <> '') and ($Group['MangosDatabase'] == 'mangos'))
|
---|
| 301 | $new = $Value[$GroupItem['MangosColumn']];
|
---|
| 302 | else $new = $Value[$GroupItem['Column']];
|
---|
| 303 |
|
---|
| 304 | $new = str_replace(chr(10), '', $new);
|
---|
| 305 | $new = str_replace(chr(13), '', $new);
|
---|
| 306 | $new = str_replace('\n', '', $new);
|
---|
| 307 | $new = str_replace('\r', '', $new);
|
---|
| 308 | $new = str_replace('\"', '"', $new);
|
---|
| 309 | $new = str_replace('\\\\', '\\', $new);
|
---|
| 310 | $new = str_replace('\32', '32', $new);
|
---|
| 311 | $new = str_replace('\124', '124', $new);
|
---|
| 312 | $new = str_replace("\'", "'", $new);
|
---|
| 313 | $new = str_replace("Â", "", $new);
|
---|
| 314 | $new = str_replace("�", "", $new);
|
---|
[681] | 315 | $new = str_replace('-', '', $new);
|
---|
| 316 | $new = str_replace(' ', '', $new);
|
---|
[680] | 317 | $new = strtolower($new);
|
---|
[681] | 318 | $new = str_replace('$b', '', $new);
|
---|
[682] | 319 |
|
---|
[688] | 320 | if ($this->Group['Id'] == 1)
|
---|
| 321 | while ($part = substr($new, strpos($new, '<'), strpos($new, '>')-strpos($new, '<')))
|
---|
[682] | 322 | if ($part <> '') {
|
---|
| 323 | $new = str_replace($part.'>', '', $new);
|
---|
| 324 | }
|
---|
[680] | 325 |
|
---|
[630] | 326 | if(($old == 'null') or ($old == 'NULL')) $old = '';
|
---|
| 327 | if(($new == 'null') or ($new == 'NULL')) $new = '';
|
---|
| 328 |
|
---|
[681] | 329 | if(($new <> '') and ($old <> $new) and ($GroupItem['Column'] <> 'Comment'))
|
---|
[630] | 330 | {
|
---|
| 331 | // echo $old.'X'.$new;
|
---|
[682] | 332 | if ( ($GroupItem['Column'] <> 'EndText')
|
---|
| 333 | and ($GroupItem['Column'] <> 'ObjectiveText1')
|
---|
| 334 | and ($GroupItem['Column'] <> 'ObjectiveText2')
|
---|
| 335 | and ($GroupItem['Column'] <> 'ObjectiveText3')
|
---|
| 336 | and ($GroupItem['Column'] <> 'ObjectiveText4') )
|
---|
| 337 | $result = false;
|
---|
[630] | 338 | }
|
---|
| 339 | }
|
---|
[681] | 340 |
|
---|
[630] | 341 | return($result);
|
---|
| 342 | }
|
---|
| 343 |
|
---|
| 344 | function ImportDBC()
|
---|
| 345 | {
|
---|
| 346 | global $System, $TranslationTree, $Config;
|
---|
| 347 |
|
---|
| 348 | $Output = 'Načítání textů z DBC souboru...';
|
---|
| 349 | if(($this->Group['DBCFileName'] != '') and ($this->Group['TablePrefix'] != ''))
|
---|
| 350 | {
|
---|
| 351 | $Output .= '<br />'.$this->Group['Name'].'<br />';
|
---|
| 352 |
|
---|
| 353 | // Load string column index list
|
---|
| 354 | $DbResult = $System->Database->query('SELECT * FROM `GroupItem` JOIN `GroupItemDBC` ON `GroupItem`.`Id` = `GroupItemDBC`.`GroupItem` AND `GroupItemDBC`.`ClientVersion` = '.$this->Version['Id'].' WHERE `GroupItem`.`Group` = '.$this->Group['Id']);
|
---|
| 355 |
|
---|
| 356 | $ColumnIndexes = array();
|
---|
| 357 | $ColumnFormat = array();
|
---|
| 358 | while($DbRow = $DbResult->fetch_assoc())
|
---|
| 359 | {
|
---|
| 360 | $ColumnFormat[$DbRow['ColumnIndex']] = FORMAT_STRING;
|
---|
| 361 | $ColumnIndexes[$DbRow['GroupItem']] = $DbRow['ColumnIndex'];
|
---|
| 362 | }
|
---|
| 363 |
|
---|
| 364 | $DBCFile = new DBCFile();
|
---|
| 365 | $DBCFile->OpenFile(dirname(__FILE__).'/../../source/'.$this->Version['Version'].'/dbc/'.$this->Group['DBCFileName'].'.dbc', $ColumnFormat);
|
---|
| 366 | $ItemCount = $DBCFile->GetRecordCount();
|
---|
| 367 | $this->NewItemCount = 0;
|
---|
| 368 | $Count = 0;
|
---|
| 369 |
|
---|
| 370 | for($I = 0; $I < $ItemCount; $I++)
|
---|
| 371 | {
|
---|
| 372 | foreach($this->Group['Items'] as $GroupItem)
|
---|
| 373 | if(array_key_exists($GroupItem['Id'], $ColumnIndexes))
|
---|
| 374 | {
|
---|
| 375 | $Value[$GroupItem['Column']] = addslashes($DBCFile->GetString($I, $ColumnIndexes[$GroupItem['Id']]));
|
---|
| 376 | }
|
---|
| 377 |
|
---|
| 378 | // Get multicolumn value
|
---|
| 379 | $Columns = explode(',', $this->Group['DBCIndex']);
|
---|
| 380 | $ColumnValue = '';
|
---|
| 381 | foreach($Columns as $Column)
|
---|
| 382 | $ColumnValue .= '_'.$DBCFile->GetUint($I, $Column);
|
---|
| 383 | $ColumnValue = substr($ColumnValue, 1);
|
---|
| 384 | $Value[$this->Group['PrimaryKeyItem']] = $ColumnValue;
|
---|
| 385 | $this->InsertItem($Value);
|
---|
| 386 | $Count++;
|
---|
| 387 | }
|
---|
| 388 | $Output .= '<br />Celkem: '.$Count.' Nových: '.$this->NewItemCount.'<br />';
|
---|
| 389 | $System->Database->query('UPDATE `Group` SET `LastVersion` = "'.$this->Version['BuildNumber'].'", `LastImport` = NOW() WHERE `Id`='.$this->Group['Id']);
|
---|
| 390 | }
|
---|
| 391 | $Output .= '<strong>Dokončeno.</strong>';
|
---|
| 392 | return($Output);
|
---|
| 393 | }
|
---|
| 394 |
|
---|
| 395 | function ImportGroup($GroupId)
|
---|
| 396 | {
|
---|
| 397 | global $TranslationTree;
|
---|
| 398 |
|
---|
| 399 | $this->Group = $TranslationTree[$GroupId];
|
---|
| 400 |
|
---|
| 401 | if($this->Group['SourceType'] == 'dbc') $Output = $this->ImportDBC();
|
---|
| 402 | else if($this->Group['SourceType'] == 'sql') $Output = $this->ImportSQL();
|
---|
| 403 | else if($this->Group['SourceType'] == 'lua') $Output = $this->ImportLUA();
|
---|
| 404 | else $Output = ShowMessage('Neznámý typ zdroje pro import', MESSAGE_CRITICAL);
|
---|
| 405 | $Output .= $this->UpdateTranslated();
|
---|
| 406 | return($Output);
|
---|
| 407 | }
|
---|
| 408 |
|
---|
| 409 | function ImportSQL()
|
---|
| 410 | {
|
---|
| 411 | global $TranslationTree, $PatchVersion;
|
---|
| 412 |
|
---|
| 413 | $Output= '';
|
---|
| 414 | $File = new FileStream();
|
---|
| 415 | $File->OpenFile(dirname(__FILE__).'/../../source/'.$this->Version['Version'].'/sql/'.$this->Group['MangosTable'].'.sql');
|
---|
| 416 | $this->NewItemCount = 0;
|
---|
| 417 | $Count = 0;
|
---|
| 418 | $folow_structure = false;
|
---|
| 419 | $i = 0;
|
---|
| 420 | while((!$File->EOF()))
|
---|
| 421 | {
|
---|
| 422 | $Line = $File->ReadLine();
|
---|
| 423 | // Struktura
|
---|
| 424 | if(strpos($Line, 'CREATE TABLE `'.$this->Group['MangosTable'].'`') !== false)
|
---|
| 425 | {
|
---|
| 426 | $Line = '';
|
---|
| 427 | $folow_structure = true;
|
---|
| 428 | $i = 0;
|
---|
| 429 | }
|
---|
| 430 | if((strpos($Line, ';') !== false) and ($folow_structure == true))
|
---|
| 431 | {
|
---|
| 432 | $folow_structure = false;
|
---|
| 433 | // echo ('Struktura: <br />');
|
---|
| 434 | // print_r($structure);
|
---|
| 435 | // echo ('<br /><br />');
|
---|
| 436 | }
|
---|
| 437 | if(($folow_structure == true) and ($Line != ''))
|
---|
| 438 | {
|
---|
| 439 | $str = substr($Line, 0, strpos($Line, '`'));
|
---|
| 440 | $Line = substr($Line, strpos($Line, '`') + 1);
|
---|
| 441 | $Line = substr($Line, 0, strpos($Line, '`'));
|
---|
| 442 | if(strlen($str) < 3) $structure[$i] = $Line;
|
---|
| 443 | $i++;
|
---|
| 444 | }
|
---|
| 445 |
|
---|
| 446 | //data
|
---|
| 447 | if((strpos($Line, 'INSERT INTO `'.$this->Group['MangosTable'].'`') !== false) and (isset($structure)))
|
---|
| 448 | {
|
---|
[720] | 449 | while ((strpos($Line, ');') === false) or ($File->EOF()))
|
---|
| 450 | $Line = $Line.$File->ReadLine();
|
---|
| 451 | $Line = str_replace("),\n(", '),(', $Line);
|
---|
| 452 |
|
---|
[630] | 453 | $Line = substr($Line, strpos($Line, '(') + 1);
|
---|
| 454 | $Line = substr($Line, 0, strpos($Line, ');'));
|
---|
| 455 | $LineParts = explode('),(', $Line);
|
---|
[720] | 456 |
|
---|
[630] | 457 | unset($Line);
|
---|
[720] | 458 |
|
---|
[630] | 459 | foreach($LineParts as $LinePart)
|
---|
| 460 | {
|
---|
[720] | 461 |
|
---|
[630] | 462 | unset($Value, $value_buff);
|
---|
| 463 | foreach($structure as $i => $column)
|
---|
| 464 | {
|
---|
| 465 | if (substr($LinePart, 0, 1) != "'")
|
---|
| 466 | {
|
---|
| 467 | $value_buff = substr($LinePart, 0, strpos($LinePart, ','));
|
---|
| 468 | $LinePart = substr($LinePart, strlen($value_buff) + 1);
|
---|
| 469 | } else
|
---|
| 470 | {
|
---|
| 471 | $LinePart = substr($LinePart, 1);
|
---|
| 472 | $value_buff = substr($LinePart, 0, strpos($LinePart, "'"));
|
---|
| 473 | while(substr($value_buff, strlen($value_buff) - 1, 1) == "\\")
|
---|
| 474 | {
|
---|
| 475 | $str = substr($LinePart, strlen($value_buff));
|
---|
| 476 | $str2 = substr($str, 0, strpos($str, "'", 1));
|
---|
| 477 | $value_buff = $value_buff.$str2;
|
---|
| 478 | $str = substr($str, strlen($str2));
|
---|
| 479 | }
|
---|
| 480 | $LinePart = substr($LinePart, strlen($value_buff) + 2);
|
---|
| 481 | }
|
---|
| 482 | if(($value_buff != 'null') and ($value_buff != 'NULL'))
|
---|
| 483 | {
|
---|
| 484 | $str = '';
|
---|
| 485 | while(substr($value_buff, strlen($value_buff) - 1,1) == " ")
|
---|
| 486 | {
|
---|
| 487 | $value_buff = substr($value_buff, 0, strlen($value_buff) - 1);
|
---|
| 488 | $str .= ' ';
|
---|
| 489 | }
|
---|
| 490 | $str2 = '';
|
---|
| 491 | while(substr($value_buff, 0, 1) == ' ')
|
---|
| 492 | {
|
---|
| 493 | $value_buff = substr($value_buff, 1, strlen($value_buff) - 1);
|
---|
| 494 | $str2 .= ' ';
|
---|
| 495 | }
|
---|
| 496 | $Value[$column] = $str2.trim($value_buff).$str;
|
---|
| 497 | } else
|
---|
| 498 | {
|
---|
| 499 | $Value[$column] = '';
|
---|
| 500 | }
|
---|
| 501 | // echo ($column.'-"'.$Value[$column].'"<br>');
|
---|
| 502 | }
|
---|
| 503 | foreach($this->Group['Items'] as $GroupItem)
|
---|
| 504 | {
|
---|
| 505 | if($GroupItem['MangosColumn'] != '')
|
---|
| 506 | $Value[$GroupItem['Column']] = $Value[$GroupItem['MangosColumn']];
|
---|
| 507 | }
|
---|
| 508 |
|
---|
| 509 | // Get multicolumn value
|
---|
| 510 | $Columns = explode(',', $this->Group['MangosTableIndex']);
|
---|
| 511 | $ColumnValue = '';
|
---|
| 512 | foreach($Columns as $Column)
|
---|
| 513 | $ColumnValue .= '_'.$Value[$Column];
|
---|
| 514 | $ColumnValue = substr($ColumnValue, 1);
|
---|
| 515 | $Value[$this->Group['PrimaryKeyItem']] = $ColumnValue;
|
---|
| 516 | $this->InsertItem($Value);
|
---|
| 517 | $Count++;
|
---|
| 518 | }
|
---|
| 519 | }
|
---|
| 520 | }
|
---|
| 521 | $Output = '<br />Celkem: '.$Count.' Nových: '.$this->NewItemCount.'<br />';
|
---|
| 522 | $this->System->Database->query('UPDATE `Group` SET `LastVersion` = "'.$this->Version['BuildNumber'].'", `LastImport` = NOW() WHERE `Id`='.$this->Group['Id']);
|
---|
| 523 | return($Output);
|
---|
| 524 | }
|
---|
| 525 | }
|
---|