Changeset 506 for trunk/includes/global.php
- Timestamp:
- Feb 14, 2013, 9:02:05 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/global.php
r505 r506 14 14 foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($_GET[$Index]); 15 15 16 include_once(dirname(__FILE__).'/global_function.php');17 16 if(file_exists(dirname(__FILE__).'/config.php')) include_once(dirname(__FILE__).'/config.php'); 18 17 else die('Nenalezen konfigurační soubor config.php ve složce includes. '. … … 23 22 include_once(dirname(__FILE__).'/system.php'); 24 23 include_once(dirname(__FILE__).'/user.php'); 24 include_once(dirname(__FILE__).'/Page.php'); 25 25 26 26 $System = new System(); … … 31 31 32 32 $TranslationTree = GetTranslationTree(); 33 $LanguageList = GetLanguageList();34 33 35 34 LogReferrer(); … … 47 46 } 48 47 49 function ShowShoutbox()50 {51 global $System, $Config, $User, $System;52 53 $Output = '<strong><a href="'.$System->Link('/action.php?action=ShoutBoxView').'">Kecátko:</a></strong>';54 if($User->Licence(LICENCE_USER))55 $Output .= ' <a href="'.$System->Link('/action.php?action=shoutbox').'">Vložit</a>';56 $Output .= '<div class="box"><table>';57 $DbResult = $System->Database->query('SELECT * FROM `ShoutBox` ORDER BY `ID` DESC LIMIT 30');58 while($Line = $DbResult->fetch_assoc())59 $Output .= '<tr><td><strong>'.$Line['UserName'].'</strong>: '.MakeActiveLinks($Line['Text']).'</td></tr>';60 $Output .= '</table></div>';61 return($Output);62 }63 64 function ShowTopBar()65 {66 global $Config, $System, $User, $System;67 68 $Output = '<div class="Menu">';69 $Output .= '<span class="MenuItem"></span>';70 if($User->Licence(LICENCE_USER))71 {72 //$DbResult = $System->Database->query('SELECT `Id`, `Name` FROM `Team` WHERE `Id`='.$User->Team);73 //$Team = $DbResult->fetch_assoc();74 //$Output .= ''<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>';75 $Output .= '<span class="MenuItem2">'.$User->Name.' <a href="'.$System->Link('/?action=logout').'">Odhlášení</a> <a href="'.$System->Link('/Options.php').'">Nastavení</a>'.76 ' <a title="Vámi přeložené texty" href="'.$System->Link('/TranslationList.php?user='.$User->Id.'&group=0&state=2&text=&entry=').'">Přeložené</a>'.77 ' <a title="Vaše rozpracované text" href="'.$System->Link('/TranslationList.php?user='.$User->Id.'&group=0&state=3&text=&entry=').'">Rozpracované</a>'.78 ' <a title="Nikým nepřeložené texty" href="'.$System->Link('/TranslationList.php?user=0&group=0&state=1&text=&entry=').'">Nepřeložené</a>'.79 '</span>';80 } else81 {82 $Output .= '<span class="MenuItem2"><form action="'.$System->Link('/?action=login').'" 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> <a href="'.$System->Link('/registrace.php').'">Registrace</a></span>';83 }84 $Output .= '</div>';85 return($Output);86 }87 88 function ShowLoginBox()89 {90 global $User;91 92 $Output = '';93 if($User->Licence(LICENCE_USER))94 {95 // $Output .= 'Jste přihlášen jako: <b>'.$User->Id.'</b> <a href="index.php?Logout">Odhlásit</a>';96 } else97 {98 $Output .= '<strong>Přihlášení:</strong>99 <form action="" method="post">100 <table>101 <tr>102 <td><input type="text" name="LoginUser" size="13" /></td>103 </tr>104 <tr>105 <td><input type="password" name="LoginPass" size="13" /></td>106 </tr>107 <tr>108 <th><input type="submit" value="Přihlásit" /></th>109 </tr>110 </table>111 </form>';112 }113 return($Output);114 }115 116 function ShowSearchBox()117 {118 global $System;119 120 $Output = '<strong>Hledání:</strong>'.121 '<form action="'.$System->Link('/action.php').'" method="get"><div>'.122 '<input type="hidden" name="action" value="search" />'.123 '<table>'.124 '<tr>'.125 '<td><input type="text" name="search" size="13" /></td>'.126 '</tr>'.127 '<tr>'.128 '<th><input type="submit" value="Hledat" /></th>'.129 '</tr>'.130 '</table></div>'.131 '</form>';132 return($Output);133 }134 135 function ShowMainMenu()136 {137 global $TranslationTree, $Config, $User, $System;138 139 $Menu = array140 (141 $System->Link('/') => array(LICENCE_ANONYMOUS, 'Hlavní stránka', 'Domů'),142 $System->Link('/dictionary.php') => array(LICENCE_ANONYMOUS, 'Slovník WoW výrazů', 'Slovníček'),143 $System->Link('/statistic.php') => array(LICENCE_ANONYMOUS, 'Stav dokončení překládů', 'Stav dokončení'),144 $System->Link('/userlist.php?action=nofilter') => array(LICENCE_ANONYMOUS, 'Seznam registrovaných uživatelů', 'Překladatelé'),145 $System->Link('/team.php?search=') => array(LICENCE_ANONYMOUS, 'Seznam překladatelských týmů', 'Týmy'),146 $System->Link('/serverlist.php') => array(LICENCE_ANONYMOUS, 'Seznam serverů, kde je nasazena čeština v praxi', 'Servery'),147 $System->Link('/export/') => array(LICENCE_ANONYMOUS, 'Zde si můžete stáhnout přeložené texty', 'Exporty'),148 $System->Link('/download.php') => array(LICENCE_ANONYMOUS, 'Stahování různých pomocných souborů a programů', 'Soubory'),149 $System->Link('/info.php') => array(LICENCE_ANONYMOUS, 'Informace k překladu hry', 'Informace'),150 $System->Link('/TranslationList.php?action=grouplist') => array(LICENCE_ANONYMOUS, 'Informace o překladových skupinách', 'Zdroje dat'),151 $System->Link('/banners.php') => array(LICENCE_ANONYMOUS, 'Informace k propagaci tohoto projektu', 'Propagace'),152 $System->Link('/promotion.php') => array(LICENCE_ANONYMOUS, 'Prezentace a motivace překladu', 'Prezentace'),153 $System->Link('/version.php') => array(LICENCE_ANONYMOUS, 'Seznam verzí herního klienta', 'Verze hry'),154 $System->Link('/aowow/') => array(LICENCE_ANONYMOUS, 'Vyhledávací databáze podobná WoWHead s překlady', 'AoWoW'),155 'http://embed.mibbit.com/?server=game.zdechov.net%3A6667&channel=%23wowpreklad&forcePrompt=true&charset=utf-8' => array(LICENCE_ANONYMOUS, 'IRC chat pro překladatele', 'Chat'),156 $System->Link('/admin/') => array(LICENCE_ADMIN, 'Volby pro správu', 'Administrace'),157 );158 159 $Output = '<strong>Hlavní menu:</strong>'.160 '<div class="verticalmenu"><ul>';161 foreach($Menu as $MenuTarget => $MenuItem)162 {163 if(isset($MenuItem[3])) $OnClick = ' onclick="'.$MenuItem[3].'"';164 else $OnClick = '';165 if($User->Licence($MenuItem[0]))166 $Output .= '<li><a class="verticalmenua" title="'.$MenuItem[1].'" href="'.$MenuTarget.'"'.$OnClick.'>'.$MenuItem[2].'</a></li>';167 }168 $Output .= '</ul></div>';169 return($Output);170 }171 172 function ShowTranslatedMenu()173 {174 global $TranslationTree, $User, $System;175 176 $Output = '<strong>Překladové skupiny:</strong><br /><div id="TranslationMenu">';177 foreach($TranslationTree as $Group)178 {179 $Output .= '<div id="menuitem-group'.$Group['Id'].'" onmouseover="show(\'group'.$Group['Id'].'\')" onmouseout="hide(\'group'.$Group['Id'].'\')">'.180 '<a href="'.$System->Link('/TranslationList.php?group='.$Group['Id'].'&action=filter').'">'.$Group['Name'].'</a></div>'.181 '<div id="group'.$Group['Id'].'" class="hidden-menu-item" onmouseover="show(\'group'.$Group['Id'].'\')" onmouseout="hide(\'group'.$Group['Id'].'\')">';182 $Output .= ' <a title="Zde můžete začít překládat" href="'.$System->Link('/TranslationList.php?group='.$Group['Id'].'&state=1&user=0&entry=&text=').'">Nepřeložené</a><br />'.183 ' <a title="Přeložené texty, můžete zde hlasovat, nebo opravovat překlady" href="'.$System->Link('/TranslationList.php?group='.$Group['Id'].'&state=2&user=0&entry=&text=').'">Přeložené</a><br />';184 if($User->Licence(LICENCE_USER))185 {186 $Output .= ' <a title="Nedokončené překlady" href="'.$System->Link('/TranslationList.php?group='.$Group['Id'].'&state=3').'">Rozepsané</a><br />187 <a title="Všechny překlady, které jste přeložil" href="'.$System->Link('/TranslationList.php?group='.$Group['Id'].'&state=1&user='.$User->Id).'&entry=&text=">Vlastní</a><br />';188 }189 $Output .= ' <a title="Sestavit speciální filtr" href="'.$System->Link('/TranslationList.php?group='.$Group['Id'].'&action=filter').'">Filtr</a><br />';190 $Output .= '</div>';191 }192 $Output .= '</div>';193 return($Output);194 }195 196 function ShowOnlineUserList()197 {198 global $System, $Moderators, $User;199 200 $Output = 'Online překladatelé:<br />';201 $DbResult = $System->Database->query('SELECT `Name`, `GM`, `ID` FROM `User` WHERE `LastLogin` >= NOW() - 300 AND ((`LastLogout` < `LastLogin`) OR (ISNULL(`LastLogout`)))');202 while($DbUser = $DbResult->fetch_assoc())203 {204 if($User->Licence(LICENCE_MODERATOR))205 $Name = '<a href="user.php?user='.$DbUser['ID'].'">'.$DbUser['Name'].'</a>';206 else $Name = $DbUser['Name'];207 $TextGM = '';208 $Output .= '<strong>'.$Name.'</strong>'.$TextGM.'<br />';209 }210 return($Output);211 }212 213 function ShowHeader()214 {215 global $User, $RSSChannels, $System;216 217 $Output = '<?xml version="1.0" encoding="'.$System->Config['Web']['Charset'].'"?>218 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">219 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cz">'.220 '<head>'.221 '<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$System->Config['Web']['Charset'].'" />'.222 '<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" />'.223 '<meta name="description" content="'.$System->Config['Web']['Title'].'" />'.224 '<meta name="robots" content="all" />'.225 '<link rel="stylesheet" href="'.$System->Link('/style/style.css').'" type="text/css" media="all" />'.226 '<script type="text/javascript" src="'.$System->Link('/style/global.js').'"></script>'.227 '<link rel="shortcut icon" href="'.$System->Link('/images/favicon.ico').'" />';228 if(isset($RSSChannels))229 foreach($RSSChannels as $Channel)230 $Output .= ' <link rel="alternate" title="'.$Channel['Title'].'" href="'.231 $System->Link('/rss.php?channel='.$Channel['Channel']).'" type="application/rss+xml" />';232 $Output .= '<title>'.$System->Config['Web']['Title'].'</title>233 </head>234 <body>';235 236 $Output .= ShowTopBar();237 $Output .= '<table class="page"><tr><td class="menu">';238 $Output .= ShowMainMenu();239 $Output .= ShowOnlineUserList();240 $Output .= '<br />';241 $Output .= ShowSearchBox();242 $Output .= '</td><td id="border-left"></td><td class="content">';243 if(isset($Message)) $Output .= ShowMessage($Message, $MessageType);244 return($Output);245 }246 247 function ShowFooter()248 {249 global $System, $ScriptStartTime, $User;250 251 $ScriptGenerateDuration = round(GetMicrotime() - $ScriptStartTime, 2);252 253 $Output = '</td>'.254 '<td class="menu2">';255 $Output .= ShowTranslatedMenu();256 $Output .= '</td>'.257 '</tr><tr>'.258 '<td colspan="4" class="page-bottom">Autoři: '.$System->Config['Web']['Authors'].259 ' <a href="http://svn.zdechov.net/trac/wowpreklad/browser/trunk">Zdrojové soubory</a> '.260 '<a href="http://svn.zdechov.net/trac/wowpreklad/log/trunk?verbose=on">Novinky</a> '.261 $System->Config['Web']['WebCounter'];262 263 $Output .= '</td></tr>';264 if($System->Config['Web']['ShowRuntimeInfo'] == true)265 $Output .= '<tr><td colspan="3" style="text-align: center;">Doba generování: '.$ScriptGenerateDuration.' s / '.ini_get('max_execution_time').' s Použitá paměť: '.HumanSize(memory_get_peak_usage(FALSE)).' / '.ini_get('memory_limit').'B <a href="http://validator.w3.org/check?uri='.htmlentities('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'?'.$_SERVER['QUERY_STRING']).'">HTML validator</a></td></tr>';266 $Output .= '</table>'.267 '</body>'.268 '</html>';269 $User->Store();270 return($Output);271 }272 273 function ShowPage($Content)274 {275 global $Config;276 277 $Output = ShowHeader().$Content.ShowFooter();278 //if($Config['Web']['FormatOutput']) $Output = FormatOutput($Output);279 echo($Output);280 }281 282 48 $UnitNames = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB'); 283 49 … … 321 87 } 322 88 89 // Log types 90 define('LOG_TYPE_TRANSLATION', 1); 91 define('LOG_TYPE_DOWNLOAD', 2); 92 define('LOG_TYPE_USER', 3); 93 define('LOG_TYPE_MODERATOR', 4); 94 define('LOG_TYPE_ERROR', 10); 95 define('LOG_TYPE_IMPORT', 11); 96 define('LOG_TYPE_EXPORT', 12); 97 define('LOG_TYPE_CZWOW', 13); 98 define('LOG_TYPE_ADMINISTRATION', 14); 99 100 101 function utf2ascii($text) 102 { 103 $return = Str_Replace( 104 Array("á","č","ď","é","ě","í","ľ","ň","ó","ř","š","ť","ú","ů","ý","ž","Á","Č","Ď","É","Ě","Í","Ľ","Ň","Ó","Ř","Š","Ť","Ú","Ů","Ý","Ž") , 105 Array("a","c","d","e","e","i","l","n","o","r","s","t","u","u","y","z","A","C","D","E","E","I","L","N","O","R","S","T","U","U","Y","Z") , 106 $text); 107 //$return = Str_Replace(Array(" ", "_"), "-", $return); //nahradí mezery a podtržítka pomlčkami 108 //$return = Str_Replace(Array("(",")",".","!",",","\"","'"), "", $return); //odstraní ().!,"' 109 //$return = StrToLower($return); // velká písmena nahradí malými. 110 return($return); 111 } 112 113 function getmonthyears($Days) 114 { 115 $month = floor($Days / 30); 116 $year = floor($month / 12); 117 $Days = floor($Days - $month * 30); 118 $month = $month - $year * 12; 119 return($year.'r '.$month.'m '.$Days.'d'); 120 } 121 122 function GetPageList($TotalCount) 123 { 124 global $System; 125 126 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']); 127 128 $ItemPerPage = $System->Config['Web']['ItemsPerPage']; 129 $Around = round($System->Config['Web']['VisiblePagingItems'] / 2); 130 $Result = ''; 131 $PageCount = floor($TotalCount / $ItemPerPage) + 1; 132 133 if(!array_key_exists('Page', $_SESSION)) $_SESSION['Page'] = 0; 134 if(array_key_exists('page', $_GET)) $_SESSION['Page'] = $_GET['page'] * 1; 135 if($_SESSION['Page'] < 0) $_SESSION['Page'] = 0; 136 if($_SESSION['Page'] >= $PageCount) $_SESSION['Page'] = $PageCount - 1; 137 $CurrentPage = $_SESSION['Page']; 138 139 140 $Result .= 'Počet položek: <strong>'.$TotalCount.'</strong> Stránky: '; 141 142 $Result = ''; 143 if($PageCount > 1) 144 { 145 if($CurrentPage > 0) 146 { 147 $QueryItems['page'] = 0; 148 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'"><<</a> '; 149 $QueryItems['page'] = ($CurrentPage - 1); 150 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'"><</a> '; 151 } 152 $PagesMax = $PageCount - 1; 153 $PagesMin = 0; 154 if($PagesMax > ($CurrentPage + $Around)) $PagesMax = $CurrentPage + $Around; 155 if($PagesMin < ($CurrentPage - $Around)) 156 { 157 $Result.= ' ... '; 158 $PagesMin = $CurrentPage - $Around; 159 } 160 for($i = $PagesMin; $i <= $PagesMax; $i++) 161 { 162 if($i == $CurrentPage) $Result.= '<strong>'.($i + 1).'</strong> '; 163 else { 164 $QueryItems['page'] = $i; 165 $Result .= '<a href="?'.SetQueryStringArray($QueryItems).'">'.($i + 1).'</a> '; 166 } 167 } 168 if($PagesMax < ($PageCount - 1)) $Result .= ' ... '; 169 if($CurrentPage < ($PageCount - 1)) 170 { 171 $QueryItems['page'] = ($CurrentPage + 1); 172 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">></a> '; 173 $QueryItems['page'] = ($PageCount - 1); 174 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">>></a>'; 175 } 176 } 177 $Result = '<div style="text-align: center">'.$Result.'</div>'; 178 return(array('SQLLimit' => ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage, 179 'Page' => $CurrentPage, 180 'Output' => $Result, 181 )); 182 } 183 184 $OrderDirSQL = array('ASC', 'DESC'); 185 $OrderArrowImage = array('sort_asc.png', 'sort_desc.png'); 186 187 function GetOrderTableHeader($Columns, $DefaultColumn, $DefaultOrder = 0) 188 { 189 global $OrderDirSQL, $OrderArrowImage, $Config, $System; 190 191 if(array_key_exists('OrderCol', $_GET)) $_SESSION['OrderCol'] = $_GET['OrderCol']; 192 if(array_key_exists('OrderDir', $_GET)) $_SESSION['OrderDir'] = $_GET['OrderDir']; 193 if(!array_key_exists('OrderCol', $_SESSION)) $_SESSION['OrderCol'] = $DefaultColumn; 194 if(!array_key_exists('OrderDir', $_SESSION)) $_SESSION['OrderDir'] = $DefaultOrder; 195 196 // Check OrderCol 197 $Found = false; 198 foreach($Columns as $Column) 199 { 200 if($Column['Name'] == $_SESSION['OrderCol']) 201 { 202 $Found = true; 203 break; 204 } 205 } 206 if($Found == false) 207 { 208 $_SESSION['OrderCol'] = $DefaultColumn; 209 $_SESSION['OrderDir'] = $DefaultOrder; 210 } 211 // Check OrderDir 212 if(($_SESSION['OrderDir'] != 0) and ($_SESSION['OrderDir'] != 1)) $_SESSION['OrderDir'] = 0; 213 214 $Result = ''; 215 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']); 216 foreach($Columns as $Index => $Column) 217 { 218 $QueryItems['OrderCol'] = $Column['Name']; 219 $QueryItems['OrderDir'] = 1 - $_SESSION['OrderDir']; 220 if($Column['Name'] == $_SESSION['OrderCol']) $ArrowImage = '<img style="vertical-align: middle; border: 0px;" src="'.$System->Link('/images/'.$OrderArrowImage[$_SESSION['OrderDir']]).'" alt="order arrow">'; 221 else $ArrowImage = ''; 222 if($Column['Name'] == '') $Result .= '<th>'.$Column['Title'].'</th>'; 223 else $Result .= '<th><a href="?'.SetQueryStringArray($QueryItems).'">'.$Column['Title'].$ArrowImage.'</a></th>'; 224 } 225 return(array( 226 'SQL' => ' ORDER BY `'.$_SESSION['OrderCol'].'` '.$OrderDirSQL[$_SESSION['OrderDir']], 227 'Output' => '<tr>'.$Result.'</tr>', 228 'Column' => $_SESSION['OrderCol'], 229 'Direction' => $_SESSION['OrderDir'], 230 )); 231 } 232 233 function FormatOutput($s) 234 { 235 $out = ''; 236 $nn = 0; 237 $n = 0; 238 while($s != '') 239 { 240 $start = strpos($s, '<'); 241 $end = strpos($s, '>'); 242 if($start != 0) 243 { 244 $end = $start - 1; 245 $start = 0; 246 } 247 $line = trim(substr($s, $start, $end + 1)); 248 if(strlen($line) > 0) 249 if($line[0] == '<') 250 { 251 if($s[$start + 1] == '/') 252 { 253 $n = $n - 2; 254 $nn = $n; 255 } else 256 { 257 if(strpos($line, ' ')) $cmd = substr($line, 1, strpos($line, ' ') - 1); 258 else $cmd = substr($line, 1, strlen($line) - 2); 259 //echo('['.$cmd.']'); 260 if(strpos($s, '</'.$cmd.'>')) $n = $n + 2; 261 } 262 }// else $line = '['.$line.']'; 263 //if($line != '') echo(htmlspecialchars(str_repeat(' ',$nn).$line."\n")); 264 if($line != '') $out .= (str_repeat(' ', $nn).$line."\n"); 265 $s = substr($s, $end + 1, strlen($s)); 266 $nn = $n; 267 } 268 return($out); 269 } 270 271 function WriteLanguages($Selected) 272 { 273 global $LanguageList, $System; 274 275 $Output = '<select name="Language">'; 276 $DbResult = $System->Database->select('Language', '`Id`, `Name`', '`Enabled` = 1'); 277 while($Language = $DbResult->fetch_assoc()) 278 { 279 $Output .= '<option value="'.$Language['Id'].'"'; 280 if($Selected == $Language['Id']) 281 $Output .= ' selected="selected"'; 282 $Output .= '>'.$Language['Name'].'</option>'; 283 } 284 $Output .= '</select>'; 285 return($Output); 286 } 287 288 function WriteLanguagesWithoutSel($Selected) 289 { 290 global $LanguageList; 291 292 $Output = ''; 293 foreach($LanguageList as $Language) 294 { 295 if($Selected == $Language['Id']) $Output .= $Language['Name']; 296 } 297 return($Output); 298 } 299 300 function MysqlDateTimeToTime($Time) 301 { 302 $Parts = explode(' ', $Time); 303 $DateParts = explode('-', $Parts[0]); 304 $TimeParts = explode(':', $Parts[1]); 305 $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]); 306 return($Result); 307 } 308 309 function GetLanguageList() 310 { 311 global $System; 312 313 $Result = array(); 314 $DbResult = $System->Database->query('SELECT * FROM `Language` WHERE `Enabled` = 1'); 315 while($DbRow = $DbResult->fetch_assoc()) 316 $Result[$DbRow['Id']] = $DbRow; 317 return($Result); 318 } 319 320 function GetTranslationTree() 321 { 322 global $System; 323 324 $Result = array(); 325 $DbResult = $System->Database->query('SELECT *, UNIX_TIMESTAMP(`LastImport`) AS `LastImportTime` FROM `Group` ORDER BY `Name`'); 326 while($DbRow = $DbResult->fetch_assoc()) 327 { 328 $DbRow['Items'] = array(); 329 $Result[$DbRow['Id']] = $DbRow; 330 } 331 $DbResult = $System->Database->query('SELECT * FROM `GroupItem` ORDER BY `Group`, `Sequence`'); 332 while($DbRow = $DbResult->fetch_assoc()) 333 { 334 $Result[$DbRow['Group']]['Items'][] = $DbRow; 335 } 336 return($Result); 337 } 338 339 $Moderators = array('Překladatel', 'Moderátor', 'Administrátor'); 340 341 function WriteLog($Text, $Type) 342 { 343 global $System, $User; 344 345 if(!isset($_SERVER['REMOTE_ADDR'])) $IP = 'Konzole'; 346 else $IP = addslashes($_SERVER['REMOTE_ADDR']); 347 348 if(!is_null($User->Id)) $UserId = $User->Id; 349 else $UserId = 'NULL'; 350 $Query = 'INSERT INTO `Log` ( `User` , `Type` , `Text` , `Date` , `IP` ) 351 VALUES ('.$UserId.', '.$Type.', "'.addslashes($Text).'", NOW(), "'.$IP.'")'; 352 $System->Database->query($Query); 353 } 354 355 function HumanDate($SQLDateTime) 356 { 357 $DateTimeParts = explode(' ', $SQLDateTime); 358 if($DateTimeParts[0] != '0000-00-00') 359 { 360 $DateParts = explode('-', $DateTimeParts[0]); 361 return(($DateParts[2] * 1).'.'.($DateParts[1] * 1).'.'.($DateParts[0] * 1)); 362 } else return(' '); 363 } 364 365 function FollowingTran($TextID, $Table, $GroupId, $Prev = false) 366 { 367 global $System; 368 369 if($Prev) 370 { 371 $sql = 'SELECT ID FROM '.$Table.' as item WHERE Language = 0 AND NOT EXISTS(SELECT entry FROM '.$Table.' AS sub WHERE sub.Language <> 0 AND sub.entry = item.entry) AND ID < '.$TextID.' ORDER BY ID DESC LIMIT 1'; 372 } else 373 { 374 $sql = 'SELECT ID FROM '.$Table.' as item WHERE Language = 0 AND NOT EXISTS(SELECT entry FROM '.$Table.' AS sub WHERE sub.Language <> 0 AND sub.entry = item.entry) AND ID > '.$TextID.' ORDER BY ID LIMIT 1'; 375 } 376 377 $DbResult = $System->Database->query($sql); 378 $Next = $DbResult->fetch_assoc(); 379 if($Next) 380 { 381 if($Prev) $Output = '<a href="form.php?group='.$GroupId.'&ID='.$Next['ID'].'">Předcházející '.$Next['ID'].'</a> '; 382 else $Output = '<a href="form.php?group='.$GroupId.'&ID='.$Next['ID'].'">Následující '.$Next['ID'].'</a> '; 383 return('form.php?group='.$GroupId.'&ID='.$Next['ID']); 384 } 385 } 386 387 function GetBuildNumber($Version) 388 { 389 global $System, $BuildNumbers; 390 391 if(isset($BuildNumbers[$Version]) == false) 392 { 393 $sql = 'SELECT `BuildNumber` FROM `ClientVersion` WHERE `Version` = "'.$Version.'"'; 394 $DbResult = $System->Database->query($sql); 395 $DbRow = $DbResult->fetch_assoc(); 396 $BuildNumbers[$Version] = $DbRow['BuildNumber']; 397 } 398 return($BuildNumbers[$Version]); 399 } 400 401 function GetVersionWOW($BuildNumber) 402 { 403 global $System, $VersionsWOW; 404 405 if(isset($VersionsWOW[$BuildNumber]) == false) 406 { 407 $sql = 'SELECT `Version` FROM `ClientVersion` WHERE `BuildNumber` = "'.$BuildNumber.'"'; 408 $DbResult = $System->Database->query($sql); 409 $Version = $DbResult->fetch_assoc(); 410 $VersionsWOW[$BuildNumber] = $Version['Version']; 411 } 412 return($VersionsWOW[$BuildNumber]); 413 } 414 415 function LoadGroupIdParameter() 416 { 417 global $TranslationTree; 418 419 if(array_key_exists('group', $_GET)) $GroupId = $_GET['group'] * 1; 420 else $GroupId = 1; 421 422 if(isset($TranslationTree[$GroupId]) == false) ErrorMessage('Překladová skupina dle zadaného Id neexistuje.'); 423 return($GroupId); 424 } 425 426 function LoadLanguageIdParameter() 427 { 428 global $LanguageList; 429 430 if(array_key_exists('language', $_GET)) $LanguageId = $_GET['language'] * 1; 431 else $LanguageId = 1; 432 433 if(isset($LanguageList[$LanguageId]) == false) 434 { 435 ErrorMessage(ShowMessage('Jazyk dle zadaného Id neexistuje.', MESSAGE_CRITICAL)); 436 } 437 return($LanguageId); 438 } 439 440 function LoadCommandLineParameters() 441 { 442 if(!array_key_exists('REMOTE_ADDR', $_SERVER)) 443 { 444 foreach($_SERVER['argv'] as $Parameter) 445 { 446 if(strpos($Parameter, '=') !== false) 447 { 448 $Index = substr($Parameter, 0, strpos($Parameter, '=')); 449 $Parameter = substr($Parameter, strpos($Parameter, '=') + 1); 450 //echo($Index.' ---- '.$Parameter); 451 $_GET[$Index] = $Parameter; 452 } 453 } 454 } 455 } 456 457 function ShowTabs($Tabs) 458 { 459 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']); 460 461 if(array_key_exists('Tab', $_GET)) $_SESSION['Tab'] = $_GET['Tab']; 462 if(!array_key_exists('Tab', $_SESSION)) $_SESSION['Tab'] = 0; 463 if(($_SESSION['Tab'] < 0) or ($_SESSION['Tab'] > (count($Tabs) - 1))) $_SESSION['Tab'] = 0; 464 $Output = '<div id="header">'. 465 '<ul>'; 466 foreach($Tabs as $Index => $Tab) 467 { 468 $QueryItems['Tab'] = $Index; 469 if($Index == $_SESSION['Tab']) $Selected = ' id="selected"'; 470 else $Selected = ''; 471 $Output .= '<li'.$Selected.'><a href="?'.SetQueryStringArray($QueryItems).'">'.$Tab.'</a></li>'; 472 } 473 $Output .= '</ul></div>'; 474 return($Output); 475 } 476 477 function CheckBox($Name, $Checked = false, $Id = '', $Class = '', $Disabled = false) 478 { 479 if($Id) $Id = ' id="'.$Id.'"'; else $Id = ''; 480 if($Class) $Class = ' class="'.$Class.'"'; else $Class = ''; 481 if($Checked) $Checked = ' checked="checked"'; else $Checked = ''; 482 if($Disabled) $Disabled = ' disabled="disabled"'; else $Disabled = ''; 483 return('<input type="checkbox" value="checked" name="'.$Name.'"'.$Checked.$Disabled.$Id.$Class.' />'); 484 } 485 486 function RadioButton($Name, $Value, $Checked = false, $OnClick = '', $Disabled = false) 487 { 488 if($Checked) $Checked = ' checked="checked"'; else $Checked = ''; 489 if($OnClick != '') $OnClick = ' onclick="'.$OnClick.'"'; else $OnClick = ''; 490 if($Disabled) $Disabled = ' disabled="disabled"'; else $Disabled = ''; 491 return('<input type="radio" name="'.$Name.'" value="'.$Value.'"'.$Checked.$Disabled.$OnClick.'/>'); 492 } 493 494 function SelectOption($Name, $Text, $Selected = false) 495 { 496 if($Selected) $Selected = ' selected="selected"'; else $Selected = ''; 497 return('<option value="'.$Name.'"'.$Selected.'>'.$Text.'</option>'); 498 } 499 500 function DeleteDirectory($dirname) 501 { 502 if(is_dir($dirname)) 503 { 504 $dir_handle = opendir($dirname); 505 if(!$dir_handle) return(false); 506 while($file = readdir($dir_handle)) 507 { 508 if(($file != '.') and ($file != '..')) 509 { 510 if(!is_dir($dirname.'/'.$file)) unlink($dirname.'/'.$file); 511 else DeleteDirectory($dirname.'/'.$file); 512 } 513 } 514 closedir($dir_handle); 515 rmdir($dirname); 516 } 517 return(true); 518 } 519 520 function ErrorMessage($Text) 521 { 522 ShowPage($Text); 523 die(); 524 } 525 526 function GetIDbyName($Table) 527 { 528 global $TranslationTree; 529 530 foreach($TranslationTree as $TableID => $Value) 531 { 532 if($Value['TablePrefix'] == $Table) return $TableID; 533 } 534 } 535 536 function GetTranslatNames($Text,$mode,$TablesColumn) 537 { 538 global $System; 539 540 /* $TablesID = array('gameobject' => 5, 541 'creature' => 6, 542 'item' => 4, 543 'transports' => 'Name', 544 'areatrigger_teleport' => 'Name', 545 'areatrigger_tavern' => 'Name',); */ 546 $buff = array(); 547 548 foreach($TablesColumn as $Table => $Column) 549 { 550 $sql = 'SELECT `ID`,`'.$Column.'`, (SELECT `'.$Column.'` FROM `'.$Table.'` AS `T` WHERE `O`.`Entry` = `T`.`Entry` AND `Language` <> 0 LIMIT 1) AS `Tran` FROM `'.$Table.'` AS `O` WHERE '; 551 $groupby = ' GROUP BY `'.$Column.'`'; 552 553 $ArrStr = explode(' ', $Text); 554 $where = '`Language` = 0 '; 555 if ($mode == 1) $where .= ' AND EXISTS(SELECT 1 FROM `'.$Table.'` AS `Sub` WHERE (`Sub`.`Language` <> 0) AND (`Sub`.`Entry` = `O`.`Entry`))'; 556 if ($mode == 2) $where .= ' AND NOT EXISTS(SELECT 1 FROM `'.$Table.'` AS `Sub` WHERE (`Sub`.`Language` <> 0) AND (`Sub`.`Entry` = `O`.`Entry`))'; 557 $where .= ' AND ('; 558 559 $SqlOK = false; 560 if (count($ArrStr) > 0) { 561 for($i = 0; $i < count($ArrStr); $i++) 562 { 563 if (strpos($ArrStr[$i],"'s") > 0) 564 $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-2); 565 if (strpos($ArrStr[$i],',') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1); 566 if (strpos($ArrStr[$i],'.') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1); 567 if (strpos($ArrStr[$i],'!') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1); 568 if (strpos($ArrStr[$i],'?') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1); 569 570 if (strlen($ArrStr[$i]) > 4) { 571 $where .= '(`O`.`'.$Column.'` LIKE "%'.addslashes($ArrStr[$i]).'%") OR '; 572 $SqlOK = true; 573 } 574 } 575 $where = substr($where, 0, strlen($where) - 4); 576 $where .= ')'; 577 if ($SqlOK) { 578 $DbResult = $System->Database->query($sql.$where.$groupby); 579 // echo ($sql.'|'.$where.'|'.$groupby); 580 while($Line = $DbResult->fetch_assoc()) 581 { 582 $buff[] = array($Line['ID'], GetIDbyName($Table), $Line[$Column], $Line['Tran']); 583 } 584 } 585 } 586 } 587 return $buff; 588 } 589 590 function ProgressBar($Width, $Percent, $Text = '') 591 { 592 $Pixels = $Width * ($Percent / 100); 593 if($Pixels > $Width) $Pixels = $Width; 594 if($Text == '') $Text = $Percent; 595 596 return('<div class="progressbar" style="width: '.$Width.'px">'. 597 '<div class="bar" style="width: '.$Pixels.'px;"></div>'. 598 '<div class="text" style="width: '.$Width.'px">'.$Text.'</div>'. 599 '</div>'); 600 } 601 602 function GetLevelMinMax($XP) 603 { 604 $IndexLevel = 100; 605 606 if($XP > 0) $Level = floor(sqrt($XP / $IndexLevel)); 607 else $Level = 0; 608 $MinXP = $Level * $Level * $IndexLevel; 609 $MaxXP = ($Level + 1) * ($Level + 1) * $IndexLevel; 610 $MaxXP = $MaxXP - $MinXP; 611 $XP = $XP - $MinXP; 612 return(array('Level' => $Level, 'XP' => $XP, 'MaxXP' => $MaxXP)); 613 } 614 615 function GetParameter($Name, $Default = '', $Numeric = false, $Session = false) 616 { 617 $Result = $Default; 618 if(array_key_exists($Name, $_GET)) $Result = $_GET[$Name]; 619 else if(array_key_exists($Name, $_POST)) $Result = $_POST[$Name]; 620 else if($Session and array_key_exists($Name, $_SESSION)) $Result = $_SESSION[$Name]; 621 if($Numeric and !is_numeric($Result)) $Result = $Default; 622 if($Session) $_SESSION[$Name] = $Result; 623 return($Result); 624 } 625 626 function LogReferrer() 627 { 628 global $System; 629 630 if(array_key_exists('HTTP_REFERER', $_SERVER)) 631 { 632 $Referrer = addslashes($_SERVER['HTTP_REFERER']); 633 $HostName = substr($Referrer, strpos($Referrer, '/') + 2); 634 $HostName = substr($HostName, 0, strpos($HostName, '/')); 635 if($HostName != $System->Config['Web']['Host']) 636 { 637 $DbResult = $System->Database->query('SELECT `Id` FROM `Referrer` WHERE `Web` = "'.$HostName.'"'); 638 if($DbResult->num_rows > 0) 639 { 640 $DbRow = $DbResult->fetch_assoc(); 641 $System->Database->query('UPDATE `Referrer` SET `Hits` = `Hits` + 1, `DateLast` = NOW(), `LastURL` = "'.addslashes($Referrer).'" WHERE `Id` = '.$DbRow['Id']); 642 } else $System->Database->query('INSERT INTO `Referrer` (`Web`, `DateFirst`, `DateLast`, `LastURL`, `Hits`) VALUES ("'.$HostName.'", NOW(), NOW( ), "'.addslashes($Referrer).'", 1)'); 643 } 644 } 645 } 646 647 function MakeActiveLinks($Content) 648 { 649 $Content = htmlspecialchars($Content); 650 $Content = str_replace("\n", ' <br/>', $Content); 651 $Content = str_replace("\r", '', $Content); 652 653 $Result = ''; 654 $I = 0; 655 while(strpos($Content, 'http://') !== false) 656 { 657 $I = strpos($Content, 'http://'); 658 $Result .= substr($Content, 0, $I); 659 $Content = substr($Content, $I); 660 $SpacePos = strpos($Content, ' '); 661 if($SpacePos !== false) $URL = substr($Content, 0, strpos($Content, ' ')); 662 else $URL = substr($Content, 0); 663 664 $Result .= '<a href="'.$URL.'">'.$URL.'</a>'; 665 $Content = substr($Content, strlen($URL)); 666 } 667 $Result .= $Content; 668 return($Result); 669 } 670 671 define('MESSAGE_WARNING', 0); 672 define('MESSAGE_CRITICAL', 1); 673 define('MESSAGE_INFORMATION', 2); 674 675 function ShowMessage($Text, $Type = MESSAGE_INFORMATION) 676 { 677 global $System; 678 679 $IconName = array( 680 MESSAGE_INFORMATION => 'information', 681 MESSAGE_WARNING => 'warning', 682 MESSAGE_CRITICAL => 'critical' 683 ); 684 $BackgroundColor = array( 685 MESSAGE_INFORMATION => '#e0e0ff', 686 MESSAGE_WARNING => '#ffffe0', 687 MESSAGE_CRITICAL => '#ffe0e0' 688 ); 689 690 return('<div class="message" style="background-color: '.$BackgroundColor[$Type]. 691 ';"><table><tr><td class="icon"><img src="'. 692 $System->Link('/images/message/'.$IconName[$Type].'.png').'" alt="'. 693 $IconName[$Type].'"><td>'.$Text.'</td></tr></table></div>'); 694 } 695 696 323 697 ?>
Note:
See TracChangeset
for help on using the changeset viewer.