Changeset 67 for trunk


Ignore:
Timestamp:
Jan 3, 2016, 11:52:37 PM (9 years ago)
Author:
chronos
Message:
  • Added: Preparation for automatic database structure update.
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application.php

    r64 r67  
    33class Application
    44{
     5  var $Database;
     6
    57  function Start()
    68  {
    7     global $Config, $Database;
     9    global $Config, $DatabaseRevision;
    810
    911    $FileName = dirname(__FILE__).'/config.php';
     
    1921    $ErrorHandler->Start();
    2022
    21     $Database = new Database();
    22     $Database->Connect($Config['Database']['Host'], $Config['Database']['User'],
     23    $this->Database = new Database();
     24    $this->Database->Connect($Config['Database']['Host'], $Config['Database']['User'],
    2325      $Config['Database']['Password'], $Config['Database']['Database']);
    24     $Database->Prefix = $Config['Database']['Prefix'];
    25     $Database->charset($Config['Database']['Charset']);
    26     $Database->ShowSQLError = $Config['Web']['ShowSQLError'];
    27     $Database->ShowSQLQuery = $Config['Web']['ShowSQLQuery'];
     26    $this->Database->Prefix = $Config['Database']['Prefix'];
     27    $this->Database->charset($Config['Database']['Charset']);
     28    $this->Database->ShowSQLError = $Config['Web']['ShowSQLError'];
     29    $this->Database->ShowSQLQuery = $Config['Web']['ShowSQLQuery'];
    2830
    2931    // SQL injection hack protection
     
    3133    foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($Item);
    3234
     35    // Check database persistence structure
     36    $UpdateManager = new UpdateManager();
     37    $UpdateManager->Database = $this->Database;
     38    $UpdateManager->Revision = $DatabaseRevision;
     39    if(!$UpdateManager->IsInstalled()) die('Systém vyžaduje instalaci databáze.');
     40    if(!$UpdateManager->IsUpToDate()) die('Systém vyžaduje aktualizaci databáze.');
     41
    3342  }
    3443}
  • trunk/Global.php

    r64 r67  
    77include_once('Measure.php');
    88include_once('Application.php');
     9include_once('Update.php');
    910
    1011function HumanDate($Time)
  • trunk/Graph.php

    r64 r67  
    218218$Application = new Application();
    219219$Application->Start();
    220 $Graph = new MeasureGraph($Database);
     220$Graph = new MeasureGraph($this->Database);
    221221$Graph->Render();
  • trunk/Version.php

    r65 r67  
    11<?php
    22
    3 $Revision = 65;
    4 $ReleaseTime = strtotime('2016-01-01');
     3// Subversion revision have to be updated always to next revision number
     4// before commiting new changes.
     5// Database revision have to be updated if database structure is changed
     6// and system will need database update.
     7
     8$Revision = 67;
     9$DatabaseRevision = 67;
     10$ReleaseTime = strtotime('2016-01-03');
  • trunk/add.php

    r64 r67  
    1010  $MeasureId = addslashes($_GET['MeasureId']);
    1111  $Value = addslashes($_GET['Value']);
    12   $Measure = new Measure($Database);
     12  $Measure = new Measure($Application->Database);
    1313  $Measure->Load($MeasureId);
    1414  if(gethostbyaddr($_SERVER['REMOTE_ADDR']) == $Measure->Data['PermissionAdd'])
  • trunk/admin.php

    r64 r67  
    55$Application->Start();
    66
    7 if(array_key_exists('Operation', $_GET)) $Operation = $_GET['Operation']; else $Operation = '';
    8 switch($Operation)
     7class AdminPage
    98{
    10   case 'Add':
    11     $Output = ShowAdd();
    12     break;
    13   case 'Delete':
    14     $Output = ShowDelete();
    15     break;
    16   case 'Edit':
    17     $Output = ShowEdit();
    18     break;
    19   case 'RebuildCache':
    20     $Output = ShowRebuildCache();
    21     break;
    22   default:
    23     $Output = ShowNone();
     9  function __construct($Database)
     10  {
     11    $this->Database = &$Database;
     12  }
     13
     14  function Show()
     15  {
     16    if(array_key_exists('Operation', $_GET)) $Operation = $_GET['Operation']; else $Operation = '';
     17    switch($Operation)
     18    {
     19      case 'Add':
     20        $Output = $this->ShowAdd();
     21        break;
     22      case 'Delete':
     23        $Output = $this->ShowDelete();
     24        break;
     25      case 'Edit':
     26        $Output = $this->ShowEdit();
     27        break;
     28      case 'RebuildCache':
     29        $Output = $this->ShowRebuildCache();
     30        break;
     31      default:
     32        $Output = $this->ShowNone();
     33    }
     34    ShowPage($Output);
     35  }
     36
     37  function ShowNone()
     38  {
     39    $Table = array(
     40      'Header' => array('Název veličiny', 'Operace'),
     41      'Rows' => array(),
     42    );
     43
     44    $Result = $this->Database->select('measure', '*', '1 ORDER BY Description');
     45    while($Measure = $Result->fetch_array())
     46    {
     47      array_push($Table['Rows'], array($Measure['Description'], MakeLink('?Operation=Edit&amp;MeasureId='.$Measure['Id'], 'Editovat').' '.MakeLink('?Operation=Delete&amp;MeasureId='.$Measure['Id'], 'Odstranit').' '.MakeLink('?Operation=RebuildCache&amp;MeasureId='.$Measure['Id'], 'Přestavět cache')));
     48    }
     49    $Output = '<h3>Seznam měření</h3>'.Table($Table).MakeLink('?Operation=Add', 'Přidat');
     50    return($Output);
     51  }
     52
     53  function ShowEdit()
     54  {
     55    $DbResult = $this->Database->select('measure', '*', 'Id='.addslashes($_GET['MeasureId']));
     56    $Values = array();
     57    $Values = $DbResult->fetch_array();
     58    return($this->ShowEditTable('Measure', $Values));
     59  }
     60
     61  function ShowAdd()
     62  {
     63    $Values = array();
     64    return($this->ShowEditTable('Measure', $Values));
     65  }
     66
     67  function ShowRebuildCache()
     68  {
     69    echo("Vytvařím novou cache...<br>");
     70    $DbResult = $this->Database->select('measure', '*', 'Id='.addslashes($_GET['MeasureId']));
     71    $Measure = $DbResult->fetch_array();
     72
     73    $Measure->RebuildMeasureCache();
     74    echo('Dokončeno<br>');
     75  }
    2476}
    25 ShowPage($Output);
    26 
    27 function ShowNone()
    28 {
    29   global $Database;
    30   $Table = array(
    31     'Header' => array('Název veličiny', 'Operace'),
    32     'Rows' => array(),
    33   );
    34 
    35   $Result = $Database->select('measure', '*', '1 ORDER BY Description');
    36   while($Measure = $Result->fetch_array())
    37   {
    38     array_push($Table['Rows'], array($Measure['Description'], MakeLink('?Operation=Edit&amp;MeasureId='.$Measure['Id'], 'Editovat').' '.MakeLink('?Operation=Delete&amp;MeasureId='.$Measure['Id'], 'Odstranit').' '.MakeLink('?Operation=RebuildCache&amp;MeasureId='.$Measure['Id'], 'Přestavět cache')));
    39   }
    40   $Output = '<h3>Seznam měření</h3>'.Table($Table).MakeLink('?Operation=Add', 'Přidat');
    41   return($Output);
    42 }
    43 
    44 function ShowEdit()
    45 {
    46   global $Database;
    47   $DbResult = $Database->select('measure', '*', 'Id='.addslashes($_GET['MeasureId']));
    48   $Values = array();
    49   $Values = $DbResult->fetch_array();
    50   return(ShowEditTable('Measure', $Values));
    51 }
    52 
    53 function ShowAdd()
    54 {
    55   global $Database;
    56   $Values = array();
    57   return(ShowEditTable('Measure', $Values));
    58 }
    59 
    60 function ShowRebuildCache()
    61 {
    62   global $Database;
    63   echo("Vytvařím novou cache...<br>");
    64   $DbResult = $Database->select('measure', '*', 'Id='.addslashes($_GET['MeasureId']));
    65   $Measure = $DbResult->fetch_array();
    66 
    67   RebuildMeasureCache($Measure);
    68   echo('Dokončeno<br>');
    69 }
  • trunk/index.php

    r64 r67  
    244244$Application = new Application();
    245245$Application->Start();
    246 $MainView = new MainView($Database);
     246$MainView = new MainView($Application->Database);
    247247$MainView->Show();
Note: See TracChangeset for help on using the changeset viewer.