<!DOCTYPE html>
<?php 
$newid=$_GET['id'];
?>
<html>
<script type="text/javascript">
    function FormatCurrency(ctrl) {
                  //Check if arrow keys are pressed - we want to allow navigation around textbox using arrow keys
                  if (event.keyCode == 37 || event.keyCode == 38 || event.keyCode == 39 || event.keyCode == 40) {
                      return;
                  }

                  var val = ctrl.value;

                  val = val.replace(/,/g, "")
                  ctrl.value = "";
                  val += '';
                  x = val.split('.');
                  x1 = x[0];
                  x2 = x.length > 1 ? '.' + x[1] : '';

                  var rgx = /(\d+)(\d{3})/;

                  while (rgx.test(x1)) {
                      x1 = x1.replace(rgx, '$1' + ',' + '$2');
                  }

                  ctrl.value = x1 + x2;
              }

              function CheckNumeric() {
                  return event.keyCode >= 48 && event.keyCode <= 57 || event.keyCode == 46;
              }
</script>
    
    <head>
        <title>Tables</title>
        <!-- Bootstrap -->
        <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
        <link href="../bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
        <link href="../assets/styles.css" rel="stylesheet" media="screen">
        <link href="../assets/DT_bootstrap.css" rel="stylesheet" media="screen">
        <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="vendors/flot/excanvas.min.js"></script><![endif]-->
        <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
            <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <script src="../vendors/modernizr-2.6.2-respond-1.1.0.min.js"></script>
    </head>
    
    <body>
        <?php include '../includes/header.php'; ?>
        <div class="container-fluid">
            <div class="row-fluid">
                <?php include '../includes/sidebar.php'; ?>
                <!--/span-->
                <div class="span5" id="content">

                        <div class="row-fluid">
                        <!-- block -->
                        <div class="block">
                            <div class="navbar navbar-inner block-header">
                                <!-- <div class="muted pull-left">Orders</div>
                                <div class="muted pull-right"><button class="btn btn-primary"> Process Order</button></div> -->
                            </div>
                            <div class="block-content collapse in">
                                <div class="span12">
                                    <?php
include '../includes/connection.php';


$sql = "SELECT id, (select product_name from stores where id=getstore.product_id)as product_name, quantity  from getstore where business_id='$business'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
   ?>
  									<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
										<thead>
											<tr>
												<tr>
                        <th>Id</th>
                        <th>Product Name</th>
                        <th>Quantity</th>
                        
                      </tr>
												
                                                
											</tr>
										</thead>
										<tbody>
                                        <?php
                                        $n=0;
                                         // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
      $n++;
        ?>
        <tr class="odd gradeX">
        
                                                <td><?php echo $n; ?></td>
                                                <td><?php echo $row['product_name']; ?></td>
                                                <td><?php echo $row['quantity']; ?></td>
                                                
                                              
                                                
                                            </tr>
                                            <?php
    }
} else {
    echo "0 results";
}


?>
											
											
										</tbody>
									</table>
                                </div>
                            </div>
                        </div>
                        <!-- /block -->
                    </div>

         
                </div>
                <div class="span4">
                <?php 
                $sqled = mysqli_query($conn,"SELECT id,product_id, (select product_name from stores where id=getstore.product_id)as product_name, quantity  from getstore where id=20 ");


if (mysqli_num_rows($sqled) > 0) {
    // output data of each row
  $rowed = mysqli_fetch_assoc($sqled);
        $prod_id=$rowed['product_id'];
        $prod_name=$rowed['product_name'];
        $qty=$rowed['quantity'];
        $id=$rowed['id'];
        
    

} else {
    echo "0 results";
}
                 ?>
                                     <form class="form-horizontal" action="" method="POST"> 
                                      <fieldset>
                                        <legend>Edit </legend>
                                        <div class="control-group">
                                          <label class="control-label" for="selectError">Product</label>
                                          <div class="controls">
                                          <input class="input-xlarge focused" name="product" id="focusedInput" type="text" value="<?php echo $prod_name; ?>" readonly>
                                          <input type="hidden" name="product_id" value="<?php echo $prod_id; ?>">

                                          </div>
                                        </div>
                                        <div class="control-group">
                                          <label class="control-label"  for="focusedInput">Quantity</label>
                                          <div class="controls">
                                            <input class="input-xlarge focused" name="quantity" id="focusedInput" type="number" value="<?php echo $qty; ?>">
                                          </div>
                                        </div>
                                         
                                       
                                         
                                        <div class="form-actions">
                                          <button type="submit" class="btn btn-primary" name="update"><i class="icon-plus "></i>Update</button>
                                          <a href="add_tostore.php"><button class="btn">Cancel</button></a>
                                        </div>
                                      </fieldset>
                                    </form>
                                    <?php
                                        include '../includes/connection.php';

                                        if(isset($_POST['update'])){
                                            $productid=$_POST['product_id'];
                                            $product=$_POST['product'];
                                            $quantity=$_POST['quantity'];
                                            
                                           
                                            // Create connection
                                       

                                        $sql = " UPDATE getstore set quantity='$quantity' where id='$id'";
                                    

                                        if (mysqli_query($conn, $sql)) {
                                           ?><meta http-equiv="refresh" content="0;URL='add_tostore.php'" /><?php
                                        } else {
                                            echo "Error: " . $sql . "<br>" . mysqli_error($conn);
                                        }

                                        mysqli_close($conn);
                                        }
                                        
                                        ?>

                                </div>
            </div>
            <hr>
           <?php include '../includes/footer.php'; ?>
        </div>
        <!--/.fluid-container-->

        <script src="../vendors/jquery-1.9.1.js"></script>
        <script src="../bootstrap/js/bootstrap.min.js"></script>
        <script src="../vendors/datatables/js/jquery.dataTables.min.js"></script>


        <script src="../assets/scripts.js"></script>
        <script src="../assets/DT_bootstrap.js"></script>
        <script>
        $(function() {
            
        });
        </script>
    </body>

</html>