<?php include 'inc/header.php';?>
<?php include 'inc/sidebar.php';?>
<?php include 'inc/navbar.php';?>
<?php
if ($_POST) { 
  $short_title = $_POST['short_title'];
  $title = $_POST['title'];
  $description = $_POST['description'];
  $button = $_POST['button'];
  $foto = $_POST['foto']; 


 if ($title <> "" && $description <> "")  

    if ($_FILES['foto']['tmp_name'] != "") {
      $boyut = $_FILES['foto']['size'];
      $tip = mime_content_type($_FILES['foto']['tmp_name']);
      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 '';
        $satir = [
          'foto' => $foto_url,
          'title' => $title,
          'description' => $description, 
          'button' => $button,
        ];
        $sql = "INSERT INTO home_banner SET foto=:foto, title=:title, description=:description, button=:button ;";
        /** @var PDO $dbh */
        $durum = ($dbh->prepare($sql))->execute($satir);



        if ($durum) {
          $sonId = $dbh->lastInsertId();
          foreach ($_POST["en"] as $key => $value) {
           dilguncelle("en","home_banner",$sonId,$key,$value);
         } 
         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 kayıt edildi.'
            })
            </script>";
          }
        }
      }
    }      
    ?>
    <!-- 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 Ekle</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 Ekle</li>
                    </ol>
                  </div><!--end col-->
                  <div class="col-auto align-self-center">
                    <button class="btn btn-success" type="submit">
                      <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
                      KAYDET
                    </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 Ekle</h4>
                  <p class="text-muted mb-0">Değerli kullanıcı, bu alandan yeni bir slider ekleyebilirsiniz. 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" required=""> 
                  </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"> 
                  </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" required=""> 
                  </div>
                </div>  

                </div>

                  <div class="row">
                    <div class="col-xl-12">  
                    </div><!--end card-header-->
                    <div class="card-body">
                      <input type="file" name="foto" accept="image/x-png,image/gif,image/png,image/jpeg,application/pdf" id="input-file-now" class="dropify" / required="">      
                    </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]"> 
                  </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]"> 
                  </div>
                </div>

                    </div>
 

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

            <!-- dil bitişi --> 

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


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



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

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

