Changeset 292 for trunk/img_level.php
- Timestamp:
- Dec 27, 2009, 8:19:32 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/img_level.php
r142 r292 2 2 3 3 require_once('includes/global.php'); 4 if (array_key_exists('nothide',$_GET)) 5 $nothide = true; 6 else 7 $nothide = false; 8 if ($nothide) ShowPage(); 4 5 if (array_key_exists('nothide', $_GET)) $nothide = true; 6 else $nothide = false; 7 if($nothide) ShowPage(); 9 8 10 9 $FontFile = 'images/FRIZQT__.ttf'; 11 $TranslationTree = GetTranslationTree();12 10 13 // nastavení11 // Nastavení 14 12 $xp_from_word = 1; 15 13 $index_level = 100; 16 14 $from_diakrit = 3; //zvýšené xp za slovo s diakritikou 17 15 18 function CheckDiakrit($word) { 19 $result = false; 20 $Diakrit = Array("á","č","ď","é","ě","í","ľ","ň","ó","ř","š","ť","ú", 21 "ů","ý","ž","Á","Č","Ď","É","Ě","Í","Ľ","Ň","Ó","Ř","Š","Ť","Ú","Ů","Ý","Ž"); 22 for ($i=0;$i<count($Diakrit);$i=$i+1) { 23 if (strpos($word,$Diakrit[$i]) <> false) { 24 $result = true; 25 } 26 } 27 return $result; 16 function CheckDiakrit($word) 17 { 18 $result = false; 19 $Diakrit = Array("á","č","ď","é","ě","í","ľ","ň","ó","ř","š","ť","ú", 20 "ů","ý","ž","Á","Č","Ď","É","Ě","Í","Ľ","Ň","Ó","Ř","Š","Ť","Ú","Ů","Ý","Ž"); 21 for($i = 0; $i < count($Diakrit); $i = $i + 1) 22 { 23 if(strpos($word, $Diakrit[$i]) <> false) 24 { 25 $result = true; 26 } 28 27 } 28 return $result; 29 } 29 30 30 function CreateImg($user,$xp) { 31 global $index_level,$FontFile; 32 33 if ($xp > 0) { 34 $level = sqrt ($xp / $index_level); 35 $level = substr($level,0,strpos($level,'.')); 36 } else { 37 $level = 0; 38 } 39 $xp_min = ($level) * ($level) * ($index_level); 40 $xp_max = ($level+1)*($level+1)* ($index_level); 41 $xp_max = $xp_max-$xp_min; 42 $xp = $xp-$xp_min; 43 44 if($xp_max > 0) $Percent = ( $xp / $xp_max) * 100; else $Percent = 0; 45 $Percent = substr($Percent, 0, 5); 31 function CreateImg($prefix, $user, $xp) 32 { 33 global $index_level, $FontFile; 34 35 if($xp > 0) 36 { 37 $level = sqrt ($xp / $index_level); 38 $level = substr($level, 0, strpos($level, '.')); 39 } else $level = 0; 40 $xp_min = $level * $level * $index_level; 41 $xp_max = ($level + 1) * ($level + 1) * $index_level; 42 $xp_max = $xp_max - $xp_min; 43 $xp = $xp - $xp_min; 44 45 if($xp_max > 0) $Percent = ( $xp / $xp_max) * 100; 46 else $Percent = 0; 47 $Percent = substr($Percent, 0, 5); 46 48 47 $PercentBar = $Percent * 2.5; 48 $Image = ImageCreateTrueColor(250, 15); 49 $Color1 = imagecolorallocate($Image, 214, 214, 214); 50 $Color2 = imagecolorallocate($Image, 239, 131, 166); 51 $Color3 = imagecolorallocate($Image, 225, 0, 0); 52 imagefilledrectangle($Image, 0, 0, 250, 15, $Color1); 53 imagefilledrectangle($Image, 0, 0, $PercentBar, 59, $Color2); 54 ImageTTFText($Image, 11, 0, 10, 12, $Color3, $FontFile, $level.' Level'); 55 ImageTTFText($Image, 8, 0, 80, 12, $Color3, $FontFile, $xp.'/'.$xp_max.' xp '.$user); 56 57 if (file_exists('tmp/teams/') == false) mkdir ('tmp/teams/'); 58 if (file_exists('tmp/'.$user.'/') == false) mkdir ('tmp/'.$user.'/'); 59 ImagePNG($Image,'tmp/'.$user.'/level.png'); 49 $PercentBar = $Percent * 2.5; 50 $Image = ImageCreateTrueColor(250, 15); 51 $Color1 = imagecolorallocate($Image, 214, 214, 214); 52 $Color2 = imagecolorallocate($Image, 239, 131, 166); 53 $Color3 = imagecolorallocate($Image, 225, 0, 0); 54 imagefilledrectangle($Image, 0, 0, 250, 15, $Color1); 55 imagefilledrectangle($Image, 0, 0, $PercentBar, 59, $Color2); 56 ImageTTFText($Image, 11, 0, 10, 12, $Color3, $FontFile, $level.' Level'); 57 ImageTTFText($Image, 8, 0, 80, 12, $Color3, $FontFile, $xp.'/'.$xp_max.' xp '.$user); 58 59 if(!file_exists('tmp/'.$prefix.'/')) mkdir('tmp/'.$prefix.'/'); 60 if(!file_exists('tmp/'.$prefix.'/'.$user.'/')) mkdir('tmp/'.$prefix.'/'.$user.'/'); 61 ImagePNG($Image, 'tmp/'.$prefix.'/'.$user.'/level.png'); 62 } 63 64 function GetXPFromTranslation($user_ID) 65 { 66 global $Database, $TranslationTree, $xp_from_word, $from_diakrit; 67 $xp = 0; 68 69 foreach($TranslationTree as $Group) 70 { //překladové skupiny 71 if($Group['TablePrefix'] != '') 72 { 73 $groupby = 'GROUP BY'; 74 foreach($TranslationTree[$Group['Id']]['Items'] as $Index => $TextItem) 75 { 76 if($groupby == 'GROUP BY') $groupby .= ' '.$TextItem['Column']; 77 else $groupby .= ', '.$TextItem['Column']; 78 } 79 $IDtran = $Database->SQLCommand('SELECT * FROM `'.$Group['TablePrefix'].'` WHERE User = '.$user_ID.' AND Complete = 1 '.$groupby); 80 while($Line = mysql_fetch_array($IDtran)) 81 { //jednotlivé překlady 82 $LineComparison = mysql_fetch_assoc($Database->SQLCommand('SELECT * FROM `'.$Group['TablePrefix'].'` WHERE ID = '.$Line['Take'])); 83 $xp_translation = 0; //mazání posledního 84 $translated = true; 85 foreach($TranslationTree[$Group['Id']]['Items'] as $Index => $TextItem) 86 { //jednotlivé položky překladu 87 if(($Line[$TextItem['Column']] <> $LineComparison[$TextItem['Column']]) and (strlen($Line[$TextItem['Column']]) > (strlen($LineComparison[$TextItem['Column']]) * 0.5))) 88 { //zda není stejný, zda je aspoň dlouhý jako polovina 89 $TextArr = explode(' ',$Line[$TextItem['Column']]); 90 for ($i = 0; $i < count($TextArr); $i = $i + 1) 91 { //pro každé slovo 92 if(CheckDiakrit($TextArr[$i])) $indikator = $from_diakrit; 93 else $indikator = 1; 94 $xp_translation = $xp_translation + ($indikator * $xp_from_word); 95 } 96 } else 97 { 98 if (($Line[$TextItem['Column']] == $LineComparison[$TextItem['Column']]) and ('0' == $LineComparison['Language']) and ($LineComparison[$TextItem['Column']] <> '') and ($TextItem['Column'] <> 'ShortCut')) $translated = false; 99 } 100 } 101 if($translated) $xp = $xp + $xp_translation; //přičítání XP za celý překlad, pokud je celý přeložený 102 } 103 } 60 104 } 105 return $xp; 106 } 61 107 62 function GetXPFromTranslation($user_ID) { 63 global $Database,$TranslationTree,$xp_from_word,$from_diakrit; 64 $xp = 0; 108 // Hlavní kod pro uživatele 109 if($nothide) $ID = $Database->SQLCommand('SELECT ID,user FROM user'); 110 else $ID = $Database->SQLCommand('SELECT ID,user FROM user WHERE NeedUpdate = 1'); 111 while($LineUser = mysql_fetch_array($ID)) 112 { 113 $xp = GetXPFromTranslation($LineUser['ID']); // Načítání XP 114 $Database->SQLCommand('UPDATE user SET XP = '.$xp.' WHERE ID = '.$LineUser['ID']); // Ukládání XP pro řazení 115 CreateImg('user', $LineUser['user'], $xp); // Vytváření obrázku 116 if($nothide) echo('<img src="tmp/user/'.$LineUser['user'].'/level.png" /><br />'); 117 } 65 118 66 foreach($TranslationTree as $Group) { //překladové skupiny 67 if($Group['TablePrefix'] != '') { 68 $groupby = 'GROUP BY'; 69 foreach($TranslationTree[$Group['Id']]['Items'] as $Index => $TextItem) { 70 if ($groupby == 'GROUP BY') $groupby .= ' '.$TextItem['Column']; 71 else $groupby .= ', '.$TextItem['Column']; 72 } 73 $IDtran = $Database->SQLCommand('SELECT * FROM `'.$Group['TablePrefix'].'` WHERE User = '.$user_ID.' AND Complete = 1 '.$groupby); 74 while ($Line = mysql_fetch_array($IDtran)) { //jednotlivé překlady 75 $LineComparison = mysql_fetch_assoc($Database->SQLCommand('SELECT * FROM `'.$Group['TablePrefix'].'` WHERE ID = '.$Line['Take'])); 76 $xp_translation = 0; //mazání posledního 77 $translated = true; 78 foreach($TranslationTree[$Group['Id']]['Items'] as $Index => $TextItem) { //jednotlivé položky překladu 79 if (($Line[$TextItem['Column']] <> $LineComparison[$TextItem['Column']]) and (strlen($Line[$TextItem['Column']]) > (strlen($LineComparison[$TextItem['Column']])*0.5))) { //zda není stejný, zda je aspoň dlouhý jako polovina 80 $TextArr = explode(' ',$Line[$TextItem['Column']]); 81 for ($i=0;$i<count($TextArr);$i=$i+1) { //pro každé slovo 82 if (CheckDiakrit($TextArr[$i])) // zjišťování diakritiky 83 $indikator = $from_diakrit; 84 else 85 $indikator = 1; 86 $xp_translation = $xp_translation + ($indikator * $xp_from_word); 87 } 88 } else { 89 if (($Line[$TextItem['Column']] == $LineComparison[$TextItem['Column']]) and 90 ('0' == $LineComparison['Language']) and 91 ($LineComparison[$TextItem['Column']] <> '') and 92 ($TextItem['Column'] <> 'ShortCut')) 93 $translated = false; 94 } 95 } 96 if ($translated) $xp = $xp+$xp_translation; //přičítání XP za celý překlad, pokud je celý přeložený 97 } 98 } 99 } 100 return $xp; 101 } 119 // Hlavní kod pro překladatelské týmy 120 if($nothide) $ID = $Database->SQLCommand('SELECT ID,name,(SELECT avg(XP) FROM user WHERE team = team.ID) as average FROM team'); 121 else $ID = $Database->SQLCommand('SELECT ID,name,(SELECT avg(XP) FROM user WHERE team = team.ID) as average FROM team WHERE ID IN (SELECT Team FROM user WHERE NeedUpdate = 1)'); 122 while($LineTeam = mysql_fetch_array($ID)) 123 { 124 CreateImg('team', $LineTeam['name'], substr($LineTeam['average'], 0, strpos($LineTeam['average'],'.'))); //vytváření obrázku 125 if($nothide) echo('<img src="tmp/team/'.$LineTeam['name'].'/level.png" /><br />'); 126 } 127 $Database->SQLCommand('UPDATE user SET NeedUpdate = 0'); 102 128 103 //hlavní kod pro uživatele 104 if ($nothide) $ID = $Database->SQLCommand('SELECT ID,user FROM user'); 105 else $ID = $Database->SQLCommand('SELECT ID,user FROM user WHERE NeedUpdate = 1'); 106 while ($LineUser = mysql_fetch_array($ID)) { 107 $xp = GetXPFromTranslation($LineUser['ID']); //načítání XP 108 $Database->SQLCommand('UPDATE user SET XP = '.$xp.' WHERE ID = '.$LineUser['ID']); //ukládání XP pro řazení 109 CreateImg($LineUser['user'],$xp); //vytváření obrázku 110 if ($nothide) echo ('<img src="tmp/'.$LineUser['user'].'/level.png" /><br />'); 111 } 112 //hlavní kod pro překladatelské týmy 113 if ($nothide) $ID = $Database->SQLCommand('SELECT ID,name,(SELECT avg(XP) FROM user WHERE team = team.ID) as average FROM team'); 114 else $ID = $Database->SQLCommand('SELECT ID,name,(SELECT avg(XP) FROM user WHERE team = team.ID) as average FROM team WHERE ID IN (SELECT Team FROM user WHERE NeedUpdate = 1)'); 115 while ($LineTeam = mysql_fetch_array($ID)) { 116 CreateImg('teams/'.$LineTeam['name'],substr($LineTeam['average'], 0, strpos($LineTeam['average'],'.'))); //vytváření obrázku 117 if ($nothide) echo ('<img src="tmp/'.$LineTeam['name'].'/level.png" /><br />'); 118 } 119 $Database->SQLCommand('UPDATE user SET NeedUpdate = 0'); 120 121 if ($nothide) ShowFooter(); 129 if($nothide) ShowFooter(); 122 130 123 131 ?>
Note:
See TracChangeset
for help on using the changeset viewer.