<?php
session_start();

// Check if user is logged in
if (!isset($_SESSION['username'])) {
    header("Location: index.php");
    exit();
}

// Display username or other content
$username = $_SESSION['username'];
?>


<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">-->
<!-- Link Bootstrap CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
<!--<style></style>-->
</head>
<body>

<div class="sidenav">
  <a href="top_products_chart.php" target="iframe_a">Dashboard</a>
  <!--<a href="#services">Products</a>-->
  <button class="dropdown-btn">Products 
    <i class="fa fa-caret-down"></i>
  </button>
  <div class="dropdown-container">
    <a href="insproducts.php" target="iframe_a">Create Products</a>
    <a href="displayproducts.php" target="iframe_a">Product List</a>
  </div>
  <!--<a href="#clients">Clients</a>-->
  <button class="dropdown-btn">Expenses 
    <i class="fa fa-caret-down"></i>
  </button>
  <div class="dropdown-container">
    <a href="insertexpense.php" target="iframe_a">Create Expense</a>
    <a href="displayexpense.php" target="iframe_a">Expenses List</a>
  </div>
  <button class="dropdown-btn">Purchase 
    <i class="fa fa-caret-down"></i>
  </button>
  <div class="dropdown-container">
    <a href="purchase.php" target="iframe_a">Create Purchase</a>
    <a href="viewpurchases.php" target="iframe_a">Purchase List(All)</a>
    <a href="viewpurchasescredit.php" target="iframe_a">Purchase List(CR)</a>
  </div>
  <button class="dropdown-btn">Sales 
    <i class="fa fa-caret-down"></i>
  </button>
  <div class="dropdown-container">
    <a href="sell.php" target="iframe_a">Create Sale</a>
    <a href="viewsells.php" target="iframe_a">Sale List(All)</a>
    <a href="viewsellscredit.php" target="iframe_a">Sale List(CR)</a>
    <a href="deletesale.php" target="iframe_a">Delete Sale</a>
  </div>
  <button class="dropdown-btn">People 
    <i class="fa fa-caret-down"></i>
  </button>
  <div class="dropdown-container">
   <!-- <a href="#">Customer List</a>
    <a href="#">Supplier List</a> -->
    <a href="display.php" target="iframe_a">User List</a>
    <a href="display_customer.php" target="iframe_a">Customer List</a>
    <a href="display_supplier.php" target="iframe_a">Supplier List</a>
  </div>
  <!-- <button class="dropdown-btn">Settings 
    <i class="fa fa-caret-down"></i>
  </button>
  <div class="dropdown-container">
   <a href="#">Category</a>
    <a href="#">Brand</a>
    <a href="gettingbackup.php" target="iframe_a">Backup</a>
  </div>-->
  <button class="dropdown-btn">Reports 
    <i class="fa fa-caret-down"></i>
  </button>
  <div class="dropdown-container">
    <!--<a href="#">Sale Report</a>
    <a href="#">Purchase Report</a>-->
    <a href="profitlossonsoldproducts.php" target="iframe_a">Profit and Loss</a>
    <a href="profitlossreport.php" target="iframe_a">Netprofit</a>
    <a href="value_on_hand.php" target="iframe_a">Value of Onhand PR</a>
    <!--<a href="#">Supplier Report Report</a>
    <a href="#">User Report</a>-->
  </div>
  <button class="dropdown-btn">Settings 
    <i class="fa fa-caret-down"></i>
  </button>
  <div class="dropdown-container">
    <!--<a href="#">Sale Report</a>
    <a href="#">Purchase Report</a>-->
    <a href="banking.php" target="iframe_a">Banking</a>
    <a href="backup.php" target="iframe_a">Backup</a>
    
   
  </div>
  <!--<a href="#contact">Contact</a>-->
  <a href="logout.php">Logout</a>
</div>
<!--  IFRAME      -->
<div class="main">
<iframe src="top_products_chart.php" style="border:none"; name="iframe_a" height="900px" width="100%" title="Iframe Example"></iframe>
</div>

<script>
/* Loop through all dropdown buttons to toggle between hiding and showing its dropdown content - This allows the user to have multiple dropdowns without any conflict */
var dropdown = document.getElementsByClassName("dropdown-btn");
var i;

for (i = 0; i < dropdown.length; i++) {
  dropdown[i].addEventListener("click", function() {
    this.classList.toggle("active");
    var dropdownContent = this.nextElementSibling;
    if (dropdownContent.style.display === "block") {
      dropdownContent.style.display = "none";
    } else {
      dropdownContent.style.display = "block";
    }
  });
}
</script>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.bundle.min.js"></script>

<script>
window.addEventListener("beforeunload", function() {
    navigator.sendBeacon('logout.php'); // Automatically log out when the window is closed
});
</script>

</body>
</html> 
