Changeset 501 for trunk/Common


Ignore:
Timestamp:
Mar 10, 2013, 8:15:46 PM (12 years ago)
Author:
chronos
Message:
  • Přidáno: FormManager pro objektové řešení zrušení vazeb na třídu System. FormManager nyní obsluhuje existující formulářové typy a třídy formulářů.
  • Přidáno: Formulářový typ FileContent zajistí načtení obsahu souboru. Typ File pak zajistí i uložení do databáze a přiřazení Id do tabulky File.
  • Odstraněno: Adresář docs obsahoval staré dokumenty. Ty musí být přesunuty do adresáře files a registrovány do databáze.
  • Upraveno: Třídy Database nyní bude hlásit chyby přes výjimky PHP.
Location:
trunk/Common
Files:
2 added
1 deleted
11 edited
2 copied
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/Common/Database.php

    r486 r501  
    3838  var $ShowSQLQuery = false;
    3939 
    40   function __construct($Host, $User, $Password, $Database)
     40  function __construct()
     41  {   
     42  }
     43 
     44  function Connect($Host, $User, $Password, $Database)
    4145  {   
    4246    if($this->Type == 'mysql') $ConnectionString = 'mysql:host='.$Host.';dbname='.$Database;
     
    6670      $this->Error = $this->Error[2];
    6771      if(($this->Error != '') and ($this->ShowSQLError == true))
    68         echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>');
     72        //echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>');
     73        throw new Exception('SQL Error: </strong>'.$this->Error.', Query: '.$Query);
    6974    }
    7075    return($Result); 
  • trunk/Common/Error.php

    r476 r501  
    44{
    55  var $Encoding;
     6  var $ShowError;
     7  var $UserErrors;
    68   
    79  function __construct()
    810  {
    911    $this->Encoding = 'utf-8';
     12    $this->ShowError = false;
     13    $this->UserErrors = E_ALL;  //E_ERROR | E_WARNING | E_PARSE;
    1014  }
    1115 
     
    1721  function Handle($Number, $Message, $FileName, $LineNumber, $Variables)
    1822  {
    19   global $Config;
     23    $Date = date('Y-m-d H:i:s');                // časové razítko položky
     24    $ErrorType = array
     25    (
     26      1 => 'Error',
     27      2 => 'Warning',
     28      4 => 'Parsing Error',
     29      8 => 'Notice',
     30      16 => 'Core Error',
     31      32 => 'Core Warning',
     32      64 => 'Compile Error',
     33      128 => 'Compile Warning',
     34      256 => 'User Error',
     35      512 => 'User Warning',
     36      1024 => 'User Notice'
     37    );
    2038 
    21   $Date = date('Y-m-d H:i:s');          // časové razítko položky
    22   $ErrorType = array
    23   (
    24     1 => 'Error',
    25     2 => 'Warning',
    26     4 => 'Parsing Error',
    27     8 => 'Notice',
    28     16 => 'Core Error',
    29     32 => 'Core Warning',
    30     64 => 'Compile Error',
    31     128 => 'Compile Warning',
    32     256 => 'User Error',
    33     512 => 'User Warning',
    34     1024 => 'User Notice'
    35   );
    36   $UserErrors = E_ALL;  //E_ERROR | E_WARNING | E_PARSE;
    37  
    38   if(($UserErrors & $Number))
    39   {
    40     $Error = '# '.$Date."\n";
    41     $Backtrace = debug_backtrace();
    42     $Backtrace[0]['function'] = $Message;
    43     $Backtrace[0]['args'] = '';
    44     $Backtrace[0]['file'] = $FileName;
    45     $Backtrace[0]['line'] = $LineNumber;
    46     //$First = array_shift($Backtrace);
    47     //print_r($Backtrace);
     39    if(($this->UserErrors & $Number))
     40    {
     41      $Error = '# '.$Date."\n";
     42      $Backtrace = debug_backtrace();
     43      $Backtrace[0]['function'] = $Message;
     44      $Backtrace[0]['args'] = '';
     45      $Backtrace[0]['file'] = $FileName;
     46      $Backtrace[0]['line'] = $LineNumber;
     47      //$First = array_shift($Backtrace);
    4848   
    49     //array_unshift($Backtrace, $First);
    50     //array_shift($Backtrace);
    51     //print_r($Backtrace);
    52     foreach($Backtrace as $Item)
    53     {
    54       $Error .= ' '.$Item['file'].'('.$Item['line'].")\t".$Item['function'];
    55       $Arguments = '';
    56       if(array_key_exists('args', $Item) and is_array($Item['args']))
     49      //array_unshift($Backtrace, $First);
     50      //array_shift($Backtrace);
     51      foreach($Backtrace as $Item)
     52      {
     53        $Error .= ' '.$Item['file'].'('.$Item['line'].")\t".$Item['function'];
     54        $Arguments = '';
     55        if(array_key_exists('args', $Item) and is_array($Item['args']))
    5756        foreach($Item['args'] as $Item)
    5857        {
     
    6160          else $Arguments .= "'".$Item."',";
    6261        }
    63       if(strlen($Arguments) > 0) $Error .= '('.substr($Arguments, 0, -1).')';
     62        if(strlen($Arguments) > 0) $Error .= '('.substr($Arguments, 0, -1).')';
     63        $Error .= "\n";     
     64      }
    6465      $Error .= "\n";
    6566     
     67      $this->System->Modules['Log']->NewRecord('Error', 'Log', $Error);   
     68   
     69      //if($Config['Web']['ErrorLogFile'] != '')
     70        // error_log($Error, 3, $Config['Web']['ErrorLogFile']);
     71            // Pošli mi zprávu (pokud je to kritická chyba)
     72         //mail($Config['Web']['AdminEmail'], $Config['Web']['Title'].' - Chybové hlášení', $Error);
     73          // Show error message
     74            if($this->ShowError == true)
     75          {
     76              echo('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>'."\n".
     77        '<meta http-equiv="Content-Language" content="cs">'."\n".
     78        '<meta http-equiv="Content-Type" content="text/html; charset='.$this->Encoding.'"></head><body>'."\n".
     79        'Došlo k vnitřní chybě!<br/> O chybě byl uvědoměn správce webu a chybu brzy odstraní.<br/><br/>');
     80            echo('<pre>'.$Error.'</pre><br/>');                 // V případě ladění chybu i zobraz
     81          echo('</body></html>');
     82            }
     83      if((E_ERROR | E_PARSE) & $Number) die();
    6684    }
    67     $Error .= "\n";
    68    
    69     $this->System->Modules['Log']->NewRecord('Error', 'Log', $Error);   
    70    
    71     //if($Config['Web']['ErrorLogFile'] != '')
    72       //error_log($Error, 3, $Config['Web']['ErrorLogFile']);
    73         // Pošli mi zprávu (pokud je to kritická chyba)
    74         //mail($Config['Web']['AdminEmail'], $Config['Web']['Title'].' - Chybové hlášení', $Error);
    75         // Show error message
    76         if($Config['Web']['ShowPHPError'] == true)
    77         {
    78             echo('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>'."\n".
    79       '<meta http-equiv="Content-Language" content="cs">'."\n".
    80       '<meta http-equiv="Content-Type" content="text/html; charset='.$this->Encoding.'"></head><body>'."\n".
    81       'Došlo k vnitřní chybě!<br/> O chybě byl uvědoměn správce webu a chybu brzy odstraní.<br/><br/>');
    82           echo('<pre>'.$Error.'</pre><br/>');                   // V případě ladění chybu i zobraz
    83           echo('</body></html>');
    84         }
    85     if((E_ERROR | E_PARSE) & $Number) die();
    86   }
    8785  }
    8886}
  • trunk/Common/Form/Form.php

    r500 r501  
    11<?php
    22
    3 include_once(dirname(__FILE__).'/../form_classes.php');
    4 include_once(dirname(__FILE__).'/Database.php');
     3include_once(dirname(__FILE__).'/../Database.php');
     4include_once(dirname(__FILE__).'/Types/Type.php');
    55
    66class Form
    77{
    8   var $Definition = array();
    9   var $Values = array();
    10   var $OnSubmit = '';
    11  
    12   function __construct($ClassName)
    13   { 
    14     global $FormClasses;
    15 
    16     $this->Definition = &$FormClasses[$ClassName];
    17   }
     8  var $FormManager;
     9  var $Definition;
     10  var $Values;
     11  var $OnSubmit;
     12  var $Database;
     13 
     14  function __construct($FormManager)
     15  {     
     16    $this->FormManager = &$FormManager;
     17    $this->Database = $FormManager->Database;
     18    $this->Definition = array();
     19    $this->Values = array();   
     20    $this->OnSubmit = '';
     21  }
     22 
     23  function SetClass($Name)
     24  {
     25    $this->Definition = &$this->FormManager->Classes[$Name];   
     26  }
    1827
    1928  function ShowViewForm()
    2029  {
    21     global $Database, $FormTypes, $System;
    22 
    2330    $Table = array(
    2431      //'Header' => array('Položka', 'Hodnota'),
     
    2633    );
    2734    foreach($this->Definition['Items'] as $Index => $Item)
    28     if(!array_key_exists($Item['Type'], $FormTypes) or
    29     (array_key_exists($Item['Type'], $FormTypes) and ($FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    30     {
    31       if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
    32         if(array_key_exists($Item['Type'], $FormTypes))
    33         {           
    34           if(!array_key_exists($Item['Type'], $System->Type->TypeDefinitionList))
    35             $System->Type->RegisterType($Item['Type'], '', $FormTypes[$Item['Type']]);
    36           if($FormTypes[$Item['Type']]['Type'] == 'Reference')
    37             $UseType = 'OneToMany';
    38           else if($FormTypes[$Item['Type']]['Type'] == 'Enumeration')
     35    if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     36    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     37    ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
     38    {
     39      if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
     40        if(array_key_exists($Item['Type'], $this->FormManager->FormTypes))
     41        {           
     42          if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
     43            $this->FormManager->Type->RegisterType($Item['Type'], '', $this->FormManager->FormTypes[$Item['Type']]);
     44          if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
     45            $UseType = 'OneToMany';
     46          else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    3947            $UseType = 'Enumeration';
    4048        } else $UseType = $Item['Type'];           
    41       $Edit = $System->Type->ExecuteTypeEvent($UseType, 'OnView',
     49      $Edit = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnView',
    4250        array('Value' => $this->Values[$Index], 'Name' => $Index,
    4351        'Type' => $Item['Type'], 'Values' => $this->Values));
    4452      if(array_key_exists('Suffix', $Item)) $Edit .= ' '.$Item['Suffix'];
    45       if(!$System->Type->IsHidden($UseType))
     53      if(!$this->FormManager->Type->IsHidden($UseType))
    4654        array_push($Table['Rows'], array($Item['Caption'].':', $Edit));
    4755    }
     
    6270  function ShowEditBlock($Context = '')
    6371  {
    64     global $Database, $FormTypes, $System;
    65 
    6672    $Hidden = '';
    6773    $IsHidden = false;
     
    7581      if(!array_key_exists('ReadOnly', $Item)) $Item['ReadOnly'] = false;
    7682    if($Item['ReadOnly'] == false)
    77     if(!array_key_exists($Item['Type'], $FormTypes) or
    78     (array_key_exists($Item['Type'], $FormTypes) and ($FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
     83    if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     84    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     85    ($$this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    7986    {
    8087      if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
     
    8491          else unset($Parameters['Null']);
    8592
    86         if(array_key_exists($Item['Type'], $FormTypes))
    87         {           
    88           if(!array_key_exists($Item['Type'], $System->Type->TypeDefinitionList))
    89             $System->Type->RegisterType($Item['Type'], '',
    90               $FormTypes[$Item['Type']]);
    91           if($FormTypes[$Item['Type']]['Type'] == 'Reference')
     93        if(array_key_exists($Item['Type'], $this->FormManager->FormTypes))
     94        {           
     95          if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
     96            $this->FormManager->Type->RegisterType($Item['Type'], '',
     97              $this->FormManager->FormTypes[$Item['Type']]);
     98          if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
    9299          {
    93100            $UseType = 'OneToMany';
    94           } else if($FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    95             $UseType = 'Enumeration';
    96         } else $UseType = $Item['Type'];
    97         $Edit = $System->Type->ExecuteTypeEvent($UseType, 'OnEdit', $Parameters);
     101          } else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
     102            $UseType = 'Enumeration';
     103        } else $UseType = $Item['Type'];
     104        $Edit = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnEdit', $Parameters);
    98105        if(array_key_exists('Suffix', $Item)) $Edit .= $Item['Suffix'];
    99106
    100       if(!$System->Type->IsHidden($UseType))
     107      if(!$this->FormManager->Type->IsHidden($UseType))
    101108          array_push($Table['Rows'], array($Item['Caption'].':', $Edit));
    102109      else $Hidden .= $Edit;
     
    110117  function LoadValuesFromDatabase($Id)
    111118  {
    112     global $Database, $FormTypes, $System;
    113 
    114     $DbResult = $Database->query('SELECT T.* FROM '.$this->Definition['Table'].' AS T WHERE T.Id='.$Id);
     119    $DbResult = $this->Database->query('SELECT T.* FROM '.$this->Definition['Table'].' AS T WHERE T.Id='.$Id);
    115120    $DbRow = $DbResult->fetch_array();
    116121    foreach($this->Definition['Items'] as $Index => $Item)
    117     if(!array_key_exists($Item['Type'], $FormTypes) or
    118     (array_key_exists($Item['Type'], $FormTypes) and ($FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    119     {
    120       if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
    121         if(array_key_exists($Item['Type'], $FormTypes))
    122         {           
    123           if(!array_key_exists($Item['Type'], $System->Type->TypeDefinitionList))
    124             $System->Type->RegisterType($Item['Type'], '',
    125               $FormTypes[$Item['Type']]);
    126           if($FormTypes[$Item['Type']]['Type'] == 'Reference')
    127             $UseType = 'OneToMany';
    128           else if($FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    129             $UseType = 'Enumeration';
    130         } else $UseType = $Item['Type'];
    131         $this->Values[$Index] = $System->Type->ExecuteTypeEvent($UseType, 'OnLoadDb',
     122    if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     123    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     124    ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
     125    {
     126      if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
     127        if(array_key_exists($Item['Type'], $this->FormManager->FormTypes))
     128        {           
     129          if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
     130            $this->FormManager->Type->RegisterType($Item['Type'], '',
     131              $this->FormManager->FormTypes[$Item['Type']]);
     132          if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
     133            $UseType = 'OneToMany';
     134          else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
     135            $UseType = 'Enumeration';
     136        } else $UseType = $Item['Type'];
     137        $this->Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoadDb',
    132138            array('Value' => $DbRow[$Index], 'Name' => $Index,
    133139            'Type' => $Item['Type'], 'Values' => $this->Values));
     
    139145  function SaveValuesToDatabase($Id)
    140146  {
    141     global $Database, $FormTypes, $System;
    142 
    143147    $Values = array();
    144148    foreach($this->Definition['Items'] as $Index => $Item)
     
    146150      if(!array_key_exists('ReadOnly', $Item)) $Item['ReadOnly'] = false;
    147151      if($Item['ReadOnly'] == false)
    148     if(!array_key_exists($Item['Type'], $FormTypes) or
    149     (array_key_exists($Item['Type'], $FormTypes) and ($FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
     152    if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     153    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     154    ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    150155    {
    151156      if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
     
    153158          'Type' => $Item['Type'], 'Values' => $this->Values);
    154159     
    155         if(array_key_exists($Item['Type'], $FormTypes))
    156         {           
    157           if(!array_key_exists($Item['Type'], $System->Type->TypeDefinitionList))
    158             $System->Type->RegisterType($Item['Type'], '',
    159               $FormTypes[$Item['Type']]);
    160           if($FormTypes[$Item['Type']]['Type'] == 'Reference')
     160        if(array_key_exists($Item['Type'], $this->FormManager->FormTypes))
     161        {           
     162          if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
     163            $this->FormManager->Type->RegisterType($Item['Type'], '',
     164              $this->FormManager->FormTypes[$Item['Type']]);
     165          if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
    161166          {
    162167            $UseType = 'OneToMany';
    163168          }
    164           else if($FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    165             $UseType = 'Enumeration';
    166         } else $UseType = $Item['Type'];
    167         $Values[$Index] = $System->Type->ExecuteTypeEvent($UseType, 'OnSaveDb', $Parameters);
     169          else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
     170            $UseType = 'Enumeration';
     171        } else $UseType = $Item['Type'];
     172        $Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnSaveDb', $Parameters);
    168173        if(($Item['Type'] == 'Password') and ($Values[$Index] == '')) unset($Values[$Index]);
    169174       
     
    174179    {
    175180      $Values['Id'] = $Id;
    176       $DbResult = $Database->insert($this->Definition['Table'], $Values);
     181      $DbResult = $this->Database->insert($this->Definition['Table'], $Values);
    177182    } else
    178       $DbResult = $Database->update($this->Definition['Table'], 'Id='.$Id, $Values);
     183      $DbResult = $this->Database->update($this->Definition['Table'], 'Id='.$Id, $Values);
    179184    //echo($Database->LastQuery);
    180185  }
     
    187192  function LoadValuesFromFormBlock($Context = '')
    188193  {
    189     global $Database, $FormTypes, $System;
    190 
    191194    if($Context != '') $Context = $Context.'-';
    192195    $Values = array();
    193196    foreach($this->Definition['Items'] as $Index => $Item)
    194     if((!array_key_exists($Item['Type'], $FormTypes) or
    195     (array_key_exists($Item['Type'], $FormTypes) and
    196     ($FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) and
     197    if((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     198    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     199    ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) and
    197200    (!array_key_exists('ReadOnly', $Item) or
    198201    (array_key_exists('ReadOnly', $Item) and
     
    200203    {
    201204      //if(array_key_exists($Context.$Index, $_POST))
    202         if(array_key_exists($Item['Type'], $FormTypes))
    203         {           
    204           if(!array_key_exists($Item['Type'], $System->Type->TypeDefinitionList))
    205             $System->Type->RegisterType($Item['Type'], '',
    206               $FormTypes[$Item['Type']]);
    207           if($FormTypes[$Item['Type']]['Type'] == 'Reference')
    208             $UseType = 'OneToMany';
    209           else if($FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    210             $UseType = 'Enumeration';
    211         } else $UseType = $Item['Type'];
    212         $Values[$Index] = $System->Type->ExecuteTypeEvent($UseType, 'OnLoad',
     205        if(array_key_exists($Item['Type'], $this->FormManager->FormTypes))
     206        {           
     207          if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
     208            $this->FormManager->Type->RegisterType($Item['Type'], '',
     209              $this->FormManager->FormTypes[$Item['Type']]);
     210          if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
     211            $UseType = 'OneToMany';
     212          else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
     213            $UseType = 'Enumeration';
     214        } else $UseType = $Item['Type'];
     215        $Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoad',
    213216          array('Name' => $Index, 'Type' => $Item['Type'], 'Values' => $this->Values));
    214217    }
     
    246249}
    247250
    248 function ShowEditTable($ClassName, $Values)
    249 {
     251class FormManager
     252{
     253  var $Classes;
     254  var $FormTypes;
     255  var $Database;
     256  var $Type;
     257 
     258  function __construct($Database)
     259  {
     260    $this->Database = &$Database;
     261    $this->Classes = array();
     262    $this->FormTypes = array();
     263    $this->Type = new Type($this);
     264  }
     265 
     266  function RegisterClass($Name, $Class)
     267  {
     268    $this->Classes[$Name] = $Class;
     269  }
     270 
     271  function UnregisterClass($Name)
     272  {
     273    unset($this->Classes[$Name]);
     274  }
    250275}
    251276
  • trunk/Common/Form/Types/Base.php

    r484 r501  
    33class TypeBase
    44{
    5   var $System;
     5  var $FormManager;
     6  var $Database;
    67  var $DatabaseCompareOperators = array();
    78  var $Hidden;
    89
    9   function __construct($System)
     10  function __construct($FormManager)
    1011  {
    11     $this->System = &$System;
     12    $this->FormManager = &$FormManager;
     13    $this->Database = &$FormManager->Database;
    1214    $this->Hidden = false;
    1315  }
  • trunk/Common/Form/Types/Enumeration.php

    r498 r501  
    77  function OnView($Item)
    88  {
    9     $Type = $this->System->Type->GetTypeDefinition($Item['Type']);
     9    $Type = $this->FormManager->Type->GetTypeDefinition($Item['Type']);
    1010    if(array_key_exists($Item['Value'], $Type['Parameters']['States']))
    1111      $Output = $Type['Parameters']['States'][$Item['Value']];
     
    1616  function OnEdit($Item)
    1717  {
    18     $Type = $this->System->Type->GetTypeDefinition($Item['Type']);
     18    $Type = $this->FormManager->Type->GetTypeDefinition($Item['Type']);
    1919    $Output = '<select name="'.$Item['Name'].'">';
    2020      if(array_key_exists('Null', $Item) and $Item['Null'])
  • trunk/Common/Form/Types/Hidden.php

    r484 r501  
    55class TypeHidden extends TypeBase
    66{
    7   function __construct($System)
     7  function __construct($FormManager)
    88  {
    9     parent::__construct($System);
     9    parent::__construct($FormManager);
    1010    $this->Hidden = true;
    1111  }
  • trunk/Common/Form/Types/OneToMany.php

    r483 r501  
    2525  {
    2626    $Output = '<select name="'.$Item['Name'].'">';
    27     $Type = $this->System->Type->TypeDefinitionList[$Item['Type']];
     27    $Type = $this->FormManager->Type->TypeDefinitionList[$Item['Type']];
    2828    if(array_key_exists('Condition', $Type['Parameters'])) $Where = ' WHERE '.$Type['Parameters']['Condition'];
    2929      else $Where = '';
     
    3535    if(array_key_exists('View', $Type['Parameters'])) $Table = $Type['Parameters']['View'];
    3636      else $Table = $Type['Parameters']['Table'];
    37     $DbResult = $this->System->Database->query('SELECT '.$Type['Parameters']['Name'].' AS `Name`,'.$Type['Parameters']['Id'].' AS `Id` FROM '.$Table.''.$Where.' ORDER BY `Name`');
     37    $DbResult = $this->Database->query('SELECT '.$Type['Parameters']['Name'].' AS `Name`,'.$Type['Parameters']['Id'].' AS `Id` FROM '.$Table.''.$Where.' ORDER BY `Name`');
    3838    while($DbRow = $DbResult->fetch_assoc())
    3939    {
  • trunk/Common/Form/Types/RandomHash.php

    r484 r501  
    55class TypeRandomHash extends TypeBase
    66{
    7   function __construct($System)
     7  function __construct($FormManager)
    88  {
    9     parent::__construct($System);
     9    parent::__construct($FormManager);
    1010    $this->Hidden = true;
    1111  }
  • trunk/Common/Form/Types/Type.php

    r500 r501  
    1616include(dirname(__FILE__).'/Hyperlink.php');
    1717include(dirname(__FILE__).'/Hidden.php');
    18 include(dirname(__FILE__).'/File/File.php');
     18include(dirname(__FILE__).'/File.php');
     19include(dirname(__FILE__).'/FileContent.php');
    1920include(dirname(__FILE__).'/GPS.php');
    2021include(dirname(__FILE__).'/IPv4Address.php');
     
    2425class Type
    2526{
    26   var $System;
     27  var $FormManager;
    2728  var $TypeDefinitionList;
    2829  var $Values;
    2930
    30   function __construct($System)
     31  function __construct($FormManager)
    3132  {
    32     $this->System = $System;
     33    $this->FormManager = &$FormManager;
    3334    $this->TypeDefinitionList = array
    3435    (
     
    5253      'Color' => array('Name' => 'Color', 'Class' => 'Color', 'ParentType' => '', 'Parameters' => array()),
    5354      'RandomHash' => array('Name' => 'RandomHash', 'Class' => 'RandomHash', 'ParentType' => '', 'Parameters' => array()),
     55      'FileContent' => array('Name' => 'FileContent', 'Class' => 'FileContent', 'ParentType' => '', 'Parameters' => array()),
    5456    );
    5557  }
     
    6163      $Type = $this->TypeDefinitionList[$TypeName];
    6264      $TypeClass = 'Type'.$Type['Class'];
    63       $TypeObject = new $TypeClass($this->System);
     65      $TypeObject = new $TypeClass($this->FormManager);
    6466      if(is_callable(array($TypeObject, $Event))) return($TypeObject->$Event($Parameters));
    6567        else return($TypeName.'->'.$Event.'('.serialize($Parameters).')');
     
    7375      $Type = $this->TypeDefinitionList[$TypeName];
    7476      $TypeClass = 'Type'.$Type['Class'];
    75       $TypeObject = new $TypeClass($this->System);
     77      $TypeObject = new $TypeClass($this->FormManager);
    7678      return($TypeObject->Hidden);
    7779    } else return(false);
     
    9294  }
    9395
     96  function UnregisterType($Name)
     97  {
     98    unset($this->TypeDefinitionList[$Name]);
     99    // TODO: remove dependent types
     100  }
     101 
    94102  function GetTypeDefinition($TypeName)
    95103  {
  • trunk/Common/Global.php

    r500 r501  
    2121include_once(dirname(__FILE__).'/User.php');
    2222include_once(dirname(__FILE__).'/Page.php');
    23 include_once(dirname(__FILE__).'/Forms.php');
    24 include_once(dirname(__FILE__).'/Types/Type.php');
     23include_once(dirname(__FILE__).'/Form/Form.php');
    2524include_once(dirname(__FILE__).'/File.php');
    2625include_once(dirname(__FILE__).'/../aktuality/news.php');
    2726include_once(dirname(__FILE__).'/../finance/bills.php');
    2827include_once(dirname(__FILE__).'/../finance/finance.php');
     28include_once(dirname(__FILE__).'/../form_classes.php');
     29
    2930 
    3031// Application modules
     
    5758    parent::__construct();
    5859    $this->Modules = array();
    59     $this->Type = new Type($this);
    6060    $this->Pages = array();
    6161    $this->ModuleManager = new AppModuleManager();
    6262    $this->FilesDir = '';
     63    $this->Database = new Database();
     64    $this->FormManager = new FormManager($this->Database);
    6365  } 
    6466 
     
    101103  function AddModule($Module)
    102104  {
    103     global $Database;
    104 
    105105    //echo('Přidávám modul '.get_class($Module).'<br />');
    106106    $Module->System = &$this;
    107     $Module->Database = &$Database;
     107    $Module->Database = &$this->Database;
    108108    $this->Modules[get_class($Module)] = $Module;
    109109  }
     
    166166 
    167167  if(!isset($Config)) die('Systém není nainstalován. Pokračujte v instalaci <a href="admin/install.php">zde</a>.');
    168  
    169168   
    170169  // SQL injection hack protection
     
    174173  if(isset($_SERVER['REMOTE_ADDR'])) session_start();
    175174
    176   $Database = new Database($Config['Database']['Host'], $Config['Database']['User'], $Config['Database']['Password'], $Config['Database']['Database']);
    177   $Database->Prefix = $Config['Database']['Prefix'];
    178   $Database->charset($Config['Database']['Charset']);
    179   $Database->ShowSQLError = $Config['Web']['ShowSQLError'];
    180   $Database->ShowSQLQuery = $Config['Web']['ShowSQLQuery'];
     175  $System = new System();
     176  $System->Config = $Config;
     177  $System->FilesDir = dirname(__FILE__).'/../'.$Config['Web']['UploadFileFolder'].'/';
     178  $System->Database->Connect($Config['Database']['Host'], $Config['Database']['User'], $Config['Database']['Password'], $Config['Database']['Database']);
     179  $System->Database->Prefix = $Config['Database']['Prefix'];
     180  $System->Database->charset($Config['Database']['Charset']);
     181  $System->Database->ShowSQLError = $Config['Web']['ShowSQLError'];
     182  $System->Database->ShowSQLQuery = $Config['Web']['ShowSQLQuery'];
    181183 
    182184  // Check database persistence structure
    183185  $UpdateManager = new UpdateManager();
    184   $UpdateManager->Database = &$Database;
     186  $UpdateManager->Database = &$System->Database;
    185187  $UpdateManager->Revision = $DatabaseRevision;
    186188  if(!$UpdateManager->IsInstalled()) die('Systém vyžaduje instalaci databáze.');
    187189  if(!$UpdateManager->IsUpToDate()) die('Systém vyžaduje aktualizaci databáze.');
    188190 
    189   $System = new System();
    190   $System->Config = $Config;
    191   $System->FilesDir = dirname(__FILE__).'/../'.$Config['Web']['UploadFileFolder'].'/';
    192   $System->Database = &$Database;
     191  // Init old modules
    193192  $System->AddModule(new Log());
    194193  $System->AddModule(new ErrorHandler());
     194  $System->Modules['ErrorHandler']->ShowErrors = $Config['Web']['ShowPHPError'];
    195195  $System->Modules['ErrorHandler']->Init();
    196196  $System->AddModule(new User());
     
    200200  $System->AddModule(new Finance());
    201201  $System->Modules['Finance']->LoadMonthParameters(0);
     202  RegisterFormClasses($System->FormManager);
    202203 
    203204  // Register new modules
  • trunk/Common/Page.php

    r494 r501  
    125125    foreach($ScriptNameParts as $ScriptNamePart)
    126126    {
    127       //echo($ScriptNamePart.'<br />');
    128127      if(array_key_exists($ScriptNamePart, $PathTreeItem))
    129128      {
  • trunk/Common/Update.php

    r493 r501  
    153153        if(isset($_SERVER['REMOTE_ADDR'])) session_start();
    154154   
    155         $Database = new Database($this->Config['Database']['Host'], $this->Config['Database']['User'],
     155        $Database = new Database();
     156        $Database->Connect($this->Config['Database']['Host'], $this->Config['Database']['User'],
    156157           $this->Config['Database']['Password'], $this->Config['Database']['Database']);
    157158        $Database->Prefix = $this->Config['Database']['Prefix'];
  • trunk/Common/Version.php

    r500 r501  
    11<?php
    22
    3 $Revision = 500; // Subversion revision
    4 $DatabaseRevision = 500;
    5 $ReleaseTime = '2013-03-03';
     3$Revision = 501; // Subversion revision
     4$DatabaseRevision = 501;
     5$ReleaseTime = '2013-03-10';
    66
    77?>
Note: See TracChangeset for help on using the changeset viewer.