<?php

include("session_start.php");  

include("session_check.php");  

if ( ($_FILES["file"]["size"] < 20000))

  {

  if ($_FILES["file"]["error"] > 0)

    {

    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";

    }

  else

    {

    //echo "Upload: " . $_FILES["file"]["name"] . "<br />";

    //echo "Type: " . $_FILES["file"]["type"] . "<br />";

    //echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";

    //echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";



    /*if (file_exists("upload/" . $_FILES["file"]["name"]))

      {

      echo $_FILES["file"]["name"] . " already exists. ";

      }*/

    //else

      //{

      move_uploaded_file($_FILES["file"]["tmp_name"],

       $_FILES["file"]["name"]);

	  $file_name = $_FILES["file"]["name"];

	  ?>

      <script type="text/javascript" language="javascript">

	  alert("File stored Successfully");

	 // window.location="index_grid.php";

	  </script>

      <?php

	  

      //}

    }

  }

else

  {

  echo "Invalid file";

  }

  

  

  	$host = "androidappp.db.4594972.hostedresource.com";

	$user = "androidappp";

	$pass = "A!ms99AA";

	$dbname = "androidappp";

	$dbconnect = @mysql_connect($host,$user,$pass);

	$selectdb = @mysql_select_db($dbname,$dbconnect);

try 

{

	$dbh = new PDO("sqlite:test_phone.db");

   // echo "Handle has been created ...... <br><br>";



}

catch(PDOException $e)

{

    echo $e->getMessage();

    echo "<br><br>Database -- NOT -- loaded successfully .. ";

    die( "<br><br>Query Closed !!! $error");

}



//echo "Database loaded successfully ....";

$sql = "SELECT * FROM input_form";	  

$rs = $dbh->query($sql);

//if($sql) {echo"device success";}

$rs->setFetchMode(PDO::FETCH_ASSOC);

$query_input=mysql_query("select * from input_form");



while($row1_input = mysql_fetch_array($query_input))

{

	//Server database

	$id_array[] = $row1_input["id"];

}

while ($row = $rs->fetch()) {

		$id = $row["id"];

        $ward_office = $row["ward_office"];

		$survey_sheet_no = $row["survey_sheet_no"];

		$ward = $row["ward"];

		$date = $row["date"];

		$sub_area = $row["sub_area"];

		$plot_no = $row["plot_no"];

		$society_name = $row["society_name"];

		$landmark = $row["landmark"];

		$pincode = $row["pincode"];

		$city = $row["city"];

		$state = $row["state"];

		$country = $row["country"];

		$owner = $row["owner"];

		$house_no = $row["house_no"];

		$total_area = $row["total_area"];

		$type = $row["type"];

		$miscellaneous = $row["miscellaneous"];

		$informer = $row["informer"];

		$surveyor = $row["surveyor"];

		

		echo $Field1;

		if(!@in_array($id, $id_array))

				{

		$sql1=mysql_query("insert into input_form(ward_office,survey_sheet_no,ward,date,sub_area,plot_no,society_name,landmark,pincode,city,state,country,owner,house_no,total_area,type,miscellaneous,informer,surveyor)values('$ward_office','$survey_sheet_no','$ward','$date','$sub_area','$plot_no','$society_name','$landmark','$pincode','$city','$state','$country','$owner','$house_no','$total_area','$type','$miscellaneous','$informer','$surveyor')");

				}

		//echo "Copied records into input_form table";

		/*$Field11 = 'false';

		

		$sql = "UPDATE inputform 

        SET Field1=?

		WHERE id=?";

$q = $dbh->prepare($sql);

$q->execute(array($Field11,$id));

if($q){echo "success";}*/

}



$sql = "SELECT * FROM info ";

$rs = $dbh->query($sql);

//if($sql) {echo"device success";}

$rs->setFetchMode(PDO::FETCH_ASSOC);

$query=mysql_query("select * from info");



while($row1 = mysql_fetch_array($query))

{

	//Server database

	$pid_array[] = $row1["pid"];

}

while ($row = $rs->fetch()) {

		$pid = $row["pid"];

		$tree_name = $row["tree_name"];

		$scientific_name = $row["scientific_name"];

		$width = $row["width"];

		$height = $row["height"];

		$age = $row["age"];

		$con = $row["con"];

		$loc = $row["loc"];

		$aid = $row["aid"];

		$sync = $row["sync"];

		

		echo $Field1;

		

		

		

		if(!in_array($pid, $pid_array))

				{

				$sql1=mysql_query("insert into info(tree_name,scientific_name,width,height,age,con,loc,aid,sync)values('$tree_name','$scientific_name','$width','$height','$age','$con','$loc','$aid','$sync')");

				}

//echo "Copied records into info table";

/*$Field11 = 'false';



$sql = "UPDATE inputform

SET Field1=?

WHERE id=?";

$q = $dbh->prepare($sql);

$q->execute(array($Field11,$id));

if($q){echo "success";}*/

}

?>

      <script type="text/javascript" language="javascript">

	  alert("Data Copied 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>

</head>



<body>

</body>

</html>