Modules = array();
$this->Pages = array();
$this->ModuleManager = new AppModuleManager();
$this->Database = new Database();
$this->FormManager = new FormManager($this->Database);
}
function RegisterPage($Path, $Handler)
{
$this->Pages[$Path] = $Handler;
}
function SearchPage($PathItems, $Pages)
{
$PathItem = $PathItems[0];
if(array_key_exists($PathItem, $Pages))
{
if(is_array($Pages[$PathItem]))
{
array_shift($PathItems);
return($this->SearchPage($PathItems, $Pages[$PathItem]));
} else return($Pages[$PathItem]);
} else return('');
}
function ShowPage()
{
/* @var $Page Page */
$ClassName = $this->SearchPage($this->PathItems, $this->Pages);
if($ClassName != '')
{
$Page = new $ClassName();
$Page->System = &$this;
$Page->Database = &$this->Database;
$Page->GetOutput();
} else echo('Page '.implode('/', $this->PathItems).' not found.');
}
function ModulePresent($Name)
{
return(array_key_exists($Name, $this->Modules));
}
function AddModule($Module)
{
//echo('Přidávám modul '.get_class($Module).'
');
$Module->System = &$this;
$Module->Database = &$this->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()
{
$Output = '';
$DbResult = $this->Database->select('EmailQueue', '*', 'Archive=0');
while($DbRow = $DbResult->fetch_assoc())
{
$Mail = new Mail();
$Mail->AddToCombined($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'] != '')
{
$DbResult2 = $this->Database->select('File', '*', 'Id='.$DbRow['AttachmentFile']);
while($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 Link($Target)
{
global $Config;
return($Config['Web']['RootFolder'].$Target);
}
}
function GlobalInit()
{
global $Config, $Database, $System, $ScriptTimeStart, $ConfigFileName, $Mail, $Type,
$DatabaseRevision;
date_default_timezone_set('Europe/Prague');
$ScriptTimeStart = GetMicrotime();
if(!isset($Config)) die('Systém není nainstalován. Pokračujte v instalaci zde.');
// 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();
$System = new System();
$System->Config = &$Config;
$System->Database->Connect($Config['Database']['Host'], $Config['Database']['User'], $Config['Database']['Password'], $Config['Database']['Database']);
$System->Database->Prefix = $Config['Database']['Prefix'];
$System->Database->charset($Config['Database']['Charset']);
$System->Database->ShowSQLError = $Config['Web']['ShowSQLError'];
$System->Database->ShowSQLQuery = $Config['Web']['ShowSQLQuery'];
// Check database persistence structure
$UpdateManager = new UpdateManager();
$UpdateManager->Database = &$System->Database;
$UpdateManager->Revision = $DatabaseRevision;
if(!$UpdateManager->IsInstalled()) die('Systém vyžaduje instalaci databáze.');
if(!$UpdateManager->IsUpToDate()) die('Systém vyžaduje aktualizaci databáze.');
// Init old modules
$System->AddModule(new Log());
$System->AddModule(new User());
if(isset($_SERVER['REMOTE_ADDR'])) $System->Modules['User']->Check();
$System->AddModule(new Bill());
$System->AddModule(new Finance());
$System->Modules['Finance']->MainSubject = $Config['Finance']['MainSubjectId'];
$System->Modules['Finance']->DirectoryId = $Config['Finance']['DirectoryId'];
$System->Modules['Finance']->LoadMonthParameters(0);
$System->Modules['Log']->Database->LastQuery = 'ssd';
RegisterFormClasses($System->FormManager);
// Register new modules
$System->ModuleManager->RegisterModule(new ModuleError($System));
$System->ModuleManager->RegisterModule(new ModuleFile($System));
$System->ModuleManager->RegisterModule(new ModuleMeteostation($System));
$System->ModuleManager->RegisterModule(new ModulePortal($System));
$System->ModuleManager->RegisterModule(new ModuleIS($System));
$System->ModuleManager->RegisterModule(new ModuleNetwork($System));
$System->ModuleManager->RegisterModule(new ModuleTV($System));
$System->ModuleManager->RegisterModule(new ModuleOpeningHours($System));
$System->ModuleManager->RegisterModule(new ModuleMap($System));
$System->ModuleManager->RegisterModule(new ModuleChat($System));
$System->ModuleManager->RegisterModule(new ModuleWebCam($System));
$System->ModuleManager->RegisterModule(new ModuleUser($System));
$System->ModuleManager->RegisterModule(new ModuleFinance($System));
$System->ModuleManager->RegisterModule(new ModuleFinanceBankAPI($System));
$System->ModuleManager->RegisterModule(new ModuleNetworkShare($System));
$System->ModuleManager->RegisterModule(new ModuleNews($System));
$System->ModuleManager->RegisterModule(new ModuleMeals($System));
$System->ModuleManager->StartAll();
}
$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 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 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)); } 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 = '