<?
include_once('includes/top.php');
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
//$br=$_SESSION['branch'];
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}
?>
<head>
<script>
function chkey(abc)
{
 yy=abc.value
 if(yy.indexOf('  ')>-1) 
  {
    alert('Multiple space is not allowed');
    abc.value='';
  }
 if(yy.indexOf("'")>-1) 
  {
    alert("\' is not allowed");
    abc.value='';
  }
 if(yy.indexOf('"')>-1) 
  {
    alert("\" is not allowed");
    abc.value='';
  }
 if(yy.indexOf('&')>-1) 
  {
    alert("\& is not allowed");
    abc.value='';
  }
}
</script>
</head>
<?
include_once("test.php");
if(isset($_POST['add']))
{
	$agrp=$_REQUEST['agrp'];
	$conv=$_REQUEST['conv'];
 	if(strlen($agrp)<=0)
 	{	
  		print "In sufficient entry"; 
//  		return;
 	}
	if(strlen($conv)<=0)
	{
		  print "In sufficient entry"; 
//		  return;
	}
	$re=mysqli_query($db,"select * from unit where agrp='$agrp' and brcode='$brcode'");
 	if(mysqli_num_rows($re)>0)
 	{
  		print "Duplicate entry $agrp";
//		return;
 	}
	if((strlen($agrp)>0) && (strlen($conv)>0))
 	{
  		mysqli_query($db,"insert into unit values('".addslashes($agrp)."','$brcode','$conv')");
 	}
}
$aa=$_POST['del'];
$bb=$_POST['add'];
print $aa.$bb;
if(isset($_POST['del'])&&($_POST['del']!=''))
{
	$agrp=$_REQUEST['agrp'];
	print "delete from unit where agrp='$agrp'";
	mysqli_query($db,"delete from unit where agrp='$agrp'");
}
?>
<title>Demo</title>
<link rel="stylesheet" href="style.css" type="text/css" />
<script type="text/javascript" src="scripts/jquery-latest.js"></script>
<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<link type="text/css" href="css/form.css" rel="stylesheet" />
<script type="text/javascript">
        $(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        
    </script>
<script>
function valid()
{
}
</script>

<script type="text/javascript">

/***********************************************
* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
                
function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}      

</script>
<style>
#txt{
font-family: Arial, Helvetica;
background-color: #F2F2F2;

}
</style>
<style>
th{background-color:steelblue;color:white}
</style>
<body background="back_ground.jpg">
<?php //include('logo2.php'); ?>
<form name='f1' action='<?print $PHP_SELF?>' onSubmit="return valid()" method='post'> 

<br>
<table class="container"><tr><td>
<font style="font-family: 'Trebuchet MS',Verdana,Helvetica,sans-serif; font-size:15px;">  &nbsp;&nbsp;Master >> Unit Master</font>
<br>

<center>
<table class="form" ><tr><th colspan='2'>
<h3><font color='black'>Unit Master</font></h3></td></tr>
<form action='<?print $PHP_SELF?>'>

<tr><td>Unit Name </td><td><input type=text name='agrp' size=40 onKeyUp=chkey(this) onKeyPress="return handleEnter(this, event)"></td></tr>
<tr><td>Conversion </td><td><input type=text name='conv' size=40 onKeyUp=chkey(this) onKeyPress="return handleEnter(this, event)"></td></tr>
<tr> <th colspan='2' align='center'><input type=submit value='Add' name='add'></th></tr>
</table>
</form>
<br>
<table border=1 class='report' width='50%'>
<?
$i=1;
$res=mysqli_query($db,"select * from unit  order by agrp");
while($row=mysqli_fetch_array($res))
{
	print "<tr><form action='$PHP_SELF'><input type=hidden name='agrp' value='$row[0]'><td>".$i++."</td><td>$row[0]</td><td>$row[2]</td><td><input type=submit value='Del' name='del' onClick=delfun('$row[agrp]')></td></form></tr>";
}
?>
<script>
 function delfun(x)
 {
  if (confirm('do you want to delete '+x+' ?'))
   document.location='delunit.php?code='+x;
}
</script>
