<?php include 'inc/header.php';?>
<?php include 'inc/sidebar.php';?>
<?php include 'inc/navbar.php';?>
<?php

        if ($_POST) { 
           
            $select_category = $_POST['select_category'];
            $foto = $_POST['foto'];
            if ($select_category <> "" && isset($_FILES['foto'])) 
                if ($_FILES['foto']['tmp_name'] != "") {
                $boyut = $_FILES['foto']['size'];
                if ($boyut > (1024 * 1024 * 30)) {
                   echo 'Dosya 30MB den büyük olamaz.';
                } else {
                    $tip = $_FILES['foto']['type'];
                    $isim = $_FILES['foto']['name'];
                    $uzanti = explode('.', $isim);
                    $uzanti = $uzanti[count($uzanti) - 1];
                    $random = rand();
                    $dosya = $_FILES['foto']['tmp_name'];
                    $foto_url = $random . "." . $uzanti;
                    copy($dosya, '../img/' . $foto_url);
                    echo '';
                                $satir = [
                                    'foto' => $foto_url,
                                    'select_category' => $select_category,
                                ];
                                $sql = "INSERT INTO product_gallery SET foto=:foto, select_category=:select_category;";
                                $durum = $dbh->prepare($sql)->execute($satir);
                                 if ($durum) {
                                    $sonId = $dbh->lastInsertId();
                                    echo "  <script>
                                   const Toast = Swal.mixin({
                                    toast: true,
                                    position: 'top-end',
                                    showConfirmButton: false,
                                    timer: 6000,
                                    timerProgressBar: true,
                                    didOpen: (toast) => {
                                      toast.addEventListener('mouseenter', Swal.stopTimer)
                                      toast.addEventListener('mouseleave', Swal.resumeTimer)
                                    }
                                    })

                                    Toast.fire({
                                      icon: 'success',
                                      title: 'Başarı ile güncellendi.'
                                      })
                                      </script> "  ;
                                                     }
                                                     }
                                                     }
                                                     }      

                                        ?>

<?php

$sorgu = $dbh->prepare("SELECT * FROM product_gallery Where id=:id");

$sorgu->execute(['id' => (int)$_GET["id"]]);

$sonuc = $sorgu->fetch();  

?> 

<!-- Page Content-->
<div class="page-content">
  <div class="container-fluid">
    <!-- Page-Title -->

    <form method="post" action="" enctype="multipart/form-data">

      <div class="row">
        <div class="col-sm-12">
          <div class="page-title-box">
            <div class="row">
              <div class="col">
                <h4 class="page-title">Ürün Galerisi</h4>
                <ol class="breadcrumb">
                  <li class="breadcrumb-item"><a href="index.php">Anasayfa</a></li>
                  <li class="breadcrumb-item"><a href="urun-liste.php">Ürün Listesi</a></li>
                  <li class="breadcrumb-item active">Ürün Galerisi</li>
                </ol>
              </div><!--end col-->
              <div class="col-auto align-self-center">
                <button class="btn btn-primary" type="submit">
                  <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
                  GÜNCELLE
                </button> 
              </div><!--end col-->  
            </div><!--end row-->                                                              
          </div><!--end page-title-box-->
        </div><!--end col-->
      </div><!--end row-->
      <!-- end page title end breadcrumb -->


      <div class="row">
        <div class="col-lg-12">
          <div class="card">
            <div class="card-header">
              <h4 class="card-title">Ürün Galerisi</h4>
              <p class="text-muted mb-0">Değerli kullanıcı, bu alandan ürünlerinize çoklu fotoğraf yüklemesi yapabilirsiniz. Tüm fotoğrafları tek tek seçerek kaydetmeniz gerekmektedir.</p> 
            </div><!--end card-header-->
            <div class="card-body">

              <input type="hidden" name="select_category" value="<?php echo $_GET['id']; ?> ">

               

              <div class="row">
                <div class="col-xl-12">  
                </div><!--end card-header-->
                <div class="card-body">
                  <input type="file" id="input-file-now-custom-1" accept="image/x-png,image/gif,image/png,image/jpeg,application/pdf"  name="foto" class="dropify" />    
                </div><!--end col--> 
              </div><!--end row-->


              <?php
         
                   
            $coksorgu = $dbh->prepare("SELECT * FROM product_gallery where select_category=:id");
            $coksorgu->execute(['id' => (int)$_GET["id"]]); 
            while ($coksonuc = $coksorgu->fetch()) {
             
                $id = $coksonuc['id']; 
                $select_category = $coksonuc['select_category']; 
                $foto = $coksonuc['foto'];
                ?>


                <div class="row">
                <div class="col-xl-12">  
                </div><!--end card-header-->
                <div class="card-body">
                  <input type="file" id="input-file-now-custom-1" accept="image/x-png,image/gif,image/png,image/jpeg,application/pdf"  name="foto" class="dropify" data-default-file="../img/<?=$coksonuc['foto'];?>" disabled/>    
                </div><!--end col--> 
              </div><!--end row-->
              <a href="islem.php?id=<?=$coksonuc['id']; ?>&islem=ugaleri-sil" class="btn btn-outline-danger btn-icon mg-r-5" data-toggle="tooltip" data-trigger="hover" data-placement="right" title="" data-original-title="Fotoğrafı Sil"><div><i class="fa fa-minus-circle"></i></div></a><br>
              <?php } ?>

        <br>    
        <button class="btn btn-primary btn-block" type="submit">
          <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
          GÜNCELLE
        </button>
      </form>                                           
    </div><!--end card-body-->
  </div><!--end card-->
</div><!--end col-->


</div><!--end row-->



</div><!-- container -->

<?php include 'inc/footer.php';?>

