source: trunk/includes/global.php@ 295

Last change on this file since 295 was 295, checked in by george, 15 years ago
  • Upraveno: Volby pro administraci systému přesunuty z menu do samostatné stránky admin.php.
  • Opraveno: Použití výchozího směru řazení u tabulek.
File size: 14.9 KB
Line 
1<?php
2
3$ScriptStartTime = GetMicrotime();
4
5if(isset($_SERVER['REMOTE_ADDR'])) session_start();
6
7// SQL injection hack protection
8foreach($_POST as $Index => $Item)
9{
10 if(is_array($_POST[$Index]))
11 foreach($_POST[$Index] as $Index2 => $Item2) $_POST[$Index][$Index2] = addslashes($Item2);
12 else $_POST[$Index] = addslashes($_POST[$Index]);
13}
14foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($_GET[$Index]);
15
16include('config.php');
17include('error.php');
18include('databaseconection.php');
19include('global_function.php');
20include('rss.php');
21include_once('system.php');
22
23$Database = new Database($Config['Database']['Host'], $Config['Database']['User'], $Config['Database']['Password']);
24$Database->SQLCommand('SET NAMES '.$Config['Database']['Charset']);
25$Database->SelectDatabase($Config['Database']['Database']);
26
27$TranslationTree = GetTranslationTree();
28$LanguageList = GetLanguageList();
29
30$System = new System();
31$System->Init();
32
33function GetMicrotime()
34{
35 list($Usec, $Sec) = explode(' ', microtime());
36 return ((float)$Usec + (float)$Sec);
37}
38
39function ShowShoutbox()
40{
41 global $Database;
42
43 echo('<strong>Shoutbox:</strong>');
44 if(Licence(LICENCE_USER)) echo(' <a href="action.php?action=shoutbox">Vložit</a>');
45 echo('<div class="box"><table>');
46 $ID = $Database->SQLCommand('SELECT * FROM shoutbox ORDER BY ID DESC LIMIT 20');
47 while($Line = mysql_fetch_assoc($ID))
48 echo('<tr><td><strong>'.$Line['user'].'</strong>: '.htmlspecialchars($Line['text']).'</td></tr>');
49 echo('</table></div>');
50}
51
52function ShowTopBar()
53{
54 global $Config, $Database;
55
56 echo('<div class="Menu">');
57 echo('<span class="MenuItem"></span>');
58 if(Licence(LICENCE_USER))
59 {
60 $DbResult = $Database->SQLCommand('SELECT team, user FROM `user` WHERE ID='.$_SESSION['UserID']);
61 $User = mysql_fetch_assoc($DbResult);
62 $DbResult = $Database->SQLCommand('SELECT ID, name FROM `team` WHERE ID='.$User['team']);
63 $Team = mysql_fetch_assoc($DbResult);
64
65 //echo('<span class="MenuItem">Moje překlady: <a href="">Dokončené</a> <a href="">Rozpracované</a> <a href="">Exporty</a> Tým: <a href="">'.$Team['name'].'</a></span>');
66 echo('<span class="MenuItem2">'.$User['user'].' <a href="'.$Config['Web']['BaseURL'].'?Logout">Odhlášení</a> <a href="'.$Config['Web']['BaseURL'].'Options.php">Nastavení</a></span>');
67 } else
68 {
69 echo('<span class="MenuItem2"><form action="" method="post"> Jméno: <input type="text" name="LoginUser" size="8 " /> Heslo: <td><input type="password" name="LoginPass" size="8" /> <input type="submit" value="Přihlásit" /></form> &nbsp; <a href="'.$Config['Web']['BaseURL'].'registrace.php">Registrace</a></span>');
70 }
71 echo('</div>');
72}
73
74function ShowLoginBox()
75{
76 if(Licence(LICENCE_USER))
77 {
78 // echo 'Jste přihlášen jako: <b>'.$_SESSION['User'].'</b> <a href="index.php?Logout">Odhlásit</a>';
79 } else
80 {
81 echo('<strong>Přihlášení:</strong>
82 <form action="" method="post">
83 <table>
84 <tr>
85 <td><input type="text" name="LoginUser" size="13" /></td>
86 </tr>
87 <tr>
88 <td><input type="password" name="LoginPass" size="13" /></td>
89 </tr>
90 <tr>
91 <th><input type="submit" value="Přihlásit" /></th>
92 </tr>
93 </table>
94 </form>');
95 }
96}
97
98function ShowSearchBox()
99{
100 global $Config;
101
102 echo('<strong>Hledání:</strong>'.
103 '<form action="'.$Config['Web']['BaseURL'].'action.php" method="get"><div>'.
104 '<input type="hidden" name="action" value="search" />'.
105 '<table>'.
106 '<tr>'.
107 '<td><input type="text" name="search" size="13" /></td>'.
108 '</tr>'.
109 '<tr>'.
110 '<th><input type="submit" value="Hledat" /></th>'.
111 '</tr>'.
112 '</table></div>'.
113 '</form>');
114}
115
116function ShowMainMenu()
117{
118 global $TranslationTree, $Config;
119
120 $Menu = array
121 (
122 $Config['Web']['BaseURL'].'index.php' => array(LICENCE_ANONYMOUS, 'Hlavní stránka', 'Domů'),
123 'http://wow.zdechov.net/forum/viewforum.php?f=22' => array(LICENCE_ANONYMOUS, 'Diskuze na téma překládání', 'Fórum projektu'),
124 $Config['Web']['BaseURL'].'dictionary.php' => array(LICENCE_ANONYMOUS, 'Slovník WoW výrazů', 'Slovníček'),
125 $Config['Web']['BaseURL'].'statistic.php' => array(LICENCE_ANONYMOUS, 'Stav dokončení překládů', 'Stav dokončení'),
126 $Config['Web']['BaseURL'].'userlist.php?action=nofilter' => array(LICENCE_ANONYMOUS, 'Seznam registrovaných uživatelů', 'Překladatelé'),
127 $Config['Web']['BaseURL'].'team.php?search=' => array(LICENCE_ANONYMOUS, 'Seznam překladatelských týmů', 'Týmy'),
128 $Config['Web']['BaseURL'].'export/' => array(LICENCE_ANONYMOUS, 'Zde si můžete stáhnout přeložené texty', 'Exporty'),
129 $Config['Web']['BaseURL'].'download.php' => array(LICENCE_ANONYMOUS, 'Stahování různých pomocných souborů a programů', 'Soubory'),
130 $Config['Web']['BaseURL'].'info.php' => array(LICENCE_ANONYMOUS, 'Informace k překladu hry', 'Informace'),
131 $Config['Web']['BaseURL'].'TranslationList.php?action=grouplist' => array(LICENCE_ANONYMOUS, 'Informace o překladových skupinách', 'Zdroje dat'),
132 $Config['Web']['BaseURL'].'banners.php' => array(LICENCE_ANONYMOUS, 'Informace k propagaci tohoto projektu', 'Propagace'),
133 $Config['Web']['BaseURL'].'version.php' => array(LICENCE_ANONYMOUS, 'Seznam verzí herního klienta', 'Verze hry'),
134 $Config['Web']['BaseURL'].'aowow' => array(LICENCE_ANONYMOUS, 'Vyhledávací databáze podobná WoWHead s překlady', 'AoWoW'),
135 $Config['Web']['BaseURL'].'server.php' => array(LICENCE_ANONYMOUS, 'Pomocný WoW server pro překladatele', 'Test server'),
136'http://embed.mibbit.com/?server=game.zdechov.net%3A6667&amp;channel=%23wowpreklad&amp;forcePrompt=true&amp;charset=utf-8' => array(LICENCE_ANONYMOUS, 'IRC chat pro překladatele', 'Chat'),
137 $Config['Web']['BaseURL'].'admin.php' => array(LICENCE_ADMIN, 'Volby pro správu', 'Administrace'),
138 );
139
140 echo('<strong>Hlavní menu:</strong>'.
141 '<div class="verticalmenu"><ul>');
142
143 foreach($Menu as $MenuTarget => $MenuItem)
144 {
145 if(isset($MenuItem[3])) $OnClick = ' onclick="'.$MenuItem[3].'"'; else $OnClick = '';
146 if(Licence($MenuItem[0])) echo('<li><a class="verticalmenua" title="'.$MenuItem[1].'" href="'.$MenuTarget.'"'.$OnClick.'>'.$MenuItem[2].'</a></li>');
147 }
148 echo('</ul></div>');
149}
150
151function ShowTranslatedMenu()
152{
153 global $TranslationTree, $Config, $Database;
154
155 echo('<strong>Překladové skupiny:</strong><br /><div id="TranslationMenu">');
156 if(Licence(LICENCE_USER))
157 {
158 echo ('<a title="Všechny překlady, které jste přeložil" href="'.$Config['Web']['BaseURL'].'TranslationList.php?user='.$_SESSION['UserID'].'&amp;action=userall">Všechny moje texty</a><br />');
159 echo ('<a title="Všechny překlady, které jste rozepsal a nedokončil" href="'.$Config['Web']['BaseURL'].'TranslationList.php?user='.$_SESSION['UserID'].'&amp;not&amp;action=userall">Rozpracované texty</a>');
160 //TODO: počet nedokončených
161 echo ('<br /><br />');
162 }
163 foreach($TranslationTree as $Group)
164 {
165 echo('<div id="menuitem-group'.$Group['Id'].'" onmousemove="show(\'group'.$Group['Id'].'\')" onmouseout="hide(\'group'.$Group['Id'].'\')">
166 <a href="'.$Config['Web']['BaseURL'].'TranslationList.php?group='.$Group['Id'].'&amp;action=filter">'.$Group['Name'].'</a></div>
167 <div id="group'.$Group['Id'].'" class="hidden-menu-item" onmousemove="show(\'group'.$Group['Id'].'\')" onmouseout="hide(\'group'.$Group['Id'].'\')">');
168 echo('&nbsp;<a title="Zde můžete začít překládat" href="'.$Config['Web']['BaseURL'].'TranslationList.php?group='.$Group['Id'].'&amp;action=notran">Nepřeložené</a><br />
169 &nbsp;<a title="Přeložené texty, můžete zde hlasovat, nebo opravovat překlady" href="'.$Config['Web']['BaseURL'].'TranslationList.php?group='.$Group['Id'].'&amp;action=Translate">Přeložené</a><br />');
170 $ID = $Database->SQLCommand('SELECT * FROM connexion WHERE `Group` = '.$Group['Id']);
171 if (mysql_num_rows($ID) > 0)
172 echo('&nbsp;<a title="Vypsání souvislostí" href="'.$Config['Web']['BaseURL'].'TranslationList.php?group='.$Group['Id'].'&amp;action=connexion_list">Souvislosti</a><br />');
173
174 if(Licence(LICENCE_USER))
175 {
176 echo('&nbsp;<a title="Nedokončené překlady" href="'.$Config['Web']['BaseURL'].'TranslationList.php?group='.$Group['Id'].'&amp;action=mydevelop">Rozepsané</a><br />
177 &nbsp;<a title="Všechny překlady, které jste přeložil" href="'.$Config['Web']['BaseURL'].'TranslationList.php?group='.$Group['Id'].'&amp;action=my">Vlastní</a><br />');
178 }
179 echo('&nbsp;<a title="Sestavit speciální filtr" href="'.$Config['Web']['BaseURL'].'TranslationList.php?group='.$Group['Id'].'&amp;action=filter">Filtr</a><br />');
180 echo('</div>');
181 }
182 echo ('</div>');
183}
184
185function ShowOnlineUserList()
186{
187 global $Database, $Moderators;
188
189 echo('Online překladatelé:<br />');
190 $ID = $Database->SQLCommand('SELECT user, GM, ID FROM `user` WHERE LastLogin >= Now() - 300 AND ((LastLogout < LastLogin) OR (ISNULL(LastLogout)))');
191 while ($Line = mysql_fetch_assoc($ID))
192 {
193 if(Licence(LICENCE_MODERATOR)) $Name = '<a href="user.php?user='.$Line['ID'].'">'.$Line['user'].'</a>';
194 else $Name = $Line['user'];
195 //if($Line['GM'] <> 0) $TextGM = '<small>('.$Moderators[$Line['GM']].')</small>';
196 //else
197 $TextGM = '';
198 echo('<strong>'.$Name.'</strong>'.$TextGM.'<br />');
199 }
200}
201
202function ShowPage()
203{
204 global $Config, $Database, $RSSChannels, $PageFooterRequested;
205
206 echo('<?xml version="1.0" encoding="'.$Config['Web']['Charset'].'"?>
207 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
208<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs">'.
209'<head>'.
210'<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />'.
211'<meta name="keywords" content="wow, quest, questy, questů, preklad, mangos, překlad, překládání, přeložený, přeložení, čeština, world of warcraft, open source, free, addon" />'.
212'<meta name="description" content="Projekt překládání textů hry World of Warcraft" />'.
213'<meta name="robots" content="all" />'.
214'<link rel="stylesheet" href="'.$Config['Web']['BaseURL'].'style/style.css" type="text/css" media="all" />'.
215'<script type="text/javascript" src="'.$Config['Web']['BaseURL'].'style/global.js"></script>'.
216'<link rel="SHORTCUT ICON" href="'.$Config['Web']['BaseURL'].'images/favicon.ico" />');
217 if(isset($RSSChannels))
218 foreach($RSSChannels as $Channel)
219 echo(' <link rel="alternate" title="'.$Channel['Title'].'" href="'.$Channel['URL'].'" type="application/rss+xml" />');
220 echo('<title>Projekt překládání textů WoW</title>
221</head>
222<body>
223<table id="bannertable"><tr>
224 <td id="banner1"></td>
225 <td id="banner"><div id="bannertitle">Projekt překládání textů WoW</div></td>
226 <td id="banner2"></td></tr>
227</table>');
228
229 if(!array_key_exists('UserID', $_SESSION)) $_SESSION['UserID'] = '';
230 if(!array_key_exists('User', $_SESSION)) $_SESSION['User'] = 'NotRegistred';
231 if(!array_key_exists('Pass', $_SESSION)) $_SESSION['Pass'] = '';
232
233
234 // Odhlášení
235 if(array_key_exists('Logout', $_GET))
236 {
237 WriteLog('Odhlášení', 3);
238 if(is_numeric($_SESSION['UserID']))
239 $Database->SQLCommand('UPDATE user SET LastLogout = NOW() WHERE ID = '.$_SESSION['UserID']);
240 $_SESSION['User'] = '';
241 $_SESSION['Pass'] = '';
242 $_SESSION['UserID'] = '';
243 }
244
245 // Přihlášení
246 if(array_key_exists('LoginUser', $_POST))
247 {
248 $_SESSION['User'] = $_POST['LoginUser'];
249 $_SESSION['Pass'] = $_POST['LoginPass'];
250
251 $Line = mysql_fetch_array($Database->SQLCommand('SELECT * FROM user WHERE LOWER(user) = LOWER("'.$_SESSION['User'].'") AND pass = sha1("'.$_SESSION['Pass'].'")'));
252 if(!$Line)
253 {
254 echo('<script> alert("Jméno nebo heslo bylo zadáno špatně!"); </script>');
255 $_SESSION['UserID'] = '';
256 $_SESSION['User'] = '';
257 $_SESSION['Pass'] = '';
258 } else
259 {
260 $_SESSION['UserID'] = $Line['ID'];
261 $_SESSION['User'] = $Line['user'];
262 WriteLog('Login: '.$_SESSION['User'], 3);
263 }
264 }
265
266 //záznam o aktivitě
267 if(Licence(0) and array_key_exists('REMOTE_ADDR', $_SERVER))
268 $Database->SQLCommand('UPDATE user SET LastIP = "'.$_SERVER['REMOTE_ADDR'].'", LastLogin = NOW() WHERE ID = '.$_SESSION['UserID']);
269
270 ShowTopBar();
271
272 echo('<table class="page"><tr><td class="menu">');
273 ShowMainMenu();
274
275 // echo('<br />');
276 //ShowLoginBox();
277 //echo('<br />');
278 ShowOnlineUserList();
279 echo('<br />');
280 ShowSearchBox();
281 echo('</td><td id="border-left"></td><td class="content">');
282 $PageFooterRequested = true;
283}
284
285$UnitNames = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB');
286
287function HumanSize($Value)
288{
289 global $UnitNames;
290
291 $UnitIndex = 0;
292 while($Value > 1024)
293 {
294 $Value = round($Value / 1024, 3);
295 $UnitIndex++;
296 }
297 return($Value.' '.$UnitNames[$UnitIndex]);
298}
299
300function ShowFooter()
301{
302 global $Database, $Config, $ScriptStartTime, $PageFooterRequested;
303
304 if(isset($PageFooterRequested))
305 {
306 $ScriptGenerateDuration = round(GetMicrotime() - $ScriptStartTime, 2);
307
308 echo('</td>');
309 echo('<td class="menu2">');
310 ShowTranslatedMenu();
311 echo('<br />');
312 ShowShoutBox();
313 echo('</td>'.
314 '</tr><tr>'.
315 '<td colspan="4" class="page-bottom">Autoři: maron, chronos &nbsp; <a href="http://wowpreklad.zdechov.net/trac/wowpreklad/browser/trunk">Zdrojové soubory</a> &nbsp; '.
316 '<a href="http://wowpreklad.zdechov.net/trac/wowpreklad/log/trunk?verbose=on">Novinky</a> &nbsp; '.
317 '<a href="http://counter.cnw.cz/"><img src="http://counter.cnw.cz/monika.cgi?wowpreklad&amp;5&amp;000000&amp;FFFFFF&amp;on" alt="CNW:Counter" /></a>
318 <script type="text/javascript">
319 <!--
320 document.write("<a href=\"http://counter.cnw.cz\" target=\"_parent\"><img src=\"http://counter.cnw.cz/trackit.cgi?wowpreklad&t3&" + escape(top.document.referrer) + "\" alt=\"CNW:Tracker\" border=\"0\" width=\"1\" height=\"1\"><\/a>");
321 // -->
322 </script>');
323
324 echo('</td></tr>');
325 if($Config['Web']['ShowRuntimeInfo'] == true) echo('<tr><td colspan="3" style="text-align: center;">Doba generování: '.$ScriptGenerateDuration.' s / '.ini_get('max_execution_time').' s &nbsp;&nbsp; Použitá paměť: '.HumanSize(memory_get_peak_usage(FALSE)).' / '.ini_get('memory_limit').'B</td></tr>');
326 echo('</table>'.
327 '</body>'.
328 '</html>');
329 $Database->Disconnect();
330 }
331}
332
333function GetQueryStringArray($QueryString)
334{
335 $Result = array();
336 $Parts = explode('&', $QueryString);
337 foreach($Parts as $Part)
338 {
339 if($Part != '')
340 {
341 if(!strpos($Part, '=')) $Part .= '=';
342 $Item = explode('=', $Part);
343 $Result[$Item[0]] = $Item[1];
344 }
345 }
346 return($Result);
347}
348
349function SetQueryStringArray($QueryStringArray)
350{
351 $Parts = array();
352 foreach($QueryStringArray as $Index => $Item)
353 {
354 $Parts[] = $Index.'='.$Item;
355 }
356 return(implode('&', $Parts));
357}
358
359?>
Note: See TracBrowser for help on using the repository browser.