<?php
	require("settings.php");
	require_once("helper.php");
	require_once("test_helper.php");

	session_start();

	if(!session_is_registered("id") || $_SESSION["id"] == "") {
		echo "Not logged in";
		die();
	}

	$link = db_connect();
	$sid = intval($_REQUEST["sid"]);
	$query = "SELECT solution FROM solutions WHERE sid=$sid";
	$result = mysql_query($query, $link) or die("Can't fetch solution: ".mysql_error($link));
	$line = mysql_fetch_array($result);
	$solution = $line["solution"];
	$classname = get_classname($solution);

	header("Content-type: text/x-java-source");
	header("Content-Disposition: attachment; filename=\"$classname.java\"");
	echo $solution;
	mysql_close($link);
?>
