<?php
/*
===========================
Kasutaja paneel
"Jälgitavad oksjonid" vaade
===========================
*/
include 'config.php';
session_start();
include_once ROOT . 'db/dbconfig.php';
require_once ROOT . 'admin/objects/kasutaja.class.php';

$user_home = new Kasutaja();

include ROOT . "header.php";
include_once ROOT . 'db/dbconfig.php';

$database = new Database();
$db = $database->dbConnection();

$kasutaja = $_SESSION['userSession'];

?>

<div class="container">
    <div class="row">

        <?php
        include "kasutaja-nav.php";
        ?>

        <div class="col-md-9">
           <h3 class="decorated"><span>Jälgitavad oksjonid</span></h3><br />

           <?php
            // Loeme kõik kasutaja jälgimisnimekirjas olevad internetioksjonid
           $sql = "SELECT oksjonid.id, nimi, hetkehind, lopuaeg FROM oksjonid, jalgitavad WHERE oksjonid.id = jalgitavad.oksjoni_id AND jalgitavad.kasutaja_id = $kasutaja ORDER BY lopuaeg ASC";

           // Kuvame andmed tabelisse
           echo "<br/><table class='table table-hover table-responsive table-bordered'>";
           echo "<tr>";
           echo "<th width='10%'>ID</th>";
           echo "<th>Nimi</th>";
           echo "<th>Lõpuaeg</th>";
           echo "<th width='30%'><center>Hetkehind</center></th>";
           echo "</tr>";
           foreach ($db->query($sql) as $row) {
            echo "<tr>";
            echo "<td>".$row["id"]."</td>";
            echo "<td><a href='".HTTP."internetioksjon/oksjon.php?id=".$row["id"]."'>".$row["nimi"]."</a></td>";
            echo "<td>".$row["lopuaeg"]."</td>";
            echo "<td><center>";
            echo $row["hetkehind"]."€";
            echo "</center></td>";
            echo "</tr>";
        }
        echo "</table><br/>";
        ?>
    </div>
</div>
</div>

<?php
include ROOT . "footer.php";
?>