
<?php include("../../include/dbconnect.php");


// Get all _POST VALUES HERE..

  foreach($_POST as $p=>$t)
  {
     $_POST[$p] = trim($t);
  }

  $myArea = $_POST['Area'];


if(!($myfile=fopen("D:/temp/address.txt","w")))
{
  print("file couldnot be opened");
}
// Pull all the data from Area master & populate it
?>
<table align="center" width=590>
      <tr > 
        
<td width="139" height="31" align="right" ><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><font color="#003366">Select 
  Area &nbsp;</font></b></font></td>
<td>

<?
$stQuery = mysql_query("select areacode,location from area order by location");

?>
<form name='myForm01' method='POST' action='<?=$_SERVER[PHP_SELF]?>'>
  <select name='Area' onChange="javascript:submit();">
    <?
     echo "<option selected value=\" 0\"> Select Area";
    while($row = mysql_fetch_row($stQuery))
    {


        if(isset($myArea) && eregi("$myArea",$row[0]))
	    {
            echo "<option selected value=\"$row[0]\">$row[1]";
        }
        else{
            echo "<option value=\"$row[0]\">$row[1]";
        }
    }
?>
  </select>
</form>
</td> </tr>
    <?

// Pull all Customers from Customer  based on Selected Area id and populate it.


    $sBuyQuery = mysql_query("select name,address1,address2,city,state,pin,std,telno,email,contact,cst,tin FROM buy WHERE (areacode ='$myArea') and brcode='$brcode' order by name ");


// This form contain a hidden field AreaID which can be later used in next  page..
?><form name='myForm02' method='POST' action='entry.php' >
    <?

while ($row = mysql_fetch_row($sBuyQuery))
	{
	?>
   <table width="865" border="0">
      <tr>
        <td width="425"><b><font color="#990000"><? echo($row[0]);?></b></font></td><td width="430">Contact:<font color="#990099"><? echo($row[9]);?> </td>
      </tr>
      <tr>
        <td ><? echo($row[1]);?></td>
      </tr>
      <tr>
        <td><? echo($row[2]);?></td>
      </tr>
      <tr>
        <td><? echo($row[3]);?></td><td> CST:&nbsp;<? echo($row[10]);?></td>
      </tr>
      <tr>
        <td><? echo($row[4]);?></td><td> TIN:&nbsp;<? echo($row[11]);?></td>
      </tr>
      <tr>
        <td><? echo($row[5]);?></td>
      </tr>
      <tr>
        <td bgcolor="#6633FF">Tel:<? echo($row[6].'-'.$row[7]);?></td>
      </tr>
	        <tr>
        <td>Email:<? echo($row[8]);?></td>
      </tr>	 
	  
	  
      </tr>
	        <tr>
        <td>&nbsp;</td>
      </tr>	 	 
	  	  
      </tr>
	        <tr>
        <td>&nbsp;</td>
      </tr>	 
	    
    </table>	
	<?
	
	fputs($myfile,"$row[0] \n");
	fputs($myfile,"$row[1] \n");
	fputs($myfile,"$row[2] \n");
	fputs($myfile,"$row[3] \n");
	fputs($myfile,"$row[4] \n");
	fputs($myfile,"$row[5] \n");
	$tel=$row[6].'-'.$row[7];
	fputs($myfile,"Tel:$tel \n");
	fputs($myfile,"E-mail:$row[8]");
	fputs($myfile,"\n\n");
	}

echo("Address will be Printed in 'D:\temp\address.txt' for printing purpose");

?>
