Location: PHPKode > projects > Crown of Evanion > final/usershop.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
*/

# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
#                INCOMPLETE                 #
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
$title = "Ye Olde Shoppe";
include("include.php");

# Removes entries with no items left in them
mysql_query("DELETE FROM usershop WHERE quan = '0'");

$errors = array(
'1' => "<h5>You did not specify a shop ID!</h5>",
'2' => "<h5>No such item!</h5>",
'3' => "<h5>You don't have enough money to afford that item!</h5>",
'4' => "<h5>You can't buy that item.</h5>",
);

echo "<div align=\"center\"><p class=\"drag\"><a href=\"$PHP_SELF?page=stock\">Stock</a> | <a href=\"$PHP_SELF?page=view&id=$UserID\">Store</a></p>";

if(!$page) {
	echo "<h2>Ye Olde Shoppes</h2>
	$errors[$error]
	<p>Yarr, welcome to your shop! You can sell your goods here, arr!</p>";
}

if($page == "view") {
	if(!$id) {
		header("location: $PHP_SELF?error=1");
		die;
	}
	echo "<p><img src=\"images/guy.png\" border=\"0\" ALT=\"Shop Guy\"></p>
	<p><strong>$user_data[shopdesc]</strong></p>";
	$select = mysql_query("SELECT * FROM usershop WHERE owner = '$UserID' ORDER BY id DESC");
	$num = mysql_num_rows($select);
	if(!$num) {
		echo "<p><h5>No items in stock!</h5></p>";
	} else {
		while ($items = mysql_fetch_array($select)) {
			$sel = mysql_query("SELECT name,image FROM items WHERE id = '$items[itemid]'");
			$item = mysql_fetch_array($sel);
			echo "<div class=\"item\">
			<a href=\"$PHP_SELF?page=buy&id=$items[id]\">
			<img src=\"$item[image]\" alt=\"$item[name]\" width=\"90\" height=\"90\" border=\"0\">
			</a>
			<p class=\"name\">
			<a href=\"$PHP_SELF?page=buy&id=$items[id]\">
			$item[name]
			</p>
			<p class=\"name\">Price: $items[price]</p>
			<p class=\"name\">Quantity: $items[quan]</p>
			</a>
			</div>";
		}
	}
}

if($page == "buy") {
	if(!$id) {
		header("location: $PHP_SELF?error=2");
		die;
	}
	
	$select = mysql_query("SELECT * FROM usershop WHERE id = '$id'");
	$num = mysql_num_rows($select);
	
	if(!$num) {
		header("location: $PHP_SELF?error=2");
		die;
	}
	
	$item = mysql_fetch_array($select);
	
	if($Money < $item[price]) {	
		header("location: $PHP_SELF?error=3");
		die;
	}
	if($item[price] <= 0) {	
		header("location: $PHP_SELF?error=4");
		die;
	}
	if(!$item[quan]) {
		header("location: $PHP_SELF?error=2");
		die;
	}
	$select = mysql_query("SELECT name,id FROM items WHERE id = '$item[itemid]'");
	$itemname = mysql_fetch_array($select);

	echo "You bought a $itemname[name]!";
	mysql_query("UPDATE users SET money = money-$item[price] WHERE id = '$UserID'");
	mysql_query("UPDATE users SET money = money+$item[price] WHERE id = '$item[owner]'");
	mysql_query("DELETE FROM usershop WHERE id = '$id'");
	mysql_query("INSERT INTO useritems (owner,itemid) VALUES ('$UserID','$itemname[id]')");	
}




echo "</div>";
include("footer.php");
?>	
Return current item: Crown of Evanion