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


        <?php
        if ($_GET["islem"] == 'duzenle') {
            $yenille = $db->query("select * from mehsullar 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">Məhsul əlavəsi</li>
                        <li><a href="mehsul-listele">Məhsul listələ</a></li>
                        <li><a href="kateqoriya-elavesi">Kateqoriya əlavəsi</a></li>
                        <li><a href="kateqoriya-listele">Kateqoriya 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">Məhsul ə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 mehsullar");
                                        $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>
                            <div class="form-group">
                                <label class="col-md-2 control-label" for="fiyat">Qiyməti</label>
                                <div class="col-md-4"> <input type="text" name="fiyat" class="form-control" value="<?= $yenille["fiyat"] ?>">
                                </div>
                                <label class="col-md-2 control-label" for="layiheleraltmetin">Vahidi</label>
                                <div class="col-md-4"> <select class="form-control" name="kur">
                                    <option value="0" <?php if ($yenille["kur"] == 0) {
                                        echo ' selected';
                                    } ?>>₼</option>
                                    <option value="1" <?php if ($yenille["kur"] == 1) {
                                        echo ' selected';
                                    } ?>>$</option>

                                </select>
                            </div>
                        </div>
                        <input type="hidden" name="lan" value="<?= $dilsec["id"] ?>">
                        <div class="form-group">
                            <label class="col-md-2 control-label" for="example-email">PDF Yüklə</label>
                            <div class="col-md-10">
                                <input type="file" id="example-email" name="indir" class="form-control" value="<?= $yenille["indir"] ?>">
                            </div>
                        </div>

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

                                    <?php } ?>
                                </select>

                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-2 control-label">Ön Açıqlama</label>
                            <div class="col-md-10">
                                <textarea class="form-control" rows="5" name="onaciklama"><?= $yenille["onaciklama"] ?></textarea>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-2 control-label">Şəkli</label>
                            <div class="col-md-10">
                                <input type="file" class="form-control" name="resim" placeholder="placeholder">
                            </div>
                        </div>
                        <?php if ($_GET["islem"] == 'duzenle') { ?>
                            <div class="form-group">
                                <label class="col-md-2 control-label">Hazırki şəkli</label>
                                <div class="col-md-10">
                                    <img src="../imgupload/<?= $yenille["resim"] ?>" width="200">
                                </div>
                            </div>
                        <?php } ?>

                        <div class="form-group">
                            <label class="col-md-2 control-label">Şəkli2</label>
                            <div class="col-md-10">
                                <input type="file" class="form-control" name="resim2" placeholder="placeholder">
                            </div>
                        </div>
                        <?php if ($_GET["islem"] == 'duzenle') { ?>
                            <div class="form-group">
                                <label class="col-md-2 control-label">Hazırki şəkli2</label>
                                <div class="col-md-10">
                                    <img src="../imgupload/<?= $yenille["resim2"] ?>" width="200">
                                </div>
                            </div>
                        <?php } ?>


                        <div class="form-group">
                            <label class="col-md-2 control-label">Açıqlama</label>
                            <div class="col-md-10">
                                <textarea class="form-control ckeditor" rows="5" name="aciklama"><?= $yenille["aciklama"] ?></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label" for="example-email">SEO META TITLE</label>
                            <div class="col-md-10">
                                <input type="text" id="example-email" name="meta_title" class="form-control" value="<?= $yenille["meta_title"] ?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label" for="example-email">SEO META KEYWORDS</label>
                            <div class="col-md-10">
                                <input type="text" id="example-email" name="meta_key" class="form-control" value="<?= $yenille["meta_key"] ?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label">SEO META DESCRIPTION</label>
                            <div class="col-md-10">
                                <textarea class="form-control" rows="3" name="meta_des"><?= $yenille["meta_des"] ?></textarea>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">Vəziyyəti</label>
                            <div class="col-sm-10">
                                <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="row" id="imgupload">

                            <div class="form-group row col-sm-12" id="imgupload">


                                <?php
                                $i = 0;

                                $iddd = $_GET['id'];
                                if ($_GET['islem'] == 'duzenle') {
                                    $cek = $db->query("SELECT * FROM urun_img WHERE urun_id = '$iddd' and tur='mehsullar' order by id asc", PDO::FETCH_ASSOC);
                                    if ($cek->rowCount()) {
                                        foreach ($cek as $c) {
                                            echo '<div class="col-md-3" data-resim-dis-id="' . $i . '">
                                            <div class="uploaddis pasif" style="float:left;">
                                            <div class="yuklendi">
                                            <img src="../imgupload/' . $c['img'] . '" width="100%">
                                            <div class="icon" data-resim-sil-id="' . $i . '"><span class="fa fa-trash"></span></div>
                                            <input type="hidden" name="img[]" value="' . $c['img'] . '" required="">
                                            </div>
                                            </div>
                                            </div>';
                                            $i++;
                                        }
                                    }
                                }
                                ?>
                            </div>

                            <div class="form-group row col-md-12">
                                <div class="col-md-4 " style="margin:auto;padding:auto;">
                                    <div class="uploaddis aktif" data-id="1" style="margin:0 auto;">
                                        <div class="upload1">
                                            <span class="metin" style="width: 100%;float: left;">Məhsul şəkli yüklə</span>
                                            <div class="icon"><span class="fa fa-upload" data-id="1"></span></div>
                                        </div>
                                    </div>
                                </div>


                            </div>

                        </div>
                        <div id="queue"></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="../mehsul-elavesi?islem=duzenle&id=<?= $yenille["id"] ?>">
                                    <input type="hidden" name="id" value="<?= $yenille["id"] ?>">
                                    <button type="submit" name="mehsul-yenile" class="btn btn-info waves-effect waves-light">Yenilə</button>
                                <?php } else { ?>
                                    <input type="hidden" name="link" value="../mehsul-elavesi">
                                    <button type="submit" name="mehsul-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>