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

        <?php
        // $db değişkeninin zaten tanımlanmış ve veritabanına bağlı olduğunu varsayıyoruz
        if (isset($_GET["islem"]) && $_GET["islem"] == 'duzenle') {
            $yenille = $db->query("select * from haqqimizda where id='{$_GET["id"]}'")->fetch(PDO::FETCH_ASSOC);
        }
        ?>

        <div class="row">
            <div class="col-sm-12">
                <div class="panel panel-primary">
                    <div class="panel-heading">
                        <h3 class="panel-title">Haqqımızda düzəlişi</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" for="example-email">Adı</label>
                                <div class="col-md-10">
                                    <input type="text" id="example-email" name="adi" class="form-control"
                                        value="<?= isset($yenille["adi"]) ? $yenille["adi"] : '' ?>">
                                </div>
                            </div>
                            <input type="hidden" name="lan" value="<?= isset($dilsec["id"]) ? $dilsec["id"] : '' ?>">


                            <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"><?= isset($yenille["aciklama"]) ? $yenille["aciklama"] : '' ?></textarea>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-2 control-label">Footer Açıqlaması</label>
                                <div class="col-md-10">
                                    <textarea class="form-control ckeditor" rows="5"
                                        name="footer"><?= isset($yenille["footer"]) ? $yenille["footer"] : '' ?></textarea>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-2 control-label" for="example-email">Video Linki</label>
                                <div class="col-md-10">
                                    <input type="text" id="example-email" name="video" class="form-control"
                                        value="<?= isset($yenille["video"]) ? $yenille["video"] : '' ?>">
                                </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 (isset($_GET["islem"]) && $_GET["islem"] == 'duzenle' && isset($yenille["resim"])) { ?>
                                <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-sm-2 control-label">Vəziyyəti</label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="veziyyeti">
                                        <option value="0" <?php if (isset($yenille["veziyyeti"]) && $yenille["veziyyeti"] == 0) {
                                                                echo ' selected';
                                                            } ?>>Göstər</option>
                                        <option value="1" <?php if (isset($yenille["veziyyeti"]) && $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 (isset($_GET["islem"]) && $_GET["islem"] == 'duzenle') { ?>
                                        <input type="hidden" name="link" value="../haqqimizda-duzelisi?islem=duzenle&id=<?= isset($yenille["id"]) ? $yenille["id"] : '' ?>">
                                        <input type="hidden" name="id" value="<?= isset($yenille["id"]) ? $yenille["id"] : '' ?>">
                                        <button type="submit" name="haqqimizda-duzelis" class="btn btn-info waves-effect waves-light">Yenilə</button>
                                    <?php } else { ?>
                                        <input type="hidden" name="link" value="../haqqimizda-duzelisi">
                                        <button type="submit" name="haqqimizda-duzelis" class="btn btn-info waves-effect waves-light">Əlavə et</button>
                                    <?php } ?>
                                </div>
                            </div>

                        </form>
                    </div>
                </div>
            </div>
        </div>

        ---

        <div class="row">
            <div class="col-sm-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">Haqqımızda Məlumatlar</h3>
                    </div>
                    <div class="panel-body">
                        <div class="table-responsive">
                            <table class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>Adı</th>
                                        <th>Açıqlama</th>
                                        <th>Footer Açıqlaması</th>
                                        <th>Video Linki</th>
                                        <th>Şəkil</th>
                                        <th>Vəziyyəti</th>
                                        <th>Əməliyyatlar</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                    // 'haqqimizda' tablosundaki tüm kayıtları çekin
                                    $stmt = $db->query("SELECT * FROM haqqimizda");
                                    $all_haqqimizda = $stmt->fetchAll(PDO::FETCH_ASSOC);

                                    if ($all_haqqimizda) {
                                        foreach ($all_haqqimizda as $item) {
                                    ?>
                                            <tr>
                                                <td><?= $item["id"] ?></td>
                                                <td><?= $item["adi"] ?></td>
                                                <td><?= mb_substr(strip_tags($item["aciklama"]), 0, 100, 'UTF-8') . '...' ?></td>
                                                <td><?= mb_substr(strip_tags($item["footer"]), 0, 100, 'UTF-8') . '...' ?></td>
                                                <td><?= $item["video"] ?></td>
                                                <td>
                                                    <?php if (!empty($item["resim"])) { ?>
                                                        <img src="../imgupload/<?= $item["resim"] ?>" width="50">
                                                    <?php } else { ?>
                                                        Şəkil yoxdur
                                                    <?php } ?>
                                                </td>
                                                <td><?= $item["veziyyeti"] == 0 ? 'Göstər' : 'Gizlət' ?></td>
                                                <td>
                                                    <a href="haqqimizda-duzelisi?islem=duzenle&id=<?= $item["id"] ?>" class="btn btn-warning btn-xs">Düzəlt</a>
                                                    <a href="include/fonksiyonlar.php?islem=sil&tablo=haqqimizda&id=<?= $item["id"] ?>&link=../haqqimizda-duzelisi" class="btn btn-danger btn-xs" onclick="return confirm('Silmək istədiyinizə əminsinizmi?')">Sil</a>
                                                </td>
                                            </tr>
                                        <?php
                                        }
                                    } else {
                                        ?>
                                        <tr>
                                            <td colspan="8" class="text-center">Heç bir məlumat tapılmadı.</td>
                                        </tr>
                                    <?php
                                    }
                                    ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>