source: trunk/includes/global.php@ 546

Last change on this file since 546 was 546, checked in by chronos, 12 years ago
  • Upraveno: Seznam týmů přepracován na aplikační modul.
File size: 24.5 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/Database.php');
4include_once(dirname(__FILE__).'/system.php');
5include_once(dirname(__FILE__).'/Update.php');
6include_once(dirname(__FILE__).'/rss.php');
7include_once(dirname(__FILE__).'/user.php');
8include_once(dirname(__FILE__).'/Page.php');
9include_once(dirname(__FILE__).'/error.php');
10if(file_exists(dirname(__FILE__).'/config.php'))
11 include_once(dirname(__FILE__).'/config.php');
12include_once(dirname(__FILE__).'/Version.php');
13include_once(dirname(__FILE__).'/AppModule.php');
14
15// Include application modules
16// TODO: Make modules configurable
17include_once(dirname(__FILE__).'/../Modules/AoWoW/AoWoW.php');
18include_once(dirname(__FILE__).'/../Modules/Referrer/Referrer.php');
19include_once(dirname(__FILE__).'/../Modules/FrontPage/FrontPage.php');
20include_once(dirname(__FILE__).'/../Modules/Team/Team.php');
21
22GlobalInit();
23
24function GlobalInit()
25{
26 global $System, $ScriptStartTime, $TranslationTree, $User, $StopAfterUpdateManager,
27 $UpdateManager, $Config, $DatabaseRevision;
28
29 $ScriptStartTime = GetMicrotime();
30
31 if(isset($_SERVER['REMOTE_ADDR'])) session_start();
32
33 if(!isset($Config)) die('Systém není nainstalován. Pokračujte v instalaci <a href="admin/install.php">zde</a>.');
34 date_default_timezone_set($Config['Web']['Timezone']);
35
36 $System = new System();
37 $System->Init();
38
39 // Check database persistence structure
40 $UpdateManager = new UpdateManager();
41 $UpdateManager->Database = $System->Database;
42 $UpdateManager->Revision = $DatabaseRevision;
43 if(!$UpdateManager->IsInstalled()) die('Systém vyžaduje instalaci databáze.');
44 if(!$UpdateManager->IsUpToDate()) die('Systém vyžaduje aktualizaci databáze.');
45
46 // SQL injection hack protection
47 foreach($_POST as $Index => $Item)
48 {
49 if(is_array($_POST[$Index]))
50 foreach($_POST[$Index] as $Index2 => $Item2) $_POST[$Index][$Index2] = addslashes($Item2);
51 else $_POST[$Index] = addslashes($_POST[$Index]);
52 }
53 foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($_GET[$Index]);
54
55 $User = new User($System);
56
57 set_error_handler('ErrorHandler');
58 set_exception_handler('ExceptionHandler');
59
60 // TODO: Global initialized variable should be removed
61 $TranslationTree = GetTranslationTree();
62
63 // Initialize application modules
64 $System->ModuleManager->RegisterModule(new AoWoW($System));
65 $System->ModuleManager->RegisterModule(new Referrer($System));
66 $System->ModuleManager->Modules['Referrer']->Excluded[] = $System->Config['Web']['Host'];
67 $System->ModuleManager->RegisterModule(new FrontPage($System));
68 $System->ModuleManager->RegisterModule(new Team($System));
69 $System->ModuleManager->StartAll();
70}
71
72$RSSChannels = array(
73 array('Title' => 'Změny systému', 'Channel' => 'news'),
74 array('Title' => 'Poslední překlady', 'Channel' => 'translation'),
75 array('Title' => 'Kecátko', 'Channel' => 'shoutbox'),
76);
77
78function GetMicrotime()
79{
80 list($Usec, $Sec) = explode(' ', microtime());
81 return ((float)$Usec + (float)$Sec);
82}
83
84$UnitNames = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB');
85
86function HumanSize($Value)
87{
88 global $UnitNames;
89
90 $UnitIndex = 0;
91 while($Value > 1024)
92 {
93 $Value = round($Value / 1024, 3);
94 $UnitIndex++;
95 }
96 return($Value.' '.$UnitNames[$UnitIndex]);
97}
98
99function GetQueryStringArray($QueryString)
100{
101 $Result = array();
102 $Parts = explode('&', $QueryString);
103 foreach($Parts as $Part)
104 {
105 if($Part != '')
106 {
107 if(!strpos($Part, '=')) $Part .= '=';
108 $Item = explode('=', $Part);
109 $Result[$Item[0]] = $Item[1];
110 }
111 }
112 return($Result);
113}
114
115function SetQueryStringArray($QueryStringArray)
116{
117 $Parts = array();
118 foreach($QueryStringArray as $Index => $Item)
119 {
120 $Parts[] = $Index.'='.$Item;
121 }
122 return(implode('&', $Parts));
123}
124
125// Log types
126define('LOG_TYPE_TRANSLATION', 1);
127define('LOG_TYPE_DOWNLOAD', 2);
128define('LOG_TYPE_USER', 3);
129define('LOG_TYPE_MODERATOR', 4);
130define('LOG_TYPE_ERROR', 10);
131define('LOG_TYPE_IMPORT', 11);
132define('LOG_TYPE_EXPORT', 12);
133define('LOG_TYPE_CZWOW', 13);
134define('LOG_TYPE_ADMINISTRATION', 14);
135
136
137function utf2ascii($text)
138{
139 $return = Str_Replace(
140 Array("á","č","ď","é","ě","í","ľ","ň","ó","ř","š","ť","ú","ů","ý","ž","Á","Č","Ď","É","Ě","Í","Ľ","Ň","Ó","Ř","Š","Ť","Ú","Ů","Ý","Ž") ,
141 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") ,
142 $text);
143 //$return = Str_Replace(Array(" ", "_"), "-", $return); //nahradí mezery a podtržítka pomlčkami
144 //$return = Str_Replace(Array("(",")",".","!",",","\"","'"), "", $return); //odstraní ().!,"'
145 //$return = StrToLower($return); // velká písmena nahradí malými.
146 return($return);
147}
148
149function getmonthyears($Days)
150{
151 $month = floor($Days / 30);
152 $year = floor($month / 12);
153 $Days = floor($Days - $month * 30);
154 $month = $month - $year * 12;
155 return($year.'r '.$month.'m '.$Days.'d');
156}
157
158function GetPageList($TotalCount)
159{
160 global $System;
161
162 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
163
164 $ItemPerPage = $System->Config['Web']['ItemsPerPage'];
165 $Around = round($System->Config['Web']['VisiblePagingItems'] / 2);
166 $Result = '';
167 $PageCount = floor($TotalCount / $ItemPerPage) + 1;
168
169 if(!array_key_exists('Page', $_SESSION)) $_SESSION['Page'] = 0;
170 if(array_key_exists('page', $_GET)) $_SESSION['Page'] = $_GET['page'] * 1;
171 if($_SESSION['Page'] < 0) $_SESSION['Page'] = 0;
172 if($_SESSION['Page'] >= $PageCount) $_SESSION['Page'] = $PageCount - 1;
173 $CurrentPage = $_SESSION['Page'];
174
175
176 $Result .= 'Počet položek: <strong>'.$TotalCount.'</strong> &nbsp; Stránky: ';
177
178 $Result = '';
179 if($PageCount > 1)
180 {
181 if($CurrentPage > 0)
182 {
183 $QueryItems['page'] = 0;
184 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&lt;&lt;</a> ';
185 $QueryItems['page'] = ($CurrentPage - 1);
186 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&lt;</a> ';
187 }
188 $PagesMax = $PageCount - 1;
189 $PagesMin = 0;
190 if($PagesMax > ($CurrentPage + $Around)) $PagesMax = $CurrentPage + $Around;
191 if($PagesMin < ($CurrentPage - $Around))
192 {
193 $Result.= ' ... ';
194 $PagesMin = $CurrentPage - $Around;
195 }
196 for($i = $PagesMin; $i <= $PagesMax; $i++)
197 {
198 if($i == $CurrentPage) $Result.= '<strong>'.($i + 1).'</strong> ';
199 else {
200 $QueryItems['page'] = $i;
201 $Result .= '<a href="?'.SetQueryStringArray($QueryItems).'">'.($i + 1).'</a> ';
202 }
203 }
204 if($PagesMax < ($PageCount - 1)) $Result .= ' ... ';
205 if($CurrentPage < ($PageCount - 1))
206 {
207 $QueryItems['page'] = ($CurrentPage + 1);
208 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&gt;</a> ';
209 $QueryItems['page'] = ($PageCount - 1);
210 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&gt;&gt;</a>';
211 }
212 }
213 $Result = '<div style="text-align: center">'.$Result.'</div>';
214 return(array('SQLLimit' => ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage,
215 'Page' => $CurrentPage,
216 'Output' => $Result,
217 ));
218}
219
220$OrderDirSQL = array('ASC', 'DESC');
221$OrderArrowImage = array('sort_asc.png', 'sort_desc.png');
222
223function GetOrderTableHeader($Columns, $DefaultColumn, $DefaultOrder = 0)
224{
225 global $OrderDirSQL, $OrderArrowImage, $Config, $System;
226
227 if(array_key_exists('OrderCol', $_GET)) $_SESSION['OrderCol'] = $_GET['OrderCol'];
228 if(array_key_exists('OrderDir', $_GET)) $_SESSION['OrderDir'] = $_GET['OrderDir'];
229 if(!array_key_exists('OrderCol', $_SESSION)) $_SESSION['OrderCol'] = $DefaultColumn;
230 if(!array_key_exists('OrderDir', $_SESSION)) $_SESSION['OrderDir'] = $DefaultOrder;
231
232 // Check OrderCol
233 $Found = false;
234 foreach($Columns as $Column)
235 {
236 if($Column['Name'] == $_SESSION['OrderCol'])
237 {
238 $Found = true;
239 break;
240 }
241 }
242 if($Found == false)
243 {
244 $_SESSION['OrderCol'] = $DefaultColumn;
245 $_SESSION['OrderDir'] = $DefaultOrder;
246 }
247 // Check OrderDir
248 if(($_SESSION['OrderDir'] != 0) and ($_SESSION['OrderDir'] != 1)) $_SESSION['OrderDir'] = 0;
249
250 $Result = '';
251 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
252 foreach($Columns as $Index => $Column)
253 {
254 $QueryItems['OrderCol'] = $Column['Name'];
255 $QueryItems['OrderDir'] = 1 - $_SESSION['OrderDir'];
256 if($Column['Name'] == $_SESSION['OrderCol']) $ArrowImage = '<img style="vertical-align: middle; border: 0px;" src="'.$System->Link('/images/'.$OrderArrowImage[$_SESSION['OrderDir']]).'" alt="order arrow">';
257 else $ArrowImage = '';
258 if($Column['Name'] == '') $Result .= '<th>'.$Column['Title'].'</th>';
259 else $Result .= '<th><a href="?'.SetQueryStringArray($QueryItems).'">'.$Column['Title'].$ArrowImage.'</a></th>';
260 }
261 return(array(
262 'SQL' => ' ORDER BY `'.$_SESSION['OrderCol'].'` '.$OrderDirSQL[$_SESSION['OrderDir']],
263 'Output' => '<tr>'.$Result.'</tr>',
264 'Column' => $_SESSION['OrderCol'],
265 'Direction' => $_SESSION['OrderDir'],
266 ));
267}
268
269function FormatOutput($s)
270{
271 $out = '';
272 $nn = 0;
273 $n = 0;
274 while($s != '')
275 {
276 $start = strpos($s, '<');
277 $end = strpos($s, '>');
278 if($start != 0)
279 {
280 $end = $start - 1;
281 $start = 0;
282 }
283 $line = trim(substr($s, $start, $end + 1));
284 if(strlen($line) > 0)
285 if($line[0] == '<')
286 {
287 if($s[$start + 1] == '/')
288 {
289 $n = $n - 2;
290 $nn = $n;
291 } else
292 {
293 if(strpos($line, ' ')) $cmd = substr($line, 1, strpos($line, ' ') - 1);
294 else $cmd = substr($line, 1, strlen($line) - 2);
295 //echo('['.$cmd.']');
296 if(strpos($s, '</'.$cmd.'>')) $n = $n + 2;
297 }
298 }// else $line = '['.$line.']';
299 //if($line != '') echo(htmlspecialchars(str_repeat(' ',$nn).$line."\n"));
300 if($line != '') $out .= (str_repeat(' ', $nn).$line."\n");
301 $s = substr($s, $end + 1, strlen($s));
302 $nn = $n;
303 }
304 return($out);
305}
306
307function WriteLanguages($Selected)
308{
309 global $System;
310
311 $Output = '<select name="Language">';
312 $DbResult = $System->Database->select('Language', '`Id`, `Name`', '`Enabled` = 1');
313 while($Language = $DbResult->fetch_assoc())
314 {
315 $Output .= '<option value="'.$Language['Id'].'"';
316 if($Selected == $Language['Id'])
317 $Output .= ' selected="selected"';
318 $Output .= '>'.$Language['Name'].'</option>';
319 }
320 $Output .= '</select>';
321 return($Output);
322}
323
324function ClientVersionSelection($Selected)
325{
326 global $System;
327
328 $Output = '<select name="ClientVersion">';
329 $DbResult = $System->Database->select('ClientVersion', '`Id`, `Version`', '`Imported` = 1');
330 $Output .= '<option value=""';
331 if($Selected == '')
332 $Output .= ' selected="selected"';
333 $Output .= '>Žádná</option>';
334 while($ClientVersion = $DbResult->fetch_assoc())
335 {
336 $Output .= '<option value="'.$ClientVersion['Id'].'"';
337 if($Selected == $ClientVersion['Id'])
338 $Output .= ' selected="selected"';
339 $Output .= '>'.$ClientVersion['Version'].'</option>';
340 }
341 $Output .= '</select>';
342 return($Output);
343}
344
345function GetLanguageList()
346{
347 global $System;
348
349 $Result = array();
350 $DbResult = $System->Database->query('SELECT * FROM `Language` WHERE `Enabled` = 1');
351 while($DbRow = $DbResult->fetch_assoc())
352 $Result[$DbRow['Id']] = $DbRow;
353 return($Result);
354}
355
356function GetTranslationTree()
357{
358 global $System;
359
360 $Result = array();
361 $DbResult = $System->Database->query('SELECT *, UNIX_TIMESTAMP(`LastImport`) AS `LastImportTime` FROM `Group` ORDER BY `Name`');
362 while($DbRow = $DbResult->fetch_assoc())
363 {
364 $DbRow['Items'] = array();
365 $Result[$DbRow['Id']] = $DbRow;
366 }
367 $DbResult = $System->Database->query('SELECT * FROM `GroupItem` ORDER BY `Group`, `Sequence`');
368 while($DbRow = $DbResult->fetch_assoc())
369 {
370 $Result[$DbRow['Group']]['Items'][] = $DbRow;
371 }
372 return($Result);
373}
374
375$Moderators = array('Překladatel', 'Moderátor', 'Administrátor');
376
377function WriteLog($Text, $Type)
378{
379 global $System, $User;
380
381 if(!isset($_SERVER['REMOTE_ADDR'])) $IP = 'Konzole';
382 else $IP = addslashes($_SERVER['REMOTE_ADDR']);
383
384 if(!is_null($User->Id)) $UserId = $User->Id;
385 else $UserId = 'NULL';
386 $Query = 'INSERT INTO `Log` ( `User` , `Type` , `Text` , `Date` , `IP` )
387 VALUES ('.$UserId.', '.$Type.', "'.addslashes($Text).'", NOW(), "'.$IP.'")';
388 $System->Database->query($Query);
389}
390
391function HumanDate($SQLDateTime)
392{
393 $DateTimeParts = explode(' ', $SQLDateTime);
394 if($DateTimeParts[0] != '0000-00-00')
395 {
396 $DateParts = explode('-', $DateTimeParts[0]);
397 return(($DateParts[2] * 1).'.'.($DateParts[1] * 1).'.'.($DateParts[0] * 1));
398 } else return('&nbsp;');
399}
400
401function FollowingTran($TextID, $Table, $GroupId, $Prev = false)
402{
403 global $System, $Config;
404
405 if($Prev)
406 $sql = 'SELECT `ID` FROM `'.$Table.'` AS `item` WHERE '.
407 '(`Language` = '.$Config['OriginalLanguage'].') AND NOT EXISTS(SELECT `entry` '.
408 'FROM `'.$Table.'` AS `sub` WHERE (`sub`.`Language` <> '.$Config['OriginalLanguage'].') '.
409 'AND (`sub`.`entry` = `item`.`entry`)) AND (`ID` < '.$TextID.') ORDER BY `ID` DESC LIMIT 1';
410 else $sql = 'SELECT `ID` FROM `'.$Table.'` AS `item` WHERE '.
411 '(`Language` = '.$Config['OriginalLanguage'].') AND NOT EXISTS(SELECT `entry` '.
412 'FROM `'.$Table.'` AS `sub` WHERE (`sub`.`Language` <> '.$Config['OriginalLanguage'].') '.
413 'AND (`sub`.`entry` = `item`.`entry`)) AND `ID` > '.$TextID.' ORDER BY `ID` LIMIT 1';
414
415 $DbResult = $System->Database->query($sql);
416 $Next = $DbResult->fetch_assoc();
417 if($Next)
418 {
419 if($Prev) $Output = '<a href="form.php?group='.$GroupId.'&amp;ID='.$Next['ID'].'">Předcházející '.$Next['ID'].'</a> ';
420 else $Output = '<a href="form.php?group='.$GroupId.'&amp;ID='.$Next['ID'].'">Následující '.$Next['ID'].'</a> ';
421 return('form.php?group='.$GroupId.'&amp;ID='.$Next['ID']);
422 }
423}
424
425function GetBuildNumber($Version)
426{
427 global $System, $BuildNumbers;
428
429 if(isset($BuildNumbers[$Version]) == false)
430 {
431 $sql = 'SELECT `BuildNumber` FROM `ClientVersion` WHERE `Version` = "'.$Version.'"';
432 $DbResult = $System->Database->query($sql);
433 $DbRow = $DbResult->fetch_assoc();
434 $BuildNumbers[$Version] = $DbRow['BuildNumber'];
435 }
436 return($BuildNumbers[$Version]);
437}
438
439function GetVersionWOW($BuildNumber)
440{
441 global $System, $VersionsWOW;
442
443 if(isset($VersionsWOW[$BuildNumber]) == false)
444 {
445 $sql = 'SELECT `Version` FROM `ClientVersion` WHERE `BuildNumber` = "'.$BuildNumber.'"';
446 $DbResult = $System->Database->query($sql);
447 $Version = $DbResult->fetch_assoc();
448 $VersionsWOW[$BuildNumber] = $Version['Version'];
449 }
450 return($VersionsWOW[$BuildNumber]);
451}
452
453function LoadGroupIdParameter()
454{
455 global $TranslationTree;
456
457 if(array_key_exists('group', $_GET)) $GroupId = $_GET['group'] * 1;
458 else $GroupId = 1;
459
460 if(isset($TranslationTree[$GroupId]) == false) ErrorMessage('Překladová skupina dle zadaného Id neexistuje.');
461 return($GroupId);
462}
463
464function LoadCommandLineParameters()
465{
466 if(!array_key_exists('REMOTE_ADDR', $_SERVER))
467 {
468 foreach($_SERVER['argv'] as $Parameter)
469 {
470 if(strpos($Parameter, '=') !== false)
471 {
472 $Index = substr($Parameter, 0, strpos($Parameter, '='));
473 $Parameter = substr($Parameter, strpos($Parameter, '=') + 1);
474 //echo($Index.' ---- '.$Parameter);
475 $_GET[$Index] = $Parameter;
476 }
477 }
478 }
479}
480
481function ShowTabs($Tabs)
482{
483 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
484
485 if(array_key_exists('Tab', $_GET)) $_SESSION['Tab'] = $_GET['Tab'];
486 if(!array_key_exists('Tab', $_SESSION)) $_SESSION['Tab'] = 0;
487 if(($_SESSION['Tab'] < 0) or ($_SESSION['Tab'] > (count($Tabs) - 1))) $_SESSION['Tab'] = 0;
488 $Output = '<div id="header">'.
489 '<ul>';
490 foreach($Tabs as $Index => $Tab)
491 {
492 $QueryItems['Tab'] = $Index;
493 if($Index == $_SESSION['Tab']) $Selected = ' id="selected"';
494 else $Selected = '';
495 $Output .= '<li'.$Selected.'><a href="?'.SetQueryStringArray($QueryItems).'">'.$Tab.'</a></li>';
496 }
497 $Output .= '</ul></div>';
498 return($Output);
499}
500
501function CheckBox($Name, $Checked = false, $Id = '', $Class = '', $Disabled = false)
502{
503 if($Id) $Id = ' id="'.$Id.'"'; else $Id = '';
504 if($Class) $Class = ' class="'.$Class.'"'; else $Class = '';
505 if($Checked) $Checked = ' checked="checked"'; else $Checked = '';
506 if($Disabled) $Disabled = ' disabled="disabled"'; else $Disabled = '';
507 return('<input type="checkbox" value="checked" name="'.$Name.'"'.$Checked.$Disabled.$Id.$Class.' />');
508}
509
510function RadioButton($Name, $Value, $Checked = false, $OnClick = '', $Disabled = false)
511{
512 if($Checked) $Checked = ' checked="checked"'; else $Checked = '';
513 if($OnClick != '') $OnClick = ' onclick="'.$OnClick.'"'; else $OnClick = '';
514 if($Disabled) $Disabled = ' disabled="disabled"'; else $Disabled = '';
515 return('<input type="radio" name="'.$Name.'" value="'.$Value.'"'.$Checked.$Disabled.$OnClick.'/>');
516}
517
518function SelectOption($Name, $Text, $Selected = false)
519{
520 if($Selected) $Selected = ' selected="selected"'; else $Selected = '';
521 return('<option value="'.$Name.'"'.$Selected.'>'.$Text.'</option>');
522}
523
524function DeleteDirectory($dirname)
525{
526 if(is_dir($dirname))
527 {
528 $dir_handle = opendir($dirname);
529 if(!$dir_handle) return(false);
530 while($file = readdir($dir_handle))
531 {
532 if(($file != '.') and ($file != '..'))
533 {
534 if(!is_dir($dirname.'/'.$file)) unlink($dirname.'/'.$file);
535 else DeleteDirectory($dirname.'/'.$file);
536 }
537 }
538 closedir($dir_handle);
539 rmdir($dirname);
540 }
541 return(true);
542}
543
544function ErrorMessage($Text)
545{
546 ShowPage($Text);
547 die();
548}
549
550function GetIDbyName($Table)
551{
552 global $TranslationTree;
553
554 foreach($TranslationTree as $TableID => $Value)
555 {
556 if($Value['TablePrefix'] == $Table) return $TableID;
557 }
558}
559
560function GetTranslatNames($Text,$mode,$TablesColumn)
561{
562 global $System, $Config;
563
564 /* $TablesID = array('gameobject' => 5,
565 'creature' => 6,
566 'item' => 4,
567 'transports' => 'Name',
568 'areatrigger_teleport' => 'Name',
569 'areatrigger_tavern' => 'Name',); */
570 $buff = array();
571
572 foreach($TablesColumn as $Table => $Column)
573 {
574 $sql = 'SELECT `ID`,`'.$Column.'`, (SELECT `'.$Column.'` FROM `'.$Table.'` AS `T` WHERE '.
575 '(`O`.`Entry` = `T`.`Entry`) AND (`Language` <> '.$Config['OriginalLanguage'].') LIMIT 1) AS `Tran` FROM `'.$Table.'` AS `O` WHERE ';
576 $groupby = ' GROUP BY `'.$Column.'`';
577
578 $ArrStr = explode(' ', $Text);
579 $where = '(`Language` = '.$Config['OriginalLanguage'].') ';
580 if ($mode == 1) $where .= ' AND EXISTS(SELECT 1 FROM `'.$Table.'` AS `Sub` WHERE (`Sub`.`Language` <> '.$Config['OriginalLanguage'].') AND (`Sub`.`Entry` = `O`.`Entry`))';
581 if ($mode == 2) $where .= ' AND NOT EXISTS(SELECT 1 FROM `'.$Table.'` AS `Sub` WHERE (`Sub`.`Language` <> '.$Config['OriginalLanguage'].') AND (`Sub`.`Entry` = `O`.`Entry`))';
582 $where .= ' AND (';
583
584 $SqlOK = false;
585 if (count($ArrStr) > 0) {
586 for($i = 0; $i < count($ArrStr); $i++)
587 {
588 if (strpos($ArrStr[$i],"'s") > 0)
589 $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-2);
590 if (strpos($ArrStr[$i],',') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1);
591 if (strpos($ArrStr[$i],'.') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1);
592 if (strpos($ArrStr[$i],'!') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1);
593 if (strpos($ArrStr[$i],'?') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1);
594
595 if (strlen($ArrStr[$i]) > 4) {
596 $where .= '(`O`.`'.$Column.'` LIKE "%'.addslashes($ArrStr[$i]).'%") OR ';
597 $SqlOK = true;
598 }
599 }
600 $where = substr($where, 0, strlen($where) - 4);
601 $where .= ')';
602 if ($SqlOK) {
603 $DbResult = $System->Database->query($sql.$where.$groupby);
604 // echo ($sql.'|'.$where.'|'.$groupby);
605 while($Line = $DbResult->fetch_assoc())
606 {
607 $buff[] = array($Line['ID'], GetIDbyName($Table), $Line[$Column], $Line['Tran']);
608 }
609 }
610 }
611 }
612 return $buff;
613}
614
615function ProgressBar($Width, $Percent, $Text = '')
616{
617 $Pixels = $Width * ($Percent / 100);
618 if($Pixels > $Width) $Pixels = $Width;
619 if($Text == '') $Text = $Percent;
620
621 return('<div class="progressbar" style="width: '.$Width.'px">'.
622 '<div class="bar" style="width: '.$Pixels.'px;"></div>'.
623 '<div class="text" style="width: '.$Width.'px">'.$Text.'</div>'.
624 '</div>');
625}
626
627function GetLevelMinMax($XP)
628{
629 $IndexLevel = 100;
630
631 if($XP > 0) $Level = floor(sqrt($XP / $IndexLevel));
632 else $Level = 0;
633 $MinXP = $Level * $Level * $IndexLevel;
634 $MaxXP = ($Level + 1) * ($Level + 1) * $IndexLevel;
635 $MaxXP = $MaxXP - $MinXP;
636 $XP = $XP - $MinXP;
637 return(array('Level' => $Level, 'XP' => $XP, 'MaxXP' => $MaxXP));
638}
639
640function GetParameter($Name, $Default = '', $Numeric = false, $Session = false)
641{
642 $Result = $Default;
643 if(array_key_exists($Name, $_GET)) $Result = $_GET[$Name];
644 else if(array_key_exists($Name, $_POST)) $Result = $_POST[$Name];
645 else if($Session and array_key_exists($Name, $_SESSION)) $Result = $_SESSION[$Name];
646 if($Numeric and !is_numeric($Result)) $Result = $Default;
647 if($Session) $_SESSION[$Name] = $Result;
648 return($Result);
649}
650
651function MakeActiveLinks($Content)
652{
653 $Content = htmlspecialchars($Content);
654 $Content = str_replace("\n", ' <br/>', $Content);
655 $Content = str_replace("\r", '', $Content);
656
657 $Result = '';
658 $I = 0;
659 while(strpos($Content, 'http://') !== false)
660 {
661 $I = strpos($Content, 'http://');
662 $Result .= substr($Content, 0, $I);
663 $Content = substr($Content, $I);
664 $SpacePos = strpos($Content, ' ');
665 if($SpacePos !== false) $URL = substr($Content, 0, strpos($Content, ' '));
666 else $URL = substr($Content, 0);
667
668 $Result .= '<a href="'.$URL.'">'.$URL.'</a>';
669 $Content = substr($Content, strlen($URL));
670 }
671 $Result .= $Content;
672 return($Result);
673}
674
675define('MESSAGE_WARNING', 0);
676define('MESSAGE_CRITICAL', 1);
677define('MESSAGE_INFORMATION', 2);
678
679function ShowMessage($Text, $Type = MESSAGE_INFORMATION)
680{
681 global $System;
682
683 $IconName = array(
684 MESSAGE_INFORMATION => 'information',
685 MESSAGE_WARNING => 'warning',
686 MESSAGE_CRITICAL => 'critical'
687 );
688 $BackgroundColor = array(
689 MESSAGE_INFORMATION => '#e0e0ff',
690 MESSAGE_WARNING => '#ffffe0',
691 MESSAGE_CRITICAL => '#ffe0e0'
692 );
693
694 return('<div class="message" style="background-color: '.$BackgroundColor[$Type].
695 ';"><table><tr><td class="icon"><img src="'.
696 $System->Link('/images/message/'.$IconName[$Type].'.png').'" alt="'.
697 $IconName[$Type].'"><td>'.$Text.'</td></tr></table></div>');
698}
699
700function HandleLoginForm()
701{
702 global $User, $Message, $MessageType;
703
704 if(array_key_exists('action', $_GET))
705 {
706 if($_GET['action'] == 'login')
707 {
708 if(array_key_exists('LoginUser', $_POST) and array_key_exists('LoginPass', $_POST))
709 {
710 $User->Login($_POST['LoginUser'], $_POST['LoginPass']);
711 if($User->Role == LICENCE_ANONYMOUS)
712 {
713 $Message = 'Jméno nebo heslo bylo zadáno špatně.';
714 $MessageType = MESSAGE_CRITICAL;
715 } else
716 {
717 $Message = 'Přihlášení proběhlo úspěšně. Vítej <strong>'.$User->Name.'</strong>!';
718 $MessageType = MESSAGE_INFORMATION;
719 }
720 } else
721 {
722 $Message = 'Nebylo zadáno jméno a heslo.';
723 $MessageType = MESSAGE_CRITICAL;
724 }
725 } else
726 if($_GET['action'] == 'logout')
727 {
728 if($User->Role != LICENCE_ANONYMOUS)
729 {
730 WriteLog('Odhlášení', LOG_TYPE_USER);
731 $User->Logout();
732 $Message = 'Byl jsi odhlášen.';
733 $MessageType = MESSAGE_INFORMATION;
734 }
735 }
736 }
737}
738
739function ProcessURL()
740{
741 if(array_key_exists('REDIRECT_QUERY_STRING', $_SERVER))
742 $PathString = $_SERVER['REDIRECT_QUERY_STRING'];
743 else $PathString = '';
744 if(substr($PathString, -1, 1) == '/') $PathString = substr($PathString, 0, -1);
745 $PathItems = explode('/', $PathString);
746 if(strpos($_SERVER['REQUEST_URI'], '?') !== false)
747 $_SERVER['QUERY_STRING'] = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '?') + 1);
748 else $_SERVER['QUERY_STRING'] = '';
749 parse_str($_SERVER['QUERY_STRING'], $_GET);
750 return($PathItems);
751}
752
753?>
Note: See TracBrowser for help on using the repository browser.