<?
	ob_start();
	session_start();
	include_once("../sistem/database.php");
	include_once("../sistem/upload.php");
	include_once("sistem/admin.php");
	 $db     	= new database();
	 $admin		= new user(); 
	  $db->baglanti();
	  $login = $admin->giris();
	 if($login=="fail"){
        header("location: login.php");
    }else{
		function replace_tr($text) {
			$text = trim($text);
			$search = array('Ç','ç','Ğ','ğ','ı','İ','Ö','ö','Ş','ş','Ü','ü',' ', "'", "!", "(", ")");
			$replace = array('c','c','g','g','i','i','o','o','s','s','u','u','-', "-", "-", "", "");
			$new_text = str_replace($search,$replace,$text);
		return $new_text;
		} 
?>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9"> <![endif]-->
<!--[if !IE]><!--> <html lang="en"> <!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
	<meta charset="utf-8" />
	<title>TICARETIUMbasic Admin Paneli</title>
	<meta content="width=device-width, initial-scale=1.0" name="viewport" />
	<meta content="" name="description" />
	<meta content="" name="author" />
	 <link href="assets/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
   <link href="assets/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" />
   <link href="assets/bootstrap/css/bootstrap-fileupload.css" rel="stylesheet" />
   <link href="assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
   <link href="css/style.css" rel="stylesheet" />
   <link href="css/style_responsive.css" rel="stylesheet" />
   <link href="css/style_default.css" rel="stylesheet" id="style_color" />

   <link href="assets/fancybox/source/jquery.fancybox.css" rel="stylesheet" />
   <link rel="stylesheet" type="text/css" href="assets/gritter/css/jquery.gritter.css" />
   <link rel="stylesheet" type="text/css" href="assets/uniform/css/uniform.default.css" />
   <link rel="stylesheet" type="text/css" href="assets/chosen-bootstrap/chosen/chosen.css" />
   <link rel="stylesheet" type="text/css" href="assets/jquery-tags-input/jquery.tagsinput.css" />    
   <link rel="stylesheet" type="text/css" href="assets/clockface/css/clockface.css" />
   <link rel="stylesheet" type="text/css" href="assets/bootstrap-wysihtml5/bootstrap-wysihtml5.css" />
   <link rel="stylesheet" type="text/css" href="assets/bootstrap-datepicker/css/datepicker.css" />
   <link rel="stylesheet" type="text/css" href="assets/bootstrap-timepicker/compiled/timepicker.css" />
   <link rel="stylesheet" type="text/css" href="assets/bootstrap-colorpicker/css/colorpicker.css" />
   <link rel="stylesheet" href="assets/bootstrap-toggle-buttons/static/stylesheets/bootstrap-toggle-buttons.css" />
   <link rel="stylesheet" href="assets/data-tables/DT_bootstrap.css" />
   <link rel="stylesheet" type="text/css" href="assets/bootstrap-daterangepicker/daterangepicker.css" />
    <link href="../css/font.css" rel="stylesheet" type="text/css">


</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<body class="fixed-top">
	<!-- BEGIN HEADER -->
	<div id="header" class="navbar navbar-inverse navbar-fixed-top">
		<!-- BEGIN TOP NAVIGATION BAR -->
		<div class="navbar-inner">
			<div class="container-fluid">
				<!-- BEGIN LOGO -->
				<a class="brand" href="index.php">
				    <img src="img/logo.png" alt="Admin Lab" />
				</a>
				<!-- END LOGO -->
				<!-- BEGIN RESPONSIVE MENU TOGGLER -->
				<a class="btn btn-navbar collapsed" id="main_menu_trigger" data-toggle="collapse" data-target=".nav-collapse">
				<span class="icon-bar"></span>
				<span class="icon-bar"></span>
				<span class="icon-bar"></span>
				<span class="arrow"></span>
				</a>
				<!-- END RESPONSIVE MENU TOGGLER --><!-- END  NOTIFICATION -->
                <div class="top-nav ">
                    <ul class="nav pull-right top-menu" >
                        <!-- BEGIN SUPPORT --><!-- END SUPPORT -->
						<!-- BEGIN USER LOGIN DROPDOWN -->
						<li class="dropdown">
							<a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            	<img src="img/yvzshn.jpg" alt="">
                                <span class="username"><?=$admin->admininfo($_SESSION['a_adminus']);?></span>
							<b class="caret"></b>
							</a>
							<ul class="dropdown-menu">
								
								<li><a href="logout.php"><i class="icon-key"></i> Çıkış Yap</a></li>
							</ul>
						</li>
						<!-- END USER LOGIN DROPDOWN -->
					</ul>
					<!-- END TOP NAVIGATION MENU -->
				</div>
			</div>
		</div>
		<!-- END TOP NAVIGATION BAR -->
	</div>
	<!-- END HEADER -->
	<!-- BEGIN CONTAINER -->
	<div id="container" class="row-fluid">
		<!-- BEGIN SIDEBAR -->
		<div id="sidebar" class="nav-collapse collapse">
			<!-- BEGIN SIDEBAR TOGGLER BUTTON -->
			<div class="sidebar-toggler hidden-phone"></div>
			<!-- BEGIN SIDEBAR MENU -->
			<ul class="sidebar-menu">
             	<li><a class="" href="index.php"><span class="icon-box"><i class="icon-dashboard"></i></span> Anasayfa</a></li>
                 <li><a class="" href="ayarlar.php"><span class="icon-box"><i class="icon-wrench"></i></span> Ayarlar</a></li>
                 <li><a class="" href="odeme.php"><span class="icon-box"><i class="icon-money"></i></span> Ödemeler</a></li>
				<li class="has-sub">
					<a href="javascript:;" class="">
					    <span class="icon-box"> <i class="icon-bookmark"></i></span> Sayfalar
                        <span class="arrow"></span>
                    </a>
                    <ul class="sub">
                        <li><a class="" href="sayfa.php?p=tum">Tüm Sayfalar</a></li>
                    </ul>
				</li>
				<li class="has-sub active open">
					<a href="javascript:;" class="">
					    <span class="icon-box"> <i class="icon-barcode"></i></span> Fırsatlar
                        <span class="arrow"></span>
                    </a>
                    <ul class="sub">
                        <li><a class="" href="firsatlar.php?p=ekle">Yeni Ekle</a></li>
                        <li><a class="" href="firsatlar.php?p=tum">Tüm Fırsatlar</a></li>

                    </ul>
				</li>
                <li><a class="" href="uyeler.php"><span class="icon-box"><i class="icon-group"></i></span> Üyeler</a></li>
			</ul>
			<!-- END SIDEBAR MENU -->
		</div>
		<!-- END SIDEBAR -->
		<!-- BEGIN PAGE -->
		<div id="main-content">
			<!-- BEGIN PAGE CONTAINER-->
			<div class="container-fluid">
				<!-- BEGIN PAGE HEADER-->
			  <div class="row-fluid">
					<div class="span12">
						<!-- BEGIN PAGE TITLE & BREADCRUMB-->
						<ul class="breadcrumb">
							<li>
                                <a href="#"><i class="icon-home"></i></a><span class="divider">&nbsp;</span>
							</li>
                            <li>
                                <a href="index.php">TICARETIUMbasic</a> <span class="divider">&nbsp;</span>
                            </li>
							<li><a href="#">Fırsatlar</a><span class="divider-last">&nbsp;</span></li>
						</ul>
						<!-- END PAGE TITLE & BREADCRUMB-->
					</div>
				</div>
			  <div class="row-fluid">
			    <div class="span12">
			      <!-- BEGIN EXAMPLE TABLE widget-->
			      <div class="widget">
			        <div class="widget-title">
			          <h4><i class="icon-barcode"></i>Fırsatlar</h4>
			          <span class="tools"> <a href="javascript:;" class="icon-chevron-down"></a> </span> </div>
			        <div class="widget-body">
                    <?
                    	if(isset($_GET['p'])){
							$p = $_GET['p'];
						}else{
							$p = "";
						}
						switch($p){
							default:
					?>
			          <div class="portlet-body">
			            <div class="space15"></div>
			            <table class="table table-striped table-hover table-bordered" id="sample_editable_1">
			              <thead>
			                <tr>
			                  <th width="90%">Fırsat Adı</th>
			                  <th width="10%">İşlem</th>
		                    </tr>
		                  </thead>
			              <tbody>
                        <?
                           $n = mysql_query("SELECT * FROM `firsatlar`");
							while($y = mysql_fetch_object($n)){
						?>
                        <tr class="">
			                  <td><strong><?=$y->isim;?></strong></td>
			                  <td><a class="duzenle" href="firsatlar.php?p=duzenle&pID=<?=$y->firsatID;?>">Fırsatı Düzenle</a></td>
		                    </tr>
                        <?
							}
						?>
		                  </tbody>
		                </table>
		              </div>
                      <?
					  break;
					  case'ekle':
					  ?>
                      <form action="?p=kaydet" class="form-horizontal" method="post" enctype="multipart/form-data">
                           <div class="control-group">
                              <label class="control-label">Fırsat Başlığı</label>
                              <div class="controls">
                                 <input type="text" class="span6 " name="baslik" />
                              </div>
                           </div>
                           <div class="control-group">
                              <label class="control-label">Satın Alma Limiti</label>
                              <div class="controls">
                                 <input type="text" class="span6 " name="limit" value="" />
                              </div>
                           </div>
                            <div class="control-group">
                              <label class="control-label">Fırsat Bitiş Tarihi</label>
                              <div class="controls">
                                <input class=" m-ctrl-medium date-picker" size="16" type="text" value="2014-01-01" name="tarih">
                              </div>
                           </div>
                            <div class="control-group">
                              <label class="control-label">Fırsat Fiyatı</label>
                              <div class="controls">
                                 <div class="input-prepend input-append">
                                    <span class="add-on">TL</span><input name="fiyat" class=" " type="text"><span class="add-on">.00</span>
                                 </div>
                              </div>
                           </div>
                           <div class="control-group">
                              <label class="control-label">Fırsat Durumu</label>
                              <div class="controls">
                                 <label class="radio">
                                 <div class="radio" id="uniform-undefined"><span><input type="radio" name="durum" value="1" style="opacity: 0;" checked></span></div>
                                 Aktif
                                 </label>
                                 <label class="radio">
                                 <div class="radio" id="uniform-undefined"><span class="checked"><input type="radio" name="durum" value="0" style="opacity: 0;"></span></div>
                                 Pasif
                                 </label>  
                              </div>
                           </div>
                           <div class="control-group">
                              <label class="control-label">Fırsat Resmi</label>
                              <div class="controls">
                                        <div class="fileupload fileupload-new" data-provides="fileupload"><input type="hidden">
                                            <div class="input-append">
                                                <div class="uneditable-input">
                                                    <i class="icon-file fileupload-exists"></i>
                                                    <span class="fileupload-preview"></span>
                                                </div>
                                       <span class="btn btn-file">
                                       <span class="fileupload-new">Resim Seç</span>
                                       <span class="fileupload-exists">Değiştir</span>
                                       <input type="file" name="file" class="default">
                                       </span>
                                                <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Sil</a>
                                            </div>
                                        </div>
                                    </div>
                           </div>
                           <div class="control-group">
                              <label class="control-label">Fırsat İçeriği</label>
                              <div class="controls">
                                 <textarea class="span12 wysihtml5" rows="14" name="icerik"></textarea>
                              </div>
                           </div>
                           <div class="form-actions">
                              <button type="submit" class="btn btn-success">Kaydet</button>
                           </div>
                      </form>
                      <?
					  break;
					  case'duzenle':
					  $pID = $_GET['pID'];
					  	$n = mysql_query("SELECT * FROM `firsatlar` WHERE `firsatID`='$pID'");
							$m = mysql_fetch_object($n);
					  ?>
                      <form action="?p=guncelle" class="form-horizontal" method="post" enctype="multipart/form-data">
                      <input type="hidden" name="fID" value="<?=$pID;?>">
                           <div class="control-group">
                              <label class="control-label">Fırsat Başlığı</label>
                              <div class="controls">
                                 <input type="text" class="span6 " name="baslik" value="<?=$m->isim;?>" />
                              </div>
                           </div>
                           <div class="control-group">
                              <label class="control-label">Satın Alma Limiti</label>
                              <div class="controls">
                                 <input type="text" class="span6 " name="limit" value="<?=$m->adet;?>" />
                              </div>
                           </div>
                            <div class="control-group">
                              <label class="control-label">Fırsat Bitiş Tarihi</label>
                              <div class="controls">
                                <input class=" m-ctrl-medium date-picker" size="16" type="text" value="<?=$m->bitis;?>" name="tarih">
                              </div>
                           </div>
                            <div class="control-group">
                              <label class="control-label">Fırsat Fiyatı</label>
                              <div class="controls">
                                 <div class="input-prepend input-append">
                                    <span class="add-on">TL</span><input name="fiyat" class=" " type="text" value="<?=$m->fiyat;?>"><span class="add-on">.00</span>
                                 </div>
                              </div>
                           </div>
                           <div class="control-group">
                              <label class="control-label">Fırsat Durumu</label>
                              <div class="controls">
                                 <label class="radio">
                                 <div class="radio" id="uniform-undefined"><span><input type="radio" name="durum" value="1" style="opacity: 0;" <? if($m->durum==1){?> checked<? }?>></span></div>
                                 Aktif
                                 </label>
                                 <label class="radio">
                                 <div class="radio" id="uniform-undefined"><span class="checked"><input type="radio" name="durum" value="0" style="opacity: 0;" <? if($m->durum==0){?> checked<? }?>></span></div>
                                 Pasif
                                 </label>  
                              </div>
                           </div>
                           <div class="control-group">
                              <label class="control-label">Fırsat İçeriği</label>
                              <div class="controls">
                                 <textarea class="span12 wysihtml5" rows="14" name="icerik"><?=$m->icerik;?></textarea>
                              </div>
                           </div>
                           <div class="form-actions">
                              <button type="submit" class="btn btn-success">Güncelle</button>
                           </div>
                      </form>
                      <?
					  break;
					  case'guncelle':
					  	$baslik 	= $_POST['baslik'];
						$tarih 		= $_POST['tarih'];
						$fiyat 		= $_POST['fiyat'];
						$durum 		= $_POST['durum'];
						$limit 		= $_POST['limit'];
						$fID 		= $_POST['fID'];
						$icerik		= addslashes($_POST['icerik']);
						$n = mysql_query("UPDATE `firsatlar` SET `isim`='$baslik', `bitis`='$tarih',`icerik`='$icerik',`fiyat`='$fiyat',`durum`='$durum',`adet`='$limit' WHERE firsatID='$fID'");
						if($n){
					 ?>
                     <script>
							$(function(){
								$('body,html').animate({scrollTop:0},800);
							});
							</script>
                        	<div class="alert alert-success">
                            	<button class="close" data-dismiss="alert">×</button>
                            	<strong>İşlem Başarılı!</strong> Fırsat Başarıyla Güncellendi.
                        	</div>
                     <?		header("refresh:2; url=firsatlar.php");
								}else{
					?>
                    <script>
							$(function(){
								$('body,html').animate({scrollTop:0},800);
							});
							</script>
                            <div class="alert alert-error">
                            	<button class="close" data-dismiss="alert">×</button>
                            	<strong>Bir Hata Oluştu!</strong> Fırsat Şuanda Güncellenemedi.
                        	</div>
                    <?		header("refresh:2; url=firsatlar.php");
								}
					  break;
					  case'kaydet':
					  	$baslik 	= $_POST['baslik'];
						$tarih 		= $_POST['tarih'];
						$fiyat 		= $_POST['fiyat'];
						$durum 		= $_POST['durum'];
						$limit 		= $_POST['limit'];
						$icerik		= addslashes($_POST['icerik']);
						$res1 = new upload($_FILES['file']);
						$res2 = new upload($_FILES['file']);
					$time = time();
					if ($res1->uploaded){		
						$uzantisiz1 = explode(".", $res1->file_src_name);
						$res1->image_resize        				= true;
						$res1->file_new_name_body   			= replace_tr($time."_".$uzantisiz1[0]);
						$res1->image_x             				= 400;
   						$res1->image_ratio_y       				= true;
						$res1->image_convert 					= 'jpg';	 
						$res1->process('../upload/product');
						
						//profil resmi
						$res2->image_resize        				= true;
						$res2->file_new_name_body   			= replace_tr("thumb_".$time."_".$uzantisiz1[0]);
						$res2->image_x             				= 120;
   						$res2->image_ratio_y       				= true;
						$res2->image_convert 					= 'jpg';	 
						$res2->process('../upload/product');
						
						
					if ($res1->processed || $res2->processed){
						$resim 			=  replace_tr($time."_".$uzantisiz1[0]).".jpg";
					if($resim){
						$n = mysql_query("INSERT INTO `firsatlar` (`firsatID`, `isim`, `bitis`, `icerik`, `resim`, `fiyat`, `durum`, `adet`) VALUES (NULL, '$baslik', '$tarih', '$icerik', '$resim', '$fiyat', '$durum', '$limit');");
								if($n){
					 ?>
                     <script>
							$(function(){
								$('body,html').animate({scrollTop:0},800);
							});
							</script>
                        	<div class="alert alert-success">
                            	<button class="close" data-dismiss="alert">×</button>
                            	<strong>İşlem Başarılı!</strong> Fırsat Başarıyla Eklendi.
                        	</div>
                     <?		header("refresh:2; url=firsatlar.php");
								}else{
					?>
                    <script>
							$(function(){
								$('body,html').animate({scrollTop:0},800);
							});
							</script>
                            <div class="alert alert-error">
                            	<button class="close" data-dismiss="alert">×</button>
                            	<strong>Bir Hata Oluştu!</strong> Fırsat Şuanda Eklenemedi.
                        	</div>
                    <?		header("refresh:2; url=firsatlar.php");
								}
								}else{
								echo "Resim Yüklenemedi";
							}
					}
					$res1->clean();
				 }
					  break;
						}
					  ?>
		            </div>
		          </div>
			      <!-- END EXAMPLE TABLE widget-->
		        </div>
		      </div>
			  <!-- END PAGE HEADER-->
				<!-- BEGIN PAGE CONTENT-->
				<div id="page" class="dashboard">
                    <!-- BEGIN OVERVIEW STATISTIC BLOCKS--><!-- END OVERVIEW STATISTIC BLOCKS--><!-- BEGIN SQUARE STATISTIC BLOCKS-->
                    <div class="square-state"></div>
              <!-- END SQUARE STATISTIC BLOCKS--></div>
				<!-- END PAGE CONTENT-->
			</div>
			<!-- END PAGE CONTAINER-->
		</div>
		<!-- END PAGE -->
	</div>
	<!-- END CONTAINER -->
	<!-- BEGIN FOOTER -->
	<div id="footer">
		2013 &copy; TICARETIUMbasic Admin Paneli
		<div class="span pull-right">
			<span class="go-top"><i class="icon-arrow-up"></i></span>
		</div>
	</div>
	<!-- END FOOTER -->
	<!-- BEGIN JAVASCRIPTS -->
	<!-- Load javascripts at bottom, this will reduce page load time -->
<script src="js/jquery-1.8.2.min.js"></script>    
   <script src="assets/bootstrap/js/bootstrap.min.js"></script>
   <script type="text/javascript" src="assets/bootstrap/js/bootstrap-fileupload.js"></script>
   <script src="js/jquery.blockui.js"></script>
   <!-- ie8 fixes -->
   <!--[if lt IE 9]>
   <script src="js/excanvas.js"></script>
   <script src="js/respond.js"></script>
   <![endif]-->
   <script type="text/javascript" src="assets/chosen-bootstrap/chosen/chosen.jquery.min.js"></script>
   <script type="text/javascript" src="assets/uniform/jquery.uniform.min.js"></script>
   <script type="text/javascript" src="assets/bootstrap-wysihtml5/wysihtml5-0.3.0.js"></script> 
   <script type="text/javascript" src="assets/bootstrap-wysihtml5/bootstrap-wysihtml5.js"></script>
   <script type="text/javascript" src="assets/clockface/js/clockface.js"></script>
   <script type="text/javascript" src="assets/jquery-tags-input/jquery.tagsinput.min.js"></script>
   <script type="text/javascript" src="assets/bootstrap-toggle-buttons/static/js/jquery.toggle.buttons.js"></script>
   <script type="text/javascript" src="assets/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>   
   <script type="text/javascript" src="assets/bootstrap-daterangepicker/date.js"></script>
   <script type="text/javascript" src="assets/bootstrap-daterangepicker/daterangepicker.js"></script> 
   <script type="text/javascript" src="assets/bootstrap-colorpicker/js/bootstrap-colorpicker.js"></script>  
   <script type="text/javascript" src="assets/bootstrap-timepicker/js/bootstrap-timepicker.js"></script>
   <script type="text/javascript" src="assets/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>
   <script src="assets/fancybox/source/jquery.fancybox.pack.js"></script>
   <script src="js/scripts.js"></script>
   <script type="text/javascript" src="assets/uniform/jquery.uniform.min.js"></script>
   <script type="text/javascript" src="assets/data-tables/jquery.dataTables.js"></script>
   <script type="text/javascript" src="assets/data-tables/DT_bootstrap.js"></script>
      <script src="js/table-editable.js"></script>
      <script type="text/javascript" src="assets/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
      <script type="text/javascript" src="assets/bootstrap-daterangepicker/date.js"></script>
      <script type="text/javascript" src="assets/bootstrap-daterangepicker/daterangepicker.js"></script>

	<script>
		jQuery(document).ready(function() {
			// initiate layout and plugins
			App.init();
			TableEditable.init();
		});
	</script>
	<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>
<?
	}
?>