<?
	if ($_SERVER['REQUEST_METHOD']=='GET'){
		session_start();
		$_SESSION = array();
		session_regenerate_id(TRUE);
		session_write_close();
	}
	session_start();
	if (!isset($_SESSION['stage']))
		$_SESSION['stage']=1;
	define('HOME_URL','http://www.coromarmolada.it/');
	define('DELTA_MIN',5);
	define('IN_MAIN',TRUE);
	require('includes/db.inc.php');
	require('includes/functions.inc.php');
?>
<?
	$socioTessera=null;
	cleanOld();
	if ($_SERVER['REQUEST_METHOD']=='POST'){
		$command=$_POST['cmd'];
		switch ($command){
			case 'confirm':
				$user_email=trim($_POST['data']);
				require('includes/isemail.php');
				if ($user_email!="" && is_email($user_email,TRUE)){
					doConfirm();
				}else{
					$command='email_error';
					$email_error="<span style='font-weight:bold;'>Inserisci un&#39;e-mail valida!</span><br/>";
				}
				break;
			case 'add':
				doAdd();
				break;
			case 'remove':
				doRemove();
				break;
			case 'notify':
				doNotify();
				break;
			case 'checkTessera':
				$socioTessera=doCheckTessera();
				if ($socioTessera!=null){
					$_SESSION['socio']=$socioTessera;
					$_SESSION['stage']=2;
				}
				break;
			case 'checkAnag':
				$token='[]';
				$nome=trim(strtok($_POST['data'],$token));
				$cognome=trim(strtok($token));
				$socioTessera=doCheckAnagrafica($nome,$cognome);
				if ($socioTessera!=null){
					$_SESSION['socio']=$socioTessera;
					$_SESSION['stage']=3;
				}
				break;
			case 'go':
				$_SESSION['stage']=4;
				break;
			default:
				break;
		}
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	lang="en"
	xml:lang="en">
	<head>
		<title>Prenotazione posti Concerto Malibran, 9 dicembre 2009</title>
		<link rel="stylesheet" href="styles/prenotaposti.css"/>
		<script language="javascript" src="script/prenotaposti.js" ></script>
	</head>
	<body>
		<form id="form1" action="<?=$_SERVER['PHP_SELF']?>" method="POST">
			<input type="hidden" id="cmd" name="cmd" value="" />
			<input type="hidden" id="data" name="data"value="" />
		</form>
		<div id="sfondo">
<?
	require('includes/stage'.$_SESSION['stage'].'.inc.php');
?>
		</div> 
	</body>
</html>
<?
	if ($mysqli){
		$mysqli->close();
	}
?>