<?php
	require_once ('../common/scripts/templatize.inc.php');
	require_once ('../common/scripts/bdd.inc.php');
	require_once ('../common/scripts/emblemize.inc.php');

/***********************/
/*inscription          */
/***********************/

	session_start();
	/*
	//debug : 
	echo '<pre>';
	print_r($_POST);
	print_r($_SESSION);
	print_r($_FILES);
	echo '</pre>';
	*/

	$stringResult='';
	$imageEmblemFile = '';

	//verifie que la valeur du rectangle est la bonne
	if ($_POST['checkValue'] != $_SESSION['checkRegisterValue']) {
	
		$stringResult = '<p>Le chiffre entr&eacute; est invalide. Veuillez refaire l\'inscription &agrave; partir du d&eacute;but, en entrant le bon chiffre.</p>';
	}
	else {
		$res = uploadOrGetEmblem($_FILES['monfichier']);
		$imageEmblemFile = $res[0];
		$stringResult = $res[1];
		
		$_SESSION['checkRegisterValue'] = -2;
		
		//s'inscrit dans la base de donnees

		$folderImage = 'http://'.$_SERVER['HTTP_HOST'].substr($_SERVER['REQUEST_URI'],0,strrpos($_SERVER['REQUEST_URI'],'/'));
		
		registerPlayer($dbconn, 
			$_SESSION['register_login'],
			$_SESSION['register_password'],
			$_POST['mail'],
			$_SESSION['guilde'],
			$_POST['couleurGuilde'],
			$folderImage.'/'.$imageEmblemFile,
			$_SESSION['register_mimichant_name'],
			$_SESSION['register_mimichant_description'],
			$_SESSION['register_mimichant_sex']?'FALSE':'TRUE',
			$_SESSION['register_mimichant_head'],
			$_SESSION['register_mimichant_ears'],
			$_SESSION['register_mimichant_corps'],
			$_SESSION['register_mimichant_tail'],
			$_SESSION['register_mimichant_color'],
			$_SESSION['mimichant_strength'],
			$_SESSION['mimichant_const'],
			$_SESSION['mimichant_dext'],
			$_SESSION['mimichant_psy']
			);
		
		$stringResult = '<p>'.$stringResult.'</p>'.getPlayerInfos($dbconn, $_SESSION['register_login']);
	}
	
/**************/
/*affichage   */
/**************/

	$arrayVars = array('INSCRIPTION_RESULT'=>$stringResult);

	templatizeWithVars('../common/header.tpl','../common/menu.tpl','finInscription.tpl','../common/footer.tpl',$arrayVars);
?>
