<?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'";
		$result=mysql_query($query);
		$row=mysql_fetch_array($result);
		
		$query1="select * from info where aid='$id'";
		$rest1=mysql_query($query1);
		
		$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["date"];
		$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"];
		 
			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' 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>View Details</title>

<link rel="stylesheet" type="text/css" href="style.css" />
<script src="menuscript.js" language="javascript" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="menustyle.css" media="screen, print" /><script src="menuscript.js" language="javascript" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="menustyle.css" media="screen, print" />
<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();
}
</script>
</head>
<body>
<?php include("header.php"); ?><br />
	<form name="edit" method="post">
    
    	<table border="1"  align="center" width="80%" height="200px" bordercolor="#2a4a73">
        	<tr>
                <td bgcolor="#a9c1de" class="f"> Edit Details </td>
             </tr>
             <tr>
            	<td>  
                	<table width="75%" align="center" height="130px" bgcolor="#f4f8fb">
                    	<tr> 
                        		<br />	
                        </tr>
                    	<tr>
                        	<td bgcolor="#c1d2e8" class="f" colspan="2" align="center" > Area Information </td>
                        </tr>
                        <tr> 
                        		<td>&nbsp; </td>	
                        </tr>
                        
                        <tr>
            				<td class="c"> Ward Office </td>
                    		<td><select name ="ward_office" id="ward_office" style="width:110pt" 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 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 class="c"> Ward </td>
                    		<td ><select name ="ward" id="ward" style="width:110pt">
								<?php 
									$query_master_sub = mysql_query("select * from master_ward_drop where wid ='".$row['ward_office']."' ");
									echo "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['did'];?>"  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 class="c"> Date </td>
                    		<td> <input type="text" name="date" id="date" value="<?php echo $row['current_date1']; ?>"> </td>
            			</tr>
                        <tr>
            				<td 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 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 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 class="c"> Owner of House </td>
                    		<td> <input type="text" name="owner" id="owner" value="<?php echo $row['owner']; ?>"> </td>
            			</tr>
                        <tr>
            				<td 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 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 class="c"> Type </td>
                    		<td> <input type="text" name="type" id="type" value="<?php echo $row['type']; ?>"> </td>
            			</tr>
                        <tr>
            				<td class="c"> Miscellaneous </td>
                    		<td> <input type="text" name="miscellaneous" id="miscellaneous" value="<?php echo $row['miscellaneous']; ?>"> </td>
            			</tr>
                        <tr>
            				<td class="c"> Informer </td>
                    		<td> <input type="text" name="informer" id="informer" value="<?php echo $row['informer']; ?>"> </td>
            			</tr>
                       
                        <tr>
            				<td class="c"> Surveyor </td>
                    		<td ><select name ="surveyor" id="surveyor" style="width:110pt">
								<?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>
                        <tr>
                        	<td bgcolor="#c1d2e8" class="f" colspan="2" align="center"> Tree Information </td>
                        </tr>
                        <tr> 
                        		<td>&nbsp; </td>	
                        </tr>
                        <tr>
                        	<table border="1" width="75%" align="center" height="10px" bgcolor="#f4f8fb


" bordercolor="#2a4a73">
                        		<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"> Diameter of Tree(In Feet)</td>
                                    <td class="c"> Age </td>
                                    <td class="c"> Condition </td>
                                    <td class="c"> Longitude </td>
                                    <td class="c"> Latitude </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']."'");
											$num=mysql_num_rows($restq);
											while($num!=0)
											{
												$rowq=mysql_fetch_array($restq);
										?>
											<td> <input type="text" size="8" name="tree_name<?php echo $i; ?>" value="<?php echo $rowq['tree_name']; ?>"> </td>
                                            <td><input type="text" size="8" name="scientific_name<?php echo $i;?>" value="<?php echo $rowq['scientific_name']; ?>"></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="height<?php echo $i; ?>" value="<?php echo $rowq['diameter_of_tree']; ?>"> </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>
										</tr> 
                                        	<input type="hidden" name="row_id<?php echo $i; ?>" value="<?php echo $rowq['pid']; ?>"/>
                               <?php
							   					$i++;										
												$num--;
											}
							  ?>
                            </table>
                    	</tr>
                        
                    </table>
                </td>
            </tr>
        </table>
        <br />
        <table border="1"  align="center" width="80%"  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>
</body>
</html>