<?php
//include('Pagination.php');
session_start();

include('config/koneksi2.php');
/* $start = !empty($_POST['page'])?$_POST['page']:0;
$limit = 10;
    //Get the total number of rows
    $queryNum = mysql_query("SELECT COUNT(distinct(CONCAT(kode_ax,config_ax))) as postNum FROM bs_stok where tipe='BIKE'");
    $resultNum = mysql_fetch_array($queryNum);
    $rowCount = $resultNum['postNum'];
    
    //Initialize Pagination class and create object
    $pagConfig = array('baseURL'=>'getdata.php', 'totalRows'=>$rowCount, 'perPage'=>$limit, 'contentDiv'=>'content');
    $pagination =  new Pagination($pagConfig);
  
if(isset($_POST['page'])){
$sql=mysql_query("select *, DATEDIFF(NOW(), date) as new  from bs_stok where tipe='BIKE' group by kode_ax,config_ax order by nama ASC LIMIT $start,$limit");
}
else
{*/


if(isset($_POST['page']) && !empty($_POST['page']))
{
$vpb_page_limit = 10; //This is the number of contents to display on each page
	
	//$results = mysql_query("SELECT COUNT(*) as num FROM `vasplus_programming_blog_pagination` ORDER BY `id` DESC");
	
	$vpb_pagination_stages = 2;
	$vpb_current_page = strip_tags($_POST['page']);
	$vpb_start_page = ($vpb_current_page - 1) * $vpb_page_limit;
	
	
	//This initializes the page setup
	$username=$_SESSION['username'];
	$akses=mysql_query("select id_level from tab_user where username='$username'");
	$akses1=mysql_fetch_array($akses);
	
	$akses2=mysql_query("select id_level_brand from tab_user where username='$username'");
	$akses3=mysql_fetch_array($akses2);
	$level=$akses3[id_level_brand];
	
	$akses4=mysql_query("select id_level_brand_pa from tab_user where username='$username'");
	$akses5=mysql_fetch_array($akses4);
	$level2=$akses5[id_level_brand_pa];
	if($akses1['id_level'] =='0' and $level=='2')
	{
		$sql=mysql_query("select *, DATEDIFF(NOW(), date) as new  from bs_stok where(tipe != 'BIKE' and tipe != 'FRAME AND FORK' or brand NOT IN (SELECT nama_brand from grup_brand where id_level_brand='$level')) and  (tipe ='BIKE' and tipe ='FRAME AND FORK' or brand NOT IN (SELECT nama_brand from grup_brand_pa where id_level_brand_pa='$level2')) and tipe IN (SELECT m.nama_tipe
			FROM tab_user u
			INNER JOIN level g ON u.id_level=g.id_level
			INNER JOIN grup_menu gm ON gm.id_level=g.id_level 
			INNER JOIN tipe_new m ON gm.id_tipe=m.id
			WHERE
			u.username='$username') and status !='0'  and dealer < 4000000  order by date desc LIMIT $vpb_start_page, $vpb_page_limit");
		$results = mysql_query("select COUNT(*) as jumlah from bs_stok where(tipe != 'BIKE' and tipe != 'FRAME AND FORK' or brand NOT IN (SELECT nama_brand from grup_brand where id_level_brand='$level')) and  (tipe ='BIKE' and tipe ='FRAME AND FORK' or brand NOT IN (SELECT nama_brand from grup_brand_pa where id_level_brand_pa='$level2')) and tipe IN (SELECT m.nama_tipe
			FROM tab_user u
			INNER JOIN level g ON u.id_level=g.id_level
			INNER JOIN grup_menu gm ON gm.id_level=g.id_level 
			INNER JOIN tipe_new m ON gm.id_tipe=m.id
			WHERE
			u.username='$username') and status !='0'  and dealer < 4000000");
	}
	else
	{
		$sql=mysql_query("select *, DATEDIFF(NOW(), date) as new  from bs_stok where(tipe != 'BIKE' and tipe != 'FRAME AND FORK' or brand NOT IN (SELECT nama_brand from grup_brand where id_level_brand='$level')) and  (tipe ='BIKE' and tipe ='FRAME AND FORK' or brand NOT IN (SELECT nama_brand from grup_brand_pa where id_level_brand_pa='$level2')) and tipe IN (SELECT m.nama_tipe
			FROM tab_user u
			INNER JOIN level g ON u.id_level=g.id_level
			INNER JOIN grup_menu gm ON gm.id_level=g.id_level 
			INNER JOIN tipe_new m ON gm.id_tipe=m.id
			WHERE
			u.username='$username') and status !='0'  order by date desc LIMIT $vpb_start_page, $vpb_page_limit");
		
		$results = mysql_query("select COUNT(*) as jumlah from bs_stok where(tipe != 'BIKE' and tipe != 'FRAME AND FORK' or brand NOT IN (SELECT nama_brand from grup_brand where id_level_brand='$level')) and  (tipe ='BIKE' and tipe ='FRAME AND FORK' or brand NOT IN (SELECT nama_brand from grup_brand_pa where id_level_brand_pa='$level2')) and tipe IN (SELECT m.nama_tipe
			FROM tab_user u
			INNER JOIN level g ON u.id_level=g.id_level
			INNER JOIN grup_menu gm ON gm.id_level=g.id_level 
			INNER JOIN tipe_new m ON gm.id_tipe=m.id
			WHERE
			u.username='$username') and status !='0' ");
	}
	
	$vpb_get_total_pages = mysql_fetch_array($results);
	$vpb_get_total_pages = $vpb_get_total_pages[jumlah];
	if($vpb_current_page == 0) { $vpb_current_page = 1; }
	$vpb_previous_page = $vpb_current_page - 1;	
	$vpb_next_page = $vpb_current_page + 1;							
	$vpb_last_page = ceil($vpb_get_total_pages/$vpb_page_limit);		
	$vpb_lastpaged = $vpb_last_page - 1;					
	$vpb_pagination_system = '';
	
	if($vpb_last_page > 1)
	{	$vpb_pagination_system .= '<nav>';
    	$vpb_pagination_system .= '<ul class="pagination">';
		
		// Previous Page
		if ($vpb_current_page > 1) { $vpb_pagination_system.= "<li><a href='javascript:void(0);' onclick='vpb_pagination_system(\"$vpb_previous_page\");'>Prev</a></li>"; }
		else { $vpb_pagination_system.= "<li class='first'><a>Prev</a></li>"; }
		// Pages	
		if ($vpb_last_page < 7 + ($vpb_pagination_stages * 2))	// Not enough pages to breaking it up
		{	
			for ($vpb_page_counter = 1; $vpb_page_counter <= $vpb_last_page; $vpb_page_counter++)
			{
				if ($vpb_page_counter == $vpb_current_page) {
					$vpb_pagination_system.= "<li class='first active'><a href='#'>$vpb_page_counter</a></li>";
					
				}
				else {
					$vpb_pagination_system.= "<li><a href='javascript:void(0);' onclick='vpb_pagination_system(\"$vpb_page_counter\");'>$vpb_page_counter</a></li>";
				}					
			}
		}
		elseif($vpb_last_page > 5 + ($vpb_pagination_stages * 2))	// This hides few pages when the displayed pages are much
		{
			//Beginning only hide later pages
			if($vpb_current_page < 1 + ($vpb_pagination_stages * 2))		
			{
				for ($vpb_page_counter = 1; $vpb_page_counter < 4 + ($vpb_pagination_stages * 2); $vpb_page_counter++)
				{
					if ($vpb_page_counter == $vpb_current_page) {
						$vpb_pagination_system.= "<li class='first active'><a href='#'>$vpb_page_counter</a></li>";
					}
					else {
						$vpb_pagination_system.= "<li><a href='javascript:void(0);' onclick='vpb_pagination_system(\"$vpb_page_counter\");'>$vpb_page_counter</a></li>";
					}					
				}
				$vpb_pagination_system.= "<li><a>...</a></li>";
				$vpb_pagination_system.= "<li><a href='javascript:void(0);' onclick='vpb_pagination_system(\"$vpb_lastpaged\");'>$vpb_lastpaged</a></li>";
				$vpb_pagination_system.= "<li><a href='javascript:void(0);' onclick='vpb_pagination_system(\"$vpb_last_page\");'>$vpb_last_page</a></li>";		
			}
			//Middle hide some front and some back
			elseif($vpb_last_page - ($vpb_pagination_stages * 2) > $vpb_current_page && $vpb_current_page > ($vpb_pagination_stages * 2))
			{
				$vpb_pagination_system.= "<li><a href='javascript:void(0);' onclick='vpb_pagination_system(\"1\");'>1</a></li>";
				$vpb_pagination_system.= "<li><a href='javascript:void(0);' onclick='vpb_pagination_system(\"2\");'>2</a></li>";
				$vpb_pagination_system.= "<li><a>...</a></li>";
				for ($vpb_page_counter = $vpb_current_page - $vpb_pagination_stages; $vpb_page_counter <= $vpb_current_page + $vpb_pagination_stages; $vpb_page_counter++)
				{
					if ($vpb_page_counter == $vpb_current_page) {
						$vpb_pagination_system.= "<li class='first active'><a href='#'>$vpb_page_counter</a></li>";
					}
					else {
						$vpb_pagination_system.= "<li><a href='javascript:void(0);' onclick='vpb_pagination_system(\"$vpb_page_counter\");'>$vpb_page_counter</a></li>";
					}					
				}
				$vpb_pagination_system.= "<li><a>...</a></li>";
				$vpb_pagination_system.= "<li><a href='javascript:void(0);' onclick='vpb_pagination_system(\"$vpb_lastpaged\");'>$vpb_lastpaged</a></li>";
				$vpb_pagination_system.= "<li><a href='javascript:void(0);' onclick='vpb_pagination_system(\"$vpb_last_page\");'>$vpb_last_page</a></li>";		
			}
			//End only hide early pages
			else
			{
				$vpb_pagination_system.= "<li><a href='javascript:void(0);' onclick='vpb_pagination_system(\"1\");'>1</a></li>";
				$vpb_pagination_system.= "<li><a href='javascript:void(0);' onclick='vpb_pagination_system(\"2\");'>2</a></li>";
				$vpb_pagination_system.= "<li><a>...</a></li>";
				for ($vpb_page_counter = $vpb_last_page - (2 + ($vpb_pagination_stages * 2)); $vpb_page_counter <= $vpb_last_page; $vpb_page_counter++)
				{
					if ($vpb_page_counter == $vpb_current_page) {
						$vpb_pagination_system.= "<li class='first active'><a href='#'>$vpb_page_counter</a></li>";
					}
					else {
						$vpb_pagination_system.= "<li><a href='javascript:void(0);' onclick='vpb_pagination_system(\"$vpb_page_counter\");'>$vpb_page_counter</a></li>";
					}					
				}
			}
		}		
		//Next Page
		if ($vpb_current_page < $vpb_page_counter - 1) { $vpb_pagination_system.= "<li><a href='javascript:void(0);' onclick='vpb_pagination_system(\"$vpb_next_page\");'>Next</a></li>"; }
		else { $vpb_pagination_system.= "<span class='disabled'>Next</span>"; }
		$vpb_pagination_system.= "</div>";		
	}
	while($row=mysql_fetch_array($sql))
	{
		$id_diskon=$row[kode_diskon];
		$sql_diskon="select * from diskon where kode_diskon='$id_diskon'";
		$hasil_diskon=mysql_query($sql_diskon);
		$diskon=mysql_fetch_array($hasil_diskon);
		$diskon1= (($row[dealer] * $diskon[diskon])/100);
		$diskon3= $row[dealer] - $diskon1;
		$diskon2=number_format($diskon3);
		$harga_dealer=number_format("$row[dealer]");
		$dis=$diskon[diskon];
		?>
		<div class="product-grids simpleCart_shelfItem wow fadeInUp animated" data-wow-delay=".5s">
			<div class="new-top">
			<?php
			if($row['new'] <= 30)
			{
			?>
				<div class="mask2"><span>New</span>
				<a href="#" data-toggle="modal" data-target="#myModal" id="image" name="image" onclick="image('<?php echo $row[id] ?>')"><img src="http://lokal.bikershop.biz/inside/data/resize/<?php echo "$row[photo]"; ?>" class="img-responsive"  alt=""/></a>
			</div>
			<?php
			}
			else
			{
			?>
				<a href="#" data-toggle="modal" data-target="#myModal" id="image" name="image" onclick="image('<?php echo $row[id] ?>')"><img src="http://lokal.bikershop.biz/inside/data/resize/<?php echo "$row[photo]"; ?>" class="img-responsive" alt=""/></a>
			<?php
			}
			?>
				<!--<div class="new-text">
					<ul>
						
						<li><a class="item_add" data-toggle="modal" data-target="#myModal" id="image" name="image" href="#" onclick="image('<?php echo $row[id] ?>')">Quick View</a></li>
						<li><input type="number" class="item_quantity" name="qty" id="qty_<?php echo $row[id] ?>" min="1" value="1"></li>
						<li><a class="item_add" id="add" name="add" href="#" onclick="cart('<?php echo $row[id] ?>')"> Add to cart</a></li>
					</ul>
				</div>-->
				
			</div>
			
			<div class="new-bottom">
			<div class="b">
				<h5><?php echo "$row[nama]"; ?> <?php echo "$row[config_ax]"; ?> <?php echo "$row[size_ax]"; ?> <?php echo "$row[colour_ax]"; ?> </h5>
			</div>
						<!--<div class="rating">
							<span></span>
						</div>-->						
						<div class="ofr">
							<?php
							if($row['kode_diskon'] == '0')
							{
								?>
								<p><span class="item_price">Rp. <?php echo "$harga_dealer"; ?></span></p>
								<?php
							}
							else
							{
								?>
								<p class="pric1"><del>Rp. <?php echo "$harga_dealer"; ?></del>
								<span class="item_price">Rp. <?php echo "$diskon2"; ?></span></p>
								<?php
							}
							?>
							
						</div>
							<?php
						if($_SESSION['user_akses'] == 'dealer')
						{
							?>
							<span> Stok : <span class="badge"><?php echo $row[stok_ext] ?></span></span>
							<?php
						}
						else
						{
							?>
								<span><a href="#kode_<?php echo $row[id] ?>" data-toggle="collapse">Stok : <span class="badge"><?php echo $row[stok] ?></span></a></span>
							<?php
						 $kode=$row['kode_ax'];
						    $size=$row['size_ax'];
						    $color=$row['colour_ax'];
						    $config=$row['config_ax'];
							$select=mysql_query("select * from stok where kode_ax='$kode' and size_ax='$size' and colour_ax='$color' and config_ax='$config' and stok > 0 ");
						?>
					  <div id="kode_<?php echo $row[id] ?>" class="collapse">
						<?php
												
												while($a=mysql_fetch_array($select))
												{
												?>
												<span style="font-size:10px;"><?php echo $a['warehouse'] ?>:<?php echo $a['stok'] ?></span>,
					
												<?php
												} 
												?>
					  </div>
					  <?php 
						}
						?>
						<div class="clearfix"></div>
						<div class="bawah">
						<div class="left-in"><input type="number" class="item_quantity1" name="qty" id="qty_<?php echo $row[id] ?>" min="1" value="1"></div>
						<div class="right-add"><a id="add" name="add" href="#" onclick="cart('<?php echo $row[id] ?>')"> Beli</a></div>
						</div>
					</div>
					
				</div>

				<?php
			}
			?>
			<div style="" align="left"><?php echo $vpb_pagination_system; ?></div><!-- This is the pagination buttons -->

			<?php
			
     }
?>
		
