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

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

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

    $middle_array = array();
    foreach ($_POST['middle'] as $middle)
    {
        $row_array = date('Y-m-d H:i:s',strtotime($middle));
        array_push($middle_array,$row_array);
    }
    $ekle   = $db->prepare("insert into firma_sertifika set firma_adi=:firma_adi,sertifika=:sertifika,start=:start,middle=:middle,end=:end,isActive=:isActive");
    $simdi = $ekle->execute(array(
            "firma_adi" => $_POST['firma_adi'],
            "sertifika" => $_POST['sertifika'],
            "start"     => date('Y-m-d H:i:s',strtotime($_POST['start'])),
            "middle"    => json_encode($middle_array),
            "end"       => date('Y-m-d H:i:s',strtotime($_POST['end'])),
            "isActive"  => 1,
    ));
	if($simdi)
	{
    	$sonid=$db->query("select * from projeler order by id desc")->fetch(PDO::FETCH_ASSOC);
    	$yeni = $sonid['id'];
    		
    	$bilgi = "<div class='alert alert-success alert-dismissible fade show' role='alert'>
    	<strong>Firma Takibi Emri Ekleme BAŞARILI!</strong> Firma Takip Emri eklenmiştir.
        	<button type='button' class='close' data-dismiss='alert' aria-label='Close'>
        		<span aria-hidden='true'>&times;</span>
        	</button>
    	</div>";
	}
}

if(@$_POST['firma_sertifika_ekle'] and $_GET['islem']=="duzenle")
{
	
    $id = $_GET['id'];
    $middle_array = array();
    foreach ($_POST['middle'] as $middle)
    {
        $row_array = date('Y-m-d H:i:s',strtotime($middle));
        array_push($middle_array,$row_array);
    }
    $guncelle=$db->prepare("update firma_sertifika set firma_adi=:firma_adi,sertifika=:sertifika,start=:start,middle=:middle,end=:end,isActive=:isActive where id=:id");
    $simdii = $guncelle->execute(array(
        "firma_adi" => $_POST['firma_adi'],
        "sertifika" => $_POST['sertifika'],
        "start"     => date('Y-m-d H:i:s',strtotime($_POST['start'])),
        "middle"    => json_encode($middle_array),
        "end"       => date('Y-m-d H:i:s',strtotime($_POST['end'])),
        "isActive"  => 1,
        "id"        => $id,
        )
    );

}

if($simdii)
{
    $bilgi = "<div class='alert alert-success alert-dismissible fade show' role='alert'>
    	<strong> Firma Takibi Emri Güncelleme BAŞARILI!</strong> Firma Takibi Emri 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'];
	$guncelle   = $db->query("select * from firma_sertifika where id='$idd'")->fetch(PDO::FETCH_ASSOC);
}

$deger      = $db->query("select * from firma_sertifika order by id desc limit 1")->fetch(PDO::FETCH_ASSOC);
$sira       = $deger['sira']+1;
$idim       = $deger['id']+1;
$id         = $_SESSION['id'];
$hesabim    = $db->query("select * from yonetici where id='$id'")->fetch(PDO::FETCH_ASSOC);
?>

<!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"){?> <?=$isimler['projeler']?> Düzenle <?php } else {?>
	<?=$isimler['projeler']?> 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="drop/assets/dropzone.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']?>" />
	<style>
	    .form-control, .form-control:focus
	    {
            background-color: #ffffff;
            color: #000!important;
        }
	</style>
</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"><?=$isimler['firma_sertifika']?> 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"><?=$isimler['firma_sertifika']?> 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"><?=$isimler['firma_sertifika']?> Bilgileri</p>
                                                    </div>
                                                </a>
                                            </li>
                                          <!--<li class="nav-item">
                                            <a class="nav-link" id="calls-tab" data-toggle="tab" href="#calls" role="tab" aria-controls="calls" aria-selected="false">
                                              <div class="d-flex flex-row flex-lg-column flex-xl-row align-items-center">
                                                <i data-feather="image" 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">Çoklu Resim Alanı</p>
                                              </div>
                                            </a>
                                          </li>
                                          <li class="nav-item">
                                            <a class="nav-link" id="contacts-tab" data-toggle="tab" href="#contacts" role="tab" aria-controls="contacts" aria-selected="false">
                                              <div class="d-flex flex-row flex-lg-column flex-xl-row align-items-center">
                                                <i data-feather="users" 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">Seo Ayarları</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="firma_adi">Firma Adı</label>
                    								    <input type="text" class="form-control" id="firma_adi"  name="firma_adi" value="<?=$guncelle['firma_adi']?>">
                    								</div>
                    								
                    								<div class="form-group">
                    								    <label for="sertifika">Sertifika Adı</label>
                    								    <input type="text" class="form-control" id="sertifika"  name="sertifika" value="<?=$guncelle['sertifika']?>">
                    								</div>
                    								
                    								<div class="row">
                        								<div class="form-group col-md-6">
                        								    <label for="start">Başlangıç Tarihi</label>
                        								    <input type="datetime-local" class="form-control" id="start"  name="start" value="<?=$guncelle['start']?>">
                        								</div>
                        								
                        								<div class="form-group col-md-6">
                        								    <label for="end">Bitiş Tarihi</label>
                        								    <input type="datetime-local" class="form-control" id="end"  name="end" value="<?=$guncelle['end']?>">
                        								</div>
                    								</div>
                    								
                    								<div class="row" id="denetimContent">
                    								    <?
                    								    $middle_decode = json_decode($guncelle['middle'], true);
                    								    foreach ($middle_decode as $middle)
                    								    {
                    								    ?>
                        								    <div class="col-md-6 my-2">
                        								        <div class="row">
                        								            <div class="col-md-11">
                                    								    <label for="middle">Ara Denetim Tarihi</label>
                                    								    <input type="datetime-local" class="form-control" id="middle"  name="middle[]" value="<?=$middle;?>">
                        								            </div>
                        								            <div class="col-md-1">
                        								                <span class="removeBtn rounded-circle bg-danger p-2 cursor-pointer">
                        								                    <i class="fa fa-trash"></i>
                        								                </span>
                        								            </div>
                        								        </div>
                        								    </div>
                    								    <?
                    								    }
                    								    ?>
                    								</div>
                    								<span class="btn btn-primary btn-sm float-right my-3" id="addDenetim">
                    								    <i class="fa fa-plus"></i>
                    								    Ara Denetim Ekle
                    								</span>
                                                </div>
                                            </div>
                				        </div>
                				    </div>           
					                <input class="btn btn-primary btn-lg offset-md-3 col-md-6 mt-5" type="submit" <?php if(@$_GET['islem']=="duzenle"){?> value="<?=$isimler['firma_sertifika']?> Güncelle" <?php } else {?> value="<?=$isimler['firma_sertifika']?> Oluştur" <?php }?> name="firma_sertifika_ekle">
				                </form>
                                <br>
                			</div>
                		</div>	
                	</div>
                </div>	
            <div id="queue"></div>
        </div>
	    <?php include("include/footer.php");?>
    </div>
</div>  
	
	<script src="ckeditor-2/ckeditor.js"></script>
	<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>
	<link rel="stylesheet" href="assets/uploadfive/uploadifive.css" type="text/css">
    <script src="assets/uploadfive/jquery.uploadifive.min.js" type="text/javascript"></script>
    
	<script type="text/javascript">
	    $(document).ready(function(){

	      	var date = new Date();
	        var date_time = date.getTime();
	        $('.upload .icon span').uploadifive({
	            'auto'             : true,
	            'queueID'  : 'queue',
	            'fileSizeLimit' : '15360KB',
	            'fileExt'     : '*.jpg;*.jpeg;*.JPG;*.JPEG;*.png;*.PNG;*.svg;*.gif',
	            'width' : 25,
	            'buttonText' : " ",
	            'formData'         : {'timestamp' : date_time,'token' : 'sayim'+date_time+'sayim'},
	            'uploadScript'     : 'assets/uploadfive/uploadifive.php',
	            'removeCompleted' : true,
	            'onUploadComplete' : function(file, data) {
	                if(data == '2'){
	                    alert('Lütfen Geçerli Fortmatta Yükleme Yapınız.');
	                }else if(data == '3'){
	                    alert('İşlem Başarısız.(Dosya Boyutu İle Alakalı Olabilir.)');
	                }else{
	                    var id = $(this).attr('data-id');
	                    $('input[name="img'+id+'"]').val(data);
	                    $('#url').val('<?php echo $site; ?>madmin/lib/images/urunler/'+data);
	                    $('.uploaddis[data-id="'+id+'"] .yuklendi img').attr('src','../madmin/lib/images/urunler/'+data);
	                    $('.uploaddis[data-id="'+id+'"]').removeClass('aktif');
	                    $('.uploaddis[data-id="'+id+'"]').addClass('pasif');
	                }
	            }
	        });

	        $('.upload1 .icon span').uploadifive({
	            'auto'             : true,
	            'queueID'  : 'queue',
	            'fileSizeLimit' : '15360KB',
	            'fileExt'     : '*.jpg;*.jpeg;*.JPG;*.JPEG;*.png;*.PNG;*.svg;*.gif',
	            'width' : 25,
	            'buttonText' : " ",
	            'formData'         : {'timestamp' : date_time,'token' : 'sayim'+date_time+'sayim'},
	            'uploadScript'     : 'assets/uploadfive/uploadifive.php',
	            'removeCompleted' : true,
	            'onUploadComplete' : function(file, data) {
	                if(data == '2'){
	                    alert('Lütfen Geçerli Fortmatta Yükleme Yapınız.');
	                }else if(data == '3'){
	                    alert('İşlem Başarısız.(Dosya Boyutu İle Alakalı Olabilir.)');
	                }else{
	                    var say = $('#resimler .col-md-3').length;
	                    $('#resimler').append('\
	                    	<div class="col-md-3" data-resim-dis-id="'+say+'">\
				                    <div class="uploaddis pasif" style="float:left;">\
				        			  <div class="yuklendi">\
				        				  <img src="lib/images/urunler/'+data+'" width="100%">\
				        				  <div class="icon" data-resim-sil-id="'+say+'"><span class="fa fa-trash"></span></div>\
				        				  <input type="hidden" name="img[]" value="'+data+'" required="">\
				        			  </div>\
				        			</div>\
				                </div>\
				        ');

	                }
	            }
	        });
	        $(document).on('click','[data-resim-sil-id]', function(){
	        	$('[data-resim-dis-id="'+$(this).attr('data-resim-sil-id')+'"]').remove();
	        });

	        $('.yuklendi .icon').click(function(){
	            var id = $(this).attr('data-id');
	            $('.uploaddis[data-id="'+id+'"]').removeClass('pasif');
	            $('.uploaddis[data-id="'+id+'"]').addClass('aktif');
	            $('input[name="img'+id+'"]').val('');
	            $('.uploaddis[data-id="'+id+'"] .yuklendi img').attr('src','');
	        });
	        
	        $('#addDenetim').on('click', function()
	        {
	           $('#denetimContent').append(''
				    +'<div class="col-md-6 my-2">'
				    +'    <div class="row">'
				    +'        <div class="col-md-11">'
					+'		    <label for="middle">Ara Denetim Tarihi</label>'
					+'		    <input type="datetime-local" class="form-control" id="middle"  name="middle[]">'
				    +'        </div>'
				    +'        <div class="col-md-1">'
				    +'            <span class="removeBtn rounded-circle bg-danger p-2 cursor-pointer"><i class="fa fa-trash"></i></span>'
				    +'        </div>'
				    +'    </div>'
				    +'</div>'
	           +''); 
	        });
	        
	        $('body').on('click', '.removeBtn', function(){
	           $(this).parent().parent().parent().remove();
	        });
	      });
	      
	      
	      
	    </script>
        
</body>
</html>