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

// prepare user object
$gameSession = new GameSession($db);

// read mandatory $_POST properties : ensure sessionType and sessionName are passed in $_POST parameters
if (isset($_POST['sessionType']))
	$gameSession->sessionType = $_POST['sessionType'];
else trigger_error( missing_parameter_error("sessionType") );

if (isset($_POST['sessionName']))
	$gameSession->sessionName = $_POST['sessionName'];
else
	$gameSession->sessionName = uniqid("session_");

// read other $_POST properties for game session
$gameSession->sessionDate = date('Y-m-d H:i:s');
$gameSession->mapName = $_POST['mapName'];
$gameSession->scenarioName = $_POST['scenarioName'];
$gameSession->replayFileName = $gameSession->sessionName . date('Y-m-d_H-i-s');

// create the game session
if ($gameSession->start())
{
	$session_arr = $gameSession->getResultArray(true, "Session_In_Progress_OK");
	print_r(json_encode($session_arr));	// OK
}
else trigger_error("Error_Occured");
?>