<?php
include("session_start.php");
include("session_check.php");include("database.php");  
extract($_GET);
if($_GET['id']!="")
	{
		$query="select * from input_form where id='$id'";
		//echo "select * from input_form where id='$id'";
		$result=mysql_query($query);
		$row=mysql_fetch_array($result);
		
		$query1="select * from info where aid='$id'";
		//echo "select * from info where aid='$id'";
		$rest1=mysql_query($query1);
		$row_tree = mysql_fetch_array($rest1);
		
		$query_ward = mysql_query("select * from master_ward where wid= '".$row['ward_office']."'");
		//echo "select * from master_ward where wid= '".$row['ward_office']."'";
		$result_ward = mysql_fetch_array($query_ward);

		$query_sub = mysql_query("select * from master_ward_drop where did= '".$row['ward']."'");
		$result_sub = mysql_fetch_array($query_sub);

		
		$query_surveyor = mysql_query("select * from login where lid= '".$row['surveyor']."'");
		$result_surveyor = mysql_fetch_array($query_surveyor);

	}
if($_POST['submit']!="")
{
		//extract($_POST);
		//$query=mysql_query("update info set tree_name='$tree_name' where aid='$id'");
		$ward_office=$_POST["ward_office"];
		$survey_sheet_no=$_POST["survey_sheet_no"];
		$ward=$_POST["ward"];
		$date=$_POST["current_date1"];
		$sub_area=$_POST["sub_area"];
		$plot_no=$_POST["plot_no"];
		$society_name=$_POST["society_name"];
		$owner=$_POST["owner"];
		$house_no=$_POST["house_no"];
		$total_area=$_POST["plot_area"];
		$type=$_POST["type"."$i"];
		$miscellaneous=$_POST["miscellaneous"];
		$informer=$_POST["informer"];
		$surveyor=$_POST["surveyor"];
		
		mysql_query("update input_form SET ward_office='$ward_office',survey_sheet_no='$survey_sheet_no',ward='$ward',current_date1='$date',sub_area='$sub_area',plot_no='$plot_no',society_name='$society_name',owner='$owner',house_no='$house_no',plot_area='$total_area',type='$type',miscellaneous='$miscellaneous',informer='$informer',surveyor='$surveyor' where id='$id'");
		
		for($i=1;$i<=20;$i++)
		{

		   	$tree_name=$_POST["tree_name"."$i"];
		 	$scientific_name=$_POST["scientific_name"."$i"];
			$width=$_POST["width"."$i"];
			$height=$_POST["height"."$i"];
			$age=$_POST["age"."$i"];
			$con=$_POST["con"."$i"];
			$lng=$_POST["lng"."$i"];
			$lat=$_POST["lat"."$i"];
		 	$row_id1=$_POST["row_id"."$i"];
			$observation = $_POST["observation"."$i"];
			$manual_tree = $_POST["manual_tree"."$i"];
			$manual_sci_tree= $_POST["manual_sci_tree"."$i"];
		 
			if($tree_name!="")
			{
				mysql_query("update info SET tree_name='$tree_name',scientific_name='$scientific_name',width='$width',height='$height',age='$age',con='$con',lng='$lng',lat='$lat',observation='$observation', manual_tree='$manual_tree',manual_sci_tree='$manual_sci_tree' where pid='$row_id1'");
			}
		}
		?>
        <script language="javascript" type="text/javascript">
		alert("Updated Successfully");
		window.location="index_grid.php";
		</script>
<?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>
<script language="javascript" type="text/javascript">
function showreport()

{
	
	str = document.getElementById("ward_office").value;
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("ward").innerHTML=xmlhttp.responseText;
	
    }
  }
xmlhttp.open("GET","edit_ward.php?q="+str,true);
xmlhttp.send();
}

function showsci(str_tree,str_sci)

{
	
	str = document.getElementById(str_tree).value;
	
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(str_sci).innerHTML=xmlhttp.responseText;
	
    }
  }
xmlhttp.open("GET","edit_tree.php?q="+str,true);
xmlhttp.send();
}

function showtree(str_tree1,str_sci1)

{
	
	str1 = document.getElementById(str_sci1).value;
	
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(str_tree1).innerHTML=xmlhttp.responseText;
	
    }
  }
xmlhttp.open("GET","edit_sci.php?q="+str1,true);
xmlhttp.send();
}
</script>
</head>

<body class="body">

<div id="wrap" >
  
  
  <div id="top">
    <?php include("header.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 include("adminmenu.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">
   <?php //include("header.php"); ?><br />
	<form name="edit" method="post">
    
    	<table border="1" cellpadding="2" cellspacing="2" align="center" width="100%" height="200px" bordercolor="#2a4a73">
        	<tr>
                <td bgcolor="#a9c1de" class="f"> Edit Details </td>
             </tr>
             <tr>
            	<td>  
                	<table cellpadding="1" cellspacing="1" width="90%" align="center" height="130px">
                    	<tr> 
                        		<br />	
                        </tr>
                    	<tr>
                        	<td bgcolor="#c1d2e8" class="f" colspan="2" align="center" > Area Information </td>
                        </tr>
                        <tr> 
                        		<td>&nbsp; </td>	
                        </tr>
                        
                        <tr>
            				<td  width="30%" class="c"> Ward Office </td>
                    		<td><select name ="ward_office" id="ward_office" style="width:25%" onChange="showreport();">
							<?php 
								$query_master_ward = mysql_query("select * from master_ward");
								
								while($row_master_ward = mysql_fetch_array($query_master_ward))
								{
									if($result_ward['wid'] == $row_master_ward['wid'])
									{?>
										<option value="<?php print $row_master_ward['wid'];?>"  selected><?php print $row_master_ward['wvalue'];?> </option>	
							  <?php }
									else 
									{
									?>
                       				    <option value="<?php print $row_master_ward['wid'];?>" ><?php print $row_master_ward['wvalue'];?> </option>
                            			<?php
									}
							 		}	 ?></select>
                            </td>
            			</tr>
                        <tr>
            				<td  width="30%" class="c"> Survey Sheet Number </td>
                    		<td> <input type="text" name="survey_sheet_no" id="survey_sheet_no" value="<?php echo $row['survey_sheet_no']; ?>"></td>
            			</tr>
                        
                        <tr>
            				<td width="30%" class="c"> Ward </td>
                    		<td ><select name ="ward" id="ward" style="width:25%">
								<?php 
									$query_master_sub = mysql_query("select * from master_ward_drop where wid ='".$row['ward_office']."' ");
									while($row_master_sub = mysql_fetch_array($query_master_sub))
									{
										if($result_sub['did'] == $row_master_sub['did'])
										{
											?>
											<option value="<?php print $row_master_sub['wid'];?>"  selected><?php print $row_master_sub['dvalue'];?> </option>	
								<?php 	}
										else 
										{
										?>
											 <option value="<?php print $row_master_sub['did'];?>" ><?php print $row_master_sub['dvalue'];?> </option>
										<?php
										}
							 		} ?></select>
                            </td>
            			</tr>
                        <tr>
            				<td width="30%" class="c"> Date </td>
                    		<td> <input type="text" name="date" id="date" value="<?php echo $row['current_date1']; ?>"> </td>
            			</tr>
                        <tr>
            				<td width="30%" class="c"> Sub Area </td>
                    		<td> <input type="text" name="sub_area" id="sub_area" value="<?php echo $row['sub_area']; ?>"> </td>
            			</tr>
                        <tr>
            				<td width="30%" class="c"> Plot Number </td>
                    		<td> <input type="text" name="plot_no" id="plot_no" value="<?php echo $row['plot_no']; ?>"> </td>
            			</tr>
                        <tr>
            				<td width="30%" class="c"> Society Name </td>
                    		<td> <input type="text" name="society_name" id="society_name" value="<?php echo $row['society_name']; ?>"> </td>
            			</tr>
                        <tr>
            				<td width="30%" class="c"> Owner of House </td>
                    		<td> <input type="text" name="owner" id="owner" value="<?php echo $row['owner']; ?>"> </td>
            			</tr>
                        <tr>
            				<td width="30%" class="c"> House Number </td>
                    		<td> <input type="text" name="house_no" id="house_no" value="<?php echo $row['house_no']; ?>"> </td>
            			</tr>
                        <tr>
            				<td width="30%" class="c"> Total Area of Plot </td>
                    		<td> <input type="text" name="total_area" id="total_area" value="<?php echo $row['plot_area']; ?>"> </td>
            			</tr>
                        <tr>
            				<td width="30%" class="c"> Type </td>
                    		<td> <input type="text" name="type" id="type" value="<?php echo $row['type']; ?>"> </td>
            			</tr>
                        <tr>
            				<td width="30%" class="c"> Miscellaneous </td>
                    		<td> <input type="text" name="miscellaneous" id="miscellaneous" value="<?php echo $row['miscellaneous']; ?>"> </td>
            			</tr>
                        <tr>
            				<td width="30%" class="c"> Informer </td>
                    		<td> <input type="text" name="informer" id="informer" value="<?php echo $row['informer']; ?>"> </td>
            			</tr>
                       
                        <tr>
            				<td width="30%" class="c"> Surveyor </td>
                    		<td ><select name ="surveyor" id="surveyor" style="width:25%">
								<?php 
									$query_master_surveyor = mysql_query("select * from login");
									while($row_master_surveyor = mysql_fetch_array($query_master_surveyor))
									{
										if($result_surveyor['lid'] == $row_master_surveyor['lid'])
										{
											?>
											<option value="<?php print $row_master_surveyor['lid'];?>"  selected><?php print $row_master_surveyor['username'];?> </option>	
								<?php 	}
										else 
										{
										?>
											 <option value="<?php print $row_master_surveyor['lid'];?>" ><?php print $row_master_surveyor['username'];?> </option>
										<?php
										}
							 		} ?></select>
                            </td>
            			</tr>
                        <tr> 
                        		<td>&nbsp; </td>	
                        </tr>
                        
                    </table>
                    <br>
                    
                    <table cellpadding="2" cellspacing="2" border="1" width="90%" align="center" height="10px" bordercolor="#2a4a73">
                        		
                                <tr>
                        			<td bgcolor="#c1d2e8" class="f"  colspan="11"  align="center"> Tree Information </td>
                        		</tr>
                             
                                <tr>
                    				<td class="c"> Tree Name </td>
                        			<td class="c"> Scientific Name </td>
                                    <td class="c"> Width </td>
                                    <td class="c"> Height </td>
                                    <td class="c"> Age </td>
                                    <td class="c"> Condition </td>
                                    <td class="c"> Longitude </td>
                                    <td class="c"> Latitude </td>
                                    <td class="c" > Observation </td>
                                    <td class="c" > Manual Tree Nname </td>
                                    <td class="c" > Manual Scientific Tree Name </td>
                                </tr>
                              <?php  
										?>
										<tr>
                                        	<?php
											$i=1;
											/*$restq=mysql_query("select * from input_form left join info on input_form.id=info.aid 
											where input_form.id='".$_GET['id']."'");*/
											$restq=mysql_query("select * from info where aid='".$_GET['id']."'");
											//echo "select * from info where aid='".$_GET['id']."'";
											//$row_restq = mysql_fetch_array($restq);
											$num=mysql_num_rows($restq);
											
											while($num!=0)
											{
												$rowq=mysql_fetch_array($restq);
												$query_tree = mysql_query("select * from tree_name where tid= '".$rowq['tree_name']."'");
												$query_sci = mysql_query("select * from tree_name where tid= '".$rowq['scientific_name']."'");
												//echo "select * from tree_name where tid= '".$rowq['tree_name']."'";
												$result_tree = mysql_fetch_array($query_tree);
												$result_sci = mysql_fetch_array($query_sci);
												
										?>
                                                <td ><select name ="tree_name<?php echo $i; ?>" id ="tree_name<?php echo $i; ?>"  style="width:115pt" onChange="showsci('tree_name<?php echo $i; ?>','scientific_name<?php echo $i; ?>');">
												<?php 
                                                    $query_master_tree = mysql_query("select * from tree_name");
													//echo "select * from tree_name where tid ='".$row_tree['tree_name']."' ";
                                                    while($row_master_tree = mysql_fetch_array($query_master_tree))
                                                    {
														
                                                        if($result_tree['tid'] == $row_master_tree['tid'])
                                                        {
                                                            ?>
                                                            <option value="<?php print $row_master_tree['tid'];?>"  selected><?php print $row_master_tree['tree_name'];?> </option>	
                                                <?php 	}
                                                        else 
                                                        {
                                                        ?>
                                                             <option value="<?php print $row_master_tree['tid'];?>" ><?php print $row_master_tree['tree_name'];?> </option>
                                                        <?php
                                                        }
                                                    } ?></select>
                                			</td>
                                            
                    						<td ><select name ="scientific_name<?php echo $i; ?>" id="scientific_name<?php echo $i; ?>" style="width:110pt" onChange="showtree('tree_name<?php echo $i; ?>','scientific_name<?php echo $i; ?>');">
												<?php 
													
                                                    $query_master_sci = mysql_query("select * from tree_name");
                                                    while($row_master_sci = mysql_fetch_array($query_master_sci))
                                                    {
                                                        if($result_sci['tid'] == $row_master_sci['tid'])
                                                        {
                                                            ?>
                                                            <option value="<?php print $row_master_sci['tid'];?>"  selected><?php print $row_master_sci['scientific_name'];?> </option>	
                                                <?php 	}
                                                        else 
                                                        {
                                                        ?>
                                                             <option value="<?php print $row_master_sci['tid'];?>" ><?php print $row_master_sci['scientific_name'];?> </option>
                                                        <?php
                                                        }
                                                    } ?></select>
                            				</td>
                                            <td> <input type="text" size="8" name="width<?php echo $i; ?>" value="<?php echo $rowq['width']; ?>"> </td>
                                            <td> <input type="text" size="8" name="height<?php echo $i; ?>" value="<?php echo $rowq['height']; ?>"> </td>
                                            <td> <input type="text" size="8" name="age<?php echo $i; ?>" value="<?php echo $rowq['age']; ?>"> </td>
                                            <td> <input type="text" size="8" name="con<?php echo $i; ?>" value="<?php echo $rowq['con']; ?>"> </td>
                                            <td> <input type="text" size="8" name="lng<?php echo $i; ?>" value="<?php echo $rowq['lng']; ?>"> </td>
                                            <td> <input type="text" size="8" name="lat<?php echo $i; ?>" value="<?php echo $rowq['lat']; ?>"> </td>
                                            <td> <input type="text" size="11" name="observation<?php echo $i; ?>" value="<?php echo $rowq['observation']; ?>"> </td>
                                            <td> <input type="text" size="8" name="manual_tree<?php echo $i; ?>" value="<?php echo $rowq['manual_tree']; ?>"> </td>
                                            <td> <input type="text" size="8" name="manual_sci_tree<?php echo $i; ?>" value="<?php echo $rowq['manual_sci_tree']; ?>"> </td>
										</tr> 
                                        	<input type="hidden" name="row_id<?php echo $i; ?>" value="<?php echo $rowq['pid']; ?>"/>
                               <?php
							   					$i++;										
												$num--;
											}
							  ?>
                            </table>
                    
                </td>
            </tr>
        </table>
        <br />
        <table cellpadding="2" cellspacing="2" border="1"  align="center" width="100%"  bordercolor="#2a4a73">
        	<tr>
            	<td bgcolor="#a9c1de" class="f"align="right"><input type="submit"  name="submit" id="submit" value="Submit" onClick="return validate(); " style="text-decoration:none" class="button_c"><a href="index_grid.php " style="text-decoration:none"><input type="button" value = "Back" class="button_c" /></a></td>
                </tr>
        </table>
    </form>

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

    	
   </div> 

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





</body>
</html>