<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?PHP
	session_start(); // Initialize session data
	if(! isset($_SESSION['useBT'])){ #If started in the middle go to 1st page
		header("Location: index.php");
	}

	$tmpStr = "<ans>\n<time>" . time() . "</time>\n<ip>";
	$tmpStr = $tmpStr . $_SERVER['REMOTE_ADDR'] . "</ip>\n<refer>" . $_SESSION['refer'] . "</refer>\n<useBT>" . $_SESSION['useBT'] . "</useBT>\n";
	if ($_SESSION['useBT'] == 'Yes'){
		$tmpStr2 = "<cTypes>" . implode(",",$_SESSION['cTypes']) . "</cTypes>\n";
		$tmpStr2 = $tmpStr2 . "<features>" . implode(",", $_SESSION['features']) . "</features>\n";
		$tmpStr2 = $tmpStr2 . "<siteKnow>" . implode(",",$_SESSION['sitesKnow']) . "</siteKnow>\n";
		$tmpStr2 = $tmpStr2 . "<siteUse>" . implode(",",$_SESSION['sitesUse']) . "</siteUse>\n";	
		$tmpStr2 = $tmpStr2 . "<fSiteUse>" . array_implode(",", ":", $_SESSION['fSitesUse']) . "</fSiteUse>\n";
		$tmpStr2 = $tmpStr2 . "<country>" . $_SESSION['country'] . "</country>\n";
		if (isset($_SESSION['comment'])){
			$tmpStr2 = $tmpStr2 . "<comment>" . $_SESSION['comment'] . "</comment>\n";
		}
			$tmpStr = $tmpStr .	$tmpStr2;
	}
	$fh = fopen('../../../../sResult.xml', 'a');
	$tmpStr = $tmpStr . "</ans>\n" ;
	fwrite($fh, $tmpStr);
	fclose($fh);
	
	session_destroy(); // Destroy the session

	function array_implode( $glue, $separator, $array ) {
    if ( ! is_array( $array ) ) return $array;
    $string = array();
    foreach ( $array as $key => $val ) {
        if ( is_array( $val ) )
            $val = implode( ',', $val );
        $string[] = "{$key}{$glue}{$val}";
       
    }
    return implode( $separator, $string );
   
}
?>

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

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link rel="stylesheet" type="text/css" href="css.css" />
<title>BitTorrent Search Engine Survey</title>
<style type="text/css">
.auto-style1 {
	text-align: center;
}
.auto-style2 {
	text-align: right;
}
.auto-style3 {
	text-align: center;
	font-size: small;
}
</style>
</head>

<body>
<table style="width: 800px" align="center">
	<tr>
		<td>
<h1 class="auto-style1">BitTorrent Search Engine/Site Survey&nbsp;</h1>
		</td>
	</tr>
	<tr>
		<td style="height: 21px"></td>
	</tr>
	<tr>
		<td>
<p>Thank you for completing the survey. We highly appreciate your contribution.</p>
		<p>Please share this survey with your friends, collegues, and 
		acquaintances on Facebook, google+, Twitter, blogs, e-mails, etc. Please 
		use the following link:</p>
		<p>www.cnrl.colostate.edu/Projects/CP2P/BTSurvey/ </p>
		</td>
	</tr>
	<tr>
		<td style="height: 21px">
		</td>
	</tr>
	<tr><td><p class="auto-style3">Progress 8/8</p></td></tr>
</table>
</body>

</html>
