Name = 'Team'; $this->Version = '1.0'; $this->Creator = 'Chronos'; $this->License = 'GNU/GPL'; $this->Description = 'Allow users to create teams similar to guilds in the game.'; $this->Dependencies = array('User'); } function DoStart(): void { $this->System->RegisterPage(['team'], 'PageTeam'); Core::Cast($this->System)->RegisterMenuItem(array( 'Title' => T('Teams'), 'Hint' => T('List of translating teams'), 'Link' => $this->System->Link('/team/'), 'Permission' => LICENCE_ANONYMOUS, 'Icon' => '', ), 1); if (array_key_exists('Search', $this->System->ModuleManager->Modules)) $this->System->ModuleManager->Modules['Search']->RegisterSearch('team', T('Teams'), array('Name'), '`Team`', $this->System->Link('/team/?search=')); } } class PageTeam extends Page { function ShowTeamList() { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; $this->Title = T('Teams'); $Output = '

'.T('List of translating teams').'

'; $Output .= 'Týmy jsou seskupení překladatelů, kteří se hlásí k něčemu společnému jako např. WoW serveru, způsobu překladu, ke stejnému hernímu spolku, aj. Být členem týmu samo o sobě nemá žádný zásadní důsledek a spíše to může pomoci se lépe orientovat mezi překladateli někomu, kdo sestavuje export.
'; if (array_key_exists('search', $_GET)) $_SESSION['search'] = $_GET['search']; else if (!array_key_exists('search', $_SESSION)) $_SESSION['search'] = ''; if (array_key_exists('search', $_GET) and ($_GET['search'] == '')) $_SESSION['search'] = ''; if ($User->Licence(LICENCE_USER)) $Output .= '
'.T('Create translating team').'

'; if ($_SESSION['search'] != '') { $SearchQuery = ' AND ((`Name` LIKE "%'.$_SESSION['search'].'%") OR (`Description` LIKE "%'.$_SESSION['search'].'%"))'; $Output .= '
'.sprintf(T('Disable filter "%s"'), htmlspecialchars($_SESSION['search'])).'
'; } else $SearchQuery = ''; $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Team` WHERE 1'.$SearchQuery); $DbRow = $DbResult->fetch_row(); $PageList = GetPageList($DbRow[0]); $Output .= $PageList['Output']; $Output .= ''; $TableColumns = array( array('Name' => 'Name', 'Title' => T('Name')), array('Name' => 'URL', 'Title' => T('Web pages')), array('Name' => 'LeaderName', 'Title' => T('Leader')), array('Name' => 'NumberUser', 'Title' => T('Member count')), array('Name' => 'TimeCreate', 'Title' => T('Founding date')), ); if ($User->Licence(LICENCE_USER)) $TableColumns[] = array('Name' => '', 'Title' => T('User actions')); $Order = GetOrderTableHeader($TableColumns, 'NumberUser', 1); $Output .= $Order['Output']; $DbResult = $this->Database->query('SELECT *, (SELECT COUNT(*) FROM `User` WHERE `User`.`Team` = `Team`.`Id`) AS `NumberUser`, '. '(SELECT `Name` FROM `User` WHERE `User`.`ID`=`Team`.`Leader`) AS `LeaderName` '. 'FROM `Team` WHERE 1'.$SearchQuery.$Order['SQL'].$PageList['SQLLimit']); while ($Team = $DbResult->fetch_assoc()) { $Output .= ''. ''. ''. ''. ''. ''; if ($User->Licence(LICENCE_USER)) { if ($Team['Leader'] == $User->Id) $Action = ' '.T('Edit').''; else $Action = ''; if ($Team['Id'] == $User->Team) $Action = ' '.T('Leave').''; $Output .= ''; } $Output .= ''; } $Output .= '
'.htmlspecialchars($Team['Name']).''.htmlspecialchars($Team['URL']).''.$Team['LeaderName'].''.$Team['NumberUser'].''.HumanDate($Team['TimeCreate']).''.T('Enter').''.$Action.'
'. $PageList['Output']; return $Output; } function TeamJoin() { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; if ($User->Licence(LICENCE_USER)) { if (array_key_exists('id', $_GET)) { $this->Database->query('UPDATE `User` SET `Team` = '.$_GET['id'].' WHERE `ID` = '.$User->Id); $Output = ShowMessage(T('You joined new team')); $this->System->ModuleManager->Modules['Log']->WriteLog('Uživatel vstoupil do týmu '.$_GET['id'], LOG_TYPE_USER); // Delete all teams without users $this->Database->query('DELETE FROM `Team` WHERE (SELECT COUNT(*) FROM `User` WHERE `User`.`Team` = `Team`.`Id`) = 0'); // Set new leader for teams where old leader went to other team $this->Database->query('UPDATE `Team` SET `Leader`=(SELECT `Id` FROM `User` WHERE `User`.`Team`=`Team`.`Id` ORDER BY `User`.`RegistrationTime` LIMIT 1) WHERE `Leader` NOT IN (SELECT `ID` FROM `User` WHERE `User`.`Team`=`Team`.`Id`);'); $Output .= $this->ShowTeamList(); } else $Output = ShowMessage('Nutno zadat id týmu.', MESSAGE_CRITICAL); } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); return $Output; } function TeamCreateFinish() { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = ''; if ($User->Licence(LICENCE_USER)) { if (array_key_exists('Name', $_POST) and array_key_exists('Description', $_POST)) { $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Team` WHERE `Name` = "'.trim($_POST['Name']).'"'); $DbRow = $DbResult->fetch_row(); $Count = $DbRow[0]; if (($Count == 0) and ($_POST['Name'] != '')) { $this->Database->query('INSERT INTO `Team` (`Name` ,`Description`, `URL`, `TimeCreate`, `Leader`)'. ' VALUES ("'.trim($_POST['Name']).'", "'.trim($_POST['Description']).'", "'. $_POST['URL'].'", NOW(), '.$User->Id.')'); $this->Database->query('UPDATE `User` SET `Team` = '.$this->Database->insert_id.' WHERE `ID` = '.$User->Id); $Output .= ShowMessage('Překladatelský tým vytvořen.'); $this->System->ModuleManager->Modules['Log']->WriteLog('Překladatelský tým vytvořen '.$_POST['Name'], LOG_TYPE_USER); // Delete all teams without users $this->Database->query('DELETE FROM `Team` WHERE (SELECT COUNT(*) FROM `User` WHERE `User`.`Team` = `Team`.`Id`) = 0'); } else $Output .= ShowMessage('Již existuje tým se stejným jménem', MESSAGE_CRITICAL); } else $Output .= ShowMessage('Chybí údaje formuláře', MESSAGE_CRITICAL); } else $Output .= ShowMessage(T('Access denied'), MESSAGE_CRITICAL); $Output .= $this->ShowTeamList(); return $Output; } function TeamModify() { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; if ($User->Licence(LICENCE_USER)) { if (array_key_exists('id', $_GET)) { $DbResult = $this->Database->query('SELECT * FROM `Team` WHERE `Id`='.$_GET['id'].' AND `Leader`='.$User->Id); if ($DbResult->num_rows > 0) { $Team = $DbResult->fetch_assoc(); $Output = '
'. '
Nastavení týmu'. ''. ''. ''. ''. '
Jméno:
Webové stránky:http://
Popis:
'; } else $Output = ShowMessage('Tým nenalezen.', MESSAGE_CRITICAL); } else $Output = ShowMessage('Nezadáno id týmu', MESSAGE_CRITICAL); } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); return $Output; } function TeamModifyFinish() { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = ''; if ($User->Licence(LICENCE_USER)) { if (array_key_exists('id', $_GET) and array_key_exists('Name', $_POST) and array_key_exists('Description', $_POST) and array_key_exists('URL', $_POST)) { $DbResult = $this->Database->query('SELECT * FROM `Team` WHERE `Id`='.$_GET['id'].' AND `Leader`='.$User->Id); if ($DbResult->num_rows > 0) { $Team = $DbResult->fetch_assoc(); $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Team` WHERE `Name` = "'.trim($_POST['Name']).'"'); $DbRow = $DbResult->fetch_row(); $Count = $DbRow[0]; if (($Count == 0) and ($_POST['Name'] != '')) { $this->Database->query('UPDATE `Team` SET `Name`="'.$_POST['Name'].'", `Description`="'.$_POST['Description'].'", `URL`="'.$_POST['URL'].'" WHERE Id='.$Team['Id']); $Output .= ShowMessage('Nastavení týmu uloženo.'); $this->System->ModuleManager->Modules['Log']->WriteLog('Překladatelský tým upraven '.$_POST['Name'], LOG_TYPE_USER); } else $Output .= ShowMessage('Již existuje tým se stejným jménem.', MESSAGE_CRITICAL); } else $Output .= ShowMessage('Tým nenalezen nebo nemáte oprávnění.', MESSAGE_CRITICAL); } else $Output .= ShowMessage('Nezadáno id týmu nebo některé položky formuláře.', MESSAGE_CRITICAL); } else $Output .= ShowMessage(T('Access denied'), MESSAGE_CRITICAL); $Output .= $this->ShowTeamList(); return $Output; } function TeamCreate() { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; if ($User->Licence(LICENCE_USER)) { $Output ='
'. '
Vytvoření nového týmu'. ''. ''. ''. ''. '
Jméno:
Webové stránky:http://
Popis:
'; } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); return $Output; } function TeamShow() { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; $Output = ''; if (array_key_exists('id', $_GET) and is_numeric($_GET['id'])) { $DbResult = $this->Database->query('SELECT `Id`, `Name`, `Description`, `URL`, `Leader`, '. '(SELECT COUNT(*) FROM `User` WHERE '. '`Team` = `Team`.`Id`) AS `NumberUser`, '. '(SELECT SUM(`TranslatedCount`) FROM `User` WHERE `Team` = `Team`.`Id`) AS `NumberTranslate`, '. '(SELECT ROUND(AVG(`XP`)) FROM `User` WHERE `Team` = `Team`.`Id`) AS `AverageXP` FROM '. '`Team` WHERE `Id`='.($_GET['id'] * 1)); if ($DbResult->num_rows > 0) { $Team = $DbResult->fetch_assoc(); $DbResult2 = $this->Database->query('SELECT `Name`, `Id` FROM `User` WHERE `ID`='.$Team['Leader']); if ($DbResult2->num_rows > 0) { $Leader = $DbResult2->fetch_assoc(); } else $Leader = array('Name' => '', 'Id' => 0); $Output .='

'.T('Translation team').' '.htmlspecialchars($Team['Name']).'


'. T('Web pages').': '.htmlspecialchars($Team['URL']).'
'. T('Leader').': '.$Leader['Name'].'
'; if ($Team['Description'] != '') $Output .= T('Description').': '.htmlspecialchars($Team['Description']).'
'; $Output .= '
'; //$Output .= 'Exportovat překlad týmu '; if ($User->Licence(LICENCE_USER)) $Output .=''.T('Enter to team').'

'; $XP = GetLevelMinMax($Team['AverageXP']); $Output .='
'.T('Statistics').''. T('Team member count').': '.$Team['NumberUser'].'
'. T('Team number of translated texts').': '.$Team['NumberTranslate'].'
'. T('Average level of team members').': '.$XP['Level'].' '.T('experience').': '.ProgressBar(150, round($XP['XP'] / $XP['MaxXP'] * 100, 2), $XP['XP'].' / '.$XP['MaxXP']).'
'. '
'. ''.T('Team completion state for version').' '.Core::Cast($this->System)->Config['Web']['GameVersion'].'
'; $BuildNumber = GetBuildNumber(Core::Cast($this->System)->Config['Web']['GameVersion']); $GroupListQuery = 'SELECT `Group`.* FROM `Group`'; $Query = ''; $DbResult = $this->Database->query($GroupListQuery); if ($DbResult->num_rows > 0) { while ($DbRow = $DbResult->fetch_assoc()) { $Query .= 'SELECT (SELECT COUNT(DISTINCT(`Entry`)) FROM ('. 'SELECT `T`.`Entry` FROM `'.$DbRow['TablePrefix'].'` AS `T` '. 'WHERE (`User` IN (SELECT `ID` FROM `User` WHERE `Team` = '.$Team['Id'].')) '. 'AND (`Complete` = 1) AND (`T`.`Language`!='.Core::Cast($this->System)->Config['OriginalLanguage'].') '. 'AND (`VersionStart` <= '.$BuildNumber.') AND (`VersionEnd` >= '.$BuildNumber.')'. ') AS `C1`) AS `Translated`, '. '(SELECT COUNT(DISTINCT(`Entry`)) FROM ('. 'SELECT `T`.`Entry` FROM `'.$DbRow['TablePrefix'].'` AS `T` '. 'WHERE (`Language` = '.Core::Cast($this->System)->Config['OriginalLanguage'].') '. 'AND (`VersionStart` <= '.$BuildNumber.') AND (`VersionEnd` >= '.$BuildNumber.')'. ') AS `C2`) AS `Total`, "'.$DbRow['Name'].'" AS `Name` UNION '; } $Query = substr($Query, 0, - 6); $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$GroupListQuery.') AS `T`'); $DbRow = $DbResult->fetch_row(); $PageList = GetPageList($DbRow[0]); $Output .= $PageList['Output']; $Output .=''; $TableColumns = array( array('Name' => 'Name', 'Title' => T('Name')), array('Name' => 'Translated', 'Title' => T('Translated')), array('Name' => 'Total', 'Title' => T('Original')), array('Name' => 'Percent', 'Title' => T('Percent')), ); $Order = GetOrderTableHeader($TableColumns, 'Name', 0); $Output .= $Order['Output']; $Translated = 0; $Total = 0; $DbResult = $this->Database->query('SELECT *, ROUND(`Translated` / `Total` * 100, 2) AS `Percent` FROM ('.$Query.') AS `C3` '.$Order['SQL'].$PageList['SQLLimit']); while ($Group = $DbResult->fetch_assoc()) { $Output .=''; $Translated += $Group['Translated']; $Total += $Group['Total']; } if ($Total > 0) $Progress = round($Translated / $Total * 100, 2); else $Progress = 0; $Output .=''; $Output .='
'.T($Group['Name']).''.$Group['Translated']. ''.$Group['Total'].''.ProgressBar(150, $Group['Percent']).'
'.T('Total').''. $Translated.''.$Total.''. ProgressBar(150, $Progress).'
'; } $Output .='
'; } else $Output .= ShowMessage('Tým nenalezen', MESSAGE_CRITICAL); } else $Output .= ShowMessage('Musíte zadat id týmu', MESSAGE_CRITICAL); return $Output; } function TeamLeave() { $User = ModuleUser::Cast($this->System->GetModule('User'))->User; if ($User->Licence(LICENCE_USER)) { $this->Database->query('UPDATE `User` SET `Team` = NULL WHERE `ID` = '.$User->Id); $Output = ShowMessage(T('You are now not member of any team')); $this->System->ModuleManager->Modules['Log']->WriteLog('Uživatel vystoupil z týmu', LOG_TYPE_USER); // Delete all teams without users $this->Database->query('DELETE FROM `Team` WHERE (SELECT COUNT(*) FROM `User` WHERE `User`.`Team` = `Team`.`Id`) = 0'); // Set new leader for teams where old leader went to other team $this->Database->query('UPDATE `Team` SET `Leader`=(SELECT `Id` FROM `User` WHERE `User`.`Team`=`Team`.`Id` ORDER BY `User`.`RegistrationTime` LIMIT 1) WHERE `Leader` NOT IN (SELECT `ID` FROM `User` WHERE `User`.`Team`=`Team`.`Id`);'); $Output .= $this->ShowTeamList(); } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); return $Output; } function Show(): string { if (array_key_exists('action', $_GET)) { if ($_GET['action'] == 'gointeam') $Output = $this->TeamJoin(); else if ($_GET['action'] == 'finish_create') $Output = $this->TeamCreateFinish(); else if ($_GET['action'] == 'modify') $Output = $this->TeamModify(); else if ($_GET['action'] == 'finish_modify') $Output = $this->TeamModifyFinish(); else if ($_GET['action'] == 'create') $Output = $this->TeamCreate(); else if ($_GET['action'] == 'team') $Output = $this->TeamShow(); else if ($_GET['action'] == 'leave') $Output = $this->TeamLeave(); else $Output = $this->ShowTeamList(); } else $Output = $this->ShowTeamList(); return $Output; } }