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

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