<?php
if(isset($_SESSION['kullanici']['login'])){
    die('<meta http-equiv="refresh" content="0;URL=index.php">');
}
$_title         =  'Kayıt Ol - Giriş Yap';
?>
<div class="container-fluid adres_cubugu">
  <div class="row">
  	<div class="container">
  		<div class="row">
  			<div class="col-md-12">
  				<ul>
  					<li><a href="index.php"><i class="fa fa-home"></i> Anasayfa</a> <span><i class="fa fa-arrow-right"></i></span></li>
  					<li><a href="kayit-giris">Kayıt Ol - Giriş Yap</a></li>
  				</ul>
  			</div>
  		</div>
  	</div>
  </div>
</div>

<section class="bg-dis">
	<div class="container">

        <div class="row mt-15">
          
          <div class="col-md-6">
            <?php
              if($_POST['giris']){

                $query = $db->prepare("SELECT * FROM kullanici where email=:email AND sifre=:sifre LIMIT 1");
                $giris = $query->execute(array(":email"=>$_POST['email'],":sifre"=>$_POST['sifre']));
                $giris = $query->fetch(PDO::FETCH_ASSOC);

                if($giris){
                    echo '<div style="float: left;width: 100%;text-align: center;border: 1px solid green;background: green;color: #fff;padding: 4px 0px;font-size: 15px;margin-bottom: 10px;">Başarı ile giriş yaptınız.<br>Yönlendiriliyorsunuz.<meta http-equiv="refresh" content="2;URL=index.php"></div>';
                    $_SESSION['kullanici']['login'] = 1;
                    $_SESSION['kullanici']['id'] = $giris['id'];
                }else{
                    echo '<div style="float: left;width: 100%;text-align: center;border: 1px solid #13ad19;background: #13ad19;color: #fff;padding: 4px 0px;font-size: 15px;margin-bottom: 10px;">Giriş bilgileriniz yanlış.</div>';
                }

              }
            ?>
            <div class="alan" style="margin-bottom: 0px;border-bottom: 0px">
              <h3 style="margin-top: 0px;float: left;width: 100%;margin-bottom: 0px">Giriş Yap</h3>
            </div>
            <div class="alan">
              <form action="" method="post">
                  <fieldset class="form-group mt-4 col-md-12">
                     <label>Email Adresiniz</label>
                     <input type="email" class="form-control" name="email" required="" placeholder="Email Adresiniz" value="">
                  </fieldset>
                  <fieldset class="form-group col-md-12">
                     <label>Şifreniz</label>
                     <input type="password" class="form-control" name="sifre" required="" placeholder="********">
                  </fieldset>
                  <fieldset class="form-group col-md-12">
                    <label class="form-check-label" for="exampleCheck1"><a href="sifremi-unuttum"><i class="fa fa-envelope-open"></i> Şifremi Unuttum</a></label>
                  </fieldset>
                  <fieldset class="form-group col-md-12">
                     <button class="btn icon-btn btn-success" style="width: 100%">Giriş Yap</button>
                  </fieldset>
                  <input type="hidden" name="giris" value="1">
                </form>
            </div>
          </div>

           <div class="col-md-6">
            <?php
              if($_POST['kayit']){

                $query = $db->prepare("SELECT * FROM kullanici where email=:email LIMIT 1");
                $kayit = $query->execute(array(":email"=>$_POST['email']));
                $kayit = $query->fetch(PDO::FETCH_ASSOC);

                if($kayit){
                  echo '<div style="float: left;width: 100%;text-align: center;border: 1px solid #d45d56;background: #ca5454;color: #fff;padding: 4px 0px;font-size: 15px;margin-bottom: 10px;">Bu email adresi zaten kullanılıyor.</div>';
                }else{
                  $islem = $db->prepare("INSERT INTO kullanici SET ad = ?, soyad = ?, telefon = ?, email = ?, sifre = ?, adres = ?");
                  $islem = $islem->execute(array($_POST['ad'],$_POST['soyad'],$_POST['telefon'],$_POST['email'],$_POST['sifre'],''));
                  if($islem){
                      echo '<div style="float: left;width: 100%;text-align: center;border: 1px solid #13ad19;background: #13ad19;color: #fff;padding: 4px 0px;font-size: 15px;margin-bottom: 10px;">Başarı ile kayıt oldunuz.<br>Yönlendiriliyorsunuz.<meta http-equiv="refresh" content="2;URL=index.php"></div>';
                      $_SESSION['kullanici']['login'] = 1;
                      $_SESSION['kullanici']['id'] = $db->lastInsertId();
                  }else{
                      echo 'İşlem başarısız.';
                  }
                }

              }
            ?>

            <div class="alan" style="margin-bottom: 0px;border-bottom: 0px">
              <h3 style="margin-top: 0px;float: left;width: 100%;margin-bottom: 0px">Kayıt Ol</h3>
            </div>
            <div class="alan">
              <form action="" method="post">
                  <fieldset class="form-group mt-4 col-md-6">
                     <label>Adınız</label>
                     <input type="text" class="form-control" name="ad" required="" placeholder="Adınız" value="">
                  </fieldset>
                  <fieldset class="form-group mt-4 col-md-6">
                     <label>Soyadınız</label>
                     <input type="text" class="form-control" name="soyad" required="" placeholder="Soyadınız" value="">
                  </fieldset>
                  <fieldset class="form-group mt-4 col-md-6">
                     <label>Telefon</label>
                     <input type="text" class="form-control" name="telefon" required="" placeholder="Telefon" value="">
                  </fieldset>
                  <fieldset class="form-group mt-4 col-md-6">
                     <label>Email Adresiniz</label>
                     <input type="email" class="form-control" name="email" required="" placeholder="Email Adresiniz" value="">
                  </fieldset>
                  <fieldset class="form-group col-md-12">
                     <label>Şifreniz</label>
                     <input type="password" class="form-control" name="sifre" required="" placeholder="********">
                  </fieldset>
                  <fieldset class="form-group col-md-12">
                     <label>Adresiniz</label>
                     <textarea class="form-control" name="adres" required="" placeholder="Adresiniz" rows="3"></textarea>
                  </fieldset>
                  <fieldset class="form-group col-md-12">
                    <div class="form-check">
                      <input type="checkbox" class="form-check-input" id="exampleCheck1" required="">
                      <label class="form-check-label" for="exampleCheck1">Talebim doğrultusunda <a href="sayfa/kullanici-sozlesmesi" target="_blank">kullanıcı sözleşmesini</a> onaylıyorum.</label>
                    </div>
                  </fieldset>
                  <fieldset class="form-group col-md-12">
                     <button class="btn icon-btn btn-success" style="width: 100%">Kayıt Ol</button>
                  </fieldset>
                  <input type="hidden" name="kayit" value="1">
                </form>
            </div>
          </div>


        </div>

  </div>
</section>
