<?php
include("include/baglan.php");
include("include/fonksiyonlar.php");



ob_start();
session_start();
oturumkontrolana();

$id=$_SESSION['id'];
$hesabim=$db->query("select * from yonetici where id='$id'")->fetch(PDO::FETCH_ASSOC);

if($_POST['kaydet'] and $_GET['islem']=="" ){

	$ad_soyad=$_POST['ad_soyad'];
	$eposta=$_POST['eposta'];
	
		$normalsifre=$_POST['sifre'];
	$sifre=$_POST['sifre'];
	$sifre = sha1($sifre);
	
	$klasor1="lib/images/yonetici/";
	$resim_tmp1 = $_FILES['logo']['tmp_name'];
	if(empty($resim_tmp1))
	{
		$logo = "resim-yok";
	}
	else
	{
		
		if ($_FILES["logo"]["type"] =="image/gif" || $_FILES["logo"]["type"] =="image/png"|| $_FILES["logo"]["type"] =="image/jpg"|| $_FILES["logo"]["type"] =="image/jpeg") 
		{
			$random = rand(0,999);
			
			$logo = $random.$adii.substr($_FILES['logo']['name'], -3);
			
			move_uploaded_file($_FILES['logo']['tmp_name'],$klasor1."/".$logo);
		}
		else
		{
			$bilgi = '<div class="alert alert-error">
										<button class="close" data-dismiss="alert">×</button>
										<strong>Hata !</strong> Lütfen  Uygun Formatta Bir Resim Dosyası Seçiniz ( .jpg - .gif - .png ).
			</div>';
		}
	}
	
	
	
	$klasor2="lib/images/yonetici/";
	$resim_tmp2 = $_FILES['kapak_foto']['tmp_name'];
	if(empty($resim_tmp2))
	{
		$kapak_foto = "resim-yok";
	}
	else
	{
		
		if ($_FILES["kapak_foto"]["type"] =="image/gif" || $_FILES["kapak_foto"]["type"] =="image/png"|| $_FILES["kapak_foto"]["type"] =="image/jpg"|| $_FILES["kapak_foto"]["type"] =="image/jpeg") 
		{
			$random = rand(0,999);
			
			$kapak_foto = $random."-".$adii.".".substr($_FILES['kapak_foto']['name'], -3);
			
			move_uploaded_file($_FILES['kapak_foto']['tmp_name'],$klasor2."/".$kapak_foto);
		}
		else
		{
			$bilgi = '<div class="alert alert-error">
										<button class="close" data-dismiss="alert">×</button>
										<strong>Hata !</strong> Lütfen  Uygun Formatta Bir Resim Dosyası Seçiniz ( .jpg - .gif - .png ).
			</div>';
		}
	}
	
	
	$ekle=$db->prepare("insert into yonetici set normalsifre=:normalsifre,ad_soyad=:ad_soyad,eposta=:eposta,sifre=:sifre,kapak_foto=:kapak_foto,logo=:logo");
	
	$simdii=$ekle->execute(array("normalsifre"=>$normalsifre,"ad_soyad"=>$ad_soyad,"sifre"=>$sifre,"eposta"=>$eposta,"logo"=>$logo,"kapak_foto"=>$kapak_foto));
	
	if($simdii){
	$bilgi = "<div class='alert alert-success alert-dismissible fade show' role='alert'>
	<strong>Yönetici Ekleme BAŞARILI!</strong> Yönetici Eklenmiştir.
	<button type='button' class='close' data-dismiss='alert' aria-label='Close'>
		<span aria-hidden='true'>&times;</span>
	</button>
</div>";
}
	
	
}

if($_POST['kaydet'] and $_GET['islem']=='duzenle'){
	
	$id=$_GET['id'];
	
	$ad_soyad=$_POST['ad_soyad'];
	$sifre=$_POST['sifre'];
	$eposta=$_POST['eposta'];
	$normalsifre=$_POST['sifre'];
	$sifre = sha1($sifre);
	$klasor3="lib/images/yonetici/";
	
	$resim_tmp3 = $_FILES['logo']['tmp_name'];
	
	if(empty($resim_tmp3))
	{
		$id = $_GET['id'];
		$ayar_kaydi = $db->query("SELECT * FROM yonetici WHERE id = '$id'")->fetch(PDO::FETCH_ASSOC);
		$logo = $ayar_kaydi['logo'];
	}
	else
	{
		if ($_FILES["logo"]["type"] =="image/gif" || $_FILES["logo"]["type"] =="image/png"|| $_FILES["logo"]["type"] =="image/jpg"|| $_FILES["logo"]["type"] =="image/jpeg") 
		{
			
			$ayar_kaydi = $db->query("SELECT * FROM yonetici WHERE id = '$id'")->fetch(PDO::FETCH_ASSOC);
  			if($ayar_kaydi['logo']!="resim-yok")
			{
			  unlink("lib/images/yonetici/".$ayar_kaydi['logo']);	  
			}
			
			$random = rand(0,999);
			
			$logo = $random."-".$adii.".".substr($_FILES['logo']['name'], -3);
			
			move_uploaded_file($_FILES['logo']['tmp_name'],$klasor3."/".$logo);
		}
		else
		{
			$bilgi = '<div class="alert alert-error">
										<button class="close" data-dismiss="alert">×</button>
										<strong>Hata !</strong> Lütfen  Uygun Formatta Bir Resim Dosyası Seçiniz ( .jpg - .gif - .png ).
			</div>';
		}
	}
	
	
	$klasor1="lib/images/yonetici/";
	
	$resim_tmp1 = $_FILES['kapak_foto']['tmp_name'];
	
	if(empty($resim_tmp1))
	{
		$id = $_GET['id'];
		$ayar_kaydi = $db->query("SELECT * FROM yonetici WHERE id = '$id'")->fetch(PDO::FETCH_ASSOC);
		$kapak_foto = $ayar_kaydi['kapak_foto'];
	}
	else
	{
		if ($_FILES["kapak_foto"]["type"] =="image/gif" || $_FILES["kapak_foto"]["type"] =="image/png"|| $_FILES["kapak_foto"]["type"] =="image/jpg"|| $_FILES["kapak_foto"]["type"] =="image/jpeg") 
		{
			
			$ayar_kaydi = $db->query("SELECT * FROM yonetici WHERE id = '$id'")->fetch(PDO::FETCH_ASSOC);
  			if($ayar_kaydi['kapak_foto']!="resim-yok")
			{
			  unlink("lib/images/yonetici/".$ayar_kaydi['kapak_foto']);	  
			}
			
			$random = rand(0,999);
			
			$kapak_foto = $random."-".$adii.".".substr($_FILES['kapak_foto']['name'], -3);
			
			move_uploaded_file($_FILES['kapak_foto']['tmp_name'],$klasor1."/".$kapak_foto);
		}
		else
		{
			$bilgi = '<div class="alert alert-error">
										<button class="close" data-dismiss="alert">×</button>
										<strong>Hata !</strong> Lütfen  Uygun Formatta Bir Resim Dosyası Seçiniz ( .jpg - .gif - .png ).
			</div>';
		}
	}
	
	
	$guncelle=$db->prepare("update yonetici SET normalsifre=:normalsifre,ad_soyad=:ad_soyad,eposta=:eposta,sifre=:sifre,logo=:logo,kapak_foto=:kapak_foto,ilk_giris=:ilk_giris where id=:id");
	
	$simdi=$guncelle->execute(array("normalsifre"=>$normalsifre,"ad_soyad"=>$ad_soyad,"sifre"=>$sifre,"eposta"=>$eposta,"logo"=>$logo,"kapak_foto"=>$kapak_foto,"ilk_giris"=>$tarih,"id"=>$id));

	
	
}

if($simdi){
	$bilgi = "<div class='alert alert-success alert-dismissible fade show' role='alert'>
	<strong>Yönetici Güncelleme BAŞARILI!</strong> Yönetici Güncellenmiştir.
	<button type='button' class='close' data-dismiss='alert' aria-label='Close'>
		<span aria-hidden='true'>&times;</span>
	</button>
</div>";
}
	
	
	
if(@$_GET['islem']=="duzenle"){
	
	$idd=$_GET['id'];
	
	$goster=$db->query("select * from yonetici where id='$idd'")->fetch(PDO::FETCH_ASSOC);
	
	
	
		$gsifre = sha1($goster['sifre']);
	
}





?>


<!DOCTYPE html>
<html lang="tr">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>
	    
	    <?php
	    if($_GET['islem']=="duzenle"){
	    ?>
	    <?=$goster['ad_soyad']?> Düzenle <?php } else {?>
	    Yönetici Ekle <?php }?> - <?=$ayar['site_title']?></title>

	<link rel="stylesheet" href="assets/vendors/core/core.css">
<link rel="stylesheet" href="assets/vendors/sweetalert2/sweetalert2.min.css">
	<link rel="stylesheet" href="assets/vendors/select2/select2.min.css">
	<link rel="stylesheet" href="assets/vendors/jquery-tags-input/jquery.tagsinput.min.css">
	<link rel="stylesheet" href="assets/vendors/dropzone/dropzone.min.css">
	<link rel="stylesheet" href="assets/vendors/dropify/dist/dropify.min.css">
	<link rel="stylesheet" href="assets/vendors/bootstrap-colorpicker/bootstrap-colorpicker.min.css">
	<link rel="stylesheet" href="assets/vendors/bootstrap-datepicker/bootstrap-datepicker.min.css">
	<link rel="stylesheet" href="assets/vendors/font-awesome/css/font-awesome.min.css">
	<link rel="stylesheet" href="assets/vendors/tempusdominus-bootstrap-4/tempusdominus-bootstrap-4.min.css">

	<link rel="stylesheet" href="assets/fonts/feather-font/css/iconfont.css">
	<link rel="stylesheet" href="assets/vendors/flag-icon-css/css/flag-icon.min.css">

	<link rel="stylesheet" href="assets/css/demo_2/style.css">
<link rel="shortcut icon" href="lib/images/logo/<?=$ayar['favicon']?>" />
</head>
<body>
	<div class="main-wrapper">

		<?php include("include/menu.php");?>
    
	
	
		<div class="page-wrapper">
				
		
			<?php include("include/header.php");?>
			<div class="page-content">

				<nav class="page-breadcrumb">
					<ol class="breadcrumb">
						<li class="breadcrumb-item"><a href="./">Anasayfa</a></li>
						<li class="breadcrumb-item active" aria-current="page">Yönetici Ekle</li>
					</ol>
				</nav>

			
				
				<div class="row">
					<div class="col-md-12 grid-margin stretch-card">
						<div class="card">
							<div class="card-body">
								<h6 class="card-title">Site Bilgilerini Giriniz</h6>
                                <?=$bilgi?>
								<form class="cmxform" method="post" enctype="multipart/form-data">
								
                                    
                                  
                                    
                             <div class="aside-body">
                        <ul class="nav nav-tabs mt-3" role="tablist">
                          <li class="nav-item">
                            <a class="nav-link active" id="chats-tab" data-toggle="tab" href="#chats" role="tab" aria-controls="chats" aria-selected="true">
                              <div class="d-flex flex-row flex-lg-column flex-xl-row align-items-center">
                                <i data-feather="message-square" class="icon-sm mr-sm-2 mr-lg-0 mr-xl-2 mb-md-1 mb-xl-0"></i>
                                <p class="d-none d-sm-block">Yönetici Bilgileri</p>
                              </div>
                            </a>
                          </li>
                          
                          
                        </ul>
                        <div class="tab-content mt-3">
                          <div class="tab-pane fade show active" id="chats" role="tabpanel" aria-labelledby="chats-tab">
                            <div>
                             
                            
								
                             
                             <div class="form-group">
										<label for="exampleInputText1">Yönetici Adı</label>
	<input type="text" class="form-control" id="exampleInputText1"  name="ad_soyad" value="<?=$goster['ad_soyad']?>">
									</div>
                                    
                                      <div class="form-group">
										<label for="exampleInputText1">Yönetici E-Posta</label>
		<input type="text" class="form-control" id="exampleInputText1"  name="eposta" value="<?=$goster['eposta']?>">
									</div>
                                    
                                      <div class="form-group">
										<label for="exampleInputText1">Yönetici Şifre</label>
	<input type="password" class="form-control" id="exampleInputText1"  name="sifre" value="<?=$goster['normalsifre']?>">
									</div>
									
									
									
									
									
									
									
									
									
									
                                     <div class="row">
				
					<div class="col-md-4 stretch-card">
						<div class="card">
							<div class="card-body">
								<h6 class="card-title">Yönetici Logo</h6>
								
								<input type="file" id="myDropify" class="border" name="logo" <?php if(@$_GET['islem']=="duzenle"){?> data-default-file="lib/images/yonetici/<?=$goster['logo']?>" <?php }?>/>
							</div>
						</div>
					</div>
                    
                    <div class="col-md-4 stretch-card">
						<div class="card">
							<div class="card-body">
								<h6 class="card-title">Yönetici Kapak Fotoğrafı</h6>
								
								<input type="file" id="myDropify1" class="border" name="kapak_foto"  <?php if(@$_GET['islem']=="duzenle"){?> data-default-file="lib/images/yonetici/<?=$goster['kapak_foto']?>" <?php }?> />
							</div>
						</div>
					</div>
                    
                   
				</div>
                
              

                                    
									
							
                                    
                                    
                                     
                            </div>
                          </div>
                          
                          
                        </div>
                      </div>       
                                   
				
                                    
									  <br>                                
		<input class="btn btn-primary" type="submit"<?php if(@$_GET['islem']=="duzenle"){?> value="Yönetici Güncelle" <?php } else {?> value="Yönetici Ekle" <?php }?> name="kaydet">
								</form>
							</div>
						</div>
					</div>
				</div>
				
				

				

			</div>

			<?php include("include/footer.php");?>
	
		</div>
	</div>
	<script src="assets/vendors/core/core.js"></script>

	<script src="assets/vendors/jquery-validation/jquery.validate.min.js"></script>
	<script src="assets/vendors/bootstrap-maxlength/bootstrap-maxlength.min.js"></script>
	<script src="assets/vendors/inputmask/jquery.inputmask.min.js"></script>
	<script src="assets/vendors/select2/select2.min.js"></script>
	<script src="assets/vendors/typeahead.js/typeahead.bundle.min.js"></script>
	<script src="assets/vendors/jquery-tags-input/jquery.tagsinput.min.js"></script>
	<script src="assets/vendors/dropzone/dropzone.min.js"></script>
	<script src="assets/vendors/dropify/dist/dropify.min.js"></script>
	<script src="assets/vendors/bootstrap-colorpicker/bootstrap-colorpicker.min.js"></script>
	<script src="assets/vendors/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
	<script src="assets/vendors/moment/moment.min.js"></script>
	<script src="assets/vendors/tempusdominus-bootstrap-4/tempusdominus-bootstrap-4.js"></script>

	<script src="assets/vendors/feather-icons/feather.min.js"></script>
	<script src="assets/js/template.js"></script>
	<script src="assets/vendors/tinymce/tinymce.min.js"></script>
	<script src="assets/js/form-validation.js"></script>
	<script src="assets/js/bootstrap-maxlength.js"></script>
	<script src="assets/js/inputmask.js"></script>
	<script src="assets/js/select2.js"></script>
	<script src="assets/js/typeahead.js"></script>
	<script src="assets/js/tags-input.js"></script>
	<script src="assets/js/dropzone.js"></script>
	<script src="assets/js/dropify.js"></script>
	<script src="assets/js/bootstrap-colorpicker.js"></script>
	<script src="assets/js/datepicker.js"></script>
	<script src="assets/js/timepicker.js"></script>
<script src="assets/js/tinymce.js"></script>

 <script src="assets/vendors/sweetalert2/sweetalert2.min.js"></script>
   <script src="assets/js/sweet-alert.js"></script>


</body>
</html>