Index: trunk/Application.php
===================================================================
--- trunk/Application.php	(revision 64)
+++ trunk/Application.php	(revision 64)
@@ -0,0 +1,34 @@
+<?php
+
+class Application
+{
+  function Start()
+  {
+    global $Config, $Database;
+
+    $FileName = dirname(__FILE__).'/config.php';
+    if(file_exists($FileName)) include_once($FileName);
+    else {
+      die('Configuration file "'.$FileName.'" not found.');
+    }
+
+    session_start();
+
+    $ErrorHandler = new ErrorHandler();
+    $ErrorHandler->ShowError = $Config['Web']['ShowError'];
+    $ErrorHandler->Start();
+
+    $Database = new Database();
+    $Database->Connect($Config['Database']['Host'], $Config['Database']['User'],
+      $Config['Database']['Password'], $Config['Database']['Database']);
+    $Database->Prefix = $Config['Database']['Prefix'];
+    $Database->charset($Config['Database']['Charset']);
+    $Database->ShowSQLError = $Config['Web']['ShowSQLError'];
+    $Database->ShowSQLQuery = $Config['Web']['ShowSQLQuery'];
+
+    // SQL injection hack protection
+    foreach($_POST as $Index => $Item) $_POST[$Index] = addslashes($Item);
+    foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($Item);
+
+  }
+}
Index: trunk/Global.php
===================================================================
--- trunk/Global.php	(revision 63)
+++ trunk/Global.php	(revision 64)
@@ -1,10 +1,4 @@
 <?php
 
-session_start();
-$FileName = dirname(__FILE__).'/config.php';
-if(file_exists($FileName)) include_once($FileName);
-else {
-  die('Configuration file "'.$FileName.'" not found.');
-}
 include_once('Version.php');
 include_once('Types.php');
@@ -12,20 +6,5 @@
 include_once('Packages/Common/Common.php');
 include_once('Measure.php');
-
-$PrefixMultiplier = new PrefixMultiplier();
-$ErrorHandler = new ErrorHandler();
-$ErrorHandler->ShowError = $Config['Web']['ShowError'];
-$ErrorHandler->Start();
-$Database = new Database();
-$Database->Connect($Config['Database']['Host'], $Config['Database']['User'],
-  $Config['Database']['Password'], $Config['Database']['Database']);
-$Database->Prefix = $Config['Database']['Prefix'];
-$Database->charset($Config['Database']['Charset']);
-$Database->ShowSQLError = $Config['Web']['ShowSQLError'];
-$Database->ShowSQLQuery = $Config['Web']['ShowSQLQuery'];
-
-// SQL injection hack protection
-foreach($_POST as $Index => $Item) $_POST[$Index] = addslashes($Item);
-foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($Item);
+include_once('Application.php');
 
 function HumanDate($Time)
Index: trunk/Graph.php
===================================================================
--- trunk/Graph.php	(revision 63)
+++ trunk/Graph.php	(revision 64)
@@ -3,195 +3,219 @@
 include('Global.php');
 
-if(array_key_exists('Debug', $_GET)) $Debug = $_GET['Debug'];
-  else $Debug = 0;
-
-if(!array_key_exists('From',$_GET)) die('Musíte zadat čas počátku');
-$StartTime = addslashes($_GET['From']);
-if(!array_key_exists('To',$_GET)) die('Musíte zadat čas konce');
-$EndTime = addslashes($_GET['To']);
-if($EndTime < $StartTime) $EndTime = $StartTime + 60;
-$TimeDifference = $EndTime - $StartTime;
-if(!array_key_exists('Measure', $_GET)) die('Musíte zadat měřenou veličinu');
-$MeasureId = addslashes($_GET['Measure']);
-if(!array_key_exists('Width', $_GET)) $Width = $DefaultWidth;
-else $Width = addslashes($_GET['Width']);
-if(!array_key_exists('Height', $_GET)) $Height = $DefaultHeight;
-else $Height = addslashes($_GET['Height']);
-if(!array_key_exists('Differential', $_GET)) $Differential = $Config['DefaultVariables']['Differential'];
-else $Differential = addslashes($_GET['Differential']);
-$VerticalLinesCount = round($Height / ($FontSize + 4));
-
-$StopWatchStart = GetMicrotime();
-
-$Measure = new Measure($Database);
-$Measure->Load($MeasureId);
-$Measure->DivisionCount = $Config['DivisionCount'];
-$Measure->LevelReducing = $Config['LevelReducing'];
-$Measure->MaxLevel = $Config['MaxLevel'];
-$Measure->ReferenceTime = $Config['ReferenceTime'];
-$Measure->Differential = $Differential;
-
-$Level = floor(log(($EndTime - $StartTime) / $Measure->DivisionCount / 60) / log($Measure->LevelReducing)) - 1;
-if($Level < 0) $Level = 0;
-if($Level > $Measure->MaxLevel) $Level = $Measure->MaxLevel;
-
-$Points = $Measure->GetValues($StartTime, $EndTime, $Level);
-
-if($Debug) echo('Points count: '.count($Points).'<br>');
-//if($Debug) foreach($Points as $Index => $Item)
-//  echo($Index.': '.$Item['min'].'<br>');
-
-// Calculate total max, avg, min value
-$MaxValue = -1000000000000000000;
-$AvgValue = 0;
-$MinValue = 1000000000000000000;
-foreach($Points as $Index => $Item)
+class MeasureGraph
 {
-  //$Points[$Index]['min'] =  $Points[$Index]['min'] / $Measure['Divider'];
-  //$Points[$Index]['avg'] =  $Points[$Index]['avg'] / $Measure['Divider'];
-  //$Points[$Index]['max'] =  $Points[$Index]['max'] / $Measure['Divider'];
-  if($Points[$Index]['avg'] > $MaxValue) $MaxValue = $Points[$Index]['avg'];
-  if($Points[$Index]['avg'] < $MinValue) $MinValue = $Points[$Index]['avg'];
-  if($Points[$Index]['max'] > $MaxValue) $MaxValue = $Points[$Index]['max'];
-  if($Points[$Index]['min'] < $MinValue) $MinValue = $Points[$Index]['min'];
-  $AvgValue = $AvgValue + $Points[$Index]['avg'];
-}
-//$MinValue = round($MinValue * $Measure['Divider']) / $Measure['Divider'];
-//$MaxValue = round($MaxValue * $Measure['Divider']) / $Measure['Divider'];
-$AvgValue = $AvgValue / count($Points); //round(* $Measure['Divider']) / $Measure['Divider'];
-
-// Generate polygon and recalculate y values to fit graph height
-$PointsMin = array(0, $Height - 1);
-$PointsAvg = array(0, $Height - 1);
-$PointsMax = array(0, $Height - 1);
-if(($MaxValue - $MinValue) == 0) $MaxValue = $MinValue + 1;
-{
-  foreach($Points as $Index => $Item)
+  var $Database;
+  var $FontSize;
+  var $FontFileNameName;
+  var $ValueToImageHeigthCoefficient;
+  var $DefaultWidth;
+  var $DefaultHeight;
+
+  function __construct(Database $Database)
   {
-    $PointsMin[] = $Index * $Width / $Measure->DivisionCount;
-    $PointsMin[] = $Height - 1 - ($Points[$Index]['min'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $K;
-    $PointsAvg[] = $Index * $Width / $Measure->DivisionCount;
-    $PointsAvg[] = $Height - 1 - ($Points[$Index]['avg'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $K;
-    $PointsMax[] = $Index * $Width / $Measure->DivisionCount;
-    $PointsMax[] = $Height - 1 - ($Points[$Index]['max'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $K;
-    //echo($Index.' - '.$Item.' '.$Points[$Index].'<br>');
+    $this->Database = &$Database;
+    $this->DefaultWidth = 800;
+    $this->DefaultHeight = 200;
+    $this->FontSize = 10;
+    $this->FontFileName = './arial.ttf';
+    $this->ValueToImageHeigthCoefficient = 0.9;
+  }
+
+  function Render()
+  {
+    global $Config;
+
+    if(!array_key_exists('From',$_GET)) die('Musíte zadat čas počátku');
+    $StartTime = addslashes($_GET['From']);
+    if(!array_key_exists('To',$_GET)) die('Musíte zadat čas konce');
+    $EndTime = addslashes($_GET['To']);
+    if($EndTime < $StartTime) $EndTime = $StartTime + 60;
+    $TimeDifference = $EndTime - $StartTime;
+    if(!array_key_exists('Measure', $_GET)) die('Musíte zadat měřenou veličinu');
+    $MeasureId = addslashes($_GET['Measure']);
+    if(!array_key_exists('Width', $_GET)) $Width = $this->DefaultWidth;
+    else $Width = addslashes($_GET['Width']);
+    if(!array_key_exists('Height', $_GET)) $Height = $this->DefaultHeight;
+    else $Height = addslashes($_GET['Height']);
+    if(!array_key_exists('Differential', $_GET)) $Differential = $Config['DefaultVariables']['Differential'];
+    else $Differential = addslashes($_GET['Differential']);
+    $VerticalLinesCount = round($Height / ($this->FontSize + 4));
+
+    $PrefixMultiplier = new PrefixMultiplier();
+    $StopWatchStart = GetMicrotime();
+
+    $Measure = new Measure($this->Database);
+    $Measure->Load($MeasureId);
+    $Measure->DivisionCount = $Config['DivisionCount'];
+    $Measure->LevelReducing = $Config['LevelReducing'];
+    $Measure->MaxLevel = $Config['MaxLevel'];
+    $Measure->ReferenceTime = $Config['ReferenceTime'];
+    $Measure->Differential = $Differential;
+
+    $Level = floor(log(($EndTime - $StartTime) / $Measure->DivisionCount / 60) / log($Measure->LevelReducing)) - 1;
+    if($Level < 0) $Level = 0;
+    if($Level > $Measure->MaxLevel) $Level = $Measure->MaxLevel;
+
+    $Points = $Measure->GetValues($StartTime, $EndTime, $Level);
+
+    // Calculate total max, avg, min value
+    $MaxValue = -1000000000000000000;
+    $AvgValue = 0;
+    $MinValue = 1000000000000000000;
+    foreach($Points as $Index => $Item)
+    {
+      //$Points[$Index]['min'] =  $Points[$Index]['min'] / $Measure['Divider'];
+      //$Points[$Index]['avg'] =  $Points[$Index]['avg'] / $Measure['Divider'];
+      //$Points[$Index]['max'] =  $Points[$Index]['max'] / $Measure['Divider'];
+      if($Points[$Index]['avg'] > $MaxValue) $MaxValue = $Points[$Index]['avg'];
+      if($Points[$Index]['avg'] < $MinValue) $MinValue = $Points[$Index]['avg'];
+      if($Points[$Index]['max'] > $MaxValue) $MaxValue = $Points[$Index]['max'];
+      if($Points[$Index]['min'] < $MinValue) $MinValue = $Points[$Index]['min'];
+      $AvgValue = $AvgValue + $Points[$Index]['avg'];
+    }
+    //$MinValue = round($MinValue * $Measure['Divider']) / $Measure['Divider'];
+    //$MaxValue = round($MaxValue * $Measure['Divider']) / $Measure['Divider'];
+    $AvgValue = $AvgValue / count($Points); //round(* $Measure['Divider']) / $Measure['Divider'];
+
+    // Generate polygon and recalculate y values to fit graph height
+    $PointsMin = array(0, $Height - 1);
+    $PointsAvg = array(0, $Height - 1);
+    $PointsMax = array(0, $Height - 1);
+    if(($MaxValue - $MinValue) == 0) $MaxValue = $MinValue + 1;
+    {
+      foreach($Points as $Index => $Item)
+      {
+        $PointsMin[] = $Index * $Width / $Measure->DivisionCount;
+        $PointsMin[] = $Height - 1 - ($Points[$Index]['min'] - $MinValue) /
+          ($MaxValue - $MinValue) * $Height * $this->ValueToImageHeigthCoefficient;
+        $PointsAvg[] = $Index * $Width / $Measure->DivisionCount;
+        $PointsAvg[] = $Height - 1 - ($Points[$Index]['avg'] - $MinValue) /
+          ($MaxValue - $MinValue) * $Height * $this->ValueToImageHeigthCoefficient;
+        $PointsMax[] = $Index * $Width / $Measure->DivisionCount;
+        $PointsMax[] = $Height - 1 - ($Points[$Index]['max'] - $MinValue) /
+          ($MaxValue - $MinValue) * $Height * $this->ValueToImageHeigthCoefficient;
+      }
+    }
+    $PointsMin[] = $Width - 1;
+    $PointsMin[] = $Height - 1;
+    $PointsAvg[] = $Width - 1;
+    $PointsAvg[] = $Height - 1;
+    $PointsMax[] = $Width - 1;
+    $PointsMax[] = $Height - 1;
+    $PointsMin[] = $Width - 1;
+    $PointsMin[] = $Height - 1;
+    $PointsAvg[] = $Width - 1;
+    $PointsAvg[] = $Height - 1;
+    $PointsMax[] = $Width - 1;
+    $PointsMax[] = $Height - 1;
+
+    //array_unshift($Points, $Height - 1);
+    //array_unshift($Points, 0);
+    //$Points[] = $Width - 1;
+    //$Points[] = $Height - 1;
+
+    // Generate image
+    $Image = @imagecreate($Width, $Height);
+    $BackgroundColor = imagecolorallocate($Image, 255, 255, 255);
+    $Black = imagecolorallocate($Image, 0, 0, 0);
+    $White = imagecolorallocate($Image, 255, 255, 255);
+    $Gray = imagecolorallocate($Image, 200, 200, 200);
+    $DarkGray = imagecolorallocate($Image, 100, 100, 100);
+    $LightBlue = imagecolorallocate($Image, 150, 150, 255);
+    $Blue = imagecolorallocate($Image, 0, 0, 255);
+    $LightRed = imagecolorallocate($Image, 255, 150, 150);
+    $Red = imagecolorallocate($Image, 255, 0, 0);
+    $Green = imagecolorallocate($Image, 0, 200, 0);
+    $LightGreen = imagecolorallocate($Image, 150, 255, 150);
+
+    imagefilledpolygon($Image, $PointsMax, count($PointsMax) / 2, $LightRed);
+    imagefilledpolygon($Image, $PointsAvg, count($PointsAvg) / 2, $LightGreen);
+    imagefilledpolygon($Image, $PointsMin, count($PointsMin) / 2, $LightBlue);
+
+    $TimeMarks = array(1, 60, 60*60, 60*60*24, 60*60*24*7, 60*60*24*30,
+      60*60*24*365, 60*60*24*365*10);
+
+    $TimeRange = $EndTime - $StartTime;
+    $TimeMarksIndex = 0;
+    while(($TimeRange / $TimeMarks[$TimeMarksIndex]) > 1) $TimeMarksIndex += 1;
+    if($TimeMarksIndex < 2) $TimeMarksIndex = 2;
+    $MajorTimeMarks = $TimeMarks[$TimeMarksIndex - 1];
+    $MinorTimeMarks = $TimeMarks[$TimeMarksIndex - 2];
+
+    $TimeShift = $Measure->AlignTime($StartTime, $MajorTimeMarks) - $StartTime;
+    //imagestring($Image, 10, 40, 50, $TimeShift, $Black);
+
+    // Zobraz měřítko Y
+    $VerticalLinesDistance = $Height / $VerticalLinesCount;
+    for($I = 1; $I <= $VerticalLinesCount; $I++)
+    {
+      $Y = $Height - 1 - ($VerticalLinesDistance * $I);
+      for($X = 1; $X < $Width; $X = $X + 3) imagesetpixel($Image, $X, $Y, $Gray);
+      //imageline($Image, 30, $Y, $Width-1, $Y, IMG_COLOR_STYLED);
+    }
+
+    $TimeShift = $Measure->AlignTime($StartTime, $MinorTimeMarks) - $StartTime;
+
+    // Zobraz měřítko X
+    $LastTextEnd = 0;
+    for($Time = $StartTime; $Time < $EndTime; $Time += $MajorTimeMarks)
+    {
+      $X = round(($Time - $StartTime + $TimeShift) / $TimeRange * $Width) % $Width;
+      //imageline($Image, 30, $Y, $Width-1, $Y, IMG_COLOR_STYLED);
+      if(($MajorTimeMarks > 60*60*24)) $Text = date('j.n.Y', $Time + $TimeShift);
+        else $Text = date('j.n.Y G:i', $Time + $TimeShift);
+      $BoundBox = imagettfbbox($this->FontSize, 0, $this->FontFileName, $Text);
+      if($LastTextEnd < ($X - ($BoundBox[2] - $BoundBox[0] + 20) / 2))
+      {
+        for($Y = 0; $Y < $Height; $Y = $Y + 1) imagesetpixel($Image, $X, $Y, $Gray);
+        imagettftext($Image, $this->FontSize, 0, $X - ($BoundBox[2] - $BoundBox[0]) / 2,  $Height - 2, $Black, $this->FontFileName, $Text);
+        $LastTextEnd = $X + ($BoundBox[2] - $BoundBox[0]) / 2;
+      }
+      else for($Y=0; $Y < $Height; $Y = $Y + 3) imagesetpixel($Image, $X, $Y, $Gray);
+    }
+
+    // Popisky osy Y
+    for($I = 1; $I <= $VerticalLinesCount; $I++)
+    {
+      $Y = $Height - 1 - ($VerticalLinesDistance * $I);
+      //$Y = $Height - 1 - ($VerticalLinesDistance * $I / ($MaxValue - $MinValue) * $this->ValueToImageHeigthCoefficient * $Height);
+      $Text = $PrefixMultiplier->Add(round(($I * $VerticalLinesDistance / $Height /
+          $this->ValueToImageHeigthCoefficient * ($MaxValue - $MinValue) + $MinValue)),
+          $Measure->Data['Unit'], 3);
+      $BoundBox = imagettfbbox($this->FontSize, 0, $this->FontFileName, $Text);
+      if(($Y - ($BoundBox[5] - $BoundBox[1]) / 2) > 10)
+        imagettftext($Image, $this->FontSize, 0, 2,  $Y - ($BoundBox[5] - $BoundBox[1]) / 2, $Black, $this->FontFileName, $Text);
+    }
+    $GenerationTime = floor((GetMicrotime() - $StopWatchStart) * 1000  ) / 1000;
+
+    $Left = $Width - 10;
+    $Text = "    Max. ".$PrefixMultiplier->Add($MaxValue, $Measure->Data['Unit']);
+    $BoundingBox = imagettfbbox($this->FontSize, 0, $this->FontFileName, $Text);
+    $Left -= ($BoundingBox[2] - $BoundingBox[0]);
+    imagettftext($Image, $this->FontSize, 0, $Left, 14, $Red, $this->FontFileName, $Text);
+
+    $Text = "    Avg.  ".$PrefixMultiplier->Add($AvgValue, $Measure->Data['Unit'], 4);
+    $BoundingBox = imagettfbbox($this->FontSize, 0, $this->FontFileName, $Text);
+    $Left -= ($BoundingBox[2] - $BoundingBox[0]);
+    imagettftext($Image, $this->FontSize, 0, $Left, 14, $Green, $this->FontFileName, $Text);
+
+    $Text = "    Min.  ".$PrefixMultiplier->Add($MinValue, $Measure->Data['Unit']);
+    $BoundingBox = imagettfbbox($this->FontSize, 0, $this->FontFileName, $Text);
+    $Left -= ($BoundingBox[2] - $BoundingBox[0]);
+    imagettftext($Image, $this->FontSize, 0, $Left, 14, $Blue, $this->FontFileName, $Text);
+    //imagestring($Image, 2, 70, 20, 'Vygenerováno za '.$GenerationTime.' sekund', $Black);
+    //imagestring($Image, 2, 50, 30, 'Level: '.$Level, $Black);
+
+    imagettftext($Image, $this->FontSize, 0, 70, 14, $Black, $this->FontFileName, $Measure->Data['Description']);
+    imagerectangle($Image, 0, 0, $Width - 1, $Height - 1, $Black);   // Frame border
+    Header("Content-type: image/png");
+    Header("Cache-Control: no-cache"); // Dynamic graph - no cache
+    imagepng($Image);
+    imagedestroy($Image);
   }
 }
-$PointsMin[] = $Width - 1;
-$PointsMin[] = $Height - 1;
-$PointsAvg[] = $Width - 1;
-$PointsAvg[] = $Height - 1;
-$PointsMax[] = $Width - 1;
-$PointsMax[] = $Height - 1;
-$PointsMin[] = $Width - 1;
-$PointsMin[] = $Height - 1;
-$PointsAvg[] = $Width - 1;
-$PointsAvg[] = $Height - 1;
-$PointsMax[] = $Width - 1;
-$PointsMax[] = $Height - 1;
-
-
-//array_unshift($Points, $Height - 1);
-//array_unshift($Points, 0);
-//$Points[] = $Width - 1;
-//$Points[] = $Height - 1;
-
-// Generate image
-if(!$Debug)
-{
-  Header("Content-type: image/png");
-  Header("Cache-Control: no-cache");	// Dynamic graph - no cache
-  $Image = @imagecreate($Width, $Height);
-  $BackgroundColor = imagecolorallocate($Image, 255, 255, 255);
-  $Black = imagecolorallocate($Image, 0, 0, 0);
-  $White = imagecolorallocate($Image, 255, 255, 255);
-  $Gray = imagecolorallocate($Image, 200, 200, 200);
-  $DarkGray = imagecolorallocate($Image, 100, 100, 100);
-  $LightBlue = imagecolorallocate($Image, 150, 150, 255);
-  $Blue = imagecolorallocate($Image, 0, 0, 255);
-  $LightRed = imagecolorallocate($Image, 255, 150, 150);
-  $Red = imagecolorallocate($Image, 255, 0, 0);
-  $Green = imagecolorallocate($Image, 0, 200, 0);
-  $LightGreen = imagecolorallocate($Image, 150, 255, 150);
-
-  imagefilledpolygon($Image, $PointsMax, count($PointsMax) / 2, $LightRed);
-  imagefilledpolygon($Image, $PointsAvg, count($PointsAvg) / 2, $LightGreen);
-  imagefilledpolygon($Image, $PointsMin, count($PointsMin) / 2, $LightBlue);
-
-  $TimeMarks = array(1, 60, 60*60, 60*60*24, 60*60*24*7, 60*60*24*30, 60*60*24*365, 60*60*24*365*10);
-
-  $TimeRange = $EndTime - $StartTime;
-  $TimeMarksIndex = 0;
-  while(($TimeRange / $TimeMarks[$TimeMarksIndex]) > 1) $TimeMarksIndex += 1;
-  if($TimeMarksIndex < 2) $TimeMarksIndex = 2;
-  $MajorTimeMarks = $TimeMarks[$TimeMarksIndex - 1];
-  $MinorTimeMarks = $TimeMarks[$TimeMarksIndex - 2];
-
-  $TimeShift = $Measure->AlignTime($StartTime, $MajorTimeMarks) - $StartTime;
-  //imagestring($Image, 10, 40, 50, $TimeShift, $Black);
-
-  // Zobraz měřítko Y
-  $VerticalLinesDistance = $Height / $VerticalLinesCount;
-  for($I=1; $I<=$VerticalLinesCount; $I++)
-  {
-    $Y = $Height - 1 - ($VerticalLinesDistance * $I);
-    for($X=1; $X < $Width; $X = $X + 3) imagesetpixel($Image, $X, $Y, $Gray);
-    //imageline($Image, 30, $Y, $Width-1, $Y, IMG_COLOR_STYLED);
-  }
-
-  $TimeShift = $Measure->AlignTime($StartTime, $MinorTimeMarks) - $StartTime;
-
-  // Zobraz měřítko X
-  $LastTextEnd = 0;
-  for($Time = $StartTime; $Time < $EndTime; $Time += $MajorTimeMarks)
-  {
-    $X = round(($Time - $StartTime + $TimeShift) / $TimeRange * $Width) % $Width;
-    //imageline($Image, 30, $Y, $Width-1, $Y, IMG_COLOR_STYLED);
-    if(($MajorTimeMarks > 60*60*24)) $Text = date('j.n.Y', $Time + $TimeShift);
-      else $Text = date('j.n.Y G:i', $Time + $TimeShift);
-    $BoundBox = imagettfbbox($FontSize, 0, $FontFile, $Text);
-    if($LastTextEnd < ($X - ($BoundBox[2] - $BoundBox[0] + 20) / 2))
-    {
-      for($Y=0; $Y < $Height; $Y = $Y + 1) imagesetpixel($Image, $X, $Y, $Gray);
-      imagettftext($Image, $FontSize, 0, $X - ($BoundBox[2] - $BoundBox[0]) / 2,  $Height - 2, $Black, $FontFile, $Text);
-      $LastTextEnd = $X + ($BoundBox[2] - $BoundBox[0]) / 2;
-    }
-    else for($Y=0; $Y < $Height; $Y = $Y + 3) imagesetpixel($Image, $X, $Y, $Gray);
-  }
-
-  // Popisky osy Y
-  for($I = 1; $I <= $VerticalLinesCount; $I++)
-  {
-    $Y = $Height - 1 - ($VerticalLinesDistance * $I);
-    //$Y = $Height - 1 - ($VerticalLinesDistance * $I / ($MaxValue - $MinValue) * $K * $Height);
-    $Text = $PrefixMultiplier->Add(round(($I * $VerticalLinesDistance / $Height /
-      $K * ($MaxValue - $MinValue) + $MinValue)), $Measure->Data['Unit'], 3);
-    $BoundBox = imagettfbbox($FontSize, 0, $FontFile, $Text);
-    if(($Y - ($BoundBox[5] - $BoundBox[1]) / 2) > 10)
-      imagettftext($Image, $FontSize, 0, 2,  $Y - ($BoundBox[5] - $BoundBox[1]) / 2, $Black, $FontFile, $Text);
-  }
-  $GenerationTime = floor((GetMicrotime() - $StopWatchStart) * 1000  ) / 1000;
-
-  $Left = $Width - 10;
-  $Text = "    Max. ".$PrefixMultiplier->Add($MaxValue, $Measure->Data['Unit']);
-  $BoundingBox = imagettfbbox($FontSize, 0, $FontFile, $Text);
-  $Left -= ($BoundingBox[2] - $BoundingBox[0]);
-  imagettftext($Image, $FontSize, 0, $Left, 14, $Red, $FontFile, $Text);
-
-  $Text = "    Avg.  ".$PrefixMultiplier->Add($AvgValue, $Measure->Data['Unit'], 4);
-  $BoundingBox = imagettfbbox($FontSize, 0, $FontFile, $Text);
-  $Left -= ($BoundingBox[2] - $BoundingBox[0]);
-  imagettftext($Image, $FontSize, 0, $Left, 14, $Green, $FontFile, $Text);
-
-  $Text = "    Min.  ".$PrefixMultiplier->Add($MinValue, $Measure->Data['Unit']);
-  $BoundingBox = imagettfbbox($FontSize, 0, $FontFile, $Text);
-  $Left -= ($BoundingBox[2] - $BoundingBox[0]);
-  imagettftext($Image, $FontSize, 0, $Left, 14, $Blue, $FontFile, $Text);
-  //imagestring($Image, 2, 70, 20, 'Vygenerováno za '.$GenerationTime.' sekund', $Black);
-  //imagestring($Image, 2, 50, 30, 'Level: '.$Level, $Black);
-
-  imagettftext($Image, $FontSize, 0, 70, 14, $Black, $FontFile, $Measure->Data['Description']);
-  imagerectangle($Image, 0, 0, $Width - 1, $Height - 1, $Black);   // Frame border
-  imagepng($Image);
-  imagedestroy($Image);
-}
+
+$Application = new Application();
+$Application->Start();
+$Graph = new MeasureGraph($Database);
+$Graph->Render();
Index: trunk/Measure.php
===================================================================
--- trunk/Measure.php	(revision 63)
+++ trunk/Measure.php	(revision 64)
@@ -14,5 +14,5 @@
   var $DivisionCount;
 
-  function __construct($Database)
+  function __construct(Database $Database)
   {
     $this->Id = 0;
Index: trunk/Version.php
===================================================================
--- trunk/Version.php	(revision 63)
+++ trunk/Version.php	(revision 64)
@@ -1,4 +1,4 @@
 <?php
 
-$Revision = 63;
+$Revision = 64;
 $ReleaseTime = strtotime('2016-01-01');
Index: trunk/add.php
===================================================================
--- trunk/add.php	(revision 63)
+++ trunk/add.php	(revision 64)
@@ -2,4 +2,7 @@
 
 include('Global.php');
+
+$Application = new Application();
+$Application->Start();
 
 if(array_key_exists('MeasureId', $_GET) and array_key_exists('Value', $_GET))
Index: trunk/admin.php
===================================================================
--- trunk/admin.php	(revision 63)
+++ trunk/admin.php	(revision 64)
@@ -1,4 +1,7 @@
 <?php
 include('Global.php');
+
+$Application = new Application();
+$Application->Start();
 
 if(array_key_exists('Operation', $_GET)) $Operation = $_GET['Operation']; else $Operation = '';
@@ -6,17 +9,17 @@
 {
   case 'Add':
-    $Output = ShowAdd();  
+    $Output = ShowAdd();
     break;
   case 'Delete':
-    $Output = ShowDelete();  
+    $Output = ShowDelete();
     break;
   case 'Edit':
-    $Output = ShowEdit();  
+    $Output = ShowEdit();
     break;
   case 'RebuildCache':
-    $Output = ShowRebuildCache();  
+    $Output = ShowRebuildCache();
     break;
   default:
-    $Output = ShowNone();  
+    $Output = ShowNone();
 }
 ShowPage($Output);
@@ -36,5 +39,5 @@
   }
   $Output = '<h3>Seznam měření</h3>'.Table($Table).MakeLink('?Operation=Add', 'Přidat');
-  return($Output); 
+  return($Output);
 }
 
@@ -62,5 +65,5 @@
   $Measure = $DbResult->fetch_array();
 
-  RebuildMeasureCache($Measure);  
-  echo('Dokončeno<br>');         
+  RebuildMeasureCache($Measure);
+  echo('Dokončeno<br>');
 }
Index: trunk/index.php
===================================================================
--- trunk/index.php	(revision 63)
+++ trunk/index.php	(revision 64)
@@ -2,203 +2,246 @@
 include('Global.php');
 
-$Debug = 0;
-
-function EditTime($Time)
+class MainView
 {
-  global $Months;
-
-  $Output = '<form style="display: inline;" action="?Operation=SetTime&amp;Time='.$Time.'" method="post">';
-  $TimeParts = getdate($_SESSION[$Time]);
-
-  // Day selection
-  $Output .= '<select name="Day">';
-  for($I = 1; $I < 32; $I++)
-  {
-    if($I == $TimeParts['mday']) $Selected = ' selected="1"'; else $Selected = '';
-    $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
-  }
-  $Output .= '</select>. ';
-
-  // Month selection
-  $Output .= '<select name="Month">';
-  foreach($Months as $Index => $Month)
-  {
-    if($Index == $TimeParts['mon']) $Selected = ' selected="1"'; else $Selected = '';
-    if($Index > 0) $Output .= '<option value="'.$Index.'"'.$Selected.'>'.$Month.'</option>';
-  }
-  $Output .= '</select>. ';
-
-  // Year selection
-  $Output .= '<select name="Year">';
-  for($I = 2000; $I <= date("Y"); $I++)
-  {
-    if($I == $TimeParts['year']) $Selected = ' selected="1"'; else $Selected = '';
-    $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
-  }
-  $Output .= '</select> &nbsp;&nbsp; ';
-
-  // Hour selection
-  $Output .= '<select name="Hour">';
-  for($I = 0; $I < 24; $I++)
-  {
-    if($I == $TimeParts['hours']) $Selected = ' selected="1"'; else $Selected = '';
-    $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
-  }
-  $Output .= '</select> : ';
-
-  // Minute selection
-  $Output .= '<select name="Minute">';
-  for($I = 0; $I < 60; $I++)
-  {
-    if($I == $TimeParts['minutes']) $Selected = ' selected="1"'; else $Selected = '';
-    $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
-  }
-  $Output .= '</select> ';
-
-  $Output .= '<input type="submit" value="Nastavit">';
-  $Output .= '</form>';
-  $Output .= ' <form style="display: inline;" action="?Operation=SetTimeNow&amp;Time='.$Time.'" method="post">';
-  $Output .= '<input type="submit" value="Aktuální čas">';
-  $Output .= '</form>';
-
-  return($Output);
+  var $Months;
+  var $GrafTimeRanges;
+
+  function __construct($Database)
+  {
+    $this->Database = &$Database;
+    $this->Months = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září',
+      'Říjen', 'Listopad', 'Prosinec');
+
+    $this->GrafTimeRanges = array(
+      'hour' => array(
+        'caption' => 'Hodina',
+        'period' => 3600,
+      ),
+      'day' => array(
+        'caption' => 'Den',
+        'period' => 3600 * 24,
+      ),
+      'week' => array(
+        'caption' => 'Týden',
+        'period' => 3600 * 24 * 7,
+      ),
+      'month' => array(
+        'caption' => 'Měsíc',
+        'period' => 3600 * 24 * 30,
+      ),
+      'year' => array(
+        'caption' => 'Rok',
+        'period' => 3600 * 24 * 365,
+      ),
+      'years' => array(
+        'caption' => 'Desetiletí',
+        'period' => 3600 * 24 * 365 * 10,
+      ),
+    );
+  }
+
+  function EditTime($Time)
+  {
+    $Output = '<form style="display: inline;" action="?Operation=SetTime&amp;Time='.$Time.'" method="post">';
+    $TimeParts = getdate($_SESSION[$Time]);
+
+    // Day selection
+    $Output .= '<select name="Day">';
+    for($I = 1; $I < 32; $I++)
+    {
+      if($I == $TimeParts['mday']) $Selected = ' selected="1"'; else $Selected = '';
+      $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
+    }
+    $Output .= '</select>. ';
+
+    // Month selection
+    $Output .= '<select name="Month">';
+    foreach($this->Months as $Index => $Month)
+    {
+      if($Index == $TimeParts['mon']) $Selected = ' selected="1"'; else $Selected = '';
+      if($Index > 0) $Output .= '<option value="'.$Index.'"'.$Selected.'>'.$Month.'</option>';
+    }
+    $Output .= '</select>. ';
+
+    // Year selection
+    $Output .= '<select name="Year">';
+    for($I = 2000; $I <= date("Y"); $I++)
+    {
+      if($I == $TimeParts['year']) $Selected = ' selected="1"'; else $Selected = '';
+      $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
+    }
+    $Output .= '</select> &nbsp;&nbsp; ';
+
+    // Hour selection
+    $Output .= '<select name="Hour">';
+    for($I = 0; $I < 24; $I++)
+    {
+      if($I == $TimeParts['hours']) $Selected = ' selected="1"'; else $Selected = '';
+      $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
+    }
+    $Output .= '</select> : ';
+
+    // Minute selection
+    $Output .= '<select name="Minute">';
+    for($I = 0; $I < 60; $I++)
+    {
+      if($I == $TimeParts['minutes']) $Selected = ' selected="1"'; else $Selected = '';
+      $Output .= '<option value="'.$I.'"'.$Selected.'>'.$I.'</option>';
+    }
+    $Output .= '</select> ';
+
+    $Output .= '<input type="submit" value="Nastavit">';
+    $Output .= '</form>';
+    $Output .= ' <form style="display: inline;" action="?Operation=SetTimeNow&amp;Time='.$Time.'" method="post">';
+    $Output .= '<input type="submit" value="Aktuální čas">';
+    $Output .= '</form>';
+
+    return($Output);
+  }
+
+  /* Produce table with available measures */
+  function ShowMeasureTable()
+  {
+    $PrefixMultiplier = new PrefixMultiplier();
+    $Output = '<table border="1" cellspacing="0" cellpadding="2" style="font-size: small; margin: 0px auto;">';
+    $Output .= '<tr><th>Měřená veličina</th><th>Poslední hodnota</th><th>Čas posledního měření</th><th>Interpolace</th><th>Poznámky</th>';
+    if(array_key_exists('Debug', $_GET)) $Output .= '<th>Počet položek</th><th>Čas vykonání</th>';
+    $Output .= '</tr>';
+    $Result = $this->Database->select('measure', '*', '(Enabled=1) AND ((PermissionView="all") OR (PermissionView="'.gethostbyaddr($_SERVER['REMOTE_ADDR']).'")) ORDER BY Description');
+    while($Measure = $Result->fetch_array())
+    {
+      $StopWatchStart = GetMicrotime();
+      if(array_key_exists('Debug', $_GET))
+      {
+        $DbResult = $this->Database->select($Measure['DataTable'], 'COUNT(*)', 'measure='.$Measure['Id']);
+        $RowCount = $DbResult->fetch_array();
+        $RowCount = $RowCount[0];
+      }
+      $Result2 = $this->Database->select($Measure['DataTable'], 'time, avg', '(measure='.$Measure['Id'].') AND (level=0) ORDER BY time DESC LIMIT 1');
+      if($Result2->num_rows > 0)
+      {
+        $Row = $Result2->fetch_array();
+        $LastMeasureTime = date('j.n.Y G:i:s', MysqlDateTimeToTime($Row['time']));
+        $LastMeasureValue = $PrefixMultiplier->Add($Row['avg'], $Measure['Unit']);
+      } else {
+        $LastMeasureTime = '&nbsp;';
+        $LastMeasureValue = '&nbsp;';
+      }
+      if($Measure['Continuity'] == 1) $Interpolate = 'Ano'; else $Interpolate = 'Ne';
+      if($Measure['Info'] == '') $Measure['Info'] = '&nbsp;';
+      $GenerationTime = floor((GetMicrotime() - $StopWatchStart) * 1000  ) / 1000;
+      $Output .= '<tr><td style="text-align: left"><a href="?Measure='.$Measure['Id'].'&amp;Differential=0">'.$Measure['Description'].'</a></td><td align="center">'.$LastMeasureValue.'</td><td align="center">'.$LastMeasureTime.'</td><td align="center">'.$Interpolate.'</td><td>'.$Measure['Info'].'</td>';
+      if(array_key_exists('Debug', $_GET)) $Output .= '<td>'.$RowCount.'</td><td>'.$GenerationTime.'</td>';
+      $Output .= '</tr>';
+    }
+    $Output .= '</table>';
+    return($Output);
+  }
+
+  function ShowGraph()
+  {
+    $Output = '<strong>Graf:</strong><br>';
+    $Output .= '<img alt="Graf" src="Graph.php?Measure='.$_SESSION['Measure'].'&amp;From='.
+      $_SESSION['TimeStart'].'&amp;To='.$_SESSION['TimeEnd'].
+      '&amp;Width=750&amp;Height=200&amp;Differential='.
+      $_SESSION['Differential'].'" width="750" height="200"><br>';
+    $Output .= '<a href="?Measure='.$_SESSION['Measure'].'&amp;TimeStart='.
+      $_SESSION['TimeStart'].'&amp;TimeEnd='.$_SESSION['TimeEnd'].
+      '&amp;TimeSpecify=1&amp;Differential='.$_SESSION['Differential'].
+      '">Odkaz na vybraný graf</a><br/>';
+    return($Output);
+  }
+
+  function ShowTimeRange()
+  {
+    $Output = '';
+    if($_SESSION['TimeSpecify'] == 0)
+    {
+      $_SESSION['TimeEnd'] = time() - 60;
+      $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $this->GrafTimeRanges[$_SESSION['Period']]['period'];
+    }
+
+    if(!array_key_exists('Operation', $_GET)) $_GET['Operation'] = '';
+    switch($_GET['Operation'])
+    {
+      case 'SetTime':
+        if(array_key_exists('Time', $_GET) and array_key_exists('Month', $_POST) and array_key_exists('Day', $_POST) and
+        array_key_exists('Year', $_POST) and array_key_exists('Hour', $_POST) and array_key_exists('Minute', $_POST))
+        {
+          if(($_GET['Time'] == 'TimeStart') or ($_GET['Time'] == 'TimeEnd'))
+          {
+            $_SESSION[$_GET['Time']] = mktime($_POST['Hour'], $_POST['Minute'], 0, $_POST['Month'],
+                $_POST['Day'], $_POST['Year']);
+            $$_GET['Time'] = $_SESSION[$_GET['Time']];
+          }
+        }
+        break;
+      case 'SetTimeNow':
+        if(array_key_exists('Time', $_GET))
+        {
+          if(($_GET['Time'] == 'TimeStart') or ($_GET['Time'] == 'TimeEnd'))
+          {
+            $_SESSION[$_GET['Time']] = time();
+            $$_GET['Time'] = $_SESSION[$_GET['Time']];
+          }
+        }
+        break;
+
+    }
+    $Output .= '<strong>Časový úsek:</strong><br>';
+
+    // Show graph time range menu
+    if($_SESSION['TimeSpecify'] == 0)
+    {
+      $Output .= 'Délka úseku: ';
+      foreach($this->GrafTimeRanges as $Index => $Item)
+        $Output .= '<a href="?Period='.$Index.'">'.$Item['caption'].'</a>&nbsp;';
+      $Output .= '<br>';
+      $Output .= '<a href="?TimeSpecify=1">Přesnější nastavení...</a><br>';
+    } else {
+      $Output .= '<table cellspacing="0" cellpadding="2" border="0" style="margin: 0px auto;">';
+      $Output .= '<tr><td>Počátek:</td><td>'.$this->EditTime('TimeStart').'</td></tr>';
+      $Output .= '<tr><td>Konec:</td><td>'.$this->EditTime('TimeEnd').'</td></tr>';
+      $Output .= '</table>';
+      $Output .= '<a href="?TimeSpecify=0">Jednoduché nastavení...</a><br>';
+    }
+    $Output .= '<br/>';
+    return($Output);
+
+  }
+
+  function Show()
+  {
+    global $Config;
+
+    $Debug = 0;
+    foreach($Config['DefaultVariables'] as $Index => $Variable)
+    {
+      if(!array_key_exists($Index, $_SESSION)) $_SESSION[$Index] = $Variable;
+      if(array_key_exists($Index, $_GET)) $_SESSION[$Index] = $_GET[$Index];
+      if(array_key_exists($Index, $_POST)) $_SESSION[$Index] = $_POST[$Index];
+      //$$Index = $_SESSION[$Index];
+    }
+
+    $Output = '<div style="text-align: center"><div class="Title">'.$Config['Web']['Title'].'</div>';
+
+    $Result = $this->Database->select('measure', 'Id', '(`Enabled`=1) AND '.
+        '((`PermissionView`="all") OR (`PermissionView`="'.gethostbyaddr($_SERVER['REMOTE_ADDR']).'")) '.
+        'AND (`Id`='.($_SESSION['Measure'] * 1).')');
+    if($Result->num_rows == 0)
+      $_SESSION['Measure'] = $Config['DefaultVariables']['Measure'];
+
+    $Output .= $this->ShowTimeRange();
+    $Output .= $this->ShowGraph();
+    $Output .= '<br/>';
+    $Output .= $this->ShowMeasureTable();
+    $Output .= '</div>';
+
+    ShowPage($Output);
+  }
 }
 
-$Months = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září',
-  'Říjen', 'Listopad', 'Prosinec');
-
-$GrafTimeRanges = array(
-  'hour' => array(
-    'caption' => 'Hodina',
-    'period' => 3600,
-  ),
-  'day' => array(
-    'caption' => 'Den',
-    'period' => 3600 * 24,
-  ),
-  'week' => array(
-    'caption' => 'Týden',
-    'period' => 3600 * 24 * 7,
-  ),
-  'month' => array(
-    'caption' => 'Měsíc',
-    'period' => 3600 * 24 * 30,
-  ),
-  'year' => array(
-    'caption' => 'Rok',
-    'period' => 3600 * 24 * 365,
-  ),
-  'years' => array(
-    'caption' => 'Desetiletí',
-    'period' => 3600 * 24 * 365 * 10,
-  ),
-);
-
-foreach($Config['DefaultVariables'] as $Index => $Variable)
-{
-  if(!array_key_exists($Index, $_SESSION)) $_SESSION[$Index] = $Variable;
-  if(array_key_exists($Index, $_GET)) $_SESSION[$Index] = $_GET[$Index];
-  if(array_key_exists($Index, $_POST)) $_SESSION[$Index] = $_POST[$Index];
-  //$$Index = $_SESSION[$Index];
-}
-
-if($_SESSION['TimeSpecify'] == 0)
-{
-  $_SESSION['TimeEnd'] = time() - 60;
-  $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $GrafTimeRanges[$_SESSION['Period']]['period'];
-}
-
-$Output = '<div style="text-align: center"><div class="Title">'.$Config['Web']['Title'].'</div>';
-
-if(!array_key_exists('Operation', $_GET)) $_GET['Operation'] = '';
-switch($_GET['Operation'])
-{
-  case 'SetTime':
-    if(array_key_exists('Time', $_GET) and array_key_exists('Month', $_POST) and array_key_exists('Day', $_POST) and
-      array_key_exists('Year', $_POST) and array_key_exists('Hour', $_POST) and array_key_exists('Minute', $_POST))
-      {
-        if(($_GET['Time'] == 'TimeStart') or ($_GET['Time'] == 'TimeEnd'))
-        {
-          $_SESSION[$_GET['Time']] = mktime($_POST['Hour'], $_POST['Minute'], 0, $_POST['Month'],
-            $_POST['Day'], $_POST['Year']);
-          $$_GET['Time'] = $_SESSION[$_GET['Time']];
-        }
-      }
-    break;
-  case 'SetTimeNow':
-    if(array_key_exists('Time', $_GET))
-    {
-      if(($_GET['Time'] == 'TimeStart') or ($_GET['Time'] == 'TimeEnd'))
-      {
-        $_SESSION[$_GET['Time']] = time();
-        $$_GET['Time'] = $_SESSION[$_GET['Time']];
-      }
-    }
-    break;
-
-}
-$Output .= '<strong>Časový úsek:</strong><br>';
-
-// Show graph time range menu
-if($_SESSION['TimeSpecify'] == 0)
-{
-  $Output .= 'Délka úseku: ';
-  foreach($GrafTimeRanges as $Index => $Item)
-    $Output .= '<a href="?Period='.$Index.'">'.$Item['caption'].'</a>&nbsp;';
-  $Output .= '<br>';
-  $Output .= '<a href="?TimeSpecify=1">Přesnější nastavení...</a><br>';
-} else {
-  $Output .= '<table cellspacing="0" cellpadding="2" border="0" style="margin: 0px auto;">';
-  $Output .= '<tr><td>Počátek:</td><td>'.EditTime('TimeStart').'</td></tr>';
-  $Output .= '<tr><td>Konec:</td><td>'.EditTime('TimeEnd').'</td></tr>';
-  $Output .= '</table>';
-  $Output .= '<a href="?TimeSpecify=0">Jednoduché nastavení...</a><br>';
-}
-$Output .= '<br>';
-
-$Result = $Database->select('measure', 'Id', '(Enabled=1) AND ((PermissionView="all") OR (PermissionView="'.gethostbyaddr($_SERVER['REMOTE_ADDR']).'")) AND (Id='.($_SESSION['Measure'] * 1).')');
-if($Result->num_rows == 0)
-  $_SESSION['Measure'] = $Config['DefaultVariables']['Measure'];
-
-$Output .= '<strong>Graf:</strong><br>';
-$Output .= '<img alt="Graf" src="Graph.php?Measure='.$_SESSION['Measure'].'&amp;From='.$_SESSION['TimeStart'].'&amp;To='.$_SESSION['TimeEnd'].'&amp;Width=750&amp;Height=200&amp;Differential='.$_SESSION['Differential'].'" width="750" height="200"><br>';
-$Output .= '<a href="?Measure='.$_SESSION['Measure'].'&amp;TimeStart='.$_SESSION['TimeStart'].'&amp;TimeEnd='.$_SESSION['TimeEnd'].'&amp;TimeSpecify=1&amp;Differential='.$_SESSION['Differential'].'">Odkaz na vybraný graf</a><br>';
-
-$Output .= '<br>';
-
-// Table with available measures
-$Output .= '<table border="1" cellspacing="0" cellpadding="2" style="font-size: small; margin: 0px auto;">';
-$Output .= '<tr><th>Měřená veličina</th><th>Poslední hodnota</th><th>Čas posledního měření</th><th>Interpolace</th><th>Poznámky</th>';
-if(array_key_exists('Debug', $_GET)) $Output .= '<th>Počet položek</th><th>Čas vykonání</th>';
-$Output .= '</tr>';
-$Result = $Database->select('measure', '*', '(Enabled=1) AND ((PermissionView="all") OR (PermissionView="'.gethostbyaddr($_SERVER['REMOTE_ADDR']).'")) ORDER BY Description');
-while($Measure = $Result->fetch_array())
-{
-  $StopWatchStart = GetMicrotime();
-  if(array_key_exists('Debug', $_GET))
-  {
-    $DbResult = $Database->select($Measure['DataTable'], 'COUNT(*)', 'measure='.$Measure['Id']);
-    $RowCount = $DbResult->fetch_array();
-    $RowCount = $RowCount[0];
-  }
-  $Result2 = $Database->select($Measure['DataTable'], 'time, avg', '(measure='.$Measure['Id'].') AND (level=0) ORDER BY time DESC LIMIT 1');
-  if($Result2->num_rows > 0)
-  {
-    $Row = $Result2->fetch_array();
-    $LastMeasureTime = date('j.n.Y G:i:s', MysqlDateTimeToTime($Row['time']));
-    $LastMeasureValue = $PrefixMultiplier->Add($Row['avg'], $Measure['Unit']);
-  } else {
-    $LastMeasureTime = '&nbsp;';
-    $LastMeasureValue = '&nbsp;';
-  }
-  if($Measure['Continuity'] == 1) $Interpolate = 'Ano'; else $Interpolate = 'Ne';
-  if($Measure['Info'] == '') $Measure['Info'] = '&nbsp;';
-  $GenerationTime = floor((GetMicrotime() - $StopWatchStart) * 1000  ) / 1000;
-  $Output .= '<tr><td style="text-align: left"><a href="?Measure='.$Measure['Id'].'&amp;Differential=0">'.$Measure['Description'].'</a></td><td align="center">'.$LastMeasureValue.'</td><td align="center">'.$LastMeasureTime.'</td><td align="center">'.$Interpolate.'</td><td>'.$Measure['Info'].'</td>';
-  if(array_key_exists('Debug', $_GET)) $Output .= '<td>'.$RowCount.'</td><td>'.$GenerationTime.'</td>';
-  $Output .= '</tr>';
-}
-$Output .= '</table>';
-$Output .= '</div>';
-
-ShowPage($Output);
+$Application = new Application();
+$Application->Start();
+$MainView = new MainView($Database);
+$MainView->Show();
