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

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

$usr=$_SESSION['uname'];


echo "                <form name='sub_head' action='' method=POST onSubmit='return  validateForm();'>";




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

  <title>GLAKB  | Main Category</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='Add-Mheads' ");
$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;
}
}
}
?>

    
<style>

 

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

        }



#customers {
  font-family: Times-Roman;
  border-collapse: collapse;
  width: 50%;
}

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

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


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


<script language="javascript" type="text/javascript">

window.onload= function show()
                        {
                                if(document.sub_head.strmhead.value =="")
                                        {

                                                document.sub_head.strmhead.focus()
                                        }
                                        }






function validateForm()
{

if((document.sub_head.strmhead.value) == '')
		
	{
			alert("Please Enter Main Cost Center!");
document.sub_head.strmhead.focus();

			return false;
		}
        

return true;
}

  </script>
        <table align="left" id="customers">
       
<tr>
    <th colspan="4"><font size="4">ADD MAIN ACCOUNTS CATEGORY</th>

  </tr>


<tr>
<td>
<b><font size=3 color="black">Category Title:</b>
<td>
  <input type="text" name="strmhead" class="input-box">
   </td>                                  
 

  <tr>     

  
<td><b><font size=3 color=black>Description (If any):</b></td>
<td colspan="3"> <input type="text" name="details" class="input-box">
</td>



          
<tr>                                      


<td colspan="4" align="center">
<input type="submit" name="save" value="Save Details" style="background: none; color:#007BFF; border:2px solid #007BFF; padding:2px 20px; border-radius:5px;">

  </td>        
 <?
           

if(isset($_POST['save']))
{
date_default_timezone_set ("Asia/Karachi");
$the_time = date('d-m-Y (h:i:s a)', time());
$mhead = rtrim($_POST['strmhead']);
$det=$_POST['details'];
$strQuery = "select count(Name) as cnt from mheads where Name='$mhead'";
$nResult = mysqli_query ($link, $strQuery);
$rstRow = mysqli_fetch_array($nResult);
$counter= $rstRow["cnt"];
if($counter>0)
{
echo "<script language='javascript'>";
echo "alert('Sorry: Already Exists!')";
echo "</script>";
goto donot;
}

mysqli_query($link, "insert into mheads (Name, Details, addby, addon) values ('$mhead','$det','$usr','$the_time')");



echo "<script language='javascript'>";
echo "alert('The Accounts Category added Successfully!')";
echo "</script>";
$link1 = "<script>window.open('add_mhead.php','_self')</script>";
echo $link1; 
donot:



}





  a:      
 
  ?>

</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  ?>