Changeset 89 for trunk/export.php


Ignore:
Timestamp:
Feb 11, 2009, 7:49:33 PM (16 years ago)
Author:
george
Message:
  • Přidáno: Funkce pro export do DBC souborů. Zatím veřejně nepovoleno v nabídce, protože doba generování 45 MB souboru Spells.dbc překračuje max. dobu vykonání PHP skriptu 30 sekund. Nutno zoptimalizovat.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/export.php

    r68 r89  
    162162  return($Buffer);
    163163}     
     164
     165function ExportToDBC($Setting)
     166{
     167  global $Database, $Config, $TranslationTree;
     168 
     169  $TempDir = 'tmp/'.$_SESSION['User'].'/dbc/';
     170  if(!file_exists($TempDir)) mkdir($TempDir, 0777, true);
     171 
     172  if($_SESSION['UserID'] != '')
     173  {
     174    $DbResult = $Database->SQLCommand("SELECT user FROM `user` WHERE ID=".$_SESSION['UserID']);
     175    $User = mysql_fetch_assoc($DbResult);
     176  } else $User = array('user' => 'Neznámý');
     177
     178  $WhereLang = '';
     179  if($Setting['language-cz']) $WhereLang .= " OR (Language = 1)";
     180  if($Setting['language-sk']) $WhereLang .= " OR (Language = 2)";
     181  if($Setting['language-other']) $WhereLang .= " OR (Language = 3)";
     182  if($WhereLang == '') $WhereLang = 1;
     183    else $WhereLang = '('.substr($WhereLang, 4).')';
     184
     185  $SelectedUsers = ''; 
     186  foreach($Setting['users-selection'] as $Item)
     187    $SelectedUsers .= ','.$Item;
     188  $SelectedUsers = substr($SelectedUsers, 1);
     189
     190  if($SelectedUsers == '') $Where = 0;
     191    else $Where = 'ID IN ('.$SelectedUsers.')';
     192 
     193  $UserNames = '';
     194  $DbResult = $Database->SQLCommand('SELECT user FROM `user` WHERE '.$Where);
     195  while($DbRow = mysql_fetch_assoc($DbResult))
     196    $UserNames .= ','.$DbRow['user'];
     197  $UserNames = substr($UserNames, 1);   
     198   
     199  if($SelectedUsers == '') $WhereUsers = 1;
     200    else $WhereUsers = '(User IN ('.$SelectedUsers.'))';
     201 
     202  foreach($TranslationTree as $Group)
     203  if(in_array($Group['Id'], $Setting['groups']) and ($Group['DBCFileName'] != ''))
     204  {
     205        echo($Group['Name'].'... ');
     206    $DBCFile = new DBCFile();
     207    $DBCFile->OpenFile('dbc/'.$Group['DBCFileName'].'.dbc', $Group['DBCColumns']);
     208    $DBCFile2 = new DBCFile();
     209    $DBCFile2->CreateFile($TempDir.$Group['DBCFileName'].'.dbc', $Group['DBCColumns']);
     210        $Count = $DBCFile->GetRecordCount();
     211        //if($Group['DBCFileName'] == 'Spell') $Count = 1000;
     212        $Line = $DBCFile->GetLine(0);
     213    $DBCFile2->SetRecordCount($Count);   
     214    for($I = 0; $I < $Count; $I++)
     215    {
     216      $Line = $DBCFile->GetLine($I);
     217          //print_r($Line);
     218          $Query = 'SELECT * FROM (SELECT * FROM '.$Group['TablePrefix'].' WHERE (Complete = 1) AND '.$WhereLang.' AND '.$WhereUsers.' AND (entry='.$Line[0].') ORDER BY FIELD(User, '.$SelectedUsers.')) AS T GROUP BY T.entry';       
     219          $DbResult = $Database->SQLCommand($Query);
     220          if(mysql_num_rows($DbResult) > 0)
     221          {
     222            $DbRow = mysql_fetch_assoc($DbResult);
     223        //  if($Setting['Diacritics'] != 1) $Buffer = utf2ascii($Buffer);
     224
     225        //foreach($Group['Items'] as $GroupItem)
     226            //  if($GroupItem['DBCColumnIndex'] != '')
     227            //    $Line[$GroupItem['DBCColumnIndex']] = $DbRow[$GroupItem['Column']];
     228          }
     229      $DBCFile2->SetLine($I, $Line);
     230          echo('.');
     231    }
     232    $DBCFile2->Commit();
     233    echo('Hotovo <br />');
     234  }
     235}
     236
    164237?>
Note: See TracChangeset for help on using the changeset viewer.