<?
	ob_start();
	session_start();
	include_once("../sistem/database.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{
?>
<!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 http-equiv="Content-Type" content="text/html; 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/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/bootstrap/css/bootstrap-fileupload.css" rel="stylesheet" />
    <link href="assets/fancybox/source/jquery.fancybox.css" rel="stylesheet" />
	<link rel="stylesheet" type="text/css" href="assets/uniform/css/uniform.default.css" />
	<link href="assets/fullcalendar/fullcalendar/bootstrap-fullcalendar.css" rel="stylesheet" />
	<link href="assets/jqvmap/jqvmap/jqvmap.css" media="screen" 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="teklif.php"><span class="icon-box"><i class="icon-money"></i></span> Teklif Talepleri</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=ekle">Sayfa Ekle</a></li>
                        <li><a class="" href="sayfa.php?p=tum">Tüm Sayfalar</a></li>

                    </ul>
				</li>
				<li class="has-sub">
					<a href="javascript:;" class="">
					    <span class="icon-box"> <i class="icon-sitemap"></i></span> Kategoriler
                        <span class="arrow"></span>
                    </a>
                    <ul class="sub">
                        <li><a class="" href="kategoriler.php?p=ekle">Yeni Ekle</a></li>
                        <li><a class="" href="kategoriler.php?p=tum">Tüm Kategoriler</a></li>

                    </ul>
				</li>
				<li class="has-sub">
					<a href="javascript:;" class="">
					    <span class="icon-box"> <i class="icon-barcode"></i></span> Ürünler
                        <span class="arrow"></span>
                    </a>
                    <ul class="sub">
                        <li><a class="" href="urunler.php?p=ekle">Yeni Ekle</a></li>
                        <li><a class="" href="urunler.php?p=tum">Tüm Ürünler</a></li>

                    </ul>
				</li>
                <li><a class="" href="iletisim.php"><span class="icon-box"><i class="icon-phone-sign"></i></span> İletişim</a></li>
                <li class="active"><a class="" href="excel.php"><span class="icon-box"><i class="icon-certificate"></i></span> Excelden Ürün Aktar</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="#">Excelden Ürün Aktar</a><span class="divider-last">&nbsp;</span></li>
						</ul>
						<!-- END PAGE TITLE & BREADCRUMB-->
					</div>
				</div>
				<!-- END PAGE HEADER-->
				<!-- BEGIN PAGE CONTENT-->
				<div id="page" class="dashboard">
					<div class="row-fluid">
                        <div class="span12">
                            <!-- BEGIN RECENT ORDERS PORTLET-->
                            <div class="widget">
                                <div class="widget-title">
                                    <h4><i class="icon-certificate"></i> Excelden Ürün Aktar</h4>
                                        <span class="tools">
                                        <a href="javascript:;" class="icon-chevron-down"></a>
                                        </span>
                                </div>
                                <?php
                                    if(isset($_GET['p'])){
                                        $p = $_GET['p'];
                                    }else{
                                        $p = "";
                                    }
                                        switch($p){
                                            case'kaydet':
                                                /** Include path **/
                                                ini_set('include_path', ini_get('include_path').';../Classes/');

                                                /** PHPExcel */
                                                include 'PHPExcel.php';

                                                /** PHPExcel_Writer_Excel2007 */
                                                include 'PHPExcel/Writer/Excel2007.php';
                                                function sef_link($bas){
                                                    $bas = str_replace(array("&quot;","&#39;"), NULL, $bas);
                                                    $bul = array('Ç', 'Ş', 'Ğ', 'Ü', 'İ', 'Ö', 'ç', 'ş', 'ğ', 'ü', 'ö', 'ı', '-');
                                                    $yap = array('c', 's', 'g', 'u', 'i', 'o', 'c', 's', 'g', 'u', 'o', 'i', ' ');
                                                    $perma = strtolower(str_replace($bul, $yap, $bas));
                                                    $perma = preg_replace("@[^A-Za-z0-9\-_]@i", ' ', $perma);
                                                    $perma = trim(preg_replace('/\s+/',' ', $perma));
                                                    $perma = str_replace(' ', '-', $perma);


                                                    return $perma;
                                                }


                                                $kat   = $_POST['ust'];
                                                $excel      = $_FILES['excel'];
                                                    if(isset($excel)){
                                                        $name = $excel["name"];
                                                        $val = explode('.', $name);
                                                        $filename = sef_link($val[0]).".".$val[1];


                                                        $islem = copy($excel["tmp_name"], "../upload/excel/".$filename);
                                                            if($islem){
                                                                $objReader = PHPExcel_IOFactory::createReader('Excel2007');
                                                                $objReader->setReadDataOnly(true);

                                                                $objPHPExcel = $objReader->load("../upload/excel/".$filename);
                                                                $objWorksheet = $objPHPExcel->getActiveSheet();

                                                                $highestRow = $objWorksheet->getHighestRow(); // e.g. 10
                                                                $highestColumn = $objWorksheet->getHighestColumn(); // e.g 'F'

                                                                $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); // e.g. 5
                                                                for ($row = 2; $row <= $highestRow; ++$row) {
                                                                    for ($col = 0; $col <= $highestColumnIndex; ++$col) {
                                                                        $urunkodu   = "PROMİNA-".trim($objWorksheet->getCellByColumnAndRow(0, $row)->getValue());
                                                                        $urunResim   = trim($objWorksheet->getCellByColumnAndRow(0, $row)->getValue()).".jpg";
                                                                        copy("../upload/product/".trim($objWorksheet->getCellByColumnAndRow(0, $row)->getValue()).".jpg", "../upload/product/thumb_".trim($objWorksheet->getCellByColumnAndRow(0, $row)->getValue().".jpg"));
                                                                        $urunAdi    = $objWorksheet->getCellByColumnAndRow(1, $row)->getValue();
                                                                        $urunAcik   = $objWorksheet->getCellByColumnAndRow(2, $row)->getValue();
                                                                        $check = mysql_query("SELECT * FROM urunler WHERE stokKodu='$urunkodu'");
                                                                            if(mysql_num_rows($check)==0){
                                                                                    $g = mysql_query("INSERT INTO urunler (`firsatID`, `isim`, `stokKodu`, `bitis`, `icerik`, `resim`, `fiyat`, `durum`, `adet`, `kategori`) VALUES (NULL, '$urunAdi', '$urunkodu', '', '$urunAcik', '$urunResim', '', '1', '', '$kat');");
                                                                                        if($g){
                                                                                            echo "ekledim ürünü ben<br>";
                                                                                        }else{
                                                                                            echo $urunkodu." ekleyemedim<br>";
                                                                                        }

                                                                            }else{
                                                                                echo "bu ürünü zaten ekledim<br>";
                                                                            }
                                                                    }
                                                                }


                                                            }else{
                                                                echo "Dosya Yükleme Başarısız";
                                                            }
                                                    }
                                                break;
                                        }
                                ?>
                                <div class="widget-body">
                                    <form action="?p=kaydet" class="form-horizontal" method="post" enctype="multipart/form-data">
                                        <div class="control-group">
                                            <label class="control-label">Kategori</label>
                                            <div class="controls">
                                                <select class="input-large m-wrap" name="ust" tabindex="1">
                                                    <option value="0">Kategori Seçiniz</option>
                                                    <?php
                                                    $n = mysql_query("SELECT * FROM `kategoriler`");
                                                    while($y = mysql_fetch_object($n)){
                                                        ?>
                                                        <option value="<?=$y->kID;?>"><?=$y->kategori;?></option>
                                                    <?
                                                    }
                                                    ?>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="control-group">
                                            <label class="control-label">Ürün Excel Dosyası</label>
                                            <div class="controls">
                                                <div class="fileupload fileupload-new" data-provides="fileupload">
                                                    <div class="input-append">
                                                        <div class="uneditable-input span3"><i class="icon-file fileupload-exists"></i> <span class="fileupload-preview"></span></div><span class="btn btn-file"><span class="fileupload-new">Dosya Seç</span><span class="fileupload-exists">Değiştir</span><input type="file" name="excel"/></span><a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Kaldır</a>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-actions">
                                            <button type="submit" class="btn btn-success">Ürünleri Aktar</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                            <!-- END RECENT ORDERS PORTLET-->
                        </div>

					</div>
				</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.3.min.js"></script>
	<script src="assets/jquery-slimscroll/jquery-ui-1.9.2.custom.min.js"></script>
	<script src="assets/jquery-slimscroll/jquery.slimscroll.min.js"></script>
	<script src="assets/fullcalendar/fullcalendar/fullcalendar.min.js"></script>
	<script src="assets/bootstrap/js/bootstrap.min.js"></script>
	<script src="js/jquery.blockui.js"></script>
	<script src="js/jquery.cookie.js"></script>
    <script type="text/javascript" src="assets/bootstrap/js/bootstrap-fileupload.js"></script>

    <!-- ie8 fixes -->
	<!--[if lt IE 9]>
	<script src="js/excanvas.js"></script>
	<script src="js/respond.js"></script>
	<![endif]-->

	<script src="js/jquery.peity.min.js"></script>
	<script type="text/javascript" src="assets/uniform/jquery.uniform.min.js"></script>
	<script src="js/scripts.js"></script>
	<script>
		jQuery(document).ready(function() {
			// initiate layout and plugins
			App.setMainPage(true);
			App.init();
		});
	</script>
	<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>
<?
	}
?>