source: trunk/includes/global.php@ 628

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