<?php include("header.php");?>
<?php
if(p('kategori_adi') && g('islem')=="")
{
	$kategori_adi 	= $_POST['kategori_adi'];
	$icon		 	= $_POST['icon'];
	$durum 			= $_POST['durum'];
	$seo			= seo($kategori_adi);
	
	include_once('class.upload.php');
	$upload = new upload($_FILES['resim']);
	if ($upload->uploaded){
	$upload->file_auto_rename = true;
	$upload->process("../uploads/urunkategori");
	
	$upload->file_auto_rename = true;
	$upload->image_resize = true;
	$upload->image_ratio_crop = true;
	$upload->image_x = 870;
	$upload->image_y = 255;
	$upload->process("../uploads/urunkategori/kucuk");
	
	if ($upload->processed){
	$UrunKategoriResim=''.$upload->file_dst_name.'';
	}
	}
	$gitti1	=$UrunKategoriResim=''.$upload->file_dst_name.'';
	
	$kategori_sorgu	=	mysql_query("INSERT INTO urun_kategori SET
										kategori_adi	=	'$kategori_adi',
										resim			=	'$UrunKategoriResim', 
										icon			=	'$icon',
										seo				=	'$seo', 
										durum			=	'$durum'");	
																								   
		$bilgi = '    <div class="alert alert-success alert-block fade in">
                                  <button data-dismiss="alert" class="close close-sm" type="button">
                                      <i class="fa fa-times"></i>
                                  </button>
                                  <h4>
                                      <i class="fa fa-ok-sign"></i>
                                      Başarılı!
                                  </h4>
                                  <p>Başarıyla eklenmiştir...</p>
                              </div>
		 ' ;
		
}


if(p('kategori_adi') && g('islem')=="duzenle")
{
	$kategori_adi 	= $_POST['kategori_adi'];
	$icon		 	= $_POST['icon'];
	$durum 			= $_POST['durum'];
	$d_id 			= g('id');
	$seo			= seo($kategori_adi);
	
	include_once('class.upload.php');
	$upload = new upload($_FILES['resim']);
	if ($upload->uploaded){
	$upload->file_auto_rename = true;
	$upload->process("../uploads/urunkategori");
	
	$upload->file_auto_rename = true;
	$upload->image_resize = true;
	$upload->image_ratio_crop = true;
	$upload->image_x = 870;
	$upload->image_y = 255;
	$upload->process("../uploads/urunkategori/kucuk");
	
	if ($upload->processed){
	$UrunKategoriResim=''.$upload->file_dst_name.'';
	}
	}
	$gitti1	=$UrunKategoriResim=''.$upload->file_dst_name.'';
	
	if($UrunKategoriResim!="")
	{
		$resim_bul	=	Sonuc(Sorgu("SELECT * FROM urun_kategori WHERE id='$d_id'"));
		$resim_sil	=	unlink("../uploads/urunkategori/kucuk/".$resim_bul->resim);
		$resim_sil	=	unlink("../uploads/urunkategori/".$resim_bul->resim);
	
		$kategori_duzenle_sorgu = Sorgu("UPDATE urun_kategori SET 
											kategori_adi	=	'$kategori_adi', 
											resim			=	'$UrunKategoriResim',
											icon			=	'$icon', 
											seo				=	'$seo', 
											durum			=	'$durum' 
											WHERE id		=	'$d_id'");
	}else{
		$kategori_duzenle_sorgu = Sorgu("UPDATE urun_kategori SET 
											kategori_adi	=	'$kategori_adi', 
											icon			=	'$icon', 
											seo				=	'$seo', 
											durum			=	'$durum' 
											WHERE id		=	'$d_id'");
		
	}if($kategori_duzenle_sorgu){
		$bilgi = ' 	  <div class="alert alert-success alert-block fade in">
                                  <button data-dismiss="alert" class="close close-sm" type="button">
                                      <i class="fa fa-times"></i>
                                  </button>
                                  <h4>
                                      <i class="fa fa-ok-sign"></i>
                                      Başarılı!
                                  </h4>
                                  <p>Başarıyla güncellenmiştir...</p>
                              </div>
		 ' ;
	}
		  
}


if($_GET['islem']=="duzenle")
{
	$sayfaid = $_GET['id'];	
	$durum = "duzenle" ;
	
	$KategoriSonuc = Sonuc(Sorgu("SELECT * FROM urun_kategori WHERE id='$sayfaid'"));	
}
?>

 <!--main content start-->
      <section id="main-content">
          <section class="wrapper">
              <!-- page start-->
        
            

              <div class="row">
                  <div class="col-lg-12">
				    <?php echo $bilgi;?>
                      <section class="panel">
                          <header class="panel-heading">
                            Kategori Ekle
                          </header>
                          <div class="panel-body">
                              <form class="form-horizontal tasi-form" method="post" action="" enctype="multipart/form-data">
							  
							  

                                  <div class="form-group">
                                      <label class="col-sm-2 col-sm-2 control-label">Kategori Adı</label>
                                      <div class="col-sm-10">
                                                <input type="text" class="form-control" name="kategori_adi" value="<?php echo $KategoriSonuc->kategori_adi;?>" id="sayfaadi" placeholder="">
                                      </div>
                                  </div>
                             
                           <div class="form-group">
                                      <label class="col-sm-2 col-sm-2 control-label"><a href="http://fontawesome.io/icons/" target="_blank">Kategori İkonu Seçin    Tıkla</a></label>
                                      <div class="col-sm-10">
                                                <input type="text" class="form-control" name="icon" value="<?php echo $KategoriSonuc->icon;?>" id="icon" placeholder="Örnek :user">
                                      </div>
                                  </div>
						 
						 
						             <div class="form-group last">
                                          <label class="col-sm-2 col-sm-2 control-label">Kategori Resmi</label>
                                           <div class="col-sm-10">
                                              <div class="fileupload fileupload-new" data-provides="fileupload">
                                               <div class="fileupload-new thumbnail" style="width: 200px; height: 150px;">
                                               <?php if($_GET['islem']=='duzenle'){?>
                                               <img src="../uploads/urunkategori/<?php echo $KategoriSonuc->resim;?>" style="width: 200px; height: 200px;" alt="" />
                                               <?php } else { ?>
                                              <img src="http://www.placehold.it/200x150/EFEFEF/AAAAAA&amp;text=no+image" alt="" />
                                              <?php }?>
                                              </div>
                                                  <div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 200px; max-height: 150px; line-height: 20px;"></div>
                                                  <div>
                                                   <span class="btn btn-white btn-file">
                                                   <span class="fileupload-new"><i class="fa fa-paper-clip"></i> Resim Seç</span>
                                                   <span class="fileupload-exists"><i class="fa fa-undo"></i> Değiştir</span>
                                                   <input type="file" name="resim" class="default" />
                                                   </span>
                                                      <a href="#" class="btn btn-danger fileupload-exists" data-dismiss="fileupload"><i class="fa fa-trash"></i> Sil</a>
                                                  </div>
                                              </div>
                                            
                                          </div>
                                      </div>
						 
						 
						 
						          <div class="row m-bot15">
                                  <?php if($_GET['islem']=="duzenle"){?>
								 <label class="col-sm-2 col-sm-2 control-label">Durumu</label>
                                           <div class="col-sm-10">
                                           <input type="checkbox" name="durum" <?php if($KategoriSonuc->durum == '1') {?> checked <?php } ?> value="1" data-toggle="switch"/>
                                          </div>
                                        	<?php }else{?>
											 <label class="col-sm-2 col-sm-2 control-label">Durumu</label>
                                          <div class="col-sm-10">
                                           	<input type="checkbox" name="durum" value="1" checked data-toggle="switch"/>
                                          </div>
										  <?php } ?>
                                      </div>
						 
						 
						 
						
						 
						 
						 
						 
						 
						         <div class="form-group">
                                        <div class="col-sm-10">
									    <?php if($_GET['islem']=="duzenle"){?>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                          <button class="btn btn-shadow btn-danger" type="submit">Güncelle</button>
										  <?php }else{?>
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
										  <button class="btn btn-shadow btn-success" type="submit">Kaydet</button>
										   <?php } ?>
                                      </div>
                                  </div>
						 
						 
						 
						 
						 
						 
                              </form>
                          </div>
                      </section>
                  
                      

           

               

                  </div>
              </div>
              <!-- page end-->
          </section>
      </section>
      <!--main content end-->





















<?php include("footer.php");?>