<!DOCTYPE html>
<?php
    session_start();

#error_reporting(E_ALL ^ E_NOTICE);  
if ($_SESSION['user_name'] == NULL)
{
    echo "<script>window.location.href='../index.php';</script>";
}

require_once('../Db/dbconfig.php');
    //require_once('Db/dbconfig.php');
    $query = "select user_name,user_id from user where user_name = '".$_SESSION['user_name']."'";
    $query_run = mysqli_query($con, $query);
    if(@mysqli_num_rows($query_run)>0)
    {
        $row = mysqli_fetch_array($query_run, MYSQLI_ASSOC);
        @$name = $row['user_name'];
        @$userid = $row['user_id'];
    }
    date_default_timezone_set("Asia/Kolkata");
    $cur_date = date("Y-m-d h:i:sa");
    
    
?>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="Responsive sidebar template with sliding effect and dropdown menu based on bootstrap 3">
    <title>Petrix</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link href="../css/sidebartheme.css" rel="stylesheet" />
    <script src="https://kit.fontawesome.com/c17eae44a3.js" crossorigin="anonymous"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    
 <style type="text/css">
  @media only screen and (max-height: 700px) {
            .child{
                display: flex;
                height:100%;
            }
 </style>

</head>

<body>
<div class="page-wrapper chiller-theme toggled">
  <nav id="sidebar" class="sidebar-wrapper">
    <div class="sidebar-content">
      <div class="sidebar-header">
       <img width="200" height="100" src="../assets/images/logo-new.png"  />
      </div>
      <div class="sidebar-menu">
        <ul>
          <li id="dashboard">
            <a href="#" onclick="openIframe('../view/dashboard_view.php?username=<?php echo @$name;?>')">
              <i class="fas fa-home"></i>
              <span>Dashboard</span>
            </a>
          </li>
          <li id="purchase" class="sidebar-dropdown">
            <a href="#">
              <i class="fa fa-shopping-cart"></i>
              <span>Purchase</span>
            </a>
            <div class="sidebar-submenu">
              <ul>
                <li>
                  <a href="#" onclick="openIframe('../view/purchase.php?userid=<?php echo @$userid; ?>')">Purchase Entry

                  </a>
                </li>
                <li>
                  <a href="#" onclick="openIframe('../view/purchase_multiple.php?userid=<?php echo @$userid; ?>')">Multiple Purchase Entry</a>
                </li>
                <li>
                  <a href="#" onclick="openIframe('../view/purchase_view.php?username=<?php echo @$name;?>&userid=<?php echo @$userid; ?>')">Purchase View</a>
                </li>
              </ul>
            </div>
          </li>
          <li id="storage">
            <a href="#" onclick="openIframe('../view/storage.php?username=<?php echo @$name;?>&dptId=1&userid=<?php echo @$userid; ?>&itemCatId=0')">
              <i class="fas fa-box-open"></i>
              <span>Storage</span>
            </a>
           </li>
          <li id="admin" class="sidebar-dropdown">
            <a href="#">
              <i class="fas fa-user-shield"></i>
              <span>Admin</span>
            </a>
            <div class="sidebar-submenu">
              <ul>
                <!--<li>
                  <a href="#" onclick="openIframe('../view/admin_view.php?username=<?php echo @$name;?>&dptId=1&userid=<?php echo @$userid; ?>')">D-Process</a>
                </li>-->
				
				<li>
                  <a href="#" onclick="openIframe('../view/admin_view.php?username=<?php echo @$name;?>&dptId=1&userid=<?php echo @$userid; ?>')">Complete Process</a>
                </li>
				
				 <li>
                  <a href="#" onclick="openIframe('../view/package_view.php?username=<?php echo @$name;?>&userid=<?php echo @$userid; ?>')">Packing</a>
                </li>
				 <li>
                  <a href="#" onclick="openIframe('../view/admin_view.php?username=<?php echo @$name;?>&dptId=6&userid=<?php echo @$userid; ?>')">Other Department</a>
                </li>
				<li>
                  <a href="#" onclick="openIframe('../view/f_39_in.php?username=<?php echo @$name;?>&userid=<?php echo @$userid; ?>')">F-39 In</a>
                </li>
				<li>
                  <a href="#" onclick="openIframe('../view/f_39_out.php?username=<?php echo @$name;?>&userid=<?php echo @$userid; ?>')">F-39 Out</a>
                </li>
				
                <!--<li>
                  <a href="#" onclick="openIframe('../view/admin_view.php?username=<?php echo @$name;?>&dptId=2&userid=<?php echo @$userid; ?>')">Munchy</a>
                </li>
                <li>
                  <a href="#" onclick="openIframe('../view/admin_view.php?username=<?php echo @$name;?>&dptId=3&userid=<?php echo @$userid; ?>')">Press Bone</a>
                </li>
                <li>
                  <a href="#" onclick="openIframe('../view/admin_view.php?username=<?php echo @$name;?>&dptId=4&userid=<?php echo @$userid; ?>')">Samming & Splitting</a>
                </li>
                <li>
                  <a href="#" onclick="openIframe('../view/admin_view.php?username=<?php echo @$name;?>&dptId=5&userid=<?php echo @$userid; ?>')">Hide</a>
                </li>
                <li>
                  <a href="#" onclick="openIframe('../view/admin_view.php?username=<?php echo @$name;?>&dptId=6&userid=<?php echo @$userid; ?>')">Loading & Unloading</a>
                </li>
                <li>
                  <a href="#" onclick="openIframe('../view/admin_view.php?username=<?php echo @$name;?>&dptId=7&userid=<?php echo @$userid; ?>')">Cutting</a>
                </li>
                <li>
                  <a href="#" onclick="openIframe('../view/admin_view.php?username=<?php echo @$name;?>&dptId=8&userid=<?php echo @$userid; ?>')">Oven</a>
                </li>
                <li>
                  <a href="#" onclick="openIframe('../view/package_view.php?username=<?php echo @$name;?>&userid=<?php echo @$userid; ?>')">Packing</a>
                </li>
                <li>
                  <a href="#" onclick="openIframe('../view/scrap_view.php?username=<?php echo @$name;?>&userid=<?php echo @$userid; ?>')">Scrap</a>
                </li>
                <li>
                  <a href="#" onclick="openIframe('../view/admin_view.php?username=<?php echo @$name;?>&dptId=12&userid=<?php echo @$userid; ?>')">Other Department</a>
                </li>-->
				
              </ul>
            </div>
          </li>
          <li id="stock">
            <a href="#" onclick="openIframe('../view/stock_view.php?username=<?php echo @$name;?>&userid=<?php echo @$userid; ?>')">
              <i class="fas fa-cubes"></i>
              <span>Stock</span>
            </a>
          </li>
          <li id="export" class="sidebar-dropdown">
            <a href="#">
              <i class="fas fa-file-export"></i>
              <span>Export</span>
            </a>
            <div class="sidebar-submenu">
              <ul>
               <li>
                  <a href="#" onclick="openIframe('../view/export_view.php?username=<?php echo @$name;?>&isInternational=0&userid=<?php echo @$userid; ?>')">Domestic</a>
                </li>
               <li>
                  <a href="#" onclick="openIframe('../view/export_view.php?username=<?php echo @$name;?>&isInternational=1&userid=<?php echo @$userid; ?>')">International</a>
                </li>
              </ul>
            </div>
          </li>
          <li id="producthistory" class="sidebar-dropdown">
            <a href="#">
              <i class="fas fa-history"></i>
              <span>Product History</span>
            </a>
            <div class="sidebar-submenu">
              <ul>
               <li>
                  <a href="#" onclick="openIframe('../view/purchase_history_view.php')">
                    Single Material
                  </a>
                </li>
               <li>
                  <a href="#" onclick="openIframe('../view/purchase_history_multiple_view.php')">
                    Multiple Materials
                  </a>
                </li>
              </ul>
            </div>
          </li>
          <li id="masters" class="sidebar-dropdown">
            <a href="#">
              <i class="fas fa-list-alt"></i>
              <span>Masters</span>
            </a>
            <div class="sidebar-submenu">
              <ul>
                <li id="purchaser">
                  <a href="#" onclick="openIframe('../view/purchaser_master.php?username=<?php echo @$name;?>')">Purchaser</a>
                </li>
                <li id="supplier">
                  <a href="#" onclick="openIframe('../view/supplier_master.php?username=<?php echo @$name;?>')">Supplier</a>
                </li>
               </ul>
            </div>
          </li>
          <li id="reports">
            <a href="#" onclick="openIframe('../view/reports.php')">
              <i class="far fa-chart-bar"></i>
              <span>Reports</span>
            </a>
          </li>
          
        </ul>
      </div>
      <!-- sidebar-menu  -->
    </div>
    <!-- sidebar-content  -->
   <!--  <div class="sidebar-footer">
      <a href="#">
        <i class="fa fa-bell"></i>
        <span class="badge badge-pill badge-warning notification">3</span>
      </a>
      <a href="#">
        <i class="fa fa-envelope"></i>
        <span class="badge badge-pill badge-success notification">7</span>
      </a>
      <a href="#">
        <i class="fa fa-cog"></i>
        <span class="badge-sonar"></span>
      </a>
      <a href="#">
        <i class="fa fa-power-off"></i>
      </a>
    </div> -->
  </nav>
  <!-- sidebar-wrapper  -->
  <main class="page-content">
     <nav class="navbar navbar-expand-lg navbar-light bg-light border-bottom">
                  <a id="show-sidebar" class="btn btn-sm btn-dark" href="#">
                    <i class="fas fa-bars"></i>
                  </a>
                  <div id="close-sidebar">
                    <i class="fas fa-times"></i>
                  </div>
                  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
                    <div class="collapse navbar-collapse" id="navbarSupportedContent">
                        <ul class="navbar-nav ml-auto mt-2 mt-lg-0">
                            <li class="nav-item dropdown">
                                <a class="nav-link dropdown-toggle" id="navbarDropdown" href="#!" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?php echo @$name; ?></a>
                                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
                                    <a class="dropdown-item" href="#" onclick="signout()">Sign Out</a>
                                </div>
                            </li>
                        </ul>
                    </div>
                 
                </nav>
    <div class="container-fluid child">
      <div class="embed-responsive embed-responsive-16by9">
        <iframe class="embed-responsive-item" src="../view/purchase.php" allowfullscreen id="mainFrame"></iframe>
      </div>
    </div>
  </main>
  <!-- page-content" -->
</div>
<!-- page-wrapper -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
        crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
        crossorigin="anonymous"></script>
    
</body>
<?php include '../nav/footer.php';?>
<script type="text/javascript">
  jQuery(function ($) {
$('.dropdown-toggle').dropdown();
    $(".sidebar-dropdown > a").click(function() {
  $(".sidebar-submenu").slideUp(200);
  if (
    $(this)
      .parent()
      .hasClass("active")
  ) {
    $(".sidebar-dropdown").removeClass("active");
    $(this)
      .parent()
      .removeClass("active");
  } else {
    $(".sidebar-dropdown").removeClass("active");
    $(this)
      .next(".sidebar-submenu")
      .slideDown(200);
    $(this)
      .parent()
      .addClass("active");
  }
});

$("#close-sidebar").click(function() {
  $(".page-wrapper").removeClass("toggled");
});
$("#show-sidebar").click(function() {
  $(".page-wrapper").addClass("toggled");
});

  var username = '<?php echo @$name; ?>';
  var userid = '<?php echo @$userid; ?>';

  console.log('userid',userid);

  if(username == 'storage'){
    openIframe('../view/storage.php?username='+username+'&userid='+userid);
    document.getElementById('purchase').style.display="none";
    document.getElementById('dashboard').style.display="none";
    document.getElementById('admin').style.display="none";
    document.getElementById('stock').style.display="none";
    document.getElementById('export').style.display="none";
    document.getElementById('producthistory').style.display="none";
    document.getElementById('masters').style.display="none";
  }else if(username == 'purchase'){
      openIframe('../view/purchase.php?userid=<?php echo @$userid; ?>');
    document.getElementById('storage').style.display="none";
    document.getElementById('dashboard').style.display="none";
    document.getElementById('admin').style.display="none";
    document.getElementById('stock').style.display="none";
    document.getElementById('export').style.display="none";
    document.getElementById('producthistory').style.display="none";
    document.getElementById('purchaser').style.display="none";
  }else if(username == 'Admin'){
      openIframe('../view/admin_view.php?username=<?php echo @$name;?>&dptId=1&userid=<?php echo @$userid; ?>');
    document.getElementById('purchase').style.display="none";
    document.getElementById('storage').style.display="none";
    document.getElementById('dashboard').style.display="none";
    document.getElementById('stock').style.display="none";
    document.getElementById('export').style.display="none";
    document.getElementById('producthistory').style.display="none";
    document.getElementById('masters').style.display="none";
  }else if(username == 'stock'){
      openIframe('../view/stock_view.php?username=<?php echo @$name;?>&userid=<?php echo @$userid; ?>');
    document.getElementById('purchase').style.display="none";
    document.getElementById('storage').style.display="none";
    document.getElementById('admin').style.display="none";
    document.getElementById('dashboard').style.display="none";
    document.getElementById('producthistory').style.display="none";
    document.getElementById('supplier').style.display="none";
  }else{
      openIframe('../view/purchase.php?userid=<?php echo @$userid; ?>');
  }
   
});

  function openIframe(framnm){
   // console.log('usernameHello2',framnm);
    var $iframe = $('#mainFrame');
    if ($iframe.length) {
        $iframe.attr('src',framnm);
        return false;
    }

}

function signout(){
    $.ajax({
        url:'../controller/logout.php',
        type:'POST',
        data:'logout=1',
        success:function(response){
           if(response == 'Success'){
             window.location.href='../index.php';
           }
        }
    });
}
</script>
</html>