array
(
'BaseIndex' => 0,
'Definition' => array
(
array('', '', pow(2, 0)),
array('Ki', 'kibi', pow(2, 10)),
array('Mi', 'mebi', pow(2, 20)),
array('Gi', 'gibi', pow(2, 30)),
array('Ti', 'tebi', pow(2, 40)),
array('Pi', 'pebi', pow(2, 50)),
array('Ei', 'exbi', pow(2, 60)),
array('Zi', 'zebi', pow(2, 70)),
array('Yi', 'yobi', pow(2, 80)),
),
),
'Decimal' => array
(
'BaseIndex' => 8,
'Definition' => array
(
array('y', 'yocto', pow(10, -24)),
array('z', 'zepto', pow(10, -21)),
array('a', 'atto', pow(10, -18)),
array('f', 'femto', pow(10, -15)),
array('p', 'piko', pow(10, -12)),
array('n', 'nano', pow(10, -9)),
array('u', 'mikro', pow(10, -6)),
array('m', 'mili', pow(10, -3)),
array('', '', pow(10, 0)),
array('k', 'kilo', pow(10, 3)),
array('M', 'mega', pow(10, 6)),
array('G', 'giga', pow(10, 9)),
array('T', 'tera', pow(10, 12)),
array('P', 'peta', pow(10, 15)),
array('E', 'exa', pow(10, 18)),
array('Z', 'zetta', pow(10, 21)),
array('Y', 'yotta', pow(10, 24)),
),
),
'Time' => array
(
'BaseIndex' => 8,
'Definition' => array
(
array('ys', 'yoctosekunda', pow(10, -24)),
array('zs', 'zeptosekunda', pow(10, -21)),
array('as', 'attosekunda', pow(10, -18)),
array('fs', 'femtosekunda', pow(10, -15)),
array('ps', 'pikosekunda', pow(10, -12)),
array('ns', 'nanosekunda', pow(10, -9)),
array('us', 'mikrosekunda', pow(10, -6)),
array('ms', 'milisekunda', pow(10, -3)),
array('s', 'sekunda', 1),
array('minut', 'minuta', 60),
array('hodin', 'hodina', 60 * 60) ,
array('dnů', 'den', 24 * 60 * 60),
array('týdnů', 'týden', 7 * 24 * 60 * 60),
array('měsíců', 'měsíc', 30 * 24 * 60 * 60),
array('roků', 'rok', 364 * 24 * 60 * 60),
array('desetiletí', 'desetiletí', 10 * 364 * 24 * 60 * 60),
array('stalatí', 'staletí', 100 * 364 * 24 * 60 * 60),
array('tisíciletí', 'tisiciletí', 10000 * 364 * 24 * 60 * 60),
),
),
);
class System extends Module
{
var $Modules = array();
/** @var Type */
var $Type;
function __construct()
{
parent::__construct();
$this->Type = new Type($this);
}
function ModulePresent($Name)
{
return(array_key_exists($Name, $this->Modules));
}
function AddModule($Module)
{
global $Database;
//echo('Přidávám modul '.get_class($Module).'
');
$Module->System = &$this;
$Module->Database = &$Database;
$this->Modules[get_class($Module)] = $Module;
}
function AddEmailToQueue($To, $Subject, $Content, $From, $AttachmentFileId = '')
{
$Values = array('To' => $To,
'Subject' => $Subject, 'Content' => $Content, 'Time' => 'NOW()',
'From' => $From);
if($AttachmentFileId != '') $Values['AttachmentFile'] = $AttachmentFileId;
$this->Database->insert('EmailQueue', $Values);
}
function ProcessEmailQueue()
{
$Mail = new Mail();
$Output = '';
$DbResult = $this->Database->select('EmailQueue', '*', 'Archive=0');
while($DbRow = $DbResult->fetch_assoc())
{
$Mail->AddTo($DbRow['To']);
$Mail->Subject = $DbRow['Subject'];
$Mail->From = $DbRow['From'];
$Mail->AddBody(strip_tags($DbRow['Content']), 'text/plain');
$Mail->AddBody($DbRow['Content'], 'text/html');
if($DbRow['AttachmentFile'] != 'NULL')
{
$DbResult2 = $this->Dataase->select('File', '*', 'Id='.$DbRow['AttachmentFile']);
$File = $DbResult2->fetch_assoc();
$Mail->AttachFile($this->Config['Web']['FileRootFolder'].$File['DrivePath'], $File['MimeType']);
}
$Mail->Send();
$this->Database->update('EmailQueue', 'Id='.$DbRow['Id'], array('Archive' => 1));
$this->Modules['Log']->NewRecord('System', 'SendEmail', $DbRow['Id']);
$Output .= 'To: '.$DbRow['To'].' Subject: '.$DbRow['Subject'].'
';
}
return($Output);
}
function HumanDate($Time)
{
return(date('j.n.Y', $Time));
}
function TruncateDigits($Value, $Digits = 4)
{
for($II = 2; $II > -6; $II--)
{
if($Value >= pow(10, $II))
{
if($Digits < ($II + 1)) $RealDigits = $II + 1; else $RealDigits = $Digits;
$Value = round($Value / pow(10, $II - $RealDigits + 1)) * pow(10, $II - $RealDigits + 1);
break;
}
}
return($Value);
}
function AddPrefixMultipliers($Value, $Unit, $Digits = 4, $PrefixType = 'Decimal')
{
global $PrefixMultipliers;
$Negative = ($Value < 0);
$Value = abs($Value);
if(($Unit == '') and ($PrefixType != 'Time'))
return($this->TruncateDigits($Value, $Digits));
$I = $PrefixMultipliers[$PrefixType]['BaseIndex'];
if($Value == 0) return($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit);
if($Value > 1)
{
while((($I + 1) <= count($PrefixMultipliers[$PrefixType]['Definition'])) and (($Value / $PrefixMultipliers[$PrefixType]['Definition'][$I + 1][2]) > 1))
$I = $I + 1;
} else
if($Value < 1)
{
while((($I - 1) >= 0) and (($Value / $PrefixMultipliers[$PrefixType]['Definition'][$I][2]) < 1))
$I = $I - 1;
}
$Value = $Value / $PrefixMultipliers[$PrefixType]['Definition'][$I][2];
// Truncate digits count
$Value = $this->TruncateDigits($Value, $Digits);
if($Negative) $Value = -$Value;
return($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit);
}
function Link($Target)
{
global $Config;
return($Config['Web']['RootFolder'].$Target);
}
}
function GlobalInit()
{
global $Config, $Database, $System, $ScriptTimeStart, $ConfigFileName, $Mail, $Type;
date_default_timezone_set('Europe/Prague');
$ScriptTimeStart = GetMicrotime();
// SQL injection hack protection
foreach($_POST as $Index => $Item) $_POST[$Index] = addslashes($Item);
foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($Item);
if(isset($_SERVER['REMOTE_ADDR'])) session_start();
$Database = new Database($Config['Database']['Host'], $Config['Database']['User'], $Config['Database']['Password'], $Config['Database']['Database']);
$Database->Prefix = $Config['Database']['Prefix'];
$Database->charset($Config['Database']['Charset']);
$Database->ShowSQLError = $Config['Web']['ShowSQLError'];
$Database->ShowSQLQuery = $Config['Web']['ShowSQLQuery'];
$System = new System();
$System->Config = $Config;
$System->Database = &$Database;
$System->AddModule(new Log());
$System->AddModule(new ErrorHandler());
$System->Modules['ErrorHandler']->Init();
$System->AddModule(new User());
if(isset($_SERVER['REMOTE_ADDR'])) $System->Modules['User']->Check();
$System->AddModule(new News());
$System->AddModule(new Webcam());
$System->AddModule(new Bill());
$System->AddModule(new Finance());
$System->Modules['Finance']->LoadMonthParameters(0);
}
$MonthNames = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec');
$UnitNames = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB');
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 TimeToMysqlDateTime($Time) { return(date('Y-m-d H:i:s', $Time)); } function MysqlDateTimeToTime($DateTime) { if($DateTime == '') return(0); $Parts = explode(' ', $DateTime); $DateParts = explode('-', $Parts[0]); $TimeParts = explode(':', $Parts[1]); $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]); return($Result); } function MysqlDateToTime($Date) { if($Date == '') return(0); return(MysqlDateTimeToTime($Date.' 0:0:0')); } function MysqlTimeToTime($Time) { if($Time == '') return(0); return(MysqlDateTimeToTime('0000-00-00 '.$Time)); } function HumanDate($Time) { $Date = explode(' ', $Time); $Parts = explode('-', $Date[0]); if($Date != '0000-00-00') return(($Parts[2]*1).'.'.($Parts[1]*1).'.'.$Parts[0]); else return(' '); } // Zobrazení číselný seznamu stránek 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 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)); } 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 = '