<?php 
/*
======================
Administraatori paneel
Oksjoni detailne vaade
======================
*/
include "config.php";
include ADMIN_ROOT . "header.php";

$oksjoni_id = $_GET["id"];

include_once ROOT . 'db/dbconfig.php';
include_once ADMIN_ROOT . 'objects/oksjon.class.php';
include_once ADMIN_ROOT . 'objects/kategooria.class.php';
include_once ADMIN_ROOT . 'objects/pakkumine.class.php';
include_once ADMIN_ROOT . 'objects/kasutaja.class.php';

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

$oksjon = new Oksjon($db);

$oksjon->id = $oksjoni_id;

$stmt = $oksjon->readOne();

$kategooria = new Kategooria($db);

echo "
<h2 class='decorated'><span>{$oksjon->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>Hetkehind</th>
        <th>Pakkumised</th>
        <th>Algusaeg</th>
        <th>Lõpuaeg</th>
    </tr>
    <tr>
        <td>{$oksjon->id}</td>
        <td>{$oksjon->nimi}</td>
        <td>{$oksjon->kirjeldus}</td>
        <td>{$oksjon->alghind}</td>
        <td>{$oksjon->hetkehind}</td>
        <td>{$oksjon->pakkumised}</td>
        <td>{$oksjon->algusaeg}</td>
        <td>{$oksjon->lopuaeg}</td>
    </tr>
</table>";


// Oksjoni kõikide pakkumiste 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>";

    $pakkumine = new Pakkumine($db);
    $pakkumine->oksjoni_id = $oksjon->id;
    $stmt = $pakkumine->readByAuctionID();

    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}€";
            if($automaat == 1){
              echo"&nbsp;<span class=\"glyphicon glyphicon-paperclip\"></span>";
          } else if($automaat == 2){
              echo"&nbsp;<span class=\"glyphicon glyphicon-flash\"></span>";
          }
          echo "</td>
          <td width='30%'>{$aeg}</td>
      </tr>

      ";
  }
  echo"</table>
  <span class=\"glyphicon glyphicon-paperclip\"></span>&nbsp;-&nbsp;automaatpakkumise seadmine&nbsp;&nbsp;|&nbsp;
  <span class=\"glyphicon glyphicon-flash\"></span>&nbsp;-&nbsp;automaatpakkumine
  <script type=\"text/javascript\" src=".HTTP."js/backButton.js></script>
  <br/><br/><button class=\"btn btn-large\" onclick=\"goBack()\"><span class=\"glyphicon glyphicon-chevron-left\"></span>&nbsp;Tagasi</button>";

  include(ADMIN_ROOT . "footer.php");
  ?>