<?
session_start();
if(strlen($bcode)<=0 && strlen($user)<=0)
{
 print "<script> alert('Please login again'); parent.document.location='ind.php'; </script>";
 return;
}
print "User: $user <br> Branch: <font color=red>".$branch."<br><br>";
?>
<?
if($submit)
{
 include("opendb.php");
 $code=substr($username,0,3).substr(time(),7,3); 
 $code=str_replace(' ','-',$code);
 $re=mysqli_query($db,"select * from bruser where username='$username'")or die(mysqli_error());
 if(mysqli_num_rows($re)>0)
 {
    print "<script> alert('User already Exists'); history.back(1); </script>";
    return;
 }
$dt=$yf.'-'.$mf.'-'.$df;
 $sql="insert into bruser values('$code','$username','$level','$desig','$addr','$ph','$pswd1','$brcode','active','$dt')";
 mysqli_query($db,$sql) or die(mysqli_error());
 print "User has been created <br>";
}
?>
<link rel="stylesheet" href="style.css" type="text/css" />

<script>
function validate()
{
var p1=document.f1.pswd1.value
var p2=document.f1.pswd2.value

 submit="true";
 if(document.f1.username.value.length<3)
  {submit="false"; alert('Invalid User Name');}

 if(document.f1.pswd1.value.length<=0)
  {submit="false"; alert('Invalid Password');}

 if(document.f1.pswd2.value.length<=0)
  {submit="false"; alert('Invalid Password2');}
 if(p1!=p2)
  {submit="false"; alert('Passwords does not match');}

 if(submit=="false")
  return false;
}
</script>



<body bgcolor=fcfff1>
<font color=green size=4> <b>User Creation</font>
<hr bgcolor=red>
<center>
<form name='f1' action='<?print $PHP_SELF?>' method='post' onSubmit="return validate()">

<table border=0  cellspacing=2 cellpadding=5>
<tr><td>User Name</td><td><input type=text name='username' size=40></td></tr>
<tr><td>User Level</td><td><select name='level'>
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>10</option>
<option>11</option>
<option>12</option>



</select>
</td></tr>

<tr><td>Designation</td><td><input type=text name='desig' size=40></td></tr>
<tr><td>Address</td><td><input type=text name='addr' size=40></td></tr>
<tr><td>Phone/Mobile</td><td><input type=text name='ph' size=40></td></tr>
<tr><td>Password</td><td><input type=password name='pswd1' size=40></td></tr>
<tr><td>Confirm Password</td><td><input type=password name='pswd2' size=40></td></tr>
<td>
Date </td><td>dd<input type=text name='df' size=2 readonly value='<?print date('d',time())?>'>
	mm<input type=text name='mf' size=2 readonly value='<?print date('m',time())?>'>
	yy<input type=text name='yf' size=4 readonly value='<?print date('Y',time())?>'>
 </td></tr>
<tr><td colspan=2 align=center><input type=submit name='submit' value='      Save      '> 
<input type=button value='     Cancel    ' onClick=document.location='mainbr.htm'>
</td></tr>
</table>
</form>
