<?php include "../../root.class.php";
$html = new html();
$html->add_styles_page();
$table_name = "items";
$db_safeguard = new db_safeguard();
?>

<div class="form_down">
    <h1>EDIT ITEMS</h1>
    <?php

    echo $html->input_html_from_db($table_name, 'name', "`record_id` = {$_GET['record_id']}", 'name', 'name', 'name')
        ?>
    <?php

    $restorants_res = $db_safeguard->query("restorants", "SELECT * FROM restorants WHERE record_id = {$_SESSION['restorant_id']}");
    $restorant_data = $restorants_res->fetch_assoc();
    $like_query = "restorant_id = {$restorant_data['record_id']}";


    $item_categories_res = $db_safeguard->query("item_categories", "SELECT * FROM item_categories WHERE " . $like_query);
    $like_query = [];
    while ($item_categories_data = $item_categories_res->fetch_assoc()) {
        $like_query[] = "item_categories_id = {$item_categories_data['record_id']}";
    }

    echo $html->select_html_from_db('item_sub_categories', 'record_id', 'name', implode(" OR ", $like_query), "item_sub_categories_id", "item_sub_categories_id");
    
    echo $html->select_from_db_add_current_selected_column($table_name, 'item_sub_categories_id', "record_id = {$_GET["record_id"]}", 'item_sub_categories_id');

    echo $html->input_html("record_id", $_GET['record_id'], "record_id", "record_id", '', '', '', '', 'hidden');

    echo $html->submit_btn("submit", 'SAVE', "edit_$table_name()");

    ?>

</div>

<?php
$html->html_form_ajax("edit_$table_name", "UPDATE", $table_name, "record_id = {$_GET['record_id']}", false);
?>