Changeset 816 for trunk/Modules/Team
- Timestamp:
- Feb 22, 2015, 11:20:50 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Team/Team.php
r636 r816 13 13 $this->Dependencies = array('User'); 14 14 } 15 15 16 16 function Start() 17 17 { 18 19 18 $this->System->RegisterPage('team', 'PageTeam'); 19 $this->System->RegisterMenuItem(array( 20 20 'Title' => T('Teams'), 21 'Hint' => T('List of translating teams'), 21 'Hint' => T('List of translating teams'), 22 22 'Link' => $this->System->Link('/team/'), 23 'Permission' => LICENCE_ANONYMOUS, 24 'Icon' => '', 23 'Permission' => LICENCE_ANONYMOUS, 24 'Icon' => '', 25 25 ), 1); 26 26 if(array_key_exists('Search', $this->System->ModuleManager->Modules)) … … 34 34 class PageTeam extends Page 35 35 { 36 37 38 39 40 36 function ShowTeamList() 37 { 38 $this->Title = T('Teams'); 39 $Output = '<h3>'.T('List of translating teams').'</h3>'; 40 $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.<br/>'; 41 41 42 42 if(array_key_exists('search', $_GET)) $_SESSION['search'] = $_GET['search']; 43 44 45 46 47 48 49 50 $SearchQuery = ' AND ((`Name` LIKE "%'.$_SESSION['search'].'%") OR (`Description` LIKE "%'.$_SESSION['search'].'%"))'; 51 52 } else $SearchQuery = ''; 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 $Output .= $Order['Output']; 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 43 else if(!array_key_exists('search', $_SESSION)) $_SESSION['search'] = ''; 44 if (array_key_exists('search', $_GET) and ($_GET['search'] == '')) $_SESSION['search'] = ''; 45 46 if($this->System->User->Licence(LICENCE_USER)) 47 $Output .= '<br /><div style="text-align: center;"><a href="?action=create">'.T('Create translating team').'</a></div><br/>'; 48 if($_SESSION['search'] != '') 49 { 50 $SearchQuery = ' AND ((`Name` LIKE "%'.$_SESSION['search'].'%") OR (`Description` LIKE "%'.$_SESSION['search'].'%"))'; 51 $Output .= '<div><a href="?search=">'.sprintf(T('Disable filter "%s"'), $_SESSION['search']).'</a></div>'; 52 } else $SearchQuery = ''; 53 54 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Team` WHERE 1'.$SearchQuery); 55 $DbRow = $DbResult->fetch_row(); 56 $PageList = GetPageList($DbRow[0]); 57 58 $Output .= $PageList['Output']; 59 $Output .= '<table class="BaseTable">'; 60 61 $TableColumns = array( 62 array('Name' => 'Name', 'Title' => T('Name')), 63 array('Name' => 'URL', 'Title' => T('Web pages')), 64 array('Name' => 'LeaderName', 'Title' => T('Leader')), 65 array('Name' => 'NumberUser', 'Title' => T('Member count')), 66 array('Name' => 'TimeCreate', 'Title' => T('Founding date')), 67 ); 68 if($this->System->User->Licence(LICENCE_USER)) $TableColumns[] = array('Name' => '', 'Title' => T('User actions')); 69 70 $Order = GetOrderTableHeader($TableColumns, 'NumberUser', 1); 71 $Output .= $Order['Output']; 72 73 $DbResult = $this->Database->query('SELECT *, (SELECT COUNT(*) FROM `User` WHERE `User`.`Team` = `Team`.`Id`) AS `NumberUser`, '. 74 '(SELECT `Name` FROM `User` WHERE `User`.`ID`=`Team`.`Leader`) AS `LeaderName` '. 75 'FROM `Team` WHERE 1'.$SearchQuery.$Order['SQL'].$PageList['SQLLimit']); 76 while($Team = $DbResult->fetch_assoc()) 77 { 78 $Output .= '<tr>'. 79 '<td><a href="?action=team&id='.$Team['Id'].'">'.$Team['Name'].'</a></td>'. 80 '<td><a href="http://'.$Team['URL'].'">'.$Team['URL'].'</a></td>'. 81 '<td><a href="'.$this->System->Link('/user.php?user='.$Team['Leader']).'">'.$Team['LeaderName'].'</a></td>'. 82 '<td><a href="'.$this->System->Link('/userlist.php?team='.$Team['Id']).'" title="Zobrazit členy týmu">'.$Team['NumberUser'].'</a></td>'. 83 '<td>'.HumanDate($Team['TimeCreate']).'</td>'; 84 if($this->System->User->Licence(LICENCE_USER)) 85 { 86 if($Team['Leader'] == $this->System->User->Id) $Action = ' <a href="?action=modify&id='.$Team['Id'].'">Upravit</a>'; 87 else $Action = ''; 88 if($Team['Id'] == $this->System->User->Team) $Action = ' <a href="?action=leave">Opustit</a>'; 89 $Output .= '<td><a href="?action=gointeam&id='.$Team['Id'].'">Vstoupit</a>'.$Action.'</td>'; 90 } 91 $Output .= '</tr>'; 92 } 93 $Output .= '</table>'. 94 $PageList['Output']; 95 96 return($Output); 97 } 98 99 function TeamJoin() 100 { 101 if($this->System->User->Licence(LICENCE_USER)) 102 { 103 if(array_key_exists('id', $_GET)) 104 { 105 $this->Database->query('UPDATE `User` SET `Team` = '.$_GET['id'].' WHERE `ID` = '.$this->System->User->Id); 106 $Output = ShowMessage('Vstoupil jsi do týmu.'); 107 $this->System->ModuleManager->Modules['Log']->WriteLog('Uživatel vstoupil do týmu '.$_GET['id'], LOG_TYPE_USER); 108 109 // Delete all teams without users 110 $this->Database->query('DELETE FROM `Team` WHERE (SELECT COUNT(*) FROM `User` WHERE `User`.`Team` = `Team`.`Id`) = 0'); 111 112 // Set new leader for teams where old leader went to other team 113 $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`);'); 114 115 $Output .= $this->ShowTeamList(); 116 } else $Output = ShowMessage('Nutno zadat id týmu.', MESSAGE_CRITICAL); 117 } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 118 return($Output); 119 } 120 121 function TeamCreateFinish() 122 { 123 $Output = ''; 124 if($this->System->User->Licence(LICENCE_USER)) 125 { 126 if(array_key_exists('Name', $_POST) and array_key_exists('Description', $_POST)) 127 { 128 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Team` WHERE `Name` = "'.trim($_POST['Name']).'"'); 129 $DbRow = $DbResult->fetch_row(); 130 $Count = $DbRow[0]; 131 if(($Count == 0) and ($_POST['Name'] != '')) 132 { 133 $this->Database->query('INSERT INTO `Team` (`Name` ,`Description`, `URL`, `TimeCreate`, `Leader`)'. 134 ' VALUES ("'.trim($_POST['Name']).'", "'.trim($_POST['Description']).'", "'. 135 $_POST['URL'].'", NOW(), '.$this->System->User->Id.')'); 136 $this->Database->query('UPDATE `User` SET `Team` = '.$this->Database->insert_id.' WHERE `ID` = '.$this->System->User->Id); 137 $Output .= ShowMessage('Překladatelský tým vytvořen.'); 138 $this->System->ModuleManager->Modules['Log']->WriteLog('Překladatelský tým vytvořen '.$_POST['Name'], LOG_TYPE_USER); 139 140 // Delete all teams without users 141 $this->Database->query('DELETE FROM `Team` WHERE (SELECT COUNT(*) FROM `User` WHERE `User`.`Team` = `Team`.`Id`) = 0'); 142 } else $Output .= ShowMessage('Již existuje tým se stejným jménem', MESSAGE_CRITICAL); 143 } else $Output .= ShowMessage('Chybí údaje formuláře', MESSAGE_CRITICAL); 144 } else $Output .= ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 145 $Output .= $this->ShowTeamList(); 146 return($Output); 147 } 148 149 function TeamModify() 150 { 151 if($this->System->User->Licence(LICENCE_USER)) 152 { 153 if(array_key_exists('id', $_GET)) 154 { 155 $DbResult = $this->Database->query('SELECT * FROM `Team` WHERE `Id`='.$_GET['id'].' AND `Leader`='.$this->System->User->Id); 156 if($DbResult->num_rows > 0) 157 { 158 $Team = $DbResult->fetch_assoc(); 159 $Output = '<form action="?action=finish_modify&id='.$_GET['id'].'" method="post">'. 160 '<fieldset><legend>Nastavení týmu</legend>'. 161 '<table><tr><td>Jméno:</td><td><input type="text" name="Name" value="'.$Team['Name'].'"/></td></tr>'. 162 '<tr><td>Webové stránky:</td><td>http://<input type="text" name="URL" value="'.$Team['URL'].'"/></td></tr>'. 163 '<tr><td>Popis:</td><td><input type="text" name="Description" value="'.$Team['Description'].'"/></td></tr>'. 164 '<tr><td colspan="2"><input type="submit" value="Uložit" /></td></tr>'. 165 '</table></fieldset></form>'; 166 } else $Output = ShowMesage('Tým nenalezen.', MESSAGE_CRITICAL); 167 } else $Output = ShowMessage('Nezadáno id týmu', MESSAGE_CRITICAL); 168 } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 169 return($Output); 170 } 171 172 function TeamModifyFinish() 173 { 174 $Output = ''; 175 if($this->System->User->Licence(LICENCE_USER)) 176 { 177 if(array_key_exists('id', $_GET) and array_key_exists('Name', $_POST) and array_key_exists('Description', $_POST) and array_key_exists('URL', $_POST)) 178 { 179 $DbResult = $this->Database->query('SELECT * FROM `Team` WHERE `Id`='.$_GET['id'].' AND `Leader`='.$this->System->User->Id); 180 if($DbResult->num_rows > 0) 181 { 182 $Team = $DbResult->fetch_assoc(); 183 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Team` WHERE `Name` = "'.trim($_POST['Name']).'"'); 184 $DbRow = $DbResult->fetch_row(); 185 $Count = $DbRow[0]; 186 if(($Count == 0) and ($_POST['Name'] != '')) 187 { 188 $this->Database->query('UPDATE `Team` SET `Name`="'.$_POST['Name'].'", `Description`="'.$_POST['Description'].'", `URL`="'.$_POST['URL'].'" WHERE Id='.$Team['Id']); 189 $Output .= ShowMessage('Nastavení týmu uloženo.'); 190 $this->System->ModuleManager->Modules['Log']->WriteLog('Překladatelský tým upraven '.$_POST['Name'], LOG_TYPE_USER); 191 } else $Output .= ShowMessage('Již existuje tým se stejným jménem.', MESSAGE_CRITICAL); 192 } else $Output .= ShowMessage('Tým nenalezen nebo nemáte oprávnění.', MESSAGE_CRITICAL); 193 } else $Output .= ShowMessage('Nezadáno id týmu nebo některé položky formuláře.', MESSAGE_CRITICAL); 194 } else $Output .= ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 195 $Output .= $this->ShowTeamList(); 196 return($Output); 197 } 198 199 function TeamCreate() 200 { 201 if($this->System->User->Licence(LICENCE_USER)) 202 { 203 $Output ='<form action="?action=finish_create" method="post">'. 204 '<fieldset><legend>Vytvoření nového týmu</legend>'. 205 '<table><tr><td>Jméno:</td><td><input type="text" name="Name" /></td></tr>'. 206 '<tr><td>Webové stránky:</td><td>http://<input type="text" name="URL" value=""/></td></tr>'. 207 '<tr><td>Popis:</td><td><input type="text" name="Description" /></td></tr>'. 208 '<tr><td colspan="2"><input type="submit" value="Vytvořit a vstoupit" /></td></tr>'. 209 '</table></fieldset></form>'; 210 } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 211 return($Output); 212 } 213 214 function TeamShow() 215 { 216 $Output = ''; 217 if(array_key_exists('id', $_GET) and is_numeric($_GET['id'])) 218 { 219 ImgLevelUpdate(); 220 221 $DbResult = $this->Database->query('SELECT `Id`, `Name`, `Description`, `URL`, `Leader`, '. 222 '(SELECT COUNT(*) FROM `User` WHERE '. 223 '`Team` = `Team`.`Id`) AS `NumberUser`, (SELECT SUM(`TranslatedCount`) FROM `User` WHERE '. 224 '`Team` = `Team`.`Id`) AS `NumberTranslate` FROM '. 225 '`Team` WHERE `Id`='.($_GET['id'] * 1)); 226 if($DbResult->num_rows > 0) 227 { 228 $Team = $DbResult->fetch_assoc(); 229 $DbResult2 = $this->Database->query('SELECT `Name`, `Id` FROM `User` WHERE `ID`='.$Team['Leader']); 230 if($DbResult2->num_rows > 0) 231 { 232 $Leader = $DbResult2->fetch_assoc(); 233 } else $Leader = array('Name' => '', 'Id' => 0); 234 235 $Output .='<strong>Překladatelský tým '.$Team['Name'].'</strong><br />'. 236 'Webové stránky: <a href="http://'.$Team['URL'].'">'.$Team['URL'].'</a><br/>'. 237 'Vedoucí: <a href="'.$this->System->Link('/user.php?user='.$Leader['Id']).'">'.$Leader['Name'].'</a><br/>'. 238 'Popis: '.$Team['Description'].'<br /><br />'; 239 //$Output .= '<a href="export/?team='.$Team['Id'].'">Exportovat překlad týmu</a> '; 240 if($this->System->User->Licence(LICENCE_USER)) 241 $Output .='<a href="?action=gointeam&id='.$Team['Id'].'">Vstoupit do týmu</a><br /><br />'; 242 $Output .='<fieldset><legend>Statistika</legend>'. 243 'Počet členů týmu: <a href="'.$this->System->Link('/userlist.php?team='.$Team['Id']).'" title="Zobrazit členy týmu">'.$Team['NumberUser'].'</a><br />'. 244 'Počet přeložených textů týmu: <strong>'.$Team['NumberTranslate'].'</strong><br />'. 245 'Průměrná úroveň překladatelů v týmu: <img src="'.$this->System->Link('/tmp/team/'.$Team['Name'].'/level.png').'" /><br /><br />'. 246 '<strong>Stav dokončení týmu pro verzi '.$this->System->Config['Web']['GameVersion'].'</strong><br />'; 247 248 $BuildNumber = GetBuildNumber($this->System->Config['Web']['GameVersion']); 249 250 $GroupListQuery = 'SELECT `Group`.* FROM `Group`'; 251 $Query = ''; 252 $DbResult = $this->Database->query($GroupListQuery); 253 if($DbResult->num_rows > 0) 254 { 255 while($DbRow = $DbResult->fetch_assoc()) 256 { 257 $Query .= 'SELECT (SELECT COUNT(DISTINCT(`Entry`)) FROM ('. 258 'SELECT `T`.`Entry` FROM `'.$DbRow['TablePrefix'].'` AS `T` '. 259 'WHERE (`User` IN (SELECT `ID` FROM `User` WHERE `Team` = '.$Team['Id'].')) '. 260 'AND (`Complete` = 1) AND (`T`.`Language`!='.$this->System->Config['OriginalLanguage'].') '. 261 'AND (`VersionStart` <= '.$BuildNumber.') AND (`VersionEnd` >= '.$BuildNumber.')'. 262 ') AS `C1`) AS `Translated`, '. 263 '(SELECT COUNT(DISTINCT(`Entry`)) FROM ('. 264 'SELECT `T`.`Entry` FROM `'.$DbRow['TablePrefix'].'` AS `T` '. 265 'WHERE (`Language` = '.$this->System->Config['OriginalLanguage'].') '. 266 'AND (`VersionStart` <= '.$BuildNumber.') AND (`VersionEnd` >= '.$BuildNumber.')'. 267 ') AS `C2`) AS `Total`, "'.$DbRow['Name'].'" AS `Name` UNION '; 268 } 269 $Query = substr($Query, 0, - 6); 270 271 $DbResult = $this->Database->query('SELECT COUNT(*) FROM ('.$GroupListQuery.') AS `T`'); 272 $DbRow = $DbResult->fetch_row(); 273 $PageList = GetPageList($DbRow[0]); 274 $Output .= $PageList['Output']; 275 276 $Output .='<table class="BaseTable">'; 277 $TableColumns = array( 278 array('Name' => 'Name', 'Title' => 'Jméno'), 279 array('Name' => 'Translated', 'Title' => 'Přeložených'), 280 array('Name' => 'Total', 'Title' => 'Anglických'), 281 array('Name' => 'Percent', 'Title' => 'Procenta'), 282 ); 283 284 $Order = GetOrderTableHeader($TableColumns, 'Name', 0); 285 $Output .= $Order['Output']; 286 287 $Translated = 0; 288 $Total = 0; 289 $DbResult = $this->Database->query('SELECT *, ROUND(`Translated` / `Total` * 100, 2) AS `Percent` FROM ('.$Query.') AS `C3` '.$Order['SQL'].$PageList['SQLLimit']); 290 while($Group = $DbResult->fetch_assoc()) 291 { 292 $Output .='<tr><td>'.$Group['Name'].'</td><td>'.$Group['Translated'].'</td><td>'.$Group['Total'].'</td><td>'.ProgressBar(150, $Group['Percent']).'</td></tr>'; 293 $Translated += $Group['Translated']; 294 $Total += $Group['Total']; 295 } 296 if($Total > 0) $Progress = round($Translated / $Total * 100, 2); 297 else $Progress = 0; 298 $Output .='<tr><td><strong>Celkem</strong></td><td><strong>'.$Translated.'</strong></td><td><strong>'.$Total.'</strong></td><td><strong>'.ProgressBar(150, $Progress).'</strong></td></tr>'; 299 $Output .='</table>'; 300 } 301 $Output .='</fieldset>'; 302 } else $Output .= ShowMessage('Tým nenalezen', MESSAGE_CRITICAL); 303 } else $Output .= ShowMessage('Musíte zadat id týmu', MESSAGE_CRITICAL); 304 return($Output); 305 } 306 307 function TeamLeave() 308 { 309 if($this->System->User->Licence(LICENCE_USER)) 310 { 311 $this->Database->query('UPDATE `User` SET `Team` = NULL WHERE `ID` = '.$this->System->User->Id); 312 $Output = ShowMessage('Nyní nejste členem žádného týmu.'); 313 $this->System->ModuleManager->Modules['Log']->WriteLog('Uživatel vystoupil z týmu', LOG_TYPE_USER); 314 315 // Delete all teams without users 316 $this->Database->query('DELETE FROM `Team` WHERE (SELECT COUNT(*) FROM `User` WHERE `User`.`Team` = `Team`.`Id`) = 0'); 317 318 // Set new leader for teams where old leader went to other team 319 $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`);'); 320 321 $Output .= $this->ShowTeamList(); 322 } else $Output = ShowMessage(T('Access denied'), MESSAGE_CRITICAL); 323 return($Output); 324 } 325 326 function Show() 327 { 328 if(array_key_exists('action', $_GET)) 329 { 330 if($_GET['action'] == 'gointeam') $Output = $this->TeamJoin(); 331 else if($_GET['action'] == 'finish_create') $Output = $this->TeamCreateFinish(); 332 else if($_GET['action'] == 'modify') $Output = $this->TeamModify(); 333 else if($_GET['action'] == 'finish_modify') $Output = $this->TeamModifyFinish(); 334 else if($_GET['action'] == 'create') $Output = $this->TeamCreate(); 335 else if($_GET['action'] == 'team') $Output = $this->TeamShow(); 336 else if($_GET['action'] == 'leave') $Output = $this->TeamLeave(); 337 else $Output = $this->ShowTeamList(); 338 } else $Output = $this->ShowTeamList(); 339 return($Output); 340 } 341 341 }
Note:
See TracChangeset
for help on using the changeset viewer.