<?php 
/*
============================
Administraatori paneel
Kataloogi lisamine
============================
*/
include "config.php";
include ADMIN_ROOT . "header.php";
?>
<!-- DATEPICKER -->
<script type="text/javascript" src="<?php echo HTTP ?>scripts/moment/min/moment.min.js"></script>
<script type="text/javascript" src="<?php echo HTTP ?>js/bootstrap.min.js"></script>
<script type="text/javascript" src="<?php echo HTTP ?>scripts/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js"></script>
<link rel="stylesheet" href="<?php echo HTTP ?>scripts/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css" />

<?php

include_once ROOT . 'db/dbconfig.php';

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

// Kui kataloogi lisamise vorm on esitatud, POST käsitlemine
if($_POST){
  include_once ADMIN_ROOT . 'objects/kataloog.class.php';
  $kataloog = new kataloog($db);
  
  $kataloog->nimi=$_POST['nimi'];
  $kataloog->aeg = $_POST['aeg'];
  
    // Loome uue kataloogi
  if($kataloog->create()){
    echo "<div class=\"alert alert-success alert-dismissable\">";
    echo "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>";
    echo "Kataloogi lisamine õnnestus.";
    echo "</div>";
  }
  
  else{
    echo "<div class=\"alert alert-danger alert-dismissable\">";
    echo "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>";
    echo "Kataloogi lisamine ebaõnnestus.";
    echo "</div>";
  }
}
?>

<h2 class='decorated'><span>Kataloogi lisamine</span></h2><br /><br />
<form id='create-kataloog-form' action='kataloogi_lisamine.php' method='post' border='0' enctype="multipart/form-data">
  <table class='table table-hover table-responsive table-bordered'>
    <tr>
      <td style="width: 10%">Nimi</td>
      <td><input style="width: 48.5%" type='text' name='nimi' class='form-control' required /></td>
    </tr>
    <td>Aeg</td>
    <td>
      <div class="row">
        <div class='col-sm-6'>

          <script type="text/javascript">

            $(function () {
              $('#datetimepicker').datetimepicker({
                format: 'YYYY-MM-DD HH:mm'
              });
            });
            var today = new Date();
          </script>

          <div class='input-group date' id='datetimepicker'>
            <?php
            date_default_timezone_set('Europe/Tallinn');
            $t=time();
            $aeg = date('Y-m-d H:i', $t);
            echo "
            <input name='aeg' type='text' class='form-control' value='{$aeg}' required />";
            ?>
            <span class="input-group-addon">
              <span class="glyphicon glyphicon-calendar"></span>
            </span>
          </div></div>

        </div>

      </td>
    </tr>
    <tr>
      <td></td>
      <td rowspan="2" colspan="2">                
        <button type='submit' class='btn btn-primary'>
          <span class='glyphicon glyphicon-plus'></span> Loo kataloog
        </button>
        <a href='kataloogid.php' class='btn btn-default'><span class="glyphicon glyphicon-chevron-left"></span>&nbsp;Tagasi nimekirja</a>
      </td>
    </tr>
  </table>
</form>

</div></div>

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