[100] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | require_once('includes/global.php');
|
---|
| 4 |
|
---|
[586] | 5 | // Settings
|
---|
[100] | 6 | $xp_from_word = 1;
|
---|
| 7 | $index_level = 100;
|
---|
[586] | 8 | $from_diakrit = 3; // higher xp for word with diacritics
|
---|
[349] | 9 | $FontFile = 'images/FRIZQT__.ttf';
|
---|
[100] | 10 |
|
---|
[404] | 11 | function CheckDiakrit($Word)
|
---|
[292] | 12 | {
|
---|
[404] | 13 | $Result = false;
|
---|
| 14 | $Diakrit = array("á","č","ď","é","ě","í","ľ","ň","ó","ř","š","ť","ú",
|
---|
[292] | 15 | "ů","ý","ž","Á","Č","Ď","É","Ě","Í","Ľ","Ň","Ó","Ř","Š","Ť","Ú","Ů","Ý","Ž");
|
---|
| 16 | for($i = 0; $i < count($Diakrit); $i = $i + 1)
|
---|
| 17 | {
|
---|
[404] | 18 | if(strpos($Word, $Diakrit[$i]) <> false)
|
---|
| 19 | $Result = true;
|
---|
[100] | 20 | }
|
---|
[404] | 21 | return($Result);
|
---|
[292] | 22 | }
|
---|
[100] | 23 |
|
---|
[292] | 24 | function CreateImg($prefix, $user, $xp)
|
---|
| 25 | {
|
---|
[349] | 26 | global $index_level, $FontFile;
|
---|
| 27 |
|
---|
[292] | 28 | if($xp > 0)
|
---|
| 29 | {
|
---|
[349] | 30 | $level = sqrt($xp / $index_level);
|
---|
[292] | 31 | $level = substr($level, 0, strpos($level, '.'));
|
---|
| 32 | } else $level = 0;
|
---|
| 33 | $xp_min = $level * $level * $index_level;
|
---|
| 34 | $xp_max = ($level + 1) * ($level + 1) * $index_level;
|
---|
| 35 | $xp_max = $xp_max - $xp_min;
|
---|
| 36 | $xp = $xp - $xp_min;
|
---|
| 37 |
|
---|
| 38 | if($xp_max > 0) $Percent = ( $xp / $xp_max) * 100;
|
---|
| 39 | else $Percent = 0;
|
---|
| 40 | $Percent = substr($Percent, 0, 5);
|
---|
[100] | 41 |
|
---|
[292] | 42 | $PercentBar = $Percent * 2.5;
|
---|
| 43 | $Image = ImageCreateTrueColor(250, 15);
|
---|
| 44 | $Color1 = imagecolorallocate($Image, 214, 214, 214);
|
---|
| 45 | $Color2 = imagecolorallocate($Image, 239, 131, 166);
|
---|
| 46 | $Color3 = imagecolorallocate($Image, 225, 0, 0);
|
---|
| 47 | imagefilledrectangle($Image, 0, 0, 250, 15, $Color1);
|
---|
| 48 | imagefilledrectangle($Image, 0, 0, $PercentBar, 59, $Color2);
|
---|
| 49 | ImageTTFText($Image, 11, 0, 10, 12, $Color3, $FontFile, $level.' Level');
|
---|
| 50 | ImageTTFText($Image, 8, 0, 80, 12, $Color3, $FontFile, $xp.'/'.$xp_max.' xp '.$user);
|
---|
| 51 |
|
---|
| 52 | if(!file_exists('tmp/'.$prefix.'/')) mkdir('tmp/'.$prefix.'/');
|
---|
| 53 | if(!file_exists('tmp/'.$prefix.'/'.$user.'/')) mkdir('tmp/'.$prefix.'/'.$user.'/');
|
---|
| 54 | ImagePNG($Image, 'tmp/'.$prefix.'/'.$user.'/level.png');
|
---|
| 55 | }
|
---|
[100] | 56 |
|
---|
[404] | 57 | function GetXPFromTranslation($UserId)
|
---|
[292] | 58 | {
|
---|
[455] | 59 | global $System, $TranslationTree, $xp_from_word, $from_diakrit;
|
---|
[404] | 60 |
|
---|
[292] | 61 | $xp = 0;
|
---|
| 62 | foreach($TranslationTree as $Group)
|
---|
[404] | 63 | {
|
---|
[292] | 64 | if($Group['TablePrefix'] != '')
|
---|
| 65 | {
|
---|
[404] | 66 | $GroupBy = 'GROUP BY ';
|
---|
[292] | 67 | foreach($TranslationTree[$Group['Id']]['Items'] as $Index => $TextItem)
|
---|
| 68 | {
|
---|
[404] | 69 | $GroupBy .= '`'.$TextItem['Column'].'`, ';
|
---|
[292] | 70 | }
|
---|
[404] | 71 | $GroupBy = substr($GroupBy, 0, -2);
|
---|
| 72 |
|
---|
[523] | 73 | $IDtran = $System->Database->query('SELECT * FROM `'.$Group['TablePrefix'].'` WHERE (`User` = '.$UserId.') AND (`Complete` = 1) AND (`Take` IS NOT NULL) '.$GroupBy);
|
---|
[455] | 74 | while($Line = $IDtran->fetch_array())
|
---|
[404] | 75 | {
|
---|
[455] | 76 | $DbResult = $System->Database->query('SELECT * FROM `'.$Group['TablePrefix'].'` WHERE `ID` = '.$Line['Take']);
|
---|
| 77 | $LineComparison = $DbResult->fetch_assoc();
|
---|
[404] | 78 | $xp_translation = 0;
|
---|
[292] | 79 | $translated = true;
|
---|
| 80 | foreach($TranslationTree[$Group['Id']]['Items'] as $Index => $TextItem)
|
---|
[404] | 81 | {
|
---|
[292] | 82 | if(($Line[$TextItem['Column']] <> $LineComparison[$TextItem['Column']]) and (strlen($Line[$TextItem['Column']]) > (strlen($LineComparison[$TextItem['Column']]) * 0.5)))
|
---|
[404] | 83 | {
|
---|
| 84 | $TextArr = explode(' ', $Line[$TextItem['Column']]);
|
---|
| 85 | foreach($TextArr as $Word)
|
---|
| 86 | {
|
---|
| 87 | if(CheckDiakrit($Word)) $indikator = $from_diakrit;
|
---|
[292] | 88 | else $indikator = 1;
|
---|
| 89 | $xp_translation = $xp_translation + ($indikator * $xp_from_word);
|
---|
| 90 | }
|
---|
| 91 | } else
|
---|
| 92 | {
|
---|
| 93 | if (($Line[$TextItem['Column']] == $LineComparison[$TextItem['Column']]) and ('0' == $LineComparison['Language']) and ($LineComparison[$TextItem['Column']] <> '') and ($TextItem['Column'] <> 'ShortCut')) $translated = false;
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
[586] | 96 | if($translated) $xp = $xp + $xp_translation; // XP addition for entire translation if complete translated
|
---|
[292] | 97 | }
|
---|
| 98 | }
|
---|
[100] | 99 | }
|
---|
[404] | 100 | return($xp);
|
---|
[292] | 101 | }
|
---|
[100] | 102 |
|
---|
[349] | 103 | function ImgLevelUpdate()
|
---|
| 104 | {
|
---|
[525] | 105 | global $System, $TranslationTree, $Config;
|
---|
[349] | 106 |
|
---|
[540] | 107 | // Main code for users
|
---|
[455] | 108 | $DbResult = $System->Database->query('SELECT `ID`, `Name` FROM `User` WHERE `NeedUpdate` = 1');
|
---|
[771] | 109 | if($DbResult->num_rows > 0)
|
---|
[349] | 110 | {
|
---|
[771] | 111 | while($LineUser = $DbResult->fetch_array())
|
---|
[507] | 112 | {
|
---|
[771] | 113 | // Build TranslatedCount query
|
---|
| 114 | $TranslatedCount = '(';
|
---|
| 115 | if(count($TranslationTree) > 0)
|
---|
[350] | 116 | {
|
---|
[771] | 117 | foreach($TranslationTree as $Group)
|
---|
| 118 | if($Group['TablePrefix'] != '')
|
---|
| 119 | {
|
---|
| 120 | $Count = '(SELECT COUNT(*) FROM `'.$Group['TablePrefix'].'` WHERE (`Complete` = 1) AND (`Language` <> '.
|
---|
| 121 | $Config['OriginalLanguage'].') AND (`User`='.$LineUser['ID'].'))';
|
---|
| 122 | $TranslatedCount .= 'COALESCE('.$Count.', 0) + ';
|
---|
| 123 | }
|
---|
| 124 | $TranslatedCount = substr($TranslatedCount, 0, -3).')';
|
---|
| 125 | } else $TranslatedCount = 0;
|
---|
[350] | 126 |
|
---|
[771] | 127 | $xp = GetXPFromTranslation($LineUser['ID']);
|
---|
| 128 | $System->Database->query('UPDATE `User` SET `XP` = '.$xp.', `TranslatedCount` = '.$TranslatedCount.' WHERE `User`.`ID` = '.$LineUser['ID']);
|
---|
| 129 | CreateImg('user', $LineUser['Name'], $xp);
|
---|
| 130 | }
|
---|
[349] | 131 |
|
---|
[771] | 132 | // Main code for translation teams
|
---|
| 133 | $DbResult = $System->Database->query('SELECT `ID`, `Name`, (SELECT AVG(`XP`) FROM `User` WHERE `Team` = `Team`.`Id`) AS `Average` '.
|
---|
| 134 | 'FROM `Team` WHERE `ID` IN (SELECT `Team` FROM `User` WHERE `NeedUpdate` = 1)');
|
---|
| 135 | while($LineTeam = $DbResult->fetch_array())
|
---|
| 136 | {
|
---|
| 137 | CreateImg('team', $LineTeam['Name'], substr($LineTeam['Average'], 0, strpos($LineTeam['Average'],'.'))); //image creation
|
---|
| 138 | }
|
---|
| 139 | $System->Database->query('UPDATE `User` SET `NeedUpdate` = 0');
|
---|
[349] | 140 | }
|
---|
[100] | 141 | }
|
---|
[292] | 142 |
|
---|
[349] | 143 | function ImgLevelShow()
|
---|
[292] | 144 | {
|
---|
[455] | 145 | global $System;
|
---|
[349] | 146 |
|
---|
[350] | 147 | // Do update for all users
|
---|
[455] | 148 | $System->Database->query('UPDATE `User` SET `NeedUpdate` = 1');
|
---|
[350] | 149 | ImgLevelUpdate();
|
---|
| 150 |
|
---|
[504] | 151 | $Output = '<strong>Uživatelé</strong><br/>';
|
---|
[455] | 152 | $ID = $System->Database->query('SELECT `ID`, `Name` FROM `User`');
|
---|
| 153 | while($LineUser = $ID->fetch_array())
|
---|
[349] | 154 | {
|
---|
[504] | 155 | $Output .= '<img src="tmp/user/'.$LineUser['Name'].'/level.png" /> '.$LineUser['Name'].'<br />';
|
---|
[349] | 156 | }
|
---|
| 157 |
|
---|
[504] | 158 | $Output .= '<br/><strong>Týmy</strong><br/>';
|
---|
[455] | 159 | $ID = $System->Database->query('SELECT `ID`, `Name` FROM `Team`');
|
---|
| 160 | while($LineTeam = $ID->fetch_array())
|
---|
[349] | 161 | {
|
---|
[504] | 162 | $Output .= '<img src="tmp/team/'.$LineTeam['Name'].'/level.png" /> '.$LineTeam['Name'].'<br />';
|
---|
[349] | 163 | }
|
---|
[357] | 164 | WriteLog('Přegenerovány obrázky úrovní překladatelů a týmů', LOG_TYPE_ADMINISTRATION);
|
---|
[504] | 165 | return($Output);
|
---|
[131] | 166 | }
|
---|