$Item) { if ($Index != 'lvm') $Parts[] = $Index.'='.$Item; } return implode('&', $Parts); } function HumanSize(int $Value): string { global $UnitNames; $UnitIndex = 0; while ($Value > 1024) { $Value = round($Value / 1024, 3); $UnitIndex++; } return $Value.' '.$UnitNames[$UnitIndex]; } function GetPageList(int $TotalCount): array { global $Config; $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']); $ItemPerPage = (int)$Config['ItemsPerPage']; $Around = round((int)$Config['VisiblePagingItems'] / 2); $Result = ''; $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.= '>>'; } } $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(array $Columns, string $DefaultColumn, int $DefaultOrder = 0): array { global $OrderDirSQL, $OrderArrowImage, $Config; if (array_key_exists('OrderCol', $_GET)) $_SESSION['OrderCol'] = $_GET['OrderCol']; if (array_key_exists('OrderDir', $_GET) and (array_key_exists($_GET['OrderDir'], $OrderArrowImage))) $_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 = 'order arrow'; 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 GetMicrotime(): float { list($Usec, $Sec) = explode(' ', microtime()); return (float)$Usec + (float)$Sec; } class Filter { var $Items = array(); function GetOutput(string $Link): string { $Output = ''; foreach ($this->Items as $Item) { if (($Item['Type'] == 'String') or ($Item['Type'] == 'Enumeration') or ($Item['Type'] == 'Boolean')) { if (!array_key_exists($Item['Name'], $_SESSION)) $_SESSION[$Item['Name']] = ''; } else if ($Item['Type'] == 'Integer') { if (!array_key_exists($Item['Name'].'od', $_SESSION)) $_SESSION[$Item['Name'].'od'] = ''; if (!array_key_exists($Item['Name'].'do', $_SESSION)) $_SESSION[$Item['Name'].'do'] = ''; } } if (array_key_exists('lvm', $_GET) and ($_GET['lvm'] == 'seznam')) { foreach ($this->Items as $Item) { if ($Item['Type'] == 'String') { if (array_key_exists($Item['Name'], $_GET) ) $_SESSION[$Item['Name']] = $_GET[$Item['Name']]; } else if (($Item['Type'] == 'Enumeration') or ($Item['Type'] == 'Boolean')) { if (array_key_exists($Item['Name'], $_GET) ) $_SESSION[$Item['Name']] = $_GET[$Item['Name']]; if ($_SESSION[$Item['Name']] == '0') $_SESSION[$Item['Name']] = ''; } else if ($Item['Type'] == 'Integer') { if (array_key_exists($Item['Name'].'od', $_GET) ) $_SESSION[$Item['Name'].'od'] = $_GET[$Item['Name'].'od']; if ($_SESSION[$Item['Name'].'od'] == '0') $_SESSION[$Item['Name'].'od'] = ''; if (array_key_exists($Item['Name'].'do', $_GET) ) $_SESSION[$Item['Name'].'do'] = $_GET[$Item['Name'].'do']; if ($_SESSION[$Item['Name'].'do'] == '0') $_SESSION[$Item['Name'].'do'] = ''; } } } else { $Output .= '
'; foreach ($this->Items as $Item) { if ($Item['Type'] == 'String') { $Output .= '
'. '
'.$Item['Title'].'
'. ''. '
'; } else if ($Item['Type'] == 'Boolean') { $Output .= '
'; $Output .= ''; $Output .= '
'; } else if ($Item['Type'] == 'Enumeration') { $Output .= '
'. '
'.$Item['Title'].'
'; foreach ($Item['States'] as $EnumIndex => $EnumItem) { $Output .= ''; } $Output .= '
'; } else if ($Item['Type'] == 'Integer') { $Output .= '
'. '
'.$Item['Title'].'
'. ''. '
-
'. ''; if (array_key_exists('Units', $Item)) { $Output .= '
'.$Item['Units'].'
'; } $Output .= '
'; } } $Output .= '
'; } return $Output; } function GetWhere(Database $Database): string { $Where = ''; foreach ($this->Items as $Item) { if ($Item['DbName'] != '') { if ($Item['Type'] == 'String') { if ($_SESSION[$Item['Name']] != '') $Where .= ' AND ('.$Item['DbName'].' LIKE "%'.$Database->real_escape_string($_SESSION[$Item['Name']]).'%")'; } else if ($Item['Type'] == 'Boolean') { if ($_SESSION[$Item['Name']] != '') $Where .= ' AND ('.$Item['DbName'].' = '.$Database->real_escape_string($_SESSION[$Item['Name']]).')'; } else if ($Item['Type'] == 'Enumeration') { if ($_SESSION[$Item['Name']] != '') $Where .= ' AND ('.$Item['DbName'].' = '.$Database->real_escape_string($_SESSION[$Item['Name']]).')'; } else if ($Item['Type'] == 'Integer') { if ($_SESSION[$Item['Name'].'od'] != '') $Where .= ' AND ('.$Item['DbName'].' >= '.$Database->real_escape_string($_SESSION[$Item['Name'].'od']).')'; if ($_SESSION[$Item['Name'].'do'] != '') $Where .= ' AND ('.$Item['DbName'].' <= '.$Database->real_escape_string($_SESSION[$Item['Name'].'do']).')'; } } } if (substr($Where, 0, 4) == ' AND') $Where = substr($Where, 4); if ($Where == '') $Where = '1'; return $Where; } }