<?php
ob_start();
require_once("conn.php");
require_once 'db_connection.php';
include 'dbconfig.php';

$current_url = basename(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$userid = $_SESSION['user_id'];
$qry = mysqli_query($conn, "SELECT * FROM mobileusers WHERE user_id='$userid'");
$rw = mysqli_fetch_array($qry);
$usergroup = $rw['admintype'];

$qry1 = mysqli_query($conn, "SELECT * FROM pages WHERE page_link='$current_url'");
$rw1 = mysqli_fetch_array($qry1);

$page = $rw1['page_id'];

function checkPermissions($conn, $usergroup, $page)
{
  $qry = mysqli_query($conn, "SELECT * FROM pages WHERE page_id='$page'");
  $qry_row = mysqli_fetch_array($qry);
  $pageid = $qry_row['page_id'];


  if (mysqli_num_rows(mysqli_query($conn, "SELECT * FROM user_permissions WHERE user_group_id='$usergroup' and page_id='$pageid'")) == 1) {
    return true;
  } else {
    return false;
  }
}

if (!checkPermissions($conn, $usergroup, $page)) {
  header("Location: page-load-error.php");
 // exit;
}
ob_end_flush();
?>

<link rel="shortcut icon" type="image/x-icon" href="assets/img/favicon.png">

<link rel="stylesheet" href="assets/css/bootstrap.min.css">

<link rel="stylesheet" href="assets/css/animate.css">
<link rel="stylesheet" href="assets/css/dataTables.bootstrap4.min.css">
<!--Data Tables -->
<link href="assets/plugins/bootstrap-datatable/css/dataTables.bootstrap4.min.css" rel="stylesheet" type="text/css" />
<link href="assets/plugins/bootstrap-datatable/css/buttons.bootstrap4.min.css" rel="stylesheet" type="text/css" />

<link rel="stylesheet" href="assets/plugins/select2/css/select2.min.css">

<link rel="stylesheet" href="assets/plugins/owlcarousel/owl.carousel.min.css">
<link rel="stylesheet" href="assets/plugins/owlcarousel/owl.theme.default.min.css">

<link rel="stylesheet" href="assets/css/bootstrap-datetimepicker.min.css">

<link rel="stylesheet" href="assets/alertify/alertify.core.css">
<link rel="stylesheet" href="assets/alertify/alertify.default.css">

<link rel="stylesheet" href="assets/plugins/select2/css/select2.min.css">

<link rel="stylesheet" href="assets/plugins/fontawesome/css/fontawesome.min.css">
<link rel="stylesheet" href="assets/plugins/fontawesome/css/all.min.css">

<link rel="stylesheet" href="assets/css/style.css">

<link rel="stylesheet" href="assets/css/custom.css">
<script>
  document.onkeyup = function(e) {


    if (e.shiftKey && e.which == 69) {

    } else if (e.shiftKey && e.which == 80) {
      payBill();
    } else if (e.shiftKey && e.which == 68) {
      holdBill(1);
    } else if (e.shiftKey && e.which == 67) {
      window.location.href = "pos-panel.php";
    } else if (e.shiftKey && e.which == 73) {
      document.getElementById("discount_total").focus();
    } else if (e.shiftKey && e.which == 84) {

    } else if (e.shiftKey && e.which == 82) {
      goToCheckout();
    } else if (e.shiftKey && e.which == 70) {

    } else if (e.which == 113) {
      window.location.href = "addstock.php";
    } else if (e.which == 115) {
      window.location.href = "addproduct.php";
    } else if (e.shiftKey && e.which == 85) {
      alertify.error('Unholing....');
      holdBill(0);
      loadCartItems();

    } else if (e.which == 9) {
      var isOpen = $('#myModal').hasClass('show');
      if (isOpen) {
        payBill();
      } else {
        goToCheckout();
      }
    } else if (e.which == 107) {
      onlypayBill();
    }

  };
</script>