source: trunk/www/Application/View/Server.php@ 73

Last change on this file since 73 was 73, checked in by george, 16 years ago
  • Upraveno: Přímé neHTML exporty přepracovány jako funkce Controlleru negenerující HTML, ale jiné datové formáty.
File size: 18.4 KB
Line 
1<?php
2
3class ServerView extends Module
4{
5 var $ItemFormClass = array(
6 'Title' => 'Nastavení',
7 'Table' => 'Server',
8 'SubmitText' => 'Uložit',
9 'Items' => array(
10 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => 'WoW server'),
11 'Description' => array('Type' => 'Text', 'Caption' => 'Popis', 'Default' => ''),
12 'Homepage' => array('Type' => 'Hyperlink', 'Caption' => 'Webové stránky', 'Default' => ''),
13 'Database' => array('Type' => 'Database', 'Caption' => 'Databáze', 'Default' => 0),
14 'ServerId' => array('Type' => 'Hidden', 'Caption' => 'Id', 'Default' => 0),
15 'TimeCreate' => array('Type' => 'DateTime', 'Caption' => 'Datum založení', 'Default' => 'NOW()'),
16 'NetworkPortRealmd' => array('Type' => 'Integer', 'Caption' => 'Port realmd', 'Default' => ''),
17 ),
18 );
19 var $ItemListFormClass = array(
20 'Title' => 'Server',
21 'Table' => '(SELECT `Client`.`Version`, `Server`.`Name`, `Server`.`Homepage`, `Server`.`Id`, `Server`.`NetworkPortRealmd`, `User`.`Name` AS `UserName`, Server.Online, Server.CharacterOnlineCount, Server.CharacterCount, Server.AccountCount FROM `Server` JOIN `User` ON `User`.`Id` = `Server`.`User` JOIN `Database` ON `Database`.`Id` = `Server`.`Database` JOIN `Emulator` ON `Emulator`.`Id` = `Database`.`Emulator` JOIN `Client` ON `Client`.`Id` = `Emulator`.`Client`)',
22 'Items' => array(
23 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
24 'NetworkPortRealmd' => array('Type' => 'Integer', 'Caption' => 'Realmlist', 'Default' => ''),
25 'Version' => array('Type' => 'Integer', 'Caption' => 'Verze', 'Default' => 0),
26 'Online' => array('Type' => 'OnlineState', 'Caption' => 'Stav', 'Default' => 0),
27 'CharacterOnlineCount' => array('Type' => 'Integer', 'Caption' => 'Hráčů online', 'Default' => 0),
28 'AccountCount' => array('Type' => 'Integer', 'Caption' => 'Účtů', 'Default' => 0),
29 'CharacterCount' => array('Type' => 'Integer', 'Caption' => 'Postav', 0),
30 'UserName' => array('Type' => 'String', 'Caption' => 'Správce', 'Default' => ''),
31 ),
32 );
33 var $CreateFormClass = array(
34 'Title' => 'Nový server',
35 'Table' => 'Server',
36 'SubmitText' => 'Registrovat',
37 'Items' => array(
38 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => 'WoW server'),
39 'Description' => array('Type' => 'Text', 'Caption' => 'Popis', 'Default' => ''),
40 'Homepage' => array('Type' => 'Hyperlink', 'Caption' => 'Webové stránky', 'Default' => ''),
41 //'Type' => array('Type' => 'ServerType', 'Caption' => 'Typ', 'Default' => 0),
42 'Database' => array('Type' => 'Database', 'Caption' => 'Databáze', 'Default' => 0),
43 //'Motd' => array('Type' => 'String', 'Caption' => 'Zpráva dne', 'Default' => 'Vítejte na free WoW serveru'),
44 ),
45 );
46 var $EditFormClass = array(
47 'Title' => 'Nastavení',
48 'Table' => 'Server',
49 'SubmitText' => 'Uložit',
50 'Items' => array(
51 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => 'WoW server'),
52 'Description' => array('Type' => 'Text', 'Caption' => 'Popis', 'Default' => ''),
53 'Homepage' => array('Type' => 'Hyperlink', 'Caption' => 'Webové stránky', 'Default' => ''),
54 //'Type' => array('Type' => 'ServerType', 'Caption' => 'Typ', 'Default' => 0),
55 'Database' => array('Type' => 'Database', 'Caption' => 'Databáze', 'Default' => 0),
56 //'Motd' => array('Type' => 'String', 'Caption' => 'Zpráva dne', 'Default' => 'Vítejte na free WoW serveru'),
57 'ServerId' => array('Type' => 'Hidden', 'Caption' => 'Id', 'Default' => 0),
58 //'TimeCreation' => array('Type' => 'DateTime', 'Caption' => 'Datum založení', 'Default' => 'NOW()'),
59 ),
60 );
61 var $GameAccountNewFormClass = array(
62 'Title' => 'Vytvoření nového herního účtu',
63 'Table' => '',
64 'Items' => array(
65 'Name' => array('Type' => 'String', 'Caption' => 'Přihlašovací jméno', 'Default' => ''),
66 'Password' => array('Type' => 'Password', 'Caption' => 'Heslo', 'Default' => ''),
67 'Password2' => array('Type' => 'Password', 'Caption' => 'Potvrzení hesla', 'Default' => ''),
68 'Email' => array('Type' => 'String', 'Caption' => 'E-mail', 'Default' => ''),
69 'Expansion' => array('Type' => 'ServerExpansion', 'Caption' => 'Rozšíření', 'Default' => 2),
70 'ServerId' => array('Type' => 'Hidden', 'Caption' => 'Id', 'Default' => 0),
71 ),
72 );
73
74 function ShowListOnRow($Row)
75 {
76 $Row['NetworkPortRealmd'] = '<a href="?Module=Server&amp;Action=RealmList&amp;Id='.$Row['Id'].'">'.$Row['NetworkPortRealmd'].'</a>';
77 if($Row['Homepage'] != '') $Row['Name'] = '<a href="'.$Row['Homepage'].'">'.$Row['Name'].'</a>';
78 unset($Row['Homepage']);
79 return($Row);
80 }
81
82 function ItemList()
83 {
84 global $Config;
85
86 $Output = '<h4>Seznam serverů</h4>';
87 $Table = new Table($this->ItemListFormClass);
88 if(array_key_exists('Filter', $_GET))
89 {
90 if($_GET['Filter'] == 'User')
91 $Table->Definition['Table'] = substr($Table->Definition['Table'], 0, -1).' WHERE User='.$this->System->Modules['User']->User['Id'].')';
92 }
93 $Table->OnRow = array($this, 'ShowListOnRow');
94 $Table->Definition['Items']['Id'] = array('Type' => 'Hidden', 'Caption' => '', 'Default' => '');
95 $Table->LoadValuesFromDatabase($this->Database);
96 $Table->Definition['Items']['Actions'] = array('Type' => 'String', 'Caption' => '', 'Default' => '');
97 foreach($Table->Values as $Index => $Item)
98 {
99 $Table->Values[$Index]['Actions'] = '<a href="?Module=Server&amp;Action=Show&amp;Id='.$Item['Id'].'">Podrobnosti</a>';
100 unset($Table->Values[$Index]['Id']);
101 }
102 $Output .= $Table->Show();
103 if($this->System->Modules['User']->User['Role'] >= USER_ROLE_USER)
104 {
105 $DbResult = $this->Database->query('SELECT COUNT(*) FROM Server');
106 $DbRow = $DbResult->fetch_row();
107 $ServerCount = $DbRow[0];
108 $DbResult = $this->Database->query('SELECT COUNT(*) FROM Server WHERE User='.$this->System->Modules['User']->User['Id']);
109 $DbRow = $DbResult->fetch_row();
110 if(($ServerCount < $Config['MaxServerCount']) and ($DbRow[0] < $Config['MaxServerCountPerUser']))
111 $Output .= '<br /><div style="text-align: center;"><a href="?Module=Server&amp;Action=Add">Vytvořit nový server</a></dev>';
112 }
113 return($Output);
114 }
115
116 function Item()
117 {
118 global $Config;
119
120 $Id = $_GET['Id'];
121 $Server = new Server($this->Database, $Id);
122 if(isset($Server->Server))
123 {
124 $Output = '<h4>Podrobnosti serveru</h4>';
125 $Form = new Form($this->System, $this->ItemFormClass);
126 $Form->LoadValuesFromDatabase($Id);
127 $Form->Definition['Items']['Realmlist'] = array('Type' => 'String', 'Caption' => 'Adresa k připojení', 'Default' => '');
128 $Form->Definition['Items']['Uptime'] = array('Type' => 'String', 'Caption' => 'Doba běhu', 'Default' => '');
129 $Form->Definition['Items']['UsedMemory'] = array('Type' => 'String', 'Caption' => 'Použitá paměť', 'Default' => '');
130 $Form->Definition['Items']['AccountCount'] = array('Type' => 'String', 'Caption' => 'Počet účtů', 'Default' => '');
131 $ServerStatus = $Server->GetState();
132 $Form->Values['Realmlist'] = $Config['Web']['Host'].':'.$Form->Values['NetworkPortRealmd'];
133 unset($Form->Definition['Items']['NetworkPortRealmd']);
134 $Form->Values['Uptime'] = $this->System->AddPrefixMultipliers($ServerStatus['Uptime'], '', 4, 'Time');
135 $Form->Values['UsedMemory'] = $this->System->AddPrefixMultipliers($ServerStatus['UsedMemory'] * 1024, 'B', 4, 'Binary');
136 $Form->Values['AccountCount'] = $ServerStatus['AccountCount'];
137 $Output .= $Form->ShowTable();
138 $Output .= '<div style="text-align: center">';
139 if((($this->System->Modules['User']->User['Role'] >= USER_ROLE_USER) and ($this->System->Modules['User']->User['Id'] == $Server->Server['User'])) or ($this->System->Modules['User']->User['Role'] >= USER_ROLE_ADMINISTRATOR))
140 {
141 $Output .= '<br /><a href="http://'.$this->System->Config['Web']['Host'].'/mysql/">Správa databáze</a> ';
142 if(array_key_exists('Id', $Server->Server['Database']) and ($Server->Server['Lock'] == 0))
143 {
144 if($ServerStatus['RealmdPortState'] == true) $Output .= ' <a href="?Action=ServerStop&amp;Id='.$Server->Id.'">Zastavit</a> <a href="?Module=Server&amp;Action=Restart&amp;Id='.$Server->Id.'">Restartovat</a>';
145 else $Output .= ' <a href="?Module=Server&amp;Action=Start&amp;Id='.$Server->Id.'">Spustit</a>';
146 }
147 if($Server->Server['Lock'] == 0)
148 {
149 $Output .= ' <a href="?Module=Server&amp;Action=Edit&amp;Id='.$Server->Id.'">Upravit základní nastavení</a>';
150 }
151 //$Output .= ' <a href="?Action=ServerDatabaseImport&amp;Id='.$Server->Id.'">Načtení čisté databáze</a>';
152 $Output .= ' <a href="?Module=Realm&amp;Action=Add&amp;Id='.$Server->Id.'">Vytvořit nový svět</a>';
153 $Output .= ' <a href="?Module=Realm&amp;Action=UpdateCharacters&amp;Id='.$Server->Id.'">Aktualizovat počty postav</a>';
154 }
155 $Output .= ' <a href="?Module=Server&amp;Action=GameAccountRegister&amp;Id='.$Server->Id.'">Vytvoření herního účtu</a>';
156 $Output .= '</div>';
157
158 // Show realmlist
159 $RealmView = new RealmView($this->System);
160 $Output .= $RealmView->ItemList();
161 } else $Output = $this->System->SystemMessage('Zobrazení serveru', 'Server se zadaným id nenalezen.');
162 return($Output);
163 }
164
165 function Add()
166 {
167 global $Config;
168
169 $Output = '';
170 if($this->System->Modules['User']->User['Role'] >= USER_ROLE_USER)
171 {
172 $DbResult = $this->Database->query('SELECT COUNT(*) FROM Server');
173 $DbRow = $DbResult->fetch_row();
174 $ServerCount = $DbRow[0];
175 if($ServerCount < $Config['MaxServerCount'])
176 {
177 $DbResult = $this->Database->query('SELECT COUNT(*) FROM Server WHERE User='.$this->System->Modules['User']->User['Id']);
178 $DbRow = $DbResult->fetch_row();
179 if($DbRow[0] >= $Config['MaxServerCountPerUser']) $Output .= $this->System->SystemMessage('Nový server', 'Na jeden účet lze vytvořit maximálně '.$Config['MaxServerCountPerUser'].' serverů');
180 else
181 {
182 $Form = new Form($this->System, $this->CreateFormClass);
183 $Form->LoadValuesFromForm();
184 $Form->OnSubmit = '?Action=ServerCreate';
185 $Output .= 'Tento formulář vám umožní si vytvořit nový server. Pečlivě vyplňte požadované údaje.';
186 $Output .= $Form->ShowEditForm();
187 }
188 } else $Output .= $this->System->SystemMessage('Nový server', 'Nelze vytvářet další servery');
189 } else $Output .= USER_BAD_ROLE;
190 return($Output);
191 }
192
193 function Create()
194 {
195 global $Config;
196
197 $Output = '';
198 if($this->System->Modules['User']->User['Role'] >= USER_ROLE_USER)
199 {
200 $DbResult = $this->Database->query('SELECT COUNT(*) FROM Server WHERE User='.$this->System->Modules['User']->User['Id']);
201 $DbRow = $DbResult->fetch_row();
202 if($DbRow[0] >= $Config['MaxServerCountPerUser']) $Output .= $this->System->SystemMessage('Nový server', 'Na jeden účet lze vytvořit maximálně '.$Config['MaxServerCountPerUser'].' serverů');
203 else
204 {
205 $DbResult = $this->Database->query('SELECT MAX(NetworkPortRealmd) FROM Server');
206 $DbRow = $DbResult->fetch_row();
207 $NewPortRealmd = $DbRow[0] + 1;
208 if($NewPortRealmd < $Config['BaseNetworkPortRealmd']) $NewPortRealmd = $Config['BaseNetworkPortRealmd'];
209
210 $Form = new Form($this->System, $this->CreateFormClass, array());
211 $Form->LoadValuesFromForm();
212 $this->Database->insert('Server', array('Name' => $Form->Values['Name'], 'Description' => $Form->Values['Description'], 'User' => $this->System->Modules['User']->User['Id'], 'Homepage' => $Form->Values['Homepage'], 'Database' => $Form->Values['Database'], 'NetworkPortRealmd' => $NewPortRealmd, 'Lock' => 1, 'TimeCreate' => 'NOW()'));
213 $LastInsertId = $this->Database->insert_id;
214 $Server = new Server($this->Database, $LastInsertId);
215 $Server->CreateDatabase();
216 $Output .= $this->System->SystemMessage('Vytvoření serveru', $Server->ImportDatabase(true));
217 $TaskView = new TaskView($this->System);
218 $Output .= $TaskView->ItemList();
219 //$UserOptions->LoadValuesFromDatabase($this->System->Modules['User']->User['Id']);
220 //$Form->OnSubmit = '?Action=ServerCreate';
221 //$Output .= $Form->ShowEditForm();
222 }
223 } else $Output .= USER_BAD_ROLE;
224 return($Output);
225 }
226
227 function Save()
228 {
229 $Output = '';
230 $Server = new Server($this->Database, $_POST['ServerId']);
231 if(($this->System->Modules['User']->User['Id'] == $Server->Server['User']) or ($this->System->Modules['User']->User['Role'] >= USER_ROLE_ADMINISTRATOR))
232 {
233 $Form = new Form($this->System, $this->EditFormClass, array());
234 $Form->LoadValuesFromForm();
235 $ServerId = $_POST['ServerId'];
236 unset($Form->Values['ServerId']);
237 $Output .= $this->System->SystemMessage('Upravit server', 'Nastavení serveru uloženo.');
238 $Form->SaveValuesToDatabase($_POST['ServerId']);
239 $Form->OnSubmit = '?Action=ServerSave';
240
241 $Server = new Server($this->Database, $_POST['ServerId']);
242 $Server->SaveConfiguration();
243 $Form->Values['ServerId'] = $ServerId;
244 $Output .= $Form->ShowEditForm();
245 } else $Output = $this->System->SystemMessage('Nastavení serveru', 'Nemáte oprávnění');
246 return($Output);
247 }
248
249 function Edit()
250 {
251 $Output = '';
252 $Server = new Server($this->Database, $_GET['Id']);
253 if(($this->System->Modules['User']->User['Id'] == $Server->Server['User']) or ($this->System->Modules['User']->User['Role'] >= USER_ROLE_ADMINISTRATOR))
254 {
255 $Form = new Form($this->System, $this->EditFormClass);
256 $Form->LoadValuesFromDatabase($_GET['Id']);
257 $Form->Values['ServerId'] = $_GET['Id'];
258 $Form->OnSubmit = '?Action=ServerSave';
259 $Output .= $Form->ShowEditForm();
260 } else $Output = $this->System->SystemMessage('Nastavení serveru', 'Nemáte oprávnění');
261 return($Output);
262 }
263
264 function Start()
265 {
266 $Output = '';
267 if($this->System->Modules['User']->User['Role'] >= USER_ROLE_USER)
268 {
269 $Server = new Server($this->Database, $_GET['Id']);
270 if(($this->System->Modules['User']->User['Id'] == $Server->Server['User']) or ($this->System->Modules['User']->User['Role'] >= USER_ROLE_ADMINISTRATOR))
271 {
272 $Output .= $this->System->SystemMessage('Spuštění serveru', $Server->Start());
273 $TaskView = new TaskView($this->System);
274 $Output .= $TaskView->ItemList();;
275 } else $this->System->SystemMessage('Spuštění serveru', 'Nemáte oprávnění');
276 } else $Output .= USER_BAD_ROLE;
277 return($Output);
278 }
279
280 function Stop()
281 {
282 $Output = '';
283 if($this->System->Modules['User']->User['Role'] >= USER_ROLE_USER)
284 {
285 $Server = new Server($this->Database, $_GET['Id']);
286 if(($this->System->Modules['User']->User['Id'] == $Server->Server['User']) or ($this->System->Modules['User']->User['Role'] >= USER_ROLE_ADMINISTRATOR))
287 {
288 $Output .= $this->System->SystemMessage('Zastavení serveru', $Server->Stop());
289 $TaskView = new TaskView($this->System);
290 $Output .= $TaskView->ItemList();;
291 } else $this->System->SystemMessage('Zastavení serveru', 'Nemáte oprávnění');
292 } else $Output .= USER_BAD_ROLE;
293 return($Output);
294 }
295
296 function AccountCreate()
297 {
298 $Form = new Form($this->System, $this->GameAccountNewFormClass);
299 $Form->LoadValuesFromForm();
300 $Form->Values['ServerId'] = $_GET['Id'];
301 $Form->OnSubmit = '?Module=Server&amp;Action=GameAccountRegisterFinish';
302 $Output = $Form->ShowEditForm();
303 return($Output);
304 }
305
306 function AccountCreateFinish()
307 {
308 $Form = new Form($this->System, $this->GameAccountNewFormClass);
309 $Form->LoadValuesFromForm();
310 $Server = new Server($this->Database, $Form->Values['ServerId']);
311 $Output = $this->System->SystemMessage('Vytvoření herního účtu', $Server->NewAccount($Form->Values['Name'], $Form->Values['Password'], $Form->Values['Password2'], $Form->Values['Email'], $Form->Values['Expansion']));
312 $Output .= '<a href="?Module=Server&amp;Action=GameAccountRegister&amp;Id='.$Form->Values['ServerId'].'">Zpět k zadání údajů</a>';
313 return($Output);
314 }
315
316 function RealmListFile()
317 {
318 if(array_key_exists('Id', $_GET))
319 {
320 Header('Content-Type: text/plain');
321 Header('Content-Disposition: attachment; filename="realmlist.wtf"');
322 $Server = new Server($this->Database, $_GET['Id']);
323 $Output = array(
324 'set realmlist '.$this->Config['Web']['Host'].':'.$Server->Server['NetworkPortRealmd'],
325 'set patchlist '.$this->Config['Web']['Host'].':'.$Server->Server['NetworkPortRealmd'],
326 'set portal eu',
327 );
328 echo(implode("\n", $Output));
329 } else echo('Musíte zadat Id serveru');
330 }
331
332 function PatchList()
333 {
334 Header('Content-type: text/plain');
335 if(array_key_exists('Id', $_GET))
336 {
337 $Server = new Server($this->Database, $_GET['Id'] * 1);
338 echo($Server->GetPatchList());
339 } else echo('Zadané id serveru nenalezeno.');
340 }
341
342 function XMLExport()
343 {
344 Header('Content-Type: application/xml');
345
346 $Output = '<?xml version="1.0" encoding="utf-8"?>';
347 if(array_key_exists('File', $_GET))
348 {
349 Header('Content-Disposition: filename="'.$_GET['File'].'.xml"');
350 if($_GET['File'] == 'ServerList')
351 {
352 $Output .= '<serverlist version="1.0">';
353 $DbResult = $this->Database->query('SELECT * FROM Server');
354 while($Server = $DbResult->fetch_assoc())
355 {
356 $Output .= '<server>'.
357 '<name>'.$Server['Name'].'</name>'.
358 //'<playermaxcount>'.$Server['PlayerMaxCount'].'</playermaxcount>'.
359 //'<playeronlinecount>'.$Server['PlayerOnlineCount'].'</playeronlinecount>'.
360 '<homepage>'.$Server['Homepage'].'</homepage>'.
361 '</server>';
362 }
363 $Output .= '</serverlist>';
364 }
365 } else $Output .= '<document/>';
366 $Html = new Html();
367 if($this->Config['Web']['FormatHTML'] == true) echo($Html->FormatOutput($Output));
368 else echo($Output);
369 }
370}
371
372?>
Note: See TracBrowser for help on using the repository browser.