<?php
if (isset($_POST['race']) && isset($_POST['face']) && isset($_POST['size']) && isset($_POST['job']) && isset($_POST['name']) && isset($_POST['nation'])) {


$race=(int)$_POST['race'];
$face=(int)$_POST['face'];
$size=(int)$_POST['size'];
$job=(int)$_POST['job'];
$nation=(int)$_POST['nation'];
$name=strtolower($_POST['name']);
$name=ucfirst($name);

if($race<1 || $race >8){
	echo getPanel("danger","Failed","Race is not valid!");
}elseif($face<0 || $face >15){
	echo getPanel("danger","Failed","Face is not valid!");
}elseif($size<0 || $size >2){
	echo getPanel("danger","Failed","Size is not valid!");
}elseif($job<1 || $job >6){
	echo getPanel("danger","Failed","Job is not valid!");
}elseif(in_array($name,$badnames)==true){
	echo getPanel("danger","Failed","Character name is not allowed!");
}elseif(getCharacterByName($name)!='empty'){
	echo getPanel("danger","Failed","Character name is taken!");
}elseif(strlen($name)<3){
	echo getPanel("danger","Failed","Character name is too short!");
}elseif(strlen($name)>15){
	echo getPanel("danger","Failed","Character name is too long!");
}elseif(ctype_alpha($name)==false){
	echo getPanel("danger","Failed","Character name is not valid!");
}elseif($nation<0 || $nation >2){
	echo getPanel("danger","Failed","Nation is not valid!");
}else{
	$accid=$users['id'];
	$charid=getMaxCharid()+1;
	if ($accounttype == '1')
	{
		$poszone = 222;

		createCharacter($charid,$accid,$name,$poszone,$nation);
		insertLook($charid,$face,$race,$size);
		insertStats($charid,$job);
	}
	else {
		$poszone=230;

		if($nation==0){
			$poszone=rand(230,232);
		}
		if($nation==1){
			$poszone=rand(234,236);
		}
		if($nation==2){
			$exclude = array(239);
		while(in_array(($x = rand(238,241)), $exclude));
			$poszone=$x;
		}

		createCharacter($charid,$accid,$name,$poszone,$nation);
		insertLook($charid,$face,$race,$size);
		insertStats($charid,$job);
		setPlayerVariable($charid,'HQuest[newCharacterCS]notSeen','1');
	}

	echo '<div class="alert alert-success" role="alert">Character successfully created!</div>';
	if ($accounttype == '1') {
		echo '<div class="alert alert-info" role="alert">Crystal Warriors will be able to choose their "Unbreakable" status in-game during the introduction.</div>';
	}
}
/*
echo 'race:' . $race . '<br />';
echo 'face:' . $face . '<br />';
echo 'size:' . $size . '<br />';
echo 'job:' . $job . '<br />';
echo 'name:' . $name . '<br />';
echo 'nation:' . $nation . '<br />';
echo 'accid:' . $accid . '<br />';
echo 'charid:' . $charid . '<br />';
echo 'acctype:' . $accounttype . '<br />';
echo 'zone:' . $poszone . '<br />' ;
*/
}
/*
$race=$_POST['race'];
$face=$_POST['face'];
$size=$_POST['size'];
$job=$_POST['job'];
$name=$_POST['name'];
$nation=$_POST['nation'];

if (isset($race) && isset($face) && isset($size) && isset($job) && isset($name) && isset($nation)) {


$race=(int)$race;
$face=(int)$face;
$size=(int)$size;
$job=(int)$job;
$nation=(int)$nation;
$name=strtolower($name);
$name=ucfirst($name);
if($race<1 || $race >8){
	echo getPanel("danger","Failed","Race is not valid!");
}elseif($face<0 || $face >15){
	echo getPanel("danger","Failed","Face is not valid!");
}elseif($size<0 || $size >2){
	echo getPanel("danger","Failed","Size is not valid!");
}elseif($job<1 || $job >6){
	echo getPanel("danger","Failed","Job is not valid!");
}elseif(in_array($name,$badnames)==true){
	echo getPanel("danger","Failed","Character name is not allowed!");
}elseif(getCharacterByName($name)!='empty'){
	echo getPanel("danger","Failed","Character name is taken!");
}elseif(strlen($name)<3){
	echo getPanel("danger","Failed","Character name is too short!");
}elseif(strlen($name)>15){
	echo getPanel("danger","Failed","Character name is too long!");
}elseif(ctype_alpha($name)==false){
	echo getPanel("danger","Failed","Character name is not valid!");
}elseif($nation<0 || $nation >2){
	echo getPanel("danger","Failed","Nation is not valid!");
}else{
	echo "do submission step";
}
}

$accid=$users['id'];
$charid=getMaxCharid()+1;

echo 'submitted info:';
echo 'race:' . $race . '<br />';
echo 'face:' . $face . '<br />';
echo 'size:' . $size . '<br />';
echo 'job:' . $job . '<br />';
echo 'name:' . $name . '<br />';
echo 'nation:' . $nation . '<br />';
echo 'accid:' . $accid . '<br />';
echo 'charid:' . $charid . '<br />';
*/
/*
if ($accounttype == '1')
{
	$poszone = 
}
$poszone=230;
if($nation==0){
	$poszone=rand(230,232);
}
if($nation==1){
	$poszone=rand(234,236);
}
if($nation==2){
	$exclude = array(239);
while(in_array(($x = rand(238,241)), $exclude));
	$poszone=$x;
}
$accid=$users['id'];
$charid=getMaxCharid()+1;
createCharacter($charid,$accid,$name,$poszone,$nation);
insertLook($charid,$face,$race,$size);
insertStats($charid,$job);
setPlayerVariable($charid,'HQuest[newCharacterCS]notSeen','1');
echo getPanel("success","Success","Created New Character");

}
}else{
echo getPanel("danger","Max Characters","You are unable to create any more characters, please delete characters if you wish to make more.");	
	
}
*/
?>
