Changeset 880 for trunk/Modules/Export/Export.php
- Timestamp:
- Apr 7, 2020, 10:15:48 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Export/Export.php
r879 r880 17 17 { 18 18 $this->TempDir = dirname(__FILE__).'/../../'.$this->System->Config['Web']['TempFolder'].'Export/'.$this->Id.'/'; 19 if (!file_exists($this->TempDir)) mkdir($this->TempDir, 0777, true);19 if (!file_exists($this->TempDir)) mkdir($this->TempDir, 0777, true); 20 20 $this->TempDirRelative = $this->System->Config['Web']['TempFolder'].'Export/'.$this->Id.'/'; 21 21 $this->SourceDir = dirname(__FILE__).'/../../'.$this->System->Config['Web']['SourceFolder']; 22 22 $this->SourceDirRelative = $this->System->Config['Web']['SourceFolder']; 23 if (!file_exists($this->SourceDir)) mkdir($this->SourceDir, 0777, true);23 if (!file_exists($this->SourceDir)) mkdir($this->SourceDir, 0777, true); 24 24 } 25 25 … … 29 29 if ($Export['AllUsers']) { 30 30 $DbResult2 = $this->System->Database->query('SELECT ID FROM `User` WHERE `ID` NOT IN(SELECT `User` FROM `ExportUser` WHERE `Export`='.$this->Id.')'); 31 while ($UserLine = $DbResult2->fetch_assoc())31 while ($UserLine = $DbResult2->fetch_assoc()) 32 32 { 33 33 $Condition = ' WHERE `Export`='.$this->Id.' AND `User`='.$UserLine['ID']; 34 34 $DbResult = $this->System->Database->query('SELECT * FROM `ExportUser` '.$Condition); //,MAX(`Sequence`) as MaxSequence 35 if ($DbResult->num_rows > 0)35 if ($DbResult->num_rows > 0) 36 36 { 37 37 // $this->System->Database->query('UPDATE `ExportUser` SET `Sequence`='.$Value.$Condition); … … 50 50 { 51 51 $DbResult = $this->Database->query('SELECT * FROM `Export` WHERE `Id`='.$this->Id); 52 if ($DbResult->num_rows == 0) throw new Exception('Export '.$this->Id.' neexistuje');52 if ($DbResult->num_rows == 0) throw new Exception('Export '.$this->Id.' neexistuje'); 53 53 $this->Export = $DbResult->fetch_assoc(); 54 54 … … 58 58 'LEFT JOIN `User` ON `User`.`ID`=`ExportUser`.`User` '. 59 59 'WHERE `ExportUser`.`Export`='.$this->Id.' ORDER BY `ExportUser`.`Sequence`'); 60 while ($UserLine = $DbResult->fetch_assoc())60 while ($UserLine = $DbResult->fetch_assoc()) 61 61 { 62 62 $this->UserNames .= ', '.$UserLine['Name']; … … 64 64 $this->UserNames = substr($this->UserNames, 2); 65 65 66 if ($this->Export['ClientVersion'] != '')66 if ($this->Export['ClientVersion'] != '') 67 67 { 68 68 $DbResult = $this->Database->query('SELECT * FROM `ClientVersion` WHERE `Id`='.$this->Export['ClientVersion']); … … 82 82 83 83 $DbResultItem = $this->System->Database->query('SELECT * FROM `ExportGroupItem` WHERE `Export`='.$this->Id); 84 while ($GroupItem = $DbResultItem->fetch_assoc())84 while ($GroupItem = $DbResultItem->fetch_assoc()) 85 85 { 86 86 $GroupItems[$GroupItem['GroupItem']] = 1; … … 88 88 // Build selected columns 89 89 $Columns = ''; 90 foreach ($TranslationTree[$Group['Id']]['Items'] as $Column) {90 foreach ($TranslationTree[$Group['Id']]['Items'] as $Column) { 91 91 if (!isset($GroupItems[$Column['Id']])) $Columns .= ' `T`.`'.$Column['Column'].'` AS `'.$Column['Column'].'`, '; 92 92 } … … 104 104 // Build columns for english texts 105 105 $OriginalColumns = ''; 106 foreach ($TranslationTree[$Group['Id']]['Items'] as $Column) {106 foreach ($TranslationTree[$Group['Id']]['Items'] as $Column) { 107 107 $OriginalColumns .= ' `T3`.`'.$Column['Column'].'` AS `En'.$Column['Column'].'`, '; 108 108 if (isset($GroupItems[$Column['Id']])) … … 117 117 '(`T3`.`VersionStart` = `T4`.`VersionStart`) AND (`T3`.`VersionEnd` = `T4`.`VersionEnd`)'; 118 118 119 return ($Query);119 return $Query; 120 120 } 121 121 … … 129 129 if (file_exists($file)) 130 130 $date = date('Y-m-d H:i',(filemtime($file))); 131 else return (true);131 else return true; 132 132 // echo $file; 133 133 … … 135 135 'JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id); 136 136 $result = false; 137 while ($Group = $DbResult->fetch_assoc())137 while ($Group = $DbResult->fetch_assoc()) 138 138 { 139 139 $Query = 'SELECT * FROM `'.$Group['TablePrefix'].'` AS `T`'. … … 149 149 } 150 150 } 151 return ($result);151 return $result; 152 152 } 153 153 … … 172 172 $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` '. 173 173 'JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id); 174 while ($Group = $DbResult->fetch_assoc())174 while ($Group = $DbResult->fetch_assoc()) 175 175 { 176 176 $Buffer .= $Group['TablePrefix'].', '; … … 180 180 $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` '. 181 181 'JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id); 182 while ($Group = $DbResult->fetch_assoc())183 { 184 if ($Group['MangosTable'] != '')182 while ($Group = $DbResult->fetch_assoc()) 183 { 184 if ($Group['MangosTable'] != '') 185 185 { 186 186 $Buffer .= "\n\n-- ".$Group['Name']."\n\n"; 187 187 $DbResult2 = $this->Database->query($this->BuildQuery($Group)); 188 if ($DbResult2->num_rows > 0)189 while ($Line = $DbResult2->fetch_array())188 if ($DbResult2->num_rows > 0) 189 while ($Line = $DbResult2->fetch_array()) 190 190 { 191 191 $Values = ''; 192 foreach ($TranslationTree[$Group['Id']]['Items'] as $GroupItem)193 if ($GroupItem['Column'] != $Group['PrimaryKeyItem']) // Do not update primary key192 foreach ($TranslationTree[$Group['Id']]['Items'] as $GroupItem) 193 if ($GroupItem['Column'] != $Group['PrimaryKeyItem']) // Do not update primary key 194 194 { 195 if ($GroupItem['MangosColumn'] == '') $GroupItem['MangosColumn'] = $GroupItem['Column'];195 if ($GroupItem['MangosColumn'] == '') $GroupItem['MangosColumn'] = $GroupItem['Column']; 196 196 $Values .= ', `'.$GroupItem['MangosColumn'].'`="'.addslashes($Line[$GroupItem['Column']]).'"'; 197 197 } … … 200 200 // Get multicolumn index 201 201 $ColumnItems = explode(',', $Group['MangosTableIndex']); 202 if (count($ColumnItems) > 1)202 if (count($ColumnItems) > 1) 203 203 { 204 204 $Where = 'CONCAT('; 205 foreach ($ColumnItems as $ColumnItem)205 foreach ($ColumnItems as $ColumnItem) 206 206 $Where .= '`'.$ColumnItem.'`, "_", '; 207 207 $Where = substr($Where, 0, -7).')'; … … 216 216 } 217 217 } 218 if ($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer);219 return ($Buffer);218 if ($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer); 219 return $Buffer; 220 220 } 221 221 … … 243 243 'aowow_skill' => 'skillID', 244 244 ); 245 foreach ($AoWoWTables as $AoWoWTable => $IndexColum)245 foreach ($AoWoWTables as $AoWoWTable => $IndexColum) 246 246 { 247 247 $Buffer .= '--'.$AoWoWTable.', '; … … 249 249 $Query = 'SELECT `name`,`'.$IndexColum.'` FROM `'.$AoWoWTable.'`'; 250 250 $DbResult = $Database2->query($Query); 251 while ($Line = $DbResult->fetch_assoc())251 while ($Line = $DbResult->fetch_assoc()) 252 252 { 253 253 $Ori_text = $Line['name']; … … 259 259 $Tran = $DbResult2->fetch_assoc(); 260 260 //echo ($Line['name'].'='.$Tran['tran']); 261 if ($Tran['Tran'] == '')261 if ($Tran['Tran'] == '') 262 262 { 263 263 $DbResult2 = $Database2->query('SELECT `OptionText` AS `En`, … … 270 270 } 271 271 272 if ($Tran['Tran'] <> '')272 if ($Tran['Tran'] <> '') 273 273 $Buffer .= 'UPDATE `'.$AoWoWTable.'` SET `name` = "'.addslashes($Tran['Tran']).'" WHERE '.$IndexColum.' = '.$Line[$IndexColum].' ;'."\n"; 274 274 } … … 276 276 } 277 277 */ 278 if ($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer);279 return ($Buffer);278 if ($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer); 279 return $Buffer; 280 280 } 281 281 … … 299 299 if (false === strpos($String2,$varible)) { 300 300 // echo $varible; 301 return (false);301 return false; 302 302 } 303 303 } 304 304 } 305 return (true);305 return true; 306 306 } 307 307 … … 324 324 'WHERE `ExportGroup`.`Export`='.$this->Id.' AND `Group`.`DBCFileName` != ""'); 325 325 $Output = 'Počet generovaných skupin: '.$DbResult->num_rows."\n"; 326 while ($Group = $DbResult->fetch_assoc())326 while ($Group = $DbResult->fetch_assoc()) 327 327 { 328 328 $this->AddProgress(2); 329 329 $Output .= $Group['Name'].', '; 330 if (file_exists($this->SourceDir.$this->ClientVersion['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc'))330 if (file_exists($this->SourceDir.$this->ClientVersion['Version'].'/dbc/'.$Group['DBCFileName'].'.dbc')) 331 331 { 332 332 // Load string column index list … … 335 335 $ColumnIndexes = array(); 336 336 $ColumnFormat = array(); 337 while ($DbRow = $DbResult2->fetch_assoc())337 while ($DbRow = $DbResult2->fetch_assoc()) 338 338 { 339 339 $ColumnFormat[$DbRow['ColumnIndex']] = FORMAT_STRING; … … 344 344 $LookupTable = array(); 345 345 $DbResult2 = $this->Database->query($this->BuildQuery($Group)); 346 while ($DbRow = $DbResult2->fetch_assoc()) {346 while ($DbRow = $DbResult2->fetch_assoc()) { 347 347 //Export only if translate have same varible % 348 348 $CanExport = true; 349 foreach ($TranslationTree[$Group['Id']]['Items'] as $Column) {349 foreach ($TranslationTree[$Group['Id']]['Items'] as $Column) { 350 350 $DbRow[$Column['Column']] = str_replace ( '$ ','$',$DbRow[$Column['Column']]); 351 351 if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']])) { … … 369 369 370 370 // Create new DBC file 371 if (!file_exists($this->TempDir.'dbc/')) mkdir ($this->TempDir.'dbc/', 0777, true);371 if (!file_exists($this->TempDir.'dbc/')) mkdir ($this->TempDir.'dbc/', 0777, true); 372 372 $NewDBCFile = new DBCFile(); 373 373 $NewDBCFile->CreateFile($this->TempDir.'dbc/'.$Group['DBCFileName'].'.dbc', $ColumnFormat); … … 381 381 $RowCount = $SourceDBCFile->GetRecordCount(); 382 382 $FieldCount = $SourceDBCFile->GetFieldCount(); 383 for ($Row = 0; $Row < $RowCount; $Row++)383 for ($Row = 0; $Row < $RowCount; $Row++) 384 384 { 385 385 $Line = $SourceDBCFile->GetLine($Row); … … 388 388 $PrimaryKeyItem = ''; 389 389 $ColumnItems = explode(',', $Group['DBCIndex']); 390 if (count($ColumnItems) > 1)390 if (count($ColumnItems) > 1) 391 391 { 392 foreach ($ColumnItems as $ColumnItem)392 foreach ($ColumnItems as $ColumnItem) 393 393 $PrimaryKeyItem .= $Line[$ColumnItem].'_'; 394 394 $PrimaryKeyItem = substr($PrimaryKeyItem, 0, -1); 395 395 } else $PrimaryKeyItem = $Line[$Group['DBCIndex']]; 396 396 397 if (array_key_exists($PrimaryKeyItem, $LookupTable))397 if (array_key_exists($PrimaryKeyItem, $LookupTable)) 398 398 { 399 399 // Replace text columns 400 400 $LookupTableItem = $LookupTable[$PrimaryKeyItem]; 401 foreach ($TranslationTree[$Group['Id']]['Items'] as $GroupItem)401 foreach ($TranslationTree[$Group['Id']]['Items'] as $GroupItem) 402 402 { 403 if (array_key_exists($GroupItem['Id'], $ColumnIndexes))403 if (array_key_exists($GroupItem['Id'], $ColumnIndexes)) 404 404 $Line[$ColumnIndexes[$GroupItem['Id']]] = $LookupTableItem[$GroupItem['Column']]; 405 405 } … … 409 409 // Show completion progress 410 410 $Progress = round($Row / $RowCount * 100); 411 if ($Progress != $OldProgress)411 if ($Progress != $OldProgress) 412 412 { 413 413 if (($Group['Id'] == 13) and ($Progress <> 100)) $this->AddProgress(0.01); … … 422 422 } 423 423 $Output .= 'Hotovo <br />'; 424 return ($Output);424 return $Output; 425 425 } 426 426 … … 432 432 433 433 $Output = ''; 434 if (!file_exists($this->TempDir.'lua/')) mkdir($this->TempDir.'lua/', 0777, true);434 if (!file_exists($this->TempDir.'lua/')) mkdir($this->TempDir.'lua/', 0777, true); 435 435 $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id.' AND `Group`.`LuaFileName` != ""'); 436 while ($Group = $DbResult->fetch_assoc())436 while ($Group = $DbResult->fetch_assoc()) 437 437 { 438 438 $this->AddProgress(1); … … 448 448 $LookupTable = array(); 449 449 $DbResult2 = $this->Database->query($this->BuildQuery($Group)); 450 while ($DbRow = $DbResult2->fetch_assoc()) {450 while ($DbRow = $DbResult2->fetch_assoc()) { 451 451 $CanExport = true; 452 foreach ($TranslationTree[$Group['Id']]['Items'] as $Column) {452 foreach ($TranslationTree[$Group['Id']]['Items'] as $Column) { 453 453 // if (strpos($DbRow[$Column['Column']],'\\')) 454 454 // $CanExport = false; … … 502 502 } 503 503 504 while (!$File->EOF())504 while (!$File->EOF()) 505 505 { 506 506 $Line = $File->ReadLine(); 507 if (strpos($Line, '=') !== false)507 if (strpos($Line, '=') !== false) 508 508 { 509 509 $LineParts = explode('=', $Line, 2); … … 511 511 $Line = trim($LineParts[1]); 512 512 513 if ($Line[0] == '"')513 if ($Line[0] == '"') 514 514 { 515 515 // Quoted string value … … 532 532 $Value['Comment'] = addslashes(stripslashes(substr($Line, 3))); // Skip " --" 533 533 534 if (array_key_exists($Value['ShortCut'], $LookupTable))534 if (array_key_exists($Value['ShortCut'], $LookupTable)) 535 535 { 536 536 $DbRow = $LookupTable[$Value['ShortCut']]; … … 548 548 } 549 549 $NewLine = $Value['ShortCut'].' = "'.$Value['Text'].'";'; 550 //if ($Value['Comment'] != '') $NewLine .= ' -- '.$Value['Comment'];550 //if ($Value['Comment'] != '') $NewLine .= ' -- '.$Value['Comment']; 551 551 $NewLine .= "\r\n"; 552 552 $File2->WriteLine($NewLine); … … 555 555 $Output .= 'Hotovo <br/>'; 556 556 } 557 return ($Output);557 return $Output; 558 558 } 559 559 … … 656 656 " <author>".$this->System->User->Name."</author>\n". 657 657 " <contributors>\n"; 658 foreach (explode(',', $this->UserNames) as $UserName)658 foreach (explode(',', $this->UserNames) as $UserName) 659 659 $Buffer .= " <user>".$UserName."</user>\n"; 660 660 $Buffer .= … … 665 665 $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` '. 666 666 'JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id); 667 while ($Group = $DbResult->fetch_assoc())668 { 669 if ($Group['MangosTable'] == '')667 while ($Group = $DbResult->fetch_assoc()) 668 { 669 if ($Group['MangosTable'] == '') 670 670 { 671 671 $Group['MangosTable'] = $Group['TablePrefix']; … … 674 674 $Buffer .= ' <group id="'.$Group['Id'].'" name="'.$Group['TablePrefix'].'">'."\n"; 675 675 $DbResult2 = $this->Database->query($this->BuildQuery($Group)); 676 while ($Line = $DbResult2->fetch_assoc())676 while ($Line = $DbResult2->fetch_assoc()) 677 677 { 678 678 $Buffer .= ' <item id="'.$Line['Entry'].'" user="'.$Line['UserName'].'">'."\n"; 679 679 $Values = ''; 680 foreach ($TranslationTree[$Group['Id']]['Items'] as $GroupItem)680 foreach ($TranslationTree[$Group['Id']]['Items'] as $GroupItem) 681 681 { 682 if ($GroupItem['MangosColumn'] == '') $GroupItem['MangosColumn'] = $GroupItem['Column'];683 if ($Line[$GroupItem['Column']] != '')682 if ($GroupItem['MangosColumn'] == '') $GroupItem['MangosColumn'] = $GroupItem['Column']; 683 if ($Line[$GroupItem['Column']] != '') 684 684 $Buffer .= ' <text index="'.$GroupItem['Id'].'" name="'. 685 685 $GroupItem['Column'].'">'.addslashes($Line[$GroupItem['Column']]).'</text>'."\n"; … … 689 689 $Buffer .= " </group>\n"; 690 690 } 691 if ($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer);691 if ($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer); 692 692 $Buffer .= " </translation>\n". 693 693 "</document>"; 694 return ($Buffer);694 return $Buffer; 695 695 } 696 696 } … … 732 732 '((`Export`.`OutputType` = 9) OR (`Export`.`OutputType` = 10)) AND '. 733 733 '(`TimeFinish` IS NULL) OR (`Export` ='.$TaskId.') ORDER BY `TimeQueued`'); // `Export`='.$Export->Id 734 while ($Task = $DbResult->fetch_assoc())734 while ($Task = $DbResult->fetch_assoc()) 735 735 { 736 736 $Export = '<a href="'.$this->System->Link('/export/?Action=View&ExportId='.$Task['Export']).'">'.$Task['Export'].'</a>'; … … 744 744 // Show estimated time to complete 745 745 $PrefixMultiplier = new PrefixMultiplier(); 746 if ($Task['Progress'] > 0) {746 if ($Task['Progress'] > 0) { 747 747 $ElapsedTime = time() - MysqlDateTimeToTime($Task['TimeStart']); 748 748 $Output .= T('Elapsed time').': <strong>'.$PrefixMultiplier->Add($ElapsedTime, '', 4, 'Time').'</strong> / '; … … 752 752 $Output .= '</div>'; 753 753 754 if ($Task['Progress'] > 99)754 if ($Task['Progress'] > 99) 755 755 $Output .= '<script type="text/javascript" language="JavaScript" charset="utf-8">'. 756 756 'setTimeout("parent.location.href=\''.$this->System->Link('/export/?Action=View&Tab=7&ExportId='.$TaskId).'\'", 500)'. 757 757 '</script>'; 758 758 } 759 return ($Output);759 return $Output; 760 760 } 761 761 }
Note:
See TracChangeset
for help on using the changeset viewer.