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

if(!empty($_POST)){

 $id = $_GET["id"]; 
 $short_title = $_POST['short_title'];
 $title = $_POST['title'];
 $description = $_POST['description'];
 $button = $_POST['button']; 
 $foto = $_POST['foto'];

 if ($_FILES['foto']['tmp_name'] != "") {
   $boyut = $_FILES['foto']['size'];
   $tip = $_FILES['foto']['type'];
   
   if($tip!="image/jpeg" && $tip!="image/jpg" && $tip!="image/png" && $tip!="application/pdf"){
        echo 'Dosya Jpeg veya Png yada Gif , PDF formatında olmalı';
  }elseif ($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 "<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>";

      $settings = $dbh->prepare("UPDATE home_banner SET foto = '".$foto_url."' WHERE id = '".$id."'");
      $settings->execute();
    }
  }

  $update = $dbh->prepare("UPDATE home_banner SET title = '".$title."', description = '".$description."', button = '".$button."' WHERE id = '".$id."'");
  $update->execute();
  foreach ($_POST["en"] as $key => $value) {
   dilguncelle("en","home_banner",$id,$key,$value);
 }
}
?>

<?php
$sorgu = $dbh->prepare("SELECT * FROM home_banner Where id=:id");
$sorgu->execute(['id' => (int)$_GET["id"]]);
$sonuc = $sorgu->fetch();  
$sonucen = cevir("home_banner",$sonuc,"en"); 
?>   
<!-- 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">Slider Düzenle - <?=$sonuc['title'];?></h4>
                <ol class="breadcrumb">
                  <li class="breadcrumb-item"><a href="index.php">Anasayfa</a></li>
                  <li class="breadcrumb-item"><a href="slider-liste.php">Slider Listesi</a></li>
                  <li class="breadcrumb-item active">Slider Düzenle</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">Slider Düzenle</h4>
              <p class="text-muted mb-0">Değerli kullanıcı, bu alandan slider düzenleyebilirsiniz. Zorunlu olarak doldurmanız gereken alanlar * olarak belirtilmiştir.  Slider ebatlarımız 2000 x 1275 px</p> 
            </div><!--end card-header-->
            <div class="card-body">

              <div class="row">

               
                 <div class="col-xl-6">  
                  <div class="form-group">
                    <label for="exampleInputEmail1">Slider Başlığı * </label>
                    <input type="text" class="form-control" maxlength="999" id="thresholdconfig" aria-describedby="emailHelp" placeholder="Lütfen bir başlık giriniz" name="title" value="<?=$sonuc['title'];?>"> 
                  </div>
                </div>

                <div class="col-xl-6">  
                  <div class="form-group">
                    <label for="exampleInputEmail1">Slider Buton Linki </label>
                    <input type="text" class="form-control" maxlength="999" id="thresholdconfig" aria-describedby="emailHelp" placeholder="Yönlendirilmesini istediğiniz linki yazınız" name="button" value="<?=$sonuc['button'];?>"> 
                  </div>
                  </div>

                  <div class="col-xl-12">  
                  <div class="form-group">
                    <label for="exampleInputEmail1">Slider Açıklaması * </label>
                    <input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Lütfen açıklama yazınız" name="description" value="<?=$sonuc['description'];?>"> 
                  </div>
                </div>  

                </div>



              <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/<?=$sonuc['foto'];?>" />    
                </div><!--end col--> 
              </div><!--end row-->

              <!-- dil başlangıçı -->

              <div class="row"> 
                <div class="col-lg-12 col-xl-12">  
                  <div class="accordion" id="accordionExample">
                    
              <div class="card mb-1 border shadow-none">
                <div class="card-header  rounded-0" id="headingTwo">
                  <a href="" class="collapsed text-dark" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
                    <i data-feather="sliders"></i> İngilizce Dil Ayarları
                  </a>
                </div>
                <div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionExample">
                  <div class="card-body"> 

                     <div class="row">
                              
                
                 <div class="col-xl-12">  
                  <div class="form-group">
                    <label for="exampleInputEmail1">Slider Başlığı * </label>
                    <input type="text" class="form-control" maxlength="999" id="thresholdconfig" aria-describedby="emailHelp" placeholder="Lütfen bir başlık giriniz" name="en[title]" value="<?=$sonucen['title'];?>"> 
                  </div>
                </div> 

                  <div class="col-xl-12">  
                  <div class="form-group">
                    <label for="exampleInputEmail1">Slider Açıklaması * </label>
                    <input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Lütfen açıklama yazınız" name="en[description]" value="<?=$sonucen['description'];?>"> 
                  </div>
                </div>

                        </div>

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

        <!-- dil bitişi --> 

        <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';?>

