<?php

require './Controller/BakeryController.php';
$bakeryController = new BakeryController();
$title = "Add a new Bakery Product";
if (isset($_GET["update"])) {
    $bakeryproduct = $bakeryController->GetBakeryById($_GET["update"]);
    $content = "<form action='' method='post'>\n    <fieldset>\n        <legend>Add a new Bakery Product</legend>\n        <label for='name'>Name : </label>\n        <input type='text' class='inputField' name='txtName' value='{$bakeryproduct->name}'/><br/>\n        \n        <label for='type'>Type : </label>\n        <select class='inputField' name='ddlType'>\n            <option value='%'>All</option>" . $bakeryController->CreateOptionValues($bakeryController->GetBakeryTypes()) . "</select><br/>\n        \n        <label for='price'>Price : </label>\n        <input type='text' class='inputField' name='txtPrice' value='{$bakeryproduct->price}' /><br/>\n        \n        \n        <label for='image'>Image : </label>\n        <select class='inputField' name='ddlImage'>" . $bakeryController->GetImages() . "</select></br>\n        \n        <label for='description'>Description: </label>\n        <textarea cols='70' rows='12' name='txtDescription'>{$bakeryproduct->description}</textarea></br>\n        \n        <input type='submit' value='Submit'>\n        \n        \n        \n    </fieldset>\n</form>\n";
} else {
    $content = "<form action='' method='post'>\n    <fieldset>\n        <legend>Add a new Bakery Product</legend>\n        <label for='name'>Name : </label>\n        <input type='text' class='inputField' name='txtName' /><br/>\n        \n        <label for='type'>Type : </label>\n        <select class='inputField' name='ddlType'>\n            <option value='%'>All</option>" . $bakeryController->CreateOptionValues($bakeryController->GetBakeryTypes()) . "</select><br/>\n        \n        <label for='price'>Price : </label>\n        <input type='text' class='inputField' name='txtPrice' /><br/>\n        \n        \n        <label for='image'>Image : </label>\n        <select class='inputField' name='ddlImage'>" . $bakeryController->GetImages() . "</select></br>\n        \n        <label for='description'>Description: </label>\n        <textarea cols='70' rows='12' name='txtDescription'></textarea></br>\n        \n        <input type='submit' value='Submit'>\n        \n        \n        \n    </fieldset>\n</form>\n";
}
$content = "<form action='' method='post'>\n    <fieldset>\n        <legend>Add a new Bakery Product</legend>\n        <label for='name'>Name : </label>\n        <input type='text' class='inputField' name='txtName' required pattern='[a-zA-Z ]+'><br/>\n        \n        <label for='type'>Type : </label>\n        <select class='inputField' name='ddlType'>\n            <option value='%'>All</option>" . $bakeryController->CreateOptionValues($bakeryController->GetBakeryTypes()) . "</select><br/>\n        \n        <label for='price'>Price : </label>\n        <input type='text' class='inputField' name='txtPrice' /><br/>\n        \n        \n        <label for='image'>Image : </label>\n        <select class='inputField' name='ddlImage'>" . $bakeryController->GetImages() . "</select></br>\n        \n        <label for='description'>Description: </label>\n        <textarea cols='70' rows='12' name='txtDescription' required></textarea></br>\n        \n        <input type='submit' value='Submit'>\n        \n        \n        \n    </fieldset>\n</form>\n";
if (isset($_GET["update"])) {
    if (isset($_POST["txtName"])) {
        $bakeryController->UpdateBakery($_GET["update"]);
    }
} else {
    if (isset($_POST["txtName"])) {
        $bakeryController->InsertBakery();
    }
}
include './Template.php';
?>



<?php

$title = "Manage bakery product objects";
require './Controller/BakeryController.php';
$bakeryController = new BakeryController();
$content = $bakeryController->CreateOverviewTable();
if (isset($_GET["delete"])) {
    $bakeryController->DeleteBakery($_GET["delete"]);
}
include './Template.php';
?>

<?php

require 'Controller/BakeryController.php';
$bakeryController = new BakeryController();
if (isset($_POST['types'])) {
    //Fill page with bakery products of the selected type
    $bakeryTables = $bakeryController->CreateBakeryTables($_POST['types']);
} else {
    //Page is loaded for the first time, no type selected -> Fetch all types
    $bakeryTables = $bakeryController->CreateBakeryTables('%');
}
//Output page Data
$title = 'Bakery overview';
$content = $bakeryController->CreateBakeryDropdownList() . $bakeryTables;
include 'Template.php';