<?php
// include database and object files
include_once '../config/init.php';	// contains $db
include_once '../config/error.php';
include_once '../objects/stats_object.php';

$userId = -1;
$sessionId = -1;
$quickMode = 0;

if (isset($_POST['userId']))
	$userId = $_POST['userId'];
else trigger_error( missing_parameter_error("userId") );

if (isset($_POST['sessionId']))
	$sessionId = $_POST['sessionId'];
else trigger_error( missing_parameter_error("sessionId") );

if (isset($_POST['quickMode']))
	$quickMode = strtolower($_POST['quickMode']) == "true" ? 1 : 0;

//if ($userId > 0 && $sessionId > 0)
{
	$cacheKey = "userhistory_" . intval($userId) . "_" . intval($quickMode);
	$cached = cache_get($sessionId, $cacheKey);
	if ($cached !== null)
	{
		print_r($cached);
	}
	else
	{
		$stats = new StatsObject($db);
		$stats->getUserHistory($userId, $sessionId, $quickMode);

		$stats_arr = $stats->getResultArray(true, "Results_Collected_OK");
		$json = json_encode($stats_arr);
		cache_put($sessionId, $cacheKey, $json);
		print_r($json);	// OK
	}
}
?>