<?php

session_start();

$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_result = $m->dotaz($sql) or die('Query failed: ' . mysql_error());

if ($mysql_result) {  
  
	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></tr>");

  while ($row = $m->podejRadek($mysql_result)) {
  $vykon = $row->current * $row->voltage;
	echo("<tr><td align=\"left\">$row->jmeno_zasuvky</td><td align=\"center\">$row->ID_zasuvky</td><td align=\"center\">$row->date</td></tr>");
  }
	echo("</table>");
}

$sql = "SELECT rozliseni FROM setup WHERE ID_uzivatele = ".$_SESSION['userID']." ORDER BY `ID` DESC LIMIT 1";      
$mysql_result = $m->dotaz($sql) or die('Query failed: ' . mysql_error());
$rozliseni = $m->podejRadek($mysql_result);
?>


<br />
<h3>Nastavení rozlišení</h3>
Aktuální: <?php echo($rozliseni->rozliseni); ?><br />
<form method="post" action="/web/utils/nastavitrozliseni.php">
	<label>Nové: </label><input type="text" name="rozliseni" style="border-style: groove; background-color: white; position: absolute; left: 125px"><br /><br />
  <input type="submit" value="Nastavit" style="position: absolute; left: 175px">
</form>

<br />
<h3>Přidání/odebrání zásuvky</h3>
<form method="post" action="/web/utils/pridatzasuvku.php">
	<label>Jméno zásuvky: </label><input type="text" name="jmenoZasuvky1" style="border-style: groove; background-color: white; position: absolute; left: 125px"><br /><br />
	<label>ID zásuvky: </label><input type="text" name="IDZasuvky1" style="border-style: groove; background-color: white; position: absolute; left: 125px"><br /><br />
	<input type="submit" name="pridat" value="Přidat" style="position: absolute; left: 125px">
  <input type="submit" name="odebrat" value="Odebrat" style="position: absolute; left: 235px">
</form>

<?php
$sql = "select z1.jmeno_zasuvky, z1.ID_zasuvky, z2.current, max(z2.date) as date, z2.voltage
        from zasuvky z1
        inner 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";
?>