<link href="css/form.css" type="text/css" rel="stylesheet" media="screen"  />
<html>
<body >


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

if($save)
{
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
 return;
}
$ondate=date("Y-m-d");
$ontime=date("H:i:s");

$lo=mysqli_query($db,"select * from prospmaster where pcode='$pcodee' ");
$l=mysqli_fetch_array($lo);
if(mysqli_num_rows($lo)<=0)
{
 $code=substr($pname,0,4).substr(time(),5);
 $sql="insert into prospmaster values('$code','$brcode','$pname','$sex','$age','$addr1', '$city', '$pin','$ph1','$ph2', '$mob','$exec', '$district','$addr2','$addr3','$addr4','$std','$location','$ctype','$eic','$tat','$ley','$mah','$maz','$oth','$bbenz','$eichermodel','$tatamodel','$leylandmodel','$mahindramodel','$mazdamodel','$othersmodel','$bbenzmodel','$active','$ondate','$ontime')";
  mysqli_query($db,$sql) or die(mysqli_error());
}
else
{

print $sql="update prospmaster set pname= '$pname',sex ='$sex',age='$age',addr1='$addr1',city='$city',pin= '$pin',ph1= '$ph1',ph2='$ph2',mob= '$mob',exec='$exec',district=  '$district',addr2='$addr2',addr3='$addr3',addr4='$addr4',std ='$std',
location=  '$location',ctype='$ctype',eicher= '$eic',tata=  '$tat',leyland='$ley',mahindra='$mah',mazda='$maz',others='$oth'=bbenz='$bbenz', eichermodel='$eichermodel',tatamodel='$tatamodel',leylandmodel='$leylandmodel',mahindramodel='$mahindramodel',mazdamodel='$mazdamodel',othersmodel='$othersmodel',bbenzmodel='$bbenzmodel',active='$active' where pcode='$pcodee'";
  mysqli_query($db,$sql) or die(mysqli_error());
return;
}

}


if($sea)
{




?>
<head>
<script>
 function valid()
 {
  var phone1=document.f1.ph1.value;
  var phone2=document.f1.ph2.value;
  var mobile=document.f1.mob.value;

   if(document.f1.pname.value.length<=0)
   {
     alert('Invalid Prospect');
	document.f1.pname.focus();
     return false;
   }
   if(document.f1.addr1.value.length<=0)
   {
     alert('Invalid Address');
	document.f1.addr1.focus();
     return false;
   }
 if(document.f1.mobile.length<=0 )
 {
     alert('Invalid Mobile Number');
	document.f1.mob.focus();
     return false;
   }    
 if(document.f1.ctype.length<=0 )
 {
     alert('Invalid customer type');
	document.f1.ctype.focus();
     return false;
   }    





 if(phone1.length<=0 && phone2.length<=0 && mobile.length<=0)
   {
     alert('Invalid Contact Numbers');
	document.f1.ph1.focus();
     return false;
   }
 if(mobile.length>0 && mobile.length!=10)
 {
     alert('Invalid Mobile Number');
	document.f1.mob.focus();
     return false;
   }


   return true;
 }

</script>

</head>
<center>
<form name='f1' action='<?print $PHP_SELF?>' method='post' onsubmit="return valid()">
  <table border="0" cellpadding="5" cellspacing="1" bgcolor='steelblue'>
    <tr>
      <td colspan="9" align="center" height="17" bgcolor="steelblue">
<font color=white><b>P R O S P E C T &nbsp;&nbsp; M A S T E R </td>
    </tr>
<?

$lo=mysqli_query($db,"select * from prospmaster where mob='$pcode' ");
$l=mysqli_fetch_array($lo);

if (mysqli_num_rows($lo)>0)
{
print $l[0];

}
else
{
 $l[11]=$user;

}


?>
<TR><TD><font color=red>*</font>Name </td><td><input type=text value=<?print "'$l[2]'"?> name='pname' size=40 ></td>
	<td>	Sex <select name='sex'><option>Male</option><option>Female</option> </select></td>
	<td>Age</td><td><input type=text name='age' size=3 maxlength=2 value=<?print "'$l[4]'"?>> <?print $nbsp;?><input type=text value=<?print "'$l[0]'"?> name='pcodee' size=10 ></td>
</tr>
<tr><td><font color=red>*</font>Address 1</td><td colspan=6><input type=text name='addr1' size=70 value=<?print "'$l[5]'"?>></td></tr>
<tr><td>Address 2</td><td colspan=6><input type=text name='addr2' size=70 value=<?print "'$l[13]'"?>></td></tr>
<tr><td>Address 3</td><td colspan=6><input type=text name='addr3' size=70 value=<?print "'$l[14]'"?>></td></tr>
<tr><td>Address 4</td><td colspan=6><input type=text name='addr4' size=70 value=<?print "'$l[15]'"?>></td></tr>
<?





?>

<tr><td>District</td><td >
 <select name='district'>
<option>Alappuzha</option>
<option>Ernakulam</option>
<option>Idukki</option>
<option>Kollam</option>
<option>Kannur</option>
<option>Kasaragod</option>
<option>Kottayam</option>
<option>Kozhikode</option>
<option>Malappuram</option>
<option>Palakkad</option>
<option>Pathanamthitta</option>
<option>Thrissur</option>
<option>Thiruvananthapuram</option>
<option>Wayanad</option>

   <option>   Bangalore Urban  </option>
   <option>   Bangalore Rural  </option>
   <option>   Bagalakot  </option>
   <option>   Belgaum  </option>
   <option>   Bellary  </option>
   <option>   Bidar  </option>
   <option>   Bijapur  </option>
   <option>   Chamarajanagar  </option>
   <option>   Chikballapur  </option>
   <option>   Chikkamaglur  </option>
   <option>   Chitiradurga  </option>
   <option>   Coorg  </option>
   <option>   Davanagere  </option>
   <option>   Dharwad  </option>
   <option>   Gulbarga  </option>
   <option>   Gadag  </option>
   <option>   Hassan  </option>
   <option>   Haveri  </option>
   <option>   Kolar  </option>
   <option>   Koppal  </option>
   <option>   Mandya  </option>
   <option>   Dakshina Kannada  </option>
   <option>   Mysore  </option>
   <option>   Raichur  </option>
   <option>   Ramanagra  </option>
   <option>   Shimoga  </option>
   <option>   Tumkur  </option>
   <option>   Udupi  </option>
   <option>   Uttara Kannada  </option> 

</td>
	<td>Pin</td><td><input type=text name='pin' maxlength=6 value=<?print "'$l[7]'"?>></td>
</tr>

<tr><td>Std Code</td> <td colspan=10><input type=text name='std' size=4 maxlength=4 value=<?print "'$l[16]'"?>> Phone 1 <input type=text name='ph1' value=<?print "'$l[8]'"?>>
	Phone 2 <input type=text name='ph2' value=<?print "'$l[9]'"?>>
</tr>
<tr><td><font color=red>*Mobile </font></td><td colspan=4><input type=text name='mob' size=23 maxlength=10 value=<?print $pcode ?>></td></tr>

<tr><td> Executive </td><td colspan=10><select name='exec'>
<option><?print "$l[11]"?></option>
<option><?print $user?></option>

</select>

<tr><td>
Ctype </td><td colspan=10><select name='ctype'>
<option><?print "$l[18]"?></option>
<option>FTU</option>
<option>Existing</option>
<option>Competetion</option>
<option>Both</option>

</td>
</tr>

<tr><td>Existing vehicles(Qty) -Eicher</td> <td colspan=10><input type=text name='eic' size=4 maxlength=4  value=<?print "'$l[19]'"?>> Tata <input type=text name='tat' size=4 maxlength=4  value=<?print "'$l[20]'"?>>
	Leyland <input type=text name='ley' size=4 maxlength=4  value=<?print "'$l[21]'"?>>
        Mahindra <input type=text name='mah' size=4 maxlength=4  value=<?print "'$l[22]'"?>>
        Mazda <input type=text name='maz' size=4 maxlength=4  value=<?print "'$l[23]'"?>>
        BharatBenz <input type=text name='bbenz' size=4 maxlength=4  value=<?print "'$l[25]'"?>>

Others <input type=text name='oth' size=4 maxlength=4  value=<?print "'$l[24]'"?>>
</tr>

<tr><td>Existing vehicles-Models</td> <td colspan=10><select name='eichermodel'><option><?print "$l[26]"?></option>
<?
$rr=mysqli_query($db,"select subname from brand where gname='eicher' order by subname");
while($r=mysqli_fetch_row($rr))
{
 print "<option>$r[0]</option>";
}
?>
</select> Tata <select name='tatamodel'><option><?print "$l[27]"?></option>
<?
$rr=mysqli_query($db,"select subname from brand where gname='tata' order by subname");
while($r=mysqli_fetch_row($rr))
{
 print "<option>$r[0]</option>";
}
?>
</select>
	Leyland <select name='leylandmodel'><option><?print "$l[28]"?></option>
<?
$rr=mysqli_query($db,"select subname from brand where gname='leyland' order by subname");
while($r=mysqli_fetch_row($rr))
{
 print "<option>$r[0]</option>";
}
?>
</select>
        Mahindra <select name='mahindramodel'><option><?print "$l[29]"?></option>
<?
$rr=mysqli_query($db,"select subname from brand where gname='mahindra' order by subname");
while($r=mysqli_fetch_row($rr))
{
 print "<option>$r[0]</option>";
}
?>
</select>
        Mazda <select name='mazdamodel'><option><?print "$l[30]"?></option>
<?
$rr=mysqli_query($db,"select subname from brand where gname='mazda' order by subname");
while($r=mysqli_fetch_row($rr))
{
 print "<option>$r[0]</option>";
}
?>
</select>
        BharatBenz <select name='bbenzmodel'><option><?print "$l[32]"?></option>
<?
$rr=mysqli_query($db,"select subname from brand where gname='bbenz' order by subname");
while($r=mysqli_fetch_row($rr))
{
 print "<option>$r[0]</option>";
}
?>
</select>

Others <select name='othersmodel'><option><?print "$l[31]"?></option>
<?
$rr=mysqli_query($db,"select subname from brand where gname='others' order by subname");
while($r=mysqli_fetch_row($rr))
{
 print "<option>$r[0]</option>";
}
?>
</select>
</tr>
<?
$locres1=mysqli_query($db,"select location from saletarget where exec='$user'");
$locrow1=mysqli_fetch_array($locres1);
?>
<tr><td>Area of Executive</td><td><input type=text name='city' size=20 value=<?print "'$l[6]'"?>></td><td>District of Executive</td><td ><select name='location'>
<option><?print $locrow1[0]?></option>

</td></tr><tr><td>Active</td><td><input type=text name='active' size=10 value='active' ></td></tr>

<tr>
      <td colspan="9" align="center" height="17" bgcolor="steelblue">
	<input type=submit value='Save' name='save'> <input type=reset value='Cancel'>
</td></tr>
</table>
</form>
<style>
th{color:white;background-color:steelblue}
</style>

<table border="0" cellpadding="3" cellspacing="1" bgcolor='steelblue'>
<th>No <th>Name <th>Address <th>City <th>Pin<th>STD<th>Phone1 <th>Phone2 <th>Mobile<th>District
<?
$i=1;
$pres=mysqli_query($db,"select * from prospmaster where brcode='$brcode' and exec='$user' order by pname");
while($prow=mysqli_fetch_array($pres))
{
 print "\n<tr><td>".$i++."</td><td>$prow[2]</td><td>$prow[addr1]</td><td>$prow[city]</td>";
 print "<td>$prow[pin]</td><td>$prow[std]</td><td>$prow[ph1]</td><td>$prow[ph2]</td><td>$prow[mob]</td>";
 print "<td>$prow[district]</td></tr>";
}
?>
</table>
<?
}
?>

<center>

<form name='f2' action='<?print $PHP_SELF?>' method='post' onsubmit="return valid()">
<table>
<th colspan=4>Enter Mobile No.</th>
<tr><td><input type="text" name="pcode"  style="font-size:8pt;width:15ex;"><br>
</td></tr>

<th colspan=3><input type=submit value='Next' name='sea'>
</td></tr>
</table>
<script>
valid()
{
 if(document.f2.pcode.length>0 && document.f2.pcode.length!=10)
 {
     alert('Invalid Mobile Number');
	document.f2.pcode.focus();
     return false;
   }
}
</script>
</form>

