<?php
/*
======================
Administraatori paneel
Hindamise vorm
======================
*/
include "config.php";
include ADMIN_ROOT . "header.php";
include ADMIN_ROOT . 'objects/hinnatav.class.php';
include ADMIN_ROOT . 'objects/pilt.class.php';

?>
<!-- jQuery Gallery CSS -->
<link rel="stylesheet" href="<?php echo HTTP; ?>css/stylesheet.css">
<link rel="stylesheet" href="<?php echo HTTP; ?>scripts/fancybox/jquery.fancybox.css">
<?php

// Pärime GET-ga hinnatava eseme ID
$hinnatava_id = $_GET['id'];

// Loome andmebaasi ühenduse
$database = new Database();
$db       = $database->dbConnection();

$hinnatav     = new Hinnatav($db);
$hinnatav->id = $hinnatava_id;
$hinnatav->lugemineID();

$img = new Pilt($db);

echo "<center><h2 class='decorated'><span>Hindamine</span></h2>";
echo "<br/><br/><table class='table table-hover table-responsive table-bordered'>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>Aeg</th>";
echo "<th>Nimi</th>";
echo "<th>E-mail</th>";
echo "<th>Kirjeldus</th>";
echo "</tr>";
echo "<tr>";
echo "<td>{$hinnatav->id}</td>";
echo "<td>{$hinnatav->aeg}</td>";
echo "<td>{$hinnatav->nimi}</td>";
echo "<td>{$hinnatav->email}</td>";
echo "<td>{$hinnatav->kirjeldus}</td>";
echo "</tr>";
echo "</table>";

// Pärime andmebaasist hinnatava eseme pildid ID järgi
$stmt_img = $img->readAllHinnatav($hinnatav->id);

echo '<div class="previews">';

while ($row_img = $stmt_img->fetch(PDO::FETCH_ASSOC)) {
    extract($row_img);
    echo "<a href='#' data-full='" . HTTP . "admin/img/hindamine/{$hinnatava_id}/{$nimi}'><img src='" . HTTP . "admin/img/hindamine/{$hinnatava_id}/thumbnail_{$nimi}' height='50' width='50'/></a>";
}

$stmt_kaanefoto = $img->readOneHinnatav($hinnatav->id);
$row_kaanefoto  = $stmt_kaanefoto->fetch(PDO::FETCH_ASSOC);
extract($row_kaanefoto);

echo "</div>";
echo "<div class='full'>
<img src='" . HTTP . "admin/img/hindamine/{$hinnatava_id}/{$nimi}' /></div>
<script src='" . HTTP . "scripts/fancybox/jquery.fancybox.js?v=2.1.4'></script> 
<script src='" . HTTP . "js/pildid1.js'></script><script src='" . HTTP . "js/pildid2.js'></script>";
?>

<br/><br/>
<div class="col-md-6 col-md-offset-3">
    <form id='hindamine_vastus' action='<?php echo ADMIN_HTTP;?>hindamine/' method='post' border='0' enctype="multipart/form-data">
        <div class="form-group">
          <label for="vastus">Vastus:</label>
          <textarea class="form-control" rows="5" name="vastus" id="vastus"></textarea>
      </div>
      <input type="hidden" name="email" id="email" value='<?php
      echo $hinnatav->email;
      ?>'>
      <input type="hidden" name="pealkiri" id="pealkiri" value='Eseme(te) hindamine'>
      <input type="hidden" name="id" id="id" value='<?php
      echo $hinnatav->id;
      ?>'>
      <a href='<?php
      echo ADMIN_HTTP;
      ?>hindamine/' class='btn btn-default'><span class='glyphicon glyphicon-chevron-left'></span>&nbsp;Tagasi nimekirja</a>
      <button type='submit' class='btn btn-primary'>Saada vastus</button>
  </form>
</div>
</center>
<?php
include ADMIN_ROOT . "footer.php";
?>