
<h3><?php echo $page_title;?></h3>
<?php 
$table="tpl_vendor_definition";
if($_REQUEST['Save'] && isset($_REQUEST['action']))
{
 	$data['vendor_name']=$_REQUEST['vendor_name']; 
    $data['vendor_code']=$_REQUEST['vendor_code']; 
	$data['vendor_address']=$_REQUEST['vendor_address']; 
	$data['vendor_country']=$_REQUEST['vendor_country'];
	$data['vendor_mobile']=$_REQUEST['vendor_mobile']; 
	$data['vendor_city']=$_REQUEST['vendor_city']; 
	$data['vendor_faxno']=$_REQUEST['vendor_faxno']; 
	$data['vendor_phone']=$_REQUEST['vendor_phone']; 
	$data['vendor_email']=$_REQUEST['vendor_email']; 
	$data['vendor_phone_reg']=$_REQUEST['vendor_phone_reg']; 
	$data['vendor_contactperson']=$_REQUEST['vendor_contactperson']; 
	$data['vendor_pincode']=$_REQUEST['vendor_pincode']; 
	$data['vendor_website']=$_REQUEST['vendor_website']; 
	$data['vendor_introducedby']=$_REQUEST['vendor_introducedby']; 
	$data['vendor_servicetaxno']=$_REQUEST['vendor_servicetaxno']; 
	$data['vendor_cstno']=$_REQUEST['vendor_cstno']; 
	$data['vendor_creditdays']=$_REQUEST['vendor_creditdays']; 
	$data['vendor_pan']=$_REQUEST['vendor_pan']; 
	$data['vendor_tallyledger']=$_REQUEST['vendor_tallyledger']; 
	$data['vendor_vattin']=$_REQUEST['vendor_vattin']; 
	
   	if($_REQUEST['action']=='AddNew'){
     $r=$s->RecordInsert($table, $data);
	 if($r)
	    $s->pageLocation($redirect_page.'&daction=Insert');
	 }
	 elseif($_REQUEST['action']=='Edit')
	 {
	 	$cond="id='".$_REQUEST['Vid']."'";
		  $r=$s->RecordEdit($table, $data, $cond);
		  $s->pageLocation($redirect_page.'&daction=Updated');

	 }
	 
}

if($_REQUEST['action']=='Delete')
{	$condition="id='".$_REQUEST['Vid']."'";
	$r=$s->DeleteRecord($table,  $condition);
	  $s->pageLocation($redirect_page.'&daction=Deleted');
}
if($_REQUEST['action']=='Edit')
{
	$condition="id='".$_REQUEST['Vid']."'";
   $result= $s->GetRecordById($table,  $condition);
   while($rowdata=DB_fetch_array( $result))
   {
    $vendor_name=$rowdata['vendor_name']; 
    $vendor_code=$rowdata['vendor_code']; 
	$vendor_address=$rowdata['vendor_address'];
	$vendor_country=$rowdata['vendor_country'];  
	$vendor_mobile=$rowdata['vendor_mobile']; 
	$vendor_city=$rowdata['vendor_city']; 
	$vendor_faxno=$rowdata['vendor_faxno']; 
	$vendor_phone=$rowdata['vendor_phone']; 
	$vendor_email=$rowdata['vendor_email']; 
	$vendor_phone_reg=$rowdata['vendor_phone_reg']; 
	$vendor_contactperson=$rowdata['vendor_contactperson']; 
	$vendor_pincode=$rowdata['vendor_pincode']; 
	$vendor_website=$rowdata['vendor_website']; 
	$vendor_introducedby=$rowdata['vendor_introducedby']; 
	$vendor_servicetaxno=$rowdata['vendor_servicetaxno']; 
	$vendor_cstno=$rowdata['vendor_cstno']; 
	$vendor_creditdays=$rowdata['vendor_creditdays']; 
	$vendor_pan=$rowdata['vendor_pan']; 
	$vendor_tallyledger=$rowdata['vendor_tallyledger']; 
	$vendor_vattin=$rowdata['vendor_vattin']; 
	$vendor_status=$rowdata['vendor_status'];
    }
}
?>

<?php 
if($_REQUEST['daction'])
{
  echo "<div class='success'>Record ".$_REQUEST['daction']." Successfully</div>";
}
  if(isset($_REQUEST['action']) &&($_REQUEST['action']=='AddNew' || $_REQUEST['action']=='Edit'))
  {
?>
<form action="" method="post">
<table width="100%" border="0" cellpadding="4" cellspacing="4" class="font_bold">
  <tr  valign="top">
    <td width="10%">Name</td>
      <td width="25%">: <input type="text" name="vendor_name" class="col_230" value="<?php  echo $vendor_name;?>"></td>
      <td width="10%">Vendor Code </td>
      <td width="25%">: <input type="text" name="vendor_code" class="col_230" value="<?php  echo $vendor_code;?>"></td>
  </tr>
   <tr  valign="top">
    <td>Address</td>
    <td valign="top"><span class="top_blt">: </span><textarea name="vendor_address" rows="2" cols="11" class="col_230"><?php echo $vendor_address;?></textarea>&nbsp;</td>
   
   
<td width="5%">
<table class="font_bold"> <tr>
	<td>Country</td></tr>
	<tr>
		<td><br />State</td>
		</tr>
</table></td>
 
 
    <td>
	<table cellpadding="0" cellspacing="0" class="font_bold"><tr>
	<td>
    	: <select name="vendor_country" id="country" style="width:230px" onchange="getstate(this.value)">
    	<option value="">select country</option>
    	<?php 
    	   	$query=DB_query("SELECT * FROM country_master",$db); 
    		while($row_res=DB_fetch_array($query))
			{ 
					$s='';
					if($vendor_country==$row_res['id'])
					$s="selected";
				?>
			<option value="<?php echo $row_res['id'];?>" <?php echo $s;?>><?php echo $row_res['country'];?></option>
    	<?php } ?>
    </select>
</td>
  </tr>
  
  <tr ><td ><br /> 
    	: <select name="vendor_state"  style="width:230px" onchange="getcity(this.value)" id="state">
    	<option value="">select State</option>
    	    </select>
</td></tr></table></td>
   <!-- =================State and country close here===========-->
   <tr  valign="top">
   	
    <td>Mobile</td>
    <td>: <input type="text" name="vendor_mobile" class="col_230" value="<?php  echo $vendor_mobile;?>"></td>
    <td width="5%">City</td>
    <td >: <select name="vendor_city"  style="width:230px" id="city">
    	<option value="">select City</option>
    	    </select>
    	
    	
    	
    	</td>
  </tr>
   <tr  valign="top">
    <td>Fax No. </td>
    <td>: <input type="text" name="vendor_faxno" class="col_230" value="<?php  echo $vendor_faxno;?>"></td>
    <td>Phone(Office)</td>
    <td>: <input type="text" name="vendor_phone" class="col_230" value="<?php  echo $vendor_phone;?>"></td>
  </tr>
   <tr  valign="top">
    <td>Email Id</td>
    <td>: <input type="text" name="vendor_email" class="col_230" value="<?php  echo $vendor_email;?>"></td>
    <td>Phone(Reg)</td>
    <td>: <input type="text" name="vendor_phone_reg" class="col_230" value="<?php  echo $vendor_phone_reg;?>"></td>
  </tr>
   <tr  valign="top">
    <td>Contact Person </td>
    <td>: <input type="text" name="vendor_contactperson" class="col_230" value="<?php  echo $vendor_contactperson;?>"></td>
    <td>Pin code </td>
    <td>: <input type="text" name="vendor_pincode" class="col_230" value="<?php  echo $vendor_pincode;?>"></td>
  </tr>
   <tr  valign="top">
    <td>Website</td>
    <td>: <input type="text" name="vendor_website" class="col_230" value="<?php  echo $vendor_website;?>"></td>
    <td>Introduced By </td>
    <td>: <input type="text" name="vendor_introducedby" class="col_230" value="<?php  echo $vendor_introducedby;?>"></td>
  </tr>
   <tr  valign="top">
    <td>Service Tax no </td>
    <td>: <input type="text" name="vendor_servicetaxno" class="col_230" value="<?php  echo $vendor_servicetaxno;?>"></td>
    <td>CST NO </td>
    <td>: <input type="text" name="vendor_cstno" class="col_230" value="<?php  echo $vendor_cstno;?>"></td>
  </tr>
   <tr  valign="top">
    <td>Credit days </td>
    <td>: <input type="text" name="vendor_creditdays" class="col_230" value="<?php  echo $vendor_creditdays;?>"></td>
    <td>PAN</td>
    <td>: <input type="text" name="vendor_pan" class="col_230" value="<?php  echo $vendor_pan;?>"></td>
  </tr>
   <tr  valign="top">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>Vendor Tally Ledger </td>
    <td>: <input type="text" name="vendor_tallyledger" class="col_230" value="<?php  echo $vendor_tallyledger;?>"></td>
  </tr>
   <tr  valign="top">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>VAT/TIN No </td>
    <td>: <input type="text" name="vendor_vattin" class="col_230" value="<?php  echo $vendor_vattin;?>"></td>
  </tr>
   <tr  valign="top">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type="checkbox" class="col_20" name="vendor_status" value="Y" <?php  echo ($vendor_status=='Y'?'checked':'')?>>Active</td>
    <td>&nbsp;</td>
  </tr>
   <tr  valign="top">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type="submit" name="Save" value="Save" class="pointer"></td>
    <td>&nbsp;</td>
  </tr>
</table>
</form>
<?php } 
else
{?>
<a href="<?php echo $redirect_page?>&action=AddNew">Addnew</a>
<table width="100%" border="1" cellpadding="2" cellspacing="2">
  <tr>
    <th>Vendor Code</th>
    <th>Vendor Name</th>  <th>Vendor Status</th>
    <th>Edit</th>
    <th>Delete</th>
  </tr>
<?php 
  	$condition="vendor_status='Y'";
   $result= $s->GetRecordById($table,  $condition);
   while($rowdata=DB_fetch_array( $result))
   {
?>
  <tr>
    <td><?php echo $rowdata['vendor_code'] ?></td>
    <td><?php echo $rowdata['vendor_name'] ?></td>
	 <td><?php echo ($rowdata['vendor_status']=='Y'?'Active':'Inactive'); ?></td>
    <td><a href="<?php echo $redirect_page?>&action=Edit&Vid=<?php echo  $rowdata['id'] ?>"><img src="images/icon-edit.png" width="10" height="10"></a></td>
   <td> <a href="<?php echo $redirect_page?>&action=Delete&Vid=<?php echo  $rowdata['id'] ?>"><img src="images/Icon_Delete.png" width="10" height="10"></a></td>
  </tr>
<?php } ?>  
</table>
 <?php } ?>
 <script language="JavaScript"> 
  
function getstate(country) 
{	 
	
if (country.length==0)
  {
  	  document.getElementById("state").innerHTML='';
 
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("state").innerHTML=xmlhttp.responseText;
      }
  }
 
xmlhttp.open("GET","getstate_citydata.php?country="+country,true);
xmlhttp.send();
}
function getcity(state) 
{	 
	
if (state.length==0)
  {
  document.getElementById("city").style.display='hide';
 
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("city").innerHTML=xmlhttp.responseText;
      }
  }
  var coun=document.getElementById("country").value;
 
 //mlhttp.open("GET","getstate_citydata.php?state="+state&con="+coun,true);
xmlhttp.open("GET","getstate_citydata.php?state="+state,true);
xmlhttp.send();
}

</script>

