<?php include("session_start.php");

include("session_check.php");

include("database.php");

if($_GET['tree_name']!="")

{	

	$tree_name=$_GET["tree_name"];
	$ver_name = $_GET["ver_name"];
	$gbh = $_GET["gbh"];
	$height=$_GET["height"];
	$ecological=$_GET["ecological"];
	$economical=$_GET["economical"];
	
	$flowering_season_from=$_GET["flowering_season_from"];
	$flowering_season_to=$_GET["flowering_season_to"];
	
	
	$flower = $flowering_season_from."-".$flowering_season_to;
	
	$sql3 = "SELECT distinct i . aid,p.plot_area FROM info i, tree_name m, input_form p WHERE i.tree_name = m.tid
AND i.aid = p.id AND ( i.tree_name = '$ver_name' OR i.scientific_name = '$tree_name' OR i.width = '$gbh' OR i.height = '$height' or m.flowering_season = '$flower' );";
 
// echo $sql3;
 //exit;
 	$res = mysql_query($sql3);
	
	$num = @mysql_num_rows($res); if($num >0)
	{?>
    
    	<a href="print_tree_wise_report.php?tree_name=<?php echo $tree_name?>&ver_name=<?php echo $ver_name?>&gbh=<?php echo $gbh?>&height=<?php echo $height?>&ecological=<?php echo $ecological?>&economical=<?php echo $economical?>&flowering_season_from=<?php echo $flowering_season_from?>&flowering_season_to=<?php echo $flowering_season_to?>" style="text-decoration:none"> <input type="button" bgcolor="#a9c1de"  name="print" id="print" value="Print"   class="button_c" onClick=""></a><br />
        <b>Total Number of Records : <?php echo $num ?>
        
        <table border="1" cellpadding="2" cellspacing="2" width="100%" align="center" bordercolor="#bcd5e7">
        <tr>
        
        <td align="left" ><font class="font4"><b>View</font></td>
        <td align="left"><font class="font4"><b>Ward Office</font></td>

        <td align="left"><font class="font4"><b>Ward</font></td>

        <td align="left"><font class="font4"><b>Date</font></td>

        <td align="left"><font class="font4"><b>Society Name</font></td>

        <td align="left"><font class="font4"><b>Tree Records</font>

        </td>
        </tr>
        
        <?php 
			while($row =@mysql_fetch_object($res))
			{
				$flag = true;
				$flag2 = true;
				$plot = $row->plot_area;
				if($plot_area_to != "")
				{
					if($measure == "sq.ft")
					{
						if(strpos($plot,"sq.ft") != false)
						{
							$plot = str_replace("sq.ft","",$plot);
						}
						else
						{
							$flag = false;
						}
					}
					else
					{
						if(strpos($plot,"m") != false)
						{
							$plot = str_replace("m","",$plot);
						}
						else
						{
							$flag = false;
						}
					}
					
					$plot = (int)$plot;
					
					if(!($plot_area_from <= $plot && $plot <= $plot_area_to))
					{
						$flag2 = false;
					}
				}
				if($flag2 && $flag)
				{
				
				
				$sql = mysql_query("SELECT i . * , m . * , p . * FROM info i, tree_name m, input_form p WHERE i.tree_name = m.tid AND i.aid = p.id AND ( i.tree_name = '$ver_name' OR i.scientific_name = '$tree_name' OR i.width = '$gbh' OR i.height = '$height') AND i.aid = '". $row->aid."'");
				
				//echo "SELECT i . * , m . * , p . * FROM info i, tree_name m, input_form p WHERE i.tree_name = m.tid AND i.aid = p.id AND ( i.tree_name = '$ver_name' OR i.scientific_name = '$tree_name' OR i.width = '$gbh' OR i.height = '$height') AND i.aid = '". $row->aid."'";
				
				$sql2 = mysql_query("SELECT i . * , m . * , p . * FROM info i, tree_name m, input_form p WHERE i.tree_name = m.tid AND i.aid = p.id AND ( i.tree_name = '$ver_name' OR i.scientific_name = '$tree_name' OR i.width = '$gbh' OR i.height = '$height') AND i.aid = '". $row->aid."'"); 
				 
				 
				
				$res_sql = mysql_fetch_array($sql);
				
				
				//echo $plot;
							
								
				$query_ward = mysql_query("select * from master_ward where wid= '".$res_sql['ward_office']."'");

				$result_ward = mysql_fetch_array($query_ward);
			
				
			
				$query_sub = mysql_query("select * from master_ward_drop where did= '".$res_sql['ward']."'");
			
				$result_sub = mysql_fetch_array($query_sub);
							
				echo "<tr>";
				
				echo "<td align='left' valign='top' ><a href='view_records_tree.php?id=$row->aid&tree_name=$tree_name&ver_name=$ver_name&gbh=$gbh&height=$height&ecological=$ecological&economical=$economical&flowering_season_from=$flowering_season_from&flowering_season_to=$flowering_season_to'><font class='font4'>"."<img src='images/view.png' border='0'>"."</font></div></td>";
				
				echo "<td  align='left' valign='top'>"."<div align='center'>"."<font class='font4'>".$result_ward['wvalue']."</font></div></td>";
				
				echo "<td  align='left' valign='top'>"."<div align='center'>"."<font class='font4'>".$result_sub['dvalue']."</font></div></td>";
				
				echo "<td  align='left' valign='top'>"."<div align='center'>"."<font class='font4'>".$res_sql['current_date1']."</font></div></td>";
				
				echo "<td  align='left' valign='top'>"."<div align='center'>"."<font class='font4'>".$res_sql['society_name']."</font></div></td>";
				
				echo "<td>"; ?>
					
                    <table align="center" border="1" width="100%" bordercolor="#bcd5e7">
                     <tr>
                        <td align="center" ><font class="font4"/><b> Tree Name </td>
            
                        <td align="center" ><font class="font4"/><b> Scientific Name </td>
            
                        <td align="center" ><font class="font4"/><b> Longitude </td>
            
                        <td align="center" ><font class="font4"/><b> Latitude </td>
            
                     </tr>
                     <?php
                     while($row1 = @mysql_fetch_object($sql2))
					 {
						echo "	<tr>

				<td align='left'>"."<div align='center'>"."<font class='font4'>".$row1->tree_name."</font></div></td>

				<td align='left'>"."<div align='center'>"."<font class='font4'>".$row1->scientific_name."</font></div></td>

				<td align='left'>"."<div align='center'>"."<font class='font4'>".$row1->lng."</font></div></td>

				<td align='left'>"."<div align='center'>"."<font class='font4'>".$row1->lat."</font></div></td>

			</tr>

		

	";

					 }
					 ?>
                    
                    </table>
					
				
				
<?php				echo "</td>";
				
				echo "</tr>";
			}
				
			} 
		?>
        
       
        </table>
<?php
		
		
	}
 
	 else
	
	{
	
		echo "No Records To Display";
	
	}

}
?>

<!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>Survey Application</title>

</head>



<body>

</body>

</html>