<?php
error_reporting(0);
ob_start();
include '../dbconnect.php';
?>
<?php   
if($_POST['statuschange']!="")

 {

  if($_POST['statuschange']==3) 

    {

	$prodlist=mysql_query("select * from tblcartdetails where cartid=".$_POST['hidcartid']."");

	   while($prodrows=mysql_fetch_array($prodlist))

	     { 

		   //echo $prodrows['PRODUCTID'];

		  $selprod=mysql_query("select * from products where pid=".$prodrows['pid']." ");

		     $selproducts=mysql_fetch_array($selprod);

			 $final=$selproducts['pqty']-$prodrows['QUANTITY'];

		  mysql_query("update products set pqty=".$final." where pid=".$selproducts['pid']."");

		 }



	 }

	

	echo  $fdf="update tblcart set status=".$_POST['statuschange']." where cartid=".$_POST['hidcartid']." ";

	 $wew=mysql_query($fdf);

	 

if(!mysql_query("update tblcart set status=".$_POST['statuschange']." where cartid=".$_POST['hidcartid']." "))

  die("error:".mysql_error());

   header("Location: order.php?cartid=".$_POST['hidcartid']."");

  }



  

  	if($_GET['sortorder']=="") 

				  {

				  $inorder="kk";

				  }

				  else

				  $inorder=$_GET['sortorder']; 

				  

				  if($inorder=="kk")

				    $inorder="'%'";

				   if($_GET['sortby']!="")

				      {

					  $inorder=urlencode($_GET['sortby']);

					  }

						?>

<!DOCTYPE html>



<html lang="en">

<head>

    <meta charset="utf-8">



    <meta http-equiv="X-UA-Compatible" content="IE=edge">



    <meta name="viewport" content="width=device-width, initial-scale=1">



    <meta name="description" content="">



    <meta name="author" content="">



     <style type="text/css">
 
      /* Sticky footer styles
       -------------------------------------------------- */

    </style>



<?php include_once("title.php"); ?>

    <!-- Bootstrap Core CSS -->

    <link href="css/bootstrap.min.css" rel="stylesheet">

    <link href="css/main.css" rel="stylesheet">

    <!-- Custom CSS -->

    <link href="css/logo-nav.css" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->

    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->

    <!--[if lt IE 9]>

        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>

        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('#select_all').on('click',function(){
        if(this.checked){
            $('.checkbox').each(function(){
                this.checked = true;
            });
        }else{
             $('.checkbox').each(function(){
                this.checked = false;
            });
        }
    });
    
    $('.checkbox').on('click',function(){
        if($('.checkbox:checked').length == $('.checkbox').length){
            $('#select_all').prop('checked',true);
        }else{
            $('#select_all').prop('checked',false);
        }
    });
});
</script>

</head>

<body>
     <div id="wrap">
    <!-- Navigation -->
       <?php include_once("header.php"); ?>
    <!-- Page Content -->
    <div class="container">
         <div class="row">
            <div class="col-lg-12">
 
                <br> <br> <br><br>
                   <h1 style="text-align: center;">All Orders</h1>
                 <div class="row">
             <div class="col-lg-12">
                 <table class="table table-striped table-condensed">
 <form action="deleteorderss.php" method="post">
  <thead><tr>
  <th>S No.</th>
 <th><input type="checkbox" id="select_all" /> Select all</th>

 <th style="text-align: center;">Customer Name</th>

 <th style="text-align: center;"><!--Mobile Customer--></th>

 <th style="text-align: center;"><!--Source--></th>

 <th>Grand Total</th>

 <th>Time</th>

 <!-- <th>Delete</th>-->

 <th></th></tr>
 <tr>
  <th><button class="btn btn-danger btn-sm" type="submit"><span class="glyphicon glyphicon-trash"></span> Delete All</button></th>
 <th></th>

 <th style="text-align: center;" colspan="4"><!--All Orders In Decending Order--></th>
<th style="text-align: center;" colspan="3"><!--<a href="orderdes.php">Click here to Ascending order</a>--></th>
</tr>
 </thead>


                    <tbody>

  <?php

$i=1;

				$tbl_name="tblcart";		//your table name

	// How many adjacent pages should be shown on each side?

	$adjacents = 2;

	

	/* 

	   First get total number of rows in data table. 

	   If you have a WHERE clause in your query, make sure you mirror it here.

	*/

	//echo "Select count(*) as num from register as a, tblcart as b, guestregister as c where a.user_id=b.userid or c.user_id=b.guestid and b.status like ".$inorder." order by cartid";exit;

// $query = "Select count(*) as num from register as a, tblcart as b where a.user_id=b.userid and b.status like ".$inorder." order by cartid"; 

 $query = "Select count(*) as num from register as a, tblcart as b where a.user_id=b.userid and b.status like ".$inorder." order by cartid DESC"; 

	$total_pages = mysql_fetch_array(mysql_query($query));

	$total_pages = $total_pages[num];

	

	/* Setup vars for query. */

	$targetpage = "order.php?sortorder=".$_GET[sortorder]; 	//your file name  (the name of this file)

	$limit = 1000; 								//how many items to show per page

	$page = $_GET['page'];

	if($page) 

		$start = ($page - 1) * $limit; 			//first item to display on this page

	else

		$start = 0;								//if no page var is given, set start to 0

	

	/* Get data. */

	//echo "Select a.billfname ,a.billlname,b.status,b.cartid,b.userid,b.grandtotal,b.time,c.billfname,c.billlname from register as a,tblcart as b,guestregister as c where a.user_id=b.userid or c.user_id=b.guestid  and b.status like ".$inorder." order by cartid desc LIMIT $start, $limit";exit;

/*	 $sql = "Select a.billfname ,a.billlname,b.status,b.cartid,b.userid,b.grandtotal,b.time,b.mobilecustomer from  tblcart as b 

	 

	 left outer join register as a on 

	   a.user_id=b.userid where b.status like ".$inorder." order by cartid desc LIMIT $start, $limit";    */     

	   //this is

	   $sql = "Select a.billfname ,a.billlname,a.billingaddress1,b.status,b.cartid,b.userid,b.grandtotal,b.time from register as a,tblcart as b where a.user_id=b.userid and b.status like ".$inorder." order by cartid desc LIMIT $start, $limit"; 

	   //end

	$catres = mysql_query($sql);

	

	/* Setup page vars for display. */

	if ($page == 0) $page = 1;					//if no page var is given, default to 1.

	$prev = $page - 1;							//previous page is page - 1

	$next = $page + 1;							//next page is page + 1

	$lastpage = ceil($total_pages/$limit);		//lastpage is = total pages / items per page, rounded up.

	$lpm1 = $lastpage - 1;						//last page minus 1

	

	/* 

		Now we apply our rules and draw the pagination object. 

		We're actually saving the code to a variable in case we want to draw it more than once.

	*/

	$pagination = "";

	if($lastpage > 1)

	{	

		$pagination .= "<div class=\"pagination\">";

		//previous button

		if ($page > 1) 

			$pagination.= "<a href=\"$targetpage&page=$prev\">&laquo; previous</a>";

		else

			$pagination.= "<span class=\"disabled\">&laquo; previous</span>";	

		

		//pages	

		if ($lastpage < 7 + ($adjacents * 2))	//not enough pages to bother breaking it up

		{	

			for ($counter = 1; $counter <= $lastpage; $counter++)

			{

				if ($counter == $page)

					$pagination.= "<span class=\"current\">$counter</span>";

				else

					$pagination.= "<a href=\"$targetpage&page=$counter\">$counter</a>";					

			}

		}

		elseif($lastpage > 5 + ($adjacents * 2))	//enough pages to hide some

		{

			//close to beginning; only hide later pages

			if($page < 1 + ($adjacents * 2))		

			{

				for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)

				{

					if ($counter == $page)

						$pagination.= "<span class=\"current\">$counter</span>";

					else

						$pagination.= "<a href=\"$targetpage&page=$counter\">$counter</a>";					

				}

				$pagination.= "...";

				$pagination.= "<a href=\"$targetpage&page=$lpm1\">$lpm1</a>";

				$pagination.= "<a href=\"$targetpage&page=$lastpage\">$lastpage</a>";		

			}

			//in middle; hide some front and some back

			elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))

			{

				$pagination.= "<a href=\"$targetpage&page=1\">1</a>";

				$pagination.= "<a href=\"$targetpage&page=2\">2</a>";

				$pagination.= "...";

				for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)

				{

					if ($counter == $page)

						$pagination.= "<span class=\"current\">$counter</span>";

					else

						$pagination.= "<a href=\"$targetpage&page=$counter\">$counter</a>";					

				}

				$pagination.= "...";

				$pagination.= "<a href=\"$targetpage&page=$lpm1\">$lpm1</a>";

				$pagination.= "<a href=\"$targetpage&page=$lastpage\">$lastpage</a>";		

			}

			//close to end; only hide early pages

			else

			{

				$pagination.= "<a href=\"$targetpage&page=1\">1</a>";

				$pagination.= "<a href=\"$targetpage&page=2\">2</a>";

				$pagination.= "...";

				for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)

				{

					if ($counter == $page)

						$pagination.= "<span class=\"current\">$counter</span>";

					else



						$pagination.= "<a href=\"$targetpage&page=$counter\">$counter</a>";					

				}

			}

		}

		

		//next button

		if ($page < $counter - 1) 

			$pagination.= "<a href=\"$targetpage&page=$next\">next &raquo;</a>";

		else

			$pagination.= "<span class=\"disabled\">next &raquo;</span>";

		$pagination.= "</div>\n";		



	}

 

										   

			while($catrow=mysql_fetch_array($catres))

				 {

				 //$gift=mysql_fetch_array(mysql_query("select * from addressdetails where cartid=".$catrow['cartid']));

						//echo $catrow['billfname'];?>

        <tr>

  <td style="vertical-align: middle;"><?php echo $i; ?></td>
 <td style="vertical-align: middle;"><input type="checkbox" class="checkbox" name="selectall[]" value="<?php echo $catrow['cartid'] ?>"/></td>
        
                        <td style="text-align: center"><a href="orderdetails.php?cartid=<?php echo $catrow['cartid'] ?>&userid=<?php echo $catrow['userid'] ?>"><?php echo ucfirst($catrow['billfname'])." ".$catrow['billlname']; ?></a></td>

                        <td style="vertical-align: middle;"><?php echo $catrow['mobilecustomer']; ?></td>

                        <td style="vertical-align: middle;"><?php echo $catrow['source']; ?></td>

                         <td style="vertical-align: middle;"><?php echo $catrow['grandtotal']; ?></td>

                         <td style="vertical-align: middle;"><?php echo $catrow['time']; ?></td>

     <!--<td style="vertical-align: middle;"><a href="deleteorders.php?cartid=<?php echo $catrow['cartid'] ?>&userid=<?php echo $catrow['userid'] ?>"  onclick="return confirm('Do you really want to remove this?');"><button class="btn btn-danger btn-sm"><span class="glyphicon glyphicon-trash"></span> Delete</button></a>
                         </td>-->

                    </tr>
   <?php $i++;}?>

                   <!-- <tr>
                        <td>cell is row 1, column 0</td><td>cell is row 1, column 1</td><td>cell is row 1, column 2</td>
                    </tr>
                    <tr>
                        <td>cell is row 2, column 0</td><td>cell is row 2, column 1</td><td><button class="btn btn-primary btn-sm"><span class="glyphicon glyphicon-edit"></span> Edit</button> <button class="btn btn-danger btn-sm"><span class="glyphicon glyphicon-trash"></span> Delete</button> <button class="btn btn-success btn-sm active"><span class="glyphicon glyphicon-ok"></span> Active</button> <button class="btn btn-default btn-sm disabled"><span class="glyphicon glyphicon-remove"></span> Disable</button></td>
                    </tr>-->
                    </tbody>

</form>

                </table>



                </div></div>



                <br>







                



               



    </div>







        </div>







  







            </div>



            



         <div id="push"></div>



    </div>







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



   







    



    <!-- /.container -->







    <!-- jQuery -->



    <script src="js/jquery.js"></script>







    <!-- Bootstrap Core JavaScript -->



    <script src="js/bootstrap.min.js"></script>











</body>







</html>



