Ignore:
Timestamp:
Mar 1, 2015, 12:43:56 PM (9 years ago)
Author:
chronos
Message:
  • Moved trunk as mvc branch.
Location:
branches/mvc
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/mvc/Base/System.php

    r47 r59  
    11<?php
    22
     3include_once(dirname(__FILE__).'/Version.php');
    34include_once(dirname(__FILE__).'/Database.php');
    45include_once(dirname(__FILE__).'/Error.php');
     
    910include_once(dirname(__FILE__).'/Output.php');
    1011include_once(dirname(__FILE__).'/Permission.php');
     12include_once(dirname(__FILE__).'/PrefixMultiplier.php');
     13include_once(dirname(__FILE__).'/Setup.php');
    1114
    1215$MonthNames = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec');
    13 
    14 $PrefixMultipliers = array
    15 (
    16   'Binary' => array
    17   (
    18     'BaseIndex' => 0,
    19     'Definition' => array
    20     (
    21       array('', '', pow(2, 0)),
    22       array('Ki', 'kibi', pow(2, 10)),
    23       array('Mi', 'mebi', pow(2, 20)),
    24       array('Gi', 'gibi', pow(2, 30)),
    25       array('Ti', 'tebi', pow(2, 40)),
    26       array('Pi', 'pebi', pow(2, 50)),
    27       array('Ei', 'exbi', pow(2, 60)),
    28       array('Zi', 'zebi', pow(2, 70)),
    29       array('Yi', 'yobi', pow(2, 80)),
    30     ),
    31   ),
    32   'Decimal' => array
    33   (
    34     'BaseIndex' => 8,
    35     'Definition' => array
    36     (
    37       array('y', 'yocto', pow(10, -24)),
    38       array('z', 'zepto', pow(10, -21)),
    39       array('a', 'atto', pow(10, -18)),
    40       array('f', 'femto', pow(10, -15)),
    41       array('p', 'piko', pow(10, -12)),
    42       array('n', 'nano', pow(10, -9)),
    43       array('u', 'mikro', pow(10, -6)),
    44       array('m', 'mili', pow(10, -3)),
    45       array('', '', pow(10, 0)),
    46       array('k', 'kilo', pow(10, 3)),
    47       array('M', 'mega', pow(10, 6)),
    48       array('G', 'giga', pow(10, 9)),
    49       array('T', 'tera', pow(10, 12)),
    50       array('P', 'peta', pow(10, 15)),
    51       array('E', 'exa', pow(10, 18)),
    52       array('Z', 'zetta', pow(10, 21)),
    53       array('Y', 'yotta', pow(10, 24)),
    54     ),
    55   ),
    56   'Time' => array
    57   (
    58     'BaseIndex' => 8,
    59     'Definition' => array
    60     (
    61       array('ys', 'yoctosekunda', pow(10, -24)),
    62       array('zs', 'zeptosekunda', pow(10, -21)),
    63       array('as', 'attosekunda', pow(10, -18)),
    64       array('fs', 'femtosekunda', pow(10, -15)),
    65       array('ps', 'pikosekunda', pow(10, -12)),
    66       array('ns', 'nanosekunda', pow(10, -9)),
    67       array('us', 'mikrosekunda', pow(10, -6)),
    68       array('ms', 'milisekunda', pow(10, -3)),
    69       array('s', 'sekund', 1),
    70       array('minut', 'minuta', 60),
    71       array('hodin', 'hodina', 60 * 60) ,
    72       array('dnů', 'den', 24 * 60 * 60),
    73       array('týdnů', 'týden', 7 * 24 * 60 * 60),
    74       array('měsíců', 'měsíc', 30 * 24 * 60 * 60),
    75       array('roků', 'rok', 364 * 24 * 60 * 60),
    76       array('desitiletí', 'desetiletí', 10 * 364 * 24 * 60 * 60),
    77       array('staletí', 'staletí', 100 * 364 * 24 * 60 * 60),
    78       array('tisíciletí', 'tisiciletí', 10000 * 364 * 24 * 60 * 60),
    79     ),
    80   ),
    81 );
    8216
    8317function ErrorHandler()
     
    11246    $this->Output = new Output($this);
    11347
     48    $Config = array();
     49
    11450    $FileName = dirname(__FILE__).'/Config/Config.php';
    11551    if(file_exists($FileName)) include($FileName);
     
    11854        exit;
    11955      }
    120 
    121     $Config = array();
    12256
    12357    $FileName = dirname(__FILE__).'/../Application/Config/Config.php';
     
    13872
    13973    if(isset($_SERVER['REMOTE_ADDR'])) session_start();
    140     $this->Database = new Database($this->Config['Database']['Host'],
    141     $this->Config['Database']['User'], $this->Config['Database']['Password'],
    142     $this->Config['Database']['Database']);
     74    $this->Database = new Database();
     75    $this->Database->Connect($this->Config['Database']['Host'],
     76      $this->Config['Database']['User'], $this->Config['Database']['Password'],
     77      $this->Config['Database']['Database']);
    14378    $this->Database->ShowSQLQuery = $this->Config['System']['ShowSQLQuery'];
    14479    $this->Database->ShowSQLError = $this->Config['System']['ShowSQLError'];
     
    16095    foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($Item);
    16196
     97    // Register and start existing modules
     98    $this->Setup = new Setup($this);
     99    $this->Setup->Start();
     100
    162101    if(array_key_exists('M', $_GET)) $Module = $_GET['M'];
    163102      else $Module = $this->DefaultModule;
    164103
    165104    $ControllerName = $Module.'Controller';
    166     $FileName = dirname(__FILE__).'/../Application/Controller/'.$Module.'.php';
    167     if(!file_exists($FileName))
     105    if(!class_exists($ControllerName))
    168106    {
    169       $this->Output->Show($this->Output->SystemMessage('Soubor '.$FileName.' nenalezen.'));
    170       exit;
    171     } else include($FileName);
     107        // Try to load controller class
     108      $FileName = dirname(__FILE__).'/../Application/Controller/'.$Module.'.php';
     109      if(!file_exists($FileName))
     110      {
     111        $this->Output->Show($this->Output->SystemMessage('Soubor '.$FileName.' nenalezen.'));
     112        exit;
     113      } else include($FileName);
     114    }
    172115    if(class_exists($ControllerName))
    173116    {
     
    190133  {
    191134    return(date('j.n.Y', $Time));
    192   }
    193 
    194   function TruncateDigits($Value, $Digits = 4)
    195   {
    196     for($II = 2; $II > -6; $II--)
    197     {
    198       if($Value >= pow(10, $II))
    199       {
    200         if($Digits < ($II + 1)) $RealDigits = $II + 1; else $RealDigits = $Digits;
    201         $Value = round($Value / pow(10, $II - $RealDigits + 1)) * pow(10, $II - $RealDigits + 1);
    202         break;
    203       }
    204     }
    205     return($Value);
    206   }
    207 
    208   function AddPrefixMultipliers($Value, $Unit, $Digits = 4, $PrefixType = 'Decimal')
    209   {
    210     global $PrefixMultipliers;
    211 
    212     $Negative = ($Value < 0);
    213     $Value = abs($Value);
    214     if(($Unit == '') and ($PrefixType != 'Time'))
    215       return($this->TruncateDigits($Value, $Digits));
    216 
    217     $I = $PrefixMultipliers[$PrefixType]['BaseIndex'];
    218     if($Value == 0) return($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit);
    219 
    220     if($Value > 1)
    221     {
    222       while((($I + 1) <= count($PrefixMultipliers[$PrefixType]['Definition'])) and (($Value / $PrefixMultipliers[$PrefixType]['Definition'][$I + 1][2]) > 1))
    223         $I = $I + 1;
    224     } else
    225     if($Value < 1)
    226     {
    227       while((($I - 1) >= 0) and (($Value / $PrefixMultipliers[$PrefixType]['Definition'][$I][2]) < 1))
    228         $I = $I - 1;
    229     }
    230     $Value = $Value / $PrefixMultipliers[$PrefixType]['Definition'][$I][2];
    231 
    232     // Truncate digits count
    233     $Value = $this->TruncateDigits($Value, $Digits);
    234     if($Negative) $Value = -$Value;
    235     return($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit);
    236135  }
    237136
Note: See TracChangeset for help on using the changeset viewer.