<?php 
/*
============================
Administraatori paneel
"Aktiivsed oksjonid" vaade
Admin. paneeli avavaade
============================
*/
include "config.php";
include "header.php";
?>
<h2 class="decorated"><span>Aktiivsed 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 'objects/oksjon.class.php';

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

$oksjon = new Oksjon($db);

// Loeme andmebaasist kõik aktiivsed oksjonid ja kuvame need tabelisse
$stmt = $oksjon->readAktiivsed($page, $from_record_num, $records_per_page);
$num = $stmt->rowCount();

if($num>0){

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

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

    extract($row);

    echo "<tr>";
    echo "<td width=15%>{$nimi}</td>";
    echo "<td width=5%>{$alghind}</td>";
    echo "<td width=5%>{$hetkehind}</td>";
    echo "<td width=5%>{$pakkumised}</td>";
    echo "<td width=15%>{$algusaeg}</td>";
    echo "<td width=15%>{$lopuaeg}</td>";

    echo "<td width=\"25%\"><center>";
    echo "<a href='".ADMIN_HTTP."internetioksjon/oksjon_detailid.php?id={$id}' class='btn btn-default left-margin'>Detailid</a>
    <a href='".ADMIN_HTTP."internetioksjon/update_oksjon.php?id={$id}' class='btn btn-default left-margin'>Muuda</a> ";
    echo "<a delete-id='{$id}' page='oksjon' class='btn btn-default delete-object'>Kustuta</a>
  </center>";
  echo "</td>";
  echo "</tr>";

}

echo "</table>";

$page_dom = basename(__FILE__);
include_once ADMIN_ROOT . 'internetioksjon/paging_oksjon.php';
}

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

<script src="<?php echo HTTP ?>js/delete.js"></script>
<?php
include(ADMIN_ROOT . "footer.php");
?>