<?php
  $page_title = 'All Product';
  require_once('includes/load.php');
  // Checkin What level user has permission to view this page
  page_require_level(2);

  require_once('includes/functions.php');

  // Search Logic
  if (isset($_POST['search'])) {
    $search_query = $_POST['search_query'];
    $products = search_products($search_query);
  } else {
    $products = join_product_table();
  }
?>
<?php include_once('layouts/header.php'); ?>

<div class="row">
  <div class="col-md-12">
    <?php echo display_msg($msg); ?>
  </div>
  <div class="col-md-12">
    <div class="panel panel-default">
      <div class="panel-heading clearfix">
        <div class="pull-right">
          <a href="add_product.php" class="btn btn-primary">Add New</a>
        </div>
        <div class="pull-left">
          <?php include('search_products.php'); ?>
        </div>
      </div>
      <div class="panel-body">
        <table class="table table-bordered">
          <!-- Table headers... -->
          <tbody>
            <?php foreach ($products as $product): ?>
              <tr>
                <!-- Table rows... -->
              </tr>
            <?php endforeach; ?>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>

<?php include_once('layouts/footer.php'); ?>
