'Ne', true => 'Ano');
function HumanSize($Value)
{
global $UnitNames;
$UnitIndex = 0;
while($Value > 1024)
{
$Value = round($Value / 1024, 3);
$UnitIndex++;
}
return($Value.' '.$UnitNames[$UnitIndex]);
}
function GetMicrotime()
{
list($Usec, $Sec) = explode(' ', microtime());
return ((float)$Usec + (float)$Sec);
}
function ShowArray($Pole)
{
echo('
');
print_r($Pole);
echo('
');
}
function HumanDate($Time)
{
if($Time != '') {
$Date = explode(' ', $Time);
$Parts = explode('-', $Date[0]);
if($Date != '0000-00-00') return(($Parts[2]*1).'.'.($Parts[1]*1).'.'.$Parts[0]);
else return(' ');
} else return(' ');
}
// Show page listing numbers
function PagesList($URL, $Page, $TotalCount, $CountPerPage)
{
$Count = ceil($TotalCount / $CountPerPage);
$Around = 10;
$Result = '';
if($Count>1)
{
if($Page>0)
{
$Result.= '<< ';
$Result.= '< ';
}
$PagesMax = $Count-1;
$PagesMin = 0;
if($PagesMax>($Page+$Around)) $PagesMax = $Page+$Around;
if($PagesMin<($Page-$Around))
{
$Result.= ' .. ';
$PagesMin = $Page-$Around;
}
for($i=$PagesMin;$i<=$PagesMax;$i++)
{
if($i==$Page) $Result.= '';
$Result.= ''.($i+1).' ';
if($i==$Page) $Result.= '';
}
if($PagesMax<($Count-1)) $Result .= ' .. ';
if($Page<($Count-1))
{
$Result.= '> ';
$Result.= '>>';
}
}
return($Result);
}
function ExtractTime($Time)
{
return(array(
'Year' => date('Y', $Time),
'Month' => date('n', $Time),
'Day' => date('j', $Time),
'Hour' => date('h', $Time),
'Minute' => date('i', $Time),
'Second' => date('s', $Time)
));
}
function GetQueryStringArray($QueryString)
{
$Result = array();
$Parts = explode('&', $QueryString);
foreach($Parts as $Part)
{
if($Part != '')
{
if(!strpos($Part, '=')) $Part .= '=';
$Item = explode('=', $Part);
$Result[$Item[0]] = $Item[1];
}
}
return($Result);
}
function SetQueryStringArray($QueryStringArray)
{
$Parts = array();
foreach($QueryStringArray as $Index => $Item)
{
$Parts[] = $Index.'='.$Item;
}
return(implode('&', $Parts));
}
class Paging
{
var $TotalCount;
var $ItemPerPage;
var $Around;
var $SQLLimit;
var $Page;
function __construct()
{
global $System;
$this->ItemPerPage = $System->Config['Web']['ItemsPerPage'];
$this->Around = $System->Config['Web']['VisiblePagingItems'];
}
function Show()
{
$QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
$Result = '';
if(array_key_exists('all', $QueryItems))
{
$PageCount = 1;
$ItemPerPage = $this->TotalCount;
} else
{
$ItemPerPage = $this->ItemPerPage;
$Around = round($this->Around / 2);
$PageCount = floor($this->TotalCount / $ItemPerPage) + 1;
}
if(!array_key_exists('Page', $_SESSION)) $_SESSION['Page'] = 0;
if(array_key_exists('page', $_GET)) $_SESSION['Page'] = $_GET['page'] * 1;
if($_SESSION['Page'] < 0) $_SESSION['Page'] = 0;
if($_SESSION['Page'] >= $PageCount) $_SESSION['Page'] = $PageCount - 1;
$CurrentPage = $_SESSION['Page'];
$Result .= 'Počet položek: '.$this->TotalCount.' Stránky: ';
$Result = '';
if($PageCount > 1)
{
if($CurrentPage > 0)
{
$QueryItems['page'] = 0;
$Result.= '<< ';
$QueryItems['page'] = ($CurrentPage - 1);
$Result.= '< ';
}
$PagesMax = $PageCount - 1;
$PagesMin = 0;
if($PagesMax > ($CurrentPage + $Around)) $PagesMax = $CurrentPage + $Around;
if($PagesMin < ($CurrentPage - $Around))
{
$Result.= ' ... ';
$PagesMin = $CurrentPage - $Around;
}
for($i = $PagesMin; $i <= $PagesMax; $i++)
{
if($i == $CurrentPage) $Result.= ''.($i + 1).' ';
else {
$QueryItems['page'] = $i;
$Result .= ''.($i + 1).' ';
}
}
if($PagesMax < ($PageCount - 1)) $Result .= ' ... ';
if($CurrentPage < ($PageCount - 1))
{
$QueryItems['page'] = ($CurrentPage + 1);
$Result.= '> ';
$QueryItems['page'] = ($PageCount - 1);
$Result.= '>>';
}
}
$QueryItems['all'] = '1';
if($PageCount > 1) $Result.= ' Vše';
$Result = ''.$Result.'
';
$this->SQLLimit = ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage;
$this->Page = $CurrentPage;
return($Result);
}
}
function GetPageList($TotalCount)
{
global $System;
$QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
$Result = '';
if(array_key_exists('all', $QueryItems))
{
$PageCount = 1;
$ItemPerPage = $TotalCount;
} else
{
$ItemPerPage = $System->Config['Web']['ItemsPerPage'];
$Around = round($System->Config['Web']['VisiblePagingItems'] / 2);
$PageCount = floor($TotalCount / $ItemPerPage) + 1;
}
if(!array_key_exists('Page', $_SESSION)) $_SESSION['Page'] = 0;
if(array_key_exists('page', $_GET)) $_SESSION['Page'] = $_GET['page'] * 1;
if($_SESSION['Page'] < 0) $_SESSION['Page'] = 0;
if($_SESSION['Page'] >= $PageCount) $_SESSION['Page'] = $PageCount - 1;
$CurrentPage = $_SESSION['Page'];
$Result .= 'Počet položek: '.$TotalCount.' Stránky: ';
$Result = '';
if($PageCount > 1)
{
if($CurrentPage > 0)
{
$QueryItems['page'] = 0;
$Result.= '<< ';
$QueryItems['page'] = ($CurrentPage - 1);
$Result.= '< ';
}
$PagesMax = $PageCount - 1;
$PagesMin = 0;
if($PagesMax > ($CurrentPage + $Around)) $PagesMax = $CurrentPage + $Around;
if($PagesMin < ($CurrentPage - $Around))
{
$Result.= ' ... ';
$PagesMin = $CurrentPage - $Around;
}
for($i = $PagesMin; $i <= $PagesMax; $i++)
{
if($i == $CurrentPage) $Result.= ''.($i + 1).' ';
else {
$QueryItems['page'] = $i;
$Result .= ''.($i + 1).' ';
}
}
if($PagesMax < ($PageCount - 1)) $Result .= ' ... ';
if($CurrentPage < ($PageCount - 1))
{
$QueryItems['page'] = ($CurrentPage + 1);
$Result.= '> ';
$QueryItems['page'] = ($PageCount - 1);
$Result.= '>>';
}
}
$QueryItems['all'] = '1';
if($PageCount > 1) $Result.= ' Vše';
$Result = ''.$Result.'
';
return(array('SQLLimit' => ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage,
'Page' => $CurrentPage,
'Output' => $Result,
));
}
$OrderDirSQL = array('ASC', 'DESC');
$OrderArrowImage = array('sort_asc.png', 'sort_desc.png');
function GetOrderTableHeader($Columns, $DefaultColumn, $DefaultOrder = 0)
{
global $OrderDirSQL, $OrderArrowImage, $Config, $System;
if(array_key_exists('OrderCol', $_GET)) $_SESSION['OrderCol'] = $_GET['OrderCol'];
if(array_key_exists('OrderDir', $_GET)) $_SESSION['OrderDir'] = $_GET['OrderDir'];
if(!array_key_exists('OrderCol', $_SESSION)) $_SESSION['OrderCol'] = $DefaultColumn;
if(!array_key_exists('OrderDir', $_SESSION)) $_SESSION['OrderDir'] = $DefaultOrder;
// Check OrderCol
$Found = false;
foreach($Columns as $Column)
{
if($Column['Name'] == $_SESSION['OrderCol'])
{
$Found = true;
break;
}
}
if($Found == false)
{
$_SESSION['OrderCol'] = $DefaultColumn;
$_SESSION['OrderDir'] = $DefaultOrder;
}
// Check OrderDir
if(($_SESSION['OrderDir'] != 0) and ($_SESSION['OrderDir'] != 1)) $_SESSION['OrderDir'] = 0;
$Result = '';
$QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
foreach($Columns as $Index => $Column)
{
$QueryItems['OrderCol'] = $Column['Name'];
$QueryItems['OrderDir'] = 1 - $_SESSION['OrderDir'];
if($Column['Name'] == $_SESSION['OrderCol']) $ArrowImage = '';
else $ArrowImage = '';
if($Column['Name'] == '') $Result .= ''.$Column['Title'].' | ';
else $Result .= ''.$Column['Title'].$ArrowImage.' | ';
}
return(array(
'SQL' => ' ORDER BY `'.$_SESSION['OrderCol'].'` '.$OrderDirSQL[$_SESSION['OrderDir']],
'Output' => ''.$Result.'
',
'Column' => $_SESSION['OrderCol'],
'Direction' => $_SESSION['OrderDir'],
));
}
function GetRemoteAddress()
{
if(array_key_exists('REMOTE_ADDR', $_SERVER)) $IP = $_SERVER['REMOTE_ADDR'];
else $IP = '0.0.0.0';
return($IP);
}
function IsInternetAddr()
{
$RemoteAddr = GetRemoteAddress();
$RemoteAddr = explode('.', $RemoteAddr);
// return(!(($RemoteAddr[0] == 10) and ($RemoteAddr[1] == 145)));
return(!(($RemoteAddr[0] == 10)));
}
function GetMemberByIP($IP)
{
global $Database;
$DbResult = $Database->query('SELECT Id FROM Member WHERE '.
'(SELECT Member FROM NetworkDevice WHERE (SELECT Device FROM NetworkInterface '.
'WHERE LocalIP = "'.$IP.'") = NetworkDevice.Id) = Member.Id');
if($DbResult->num_rows > 0)
{
$DbRow = $DbResult->fetch_assoc();
return($DbRow['Id']);
} else return('');
}
function RemoveDiacritic($Text)
{
return(str_replace(
array('á', 'č', 'ď', 'é', 'ě', 'í', 'ľ', 'ň', 'ó', 'ř', 'š', 'ť', 'ú', 'ů',
'ý', 'ž', 'Á', 'Č', 'Ď', 'É', 'Ě', 'Í', 'Ľ', 'Ň', 'Ó', 'Ř', 'Š', 'Ť', 'Ú', 'Ů', 'Ý', 'Ž'),
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'),
$Text));
}
function RouterOSIdent($Name)
{
return(strtr(strtolower(trim($Name)), array(' ' => '-', '.' => '', '(' => '-', ')' => '-',
'č' => 'c', 'š' => 's', 'ě' => 'e', 'ř' => 'r', 'ž' => 'z', 'ý' => 'y',
'á' => 'a', 'í' => 'i', 'é' => 'e', 'ů' => 'u', 'ú' => 'u', 'ď' => 'd',
'ť' => 't', 'ň' => 'n', 'ó' => 'o',
'Č' => 'c', 'Š' => 's', 'Ě' => 'e', 'Ř' => 'r', 'Ž' => 'z', 'Ý' => 'y',
'Á' => 'a', 'Í' => 'i', 'É' => 'e', 'Ů' => 'u', 'Ú' => 'u', 'Ď' => 'd',
'Ť' => 't', 'Ň' => 'n', 'Ó' => 'o',
)));
}
function NotBlank($Text)
{
if($Text == '') return(' ');
else return($Text);
}
function strip_cdata($string)
{
preg_match_all('//is', $string, $matches);
return str_replace($matches[0], $matches[1], $string);
}
function html2txt($document)
{
$search = array('@@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@@siU', // Strip style tags properly
'@@' // Strip multi-line comments including CDATA
);
$text = preg_replace($search, '', $document);
return $text;
}
function ProcessURL()
{
if(array_key_exists('REDIRECT_QUERY_STRING', $_SERVER))
$PathString = $_SERVER['REDIRECT_QUERY_STRING'];
else $PathString = '';
if(substr($PathString, -1, 1) == '/') $PathString = substr($PathString, 0, -1);
$PathItems = explode('/', $PathString);
if(strpos($_SERVER['REQUEST_URI'], '?') !== false)
$_SERVER['QUERY_STRING'] = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '?') + 1);
else $_SERVER['QUERY_STRING'] = '';
parse_str($_SERVER['QUERY_STRING'], $_GET);
return($PathItems);
}
function RepeatFunction($Period, $Function)
{
while(1)
{
$StartTime = time();
$Function();
$EndTime = time();
$Delay = $Period - ($EndTime - $StartTime);
if($Delay < 0) $Delay = 0;
echo('Waiting '.$Delay.' seconds...'."\n");
sleep($Delay);
}
}