<?php 
/*
=================================
Administraatori paneel
Saalioksjoni eseme detailne vaade
=================================
*/
include "config.php";
include ADMIN_ROOT . "header.php";
include_once ROOT . 'db/dbconfig.php';
include_once ADMIN_ROOT . 'objects/ese.class.php';
include_once ADMIN_ROOT . 'objects/eelpakkumine.class.php';
include_once ADMIN_ROOT . 'objects/kasutaja.class.php';

$eseme_id = $_GET["id"];

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

$ese = new Ese($db);

$ese->id = $eseme_id;

$stmt = $ese->readOne();
// Loeme eseme kohta käiva informatsiooni andmebaasist ning kuvame tabelisse
echo "
<h2 class='decorated'><span>{$ese->nimi}</span></h2>
<br/><br/>
<table class='table table-hover table-responsive table-bordered'>
    <tr>
        <th>ID</th>
        <th>Nimi</th>
        <th>Kirjeldus</th>
        <th>Alghind</th>
        <th>Eelpakkumised</th>
    </tr>
    <tr>
        <td>{$ese->id}</td>
        <td>{$ese->nimi}</td>
        <td>{$ese->kirjeldus}</td>
        <td>{$ese->alghind}</td>
        <td>{$ese->eelpakkumised}</td>
    </tr>
</table>
";

// Saalioksjoni eseme kõikide eelpakkumiste kuvamine
echo "<br/>
<table class='table table-hover table-responsive table-bordered'>
    <tr>
        <th>Pakkuja ID</th>
        <th>Pakkuja</th>
        <th>Summa</th>
        <th>Aeg</th>
    </tr>
    ";

    $eelpakkumine = new Eelpakkumine($db);
    $eelpakkumine->eseme_id = $ese->id;
    $stmt = $eelpakkumine->readByEsemeID();

    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){

        extract($row);
        echo"<tr>
        <td width='10%'>{$kasutaja_id}</td>
        ";
        $kasutaja = new Kasutaja();
        $kasutaja->id = $kasutaja_id;
        $stmt_ = $kasutaja->loeAndmed();
        $row_ = $stmt_->fetch(PDO::FETCH_ASSOC);
        extract($row_);
        echo"<td width='20%'>{$eesnimi} {$perekonnanimi}</td>";
        extract($row);
        echo"
        <td width='20%'>{$summa}€</td>
        <td width='30%'>{$aeg}</td>
    </tr>";
}
echo"</table>
<button class=\"btn btn-large\" onclick=\"goBack()\"><span class=\"glyphicon glyphicon-chevron-left\"></span>&nbsp;Tagasi</button>";


?>
<script type="text/javascript" src="<?php echo HTTP ?>/js/backButton.js"></script> 
<?php

include ADMIN_ROOT . "footer.php";
?>