<?php 
/*
======================
Administraatori paneel
Kategooria lisamine
======================
*/
include "config.php";
include ADMIN_ROOT . "header.php";
include_once ROOT . 'db/dbconfig.php';

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

// Esitatud vormi töötlemine
if($_POST){
    include_once ADMIN_ROOT.'objects/kategooria.class.php';
    $category = new Kategooria($db);

    $category->nimi=$_POST['nimi'];

    // Loome kategooria
    if($category->create()){
        echo "<div class=\"alert alert-success alert-dismissable\">";
        echo "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>";
        echo "Kategooria 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 "Kategooria lisamine ebaõnnestus.";
        echo "</div>";
    }
}
?>

<h2 class='decorated'><span>Kategooria lisamine</span></h2><br /><br />
<form id='create-category-form' action='kategooria_lisamine.php' method='post' border='0' enctype="multipart/form-data">
    <table class='table table-hover table-responsive table-bordered'>
        <tr>
            <td>Nimi</td>
            <td><input type='text' name='nimi' class='form-control' required /></td>
        </tr>
        <td></td>
        <td>                
            <button type='submit' class='btn btn-primary'>
                <span class='glyphicon glyphicon-plus'></span>&nbsp;Lisa kategooria
            </button>
            <a href='kategooriad.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");
?>