<?php 
    require_once("../_ayarlar.php");
    require_once("../_fonksiyonlar.php");
?>
<!DOCTYPE html>
<html lang="tr">

<head>
    <?php include("_head.php") ?>
    <title>Kategori Güncelle</title>
</head>

<body id="page-top">

    <!-- Page Wrapper -->
    <div id="wrapper">

        <?php include("_sidebar.php") ?>

        <!-- Content Wrapper -->
        <div id="content-wrapper" class="d-flex flex-column">

            <!-- Main Content -->
            <div id="content">

                <?php include("_topbar.php") ?>

                <!-- Sayfaya Özel İçerik -->
                <div class="container-fluid">

                    <div class="card shadow mb-4">
                        <div class="card-header py-3">
                            <h6 class="m-0 font-weight-bold text-primary">Kategori Güncelle</h6>
                        </div>
                        <div class="card-body">
                        <?php
                        $id = @$_GET["id"];

                        $adbul = "SELECT * FROM kategori WHERE kategori_id = '$id' ";
                        $adsonuc = $vt->query($adbul);
                        $adsatir = $adsonuc->fetch_assoc();

                        if (isset($_POST["kategori_guncelle"])) {
                                    
                            $yeni_ad = addslashes($_POST["ad"]);

                            $sql = "UPDATE kategori SET kategori_ad	= '$yeni_ad' WHERE kategori_id = '$id' ";

                            $sonuc = $vt->query($sql);

                            if($sonuc===TRUE){
                                echo '<div class="alert alert-success alert-dismissible fade show" role="alert">
                                Kategori güncelleme işlemi başarılı.
                                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                                </div>';
                            }
                            else {
                                echo '<div class="alert alert-danger alert-dismissible fade show" role="alert">
                                Kategori güncelleme işleminde hata meydana geldi.
                                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                                </div>';
                            }
                        }
                        ?>
                        <?php
                            $kategori_sql = "SELECT * FROM kategori WHERE kategori_id = '$id' ";
                            $kategori_tablo = $vt->query($kategori_sql);
                            $kategori_satir = $kategori_tablo->fetch_array();
                        ?>
                            <form method="post" enctype="multipart/form-data">
                                <div class="mb-3">
                                    <label for="ad" class="form-label">Kategori Adı</label>
                                    <input type="text" class="form-control" id="ad" name="ad" value="<?php echo @$kategori_satir["kategori_ad"]; ?>">
                                </div>
                                <div class="form-group">
                                    <button class="btn btn-primary btn-user btn-block" name="kategori_guncelle">Kategori Güncelle</button>
                                </div>
                            </form>

                        </div>
                    </div>

                </div>
                <!-- /.container-fluid -->

            </div>
            <!-- End of Main Content -->

            <?php include("_footer.php") ?>

        </div>
        <!-- End of Content Wrapper -->

    </div>
    <!-- End of Page Wrapper -->

    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
        <i class="fas fa-angle-up"></i>
    </a>

    <?php include("_script.php") ?>
</body>
</body>

</html>