source: trunk/Modules/Team/Team.php@ 838

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