Changeset 816 for trunk/img_level.php


Ignore:
Timestamp:
Feb 22, 2015, 11:20:50 PM (10 years ago)
Author:
chronos
Message:
  • Modified: Tabs converted to spaces.
  • Modified: Remove spaces from end of lines.
  • Added: Code format script.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/img_level.php

    r771 r816  
    1414  $Diakrit = array("á","č","ď","é","ě","í","ľ","ň","ó","ř","š","ť","ú",
    1515  "ů","ý","ž","Á","Č","Ď","É","Ě","Í","Ľ","Ň","Ó","Ř","Š","Ť","Ú","Ů","Ý","Ž");
    16   for($i = 0; $i < count($Diakrit); $i = $i + 1) 
     16  for($i = 0; $i < count($Diakrit); $i = $i + 1)
    1717  {
    18     if(strpos($Word, $Diakrit[$i]) <> false) 
     18    if(strpos($Word, $Diakrit[$i]) <> false)
    1919      $Result = true;
    2020  }
     
    2222}
    2323
    24 function CreateImg($prefix, $user, $xp) 
     24function CreateImg($prefix, $user, $xp)
    2525{
    26   global $index_level, $FontFile;   
    27  
    28   if($xp > 0) 
     26  global $index_level, $FontFile;
     27
     28  if($xp > 0)
    2929  {
    3030    $level = sqrt($xp / $index_level);
     
    3535  $xp_max = $xp_max - $xp_min;
    3636  $xp = $xp - $xp_min;
    37    
    38   if($xp_max > 0) $Percent = ( $xp / $xp_max) * 100; 
     37
     38  if($xp_max > 0) $Percent = ( $xp / $xp_max) * 100;
    3939    else $Percent = 0;
    4040  $Percent = substr($Percent, 0, 5);
     
    4949  ImageTTFText($Image, 11, 0, 10, 12, $Color3, $FontFile, $level.' Level');
    5050  ImageTTFText($Image, 8, 0, 80, 12, $Color3, $FontFile, $xp.'/'.$xp_max.' xp   '.$user);
    51  
     51
    5252  if(!file_exists('tmp/'.$prefix.'/')) mkdir('tmp/'.$prefix.'/');
    5353  if(!file_exists('tmp/'.$prefix.'/'.$user.'/')) mkdir('tmp/'.$prefix.'/'.$user.'/');
    54   ImagePNG($Image, 'tmp/'.$prefix.'/'.$user.'/level.png'); 
     54  ImagePNG($Image, 'tmp/'.$prefix.'/'.$user.'/level.png');
    5555}
    5656
    57 function GetXPFromTranslation($UserId) 
     57function GetXPFromTranslation($UserId)
    5858{
    5959  global $System, $TranslationTree, $xp_from_word, $from_diakrit;
    60  
     60
    6161  $xp = 0;
    62   foreach($TranslationTree as $Group) 
    63   { 
    64     if($Group['TablePrefix'] != '') 
     62  foreach($TranslationTree as $Group)
     63  {
     64    if($Group['TablePrefix'] != '')
    6565    {
    6666      $GroupBy = 'GROUP BY ';
    67       foreach($TranslationTree[$Group['Id']]['Items'] as $Index => $TextItem) 
    68       { 
     67      foreach($TranslationTree[$Group['Id']]['Items'] as $Index => $TextItem)
     68      {
    6969         $GroupBy .= '`'.$TextItem['Column'].'`, ';
    70       } 
     70      }
    7171      $GroupBy = substr($GroupBy, 0, -2);
    72      
     72
    7373      $IDtran = $System->Database->query('SELECT * FROM `'.$Group['TablePrefix'].'` WHERE (`User` = '.$UserId.') AND (`Complete` = 1) AND (`Take` IS NOT NULL) '.$GroupBy);
    74       while($Line = $IDtran->fetch_array()) 
    75       {   
     74      while($Line = $IDtran->fetch_array())
     75      {
    7676        $DbResult = $System->Database->query('SELECT * FROM `'.$Group['TablePrefix'].'` WHERE `ID` = '.$Line['Take']);
    7777        $LineComparison = $DbResult->fetch_assoc();
    78         $xp_translation = 0;   
     78        $xp_translation = 0;
    7979        $translated = true;
    80         foreach($TranslationTree[$Group['Id']]['Items'] as $Index => $TextItem) 
    81         { 
    82           if(($Line[$TextItem['Column']] <> $LineComparison[$TextItem['Column']]) and (strlen($Line[$TextItem['Column']]) > (strlen($LineComparison[$TextItem['Column']]) * 0.5))) 
    83           { 
     80        foreach($TranslationTree[$Group['Id']]['Items'] as $Index => $TextItem)
     81        {
     82          if(($Line[$TextItem['Column']] <> $LineComparison[$TextItem['Column']]) and (strlen($Line[$TextItem['Column']]) > (strlen($LineComparison[$TextItem['Column']]) * 0.5)))
     83          {
    8484            $TextArr = explode(' ', $Line[$TextItem['Column']]);
    85             foreach($TextArr as $Word) 
    86             { 
     85            foreach($TextArr as $Word)
     86            {
    8787              if(CheckDiakrit($Word)) $indikator = $from_diakrit;
    8888                else $indikator = 1;
    8989              $xp_translation = $xp_translation + ($indikator * $xp_from_word);
    90             }                               
    91           } else 
     90            }
     91          } else
    9292          {
    9393            if (($Line[$TextItem['Column']] == $LineComparison[$TextItem['Column']]) and ('0' == $LineComparison['Language']) and ($LineComparison[$TextItem['Column']] <> '') and ($TextItem['Column'] <> 'ShortCut')) $translated = false;
    9494          }
    95         }       
     95        }
    9696        if($translated) $xp = $xp + $xp_translation;   // XP addition for entire translation if complete translated
    9797      }
     
    102102
    103103function ImgLevelUpdate()
    104 { 
     104{
    105105  global $System, $TranslationTree, $Config;
    106106
     
    109109  if($DbResult->num_rows > 0)
    110110  {
    111     while($LineUser = $DbResult->fetch_array()) 
     111    while($LineUser = $DbResult->fetch_array())
    112112    {
    113113      // Build TranslatedCount query
     
    115115      if(count($TranslationTree) > 0)
    116116      {
    117             foreach($TranslationTree as $Group)
     117      foreach($TranslationTree as $Group)
    118118        if($Group['TablePrefix'] != '')
    119119        {
     
    124124        $TranslatedCount = substr($TranslatedCount, 0, -3).')';
    125125      } else $TranslatedCount = 0;
    126    
    127       $xp = GetXPFromTranslation($LineUser['ID']); 
     126
     127      $xp = GetXPFromTranslation($LineUser['ID']);
    128128      $System->Database->query('UPDATE `User` SET `XP` = '.$xp.', `TranslatedCount` = '.$TranslatedCount.' WHERE `User`.`ID` = '.$LineUser['ID']);
    129129      CreateImg('user', $LineUser['Name'], $xp);
     
    133133    $DbResult = $System->Database->query('SELECT `ID`, `Name`, (SELECT AVG(`XP`) FROM `User` WHERE `Team` = `Team`.`Id`) AS `Average` '.
    134134      'FROM `Team` WHERE `ID` IN (SELECT `Team` FROM `User` WHERE `NeedUpdate` = 1)');
    135     while($LineTeam = $DbResult->fetch_array()) 
     135    while($LineTeam = $DbResult->fetch_array())
    136136    {
    137137      CreateImg('team', $LineTeam['Name'], substr($LineTeam['Average'], 0, strpos($LineTeam['Average'],'.')));  //image creation
     
    144144{
    145145  global $System;
    146  
     146
    147147  // Do update for all users
    148148  $System->Database->query('UPDATE `User` SET `NeedUpdate` = 1');
    149149  ImgLevelUpdate();
    150  
     150
    151151  $Output = '<strong>Uživatelé</strong><br/>';
    152152  $ID = $System->Database->query('SELECT `ID`, `Name` FROM `User`');
    153   while($LineUser = $ID->fetch_array()) 
     153  while($LineUser = $ID->fetch_array())
    154154  {
    155155    $Output .= '<img src="tmp/user/'.$LineUser['Name'].'/level.png" /> '.$LineUser['Name'].'<br />';
     
    158158  $Output .= '<br/><strong>Týmy</strong><br/>';
    159159  $ID = $System->Database->query('SELECT `ID`, `Name` FROM `Team`');
    160   while($LineTeam = $ID->fetch_array()) 
     160  while($LineTeam = $ID->fetch_array())
    161161  {
    162162    $Output .= '<img src="tmp/team/'.$LineTeam['Name'].'/level.png" /> '.$LineTeam['Name'].'<br />';
    163163  }
    164   WriteLog('Přegenerovány obrázky úrovní překladatelů a týmů', LOG_TYPE_ADMINISTRATION); 
     164  WriteLog('Přegenerovány obrázky úrovní překladatelů a týmů', LOG_TYPE_ADMINISTRATION);
    165165  return($Output);
    166166}
Note: See TracChangeset for help on using the changeset viewer.