<? session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
include("opendb.php");
if(isset($_POST['submit']))
{
$brname=$_REQUEST['brname'];
$addr1=$_REQUEST['addr1'];
$addr2=$_REQUEST['addr2'];
$city=$_REQUEST['city'];
$dist=$_REQUEST['dist'];
$stat=$_REQUEST['stat'];
$pin=$_REQUEST['pin'];
$phone1=$_REQUEST['phone1'];

$phone2=$_REQUEST['phone2'];
$email=$_REQUEST['email'];
$web=$_REQUEST['web'];
$phone1=$_REQUEST['phone1'];
 $code=substr($brname,0,3).substr(time(),7,3); 
 $code=str_replace(' ','-',$code);
  $re=mysqli_query($db,"select * from branch where brname='$brname'");
  if(mysqli_num_rows($re)>0)
  {
    print "<script> alert('Duplicate entry'); history.back(1); </script>";
    return;
  }

 $sql="insert into branch values('$code','$brname','$addr1','$addr2','$city','$dist', '$stat','$pin','$phone1','$phone2','$email','$web','$brcode','$brpass')";
 mysqli_query($db,$sql)or die(mysqli_error($db));

 $sql="insert into ledger values('$brname','Branches','0','Dr','$code','$brcode')";
 mysqli_query($db,$sql)or die(mysqli_error($db));
 
}
?>
<script>
function valid()
{
  submitOK="true";

 if(document.f1.brname.value.length<=0)
 {
   submitOK="false";
   alert('Invalid Branch name');
 }

  if(submitOK=="true")
   return true;
  else
   return false;
}
</script>
<title></title>
    <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>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:c1d7}
.mnu{margin-left:5}
</style>
<body background="back_ground.jpg">
<?php include('includes/top.php'); ?>
<br><br>
<div id='container'>
<CENTER>
<BR>
<!--
<form name='f1' action='<? print $PHP_SELF?>' method='Post' onSubmit="return valid()">
<table cellspacing=1 cellpadding=1 bgcolor=green>
<tr><td align=center>
<table>
<tr><td colspan=2 align=center>BRANCH MASTER</TD></TR>
<tr style={background:yellow}><td><font color=red>Branch Name <BR>
 <FONT SIZE=1 color=brown>(Non editable)</font> </td>
<td><input type=text name='brname' size=40 onKeyDown=chkey(this); style={color:red} title='As it will create A/c head, it cannot be edited'></td></tr>
<tr><td>Address1 </td><td><input type=text name='addr1' size=40></td></tr>
<tr><td>Address2 </td><td><input type=text name='addr2' size=40></td></tr>
<tr><td>City </td><td><input type=text name='city' size=40></td></tr>
<tr><td>District </td><td><input type=text name='dist' size=40></td></tr>
<tr><td>State </td><td><input type=text name='stat' size=40 value='KERALA'></td></tr>
<tr><td>Pin No </td><td><input type=text name='pin' size=40></td></tr>
<tr><td>Phone1 </td><td><input type=text name='phone1' size=40></td></tr>
<tr><td>Phone2 </td><td><input type=text name='phone2' size=40></td></tr>
<tr><td>Email_id </td><td><input type=text name='email' size=40></td></tr>
<tr><td>Web</td><td><input type=text name='web' size=40></td></tr>
<tr><td>Password</td><td><input type=password name='brpass' size=10></td></tr>
<TR><TD COLSPAN=2 ALIGN=CENTER><INPUT TYPE=SUBMIT name='submit' VALUE='  SAVE  '></TD></TR>

</table>
</td></tr>
</table>
</form>-->
<br>
<?
$result=mysqli_query($db,"select * from branch where brcode='$brcode' and active='Y'")or die(mysqli_error($db));
print "<table cellspacing=1 cellpadding=1 border=1 class=report>";
print "<th> No.<th>Name  <th>Address<th>City <th>State<th>Phone <th>Pin <th>Cst No";
print "<th>Edit";
$i=1;
while($row=mysqli_fetch_row($result))
{
 print "<tr><td>".$i++."</td><td>$row[1]</td><td>$row[3]</td>";
 print "<td>$row[4]</td><td>$row[10]</td><td>$row[5]</td><td>$row[11]</td><td>$row[9]</td>";
 print "<td><a href='editbranch.php?code=$row[0]'> <img src='img/signit.gif' border=0></a> </td> </tr>";
}
?>
</table>
<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='';
  }

}
</script>
</div>
