<?php include "core/menu.php" ?>
							<br/><br/>
						</div>
					</div>
				</div>
				
				<div class="spacer"></div>				<div class="news">
				<div />
				<div>
				<?php
error_reporting(0);
include ('config/config.php');
$username = $_SESSION['username'];
if(isset($_POST['objet']) and (isset($_POST['pseudo'])))
{
	try
{
    $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
    $bdd = new PDO('mysql:host=localhost;dbname=realmd', 'root2', '123', $pdo_options);

    $reponse = $bdd->query("SELECT online FROM account WHERE username = '".$username."'");
	


    while ($donnees = $reponse->fetch())
    {
		$online = $donnees['online'];
    }
    
    $reponse->closeCursor();
}
catch(Exception $e)
{
    die('Erreur : '.$e->getMessage());
}
try
{
    $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
    $bdd2 = new PDO('mysql:host=localhost;dbname=characters', 'root2', '123', $pdo_options);
	
    $reponse2 = $bdd2->query("SELECT online FROM characters WHERE account = '".$_POST['pseudo']."'");

    while ($donnees2 = $reponse2->fetch())
    {
	$online2 = $donnees2['online'];
    }
    $reponse->closeCursor();
}
catch(Exception $e)
{
    die('Erreur : '.$e->getMessage());
}
if($online != 0 or $online2 != 0)
{
	echo "Erreur, vous devez être connectez.";
}
else
{
		try
{
    $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
    $bdd = new PDO('mysql:host=localhost;dbname=characters', 'root2', '123', $pdo_options);

    $reponse = $bdd->query("SELECT money FROM characters WHERE name = '".$_POST['pseudo']."'");

    while ($donnees = $reponse->fetch())
    {
	$money = $donnees['money'];
    }
    
    $reponse->closeCursor();
}
catch(Exception $e)
{
    die('Erreur : '.$e->getMessage());
}
	if($objet = 50000000)
	{
		$point = 10;
	}
	elseif($objet = 100000000)
	{
		$point = 20;
	}
	elseif($objet = 150000000)
	{
		$point = 30;
	}
	$objet = $_POST['objet'];
	if($objet + $money > 4294967295)
	{
		echo "Impossible.";
	}
	else
	{
	try
{
    $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
    $bdd = new PDO('mysql:host=localhost;dbname=realmd', 'root2', '123', $pdo_options);

    $reponse = $bdd->query("SELECT id FROM account WHERE username = '".$username."'");

    while ($donnees = $reponse->fetch())
    {
	$id = $donnees['id'];
    }
    
    $reponse->closeCursor();
}
catch(Exception $e)
{
    die('Erreur : '.$e->getMessage());
}
try
{
	$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
	$bdd = new PDO('mysql:host=localhost;dbname=realmd', 'root2', '123', $pdo_options);
	
}
catch (Exception $e)
{
        die('Erreur : ' . $e->getMessage());
}

$reponse = $bdd->query("SELECT dp FROM account WHERE username = '".$username."'");
while ($donnees = $reponse->fetch())
{
$dp = $donnees['dp'];
}

if ($point > $dp)
{
echo "Vous n'avez pas assez de points S.";
}
else
{
	mysql_connect('localhost','root2','123');
	mysql_select_db("realmd");
	mysql_query("UPDATE account SET dp = dp - '".$point."' WHERE username = '".$username."'");
	mysql_connect('localhost','root2','123');
	mysql_select_db("characters");
	mysql_query("UPDATE characters SET money = '".$money."' + '".$objet."' WHERE name = '".$_POST['pseudo']."'");
?>
Vous avez reçu vos pièces d'or sur votre personnage.
<?php
	}
	}
	}
}
else
{
try
{
    $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
    $bdd = new PDO('mysql:host=localhost;dbname=realmd', 'root2', '123', $pdo_options);

    $reponse = $bdd->query("SELECT id FROM account WHERE username = '".$username."'");

    while ($donnees = $reponse->fetch())
    {
	$id = $donnees['id'];
    }
    
    $reponse->closeCursor();
}
catch(Exception $e)
{
    die('Erreur : '.$e->getMessage());
}
?>
	<center><form method="post" action=""><img src="img/money.png" />
<div></strong><select name="objet" required><option value="50000000">5 000 Pi&egraveces d'or - 10 Points</option><option value="100000000">10 000 Pi&egraveces d'or - 20 Points</option><option value="150000000">15 000 Pi&egraveces d'or - 30 Points</option></select></div>
<br />
<h3>Nom du personnage</h3>
<select name="pseudo">
<option>Choisissez votre personnage...</option>
<optgroup label="Synarius [Fun]">
<?php
try
{
    $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
    $bdd = new PDO('mysql:host=localhost;dbname=characters', 'root2', '123', $pdo_options);

    $reponse = $bdd->query("SELECT name FROM characters WHERE account = '".$id."'");

    while ($donnees = $reponse->fetch())
    {
	$name = $donnees['name'];
	?>
    <option value="<?php echo $name; ?>"><?php echo $name; ?></option>
    <?php
    }
    
    $reponse->closeCursor();
}
catch(Exception $e)
{
    die('Erreur : '.$e->getMessage());
}
?>
</optgroup>
</select><br /><br />
<input type="submit" value="Envoyez"></form>
<?php
}
?>

</div>
					</div>
					<div class="spacer"></div>
				</div>
			</div>

<?php include "core/end.php" ?>