<? session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}

include("../opendb.php");
if($submit)
{
if(strlen($repname)<=0)
{
 print "<script> alert('Invalid Entry'); history.back(1); </script>";
 return;
}
 $code=substr($config,0,3).substr(time(),7,3); 
 $code=str_replace(' ','-',$code);

 $sql="insert into coo_master values('$code','$repname','$addr1','$addr2','$city','$dist', '$stat','$pin','$phone1','$phone2','$email','$brcode','$sman')";
 mysqli_query($db,$sql);
}
?>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:c1d7bb}
.mnu{margin-left:5}
</style>
<body bgcolor='ivory'>

<CENTER>
<BR>
<FORM ACTION='<?print $PHP_SELF?>' METHOD='POST'>
<table cellspacing=1 cellpadding=1 bgcolor=green>
<tr><td align=center>
<table>
<tr><td colspan=2 align=center><STRONG>SALES CO-ORDINATOR  MASTER</TD></TR>
<tr><td>Name </td><td><input type=text name='repname' size=40 onKeyDown=chkey(this)></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>Branch </td><td><select name='dist'> 
<?
$re=mysqli_query($db,"select * from br_master where brcode='$brcode' order by dist");
while($row=mysqli_fetch_row($re))
{
 print "<option>$row[1]</option>";
}
?>
</select></td></tr>

<tr><td>Sales Manager </td><td><select name='sman'> 
<?
$re=mysqli_query($db,"select * from sman_master where branch='$brcode' order by dist");
while($row=mysqli_fetch_row($re))
{
 print "<option>$row[1]</option>";
}
?>
</select></td></tr>

<tr><td>State </td><td><input type=text name='stat' size=40></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 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 coo_master where branch='$brcode' order by repname")or die(mysqli_error());
print "<table cellspacing=1 cellpadding=1 border=1>";
print "<th> No.<th>Name <th>Manager <th>Addr1 <th>Addr 2 <th>City <th>Dist. <th>State <th>Pin <th>Phone1 <th>Phone 2 ";
print " <th>Email <th>";
$i=1;
while($row=mysqli_fetch_row($result))
{
 print "\n<tr><td>".$i++."</td><td>$row[1]</td><td>$row[12]</td><td>$row[2]</td><td>$row[3]</td>";
 print "<td>$row[4]</td><td>$row[5]</td><td>$row[6]</td><td>$row[7]</td><td>$row[8]</td>";
 print "\n<td>$row[9]</td><td>$row[10]</td> <td align=center>\n&nbsp;<a href='editcoo_mast.php?code=$row[0]' title='Edit Entry' onMouseOver='window.status=''; return true'><img src='../img/edit.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='';
  }
}
</script>
