source: trunk/img_level.php@ 268

Last change on this file since 268 was 142, checked in by maron, 16 years ago

Oprava menších chyb, pravé menu

File size: 5.3 KB
Line 
1<?php
2
3require_once('includes/global.php');
4if (array_key_exists('nothide',$_GET))
5 $nothide = true;
6else
7 $nothide = false;
8if ($nothide) ShowPage();
9
10$FontFile = 'images/FRIZQT__.ttf';
11$TranslationTree = GetTranslationTree();
12
13//nastavení
14$xp_from_word = 1;
15$index_level = 100;
16$from_diakrit = 3; //zvýšené xp za slovo s diakritikou
17
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;
28 }
29
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);
46
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');
60 }
61
62 function GetXPFromTranslation($user_ID) {
63 global $Database,$TranslationTree,$xp_from_word,$from_diakrit;
64 $xp = 0;
65
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 }
102
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');
106while ($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)');
115while ($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
121if ($nothide) ShowFooter();
122
123?>
Note: See TracBrowser for help on using the repository browser.