<?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: zeph.register.php
Last Change: 12 June 2011
*/

define('IN_FIEME', 1);

include 'global.php';

class zepheus
{
	var $db;
	
	function __construct()
	{
		$this->db = mysqli_connect("localhost", "root", "1q2w3e", "zepheus");
	}
	
	function make_game_acc($name, $password, $admin = 0)
	{
		$stmt = $this->db->prepare("SELECT * FROM accounts WHERE Username = ?");
		$stmt->bind_param("s", $name); 
		$stmt->execute();
		$stmt->store_result();
		
		if ($stmt->num_rows != 0)
		{
			return 2; //Name already used
		}
		
		$stmt = $this->db->prepare("INSERT INTO accounts (`Username`, `Password`, `Admin`) VALUES (?, ?, ?)");
		$stmt->bind_param("ssi", $name, $password, $admin); 
		$stmt->execute();
		return 1;
	}
}

$zepheus = new zepheus;

if (isset($_POST['submit']))
{
	//register the player.
	//make our own checks for data validity. In terms of the code, it will take anything it's given (injections impossible)
	
	if ($_POST['password'] == $_POST['password2'])
	{
		$create = $zepheus->make_game_acc("$_POST[username]", "$_POST[password]", "$_POST[username]", 1, "$_SERVER[REMOTE_ADDR]");
		if ($create == 2)
		{
			$error = "<div style=\"color:#F00\">\"$_POST[username]\" is already a registered account name.<br />Please use another account name.</div>";
		}
		elseif ($create == 1)
		{
			$error = "Everything went fine ;)!<br />";
		}
		else
		{
			$error = "Something went wrong. Please try again!<br />";
		}
	}
	else
	{
		$error = "The given passwords don't match :(<br />";
	}
}
else
{
	$error = "";
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Register script Zepheus - fiemeCP</title>
</head>

<body style="background:#CFF">
<!-- html script -- do not remove !-->

<div style="margin-top: 150px; margin-bottom:10px; width: 400px; margin-left:auto; margin-right:auto; text-align:center">Register for Zepheus.</div>

<table style="width: 500px; border: 1px solid #000; margin-left:auto; margin-right:auto; text-align: center; background:#DFF">
<tr>
	<td width="60%"><form action="zeph.register.php" method="post">Username:</td>
    <td width="40%"><input name="username" maxlength="30"  /></td>
</tr>
<tr>
	<td>Password:</td>
    <td><input name="password" maxlength="30" type="password" /></td>
</tr>
<tr>
	<td>Repeat Password:</td>
    <td><input name="password2" maxlength="30" type="password" /></td>
</tr>
<tr>
	<td colspan="2"><?php echo $error; ?><input name="submit" value="Register!" type="submit" /></form></td>
</tr>
</table>

<div style="margin-top: 150px; margin-bottom:10px; width: 800px; margin-left:auto; margin-right:auto; text-align:center; font-size: 80%;">&copy;2011 xDario. Part of fiemeCP (rev <?php echo FIEME_REV; ?>)<br />
Skin by: xDario (this may be removed and changed at will. The copyright notice above must stay.)</div>

</body>
</html>