Index: trunk/Application/Core.php
===================================================================
--- trunk/Application/Core.php	(revision 83)
+++ trunk/Application/Core.php	(revision 84)
@@ -36,5 +36,5 @@
     $ErrorHandler = new ErrorHandler();
     $ErrorHandler->ShowError = $Config['Web']['ShowError'];
-    $ErrorHandler->Start();
+    //$ErrorHandler->Start();
 
     try {
Index: trunk/Application/Version.php
===================================================================
--- trunk/Application/Version.php	(revision 83)
+++ trunk/Application/Version.php	(revision 84)
@@ -6,5 +6,5 @@
 // and system will need database update.
 
-$Revision = 79;
+$Revision = 84;
 $DatabaseRevision = 79;
-$ReleaseTime = strtotime('2016-12-31');
+$ReleaseTime = strtotime('2018-01-20');
Index: trunk/Modules/Measure/Page.php
===================================================================
--- trunk/Modules/Measure/Page.php	(revision 83)
+++ trunk/Modules/Measure/Page.php	(revision 84)
@@ -4,5 +4,5 @@
 {
   var $Months;
-  var $GrafTimeRanges;
+  var $GraphTimeRanges;
 
   function __construct(System $System)
@@ -12,5 +12,5 @@
       'Říjen', 'Listopad', 'Prosinec');
 
-    $this->GrafTimeRanges = array(
+    $this->GraphTimeRanges = array(
       'hour' => array(
         'caption' => 'Hodina',
@@ -37,5 +37,23 @@
         'period' => 3600 * 24 * 365 * 10,
       ),
+      'all' => array(
+        'caption' => 'Vše',
+        'period' => -1,
+      ),
     );
+    $this->Time = time();
+  }
+  
+  function GetTimeRange()
+  {
+    $Result = $this->GraphTimeRanges[$_SESSION['Period']]['period'];
+    if ($Result == -1)
+    {
+      $Measure = $this->LoadMeasure($_SESSION['Measure']);
+      $FirstValue = $this->GetFirstMeasure($Measure);
+      $LastValue = $this->GetLastMeasure($Measure);
+      $Result = $LastValue['Time'] - $FirstValue['Time'];
+    }
+    return $Result;
   }
 
@@ -98,5 +116,43 @@
     return($Output);
   }
-
+  
+  function GetFirstMeasure($Measure)
+  {
+    $Result2 = $this->Database->select($Measure['DataTable'], '`Time`, `Avg`', '(`Measure`='.$Measure['Id'].') AND (`Level`=0) ORDER BY `Time` ASC LIMIT 1');
+    if($Result2->num_rows > 0)
+    {
+      $Row = $Result2->fetch_array();
+      $LastMeasureTime = MysqlDateTimeToTime($Row['Time']);
+      $LastMeasureValue = $Row['Avg'];
+    } else {
+      $LastMeasureTime = $this->Time - $this->GetTimeRange();
+      $LastMeasureValue = 0;
+    }
+    return(array('Time' => $LastMeasureTime, 'Value' => $LastMeasureValue));
+  }
+
+  function GetLastMeasure($Measure)
+  {
+    $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 = MysqlDateTimeToTime($Row['Time']);
+      $LastMeasureValue = $Row['Avg'];
+    } else {
+      $LastMeasureTime = $this->Time;
+      $LastMeasureValue = 0;
+    }
+    return(array('Time' => $LastMeasureTime, 'Value' => $LastMeasureValue));
+  }
+  
+  function LoadMeasure($Id)
+  {
+    $DbResult = $this->Database->select('Measure', '*', '( `Enabled`=1) AND (`Id`='.$Id.') AND ((`PermissionView`="all") OR (`PermissionView`="'.
+      gethostbyaddr($_SERVER['REMOTE_ADDR']).'"))');    
+    $DbRow = $DbResult->fetch_array();
+    return $DbRow;
+  }
+  
   /* Produce table with available measures */
   function ShowMeasureTable()
@@ -107,5 +163,6 @@
     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`');
+    $Result = $this->Database->select('Measure', '*', '( `Enabled`=1) AND ((`PermissionView`="all") OR (`PermissionView`="'.
+      gethostbyaddr($_SERVER['REMOTE_ADDR']).'")) ORDER BY `Description`');
     while($Measure = $Result->fetch_array())
     {
@@ -113,14 +170,15 @@
       if(array_key_exists('Debug', $_GET))
       {
-        $DbResult = $this->Database->select($Measure['DataTable'], 'COUNT(*)', '`measure`='.$Measure['Id']);
+        $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');
+      $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']);
+        $LastMeasureTime = date('j.n.Y G:i:s', MysqlDateTimeToTime($Row['Time']));
+        $LastMeasureValue = $PrefixMultiplier->Add($Row['Avg'], $Measure['Unit']);
       } else {
         $LastMeasureTime = '&nbsp;';
@@ -130,6 +188,10 @@
       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><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>';
     }
@@ -155,9 +217,4 @@
   {
     $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'] = '';
@@ -180,5 +237,5 @@
           if(($_GET['Time'] == 'TimeStart') or ($_GET['Time'] == 'TimeEnd'))
           {
-            $_SESSION[$_GET['Time']] = time();
+            $_SESSION[$_GET['Time']] = $this->Time;
           }
         }
@@ -192,5 +249,5 @@
     {
       $Output .= 'Délka úseku: ';
-      foreach($this->GrafTimeRanges as $Index => $Item)
+      foreach($this->GraphTimeRanges as $Index => $Item)
         $Output .= '<a href="?Period='.$Index.'">'.$Item['caption'].'</a>&nbsp;';
       $Output .= '<br>';
@@ -203,8 +260,98 @@
       $Output .= '<a href="?TimeSpecify=0">Jednoduché nastavení...</a><br>';
     }
+    $Output .= 'Posun: <a href="?Move=LeftEnd">|&lt;</a> <a href="?Move=Left">&lt;</a> '.
+      '<a href="?Move=Right">&gt;</a> <a href="?Move=RightEnd">&gt;|</a> <a href="?Move=Now">Nyní</a><br>';
     $Output .= '<br/>';
     return($Output);
 
   }
+  
+  function HandleURL()
+  {
+    global $Config;
+    
+    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 (array_key_exists('Period', $_GET))
+    {
+      $_SESSION['Period'] = $_GET['Period'];
+      // Update time start according time period
+      if ($_SESSION['Period'] == 'all') 
+      {
+        $Measure = $this->LoadMeasure($_SESSION['Measure']);
+        $FirstValue = $this->GetFirstMeasure($Measure);
+        $LastValue = $this->GetLastMeasure($Measure);
+        $_SESSION['TimeStart'] = $FirstValue['Time'];
+        $_SESSION['TimeEnd'] = $LastValue['Time'];
+      } else
+      {
+        $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $this->GetTimeRange();
+      }
+    }
+    if (array_key_exists('TimeStart', $_GET))
+    {
+      $_SESSION['TimeStart'] = $_GET['TimeStart'];
+    }
+    if (array_key_exists('TimeEnd', $_GET))
+    {
+      $_SESSION['TimeStart'] = $_GET['TimeEnd'];
+    }
+    if (array_key_exists('Differential', $_GET))
+    {
+      $_SESSION['Differential'] = $_GET['Differential'];
+    }
+    if (array_key_exists('Measure', $_GET))
+    {
+      $_SESSION['Measure'] = $_GET['Measure'];
+    }
+    if (array_key_exists('TimeSpecify', $_GET))
+    {
+      if (($_SESSION['TimeSpecify'] == 1) and ($_GET['TimeSpecify'] == 0))
+      {
+        $_SESSION['TimeEnd'] = $this->Time - 60;
+        $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $this->GetTimeRange();
+      }
+      $_SESSION['TimeSpecify'] = $_GET['TimeSpecify'];
+    }
+    
+    if (array_key_exists('Move', $_GET))
+    {
+      $Move = $_GET['Move'];
+      if ($Move == 'Left') 
+      {
+        $_SESSION['TimeStart'] = $_SESSION['TimeStart'] - $this->GetTimeRange();
+        $_SESSION['TimeEnd'] = $_SESSION['TimeEnd'] - $this->GetTimeRange();
+      } else
+      if ($Move == 'Right') 
+      {
+        $_SESSION['TimeStart'] = $_SESSION['TimeStart'] + $this->GetTimeRange();
+        $_SESSION['TimeEnd'] = $_SESSION['TimeEnd'] + $this->GetTimeRange();
+      } else 
+      if ($Move == 'Now')
+      {
+        $_SESSION['TimeEnd'] = $this->Time - 60;
+        $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $this->GetTimeRange();
+      } else
+      if ($Move == 'LeftEnd')
+      {
+        $Measure = $this->LoadMeasure($_SESSION['Measure']);
+        $FirstValue = $this->GetFirstMeasure($Measure);
+        $_SESSION['TimeStart'] = $FirstValue['Time'];
+        $_SESSION['TimeEnd'] = $_SESSION['TimeStart'] + $this->GetTimeRange();
+      } else
+      if ($Move == 'RightEnd')
+      {
+        $Measure = $this->LoadMeasure($_SESSION['Measure']);
+        $LastValue = $this->GetLastMeasure($Measure);
+        $_SESSION['TimeEnd'] = $LastValue['Time'];
+        $_SESSION['TimeStart'] = $_SESSION['TimeEnd'] - $this->GetTimeRange();
+      }
+    }
+  }
 
   function Show()
@@ -213,17 +360,11 @@
 
     $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];
-    }
-
+    $this->HandleURL();
+    
     $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).')');
+      '((`PermissionView`="all") OR (`PermissionView`="'.gethostbyaddr($_SERVER['REMOTE_ADDR']).'")) '.
+      'AND (`Id`='.($_SESSION['Measure'] * 1).')');
     if($Result->num_rows == 0)
       $_SESSION['Measure'] = $Config['DefaultVariables']['Measure'];
