<?php
if(!isset($_SESSION['kullanici']['login'])){
    die('<meta http-equiv="refresh" content="0;URL=index.php">');
}
$_title         =  'Hesabım';


$query = $db->prepare("SELECT * FROM kullanici where id=:id LIMIT 1");
$kullanici = $query->execute(array(":id"=>$_SESSION['kullanici']['id']));
$kullanici = $query->fetch(PDO::FETCH_ASSOC);
?>
<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="hesabim">Hesabım</a></li>
  				</ul>
  			</div>
  		</div>
  	</div>
  </div>
</div>

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

      <div class="row mt-15">
        
        <div class="col-md-3"></div>
        <div class="col-md-9">
            
            <?php
              if($_POST){

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

                if($bilgi){
                    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("UPDATE kullanici SET  ad = ?, soyad = ?, telefon = ?, email = ?, sifre = ?, adres = ? WHERE id = ?");
                  $islem = $islem->execute(array($_POST['ad'],$_POST['soyad'],$_POST['telefon'],$_POST['email'],$_POST['sifre'],$_POST['adres'],$_SESSION['kullanici']['id']));
                  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;">Bilgileriniz başarı ile değiştirildi.<meta http-equiv="refresh" content="2;URL=hesabim"></div>';

                    }else{
                        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;">İşlem başarısız.</div>';
                    } 
                    
                }
              }
              ?>

        </div>

        <div class="col-md-3 mb-15">
            <div class="profile-sidebar">

              <div class="profile-userpic">
                <img src="images/pp.png" class="img-responsive" alt="">
              </div>

              <div class="profile-usertitle">
                <div class="profile-usertitle-name">
                  <?php echo @$kullanici['ad']; ?> <?php echo @$kullanici['soyad']; ?>
                </div>
              </div>

              <div class="profile-usermenu">
                <ul class="nav">
                  <li class="active">
                    <a href="hesabim"><i class="glyphicon glyphicon-user"></i> Hesabım</a>
                  </li>
                  <li>
                    <a href="siparislerim"><i class="glyphicon glyphicon-ok"></i> Siparişlerim</a>
                  </li>
                  <li>
                    <a href="cikis-yap"><i class="glyphicon glyphicon-log-out"></i> Çıkış Yap</a>
                  </li>
                </ul>
              </div>

            </div>
        </div>

        <div class="col-md-9">
          <div class="alan">
            <h5><i class="glyphicon glyphicon-user"></i> Kullanıcı Bilgilerim</h5>
          </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="<?php echo $kullanici['ad']; ?>">
              </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="<?php echo $kullanici['soyad'];  ?>">
              </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="<?php echo $kullanici['telefon']; ?>">
              </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="<?php echo $kullanici['email']; ?>">
              </fieldset>
              <fieldset class="form-group col-md-12">
                 <label>Şifreniz</label>
                 <input type="text" class="form-control" name="sifre" required="" value="<?php echo $kullanici['sifre']; ?>">
              </fieldset>
              <fieldset class="form-group col-md-12">
                 <label>Adresiniz</label>
                 <textarea class="form-control" name="adres" required="" placeholder="Adresiniz" rows="3"><?php echo $kullanici['adres']; ?></textarea>
              </fieldset>
              <fieldset class="form-group col-md-12">
                 <button class="btn icon-btn btn-success" style="width: 100%">Bilgilerimi Güncelle</button>
              </fieldset>
            </form>
          </div>
        </div>

      </div>

  </div>
</section>
