<?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 = 20; //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=$_SESSION['user_akses'];

	
	if($akses == 'dealer')
	{
		$sql=mysql_query("select * from bs_stok where bundling='yes' and  CURDATE() >= date and  CURDATE() <= dateto  order by date desc LIMIT $vpb_start_page, $vpb_page_limit");
		$results = mysql_query("select COUNT(*) as jumlah from bs_stok where bundling='yes' and  CURDATE() >= date and  CURDATE() <= dateto");
	}
	else
	{
		$sql=mysql_query("select * from bs_stok where bundling='yes' and  CURDATE() >= date and  CURDATE() <= dateto order by date desc LIMIT $vpb_start_page, $vpb_page_limit");
		$results = mysql_query("select COUNT(*) as jumlah from bs_stok where bundling='yes' and  CURDATE() >= date and  CURDATE() <= dateto ");
	}
	}
	
	$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.= "<li><a>Next</a></li>"; }
		$vpb_pagination_system.= "</div>";		
	}
	?>
		<div id="products" class="row list-group">
<?php
	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);
		$harga_retail=number_format($row[retail]);

		$region=$_SESSION['region'];
        $kode=$row['kode_ax'];
        $size=$row['size_ax'];
        $color=$row['colour_ax'];
        $config=$row['config_ax'];
        
        $hargato=mysql_query("select harga from harga where kode='$kode' and size='$size' and color='$color' and config='$config' and region='$region'");
        $har=mysql_fetch_array($hargato);
        if($region !="")
        {
        $diskon1= (($har[harga] * $diskon[diskon])/100);
		$diskon3= $har[harga] - $diskon1;
		$diskon2=number_format($diskon3);
		$harga_dealer=number_format($har[harga]);
		$dis=$diskon[diskon];
    
        }
        else
        {
		$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="item  col-xs-4 col-lg-4 list-group-item">
            <div class="thumbnail">
                			<div class="mask1"><span><?php echo "$dis"; ?>%</span>

                <img class="group list-group-image" src="http://lokal.bikershop.biz/inside/data/resize/<?php echo "$row[photo]"; ?>" width='100px' alt="" />
                </div>
                <div class="caption">
                    <h4 class="group inner list-group-item-heading">
                        <?php echo "$row[nama]"; ?></h4>
                    <p class="group inner list-group-item-text">
                        <?php echo "$row[deskripsi]"; ?></p>
                    <div class="row">
                        <div class="col-xs-12 col-md-6">
                            <p class="lead">
                               <span class="item_price1">HET: Rp.<?php echo "$harga_retail"; ?></span><br>NET:<del> Rp.<?php echo "$harga_dealer"; ?></del>
								<span class="item_price">Rp.<?php echo "$diskon2"; ?></span></p>
                        </div>
                        <div class="col-xs-12 col-md-6">
                            <input type="hidden" class="item_quantity1" name="qty" id="qty_<?php echo $row[id] ?>" min="1" max="1" value="1">
                            <a id="add" name="add" class="btn btn-success" href="#" onclick="cart('<?php echo $row[id] ?>')">Beli</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

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