<?php
include ("connect.php");

$sound1 = $_SESSION["randNum1"];
$sound2 = $_SESSION["randNum2"];
$response1 = $_POST["first"];
$response2 = $_POST["second"];

$url = 'https://serv.cusp.nyu.edu/files/sonyc/test_sequences/json/sequence_data.json';

$soundinfo = json_decode(file_get_contents($url), true);
$actual1 = $soundinfo['tone_sequence_'.strval($sound1).'.wav']['ntones'];
$actual2 = $soundinfo['tone_sequence_'.strval($sound2).'.wav']['ntones'];

//echo "actual1".$actual1;

$result = (($actual1 == $response1) && ($actual2 == $response2));

$query = "INSERT INTO userinfo (userid, test1, response1, test2, response2, passtest) VALUES (?, ?, ?, ?, ?, ?)";
$stmt = $mysqli->prepare($query);
$stmt->bind_param('siiiii', $_SESSION["uid"], $sound1, $response1, $sound2, $response2, $result);
$stmt->execute();

if ($result == true) {
	header("Location: http://serv.cusp.nyu.edu/projects/soundtagging/adjust.php");
	die();
}

else {
	header("Location: http://serv.cusp.nyu.edu/projects/soundtagging/sorry.php");
	die();
}

?>
