| 1 | <?php
 | 
|---|
| 2 | 
 | 
|---|
| 3 | include_once(dirname(__FILE__).'/Database.php');
 | 
|---|
| 4 | include_once(dirname(__FILE__).'/HTML/XHTML.php');
 | 
|---|
| 5 | include_once(dirname(__FILE__).'/HTML/HTML.php');
 | 
|---|
| 6 | include_once(dirname(__FILE__).'/HTTP.php');
 | 
|---|
| 7 | include_once(dirname(__FILE__).'/Types/Type.php');
 | 
|---|
| 8 | include_once(dirname(__FILE__).'/Output.php');
 | 
|---|
| 9 | 
 | 
|---|
| 10 | $MonthNames = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec');
 | 
|---|
| 11 | 
 | 
|---|
| 12 | $PrefixMultipliers = array
 | 
|---|
| 13 | (
 | 
|---|
| 14 |   'Binary' => array
 | 
|---|
| 15 |   (
 | 
|---|
| 16 |     'BaseIndex' => 0,
 | 
|---|
| 17 |     'Definition' => array
 | 
|---|
| 18 |     (
 | 
|---|
| 19 |       array('', '', pow(2, 0)),
 | 
|---|
| 20 |       array('Ki', 'kibi', pow(2, 10)),
 | 
|---|
| 21 |       array('Mi', 'mebi', pow(2, 20)),
 | 
|---|
| 22 |       array('Gi', 'gibi', pow(2, 30)),
 | 
|---|
| 23 |       array('Ti', 'tebi', pow(2, 40)),
 | 
|---|
| 24 |       array('Pi', 'pebi', pow(2, 50)),
 | 
|---|
| 25 |       array('Ei', 'exbi', pow(2, 60)),
 | 
|---|
| 26 |       array('Zi', 'zebi', pow(2, 70)),
 | 
|---|
| 27 |       array('Yi', 'yobi', pow(2, 80)),
 | 
|---|
| 28 |     ),
 | 
|---|
| 29 |   ),
 | 
|---|
| 30 |   'Decimal' => array
 | 
|---|
| 31 |   (
 | 
|---|
| 32 |     'BaseIndex' => 8,
 | 
|---|
| 33 |     'Definition' => array
 | 
|---|
| 34 |     (
 | 
|---|
| 35 |       array('y', 'yocto', pow(10, -24)),
 | 
|---|
| 36 |       array('z', 'zepto', pow(10, -21)),
 | 
|---|
| 37 |       array('a', 'atto', pow(10, -18)),
 | 
|---|
| 38 |       array('f', 'femto', pow(10, -15)),
 | 
|---|
| 39 |       array('p', 'piko', pow(10, -12)),
 | 
|---|
| 40 |       array('n', 'nano', pow(10, -9)),
 | 
|---|
| 41 |       array('u', 'mikro', pow(10, -6)),
 | 
|---|
| 42 |       array('m', 'mili', pow(10, -3)),
 | 
|---|
| 43 |       array('', '', pow(10, 0)),
 | 
|---|
| 44 |       array('k', 'kilo', pow(10, 3)),
 | 
|---|
| 45 |       array('M', 'mega', pow(10, 6)),
 | 
|---|
| 46 |       array('G', 'giga', pow(10, 9)),
 | 
|---|
| 47 |       array('T', 'tera', pow(10, 12)),
 | 
|---|
| 48 |       array('P', 'peta', pow(10, 15)),
 | 
|---|
| 49 |       array('E', 'exa', pow(10, 18)),
 | 
|---|
| 50 |       array('Z', 'zetta', pow(10, 21)),
 | 
|---|
| 51 |       array('Y', 'yotta', pow(10, 24)),
 | 
|---|
| 52 |     ),
 | 
|---|
| 53 |   ),
 | 
|---|
| 54 |   'Time' => array
 | 
|---|
| 55 |   (
 | 
|---|
| 56 |     'BaseIndex' => 8,
 | 
|---|
| 57 |     'Definition' => array
 | 
|---|
| 58 |     (
 | 
|---|
| 59 |       array('ys', 'yoctosekunda', pow(10, -24)),
 | 
|---|
| 60 |       array('zs', 'zeptosekunda', pow(10, -21)),
 | 
|---|
| 61 |       array('as', 'attosekunda', pow(10, -18)),
 | 
|---|
| 62 |       array('fs', 'femtosekunda', pow(10, -15)),
 | 
|---|
| 63 |       array('ps', 'pikosekunda', pow(10, -12)),
 | 
|---|
| 64 |       array('ns', 'nanosekunda', pow(10, -9)),
 | 
|---|
| 65 |       array('us', 'mikrosekunda', pow(10, -6)),
 | 
|---|
| 66 |       array('ms', 'milisekunda', pow(10, -3)),
 | 
|---|
| 67 |       array('s', 'sekund', 1),
 | 
|---|
| 68 |       array('minut', 'minuta', 60),
 | 
|---|
| 69 |       array('hodin', 'hodina', 60 * 60) ,
 | 
|---|
| 70 |       array('dnů', 'den', 24 * 60 * 60),
 | 
|---|
| 71 |       array('týdnů', 'týden', 7 * 24 * 60 * 60),
 | 
|---|
| 72 |       array('měsíců', 'měsíc', 30 * 24 * 60 * 60),
 | 
|---|
| 73 |       array('roků', 'rok', 364 * 24 * 60 * 60),
 | 
|---|
| 74 |       array('desitiletí', 'desetiletí', 10 * 364 * 24 * 60 * 60),
 | 
|---|
| 75 |       array('staletí', 'staletí', 100 * 364 * 24 * 60 * 60),
 | 
|---|
| 76 |       array('tisíciletí', 'tisiciletí', 10000 * 364 * 24 * 60 * 60),
 | 
|---|
| 77 |     ),
 | 
|---|
| 78 |   ),
 | 
|---|
| 79 | );
 | 
|---|
| 80 | 
 | 
|---|
| 81 | function ErrorHandler()
 | 
|---|
| 82 | {
 | 
|---|
| 83 | }
 | 
|---|
| 84 |   
 | 
|---|
| 85 | class System
 | 
|---|
| 86 | {
 | 
|---|
| 87 |   var $Model = array(); 
 | 
|---|
| 88 |   var $View = array(); 
 | 
|---|
| 89 |   var $Controller = array(); 
 | 
|---|
| 90 |   var $Config;
 | 
|---|
| 91 |   var $Database;
 | 
|---|
| 92 |   var $HTTP;
 | 
|---|
| 93 |   var $HTML;
 | 
|---|
| 94 |   var $Type;
 | 
|---|
| 95 |   var $TimeStart;
 | 
|---|
| 96 |   var $Translation;
 | 
|---|
| 97 |   var $Output;
 | 
|---|
| 98 |   var $DefaultModule;
 | 
|---|
| 99 |   var $Modules = array();
 | 
|---|
| 100 | 
 | 
|---|
| 101 |   function __construct()
 | 
|---|
| 102 |   {
 | 
|---|
| 103 |     global $ShowPHPError;
 | 
|---|
| 104 | 
 | 
|---|
| 105 |     $TimeStart = $this->GetMicrotime();
 | 
|---|
| 106 |     
 | 
|---|
| 107 |     // Change base dir to index. Helpfull if script is executed from command line with related path.
 | 
|---|
| 108 |     chdir(dirname(__FILE__));
 | 
|---|
| 109 | 
 | 
|---|
| 110 |     $this->Output = new Output($this);
 | 
|---|
| 111 | 
 | 
|---|
| 112 |     $FileName = dirname(__FILE__).'/Config/Config.php';
 | 
|---|
| 113 |     if(file_exists($FileName)) include($FileName);
 | 
|---|
| 114 |       else {
 | 
|---|
| 115 |         $this->Output->Show($this->Output->SystemMessage('Configuration file "'.$FileName.'" not found.'));
 | 
|---|
| 116 |         exit;
 | 
|---|
| 117 |       }
 | 
|---|
| 118 |     $this->Config = $Config;
 | 
|---|
| 119 |     $ShowPHPError = $this->Config['Web']['ShowPHPError'];
 | 
|---|
| 120 | 
 | 
|---|
| 121 |     $FileName = dirname(__FILE__).'/../Application/Localization/'.$Config['Web']['Locale'].'.php';
 | 
|---|
| 122 |     if(file_exists($FileName)) include($FileName);
 | 
|---|
| 123 |       else {
 | 
|---|
| 124 |         $this->Output->Show($this->Output->SystemMessage('Translation file "'.$FileName.'" not found.'));
 | 
|---|
| 125 |         exit;
 | 
|---|
| 126 |       }
 | 
|---|
| 127 |     $this->Translation = $Translation;
 | 
|---|
| 128 | 
 | 
|---|
| 129 |     if(isset($_SERVER['REMOTE_ADDR'])) session_start();
 | 
|---|
| 130 |     $this->Database = new Database($this->Config['Database']['Host'],
 | 
|---|
| 131 |     $this->Config['Database']['User'], $this->Config['Database']['Password'],
 | 
|---|
| 132 |     $this->Config['Database']['Database']);
 | 
|---|
| 133 |     $this->Database->ShowSQLQuery = $this->Config['Web']['ShowSQLQuery'];
 | 
|---|
| 134 |     $this->Database->ShowSQLError = $this->Config['Web']['ShowSQLError'];
 | 
|---|
| 135 |     $this->Database->Prefix = $this->Config['Database']['Prefix'];
 | 
|---|
| 136 |     $this->Database->charset($this->Config['Database']['Charset']);
 | 
|---|
| 137 |      
 | 
|---|
| 138 |     $this->HTTP = new HTTP();
 | 
|---|
| 139 |     $this->HTML = new HTML($this);
 | 
|---|
| 140 |     $this->Type = new Type($this);
 | 
|---|
| 141 |   }
 | 
|---|
| 142 | 
 | 
|---|
| 143 |   function Run()
 | 
|---|
| 144 |   {
 | 
|---|
| 145 |     $this->TimeStart = $this->GetMicrotime();
 | 
|---|
| 146 |     
 | 
|---|
| 147 |     // SQL injection hack protection
 | 
|---|
| 148 |     foreach($_POST as $Index => $Item) $_POST[$Index] = addslashes($Item);
 | 
|---|
| 149 |     foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($Item);
 | 
|---|
| 150 | 
 | 
|---|
| 151 |     if(array_key_exists('M', $_GET)) $Module = $_GET['M'];
 | 
|---|
| 152 |       else $Module = $this->DefaultModule;
 | 
|---|
| 153 | 
 | 
|---|
| 154 |     $ControllerName = $Module.'Controller';
 | 
|---|
| 155 |     $FileName = dirname(__FILE__).'/../Application/Controller/'.$Module.'.php';
 | 
|---|
| 156 |     if(!file_exists($FileName))
 | 
|---|
| 157 |     {
 | 
|---|
| 158 |       $this->Output->Show($this->Output->SystemMessage('Soubor '.$FileName.' nenalezen.'));
 | 
|---|
| 159 |       exit;
 | 
|---|
| 160 |     } else include($FileName);
 | 
|---|
| 161 |     if(class_exists($ControllerName))
 | 
|---|
| 162 |     {
 | 
|---|
| 163 |       $Controller = new $ControllerName($this);
 | 
|---|
| 164 |       $this->Output->Show($Controller->Process());
 | 
|---|
| 165 |     } else $this->Output->Show($this->Output->SystemMessage('Modul "'.$ControllerName.'" nenalezen.'));
 | 
|---|
| 166 |   }
 | 
|---|
| 167 | 
 | 
|---|
| 168 |   function ModulePresent($Name)
 | 
|---|
| 169 |   {
 | 
|---|
| 170 |     return(array_key_exists($Name, $this->Modules));
 | 
|---|
| 171 |   }
 | 
|---|
| 172 | 
 | 
|---|
| 173 |   function AddModule($Name)
 | 
|---|
| 174 |   {
 | 
|---|
| 175 |     $this->Modules[$Name] = new $Name($this);
 | 
|---|
| 176 |   }
 | 
|---|
| 177 |   
 | 
|---|
| 178 |   function HumanDate($Time)
 | 
|---|
| 179 |   {
 | 
|---|
| 180 |     return(date('j.n.Y', $Time));
 | 
|---|
| 181 |   }
 | 
|---|
| 182 | 
 | 
|---|
| 183 |   function TruncateDigits($Value, $Digits = 4)
 | 
|---|
| 184 |   {
 | 
|---|
| 185 |     for($II = 2; $II > -6; $II--)
 | 
|---|
| 186 |     {
 | 
|---|
| 187 |       if($Value >= pow(10, $II))
 | 
|---|
| 188 |       {
 | 
|---|
| 189 |         if($Digits < ($II + 1)) $RealDigits = $II + 1; else $RealDigits = $Digits;
 | 
|---|
| 190 |         $Value = round($Value / pow(10, $II - $RealDigits + 1)) * pow(10, $II - $RealDigits + 1);
 | 
|---|
| 191 |         break;
 | 
|---|
| 192 |       }
 | 
|---|
| 193 |     }
 | 
|---|
| 194 |     return($Value);
 | 
|---|
| 195 |   }
 | 
|---|
| 196 | 
 | 
|---|
| 197 |   function AddPrefixMultipliers($Value, $Unit, $Digits = 4, $PrefixType = 'Decimal')
 | 
|---|
| 198 |   {
 | 
|---|
| 199 |     global $PrefixMultipliers;
 | 
|---|
| 200 | 
 | 
|---|
| 201 |     $Negative = ($Value < 0);
 | 
|---|
| 202 |     $Value = abs($Value);
 | 
|---|
| 203 |     if(($Unit == '') and ($PrefixType != 'Time'))
 | 
|---|
| 204 |       return($this->TruncateDigits($Value, $Digits));
 | 
|---|
| 205 | 
 | 
|---|
| 206 |     $I = $PrefixMultipliers[$PrefixType]['BaseIndex'];
 | 
|---|
| 207 |     if($Value == 0) return($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit);
 | 
|---|
| 208 |      
 | 
|---|
| 209 |     if($Value > 1) 
 | 
|---|
| 210 |     {
 | 
|---|
| 211 |       while((($I + 1) <= count($PrefixMultipliers[$PrefixType]['Definition'])) and (($Value / $PrefixMultipliers[$PrefixType]['Definition'][$I + 1][2]) > 1))
 | 
|---|
| 212 |         $I = $I + 1;
 | 
|---|
| 213 |     } else 
 | 
|---|
| 214 |     if($Value < 1)
 | 
|---|
| 215 |     {
 | 
|---|
| 216 |       while((($I - 1) >= 0) and (($Value / $PrefixMultipliers[$PrefixType]['Definition'][$I][2]) < 1))
 | 
|---|
| 217 |         $I = $I - 1;
 | 
|---|
| 218 |     }
 | 
|---|
| 219 |     $Value = $Value / $PrefixMultipliers[$PrefixType]['Definition'][$I][2];
 | 
|---|
| 220 |     
 | 
|---|
| 221 |     // Truncate digits count
 | 
|---|
| 222 |     $Value = $this->TruncateDigits($Value, $Digits);
 | 
|---|
| 223 |     if($Negative) $Value = -$Value;
 | 
|---|
| 224 |     return($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit);
 | 
|---|
| 225 |   }
 | 
|---|
| 226 |   
 | 
|---|
| 227 |   function NetworkPortState($Address, $Port, $Timeout = 1)
 | 
|---|
| 228 |   {
 | 
|---|
| 229 |     set_error_handler('ErrorHandler');
 | 
|---|
| 230 |     $Socket = @fsockopen($Address, $Port, $ERROR_NO, $ERROR_STR, (float)$Timeout);
 | 
|---|
| 231 |     if($Socket)
 | 
|---|
| 232 |     {
 | 
|---|
| 233 |       fclose($Socket);
 | 
|---|
| 234 |       $Result = true;
 | 
|---|
| 235 |     } else $Result = false;
 | 
|---|
| 236 |     restore_error_handler();
 | 
|---|
| 237 |     return($Result);
 | 
|---|
| 238 |   }
 | 
|---|
| 239 | 
 | 
|---|
| 240 |   function Translate($Text)
 | 
|---|
| 241 |   {
 | 
|---|
| 242 |     if(array_key_exists($Text, $this->Translation)) return($this->Translation[$Text]);
 | 
|---|
| 243 |       else return('#'.$Text);
 | 
|---|
| 244 |   }
 | 
|---|
| 245 | 
 | 
|---|
| 246 |   function MakeLink($Module, $Action, $Parameters = array())
 | 
|---|
| 247 |   {
 | 
|---|
| 248 |     $Parameters = $this->HTTP->SetQueryStringArray($Parameters);
 | 
|---|
| 249 |     if($Parameters != '') $Parameters = '&'.$Parameters;
 | 
|---|
| 250 |     return('?M='.$Module.'&A='.$Action.$Parameters);
 | 
|---|
| 251 |   }
 | 
|---|
| 252 | 
 | 
|---|
| 253 |   function GetRemoteAddress()
 | 
|---|
| 254 |   {
 | 
|---|
| 255 |     if(array_key_exists('HTTP_X_FORWARDED_FOR',$_SERVER)) $IP = $_SERVER['HTTP_X_FORWARDED_FOR'] ;
 | 
|---|
| 256 |     else if(array_key_exists('REMOTE_ADDR', $_SERVER)) $IP = $_SERVER['REMOTE_ADDR'];
 | 
|---|
| 257 |     else $IP = '0.0.0.0';
 | 
|---|
| 258 |     return($IP);
 | 
|---|
| 259 |   }
 | 
|---|
| 260 | 
 | 
|---|
| 261 |   function GetMicrotime()
 | 
|---|
| 262 |   {
 | 
|---|
| 263 |     list($Usec, $Sec) = explode(' ', microtime());
 | 
|---|
| 264 |     return((float)$Usec + (float)$Sec);
 | 
|---|
| 265 |   }
 | 
|---|
| 266 | 
 | 
|---|
| 267 |   function RemoveDiacritic($Text)
 | 
|---|
| 268 |   {
 | 
|---|
| 269 |     return(str_replace(
 | 
|---|
| 270 |       array('á', 'č', 'ď', 'é', 'ě', 'í', 'ľ', 'ň', 'ó', 'ř', 'š', 'ť', 'ú', 'ů', 'ý', 'ž', 'Á', 'Č', 'Ď', 'É', 'Ě', 'Í', 'Ľ', 'Ň', 'Ó', 'Ř', 'Š', 'Ť', 'Ú', 'Ů', 'Ý', 'Ž'),
 | 
|---|
| 271 |       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'),
 | 
|---|
| 272 |       $Text));
 | 
|---|
| 273 |   }
 | 
|---|
| 274 | }
 | 
|---|
| 275 | 
 | 
|---|
| 276 | ?>
 | 
|---|