<?
session_start();
include('includes/config.php');
include('defs.php');

if(strlen($_SESSION['aid'])==0)
  { header('location:index.php');
}

$usr=$_SESSION['uname'];

 ?>

 <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <title>GLAKB  | Account Head Report</title>

  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="../plugins/fontawesome-free/css/all.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="../dist/css/adminlte.min.css">
  <!--Function Email Availabilty---->

</head>
<body class="hold-transition sidebar-mini">
<div class="wrapper">
  <!-- Navbar -->
<?php include_once("includes/navbar.php");?>
  <!-- /.navbar -->

  <!-- Main Sidebar Container -->
 <?php include_once("includes/sidebar.php");?>

 
  <div class="content-wrapper">
<?
$result12 = mysqli_query($link, "select Role from user_details where Name='$usr' ");
$row12=  mysqli_fetch_object($result12);
$role = $row12->Role;
if($role=='Operator')
{
$result = mysqli_query($link, "select Role from user_priv where Name='$usr' and Form='Rep-Head' ");
$row=  mysqli_fetch_object($result);
$role = $row->Role;
if($role=='0')
{
{
echo"<center>";
echo"<br><br><br><br><br>";
echo"<img src='users.png' width='160' height='160'><br>";
echo "<font size=6 color=red><b>ACCESS DENIED!</b><br>";
echo "<font size=4 color=darkblue><b>You Do Not Have Permission to View This Page.</b><br>";
goto a;
}
}
}



echo "                <form name='form1' action='accounts_rep.php?usr=$usr' target='_blank' method=POST >";

?>
<html>
<head>
<style>
#customers {
  font-family: Times-Roman;
  border-collapse: collapse;
  width: 98%;
}

#customers td, #customers th {
  border: 1px solid #4444;
  padding: 4px;
}

#customers tr:nth-child(even){background-color:gainsboro ;}


#customers th {
  padding-top: 5px;
  padding-bottom: 5px;
  text-align: center;
background-color:dodgerblue;
    color: white;
}

.input-box {
            width: 40%;
            padding: 2px;
            margin-top: 2px;
            margin-bottom: 2px;
            border: 2px solid gainsboro;
            border-radius: 4px;
            font-size: 16px;

        }
        #suggestions {
            border: 1px solid #ccc;
            display: none;
            position: absolute;
            background-color: white;
            width: 350px;
            max-height: 150px;
            overflow-y: auto;
            z-index: 1000;
        }
        #suggestions div {
            padding: 1px;
            cursor: pointer;
        }
        #suggestions div:hover,
        #suggestions .selected {
            background-color: #f0f0f0;
        }

</style>  



<script language="javascript">



function GetDetail1(str) {
            if (str.length == 0) {
                document.getElementById("strdup").value = "";
                 document.getElementById("str1").value = "";
                return;
            }
            else {
  
                var xmlhttp = new XMLHttpRequest();
                xmlhttp.onreadystatechange = function () {
                      if (this.readyState == 4 && 
                            this.status == 200) {
                          
                        var myObj = JSON.parse(this.responseText);
                          
document.getElementById("strdup").value = myObj[0];
document.getElementById("str1").value = myObj[1];

                              }
                };
  
                // xhttp.open("GET", "filename", true);
                xmlhttp.open("GET", "search_head.php?searchBox=" + str, true);
                  
                // Sends the request to the server
                xmlhttp.send();
            }
        }
    </script>




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


      



<table align="center" id="customers">
       
<tr>
    <th colspan="4"><font size="4">ACCOUNTS HEAD REPORT CRITERIA</th>

  </tr>
  <td width="240"><b><font size=3 color="black">Enter Accounts Head To Search:</b></td>
<td colspan="1">

    <input type="text" id="searchBox" name="searchBox" class="input-box" placeholder="Click to search..." autocomplete="off" onkeyup="GetDetail1(this.value)" onkeydown="return event.key !== 'Enter';" autofocus>
    <div id="suggestions"></div>

    <script>
        const searchBox = document.getElementById("searchBox");
        const suggestions = document.getElementById("suggestions");
        let selectedIndex = -1;

        searchBox.addEventListener("click", fetchSuggestions);
        searchBox.addEventListener("keyup", function(e) {
            const items = suggestions.querySelectorAll("div");

            if (e.key === "ArrowDown") {
                selectedIndex = (selectedIndex + 1) % items.length;
                updateSelection(items);
            } else if (e.key === "ArrowUp") {
                selectedIndex = (selectedIndex - 1 + items.length) % items.length;
                updateSelection(items);
            } else if (e.key === "Enter" && selectedIndex > -1) {
                searchBox.value = items[selectedIndex].innerText;
                suggestions.style.display = "none";
            } else {
                fetchSuggestions();
            }
        });

        function updateSelection(items) {
            items.forEach((item, i) => {
                item.classList.toggle("selected", i === selectedIndex);
            });
        }

        function fetchSuggestions() {
            const query = searchBox.value;
            fetch(`search2.php?q=${encodeURIComponent(query)}`)
                .then(response => response.json())
                .then(data => {
                    suggestions.innerHTML = "";
                    data.forEach(name => {
                        const div = document.createElement("div");
                        div.textContent = name;
                        div.onclick = () => {
                            searchBox.value = name;
                            suggestions.style.display = "none";
                        };
                        suggestions.appendChild(div);
                    });
                    suggestions.style.display = data.length ? "block" : "none";
                    selectedIndex = -1;
                });
        }
    </script>
                               

<b><font size=3 color="black">Head Type:</b>
<input type='text' size='20' name="strdup" id='strdup' value="" readonly>
<b><font size=3 color="black">Head Code:</b>
<input type='text' size='10' name="str1" id='str1' value="" readonly>

 
<tr>

        <?


    echo "        <td><b><font size=3 color=black>Report Option :      </b></td>";



echo "<td>";
echo "&nbsp &nbsp &nbsp";
echo "<b><font size=3 color=darkblue>Date-Wise :</b>";
echo "&nbsp &nbsp";
echo "<input type='radio' name='strn' value='dw'>";

echo "&nbsp &nbsp &nbsp";
echo "<b><font size=3 color=darkblue>Overall :</b>";
echo "&nbsp &nbsp";
echo "<input type='radio' name='strn' value='oa'>";

   echo "<tr>";
$strvoucher= Date("Y-m-d");

 AddDate("<font size=3 color=black><b>From Date : </b>", "strFrom", "$strvoucher", 25, 10, 0);
  echo "<tr>";

 AddDate("<font size=3 color=black><b>To Date : </b>", "strTo", "$strvoucher", 25, 10, 0);       

?>
<tr>
 <td colspan="3" align="center">     
<input type="submit" name="save" value="View Report" style="background: none; color:#007BFF; border:2px solid #007BFF; padding:2px 20px; border-radius:5px;">
</td>

<?
      

        echo "
                                </form>
                                </table>
                        ";
a:
        include "footer.php";
?>
</div>
<!-- ./wrapper -->

<!-- jQuery -->
<script src="../plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- bs-custom-file-input -->
<script src="../plugins/bs-custom-file-input/bs-custom-file-input.min.js"></script>
<!-- AdminLTE App -->
<script src="../dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../dist/js/demo.js"></script>
<!-- Page specific script -->
<script>
$(function () {
  bsCustomFileInput.init();
});
</script>
</body>
</html>
<?php  ?>