<?php
session_start();
$username=$_SESSION['username'];
$code=$_REQUEST['code'];
if(!isset($_SESSION['username']))
{

    header('Location:login.php');
}
include_once('opendb.php');

if(isset($_POST['submit']))
{ 
    $brname=$_REQUEST[brname];
    $brman=$_REQUEST[brman];
    $braddr=$_REQUEST[braddr];
    $brcity=$_REQUEST[brcity];
    $brphone=$_REQUEST[brphone];
    $tin=$_REQUEST[tin];
    $brcode=$code;
    $sql="update branch set brname = '$brname',brman='$brman',braddr='$braddr',brcity='$brcity',brphone='$brphone',brtype='$btype',tin='$tin' where brcode ='$code'";
    mysqli_query($db,$sql) or die(mysqli_error());
//    $led_code=$brname.substr(time(),7,3).date("s"); 
//    mysqli_query($db,"insert into ledger values('$brname','Branches','','Dr','$led_code','$brcode')") or die('1'.mysqli_error());
}
if($ins==1){ $alert="One Record Added";}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin -  Nirmala Automobiles</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<center>
<div id="container">
	<!-- Header content goes here -->
    <!-- footer content goes here -->
    
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="left" background="images/top-bg.jpg"></td>
    <td align="right" valign="bottom" background="images/top-bg.jpg"><div id="admin-title"></div></td>
  </tr>
  <tr>
    <td width="219px" valign="top">
    <?php include "includes/leftmenu.php"; 
    $res=mysqli_query($db,"select * from branch where brcode='$code'");
    $row=mysqli_fetch_array($res);
    ?>
    </td>
    <td width="100%" valign="top" align="center" style="padding-top:20px;">
    <form id="addcategory" name="addcategory" method="post" action="">
        
        <table width="98%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td class="titles">Manage Branch &raquo; Branch Creation</td>
        </tr>
        <tr>
          <td valign="top"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td height="26" colspan="2"><table width="100%" border="0" align="center" cellpadding="2" cellspacing="0">
                  <tr>
                    <td height="10" colspan="8" align="center"><font color="#FF0000"><?php echo $alert;?></font></td>
                  </tr>
                  <tr class="td2">
                    <td width="17">&nbsp;</td>
                    <td colspan="3">Branch Name : <span class="red">*</span></td>
                    <td colspan="3" align="left"><input name="brname" type="text" class="textfield2" id="brname" value= "<?print $row[brname];?>" maxlength="255" onKeyPress="if(event.keyCode=='13')return editcategory_validate(document.editcategory);"/></td>
                    <td width="16"></td>
                    <td width="17" align="right">&nbsp;</td>
                  </tr>
                  <tr class="td2">
                    <td width="17">&nbsp;</td>
                    <td colspan="3">Branch Type : <span class="red">*</span></td>
                    <td colspan="3" align="left"><input name="btype" type="text" class="textfield2" id="btype" value="<?print $row[brtype];?>" maxlength="255" onKeyPress="if(event.keyCode=='13')return editcategory_validate(document.editcategory);"/></td>
                    <td width="16"></td>
                    <td width="17" align="right">&nbsp;</td>
                  </tr>
                  <tr class="td2">
                    <td width="17">&nbsp;</td>
                    <td colspan="3">Branch Manager : <span class="red">*</span></td>
                    <td colspan="3" align="left"><input name="brman" type="text" class="textfield2" id="brman" value="<?print $row[brman];?>" maxlength="255" onKeyPress="if(event.keyCode=='13')return editcategory_validate(document.editcategory);"/></td>
                    <td width="16"></td>
                    <td width="17" align="right">&nbsp;</td>
                  </tr>
                  <tr class="td2">
                    <td width="17">&nbsp;</td>
                    <td colspan="3">Address : <span class="red">*</span></td>
                    <td colspan="3" align="left"><input name="braddr" type="text" class="textfield2" id="braddr" value="<?print $row[braddr];?>" maxlength="255" onKeyPress="if(event.keyCode=='13')return editcategory_validate(document.editcategory);"/></td>
                    <td width="16"></td>
                    <td width="17" align="right">&nbsp;</td>
                  </tr>
                  <tr class="td2">
                    <td width="17">&nbsp;</td>
                    <td colspan="3">City : <span class="red">*</span></td>
                    <td colspan="3" align="left"><input name="brcity" type="text" class="textfield2" id="brcity" value="<?print $row[brcity];?>" maxlength="255" onKeyPress="if(event.keyCode=='13')return editcategory_validate(document.editcategory);"/></td>
                    <td width="16"></td>
                    <td width="17" align="right">&nbsp;</td>
                  </tr>
                  <tr class="td2">
                    <td width="17">&nbsp;</td>
                    <td colspan="3">State : <span class="red">*</span></td>
                    <td colspan="3" align="left"><select name='brstate'>
<option>Kerala</option>
<option>Karnataka</option>
</select></td>
                    <td width="16"></td>
                    <td width="17" align="right">&nbsp;</td>
                  </tr>
                  
                  <tr class="td2">
                    <td width="17">&nbsp;</td>
                    <td colspan="3">Phone : <span class="red">*</span></td>
                    <td colspan="3" align="left"><input name="brphone" type="text" class="textfield2" id="brphone" value="<?print $row[brphone];?>" maxlength="255" onKeyPress="if(event.keyCode=='13')return editcategory_validate(document.editcategory);"/></td>
                    <td width="16"></td>
                    <td width="17" align="right">&nbsp;</td>
                  </tr>
                  <tr class="td2">
                    <td width="17">&nbsp;</td>
                    <td colspan="3">GST No. : <span class="red">*</span></td>
                    <td colspan="3" align="left"><input name="tin" type="text" class="textfield2" id="tin" value="<?print $row[tin];?>" maxlength="255" onKeyPress="if(event.keyCode=='13')return editcategory_validate(document.editcategory);"/></td>
                    <td width="16"></td>
                    <td width="17" align="right">&nbsp;</td>
                  </tr>
                </table>
<tr bgcolor='lightsteelblue'><td colspan=2 align=center><input type=submit name='submit' value='  S A V E  '> <input type=button value='   C A N C E L    ' onClick=document.location='main.htm'></td></tr>

          </table></td>
        </tr>
      </table>
      
    </form>
    
    
    </td>
  </tr>
  <tr>
    <td colspan="2" align="center"><?php include("includes/footer.php");?></td>
  </tr>
</table>
</div>
</center>
<br clear="all" />
</body>
</html>

<script language="javascript" type="text/javascript">
function addcategory_validate(thisform)
{
	with (thisform)
	{
			if (emptyvalidation(catname,"Woops! You forgot to fill Category Name")==false) 
			{
			catname.focus();
			return false;
			}
	}
	thisform.submit();
}
function emptyvalidation(entered, alertbox)
{
	with (entered)
	{
		while (value.charAt(0) == ' ')
			value = value.substring(1);
		while (value.charAt(value.length - 1) == ' ')
			value = value.substring(0, value.length - 1);
		if (value==null || value=="")
		{
			if (alertbox!="") alert(alertbox);
			return false;
		}
		else return true;
	}
}
function emailvalidation(entered,alertbox)
{
	with (entered)
	{
		lastpos=value.length-1;//Total Letters
		apos=value.indexOf("@"); //Total letters before @
		dotpos=value.lastIndexOf(".");//Total letters before .
		beforeStr=value.substring(0,apos);
		afterStr=value.substring(apos);
		dotafatpos=afterStr.indexOf(".");
		udslpos=beforeStr.lastIndexOf("_");
		dotfpos=beforeStr.indexOf(".");
		dotlpos=beforeStr.lastIndexOf(".");
		if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2 || dotfpos!=dotlpos || apos-1==udslpos || dotafatpos==1) 
		{if (alertbox) {alert(alertbox);} return false; }
		else {return true;}
	}
}
document.location='listbr.php';
</script>
