1 | <?php
|
---|
2 |
|
---|
3 | require_once('includes/global.php');
|
---|
4 |
|
---|
5 | if (array_key_exists('nothide', $_GET)) $nothide = true;
|
---|
6 | else $nothide = false;
|
---|
7 | if($nothide) ShowPage();
|
---|
8 |
|
---|
9 | $FontFile = 'images/FRIZQT__.ttf';
|
---|
10 |
|
---|
11 | // Nastavení
|
---|
12 | $xp_from_word = 1;
|
---|
13 | $index_level = 100;
|
---|
14 | $from_diakrit = 3; //zvýšené xp za slovo s diakritikou
|
---|
15 |
|
---|
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 | }
|
---|
27 | }
|
---|
28 | return $result;
|
---|
29 | }
|
---|
30 |
|
---|
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);
|
---|
48 |
|
---|
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 | }
|
---|
104 | }
|
---|
105 | return $xp;
|
---|
106 | }
|
---|
107 |
|
---|
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 | }
|
---|
118 |
|
---|
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');
|
---|
128 |
|
---|
129 | if($nothide) ShowFooter();
|
---|
130 |
|
---|
131 | ?>
|
---|