<h3> Zobrazit data za poslední: </h3>
  <form type="GET" action="/web/index.php">
  <input type="hidden" name="sekce" value="spotreba">
  <select onchange="this.form.submit()" name="platforma" size="1" style="border-style: groove; background-color: white;"> 
  <option value="den">Den
  <option value="mesic">Měsíc
  <option value="rok">Rok
  </select>
  </form>

<?php
$m = new Mysql();
$sql = "select z1.jmeno_zasuvky, z1.ID_zasuvky, max(z2.date) as date
        from zasuvky z1
        left join(
            select date, current, voltage, CHIP_ID
            from zasuvky_data
            order by date desc
        ) z2 on z1.ID_zasuvky = z2.CHIP_ID
        where z1.ID_uzivatele = ".$_SESSION['userID']."
        group by z1.jmeno_zasuvky";


$mysql_result1 = $m->dotaz($sql) or die('Query failed: ' . mysql_error());
if ($mysql_result1) {  
  
	echo("<table rules=rows>");
	echo("<tr><td align=\"left\"><b>JMÉNO ZÁSUVKY</b></td><td align=\"center\"><b>ID ZÁSUVKY</b></td><td align=\"center\"><b>ČAS POSLEDNÍHO ZÁZNAMU</b></td><td align=\"center\"><b>HODNOTA</b></td></tr>");

  while ($row = $m->podejRadek($mysql_result1)) {

        $sql = "SELECT current, voltage, date 
                FROM zasuvky_data
                where CHIP_ID = ".$row->ID_zasuvky."
                order by date desc";
        $mysql_result2 = $m->dotaz($sql) or die('Query failed: ' . mysql_error());   
             
             $bleh = 0;
             $date = -1;
             
        if(!isset($_POST['platforma']) OR $_POST['platforma'] == den){    
           $time = 24*60*60;
        }else if($_POST['platforma'] == mesic){    
           $time = 24*60*60*30;
        }else if($_POST['platforma'] == rok){    
           $time = 24*60*60*365;
        }
        
          while($row1 = $m->podejRadek($mysql_result2)){
                if($date = -1) $date = $row1->date;
                if($date-$row1->date > $time) break;
                
                $bleh += $row1->current * $row1->voltage;
                  
          }
        
  
	echo("<tr><td align=\"left\">$row->jmeno_zasuvky</td><td align=\"center\">$row->ID_zasuvky</td><td align=\"center\">$row->date</td><td>$bleh</td></tr>");
  
  }
	echo("</table>");
  
}
?>


