<?php
/*
===========================
Administraatori paneel
"Ootel oksjonid" vaade
===========================
*/
include "config.php";
include ADMIN_ROOT . "header.php";
?>
<h2 class="decorated"><span>Ootel oksjonid</span></h2>
<?php

$page = isset($_GET['page']) ? $_GET['page'] : 1;
$records_per_page = 10;
$from_record_num = ($records_per_page * $page) - $records_per_page;

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

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

$oksjon = new Oksjon($db);

// Loeme andmebaasist oksjonid, mis ei ole veel aktiivsed
$stmt = $oksjon->readOotel($page, $from_record_num, $records_per_page);
$num = $stmt->rowCount();

// Kuvame tulemused tabelisse
if($num>0){

  $kategooria = new Kategooria($db);

  echo "<br/><br/><table class='table table-hover table-responsive table-bordered'>";
  echo "<tr>";
  echo "<th>Nimi</th>";
  echo "<th>Kirjeldus</th>";
  echo "<th>Alghind</th>";
  echo "<th>Hetkehind</th>";
  echo "<th>Pakkumised</th>";
  echo "<th>Algusaeg</th>";
  echo "<th>Lõpuaeg</th>";
  echo "<th>Kategooria</th>";
  echo "<th style='text-align:center;'>Tegevus</th>";
  echo "</tr>";

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

    extract($row);

    echo "<tr>";
    echo "<td>{$nimi}</td>";
    echo "<td>{$kirjeldus}</td>";
    echo "<td>{$alghind}</td>";
    echo "<td>{$hetkehind}</td>";
    echo "<td>{$pakkumised}</td>";
    echo "<td>{$algusaeg}</td>";
    echo "<td>{$lopuaeg}</td>";
    echo "<td>";
    $kategooria->id = $kategooria_id;
    $kategooria->readName();
    echo $kategooria->nimi;
    echo "</td>";

    echo "<td>";
    echo "<a href='update_oksjon.php?id={$id}' class='btn btn-default left-margin'>Muuda</a> ";
    echo "<a delete-id='{$id}' class='btn btn-default delete-object'>Kustuta</a>";
    echo "</td>";
    echo "</tr>";
  }

  echo "</table>";

  include_once 'paging_ooteloksjonid.php';
}

else{
  echo "<br /><center>Ootel oksjonid puuduvad.</center>";
}
?>

<script src="<?php echo HTTP ?>js/delete.js"></script>

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