<?php
/*
fiemeCP - BETA.
Written by, and managed by xDario.

The script may be altered at wish, but redistributing any part of it, even with credets, is prohibited. Currently, only myself and my website (http://www.dario-ml.com/) along with kryptodev are aloud to host my script.

©2011 xDario (created for Ohai Online)

You must provide a thanks on the page from which this is called, unless you have donated. If I find my class used without copyright, or a mention of appreciation, I will pursude you. Fiesta servers aren't thousands, so you're not hard to spot out.

Page: member.php
Last Change: 12 June 2011
*/

define('IN_FIEME', 1);

require_once 'global.php';

$plugin->run_hooks("member_page_start");

if (@$_GET['do'] == 'register')
{
	$settings->load("member");
	$lang->load("member");
	
	if ($settings->register_licence == 1 && @$_POST['register_licence'] != "on")
	{
		if (@$_POST['page'] == 'licence') //someone's posted, but the checkbox wasn't selected
		{
			$error = "<div class=\"form-bad\">$lang->register_agree_acceptlicence</div><br />";
		} else { $error = ""; }
		
		$plugin->run_hooks("member_register_licence_no_1");
		
		eval("\$licence = \"".$settings->register_licence_content."\";");
		eval("\$register_content = \"".$template->get("register_licence")."\";");
		
		$plugin->run_hooks("member_register_licence_no_2");
	}
	else
	{
		if (@$_POST['page'] == 'register') //data validation
		{
			//register the player.
			//make our own checks for data validity. In terms of the code, it will take anything it's given (injections impossible)
			
			$plugin->run_hooks("member_register_start");
			
			//before anything, let's do captcha shit.
			if ($settings->register_captcha == 1)
			{
				include_once 'includes/captcha/securimage.php';
				$securimage = new Securimage();
				
				if ($securimage->check($_POST['captcha_code']) == false) 
				{
					$error = $lang->register_error_captcha;
				}
			}
			
			if (($_POST['email1'] == $_POST['email2']) && !isset($error))
			{
				if (!preg_match("/^([.0-9a-z_-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i", $_POST['email1']))
				{
					$error = $lang->register_error_invalid_email;
				}
			}
			elseif (!isset($error))
			{
				$error = $lang->register_error_email_mismatch;
			}
			
			if (!preg_match("/^([.0-9a-z]+)$/i", $_POST['username']))
			{
				$error = $lang->register_error_char_invalid_chars;
			}
			
			if (($_POST['password'] == $_POST['password2']) && !isset($error))
			{
				if (strlen($_POST['password']) < $settings->register_min_pass_length)
				{
					$error = $lang->register_error_pass_short;
				}
			}
			elseif (!isset($error))
			{
				$error = $lang->register_error_pass_mismatch;
			}
			
			
			if (!isset($error))
			{
				$create = $fiemecp->make_game_acc("$_POST[username]", "$_POST[password]", "$_POST[username]", "$_POST[email1]", 1, "$_SERVER[REMOTE_ADDR]");
				if ($create == 2)
				{
					$error = dsprintf($lang->register_error_already_registered, array('uname'=>"$_POST[username]"));
				}
				elseif ($create == 0)
				{
					$error = $lang->register_error_unknown_error;
				}
			}
		}
		
		if (isset($error) || !isset($_POST['username'])) //if there was an error, of if it's the first time we're here, show the form
		{
			if ($settings->register_captcha == 1)
			{
				eval("\$captcha = \"".$template->get("register_captcha")."\";");
			}
			else	{	$captcha = "";	}
			
			$data = array('uname'=>@$_POST['username'], 'email1'=>@$_POST['email1'], 'email2'=>@$_POST['email2']);
			
			if (!isset($error)) { $error = ""; }
			
			$plugin->run_hooks("member_register_errored");
			
			eval("\$register_content = \"". $template->get("register_form") ."\";");
		}
		else
		{
			$plugin->run_hooks("member_register_success");
			
			eval("\$register_content = \"".$template->get("register_success")."\";");
		}
		
	}
	
	$plugin->run_hooks("member_register_end");
	
	eval("\$register = \"".$template->get("register")."\";");
	output_page($register);
}

$plugin->run_hooks("member_page_page");

?>