<div class="content">
    <div class="container">


        <?php
        if ($_GET["islem"] == 'duzenle') {
            $yenille = $db->query("select * from menu where id='{$_GET["id"]}'")->fetch(PDO::FETCH_ASSOC);
        }
        ?>
        <div class="row">
            <div class="col-sm-12">
                <div class="page-header-title">
                    <h4 class="pull-left page-title">Datatables</h4>
                    <ol class="breadcrumb pull-right">
                        <li><a href="./">Əsas səhifə</a></li>
                        <li class="active">Menyu əlavəsi</li>
                        <li><a href="menyu-listele">Header menyu listələ</a></li>
                        
                    </ol>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
        <div class="row">

            <div class="col-sm-12">
                <div class="panel panel-primary">
                    <div class="panel-heading">
                        <h3 class="panel-title">Menyu əlavəsi</h3>
                    </div>
                    <div class="panel-body">
                        <form class="form-horizontal" action="include/fonksiyonlar.php" method="post" enctype="multipart/form-data">
                            <div class="form-group">
                                <label class="col-md-2 control-label">Sıra</label>
                                <div class="col-md-10">
                                    <?php
                                        // Eğer düzenleme moduysa, $yenille dizisindeki sıra değerini kullan.
                                        // Eğer değilse (yeni ekleme), veritabanındaki son sıra numarasını bulup 1 ekle.
                                    if (isset($_GET['islem']) && $_GET['islem'] == 'duzenle' && isset($yenille['sira'])) {
                                        $sira_degeri = $yenille['sira'];
                                    } else {
                                         // Yeni ürün ekleme modu için otomatik sıra numarası
                                        $sorgu = $db->query("SELECT MAX(sira) AS max_sira FROM menu");
                                        $sonuc = $sorgu->fetch(PDO::FETCH_ASSOC);
                                        $sira_degeri = ($sonuc && isset($sonuc['max_sira'])) ? $sonuc['max_sira'] + 1 : 1;
                                    }
                                    ?>
                                    <input type="text" class="form-control" name="sira" value="<?= htmlspecialchars($sira_degeri) ?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-2 control-label" for="example-email">Adı</label>
                                <div class="col-md-10">
                                    <input type="text" id="example-email" name="adi" class="form-control" value="<?= $yenille["adi"] ?>">
                                </div>
                            </div>
                            <input type="hidden" name="lan" value="<?= $dilsec["id"] ?>">
                            <div class="form-group">
                                <label class="col-md-2 control-label" for="example-email">Linki</label>
                                <div class="col-md-10">
                                    <input type="text" id="example-email" name="url" class="form-control" value="<?= $yenille["url"] ?>">
                                </div>
                            </div>


                            <div class="form-group">
                                <label class="col-sm-2 control-label">Açılan menyu</label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="acilir">
                                        <option value="0" <?php if ($yenille["acilir"] == 0) {
                                                                echo ' selected';
                                                            } ?>>Açılsın</option>
                                        <option value="1" <?php if ($yenille["acilir"] == 1) {
                                                                echo ' selected';
                                                            } ?>>Açılmasın</option>

                                    </select>

                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">Menyu sahəsi</label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="footer">
                                        <option value="0" <?php if ($yenille["footer"] == 0) {
                                                                echo ' selected';
                                                            } ?>>Header de göstər</option>
                                        <option value="1" <?php if ($yenille["footer"] == 1) {
                                                                echo ' selected';
                                                            } ?>>Footer da göstər</option>

                                    </select>

                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">Menyu Yeri</label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="kategori">
                                        <option value="0" <?php if ($yenille["kategori"] == 0) {
                                                                echo ' selected';
                                                            } ?>>Əsas menyu</option>
                                        <?php
                                        $cek = $db->query("select * from menu where not id='{$yenille["id"]}' order by id desc")->fetchAll(PDO::FETCH_ASSOC);
                                        foreach ($cek as $goster) {
                                        ?>
                                            <option value="<?= $goster["id"] ?>" <?php if ($goster["id"] == $yenille["kategori"]) {
                                                                                        echo ' selected';
                                                                                    } ?>><?= $goster["adi"] ?></option>
                                        <?php } ?>
                                    </select>

                                </div>
                            </div>

                            <!-- <div class="form-group">
                                <label class="col-sm-2 control-label">Maəhsul Kateqoriyası</label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="mehsul_kateqoriya">
                                        <option value="0" <?php if ($yenille["mehsul_kateqoriya"] == 0) {
                                                                echo ' selected';
                                                            } ?>>Əsas kateqoriya</option>
                                        <?php
                                        $cek = $db->query("select * from mehsul_kateqoriya where veziyyeti='0' and not id='{$yenille["id"]}' order by id desc")->fetchAll(PDO::FETCH_ASSOC);
                                        foreach ($cek as $goster) {
                                        ?>
                                            <option value="<?= $goster["id"] ?>" <?php if ($yenille["id"] == $goster["id"]) {
                                                                                        echo ' selected';
                                                                                    } ?>><?= $goster["adi"] ?></option>

                                        <?php } ?>
                                    </select>

                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">Layihə kateqoriya yeri</label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="layihe_kateqoriya_yeri">
                                        <option value="0" <?php if ($yenille["layihe_kateqoriya_yeri"] == 0) {
                                                                echo ' selected';
                                                            } ?>>Əsas menyu</option>
                                        <?php
                                        $cek = $db->query("select * from layihe_kateqoriya where not id='{$yenille["id"]}' order by id desc")->fetchAll(PDO::FETCH_ASSOC);
                                        foreach ($cek as $goster) {
                                        ?>
                                            <option value="<?= $goster["id"] ?>" <?php if ($goster["id"] == $yenille["layihe_kateqoriya_yeri"]) {
                                                                                        echo ' selected';
                                                                                    } ?>><?= $goster["adi"] ?></option>
                                        <?php } ?>
                                    </select>

                                </div>
                            </div> -->

                            <div class="form-group">
                                <label class="col-sm-2 control-label">Səhifə</label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="sekme">
                                        <option value="0" <?php if ($yenille["sekme"] == 0) {
                                                                echo ' selected';
                                                            } ?>>Eyni səhifədə aç</option>
                                        <option value="1" <?php if ($yenille["sekme"] == 1) {
                                                                echo ' selected';
                                                            } ?>>Yeni səhifədə aç</option>

                                    </select>

                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">Vəziyyəti</label>
                                <div class="col-sm-4">
                                    <select class="form-control" name="veziyyeti">
                                        <option value="0" <?php if ($yenille["veziyyeti"] == 0) {
                                                                echo ' selected';
                                                            } ?>>Göstər</option>
                                        <option value="1" <?php if ($yenille["veziyyeti"] == 1) {
                                                                echo ' selected';
                                                            } ?>>Gizlət</option>

                                    </select>

                                </div>
                            </div>
                            <div class="form-group ">
                                <div class="col-sm-offset-11 col-sm-1">
                                    <?php if ($_GET["islem"] == 'duzenle') { ?>
                                        <input type="hidden" name="link" value="../menyu-elavesi?islem=duzenle&id=<?= $yenille["id"] ?>">
                                        <input type="hidden" name="id" value="<?= $yenille["id"] ?>">
                                        <button type="submit" name="menu-yenille" class="btn btn-info waves-effect waves-light">Yenilə</button>
                                    <?php } else { ?>
                                        <input type="hidden" name="link" value="../menyu-elavesi">
                                        <button type="submit" name="menyu-elavesi" class="btn btn-info waves-effect waves-light">Əlavə et</button>
                                    <?php } ?>
                                </div>
                            </div>

                        </form>
                    </div> <!-- panel-body -->
                </div> <!-- panel -->
            </div> <!-- col -->
        </div>
    </div> <!-- container -->

</div>