Ignore:
Timestamp:
Apr 7, 2020, 10:15:48 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Improved code formatting.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Export/Export.php

    r879 r880  
    1717  {
    1818    $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);
    2020    $this->TempDirRelative = $this->System->Config['Web']['TempFolder'].'Export/'.$this->Id.'/';
    2121    $this->SourceDir = dirname(__FILE__).'/../../'.$this->System->Config['Web']['SourceFolder'];
    2222    $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);
    2424  }
    2525
     
    2929    if ($Export['AllUsers']) {
    3030      $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())
    3232      {
    3333            $Condition = ' WHERE `Export`='.$this->Id.' AND `User`='.$UserLine['ID'];
    3434            $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)
    3636            {
    3737            //  $this->System->Database->query('UPDATE `ExportUser` SET `Sequence`='.$Value.$Condition);
     
    5050  {
    5151    $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');
    5353    $this->Export = $DbResult->fetch_assoc();
    5454
     
    5858      'LEFT JOIN `User` ON `User`.`ID`=`ExportUser`.`User` '.
    5959      'WHERE `ExportUser`.`Export`='.$this->Id.' ORDER BY `ExportUser`.`Sequence`');
    60     while($UserLine = $DbResult->fetch_assoc())
     60    while ($UserLine = $DbResult->fetch_assoc())
    6161    {
    6262      $this->UserNames .= ', '.$UserLine['Name'];
     
    6464    $this->UserNames = substr($this->UserNames, 2);
    6565
    66     if($this->Export['ClientVersion'] != '')
     66    if ($this->Export['ClientVersion'] != '')
    6767    {
    6868      $DbResult = $this->Database->query('SELECT * FROM `ClientVersion` WHERE `Id`='.$this->Export['ClientVersion']);
     
    8282
    8383    $DbResultItem = $this->System->Database->query('SELECT * FROM `ExportGroupItem` WHERE `Export`='.$this->Id);
    84     while($GroupItem = $DbResultItem->fetch_assoc())
     84    while ($GroupItem = $DbResultItem->fetch_assoc())
    8585    {
    8686      $GroupItems[$GroupItem['GroupItem']] = 1;
     
    8888    // Build selected columns
    8989    $Columns = '';
    90     foreach($TranslationTree[$Group['Id']]['Items'] as $Column) {
     90    foreach ($TranslationTree[$Group['Id']]['Items'] as $Column) {
    9191      if (!isset($GroupItems[$Column['Id']])) $Columns .= ' `T`.`'.$Column['Column'].'` AS `'.$Column['Column'].'`, ';
    9292    }
     
    104104    // Build columns for english texts
    105105    $OriginalColumns = '';
    106     foreach($TranslationTree[$Group['Id']]['Items'] as $Column) {
     106    foreach ($TranslationTree[$Group['Id']]['Items'] as $Column) {
    107107      $OriginalColumns .= ' `T3`.`'.$Column['Column'].'` AS `En'.$Column['Column'].'`, ';
    108108      if (isset($GroupItems[$Column['Id']]))
     
    117117    '(`T3`.`VersionStart` = `T4`.`VersionStart`) AND (`T3`.`VersionEnd` = `T4`.`VersionEnd`)';
    118118
    119     return($Query);
     119    return $Query;
    120120  }
    121121
     
    129129    if (file_exists($file))
    130130      $date = date('Y-m-d H:i',(filemtime($file)));
    131     else return(true);
     131    else return true;
    132132  // echo $file;
    133133
     
    135135      'JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id);
    136136    $result = false;
    137     while($Group = $DbResult->fetch_assoc())
     137    while ($Group = $DbResult->fetch_assoc())
    138138    {
    139139      $Query = 'SELECT * FROM `'.$Group['TablePrefix'].'` AS `T`'.
     
    149149        }
    150150    }
    151     return($result);
     151    return $result;
    152152  }
    153153
     
    172172    $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` '.
    173173      'JOIN `Group` ON `Group`.`Id` = `ExportGroup`.`Group` WHERE `ExportGroup`.`Export`='.$this->Id);
    174     while($Group = $DbResult->fetch_assoc())
     174    while ($Group = $DbResult->fetch_assoc())
    175175    {
    176176      $Buffer .= $Group['TablePrefix'].', ';
     
    180180    $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` '.
    181181      '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'] != '')
    185185      {
    186186        $Buffer .= "\n\n-- ".$Group['Name']."\n\n";
    187187        $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())
    190190        {
    191191          $Values = '';
    192           foreach($TranslationTree[$Group['Id']]['Items'] as $GroupItem)
    193           if($GroupItem['Column'] != $Group['PrimaryKeyItem']) // Do not update primary key
     192          foreach ($TranslationTree[$Group['Id']]['Items'] as $GroupItem)
     193          if ($GroupItem['Column'] != $Group['PrimaryKeyItem']) // Do not update primary key
    194194          {
    195             if($GroupItem['MangosColumn'] == '') $GroupItem['MangosColumn'] = $GroupItem['Column'];
     195            if ($GroupItem['MangosColumn'] == '') $GroupItem['MangosColumn'] = $GroupItem['Column'];
    196196            $Values .= ', `'.$GroupItem['MangosColumn'].'`="'.addslashes($Line[$GroupItem['Column']]).'"';
    197197          }
     
    200200          // Get multicolumn index
    201201          $ColumnItems = explode(',', $Group['MangosTableIndex']);
    202           if(count($ColumnItems) > 1)
     202          if (count($ColumnItems) > 1)
    203203          {
    204204            $Where = 'CONCAT(';
    205             foreach($ColumnItems as $ColumnItem)
     205            foreach ($ColumnItems as $ColumnItem)
    206206              $Where .= '`'.$ColumnItem.'`, "_", ';
    207207            $Where = substr($Where, 0, -7).')';
     
    216216      }
    217217    }
    218     if($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer);
    219     return($Buffer);
     218    if ($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer);
     219    return $Buffer;
    220220  }
    221221
     
    243243      'aowow_skill' => 'skillID',
    244244    );
    245     foreach($AoWoWTables as $AoWoWTable => $IndexColum)
     245    foreach ($AoWoWTables as $AoWoWTable => $IndexColum)
    246246    {
    247247      $Buffer .= '--'.$AoWoWTable.', ';
     
    249249      $Query = 'SELECT `name`,`'.$IndexColum.'` FROM `'.$AoWoWTable.'`';
    250250      $DbResult = $Database2->query($Query);
    251       while($Line = $DbResult->fetch_assoc())
     251      while ($Line = $DbResult->fetch_assoc())
    252252      {
    253253        $Ori_text = $Line['name'];
     
    259259        $Tran = $DbResult2->fetch_assoc();
    260260        //echo ($Line['name'].'='.$Tran['tran']);
    261         if($Tran['Tran'] == '')
     261        if ($Tran['Tran'] == '')
    262262        {
    263263          $DbResult2 = $Database2->query('SELECT `OptionText` AS `En`,
     
    270270        }
    271271
    272         if($Tran['Tran'] <> '')
     272        if ($Tran['Tran'] <> '')
    273273          $Buffer .= 'UPDATE `'.$AoWoWTable.'` SET `name` = "'.addslashes($Tran['Tran']).'" WHERE '.$IndexColum.' = '.$Line[$IndexColum].' ;'."\n";
    274274      }
     
    276276    }
    277277    */
    278     if($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer);
    279     return($Buffer);
     278    if ($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer);
     279    return $Buffer;
    280280  }
    281281
     
    299299          if (false === strpos($String2,$varible)) {
    300300              //  echo $varible;
    301             return(false);
     301            return false;
    302302          }
    303303      }
    304304    }
    305     return (true);
     305    return true;
    306306  }
    307307
     
    324324      'WHERE `ExportGroup`.`Export`='.$this->Id.' AND `Group`.`DBCFileName` != ""');
    325325    $Output = 'Počet generovaných skupin: '.$DbResult->num_rows."\n";
    326     while($Group = $DbResult->fetch_assoc())
     326    while ($Group = $DbResult->fetch_assoc())
    327327    {
    328328      $this->AddProgress(2);
    329329      $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'))
    331331      {
    332332        // Load string column index list
     
    335335        $ColumnIndexes = array();
    336336        $ColumnFormat = array();
    337         while($DbRow = $DbResult2->fetch_assoc())
     337        while ($DbRow = $DbResult2->fetch_assoc())
    338338        {
    339339          $ColumnFormat[$DbRow['ColumnIndex']] = FORMAT_STRING;
     
    344344        $LookupTable = array();
    345345        $DbResult2 = $this->Database->query($this->BuildQuery($Group));
    346         while($DbRow = $DbResult2->fetch_assoc()) {
     346        while ($DbRow = $DbResult2->fetch_assoc()) {
    347347          //Export only if translate have same varible %
    348348          $CanExport = true;
    349           foreach($TranslationTree[$Group['Id']]['Items'] as $Column)  {
     349          foreach ($TranslationTree[$Group['Id']]['Items'] as $Column)  {
    350350            $DbRow[$Column['Column']] = str_replace ( '$ ','$',$DbRow[$Column['Column']]);
    351351            if (!$this->HaveVarible($DbRow['En'.$Column['Column']],$DbRow[$Column['Column']])) {
     
    369369
    370370        // 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);
    372372        $NewDBCFile = new DBCFile();
    373373        $NewDBCFile->CreateFile($this->TempDir.'dbc/'.$Group['DBCFileName'].'.dbc', $ColumnFormat);
     
    381381        $RowCount = $SourceDBCFile->GetRecordCount();
    382382        $FieldCount = $SourceDBCFile->GetFieldCount();
    383         for($Row = 0; $Row < $RowCount; $Row++)
     383        for ($Row = 0; $Row < $RowCount; $Row++)
    384384        {
    385385          $Line = $SourceDBCFile->GetLine($Row);
     
    388388          $PrimaryKeyItem = '';
    389389          $ColumnItems = explode(',', $Group['DBCIndex']);
    390           if(count($ColumnItems) > 1)
     390          if (count($ColumnItems) > 1)
    391391          {
    392             foreach($ColumnItems as $ColumnItem)
     392            foreach ($ColumnItems as $ColumnItem)
    393393              $PrimaryKeyItem .= $Line[$ColumnItem].'_';
    394394            $PrimaryKeyItem = substr($PrimaryKeyItem, 0, -1);
    395395          } else $PrimaryKeyItem = $Line[$Group['DBCIndex']];
    396396
    397           if(array_key_exists($PrimaryKeyItem, $LookupTable))
     397          if (array_key_exists($PrimaryKeyItem, $LookupTable))
    398398          {
    399399            // Replace text columns
    400400            $LookupTableItem = $LookupTable[$PrimaryKeyItem];
    401             foreach($TranslationTree[$Group['Id']]['Items'] as $GroupItem)
     401            foreach ($TranslationTree[$Group['Id']]['Items'] as $GroupItem)
    402402            {
    403               if(array_key_exists($GroupItem['Id'], $ColumnIndexes))
     403              if (array_key_exists($GroupItem['Id'], $ColumnIndexes))
    404404                $Line[$ColumnIndexes[$GroupItem['Id']]] = $LookupTableItem[$GroupItem['Column']];
    405405            }
     
    409409          // Show completion progress
    410410          $Progress = round($Row / $RowCount * 100);
    411           if($Progress != $OldProgress)
     411          if ($Progress != $OldProgress)
    412412          {
    413413            if (($Group['Id'] == 13) and ($Progress <> 100)) $this->AddProgress(0.01);
     
    422422    }
    423423    $Output .= 'Hotovo <br />';
    424     return($Output);
     424    return $Output;
    425425  }
    426426
     
    432432
    433433    $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);
    435435    $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())
    437437    {
    438438      $this->AddProgress(1);
     
    448448      $LookupTable = array();
    449449      $DbResult2 = $this->Database->query($this->BuildQuery($Group));
    450       while($DbRow = $DbResult2->fetch_assoc()) {
     450      while ($DbRow = $DbResult2->fetch_assoc()) {
    451451          $CanExport = true;
    452           foreach($TranslationTree[$Group['Id']]['Items'] as $Column)  {
     452          foreach ($TranslationTree[$Group['Id']]['Items'] as $Column)  {
    453453          //  if (strpos($DbRow[$Column['Column']],'\\'))
    454454           //   $CanExport = false;
     
    502502      }
    503503
    504       while(!$File->EOF())
     504      while (!$File->EOF())
    505505      {
    506506        $Line = $File->ReadLine();
    507         if(strpos($Line, '=') !== false)
     507        if (strpos($Line, '=') !== false)
    508508        {
    509509          $LineParts = explode('=', $Line, 2);
     
    511511          $Line = trim($LineParts[1]);
    512512
    513           if($Line[0] == '"')
     513          if ($Line[0] == '"')
    514514          {
    515515            // Quoted string value
     
    532532          $Value['Comment'] = addslashes(stripslashes(substr($Line, 3))); // Skip " --"
    533533
    534           if(array_key_exists($Value['ShortCut'], $LookupTable))
     534          if (array_key_exists($Value['ShortCut'], $LookupTable))
    535535          {
    536536            $DbRow = $LookupTable[$Value['ShortCut']];
     
    548548          }
    549549          $NewLine = $Value['ShortCut'].' = "'.$Value['Text'].'";';
    550           //if($Value['Comment'] != '') $NewLine .= ' -- '.$Value['Comment'];
     550          //if ($Value['Comment'] != '') $NewLine .= ' -- '.$Value['Comment'];
    551551          $NewLine .= "\r\n";
    552552          $File2->WriteLine($NewLine);
     
    555555      $Output .= 'Hotovo <br/>';
    556556    }
    557     return($Output);
     557    return $Output;
    558558  }
    559559
     
    656656    "    <author>".$this->System->User->Name."</author>\n".
    657657    "    <contributors>\n";
    658     foreach(explode(',', $this->UserNames) as $UserName)
     658    foreach (explode(',', $this->UserNames) as $UserName)
    659659      $Buffer .= "      <user>".$UserName."</user>\n";
    660660    $Buffer .=
     
    665665    $DbResult = $this->Database->query('SELECT `Group`.* FROM `ExportGroup` '.
    666666      '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'] == '')
    670670      {
    671671        $Group['MangosTable'] = $Group['TablePrefix'];
     
    674674      $Buffer .= '    <group id="'.$Group['Id'].'" name="'.$Group['TablePrefix'].'">'."\n";
    675675      $DbResult2 = $this->Database->query($this->BuildQuery($Group));
    676       while($Line = $DbResult2->fetch_assoc())
     676      while ($Line = $DbResult2->fetch_assoc())
    677677      {
    678678        $Buffer .= '      <item id="'.$Line['Entry'].'" user="'.$Line['UserName'].'">'."\n";
    679679        $Values = '';
    680         foreach($TranslationTree[$Group['Id']]['Items'] as $GroupItem)
     680        foreach ($TranslationTree[$Group['Id']]['Items'] as $GroupItem)
    681681        {
    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']] != '')
    684684          $Buffer .= '        <text index="'.$GroupItem['Id'].'" name="'.
    685685            $GroupItem['Column'].'">'.addslashes($Line[$GroupItem['Column']]).'</text>'."\n";
     
    689689      $Buffer .= "    </group>\n";
    690690    }
    691     if($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer);
     691    if ($this->Export['WithDiacritic'] != 1) $Buffer = utf2ascii($Buffer);
    692692    $Buffer .= "  </translation>\n".
    693693  "</document>";
    694     return($Buffer);
     694    return $Buffer;
    695695  }
    696696}
     
    732732      '((`Export`.`OutputType` = 9) OR (`Export`.`OutputType` = 10)) AND '.
    733733      '(`TimeFinish` IS NULL) OR (`Export` ='.$TaskId.') ORDER BY `TimeQueued`'); // `Export`='.$Export->Id
    734     while($Task = $DbResult->fetch_assoc())
     734    while ($Task = $DbResult->fetch_assoc())
    735735    {
    736736      $Export = '<a href="'.$this->System->Link('/export/?Action=View&amp;ExportId='.$Task['Export']).'">'.$Task['Export'].'</a>';
     
    744744      // Show estimated time to complete
    745745      $PrefixMultiplier = new PrefixMultiplier();
    746       if($Task['Progress'] > 0) {
     746      if ($Task['Progress'] > 0) {
    747747        $ElapsedTime = time() - MysqlDateTimeToTime($Task['TimeStart']);
    748748        $Output .= T('Elapsed time').': <strong>'.$PrefixMultiplier->Add($ElapsedTime, '', 4, 'Time').'</strong> / ';
     
    752752      $Output .= '</div>';
    753753
    754       if($Task['Progress'] > 99)
     754      if ($Task['Progress'] > 99)
    755755        $Output .= '<script type="text/javascript" language="JavaScript" charset="utf-8">'.
    756756        'setTimeout("parent.location.href=\''.$this->System->Link('/export/?Action=View&Tab=7&ExportId='.$TaskId).'\'", 500)'.
    757757        '</script>';
    758758    }
    759     return($Output);
     759    return $Output;
    760760  }
    761761}
Note: See TracChangeset for help on using the changeset viewer.