<?php
session_start();
include('includes/config.php');
if(strlen($_SESSION['aid'])==0)
  { header('location:index.php');
}

$usr=$_SESSION['uname'];
$idd=$_GET['tid'];


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">
     <img src="includes/mlogo.jpg" width="1349" height="100" title="" />

  <title>GLAKB  | Edit 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">
 
 
    
<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: 98%;
}

#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:royalblue;
  color: white;
}
</style>   


<script language="javascript">

 function formconfirm() {
return confirm("Do you want to Save the Record?<? echo "$coursename";?>"); 
}



function validateForm()
{
if((document.sub_head.item33.value) == '')
{
alert("Please Select Accounts Cost Center!");
document.sub_head.item33.focus();
return false;
}


if((document.sub_head.strcode.value) == '')
{
alert("Please Enter Accounts Code!");
document.sub_head.strcode.focus();
return false;
}

if((document.sub_head.strname.value) == '')
{
alert("Please Enter Accounts Head Name!");
document.sub_head.strname.focus();
return false;
}

return true;
}






                
</script>
<form name="voucher" method="POST" action="" >



<body>
<div id="content">
<div id="left">



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


<?
$result = mysqli_query($link, "select * from mheads where Id='$idd'");
while($row  = mysqli_fetch_object($result))
{
$mhead=$row->Name;
$det=$row->Details;
}                                
?>


<table align="center" id="customers">
       
<tr>
    <th colspan="4"><font size="4">EDIT MAIN CATEGORY</th>

  </tr>


<td><b><font size=3 color="black">Select Main Category:</b></td>
                        <td>
    <select class="form-control" name="item33" id="item33" style=font-size="16" >
                                <option value="<?php echo $mhead ?>"><?php echo $mhead ?></option>
                                <?php 
                                if(isset($_GET['M_Head1']))
                                        {
                                                $M_Head1 = $_GET['M_Head1'];
                                                
                                                
                
                                        }
                                else                        
                                        $M_Head1 = "";
                                        
                                        //include('config.php');
$result = mysqli_query($link, "select Distinct Name from mheads order by Name");
                                        while($row  = mysqli_fetch_object($result))
                                        {
                                                        if($M_Head1 == $row->Name)
                                                        {
                                                                echo "<option value=\"$row->Name\" selected=\"selected\">$row->Name</option>";
                                                        }        
                                                        else
                                                        {
                                                                echo "<option value=\"$row->Name\">$row->Name</option>";
                                                        }
                                        }
                                ?>
                                </select>


<tr align="left">
<td><b><font size=3 color="black">Details (If any):</b></td>
<td colspan="2">
<input type="text" name="strdet" id="strdet" value="<?php echo $det ?>" class="input-box"  /></td>
</tr>
  

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


<input type="submit" name="hme" value="Return Back" style="background: none; color:#007BFF; border:2px solid #007BFF; padding:2px 20px; border-radius:5px;">

  </td>

</table>



         
<?php


if(isset($_POST['hme']))
{
$link1 = "<script>window.open('editmhead.php','_self')</script>";
echo $link1;
}


if(isset($_POST['save']))
{
date_default_timezone_set ("Asia/Karachi");
$date = date('d-m-Y (h:i:s a)', time());
$mhead=$_POST['item33'];
$det=$_POST['strdet'];

   

$sql1 = "SELECT Name FROM mheads where Name='$mhead'";
$q = $link->query($sql1);
if ($q->num_rows == 1) 
{
$result = mysqli_query($link, "update mheads set Details='$det' where Id = '$idd' ");

goto donot1;
}



$result = mysqli_query($link, "update mheads set Name='$mhead', Details='$det' where Id = '$idd' ");


//$result = mysqli_query($link, "update acc_heads set Name='$name', M_Head='$mhead' where A_Id = '$code' ");


echo "<script language='javascript'>";
 echo "alert('Successfully Updated!')";
  echo "</script>";
donot1:
$link1 = "<script>window.open('editmhead.php','_self')</script>";
echo $link1;

donot:

}



        echo "</form>";                
 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  ?>