<?php

		
		include("database.php");



?>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Survey Application</title>

<link rel="stylesheet" type="text/css" href="css/style.css" />

<!--<link rel="stylesheet" type="text/css" href="css/page.css">

<link href="css/admincss.css" rel="stylesheet" type="text/css">

<link rel="stylesheet" type="text/css" href="css/ddsmoothmenu.css" />-->

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<script type="text/javascript" src="js/ddsmoothmenu.js">

</script>



<script type="text/javascript">



ddsmoothmenu.init({

	mainmenuid: "smoothmenu1", //menu DIV id

	orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"

	classname: 'ddsmoothmenu', //class added to menu's outer DIV

	//customtheme: ["#1c5a80", "#18374a"],

	contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]

})







</script>

<style type='text/css' media='print'>

#prnt {display : none}

#header{display:none;}

#footer{display:none;}

#back {display : none}



</style>

</head>



<body class="body">



<div id="wrap" >

  

  

  <div id="top">

    <?php /*?><?php include("header.php"); ?><?php */?>

    <!--<div id="ban"><table width="1004" align="left"  >

  <tr>

    <td width="234"  align="left"  valign="top" ><img src="images/logoss.jpg" border="0" /></td>

    <td  valign="top" style="padding-top:5px;" width="758"  align="right" ><table align="left" width="707">

  <tr>

    <td width="386" align="left"><div ><a href="#" id="bantext1">REQUEST A DEMO</a></div></td>

    <td width="167" align="left"><div ><a href="#" id="bantext2">DOWNLOADS</a></div></td>

    <td width="138" align="left"><div ><a href="#" id="bantext2">DOWNLOADS</a></div></td>

  </tr>

  <tr>

    <td colspan="3" align="center" class="banquot">Be Smart and Survey Smartly </td>

  </tr>

</table></td>

    

    

  </tr>

</table>

    </div>-->

    

    </div>

    </div>

   <!--<div id="menuholder"><?php /*?><?php include("adminmenu.php"); ?><?php */?></div>-->

   <div id="contholder">

   

    

    <!--<div id="nav">

     <ul>

     <li><a href="adminhome.php" id="home_on">HOME</a></li>

        <li><a href="adminproducts.php" id="products_on">PRODUCTS</a></li>

		<li><a href="adminfeatures.php" id="features_on">FEATURES</a></li>

        <li><a href="adminadvantages.php" id="advantages_on">ADVANTAGES</a></li>

        <li><a href="adminhowitworks.php" id="howitworks_on">HOW IT WORKS</a></li>

        <li><a href="adminhelp.php" id="help_on">HELP</a></li>

        <li><a href="admincontactus.php" id="contactus_on">CONTACT US</a></li>

    

    </ul>

    

    </div>-->

    

    

    	<div id="contdata">

    <hr width="90%"></hr>

<center><font face="Verdana" size="2"><b>Tree wise report </b></font></center>

<hr width="90%"></hr>

<br>

<table border='0' width='80%'  align='center'  style='font-family:Verdana; font-size:10pt; border-collapse: collapse;'>

    <tr>

        <td align="right">

            <input type="button" value="Print" id="prnt" name="print" onClick="window.print()" align="center" >

            <a href="tree_wise.php" id="back"style="text-decoration:none; "><input type="button" value="Cancel" name="cancel" >  </a>

        </td>

    </tr>

</table>

<br>

<?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_from=$_GET["flowering_season_from"];
	$plot_area_to=$_GET["plot_area_to"];
	$plot_area_from=$_GET["plot_area_from"];
	$measure = $_GET["measure"];
	
	$flower = $flowering_season_from."-".$flowering_season_to;
	$sql3 = "SELECT distinct i . aid 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' );";
 
 //echo $sql3;
 //exit;
 	$res = mysql_query($sql3);
	$res1 = mysql_query($sql3);
	
	
	

while($row = mysql_fetch_array($res))

  {
	  			$res2 = "select t.growth_speed as speed,i.age as age from info i, carbon c, tree_name t where i.age = c.age and i.tree_name = t.tid and i.aid = '".$row['aid']."'";
				
	  $carbon_query = mysql_query($res2);
				
				
	 			/*$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']."'"); 
				
				$count_query = mysql_query("SELECT count( i.tree_name ) as count , m.tree_name as tn 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 = '' OR i.height = '' ) AND i.aid = '".$row['aid']."' GROUP BY i.tree_name"); 
		
		//echo "SELECT count( i.tree_name ) as count , m.tree_name as tn 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 = '' OR i.height = '' ) AND i.aid = '".$row['aid']."' GROUP BY i.tree_name";
				

				
				
				$res_sql = mysql_fetch_array($sql);
				
				$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);
				
				$query_surveyor = mysql_query("select * from login where lid= '".$res_sql['surveyor']."'");

	$result_surveyor = mysql_fetch_array($query_surveyor);
	

  
  echo "<tr>";
	
	echo "<td colspan='18'>";

 	echo "<table border='1'   align='center'  style='font-family:Verdana; font-size:8pt; border-collapse: collapse; style='width:90%; margin:15px'>";

echo "<tr><td colspan='20' style='padding:10px;'>
	Survey Sheet Number :".$res_sql['survey_sheet_no']."<br>
	Ward Name :".$result_ward['wvalue']."<br>
	Sub Ward Name :".$result_sub['dvalue']."<br>
	Date :".$res_sql['current_date1']."<br>
	Society Name :".$res_sql['society_name']."<br>
	House Owner :".$res_sql['owner']."<br>
	Area :".$res_sql['total_area']."<br>
	Type :".$res_sql['type']."<br>
	Surveyor Name :".$result_surveyor['username']."<br><br>";
		echo "<table border='1' align='center' style='font-family:Verdana; font-size:8pt; border-collapse: collapse; width:50%; margin-bottom:15px'>";
		
		echo "<tr><th>Name of the tree </th>
		<th>No of Trees</th>
	</tr>";
			while($re = mysql_fetch_array($count_query))
		{
			echo "<tr><td>";
			echo $re['tn']."</td><td> ".$re['count'];
			echo "</td></tr>";
		}
		echo "</table>";
		
echo "</td></tr>";


 echo "<tr>

<th style='width:10%;'>Tree Name</th>

<th style='width:10%;'>Scientific Name</th>

<th style='width:10%;''>GBH </th>

<th style='width:10%;'> Height </th>

<th style='width:10%;'>Canopy Diameter </th>

<th style='width:10%;'>Age </th>

<th style='width:10%;'>Condition </th>

<th style='width:10%;'>Longitude </th>

<th style='width:10%;'>Latitude </th>

<th style='width:10%;'>Observation </th>

<th style='width:10%;'>Flowering Season</th>

<th style='width:10%;'>Flower Color</th>

<th style='width:10%;'>Fruiting Season</th>

<th style='width:10%;'>Native/Exotic</th>

<th style='width:10%;'>Growth Speed</th>

<th style='width:10%;'>Wild/Cultivated</th>

<th style='width:10%;'>Use</th>

<th style='width:10%;'>Time</th>

<th style='width:10%;'>Carbon Sequestration</th>

<th style='width:10%;'>Images</th>

</tr>";



while($row1 = mysql_fetch_array($sql2))

  {

		$query_image = mysql_query("SELECT info.`aid`,`image_path`.`pid` , image_path.`img_path`,info.`tree_name` FROM info
								INNER JOIN `image_path` ON info.pid = image_path.pid WHERE info.`pid`='".$row1['pid']."'");
																					
		$result_image = mysql_fetch_array($query_image);


		$time = explode("_",$row1['current_time1']);
		$b = ($time[3] == "1")? "pm" : "am";
		$time = $time[0].":".$time[1].":".$time[2]."".$b;
		
	  $query_tree = mysql_query("select * from tree_name where tid= '".$row1['tree_name']."'");

	  $result_tree = mysql_fetch_array($query_tree);
	  
	  
	  $res_carbon_query = mysql_fetch_array($carbon_query);
	  
		  if($res_carbon_query['speed'] != "")
		  {
		  $res3 = "select `".$res_carbon_query['speed']."` from carbon where `age` = '" .$res_carbon_query['age']."'";
	  $carbon = mysql_query($res3);
	  
	 // echo $res3;
		  
	  $res_carbon = mysql_fetch_array($carbon);
		  }

   echo "<tr>";

	  echo "<td align ='left' style='width:10%;'>" . $row1['tree_name'] . "</td>";

	  echo "<td align ='left' style='width:10%;'>" . $row1['scientific_name'] . "</td>";

	  echo "<td align ='left' style='width:10%;'>" . $row1['width'] . "</td>";

	  echo "<td align ='left' style='width:10%;'>" . $row1['height'] . "</td>";

	  echo "<td align ='left' style='width:10%;'>" . $row1['diameter_of_tree'] . "</td>";

	  echo "<td align ='left' style='width:10%;'>" . $row1['age'] . "</td>";

	  echo "<td align ='left' style='width:10%;'>" . $row1['con'] . "</td>";
	  
	  

	   echo "<td  ' style='width:10%;'>" . $row1['lng'] . "</td>";	  

	   echo "<td  ' style='width:10%;'>" . $row1['lat'] . "</td>";
	   
	   echo "<td  ' style='width:10%;'>" . $row1['observation'] . "</td>";	  
	   
	   echo "<td align ='left' style='width:10%;'>" . $row1['flowering_season'] . "</td>";
	  
	  echo "<td align ='left' style='width:10%;'>" . $row1['flower_color'] . "</td>";
	
		echo "<td align ='left' style='width:10%;'>" . $row1['fruiting_season'] . "</td>";
		echo "<td align ='left' style='width:10%;'>" . $row1['native'] . "</td>";
		echo "<td align ='left' style='width:10%;'>" . $row1['growth_speed'] . "</td>";
		echo "<td align ='left' style='width:10%;'>" . $row1['wild_cultivated'] . "</td>";
		echo "<td align ='left' style='width:10%;'>" . $row1['use'] . "</td>";
		echo "<td align ='left' style='width:10%;'>" . $time . "</td>";
		echo "<td align ='left' style='width:10%;'>" . $res_carbon[$res_carbon_query['speed']] . "</td>";
		echo "<td align ='left' style='width:10%;'>" . "<div align='left'><img src='$result_image[img_path]' style='height:80; width:80'></div></td>";
  echo "</tr>";

  }

  echo "</table>";

  echo "</td>";
	
	echo "</tr>";
				}
  }

	
  echo "</table> <br>";

?>

</table>

<?php



//}

?>





		

	<?php /*?><?php include("footer.php"); ?><?php */?>	

    

   </div>

    



    	

   </div> 



<!--<div id="footer">Copyright © 2012.Smart Survey All Rights Reserved.Website Designed & Developed by Kalpak Solutions</div>-->












</body>

</html>