<!DOCTYPE html>
<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>
       <?php   include("../includes/header-links.php");?>
        <!-- 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';
         $total=0; ?>
        <div class="container-fluid">
            <div class="row-fluid">
                <?php include '../includes/sidebar.php'; ?>
                <!--/span-->
           <div class="span7" id="content">

                        <div class="row-fluid">
                        <!-- block -->
                        <div class="block">
                            <div class="navbar navbar-inner block-header">
                                <div class="muted pull-left">Stores</div>
                                
                                <div class="muted pull-right" >&nbsp &nbsp &nbsp</div>
                                <div class="muted pull-right"><a href="store.php"><button class="bt btn-primary">Store</button> </a> </div>
                                
                            </div>
                            <div class="block-content collapse in">
                                <div class="span12">
                                    <?php
                                    include '../includes/connection.php';
                                    $sql = mysqli_query($con,"SELECT id, (select product_name from stores where id=getstore.product_id)as product_name, quantity from getstore where business_id='$business'");
                                    if (mysqli_num_rows($sql) > 0) {
                                       ?>
  									<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
										<thead>
											<tr>
												<th>Id</th>
												<th>Product Name</th>
												<th>Quantity</th>
												
                          <th>Action</th>
											</tr>
										</thead>
										<tbody>
                                        <?php
                                        
                                         // output data of each row
                                        $nnnn=0;
                while($row = mysqli_fetch_assoc($sql)) {
                        $nnnn++;
                    ?>
                    <tr class="odd gradeX">

        
                                                <td><?php echo $nnnn; ?></td>
                                                <td><?php echo $row['product_name']; ?></td>
                                                <td><?php echo $row['quantity']; ?></td>
                                                
                                                <td class="center">
                                                    <a href="edit_store.php?id=<?php echo $row['id']; ?>"><button class="btn btn-primary"><i class="icon-edit icon-white"></i></button></a>
                                                    <a href="delete_store.php?id=<?php echo $row['id']; ?>"><button class="btn btn-danger"><i class="icon-trash icon-white"></i></button></a>
                                                </td>
                                            </tr>
                                            <?php
    }?>
    </tbody>
                                    </table>

                                    
                                    
                                    
            <form action="process_store.php?" method="POST">
    <div class="muted pull-left">
        
        
    
    </div>
    <div class="muted pull-right">
    

                                <button type="submit" name="process_store" class="btn btn-primary"> Save</button></div>
    
                                </form>
                               
                                    <?php 
} else {
    echo " No Products Have been Added Yet!";
}

//mysqli_close($conn);
?>
					 		
											
								
                                </div>
                            </div>
                        </div>
                        <!-- /block -->
                    </div>

         
                </div>
                <div class="span3">
                                     <form  action="" method="POST"> 
                                      <fieldset>
                                        <legend style="text-align: center;">Add product</legend>
                                        <div class="control-group" >
                                          <label class="control-label" for="selectError" style="font-size: 20px;">Product</label>
                                          <div class="controls">
                                          
                                            <select id="select01" class="chzn-select" name="product" required="required" style="width: 80%; font-size: 18px; height: 35px;" >
                                            <option disabled selected value="" >Select Product</option>
                                            <?php
                                            $sqlstore = "SELECT * FROM stores WHERE NOT EXISTS (SELECT * FROM getstore where product_id=stores.id) && business_id='$business' ";
$resultstore = mysqli_query($conn, $sqlstore);

if (mysqli_num_rows($resultstore) > 0) {
    // output data of each row

    while($row = mysqli_fetch_assoc($resultstore)) {
      ?>
      <option value="<?php echo $row['id'];?>"><?php echo $row['product_name']; ?></option>
       <?php
    }
    
} else {
    echo "0 results";
}
                                            ?>
                                            
                                            </select>
                                            
                                         
                                            
                                          </div>
                                          

  
                      
                                        </div>
                                        
                                        <div id="approved"> 
                                        <div class="control-group">
                                          <label class="control-label"  for="focusedInput" style=" font-size: 20px;">Quantity</label>
                                          <div class="controls">
                                            <input class="input-xlarge focused" name="quantity" id="quantitya" type="number" value="Enter Quantity" required="required" style=" font-size: 20px;">
                                          </div>
                                        </div>
                                        

                                        
                                       
                                        
                                        <div class="form-actions">
                                          <button type="submit" class="btn btn-primary" name="add"><i class="icon-plus "></i>Add</button>
                                       
                                        </div>
                                      
                                        </div>
                                      </fieldset>
                                    </form>
                                    <?php
                                        include '../includes/connection.php';

                                        if(isset($_POST['add'])){
                                            $product=$_POST['product'];
                                            $quantity=$_POST['quantity'];
                                            
                                              
                                              $sql2 = mysqli_query($con,"INSERT INTO getstore(product_id, quantity,business_id,user_id)
                                        VALUES ('$product', '$quantity','$business','$id_user')");
                                            
                                        

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

                                        mysqli_close($con);
                                        }
                                        
                                        ?>

                                </div>
            </div>



<div class="row-fluid">
    
</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>


        <link href="../vendors/datepicker.css" rel="stylesheet" media="screen">
        <link href="../vendors/uniform.default.css" rel="stylesheet" media="screen">
        <link href="../vendors/chosen.min.css" rel="stylesheet" media="screen">

        <link href="../vendors/wysiwyg/bootstrap-wysihtml5.css" rel="stylesheet" media="screen">

        <script src="../vendors/jquery-1.9.1.js"></script>
        <script src="../vendors/jquery.uniform.min.js"></script>
        <script src="../vendors/chosen.jquery.min.js"></script>
        <script src="../vendors/bootstrap-datepicker.js"></script>

        <script src="../vendors/wysiwyg/wysihtml5-0.3.0.js"></script>
        <script src="../vendors/wysiwyg/bootstrap-wysihtml5.js"></script>

        <script src="../vendors/wizard/jquery.bootstrap.wizard.min.js"></script>
        <script type="text/javascript" src="../vendors/jquery-validation/dist/jquery.validate.min.js"></script>
    <script src="../assets/form-validation.js"></script>
        
    <script src="../assets/scripts.js"></script>
        <script>
        $(function() {
            
        });
        </script>
        <script>

    jQuery(document).ready(function() {   
       FormValidation.init();
    });
    

        $(function() {
            $(".datepicker").datepicker();
            $(".uniform_on").uniform();
            $(".chzn-select").chosen();
            $(".chzn-select1").chosen();
            $('.textarea').wysihtml5();

            $('#rootwizard').bootstrapWizard({onTabShow: function(tab, navigation, index) {
                var $total = navigation.find('li').length;
                var $current = index+1;
                var $percent = ($current/$total) * 100;
                $('#rootwizard').find('.bar').css({width:$percent+'%'});
                // If it's the last tab then hide the last button and show the finish instead
                if($current >= $total) {
                    $('#rootwizard').find('.pager .next').hide();
                    $('#rootwizard').find('.pager .finish').show();
                    $('#rootwizard').find('.pager .finish').removeClass('disabled');
                } else {
                    $('#rootwizard').find('.pager .next').show();
                    $('#rootwizard').find('.pager .finish').hide();
                }
            }});
            $('#rootwizard .finish').click(function() {
                alert('Finished!, Starting over!');
                $('#rootwizard').find("a[href*='tab1']").trigger('click');
            });
        });
        </script>

    </body>

</html>