Location: PHPKode > projects > Crown of Evanion > final/avatar.php
<?php
/*
*   This file is part of 'Crown of Evanion'.
*
*    'Crown of Evanion' is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    'Crown of Evanion' is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with 'Crown of Evanion'; if not, write to the Free Software
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

$title = "Avatars";
include("include.php");

$errors = array(
'1' => "<h5>No such avatar.</h5>",
'2' => "<h5>You can't afford that avatar.</h5>",
'3' => "<h5>You have bought a new avatar!</h5>",
'4' => "<h5>You already own that avatar!</h5>",
'5' => "<h5>You do not own that avatar.</h5>",
'6' => "<h5>You're already using that avatar.</h5>",
'7' => "<h5>You have equiped a new avatar!</h5>",
);

echo "<div align=\"center\"><p class=\"black\"><a href=\"$PHP_SELF\">Home</a> | <a href=\"$PHP_SELF?page=shop\">Buy Avatars</a> | <a href=\"$PHP_SELF?page=manage\">Manage Avatars</a></p></div>";

if(!$page) {
	$sel = mysql_query("SELECT image,alt FROM avatars WHERE id = '$user_data[avatar]'");
	$avatarinf = mysql_fetch_array($sel);
	$avatar = $avatarinf[image];
	$avatartext = $avatarinf[alt];
	
	echo "<div align=\"center\">
	<h2>Avatar Conrol Center</h2>
	<p><strong>Current Avatar</strong></p>
	<p><img src=\"$avatar\" height=\"70\" width=\"70\" border=\"0\" alt=\"$avatartext\"></p>";
}

if($page == "shop") {
	$id = $_REQUEST['id'];
	
	echo "<div align=\"center\">
	<h2>Avatar Shop</h2>
	$errors[$error]
	<p>You can buy new forum avatars here.</p>";
	
	$select = mysql_query("SELECT * FROM avatars WHERE stat = '2'");
	$num = mysql_num_rows($select);
	if($num == 0) {
		echo "<h5>There are currently no avatars avalible to buy!</h5>";
	} else {
		while ($stocks = mysql_fetch_array($select)) {
			echo "<div class=\"item\">
			<a href=\"$PHP_SELF?page=buy&id=$stocks[id]\">
			<img src=\"$stocks[image]\" alt=\"$stocks[alt]\" width=\"70\" height=\"70\" border=\"0\">
			</a>
			<p class=\"name\">
			<a href=\"$PHP_SELF?page=buy&id=$stocks[id]\">
			<strong>Price:</strong> $stocks[price]
			</a>
			</p>
			</div>";			
		}
		echo "</div>";
	}			
}

if($page == "buy" && $id) {
	$id = $_REQUEST['id'];
	
	$select = mysql_query("SELECT * FROM avatars WHERE id = '$id'");
	$num = mysql_num_rows($select);
	$avatar = mysql_fetch_array($select);
	
	if($num == 0) {
		header("location: $PHP_SELF?page=shop&error=1");
		die;
	}
	if($avatar[price] > $Money) {
		header("location: $PHP_SELF?page=shop&error=2");
		die;
	}
	
	$select = mysql_query("SELECT id FROM avatars_user WHERE avatar = '$avatar[id]' AND owner = '$UserID'");
	$num = mysql_num_rows($select);
	if($num) {
		header("location: $PHP_SELF?page=shop&error=4");
		die;
	}
	
	mysql_query("UPDATE users SET money = money-$avatar[price] WHERE id = '$UserID'");
	mysql_query("INSERT INTO avatars_user (avatar,owner) VALUES ('$avatar[id]','$UserID')");
	header("location: $PHP_SELF?page=shop&error=3");
	die;
}
	

if($page == "manage") {
	$select = mysql_query("SELECT * FROM avatars_user WHERE owner = '$UserID'");
	$num = mysql_num_rows($select);
	
	echo "<div align=\"center\">
	<h2>Manage Avatars</h2>
	$errors[$error]
	<p>You can see and equip the avatars you have bought here.</p>
	</div>";
	
	if(!$num) {
		echo "<p>You have no avatars!</p>";
	}
	
	while($avatar = mysql_fetch_array($select)) {
		$sel = mysql_query("SELECT image,alt FROM avatars WHERE id = '$avatar[avatar]'");
		$avatardat = mysql_fetch_array($sel);
		echo "<div class=\"item\">
		<a href=\"$PHP_SELF?page=use&id=$avatar[id]\">
		<img src=\"$avatardat[image]\" alt=\"$avatardat[alt]\" width=\"70\" height=\"70\" border=\"0\">
		</a>
		<p class=\"name\">
		<a href=\"$PHP_SELF?page=use&id=$avatar[id]\">
		Use
		</a>
		</p>
		</div>";			
	}
}

if($page == "use" && $id) {
	$id = $_REQUEST['id'];
	
	$select = mysql_query("SELECT * FROM avatars_user WHERE id = '$id'");
	$num = mysql_num_rows($select);
	
	if(!$num) {
		header("location: $PHP_SELF?page=manage&error=1");
		die;
	}
	
	$tar = mysql_fetch_array($select);
	
	if($tar[owner] != $UserID) {
		header("location: $PHP_SELF?page=manage&error=5");
		die;
	}
	
	if($user_data[avatar] == $tar[avatar]) {
		header("location: $PHP_SELF?page=manage&error=6");
		die;
	}
	
	mysql_query("DELETE FROM avatars_user WHERE id = '$id'") or die("Error - " . mysql_error());
	mysql_query("INSERT INTO avatars_user (avatar,owner) VALUES ('$user_data[avatar]','$UserID')") or die("Error - " . mysql_error());
	mysql_query("UPDATE users SET avatar = '$tar[avatar]' WHERE id = '$UserID'") or die("Error - " . mysql_error());
	header("location: $PHP_SELF?page=manage&error=7");
	die;
	
}
	
	
include("footer.php");
?>
	

	
	
	
	
	
	
	
	
	
	
Return current item: Crown of Evanion