source: branches/old/global.php

Last change on this file was 480, checked in by george, 16 years ago
  • Přesunuto: trunk do branches/old.
File size: 9.6 KB
Line 
1<?php
2
3session_start();
4include('config.php');
5include('database.php');
6include('error.php');
7$Database = new Database($Config['Database']['Host'], $Config['Database']['User'], $Config['Database']['Password'], $Config['Database']['Database']);
8$Database->Prefix = $Config['Database']['Prefix'];
9$Database->charset($Config['Database']['Charset']);
10
11$Menu = array(
12 array('index.php', 'Home', 'home'),
13 array('jak_zacit.php', 'Jak začít', 'how'),
14 array('registrace/', 'Registrace', 'registrace'),
15 array('minimanager/', 'Správa účtu', 'account'),
16 array('forum/', 'Diskusní fórum', 'forum'),
17 array('server.php', 'Server', 'server'),
18 array('finance/', 'Finance', 'donate'),
19 array('databaze/', 'Online databáze', 'database'),
20 array('download_soubory/', 'Soubory', 'download'),
21 array('link.php', 'Odkazy', 'link'),
22 array('mapa.php', 'Mapa', 'mapa'),
23 array('guildy.php', 'Seznam guild', 'guilds'),
24 array('online_player.php', 'Online hráči', 'online_player'),
25 array('honor.php', 'Tabulka cti', 'honor'),
26 array('events.php', 'Události', 'udalosti'),
27 array('arena.php', 'Arény', 'areny'),
28 //array('Death%20Dealers%20Hratelne%20Rasy.php', 'Rasy', 'rasy'),
29 //array('Death%20Dealers%20Povolani.php', 'Povolání', 'povolani'),
30 //array('Death%20Dealers%20Profese.php', 'Profese', 'profese'),
31);
32
33$UnitNames = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB');
34
35function HumanSize($Value)
36{
37 global $UnitNames;
38
39 $UnitIndex = 0;
40 while($Value > 1024)
41 {
42 $Value = round($Value / 1024, 3);
43 $UnitIndex++;
44 }
45 return($Value.' '.$UnitNames[$UnitIndex]);
46}
47
48function HumanDate($DateTime)
49{
50 $DateTimeParts = explode(' ', $DateTime);
51 $Parts = explode('-', $DateTimeParts[0]);
52 if($DateTimeParts[0] != '0000-00-00') return(($Parts[2]*1).'.'.($Parts[1]*1).'.'.$Parts[0]);
53 else return('&nbsp;');
54}
55
56function OnlinePlayerCount()
57{
58 global $Database, $Config;
59
60 $Database->select_db($Config['Mangos']['DatabaseCharacters']);
61 $Result = $Database->select('characters', 'COUNT(*)', 'online=1');
62 $Row = $Result->fetch_array();
63 return($Row[0]);
64}
65
66function CharacterCount()
67{
68 global $Database, $Config;
69 $Database->select_db($Config['Mangos']['DatabaseCharacters']);
70 $Result = $Database->select('characters', 'COUNT(*)');
71 $Row = $Result->fetch_array();
72 return($Row[0]);
73}
74
75function AccountCount()
76{
77 global $Database, $Config;
78 $Database->select_db($Config['Mangos']['DatabaseRealmd']);
79 $DbResult = $Database->query('SELECT COUNT(*) FROM account');
80 $Row = $DbResult->fetch_array();
81 return($Row[0]);
82}
83
84function MangosUptime()
85{
86 global $Database, $Config;
87 $Database->select_db($Config['Mangos']['DatabaseMangos']);
88 $DbResult = $Database->query('SELECT `starttime`, `uptime` FROM `uptime` ORDER BY `starttime` DESC LIMIT 1');
89 $Row = $DbResult->fetch_array();
90 $Uptime = $Row['uptime'];
91 //$Uptime = 0;
92 $Days = floor($Uptime / 3600 / 24);
93 if($Days == 0) $DaysText = '';
94 else if($Days == 1) $DaysText = $Days.' den';
95 else if(($Days > 1) and ($Days < 5)) $DaysText = $Days.' dny';
96 else if(($Days > 5)) $DaysText = $Days.' dnů';
97 $Seconds = $Uptime - 3600;
98 return($DaysText.' '.date('G:i', $Seconds));
99}
100
101function RunningEventCount()
102{
103 global $Database, $Config;
104 $Count = 0;
105 $Database->select_db($Config['Mangos']['DatabaseMangos']);
106 $DbResult = $Database->select('game_event', 'occurence, length, UNIX_TIMESTAMP(start_time) as start', 'end_time > NOW() AND start_time < NOW()');
107 while($Row = $DbResult->fetch_array())
108 {
109 $Start = (floor((time() - $Row['start']) / ($Row['occurence'] * 60))) * $Row['occurence'] * 60 + $Row['start'];
110 $End = $Start + $Row['length'] * 60;
111 if((time() > $Start) and (time() < $End)) $Count++;
112 }
113 return($Count);
114}
115
116function ShowOnlinePlayerCount()
117{
118 $PlayerCount = OnlinePlayerCount();
119 if($PlayerCount == 1) $P = 'hráč';
120 else if(($PlayerCount >= 2) and ($PlayerCount <= 4)) $P = 'hráči';
121 else $P = 'hráčů';
122 echo($PlayerCount.' '.$P);
123}
124
125function FormatOutput($s)
126{
127 $out = '';
128 $nn = 0;
129 $n = 0;
130 while($s!='')
131 {
132 $start = strpos($s,'<');
133 $end = strpos($s,'>');
134 if($start != 0)
135 {
136 $end = $start-1;
137 $start = 0;
138 }
139 $line = trim(substr($s,$start,$end+1));
140 if(strlen($line)>0)
141 if($line[0] == '<')
142 {
143 if($s[$start+1] == '/')
144 {
145 $n = $n - 2;
146 $nn = $n;
147 } else
148 {
149 if(strpos($line,' ')) $cmd = substr($line,1,strpos($line,' ')-1);
150 else $cmd = substr($line,1,strlen($line)-2);
151 //echo('['.$cmd.']');
152 if(strpos($s,'</'.$cmd.'>')) $n = $n + 2;
153 }
154 }// else $line = '['.$line.']';
155 //if($line != '') echo(htmlspecialchars(str_repeat(' ',$nn).$line."\n"));
156 if($line != '') $out .= (str_repeat(' ',$nn).$line."\n");
157 $s = substr($s,$end+1,strlen($s));
158 $nn = $n;
159 }
160 return($out);
161}
162
163function CheckPortStatus($Ip, $Port)
164{
165 function ErrorHandler($errno,$errmsg,$filename,$linenum,$vars)
166 {
167 }
168 set_error_handler('ErrorHandler');
169 //error_reporting(0);
170 if($Fp1 = fsockopen($Ip, $Port, $ERROR_NO, $ERROR_STR,(float)0.5))
171 {
172 fclose($Fp1);
173 return true;
174 } else
175 {
176 //echo($ERROR_NO.','.$ERROR_STR);
177 //die();
178 return false;
179 }
180 restore_error_handler();
181}
182
183function GenerateMenu()
184{
185 global $Config, $Menu;
186 $Result = '';
187 foreach($Menu as $Index => $MenuItem)
188 {
189 $Result .= "<a href=\"".$Config['Web']['BaseURL'].$MenuItem[0]."\" onMouseOver=\"swtch(&quot;".($Index*2+2)."&quot;,&quot;".$MenuItem[2]."&quot;)\" onMouseOut=\"swtch(&quot;".($Index*2+1)."&quot;,&quot;".$MenuItem[2]."&quot;)\"><IMG SRC=\"".$Config['Web']['BaseURL']."images/".$MenuItem[2].".jpg\" name=\"".$MenuItem[2]."\" alt=\"".$MenuItem[1]."\" border=\"0\"></A><br>\n";
190 }
191 return($Result);
192}
193
194function ShowHeader()
195{
196 global $Config;
197 echo('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
198<HTML>
199<HEAD>
200 <META http-equiv="Content-Language" content="cs">
201 <META http-equiv="Content-Type" content="text/html; charset='.$Config['Web']['Charset'].'">
202 <META HTTP-EQUIV="Expires" CONTENT="Mon, 06 Jan 1990 00:00:01 GMT">
203 <link rel="SHORTCUT ICON" href="images/favicon.ico">
204 <link rel="alternate" title="Hlavní aktuality" href="http://'.$_SERVER['SERVER_NAME'].$Config['Web']['BaseURL'].'rss.php" type="application/rss+xml">
205 <link rel="alternate" title="Finanční příspěvky" href="http://'.$_SERVER['SERVER_NAME'].$Config['Web']['BaseURL'].'finance/rss.php" type="application/rss+xml">
206 <TITLE>WoW server Heroes of Fantasy</TITLE>
207 <style type="text/css" media="screen">@import url('.$Config['Web']['BaseURL'].'css/style.css);</style>
208 <script language="JavaScript" type="text/javascript" src="'.$Config['Web']['BaseURL'].'css/global_js.php"></script>
209</HEAD>
210<BODY text="#cccccc">
211
212
213<TABLE cellspacing="0" cellpadding="0" align="center" class="TableHlavni" border="0">
214 <TR>
215 <TD id="BlankSpace">&nbsp;</td>
216 <TD rowspan="2" id="TdSloupec" valign="top">
217 <div class="Nadpis">Heroes of Fantasy</div>
218 <div class="DivText">');
219
220 ShowOnlinePlayerCount();
221
222
223echo('</div>');
224
225echo(GenerateMenu());
226
227echo('<A HREF="http://www.toplist.cz/" target="_blank"><IMG alt="pocitadlo"
228SRC="http://toplist.cz/count.asp?logo=mc&amp;ID=324802"
229border="0" width="0" height="0"></A>
230
231 </td>
232 </tr>
233 <tr><td id="LeftCell"><div class="pHlavni">');
234}
235
236function ShowFooter()
237{
238 global $Config;
239 echo('</div>
240 </td>
241 </tr>
242 <tr>
243 <td colspan="2">
244 <DIV class="DivPaticka">
245 <A href="'.$Config['Web']['BaseURL'].'administrace/" class="Paticka">#</A>
246 | Správce serveru: '.$Config['Web']['Admin'].' | Email: '.$Config['Web']['AdminEmail'].' | Počet přístupů: <a href="http://counter.cnw.cz/" targetr="_parent">
247 <img src="http://counter.cnw.cz/monika.cgi?wowzdechov&amp;7&amp;000000&amp;FFFFFF&amp;on" border="0" alt="CNW:Counter"></a>
248 <script type="text/javascript">
249 <!--
250 document.write("<A href=\"http://counter.cnw.cz\" target=\"_parent\"><IMG src=\"http://counter.cnw.cz/trackit.cgi?wowzdechov&t5&" + escape(top.document.referrer) + "\" alt=\"CNW:Tracker\" border=\"0\" width=\"1\" height=\"1\"></A>");
251 // -->
252 </script>
253 | Provozováno na <a href="http://game.zdechov.net/">game.zdechov.net</a> |');
254// Použitá paměť:  '.HumanSize(memory_get_peak_usage(FALSE)).' |
255echo(' </DIV>
256 </td>
257 </tr>
258 </TABLE>
259 </BODY>
260</HTML>
261');
262}
263
264// Zobrazení číselný seznamu stránek
265function PagesList($URL, $Page, $TotalCount, $CountPerPage, $Around = 10)
266{
267 $Count = ceil($TotalCount / $CountPerPage);
268 $Result = '';
269 if($Count > 1)
270 {
271 if($Page > 0)
272 {
273 $Result .= '<a href="'.$URL.'0">&lt;&lt;</a> ';
274 $Result .= '<a href="'.$URL.($Page-1).'">&lt;</a> ';
275 }
276 $PagesMax = $Count - 1;
277 $PagesMin = 0;
278 if($PagesMax > ($Page + $Around)) $PagesMax = $Page + $Around;
279 if($PagesMin < ($Page - $Around))
280 {
281 $Result.= ' .. ';
282 $PagesMin = $Page - $Around;
283 }
284 for($i = $PagesMin; $i <= $PagesMax; $i++)
285 {
286 if($i == $Page) $Result .= '<strong>';
287 $Result .= '<a href="'.$URL.$i.'">'.($i + 1).'</a> ';
288 if($i == $Page) $Result .= '</strong>';
289 }
290 if($PagesMax < ($Count - 1)) $Result .= ' .. ';
291 if($Page < ($Count - 1))
292 {
293 $Result .= '<a href="'.$URL.($Page + 1).'">&gt;</a> ';
294 $Result .= '<a href="'.$URL.($Count - 1).'">&gt;&gt;</a>';
295 }
296 }
297 return($Result);
298}
299
300?>
Note: See TracBrowser for help on using the repository browser.