<?php include("side_nav.php"); ?>
<?php include("top_nav.php"); ?>
<?php
   $sql = mysqli_query($con, "SELECT * FROM shipping_info ");
?>

        <!-- page content -->
        <div class="right_col" role="main">
         
            <div class="clearfix"></div>

            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Products <small></small></h2>
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                      </li>
                      <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
                        <ul class="dropdown-menu" role="menu">
                          <li><a href="#">Settings 1</a>
                          </li>
                          <li><a href="#">Settings 2</a>
                          </li>
                        </ul>
                      </li>
                      <li><a class="close-link"><i class="fa fa-close"></i></a>
                      </li>
                    </ul>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                    <p class="text-muted font-13 m-b-30">
                      Table showing the list of displayed items.
                    </p>
					
					
                    <table id="datatable-buttons" class="table table-striped table-bordered">
                      <thead>
                        <tr>
                          <th>Product Name</th>
                          <th>Quantity</th>
                          <th>Order id</th>
                          <th>Name</th>
                          <th>Email</th>
                          <th>Address</th>
                          <th>Date</th>
                          <th>Action</th>
                        </tr>
                      </thead>

                      
                      <tbody>
					  <?php while($row = mysqli_fetch_array($sql)): ?>
                        <tr>
                          <td><?php echo $row['item_list']; ?></td>
                          <td contenteditable id="qty"><?php echo $row['quantity']; ?></td>
                          <td><?php echo $row['order_id']; ?></td>
                          <td><?php echo ($row['first_name'] . " " . $row['company_name']); ?></td>
                          <td><?php echo $row['email']; ?></td>
                          <td contenteditable id="address" ><?php echo $row['address']; ?></td>
                          <td><?php echo $row['date']; ?></td>
                          <td>
						      <div class="btn-group">
						         <a href="" id="trash" delprd="<?php echo $row['item_list'] ?>" deleteId="<?php echo $row['order_id'] ?>" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span></a>
					             <a href="" id="update_order" delprd="<?php echo $row['item_list'] ?>" deleteId="<?php echo $row['order_id'] ?>" class="btn btn-primary"><span class="glyphicon glyphicon-ok-sign"></span></a>
						      </div>
						  </td>
                        </tr>
					  <?php endwhile; ?>
                      </tbody>
					  
                    </table>
                    
				  </div>
                </div>
              </div>

            
          </div>
        </div>
        <!-- /page content -->

        
<?php include("footer.php"); ?>
<script>
	      $("body").delegate("#trash","click",function(event){
		var order = $(this).attr('deleteId');
		var prd = $(this).attr('delprd');
		$.ajax({
			url	:	"process.php",
			type:	"POST",
			data	:	{query_order:1, order_id:order, prd_name:prd},
			success	:	function(){ 
				window.location = "order.php" ;
			}
         })
		 
	})
</script>

<script>
	      $("body").delegate("#update_order","click",function(event){
		var qty = $('#qty').html();
		var loci = $('#address').html();
		var order = $(this).attr('deleteId');
		var prd = $(this).attr('delprd');
		$.ajax({
			url	:	"process.php",
			type:	"POST",
			data	:	{
				           query_update_order:1, 
						   order_id:order, 
						   prd_name:prd, 
						   address:loci,
						   quantity:qty
						},
			success	:	function(){ 
				alert("Update Successful") ;
			}
         })
		 
	})
</script>