<?php 
/*
====================================
Administraatori paneel
Kataloogi esemete nimekirja kuvamine
====================================
*/
include "config.php";
include ADMIN_ROOT . "header.php";
?>

<?php

$kataloogi_id = $_GET['id'];

include_once ROOT . 'db/dbconfig.php';
include_once ADMIN_ROOT . 'objects/ese.class.php';
include_once ADMIN_ROOT . 'objects/kataloog.class.php';

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

$kataloog = new Kataloog($db);
$kataloog->id = $kataloogi_id;
$kataloog->readInfo();

echo "<h2 class='decorated'><span>{$kataloog->nimi}</span></h2>";

// Loeme kõik kataloogi kuuluvad esemed ning kuvame need tabelisse
$ese = new Ese($db);
$ese->kataloogi_id = $kataloogi_id;
$stmt = $ese->loeKataloogist();
$num = $stmt->rowCount();


if($num>0){

  echo "<br/><br/><table class='table table-hover table-responsive table-bordered'>";
  echo "<tr>";
  echo "<th>ID</th>";
  echo "<th>Nimi</th>";
  echo "<th>Kirjeldus</th>";
  echo "<th>Alghind</th>";
    echo "<th>Eelpakkumised</th>";
  echo "<th style='text-align:center;'>Tegevus</th>";
  echo "</tr>";

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

    extract($row);
    $kirjelduse_eelvaade = substr($kirjeldus, 0, 25);
    echo "<tr>";
    echo "<td>{$id}</td>";
    echo "<td>{$nimi}</td>";
    echo "<td>{$kirjelduse_eelvaade}...</td>";
    echo "<td>{$alghind}</td>";
    echo "<td>{$eelpakkumised}</td>";
    echo "<td width=\"25%\">";
    echo "<center>
    <a href='ese_detailid.php?id={$id}' class='btn btn-default left-margin'>Detailid</a>
    <a href='update_ese.php?id={$id}' class='btn btn-default left-margin'>Muuda</a> ";
    echo "<a delete-id='{$id}' page='saal' class='btn btn-default delete-object'>Kustuta</a>
    </center>";
    echo "</td>";
    echo "</tr>";

  }
  echo "</table>";
}

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

<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> 
<script src="<?php echo HTTP ?>js/delete.js"></script>
<?php

include ADMIN_ROOT . "footer.php";
?>